NetTcpBinding 內部透過 NetTcpSecurity 類別掌控安全模式與細節。本節剖析其類別結構、建構函式與預設屬性值,為後續實戰奠定理論基礎。
NetTcpBinding() — 預設初始化NetTcpBinding(SecurityMode) — 指定安全模式NetTcpBinding(String) — 從配置名稱初始化NetTcpBinding(SecurityMode, Boolean) — 指定安全模式與是否啟用安全會話public sealed class NetTcpSecurity {
internal const SecurityMode DefaultMode = SecurityMode.Transport;
public NetTcpSecurity();
public MessageSecurityOverTcp Message { get; set; }
public SecurityMode Mode { get; set; }
public TcpTransportSecurity Transport { get; set; }
}
關鍵點:靜態欄位 DefaultMode = SecurityMode.Transport 確認預設即為傳輸安全。
public sealed class TcpTransportSecurity {
internal const TcpClientCredentialType DefaultClientCredentialType = TcpClientCredentialType.Windows;
internal const ProtectionLevel DefaultProtectionLevel = ProtectionLevel.EncryptAndSign;
[DefaultValue(1)]
public TcpClientCredentialType ClientCredentialType { get; set; }
public ExtendedProtectionPolicy ExtendedProtectionPolicy { get; set; }
[DefaultValue(2)]
public ProtectionLevel ProtectionLevel { get; set; }
}
| 屬性 | 預設值 | 說明 |
|---|---|---|
| ClientCredentialType | Windows | 客戶端身分驗證憑證類型 |
| ProtectionLevel | EncryptAndSign | 訊息保護等級:加密並簽名 |
| ExtendedProtectionPolicy | None | TCP 延伸保護策略(防禦認證轉發攻擊) |
掌握
NetTcpSecurity → TcpTransportSecurity這條屬性鏈,即能精準控制 WCF TCP 傳輸的每一項安全細節。
本文部分內容改編自《.NET 安全揭秘》
作者:玄魂
出處:https://www.cnblogs.com/xuanhun/