diff --git a/Help-D_RDP.pfx b/Help-D_RDP.pfx new file mode 100644 index 0000000..5480a5d Binary files /dev/null and b/Help-D_RDP.pfx differ diff --git a/installSSL.ps1 b/installSSL.ps1 index 076f62a..f0ecec9 100644 --- a/installSSL.ps1 +++ b/installSSL.ps1 @@ -1,31 +1,94 @@ -# ========================================== -# 📥 ШАГ 1: Установка сертификата в систему -# ========================================== -# Путь к файлу PFX -$PfxPath = "C:\edo\Help-D_RDP.pfx" -$PfxPassword = "sj032ssa" +# ============================================================ +# Skript ustanovki sertifikata dlya RDP signing +# Zapusk: irm https://git.help-d.ru/helmut/ssl.git/raw/branch/main/installSSL.ps1 | iex +# ============================================================ -Write-Host "⏳ Импорт сертификата..." -ForegroundColor Cyan +# ========== НАСТРОЙКИ (править при размещении на своём Gitea) ========== +$GiteaUrl = "https://git.help-d.ru" # Адрес твоего Gitea +$RepoPath = "helmut/ssl.git//raw/branch/main" # Путь к raw-файлам +$CertFileName = "Help-D_RDP.pfx" # Имя PFX-файла в репо +$CertPassword = "sj032ssa" # Пароль от PFX +$CertStorePath = "C:\tmp\cert" # Папка для временного хранения +$ThumbprintFile = "$CertStorePath\thumbprint.txt" # Куда сохранить отпечаток +# ====================================================================== + +# Проверка прав администратора +if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { + Write-Error "❌ Запустите PowerShell от имени Администратора" + exit 1 +} + +# 1. Подготовка папки +Write-Host "`n[1/4] Preparing folder..." -ForegroundColor Cyan +if (-not (Test-Path $CertStorePath)) { + New-Item -ItemType Directory -Path $CertStorePath -Force | Out-Null + Write-Host " Created: $CertStorePath" -ForegroundColor Gray +} + +# 2. Скачивание сертификата +Write-Host "[2/4] Downloading certificate..." -ForegroundColor Cyan +$CertUrl = "$GiteaUrl/$RepoPath/$CertFileName" +$CertPath = "$CertStorePath\$CertFileName" try { - $SecurePass = ConvertTo-SecureString -String $PfxPassword -AsPlainText -Force - - # 1. Доверенные корневые центры (Доверие цепочке) - Import-PfxCertificate -FilePath $PfxPath -CertStoreLocation Cert:\LocalMachine\Root -Password $SecurePass | Out-Null - - # 2. Доверенные издатели (Убирает предупреждение "Неизвестный издатель") - Import-PfxCertificate -FilePath $PfxPath -CertStoreLocation Cert:\LocalMachine\TrustedPublisher -Password $SecurePass | Out-Null - - # 3. Личное хранилище (Доступ к приватному ключу для подписи) - $Cert = Import-PfxCertificate -FilePath $PfxPath -CertStoreLocation Cert:\LocalMachine\My -Password $SecurePass -Exportable - - $Thumb = $Cert.Thumbprint - - Write-Host "✅ Сертификат успешно установлен." -ForegroundColor Green - Write-Host "📋 Скопируйте этот отпечаток для Шага 2:" -ForegroundColor Yellow - Write-Host "------------------------------------------------" - Write-Host "$Thumb" -ForegroundColor White -BackgroundColor DarkBlue - Write-Host "------------------------------------------------" + Invoke-WebRequest -Uri $CertUrl -OutFile $CertPath -ErrorAction Stop -UseBasicParsing + Write-Host " Downloaded: $CertFileName" -ForegroundColor Green } catch { - Write-Error "❌ Ошибка установки: $_" -} \ No newline at end of file + Write-Error "❌ Failed to download certificate from $CertUrl`n Error: $_" + exit 1 +} + +# 3. Установка в хранилища +Write-Host "[3/4] Installing certificate..." -ForegroundColor Cyan +$SecurePass = ConvertTo-SecureString -String $CertPassword -AsPlainText -Force + +try { + # Импорт в личное хранилище (приватный ключ для подписи) + $Cert = Import-PfxCertificate -FilePath $CertPath -CertStoreLocation Cert:\LocalMachine\My -Password $SecurePass -Exportable + $Thumb = $Cert.Thumbprint + + # Импорт в доверенные корневые центры + Import-PfxCertificate -FilePath $CertPath -CertStoreLocation Cert:\LocalMachine\Root -Password $SecurePass | Out-Null + + # Импорт в доверенные издатели (обязательно для RDP) + Import-PfxCertificate -FilePath $CertPath -CertStoreLocation Cert:\LocalMachine\TrustedPublisher -Password $SecurePass | Out-Null + + Write-Host " Certificate installed to:" -ForegroundColor Green + Write-Host " • LocalMachine\My" -ForegroundColor Gray + Write-Host " • LocalMachine\Root" -ForegroundColor Gray + Write-Host " • LocalMachine\TrustedPublisher" -ForegroundColor Gray + +} catch { + # Если сертификат уже установлен — берём его из хранилища + if ($_.Exception.Message -match "already exists") { + $Cert = Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Subject -like "*Help-D*" } | Select-Object -First 1 + $Thumb = $Cert.Thumbprint + Write-Host " Certificate already installed. Using existing." -ForegroundColor Yellow + } else { + Write-Error "❌ Installation error: $_" + exit 1 + } +} + +# 4. Сохранение отпечатка и вывод результата +Write-Host "[4/4] Saving thumbprint..." -ForegroundColor Cyan +$Thumb | Out-File -FilePath $ThumbprintFile -Encoding ASCII -Force +Write-Host " Saved to: $ThumbprintFile" -ForegroundColor Gray + +# ============================================ +# РЕЗУЛЬТАТ +# ============================================ +Write-Host "`n==========================================" -ForegroundColor Green +Write-Host " CERTIFICATE INSTALLATION COMPLETE" -ForegroundColor Green +Write-Host "==========================================" -ForegroundColor Green +Write-Host "`nThumbprint (для подписи RDP):" -ForegroundColor Yellow +Write-Host "------------------------------------------------" +Write-Host "$Thumb" -ForegroundColor White -BackgroundColor DarkBlue +Write-Host "------------------------------------------------" +Write-Host "`nТеперь можно запускать скрипт подписи:" -ForegroundColor Cyan +Write-Host " irm https://git.help-d.ru/.../sign-rdp.ps1 | iex" -ForegroundColor Gray +Write-Host "" + +# Очистка: удаляем PFX, оставляем только отпечаток +Remove-Item $CertPath -Force -ErrorAction SilentlyContinue +Write-Host "🗑️ PFX-файл удалён из $CertStorePath (остался только отпечаток)" -ForegroundColor Gray \ No newline at end of file