如何使用带有客户端证书的HTTPS传输来签署带有证书的WCF消息

Joh*_*car 5 .net ssl wcf web-services

编辑:

我终于确定IClientMessageInspector似乎没有反映消息签名,因此当我在我的请求中实际获得签名时我不知道它.所以现在我的新问题真正存在......

如何配置WCF客户端以呈现SSL客户端证书并签署SOAP头?

var myBinding = new BasicHttpBinding();
myBinding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
Run Code Online (Sandbox Code Playgroud)

这将导致标题具有已签名的时间戳.但是,客户端证书不再显示,我没有通过SSL.如果我将第二行更改为:

myBinding.Security.Mode = BasicHttpSecurityMode.Transport;
Run Code Online (Sandbox Code Playgroud)

然后我通过SSL但我的SOAP标头不再有签名块.

有什么方法可以让我得到HttpWebRequest,这样我就可以手动附加SSL客户端证书了吗?

webRequest.ClientCertificates.Add(certLoader.Load(@"c:\somecert.pfx"));
Run Code Online (Sandbox Code Playgroud)

原始问题

我正在开发一个WCF客户端,它需要与使用Forum Sentry网络设备来保护访问权限的第三方提供的服务互操作.它们需要SSL与传输级别的客户端证书以及带有签名的o:Security元素,并使用标头中的证书.我能够通过标准绑定实现其中一个或另一个,但我似乎无法同时发生这两种情况.理想情况下,他们希望使用与SSL客户端证书不同的证书签名的消息,但他们说我们可以使用相同的证书进行SSL客户端身份验证并签署消息.

此时我愿意做任何事情以使其工作,包括必要时使用CustomBinding.

我可以使用以下方法使SSL部分工作:

var myBinding = new BasicHttpBinding();
myBinding.Security.Mode = BasicHttpSecurityMode.Transport;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var url = "https://blah.com/services/somservice";
EndpointAddress ea = new EndpointAddress(url);
var client = new SoapClient(myBinding, ea);
var certLoader = new CertificateLoader("password");
client.ClientCredentials.ClientCertificate.Certificate = certLoader.Load(@"c:\somecert.pfx");
var resp = client.somemethod(ref profile, new RequestType { version = RequestTypeVersion.Item100 });
Run Code Online (Sandbox Code Playgroud)

Yar*_*veh 2

请发布一份工作肥皂样本(例如供应商提供的肥皂)。顺便说一句,还有比使用自定义绑定更剧烈的动作:)

编辑:要使用传输和消息安全性,您需要自定义绑定。Google 搜索“wcf 绑定转换器”来自动执行此操作。在自定义绑定中,将 http 元素更改为 https 并使用属性 requirevlientcertificate。抱歉拼写错误,我在移动设备上

编辑:

var c = new CustomBinding();            
MessageSecurityVersion version = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
var sec = SecurityBindingElement.CreateCertificateOverTransportBindingElement(version);
c.Elements.Add(sec);
c.Element.Add(new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.Soap11 };)
c.Elements.Add(new HttpsTransportBindingElement() { RequireClientCertificate = true });
Run Code Online (Sandbox Code Playgroud)