fix(tls): repair Windows certificate installer and verify trust
This commit is contained in:
+1
-1
@@ -43,7 +43,7 @@ if [ ! -f "$CERT_DIR/cert.pem" ] || [ ! -f "$CERT_DIR/key.pem" ]; then
|
|||||||
# в хранилище корневых: без него корневой сертификат считается недействительным.
|
# в хранилище корневых: без него корневой сертификат считается недействительным.
|
||||||
openssl req -x509 -nodes -newkey rsa:2048 -days 3650 \
|
openssl req -x509 -nodes -newkey rsa:2048 -days 3650 \
|
||||||
-keyout "$CERT_DIR/key.pem" -out "$CERT_DIR/cert.pem" \
|
-keyout "$CERT_DIR/key.pem" -out "$CERT_DIR/cert.pem" \
|
||||||
-subj "/CN=$CERT_CN" \
|
-subj "/O=WhatIDo/CN=$CERT_CN" \
|
||||||
-addext "subjectAltName=$SAN" \
|
-addext "subjectAltName=$SAN" \
|
||||||
-addext "basicConstraints=critical,CA:TRUE" \
|
-addext "basicConstraints=critical,CA:TRUE" \
|
||||||
-addext "keyUsage=critical,digitalSignature,keyEncipherment,keyCertSign"
|
-addext "keyUsage=critical,digitalSignature,keyEncipherment,keyCertSign"
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
@echo off
|
@echo off
|
||||||
rem Installs the WhatIDo self-signed certificate into Trusted Root on Windows.
|
rem Installs the WhatIDo self-signed certificate into Trusted Root on Windows.
|
||||||
rem Run as administrator (right-click - Run as administrator).
|
rem The script requests administrator rights automatically (UAC) unless
|
||||||
rem Pass arguments through to the PowerShell script, e.g.:
|
rem -StoreLocation CurrentUser is passed.
|
||||||
rem install-cert.cmd -StoreLocation CurrentUser
|
rem Examples:
|
||||||
rem install-cert.cmd -Uninstall
|
rem install-whatido-cert.cmd
|
||||||
|
rem install-whatido-cert.cmd -Uninstall
|
||||||
|
rem install-whatido-cert.cmd -StoreLocation CurrentUser
|
||||||
setlocal
|
setlocal
|
||||||
|
|
||||||
|
set "ELEVATE=1"
|
||||||
|
echo %* | findstr /I /C:"CurrentUser" >nul && set "ELEVATE=0"
|
||||||
|
if "%ELEVATE%"=="1" (
|
||||||
|
net session >nul 2>&1
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo Requesting administrator privileges...
|
||||||
|
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -ArgumentList '%*' -Verb RunAs"
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0install-whatido-cert.ps1" %*
|
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0install-whatido-cert.ps1" %*
|
||||||
echo.
|
echo.
|
||||||
pause
|
pause
|
||||||
|
|||||||
+52
-18
@@ -12,7 +12,7 @@
|
|||||||
# .\install-whatido-cert.ps1 -Uninstall
|
# .\install-whatido-cert.ps1 -Uninstall
|
||||||
|
|
||||||
param(
|
param(
|
||||||
[ValidateSet('LocalMachine', 'CurrentUser', IgnoresCase = $false)]
|
[ValidateSet('LocalMachine', 'CurrentUser')]
|
||||||
[string] $StoreLocation = 'LocalMachine',
|
[string] $StoreLocation = 'LocalMachine',
|
||||||
|
|
||||||
[string] $CertPath = '',
|
[string] $CertPath = '',
|
||||||
@@ -51,6 +51,18 @@ function Get-HostInSan($Cert, [string] $HostName) {
|
|||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Test-CertTrusted($Cert) {
|
||||||
|
$chain = New-Object System.Security.Cryptography.X509Certificates.X509Chain
|
||||||
|
$chain.ChainPolicy.RevocationMode = [System.Security.Cryptography.X509Certificates.X509RevocationMode]::NoCheck
|
||||||
|
$ok = $chain.Build($Cert)
|
||||||
|
if (-not $ok) {
|
||||||
|
foreach ($s in $chain.ChainStatus) {
|
||||||
|
Write-Warning ("Цепочка: " + $s.Status + " - " + $s.StatusInformation.Trim())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $ok
|
||||||
|
}
|
||||||
|
|
||||||
if (-not (Test-Path $storePath)) {
|
if (-not (Test-Path $storePath)) {
|
||||||
Write-Error "Хранилище не найдено: $storePath"
|
Write-Error "Хранилище не найдено: $storePath"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -59,21 +71,6 @@ if (-not (Test-Path $storePath)) {
|
|||||||
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store('Root', $StoreLocation)
|
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store('Root', $StoreLocation)
|
||||||
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
|
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
|
||||||
|
|
||||||
if ($Uninstall) {
|
|
||||||
$targets = @($store.Certificates | Where-Object { $_.Subject -match 'whatido' })
|
|
||||||
if (-not $targets) {
|
|
||||||
Write-Host "В хранилище $storePath нет сертификатов WhatIDo." -ForegroundColor Green
|
|
||||||
} else {
|
|
||||||
foreach ($t in $targets) {
|
|
||||||
$store.Remove($t)
|
|
||||||
Write-Host "Удалён: $($t.Subject)" -ForegroundColor Yellow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$store.Close()
|
|
||||||
Write-Host "Готово. Перезапустите браузер." -ForegroundColor Cyan
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
# --- 1. Получаем сертификат: файл рядом со скриптом, потом - загрузка по URL ---
|
# --- 1. Получаем сертификат: файл рядом со скриптом, потом - загрузка по URL ---
|
||||||
$bytes = $null
|
$bytes = $null
|
||||||
$source = ''
|
$source = ''
|
||||||
@@ -148,10 +145,40 @@ if ($CheckHost) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($Uninstall) {
|
||||||
|
$targets = @($store.Certificates | Where-Object {
|
||||||
|
$_.Thumbprint -eq $cert.Thumbprint -or $_.Subject -eq $cert.Subject -or $_.Subject -match 'O=WhatIDo'
|
||||||
|
})
|
||||||
|
if (-not $targets) {
|
||||||
|
Write-Host "В хранилище $storePath нет сертификатов WhatIDo." -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
foreach ($t in $targets) {
|
||||||
|
$store.Remove($t)
|
||||||
|
Write-Host "Удалён: $($t.Subject) ($($t.Thumbprint))" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$store.Close()
|
||||||
|
Write-Host "Готово. Перезапустите браузер." -ForegroundColor Cyan
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
$stale = @($store.Certificates | Where-Object {
|
||||||
|
$_.Thumbprint -ne $cert.Thumbprint -and ($_.Subject -eq $cert.Subject -or $_.Subject -match 'O=WhatIDo')
|
||||||
|
})
|
||||||
|
foreach ($s in $stale) {
|
||||||
|
$store.Remove($s)
|
||||||
|
Write-Host "Удалён устаревший сертификат: $($s.Subject) ($($s.Thumbprint))" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
# --- 3. Идемпотентность: если такой сертификат уже есть - ничего не делаем ---
|
# --- 3. Идемпотентность: если такой сертификат уже есть - ничего не делаем ---
|
||||||
$existing = $store.Certificates | Where-Object { $_.Thumbprint -eq $cert.Thumbprint }
|
$existing = $store.Certificates | Where-Object { $_.Thumbprint -eq $cert.Thumbprint }
|
||||||
if ($existing) {
|
if ($existing) {
|
||||||
Write-Host "Сертификат уже установлен в $storePath" -ForegroundColor Green
|
Write-Host "Сертификат уже установлен в $storePath" -ForegroundColor Green
|
||||||
|
if (Test-CertTrusted $cert) {
|
||||||
|
Write-Host "Проверка цепочки: сертификат доверенный." -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Warning "Сертификат есть в хранилище, но проверка цепочки не прошла."
|
||||||
|
}
|
||||||
$store.Close()
|
$store.Close()
|
||||||
Write-Host "Перезапустите браузер." -ForegroundColor Cyan
|
Write-Host "Перезапустите браузер." -ForegroundColor Cyan
|
||||||
exit 0
|
exit 0
|
||||||
@@ -168,10 +195,17 @@ try {
|
|||||||
|
|
||||||
Write-Host "Сертификат добавлен в хранилище $storePath" -ForegroundColor Green
|
Write-Host "Сертификат добавлен в хранилище $storePath" -ForegroundColor Green
|
||||||
|
|
||||||
# --- 5. Итог ---
|
# --- 5. Проверка цепочки ---
|
||||||
|
if (Test-CertTrusted $cert) {
|
||||||
|
Write-Host "Проверка цепочки: сертификат доверенный." -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Warning "Проверка цепочки не прошла: система всё ещё не доверяет сертификату."
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- 6. Итог ---
|
||||||
Write-Host "Теперь в хранилище:" -ForegroundColor Cyan
|
Write-Host "Теперь в хранилище:" -ForegroundColor Cyan
|
||||||
$store.Certificates |
|
$store.Certificates |
|
||||||
Where-Object { $_.NotAfter -gt (Get-Date) -and $_.Subject -match 'whatido' } |
|
Where-Object { $_.NotAfter -gt (Get-Date) -and ($_.Subject -match 'O=WhatIDo' -or $_.Thumbprint -eq $cert.Thumbprint) } |
|
||||||
Select-Object -First 5 Subject, NotAfter, Thumbprint |
|
Select-Object -First 5 Subject, NotAfter, Thumbprint |
|
||||||
Format-Table -AutoSize
|
Format-Table -AutoSize
|
||||||
|
|
||||||
|
|||||||
@@ -10634,10 +10634,15 @@ function tlsPackageReadme(tls) {
|
|||||||
' README.txt этот файл',
|
' README.txt этот файл',
|
||||||
'',
|
'',
|
||||||
'Способ 1 — один клик',
|
'Способ 1 — один клик',
|
||||||
' 1. Распакуйте архив в обычную папку (не в корзину, PowerShell из ZIP не читает).',
|
' 1. Распакуйте архив в обычную папку (не запускайте из ZIP).',
|
||||||
' 2. Нажмите правой кнопкой по install-cert.cmd → «Запустить от имени администратора».',
|
' 2. Дважды кликните install-cert.cmd — Windows запросит права администратора.',
|
||||||
' 3. Полностью закройте браузер и откройте приложение заново.',
|
' 3. Полностью закройте браузер и откройте приложение заново.',
|
||||||
'',
|
'',
|
||||||
|
'Если сертификат уже устанавливали раньше, а серверный сертификат пересоздавали,',
|
||||||
|
'в хранилище мог остаться старый отпечаток. Запустите install-cert.cmd -Uninstall,',
|
||||||
|
'затем установите сертификат из этого архива заново: браузер доверяет только',
|
||||||
|
'текущему отпечатку.',
|
||||||
|
'',
|
||||||
'Способ 2 — без PowerShell',
|
'Способ 2 — без PowerShell',
|
||||||
' 1. Дважды кликните whatido-cert.cer.',
|
' 1. Дважды кликните whatido-cert.cer.',
|
||||||
' 2. В мастере нажмите «Установить сертификат…».',
|
' 2. В мастере нажмите «Установить сертификат…».',
|
||||||
|
|||||||
Reference in New Issue
Block a user