简介: 我正在使用SOAP 1.1和WS-Security 1.0在.NET 4.0 WCF客户端上使用Web服务(另一端是DataPower,Java服务).WCF客户端必须在传输层实现客户端证书以进行相互身份验证.需要使用单独的服务/签名证书对邮件正文进行签名.SOAP标头还需要包含带有密码摘要的用户名令牌,并包含Nonce和Created标签.
我可以使用带有BasicHTTPBinding的WSE 3.0来使用这个Web服务.但到目前为止,我还没有使用WSHttpBinding或CustomBinding在WCF中实现相同的功能.我已经尝试了所有的安全绑定元素,到目前为止没有运气.
我也在这里使用usernametoken库(http://blogs.msdn.com/b/aszego/archive/2010/06/24/usernametoken-profile-vs-wcf.aspx)所以我可以添加密码摘要/ nonce /在SOAP标头中的UsernameToken中创建.
我目前正在使用SecurityBindingElement.CreateMutualCertificateBindingElement我还尝试了其他几个,如AsymmetricSecurityBindingElement,TransportSecurityBindingElement等(在下面的代码中注释掉)
CERTS: 我使用MMC将客户端证书和服务证书加载到证书存储区中(我在Windows 7上运行.)客户端证书和服务证书都有私钥.我已将PFX文件加载到LocalMachine/Personal,LocalMachine/Root和LocalMachine/TrustedPeople中.我还运行FindPrivateKey/ICACLS以授予"IIS App Pool/DefaultAppPool"帐户的权限.虽然这一点都不重要,因为我可以从我的机器运行WSE 3.0代码,但它没有任何证书问题.
命令运行:
FindPrivateKey.exe My LocalMachine -t "thumbprint of client cert"
FindPrivateKey.exe My LocalMachine -t "thumbprint of service cert"
icacls C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys\{privateKeyOfClientCert} /grant "IIS AppPool\DefaultAppPool":R <<Successfully processed 1 files; Failed processing 0 files>>
icacls C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys\{privateKeyOfServiceCert} /grant "IIS AppPool\DefaultAppPool":R <<Successfully processed 1 files; Failed processing 0 files>>
Run Code Online (Sandbox Code Playgroud)
WCF问题: 我目前从DataPower网关收到"无法为具有权限'xxcom'的SSL/TLS建立安全通道"消息.我想这可能是因为网关正在获取服务证书并使用它来进行客户端身份验证,而不是使用我发送的客户端证书.我这样说是因为当我没有为端点指定DNS标识时,我收到一条消息,说网关期望DNS标识为"{subject name of service/signing certificate}".
这是WCF生成的SOAP请求,它给出了上述错误.WCF SOAP请求看起来与WSE SOAP请求非常相似.由于SSL /传输层的证书问题,最有可能发生上述错误.
WCF SOAP请求:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<o:Security …Run Code Online (Sandbox Code Playgroud)