【问题标题】:Encrypting custom header - WCF - WSHttpBinding - Message Security加密自定义标头 - WCF - WSHttpBinding - 消息安全
【发布时间】:2019-07-29 08:57:07
【问题描述】:

我有一个WCF 服务,它在WSHttpBinding 中配置,使用security mode="Message"clientCredentialType="None"。我在BeforeSendRequest 上使用IClientMessageInspector 添加自定义MessageHeader,我还想对其进行加密。可能吗?

编辑: 目前我已经添加了一个自定义的不对称引擎,它正在加密,使用以下获得的证书:

 <behaviors>
  <endpointBehaviors>
    <behavior>
      <clientCredentials>
        <serviceCertificate>
          <authentication certificateValidationMode="Custom" customCertificateValidatorType="CustomCertificateValidator.CustomCertificateValidator, CustomCertificateValidator"/>
        </serviceCertificate>
      </clientCredentials>
    </behavior>
  </endpointBehaviors>
</behaviors>

和解密(在服务器上通过指纹找到的证书)特定值,就在将它们写入/读取到/从标头之前。这是一个好方法吗?能不能做得更好?

【问题讨论】:

    标签: wcf security encryption header


    【解决方案1】:

    这可以通过指定服务证书来完成。默认情况下,使用 Windows 凭据实现消息安全。

    WSHttpBinding binding = new WSHttpBinding();
                binding.Security.Mode = SecurityMode.Message;
                binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
    

    所以我们只需要指定一个用于加密和签名的服务证书。

    using (ServiceHost sh = new ServiceHost(typeof(MyService)))
    {
        sh.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "cbc81f77ed01a9784a12483030ccd497f01be71c");
    
        sh.Open();
        Console.WriteLine("Service is ready....");
    
        Console.ReadLine();
        sh.Close();
    }
    

    结果。
    如果有什么可以帮助的,请随时告诉我。

    【讨论】:

    • 我认为,我正在使用服务证书(由行为添加),请查看我的 web.config 的一部分,如果我错了,请告诉我:
    • 好的,只要将服务行为添加到服务部分就可以了。
    • 我已经添加了它,但标题仍未加密 - 当我通过 WireShark 查看通信时,我可以看到未加密的标题
    • 在网上找了很久,似乎没有解决方案来完成对SOAP消息头的加密。无论我使用哪种安全模式,SOAP 消息头都无法加密。
    • 请参考我搜索到的以下链接,希望对您有所帮助。 social.msdn.microsoft.com/Forums/vstudio/en-US/…oipapio.com/question-407977
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多