edit script
This commit is contained in:
helmut 2026-04-16 17:03:51 +05:00
parent 157c4f2b3b
commit 67c5d26ed3
2 changed files with 90 additions and 27 deletions

BIN
Help-D_RDP.pfx Normal file

Binary file not shown.

View File

@ -1,31 +1,94 @@
# ========================================== # ============================================================
# 📥 ШАГ 1: Установка сертификата в систему # Skript ustanovki sertifikata dlya RDP signing
# ========================================== # Zapusk: irm https://git.help-d.ru/helmut/ssl.git/raw/branch/main/installSSL.ps1 | iex
# Путь к файлу PFX # ============================================================
$PfxPath = "C:\edo\Help-D_RDP.pfx"
$PfxPassword = "sj032ssa"
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 { try {
$SecurePass = ConvertTo-SecureString -String $PfxPassword -AsPlainText -Force Invoke-WebRequest -Uri $CertUrl -OutFile $CertPath -ErrorAction Stop -UseBasicParsing
Write-Host " Downloaded: $CertFileName" -ForegroundColor Green
} catch {
Write-Error "❌ Failed to download certificate from $CertUrl`n Error: $_"
exit 1
}
# 1. Доверенные корневые центры (Доверие цепочке) # 3. Установка в хранилища
Import-PfxCertificate -FilePath $PfxPath -CertStoreLocation Cert:\LocalMachine\Root -Password $SecurePass | Out-Null Write-Host "[3/4] Installing certificate..." -ForegroundColor Cyan
$SecurePass = ConvertTo-SecureString -String $CertPassword -AsPlainText -Force
# 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
try {
# Импорт в личное хранилище (приватный ключ для подписи)
$Cert = Import-PfxCertificate -FilePath $CertPath -CertStoreLocation Cert:\LocalMachine\My -Password $SecurePass -Exportable
$Thumb = $Cert.Thumbprint $Thumb = $Cert.Thumbprint
Write-Host "✅ Сертификат успешно установлен." -ForegroundColor Green # Импорт в доверенные корневые центры
Write-Host "📋 Скопируйте этот отпечаток для Шага 2:" -ForegroundColor Yellow 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 "------------------------------------------------"
Write-Host "$Thumb" -ForegroundColor White -BackgroundColor DarkBlue Write-Host "$Thumb" -ForegroundColor White -BackgroundColor DarkBlue
Write-Host "------------------------------------------------" Write-Host "------------------------------------------------"
} catch { Write-Host "`nТеперь можно запускать скрипт подписи:" -ForegroundColor Cyan
Write-Error "❌ Ошибка установки: $_" 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