

第 4 版 (V4) 適用於 .NET 的 AWS SDK 已發行！

如需有關中斷變更和遷移應用程式的資訊，請參閱[遷移主題](https://docs.aws.amazon.com/sdk-for-net/v4/developer-guide/net-dg-v4.html)。

 [https://docs.aws.amazon.com/sdk-for-net/v4/developer-guide/net-dg-v4.html](https://docs.aws.amazon.com/sdk-for-net/v4/developer-guide/net-dg-v4.html)

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 中強制執行最低 TLS 版本 適用於 .NET 的 AWS SDK
<a name="enforcing-tls"></a>

若要在與 AWS 服務通訊時提高安全性，您應該 適用於 .NET 的 AWS SDK 將 設定為使用 TLS 1.2 或更新版本。

 適用於 .NET 的 AWS SDK 使用基礎 .NET 執行期來決定要使用的安全通訊協定。根據預設，.NET 的目前版本會使用作業系統支援之最新設定的通訊協定。應用程式可覆寫此開發套件行為，但「不建議」**這麼做。

## .NET Core
<a name="enforcing-tls-dotnet-core"></a>

根據預設，.NET Core 會使用作業系統支援之最新設定的通訊協定。 適用於 .NET 的 AWS SDK 未提供覆寫此行為的機制。

如果您是使用比 2.1 更舊的 .NET Core 版本，「強烈」**建議您升級 .NET Core 版本。

請參閱下列各個作業系統的特定資訊。

**Windows**

Windows 的現代化分發會[依預設啟用](https://learn.microsoft.com/en-us/windows/win32/secauthn/protocols-in-tls-ssl--schannel-ssp-) TLS 1.2 支援。如果您在 Windows 7 SP1 或 Windows Server 2008 R2 SP1 上執行 ，則需要確保已在登錄檔中啟用 TLS 1.2 支援，如 https：//[https://learn.microsoft.com/en-us/windows-server/security/tls/tls-registry-settings\$1tls-12](https://learn.microsoft.com/en-us/windows-server/security/tls/tls-registry-settings#tls-12) 所述。如果執行的是較舊的分發，則必須升級作業系統。如需有關 Windows 中 TLS 1.3 支援的資訊，請查看最新的 Microsoft 文件，了解最低必要用戶端或伺服器版本。

**macOS **

如果執行的是 .NET Core 2.1 或更新版本，會依預設啟用 TLS 1.2。[OS X Mavericks v10.9 或更新版本支援 TLS 1.2。](https://support.apple.com/en-us/103373).NET Core 2.1 版和更新版本需要更新版本的 macOS，如 https：//[https://learn.microsoft.com/en-us/dotnet/core/install/windows 所述？tab=net80&pivots=os-macos](https://learn.microsoft.com/en-us/dotnet/core/install/windows?tabs=net80&pivots=os-macos)。

如果您使用的是 .NET Core 1.0，.NET Core 會[在 macOS 上使用 OpenSSL](https://github.com/dotnet/announcements/issues/21)，這是必須另外安裝的相依項目。OpenSSL 在 1.0.1 版中新增了對 TLS 1.2 的支援，並在 1.1.1 版中新增了對 TLS 1.3 的支援。

**Linux**

Linux 上的 .NET Core 需要使用許多 Linux 分發隨附綁定的 OpenSSL，但也可以另外個別安裝。OpenSSL 在 1.0.1 版中新增了對 TLS 1.2 的支援，並在 1.1.1 版中新增了對 TLS 1.3 的支援。如果您是使用 .NET Core 的現代化版本 (2.1 或更新版本)，且已安裝套件管理員，可能已為您安裝 OpenSSL 更現代化的版本。

若要確認，您可以在終端機視窗中執行 **`openssl version`**，然後驗證版本確實比 1.0.1 更新。

## .NET Framework
<a name="enforcing-tls-dotnet-framework"></a>

如果您執行的是 .NET Framework 的現代化版本 (4.7 或更新版本) 以及 Windows 的現代化版本 (至少是適用於用戶端的 Windows 8、適用於伺服器的 Windows Server 2012 或更新版本)，會依預設啟用並使用 TLS 1.2。

如果您使用的是未使用作業系統設定的 .NET Framework 執行期 (.NET Framework 3.5 到 4.5.2)， 適用於 .NET 的 AWS SDK 會嘗試將 [TLS 1.1 和 TLS 1.2 的支援新增至](https://github.com/aws/aws-sdk-net/blob/main/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/AmazonSecurityProtocolManager.cs)支援的通訊協定。如果您使用的是 .NET Framework 3.5，這只有在已安裝適當的熱修補程式時才會成功，如下所示：
+ Windows 10 版本 1511 和 Windows Server 2016 – [KB3156421](https://support.microsoft.com/kb/3156421)
+ Windows 8.1 和 Windows Server 2012 R2 – [KB3154520](https://support.microsoft.com/kb/3154520)
+ Windows Server 2012 – [KB3154519](https://support.microsoft.com/kb/3154519)
+ Windows 7 SP1 和 Server 2008 R2 SP1 – [KB3154518](https://support.microsoft.com/kb/3154518)

**警告**  
2024 年 8 月 15 日， 適用於 .NET 的 AWS SDK 已結束對 .NET Framework 3.5 的支援，並將最低 .NET Framework 版本變更為 4.7.2。如需詳細資訊，請參閱部落格文章 [.NET Framework 3.5 和 4.5 目標的重要變更 適用於 .NET 的 AWS SDK](https://aws.amazon.com/blogs/developer/important-changes-coming-for-net-framework-3-5-and-4-5-targets-of-the-aws-sdk-for-net/)。

如果您的應用程式在 Windows 7 SP1 或 Windows Server 2008 R2 SP1 上較新的 .NET Framework 上執行，您需要確保已在登錄檔中啟用 TLS 1.2 支援，如 https：//[https://learn.microsoft.com/en-us/windows-server/security/tls/tls-registry-settings\$1tls-12](https://learn.microsoft.com/en-us/windows-server/security/tls/tls-registry-settings#tls-12) 所述。Windows 更新版本會[依預設啟用](https://learn.microsoft.com/en-us/windows/win32/secauthn/protocols-in-tls-ssl--schannel-ssp-)該支援。

如需搭配 .NET Framework 使用 TLS 的詳細最佳實務，請參閱 Microsoft 文章，網址為 https：//[https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls](https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls)。

## AWS Tools for PowerShell
<a name="enforcing-tls-ps"></a>

[AWS Tools for PowerShell](https://docs.aws.amazon.com/powershell/latest/userguide/) 使用 適用於 .NET 的 AWS SDK 進行對 AWS 服務的所有呼叫。環境的行為取決於執行的 Windows PowerShell 版本，如下所示。

**經由 5.x 的 Windows PowerShell 2.0**

經由 5.x 的 Windows PowerShell 2.0 可在 .NET Framework 上執行。您可以使用下列命令，驗證 PowerShell 使用的是哪個 .NET 執行時間 (2.0 或 4.0)。

```
$PSVersionTable.CLRVersion
```
+ 若使用 .NET 執行時間 2.0，請按照上述有關 適用於 .NET 的 AWS SDK 和 .NET Framework 3.5 的指示進行。
**警告**  
2024 年 8 月 15 日， 適用於 .NET 的 AWS SDK 已結束對 .NET Framework 3.5 的支援，並將最低 .NET Framework 版本變更為 4.7.2。如需詳細資訊，請參閱部落格文章 [.NET Framework 3.5 和 4.5 目標的重要變更 適用於 .NET 的 AWS SDK](https://aws.amazon.com/blogs/developer/important-changes-coming-for-net-framework-3-5-and-4-5-targets-of-the-aws-sdk-for-net/)。
+ 若使用 .NET 執行時間 4.0，請按照上述有關 適用於 .NET 的 AWS SDK 和 .NET Framework 4\$1 的指示進行。

**Windows PowerShell 6.0**

Windows PowerShell 6.0 和更新版本會在 .NET Core 上執行。您可以執行下列命令，驗證 .NET Core 使用的是哪個版本。

```
[System.Reflection.Assembly]::GetEntryAssembly().GetCustomAttributes([System.Runtime.Versioning.TargetFrameworkAttribute], $true).FrameworkName
```

請遵循先前提供的有關 適用於 .NET 的 AWS SDK 和相關 .NET Core 版本的指示。

## Xamarin
<a name="enforcing-tls-xamarin"></a>

如需 Xamarin，請參閱 https：//[https://learn.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/transport-layer-security](https://learn.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/transport-layer-security)。綜上所述：

**適用於 Android**
+ 需要 Android 5.0 或更新版本。
+ **Project Properties (專案屬性)**、**Android Options (Android 選項)**：HttpClient 實作必須設為 **Android** 且 SSL/TLS 實作必須設為 **Native TLS 1.2\$1 (原生 TLS 1.2\$1)**。

**適用於 iOS**
+ 需要 iOS 7 或更新版本。
+ **Project Properties (專案屬性)**、**iOS Build (iOS 組建)**：HttpClient 實作必須設為 **NSUrlSession**。

**適用於 macOS**
+ 需要 macOS 10.9 或更新版本。
+ **Project Options (專案選項)**、**Build (組建)**、**Mac Build (Mac 組建)**：HttpClient 實作必須設為 **NSUrlSession**。

## Unity
<a name="enforcing-tls-unity"></a>

您必須使用 Unity 2018.2 或更新版本，並使用等同於 .NET 4.x 的指令碼編寫執行時間。您可以在 **Project Settings (專案設定)**、**Configuration (組態)**、**Player (播放器)** 中設定此選項，如 [https://docs.unity3d.com/2019.1/Documentation/Manual/ScriptingRuntimeUpgrade.html](https://docs.unity3d.com/2019.1/Documentation/Manual/ScriptingRuntimeUpgrade.html) 所述。等同於 .NET 4.x 的指令碼編寫執行時間會對執行 Mono or IL2CPP 的所有 Unity 平台啟用 TLS 1.2 支援。

## 瀏覽器 (適用於 Blazor WebAssembly)
<a name="enforcing-tls-browser"></a>

WebAssembly 會在瀏覽器 (而不是伺服器) 中執行，並使用瀏覽器來處理 HTTP 流量。因此，TLS 支援是取決於瀏覽器支援。

ASP.NET Core 3.1 預覽版的 Blazor WebAssembly 僅支援支援 WebAssembly 的瀏覽器，如 https：//[https://learn.microsoft.com/en-us/aspnet/core/blazor/supported-platforms](https://learn.microsoft.com/en-us/aspnet/core/blazor/supported-platforms) 所述。所有主流瀏覽器在支援 WebAssembly 之前均已支援 TLS 1.2。如果您瀏覽器的情況是像這樣，則在應用程式執行時，該應用程式就能透過 TLS 1.2 進行通訊。

若要取得詳細資訊並進行確認，請參閱瀏覽器的文件。