11 安全

前言

  【1】传输安全
     传输安全模式
     传输安全与绑定协议
 
  【2】身份验证
     身份验证分类
     证书
     示例:传输安全匿名客户端证书的使用

 

1. 传输安全

   

     保证信息在传输过程中的安全.传输安全是身份验证和授权的前提。

  传输安全模式

    None:关闭了传输安全的功能
    transport security:对通道上所有的通信加密,除了接收者外,没有任何一方可以看见消息的内容。
    message security:只是对消息的本身进行加密而不是对传输进行加密。
    Mixed:在实现完整性和机密性以及服务端身份验证时采用的是Transport Security模式,而在保护客户端安全凭证的安全时采用了Message Security模式。
    Both:同是使用Transport模式和Message模式,就是传输时安全的,传输的消息也是经过加密的.

 

      配置

    传输安全模式是在绑定中配置的.

 

  binding与传输安全模式

    传输安全模式与各种binding是一个组合的关系,并不是每种binding都能应用所有的传输安全模式,

  所有WCF的绑定默认都是安全的,只有BasicHttpBinding默认是非安全的

名称

None

Transport

Message

Mixed

Both

BasicHttpBinding

Yes(默认)

Yes

Yes

Yes

No

NetTcpBinding

Yes

Yes(默认)

Yes

Yes

No

NetNamedPipeBinding

Yes

Yes(默认)

No

No

No

WSHttpBinding

Yes

Yes

Yes(默认)

Yes

No

WSDualHttpBinding

Yes

No

Yes(默认)

No

No

NetMsmqBinding

Yes

Yes(默认)

Yes

No

Yes

     配置文件的形式:

<bindings>
  <netTcpBinding>
    <binding name="tcpBinding">
      <security mode="Transport">
        <transport clientCredentialType="Windows“ 
    protectionLevel="EncryptAndSign"/>
      </security>
    </binding>
  </netTcpBinding>
</bindings>

  编程方式实现:

NetTcpBinding binding = new NetTcpBinding(SecurityMode.Transport);

  或者

NetTcpBinding binding1 = new NetTcpBinding();
binding1.Security.Mode = SecurityMode.Transport;


 

2. 身份验证

 

2.1 Transport模式的身份验证

 

  在Transport模式下,身份验证与binding的关系

    

 

名称

None

Windows

UserName

Certificate

BasicHttpBinding

Yes(默认)

Yes

Yes

Yes

NetTcpBinding

Yes

Yes(默认)

No

Yes

NetNamedPipeBinding

No

Yes(默认)

No

No

WSHttpBinding

Yes

Yes(默认)

Yes

Yes

WSDualHttpBinding

 

 

 

 

NetMsmqBinding

Yes

Yes(默认)

No

Yes

    

    所有的局域网绑定都支持Windows方式的身份验证

  NetTcpBinding在Transport模式下不支持UserName身份验证模式

  wsDualHttpBinding不支持Transport传输安全模式的

 

 2.2 Message模式的身份验证

     在Message传输安全模式下Binding与身份验证

 

 

名称

None

Windows

UserName

Certificate

IssuedToken

BasicHttpBinding

No

No

No

Yes

No

NetTcpBinding

Yes

Yes(默认)

Yes

Yes

Yes

NetNamedPipeBinding

 

 

 

 

 

WSHttpBinding

Yes

Yes(默认)

Yes

Yes

Yes

WSDualHttpBinding

Yes

Yes(默认)

Yes

Yes

Yes

NetMsmqBinding

Yes

Yes(默认)

Yes

Yes

Yes

 

    除了BasicHttpBinding和NetNamedPipeBinding以外,其他的模式默认都是用Windows凭证

 

    示例:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBinding_Security">
          <security mode="Transport">
            <transport clientCredentialType="None"/><!--启用传输安全,身份认证是匿名的-->
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="Keasy5.WCF.Security.Translation.Service1">
        <host>
          <baseAddresses>
            <!--Http和SSL 两者要成对-->
            <add baseAddress = "http://localhost:8733/Design_Time_Addresses/Keasy5.WCF.Security.Translation/Security/" />
            <add baseAddress = "https://localhost:8833/Design_Time_Addresses/Keasy5.WCF.Security.Translation/Security/" />
          </baseAddresses>
        </host>
        <endpoint address="" 
                  binding="wsHttpBinding" 
                  bindingConfiguration="wsHttpBinding_Security"
                  contract="Keasy5.WCF.Security.Translation.IService1">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>
View Code

相关文章:

  • 2021-10-03
  • 2021-05-29
  • 2022-12-23
  • 2021-07-28
  • 2021-08-06
  • 2021-08-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-20
  • 2021-05-29
  • 2021-07-05
  • 2021-07-24
相关资源
相似解决方案