博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WCF NetTcpBinding Transport安全模式(3) ProtectionLevel设置保护级别
阅读量:7237 次
发布时间:2019-06-29

本文共 2645 字,大约阅读时间需要 8 分钟。

WCF NetTcpBinding Transport安全模式(3)    ProtectionLevel设置保护级别

书接上文,是哪一项配置使得WCF对传输消息进行加密操作了呢?继续修改配置文件,客户端配置文件如代码清单11-18所示,服务端配置文件如代码清单11-19所示。

代码清单11-18  修改客户端protectionLevel

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

<configuration>

  <system.serviceModel>

    <behaviors >

      <endpointBehaviors>

        <behavior  name="ForListen">

          <clientVia viaUri="net.tcp://127.0.0.1:64590/HelloService"/>

        </behavior>

      </endpointBehaviors>

    </behaviors>

    <bindings>

     

 

      <netTcpBinding>

        <binding name="tcpWindowsSecurity">

          <security mode="Transport" >

    <transport protectionLevel="None"></transport>

          </security>

        </binding>

      </netTcpBinding>

    </bindings>

    <client>

      <endpoint name="helloEndPoint" address="net.tcp://127.0.0.1:64567/HelloService" 

          binding="netTcpBinding" bindingConfiguration="tcpWindowsSecurity"

          contract="WcfSecurityExampleServiceLibrary.IHelloService" behaviorConfiguration="ForListen" />

    </client>

  </system.serviceModel>

 

</configuration>

代码清单11-19    修改服务端端protectionLevel

<?xml version="1.0"?>

<configuration>

 

  <system.serviceModel>

    <services>

      <service name="WcfSecurityExampleServiceLibrary.HelloService" behaviorConfiguration="mex">

        <host>

          <baseAddresses>

            <add baseAddress="net.tcp://127.0.0.1:64567/"/>

          </baseAddresses>

        </host>

        <endpoint address="net.tcp://127.0.0.1:64567/HelloService" binding="netTcpBinding"

                  bindingConfiguration="tcpWindowsSecurity" name="helloEndPoint"

                  contract="WcfSecurityExampleServiceLibrary.IHelloService"/>

   

 

        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />

      </service>

    </services>

    <bindings>

 

      <netTcpBinding>

        <binding name="tcpWindowsSecurity">

         <security mode="Transport" >

    <transport protectionLevel="None"></transport>

         </security

        </binding>

      </netTcpBinding>

    </bindings>

 

    <behaviors>

      <serviceBehaviors>

        <behavior name="mex">

          <serviceMetadata  />

        </behavior>

      </serviceBehaviors>

    </behaviors>

  </system.serviceModel>

 

  <startup>

    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>

  </startup>

</configuration>

通过以上两段代码,Transport安全模式下protectionLevel设置为None。此时运行结果和TcpTrace结果如图11-8所示。

图11-8    protectionLevelNone监听结果

从图11-8结果看,

protectionLevel为None时WCF不提供对消息的机密性的保证。

说明:PROTECTIONLEVEL为NONE时,通信的完整性也得不到保证。

protectionLevel修改为Sign,看运行结果有何不同,如图11-9所示。

图11-9         protectionLevelSign运行结果

从图11-9结果来看,protectionLevelSign时没有对数据进行加密,结果和protectionLevelNone时没有什么差异。事实上,当protectionLevelSign时,虽然不对数据做加密处理,但是会对数据完整性做校验。实现方式是为消息添加一个加密校验和,当接收到消息后,会对消息重新计算校验和并和客户端附加校验和进行比较,如果不同请求会被拒绝。

protectionLevel第三种选项为EncryptAndSign,也是Transport安全模式下默认安全级别。在此种安全级别下,WCF既提供完整性校验又提供消息加密。

 ----------------------------注:本文部分内容改编自《.NET 安全揭秘》

本文转自玄魂博客园博客,原文链接:http://www.cnblogs.com/xuanhun/archive/2012/06/24/2560061.html,如需转载请自行联系原作者
你可能感兴趣的文章
[LeetCode] Word Break II
查看>>
两句话解决代理问题
查看>>
熊市中,值得关注的项目都有这三大特征
查看>>
2018.12.27-dtoj-4089-line
查看>>
10:比较整数大小经典案例
查看>>
ES06--elasticsearch
查看>>
pytorch1.0 用torch script导出模型
查看>>
数据结构(九)查找
查看>>
JAVA常用的集合类
查看>>
Unity3D MainCamera和NGUI UICamera的小插曲
查看>>
gnuWin32-mini-2016.10.30
查看>>
Cassandra博客更新预告
查看>>
Linux 格式化和挂载数据盘
查看>>
mybatis 中 prefix="" suffixOverrides="," prefixOverrides="" suffix=""
查看>>
分类算法三(贝叶斯)
查看>>
栈 后缀表达式
查看>>
笔记:2016-6-17
查看>>
动态SQL番外篇
查看>>
项目中数据库超时设置整理
查看>>
boot和settlement日志在不断加大,需要清理
查看>>