首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> 關於.NET

WCF 安全實戰系列(二):NetTcpBinding Transport 安全模式完整實測與 TLS over TCP 實作細節

     編輯:關於.NET

NetTcpBinding 傳輸安全架構回顧

NetTcpBinding 以 TCP 為傳輸層,安全模式分三類:

  • Message:WS-* 訊息層安全,需服務端憑證。
  • Transport - Windows:Windows Security 保護傳輸層,無需憑證。
  • Transport - 其他:TLS over TCP,需服務端憑證。TLS 為 SSL 標準化後版本,雜湊演算法不同。

測試環境:服務端 Win2008 (VS2008, .NET 3.5, IIS 7.0),客戶端同機與 Win2003 另一台。採自宿主 Console、程式碼配置。

共用服務合約

[ServiceContract(Namespace = "https://chnking.com")]
public interface IGetIdentity
{
    [OperationContract]
    string Get(string ClientIdentity);
}
public class GetIdentity : IGetIdentity
{
    public string Get(string ClientIdentity)
    {
        return "服務端Identity是'" + ServiceSecurityContext.Current.PrimaryIdentity.Name +
               "'\r\n客戶端Identity是 '" + ClientIdentity + "'";
    }
}

1. 安全模式:None

無加密、無驗證,Binary 編碼明文可見。適合受信任內網效能測試。

None 模式執行結果

TcpTrace 擷取明文封包

2. 安全模式:Transport

2.1 客戶端驗證:Windows(預設最推薦)

Windows Security 直接保護 TCP 連線,提供完整性、機密性、雙向驗證。程式碼僅需設定 SecurityMode.Transport 與 TcpClientCredentialType.Windows。封包經加密,Binary 內容不可讀。

Transport Windows 結果

加密後封包

2.2 客戶端驗證:None(TLS over TCP)

需服務端憑證建立 TLS 通道,客戶端匿名。產生憑證:makecert -sr localmachine -ss My -n CN=win2008 -sky exchange -pe -r。服務端與客戶端皆設定 TcpClientCredentialType.None 並指定服務端憑證;客戶端略過憑證驗證。

Transport None 結果

TLS 加密封包

2.3 客戶端驗證:Certificate(雙向 TLS)

服務端憑證建立 TLS,客戶端憑證互相驗證。雙方各需憑證:伺服器 CN=win2008,客戶端 CN=TestClient。服務端關閉客戶端憑證驗證模式;客戶端指定自身憑證並略過伺服器驗證。

Transport Certificate 結果

2.3.5 憑證映射至 Windows 帳號

同 Message 模式,啟用 MapClientCertificateToWindowsAccount 後,需在 AD 環境配置映射:

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved