<#
.SYNOPSIS
Script interattivo per abilitare o disabilitare i cifrari legacy (RC4, 3DES)
necessari per la compatibilità con SQL Server 2005 su sistemi Windows recenti.
#>
function Backup-Registry {
param([string]$Mode)
$timestamp = Get-Date -Format 'yyyyMMdd_HHmmss'
$path = "$env:SystemDrive\cipher_backup_${Mode}_$timestamp.reg"
reg export "HKLM\SYSTEM\CurrentControlSet\Control\Cryptography\Configuration\Local\SSL\00010002" $path | Out-Null
Write-Host "📁 Backup del registro salvato in: $path" -ForegroundColor Cyan
}
function Enable-LegacyCiphers {
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Cryptography\Configuration\Local\SSL\00010002"
$legacySuites = @(
"TLS_RSA_WITH_3DES_EDE_CBC_SHA",
"TLS_RSA_WITH_RC4_128_SHA",
"TLS_RSA_WITH_RC4_128_MD5"
)
Backup-Registry -Mode "enable"
$currentCiphers = (Get-ItemProperty -Path $regPath).Functions
$missing = $legacySuites | Where-Object { $_ -notin $currentCiphers }
if ($missing.Count -gt 0) {
Write-Host "➕ Aggiunta cipher suite legacy: $($missing -join ', ')" -ForegroundColor Yellow
$newList = $currentCiphers + $missing
Set-ItemProperty -Path $regPath -Name "Functions" -Value $newList
Write-Host "✅ Cifrari legacy abilitati." -ForegroundColor Green
} else {
Write-Host "✅ Tutti i cifrari legacy sono già presenti." -ForegroundColor Green
}
}
function Disable-LegacyCiphers {
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Cryptography\Configuration\Local\SSL\00010002"
$legacySuites = @(
"TLS_RSA_WITH_3DES_EDE_CBC_SHA",
"TLS_RSA_WITH_RC4_128_SHA",
"TLS_RSA_WITH_RC4_128_MD5"
)
Backup-Registry -Mode "disable"
$currentCiphers = (Get-ItemProperty -Path $regPath).Functions
$filtered = $currentCiphers | Where-Object { $_ -notin $legacySuites }
if ($filtered.Count -lt $currentCiphers.Count) {
Write-Host "❌ Rimozione cipher suite legacy: $($legacySuites -join ', ')" -ForegroundColor Red
Set-ItemProperty -Path $regPath -Name "Functions" -Value $filtered
Write-Host "✅ Cifrari legacy disabilitati." -ForegroundColor Green
} else {
Write-Host "✅ Nessun cifrario legacy da rimuovere." -ForegroundColor Green
}
}
function Show-Menu {
Clear-Host
Write-Host "╔═══════════════════════════════════════════╗"
Write-Host "║ SQL Server 2005 Legacy Cipher Tool ║"
Write-Host "╚═══════════════════════════════════════════╝"
Write-Host ""
Write-Host "1. ✅ Abilita cifrari legacy (RC4, 3DES)"
Write-Host "2. ❌ Disabilita cifrari legacy"
Write-Host "3. 🚪 Esci"
Write-Host ""
}
do {
Show-Menu
$choice = Read-Host "Seleziona un'opzione [1-3]"
switch ($choice) {
'1' { Enable-LegacyCiphers }
'2' { Disable-LegacyCiphers }
'3' { Write-Host "Uscita..." -ForegroundColor Cyan }
default {
Write-Host "❗ Scelta non valida. Riprova." -ForegroundColor Red
}
}
if ($choice -ne '3') {
Write-Host ""
Pause
}
} while ($choice -ne '3')