如何為 Microsoft 雲端應用程式和 Microsoft Entra Connect 強制實施 TLS 1.2

傳輸層安全性(TLS)1.2 是一種加密協定,旨在透過確保隱私和資料完整性來提供安全通訊。微軟已將 TLS 1.2 作為許多雲端服務的最低要求,其中包括 Microsoft Entra Connect。本文提供逐步指引,協助你為 Microsoft 雲端應用程式(包括 ASP.NET 應用程式)以及 Microsoft Entra Connect 伺服器強制實施 TLS 1.2。


為什麼 TLS 1.2 至關重要

與早期版本相比,TLS 1.2 提供了更強的加密和安全性,因此對於雲端環境中的安全通訊至關重要。Microsoft Entra Connect 1.2.65.0 及更高版本完全支援 TLS 1.2,而 2.3.20.0 或更高版本則需要 TLS 1.2 才能正常運作。

如果你的伺服器上未啟用 TLS 1.2,必須在部署或升級到 Microsoft Entra Connect 2.0 或更高版本之前先啟用它。


強制實施 TLS 1.2 的解決方案

強制實施 TLS 1.2 的步驟因所設定的應用程式或服務而異。以下是常見情境的詳細解決方案。


1. 對於 ASP.NET Web 應用程式

  • 更新目標 Framework
    確保應用程式的目標 Framework 設定為 4.6.2 或更高版本。使用更高版本可以提高效能和安全性。
  • 修改 Web.Config 檔案
    更新 Web.Config 檔案以指定目標 Framework:<system.web> <httpRuntime targetFramework="4.7.2" /> </system.web> 有關受支援的 .NET Framework 版本,請參閱 Microsoft .NET Framework 生命週期。

2. 如果無法更新 Web.Config

如果修改 Web.Config 檔案不可行,請使用以下因應方法,在應用程式開頭新增以下程式碼:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

這可確保你的應用程式明確使用 TLS 1.2 進行安全通訊。


3. 為 Microsoft Entra Connect 強制實施 TLS 1.2

Microsoft Entra Connect 伺服器必須啟用 TLS 1.2,以確保與 Azure 的安全通訊。請按以下步驟強制實施 TLS 1.2:

更新登錄檔

更新 Microsoft Entra Connect 伺服器上的登錄檔以強制實施 TLS 1.2。使用以下登錄機碼:

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319]
"SystemDefaultTlsVersions"=dword:00000001
"SchUseStrongCrypto"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319]
"SystemDefaultTlsVersions"=dword:00000001
"SchUseStrongCrypto"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server]
"Enabled"=dword:00000001
"DisabledByDefault"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client]
"Enabled"=dword:00000001
"DisabledByDefault"=dword:00000000

重要提示:更新登錄檔後,重新啟動 Windows 伺服器以使變更生效。


4. 使用 PowerShell 指令碼

檢查 TLS 1.2 設定

你可以使用以下 PowerShell 指令碼來驗證 Microsoft Entra Connect 伺服器上目前的 TLS 1.2 設定:

Function Get-ADSyncToolsTls12RegValue {
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory=$true)]
        [string] $RegPath,
        [Parameter(Mandatory=$true)]
        [string] $RegName
    )
    $regItem = Get-ItemProperty -Path $RegPath -Name $RegName -ErrorAction Ignore
    $output = "" | select Path, Name, Value
    $output.Path = $RegPath
    $output.Name = $RegName
    $output.Value = $regItem.$RegName -ne $null ? $regItem.$RegName : "Not Found"
    $output
}

$regSettings = @()
$regPaths = @(
    'HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319',
    'HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319',
    'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server',
    'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client'
)

foreach ($regPath in $regPaths) {
    $regSettings += Get-ADSyncToolsTls12RegValue $regPath 'SystemDefaultTlsVersions'
    $regSettings += Get-ADSyncToolsTls12RegValue $regPath 'SchUseStrongCrypto'
}

$regSettings

啟用 TLS 1.2

要強制實施 TLS 1.2,請使用以下 PowerShell 指令碼:

New-ItemProperty -Path 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319' -Name 'SystemDefaultTlsVersions' -Value '1' -PropertyType 'DWord' -Force | Out-Null
New-ItemProperty -Path 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -PropertyType 'DWord' -Force | Out-Null
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319' -Name 'SystemDefaultTlsVersions' -Value '1' -PropertyType 'DWord' -Force | Out-Null
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -PropertyType 'DWord' -Force | Out-Null
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server' -Name 'Enabled' -Value '1' -PropertyType 'DWord' -Force | Out-Null
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client' -Name 'Enabled' -Value '1' -PropertyType 'DWord' -Force | Out-Null
Write-Host 'TLS 1.2 has been enabled. Restart the server for changes to take effect.'

結語

強制實施 TLS 1.2 是維護與 Microsoft 雲端服務和 Azure 服務的安全通訊與合規性的關鍵一步。無論你是設定 ASP.NET 應用程式還是 Microsoft Entra Connect 伺服器,本文提供的解決方案都將協助你確保相容性和安全性。

如需了解更多資訊,請參閱微軟官方文件:

發表留言