c# - SOAP WCF 将 Signature 和 BinarySecurityToken 添加到标头
问题描述
我需要更多东西,签名必须在 Header 标记内的 Security 标记内,并带有 BinarySecurityToken 元素
就像:
<soapenv:Header> <!-- extrac of the example file -->
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu=" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="X509-D53CCD6983E4CE0BD7142791021078262">
MIIDbDgg4iF74cqiF6NcnzBnD9qA2MB6hSo38e0RISilEFSzWikDqBtOjgm7ux9fdeHojDm4uvhsSfbEyGmGTAQRzg9yIiD3ovjOzuZsf+I3HWS9F6xl6sb2+wvYXD4DFk/OD+N7UszGsoWFZg
</wsse:BinarySecurityToken>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
.....
</ds:Signature>
我可以直接从客户端证书以编程方式填充 xml 元素,如下所示:
var cert = new X509Certificate2(ClientCertificateFilePath, ClientCertificatePassword);
var export = cert.Export(X509ContentType.Cert, ClientCertificatePassword);
var base64 = Convert.ToBase64String(export);
问题是如何将 Signature 和 BinarySecurityToken 添加到标头?
解决方案
手动编写 SOAP 信封来调用服务可能是一种选择。
以下是有关如何添加 SOAP 标头的一些讨论。
什么是 C# WCF AddressHeader 的 Java Apache CXF 等价物?
这通常是因为服务器端的Web服务不是WCF,因此我们可能无法通过WCF调用服务。
在我看来,上述 SOAP 信封格式决定了 WCF 使用的绑定的通道形状,这可能与使用证书对客户端进行身份验证的 WCF 服务兼容。
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
当服务器使用证书对客户端进行身份验证时,客户端使用相同的绑定类型并向服务器提供证书,并在 SOAP 信封中附加证书的签名。下面是 Fiddler 捕获的与服务器端通信时的 Http 流量。他们的肥皂信封是相似的。
有关使用证书对客户端进行身份验证的更多信息,请参阅以下链接。https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/message-security-with-a-certificate-client https://docs.microsoft.com/en-us/dotnet /framework/wcf/feature-details/transport-security-with-certificate-authentication
如果有什么我可以帮忙的,请随时告诉我。
推荐阅读
- google-apps-script - 如何为每一行创建一个电子表格,并在 Google Apps 脚本中导入整行?
- python - 如何在 Python 中检查多个按键?(键盘模块)
- android - 如何为 Android 实现 BottomAppBar?
- go - 为什么我在此 libp2p 代码中收到类型错误?
- python - Python Flask - WTF SelectField 数据导致错误_mysql_exceptions.ProgrammingError
- c++ - VSCode c++ task.json 包含路径和库
- python - Tensorflow 错误获取参数
必须是字符串或张量 - php - 如何按点对这个多维数组进行排序?
- python - NetworkX g.neighbors(n) 时间复杂度
- android - 用于firestore的最小android api?