[WCF安全係列]綁定、安全模式與客戶端憑證類型:NetNamedPipeBinding、NetTcpBinding與NetMsmqBinding
在前麵兩篇(《綁定、安全模式與客戶端憑證類型:BasicHttpBinding》和《綁定、安全模式與客戶端憑證類型:WSHttpBinding與WSDualHttpBinding》)中,我們詳細地介紹了四種基於HTTP的綁定分別支持的安全模式,已經在相應的安全模式下可以采用怎樣的客戶端憑證。在本篇文章中,我們安全線相同的方式來介紹三種基於局域網的綁定,即NetNamedPipeBinding、NetTcpBinding與 NetMsmqBinding。
NetNamedPipeBinding隻能用於同一台機器上的不同進程之間的通信(IPC:Inter-Process Communication)。在IPC這樣的通信場景下,根本不需要基於Message模式的安全。所以在表示NetNamedPipeBinding安全的NetNamedPipeSecurity類型中,表示支持的安全模式的Mode屬性對應的NetNamedPipeSecurityMode枚舉僅僅具有兩個選項:None和Transport。在默認的情況下,NetNamedPipeBinding采用Transport安全模式。
此外還有一點值得一提:表示Transport模式安全的NamedPipeTransportSecurity類並不存在ClientCredentialType屬性,因為它。NetNamedPipeBinding安全相關的應用編程接口如下麵的代碼片斷所示。
1: public class NetNamedPipeBinding : Binding, IBindingRuntimePreferences
2: {
3: //其他成員
4: public NetNamedPipeSecurity Security { get; set; }
5: }
6: public sealed class NetNamedPipeSecurity
7: {
8: //其他成員
9: public NetNamedPipeSecurityMode Mode { get; set; }
10: public NamedPipeTransportSecurity Transport { get; set; }
11: }
12: public enum NetNamedPipeSecurityMode
13: {
14: None,
15: Transport
16: }
17: public sealed class NamedPipeTransportSecurity
18: {
19: //不存在ClientCredentialType屬性
20: }
較之NetNamedPipeBinding,NetTcpBinding涉及安全相關的定義就要複雜一些。Security屬性返回的是一個用於設置NetTcpBinding安全的NetTcpSecurity對象。表示安全模式的NetTcpSecurity的Mode屬性返回的是我們提到過的SecurityMode枚舉,意味著,即None、Transport、Message和Mixed(TransportWithMessageCredential)。。
NetTcpSecurity的Transport屬性返回的是一個用於進行Transport安全設置的TcpTransportSecurity類型對象。TcpTransportSecurity的ClientCredentialType屬性以TcpClientCredentialType枚舉的形式表示采用的客戶端憑證類型。定義在TcpClientCredentialType中的三個枚舉值表示NetTcpBinding在Transport模式下支持的所有客戶端憑證類型:None、Windows和Certificate。。
而通過Message屬性返回的用於進行Message安全設置的則是一個MessageSecurityOverTcp類型對象。MessageSecurityOverTcp用於表示客戶端憑證類型的ClientCredentialType屬性的依然是MessageCredentialType,意味著NetTcpBinding和上述的三個WS綁定在Message模式下,具有相同的客戶端憑證集。在默認的情況下,NetTcpBinding采用Windows憑證。NetTcpBinding安全相關的應用編程接口如下麵的代碼片斷所示。
1: public class NetTcpBinding : Binding, IBindingRuntimePreferences
2: {
3: //其他成員
4: public NetTcpSecurity Security { get;set}
5: }
6: public sealed class NetTcpSecurity
7: {
8: //其他成員
9: public SecurityMode Mode { get; set; }
10: public TcpTransportSecurity Transport { get; set; }
11: public MessageSecurityOverTcp Message { get; set; }
12: }
13: public sealed class TcpTransportSecurity
14: {
15: //其他成員
16: public TcpClientCredentialType ClientCredentialType { get; set; }
17: }
18: public sealed class MessageSecurityOverTcp
19: {
20: //其他成員
21: public MessageCredentialType ClientCredentialType { get; set; }
22: }
23: public enum TcpClientCredentialType
24: {
25: None,
26: Windows,
27: Certificate
28: }
NetMsmqBinding的Security屬性的類型為NetMsmqSecurity。而表示NetMsmqBinding采用的安全模式的Mode屬性返回一個NetMsmqSecurityMode枚舉。NetMsmqSecurityMode枚舉的定義反映了NetMsmqBinding支持的安全模式集與其它係統定義綁定都不太一樣。定義在NetMsmqSecurityMode的四個枚舉值反映了NetMsmqBinding支持的四種安全模式:None、Transport、Message和Both。
首先,。這種模式意味中同時采用Transport和Message,就像是加上了雙保險。有人可能會提出這樣的問題:如果同時采用Transport和Message兩種模式,性能豈不是會變得很差?但是,由於MSMQ總是采用一種單向(One-Way)或者異步的消息發送機製,對性能並沒有太高的要求。此外,(TransportWithMessageCredential)。。
通過NetMsmqSecurity的Transport屬性返回的用於進行Transport安全設置的是一個類型為MsmqTransportSecurity的對象。和NetNamedPipeBinding類似,。這是因為。而通過用於進行Message安全設置的Message屬性對應的類型為MessageSecurityOverMsmq。MessageSecurityOverMsmq具有一個類型為MessageCredentialType的ClientCredentialType屬性。NetMsmqSecurity安全相關的應用編程接口定義反映在下麵的代碼片斷中。
1: public class NetMsmqBinding : MsmqBindingBase
2: {
3: //其他成員
4: public NetMsmqSecurity Security {get; set; }
5: }
6: public sealed class NetMsmqSecurity
7: {
8: //其他成員
9: public NetMsmqSecurityMode Mode { get; set; }
10: public MsmqTransportSecurity Transport { get; set; }
11: public MessageSecurityOverMsmq Message { get; set; }
12: }
13: public enum NetMsmqSecurityMode
14: {
15: None,
16: Transport,
17: Message,
18: Both
19: }
20: public sealed class MsmqTransportSecurity
21: {
22: //不存在ClientCredentialType屬性
23: }
24:
25: public sealed class MessageSecurityOverMsmq
26: {
27: //其他成員
28: public MessageCredentialType ClientCredentialType {get; set; }
29: }
微信公眾賬號:大內老A
微博:www.weibo.com/artech
如果你想及時得到個人撰寫文章以及著作的消息推送,或者想看看個人推薦的技術資料,可以掃描左邊二維碼(或者長按識別二維碼)關注個人公眾號(原來公眾帳號蔣金楠的自媒體將會停用)。
本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁麵明顯位置給出原文連接,否則保留追究法律責任的權利。
最後更新:2017-10-27 11:03:54