【问题标题】:WCF Binding with both transport and message security具有传输和消息安全性的 WCF 绑定
【发布时间】:2013-09-20 15:07:51
【问题描述】:

我正在从事一个大型项目,该项目广泛使用 WCF 进行不同类型的通信。作为新需求的一部分,我们需要与第三方开发的 SOAP Web 服务进行通信。他们的服务是用 Java 开发的,有两个安全要求:

  1. 它需要 BASIC 身份验证通过传输和

  2. 消息必须使用 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


    【解决方案1】:

    配置 https 传输通道:

    HttpsTransportBindingElement h = new HttpTransportBindingElement();
    h.AuthenticationScheme = AuthenticationSchemes.Digest;
    h.realm = ...
    

    如果你遇到麻烦,我建议首先设置一个 workign 传输基本 http 绑定,这样你就会看到你通过服务器 https 传输(你应该期望得到一个肥皂错误 b/c 缺乏签名)。

    【讨论】:

    • 谢谢!这很有帮助。我确实收到了一个看起来与 BASIC 身份验证无关的新错误:“安全处理器无法在消息中找到安全标头。”我认为这意味着消息没有正确签名,你知道我可能遗漏了什么吗?
    • 您需要获取工作消息的样本并将其与您发送的消息进行比较
    • 好的,它正在工作。问题是我从服务器那里得到了一个故障并且它没有得到保护。我只需要添加一行代码:sec.EnableUnsecuredResponse = true; 现在一切正常,谢谢。
    猜你喜欢
    • 2014-05-22
    • 1970-01-01
    • 2013-02-05
    • 2011-07-30
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    • 2012-03-01
    • 2012-08-08
    相关资源
    最近更新 更多