【发布时间】:2013-09-20 15:07:51
【问题描述】:
我正在从事一个大型项目,该项目广泛使用 WCF 进行不同类型的通信。作为新需求的一部分,我们需要与第三方开发的 SOAP Web 服务进行通信。他们的服务是用 Java 开发的,有两个安全要求:
它需要 BASIC 身份验证通过传输和
消息必须使用 WS-Security (OASIS) 标准使用 X509 证书签名(未加密),以实现不可否认性。 p>
我遇到的问题是 WCF 提供的绑定允许使用传输或消息安全,但不能同时使用两者。因此,我可以对 SOAP 消息进行签名,也可以发送 BASIC 身份验证凭据,但到目前为止,我还不能按照我的要求进行这两项操作。
几天来我一直在尝试寻找解决方案,到目前为止,我得出的结论是,我最好的办法可能是以编程方式进行自定义绑定。使用多个来源,这就是我现在所拥有的:
var b = new CustomBinding();
var sec = (AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10);
UserNameSecurityTokenParameters tokenParamenters = new UserNameSecurityTokenParameters();
tokenParamenters.InclusionMode = SecurityTokenInclusionMode.AlwaysToRecipient;
tokenParamenters.RequireDerivedKeys = false;
b.Elements.Add(sec);
b.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8));
b.Elements.Add(new HttpsTransportBindingElement());
WSClient svc = new WSClient(b, new EndpointAddress(new Uri("https://serviceurl.com/SoapWS"), new DnsEndpointIdentity("CertificateIdentity"), new AddressHeaderCollection()));
svc.ClientCredentials.UserName.UserName = "username";
svc.ClientCredentials.UserName.Password = "password";
svc.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2("Certificate.p12", "password");
svc.ClientCredentials.ServiceCertificate.DefaultCertificate = new X509Certificate2("Certificate.p12", "password");
svc.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
string resp = svc.DoSomething();
虽然这似乎是在使用证书对消息进行签名(无法完全检查),但基本身份验证部分并未发生。来自服务器的响应是:
HTTP 请求未经客户端身份验证方案“匿名”授权。从服务器收到的身份验证标头是 'Basic realm="realm"'。
任何关于我如何让这个绑定通过 BASIC 身份验证在传输上进行身份验证的见解都会非常有帮助。提前致谢。
PS:请注意,我无法控制我尝试与之通信的网络服务。
【问题讨论】:
标签: wcf soap wcf-security basic-authentication ws-security