我正在尝试使用WS-Security(Https和消息已签名)开发WCF服务,基本上 - 它正在工作,我可以使用我的.NET客户端应用程序使用它,但我需要能够使用SoapUi测试此Web服务。我可以生成几乎相同的请求,例如我的.NET客户端应用程序,但只有一个区别 - SoapUi使用规范化xml-exc-c14n #like:
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<InclusiveNamespaces PrefixList="wsse s" xmlns="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:Transform>
和我的.NET客户端一样:
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
我试过过来的样品 Change canonicalization algorithm with WCF要改变这一点, 但没有成功。我无法使用从SecurityAlgorithmSuite派生的类设置defaultAlgorithmSuite变量,因为WCF仅在运行时抛出ArgumentOutOfRangeException。 以下是我的配置:
EndpointAddress address = new EndpointAddress(new Uri("dest_wcf_address"), EndpointIdentity.CreateDnsIdentity("cert"));
CustomBinding binding = new CustomBinding();
AsymmetricSecurityBindingElement asec = (AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10);
asec.SetKeyDerivation(false);
asec.AllowInsecureTransport = true;
asec.IncludeTimestamp = true;
TextMessageEncodingBindingElement textMessageEncoding = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
HttpsTransportBindingElement transport = new HttpsTransportBindingElement();
transport.RequireClientCertificate = false;
binding.Elements.Add(asec);
binding.Elements.Add(textMessageEncoding);
binding.Elements.Add(transport);
config.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true, HttpsGetEnabled = true });
config.Description.Behaviors.Add(new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
config.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "cert_cn");
config.Credentials.ClientCertificate.SetCertificate(
StoreLocation.LocalMachine,
StoreName.My,
X509FindType.FindBySubjectName,
"clienct_cert_cn");
config.Credentials.ClientCertificate.Authentication.
CertificateValidationMode =
X509CertificateValidationMode.Custom;
config.Credentials.ClientCertificate.Authentication.CustomCertificateValidator = new CustomX509CertificateValidator();
config.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
ServiceEndpoint endpoint = config.AddServiceEndpoint(typeof(IService1), binding, "service_address");
endpoint.Address = address;
那么如何改变规范化算法
答案 0 :(得分:0)
我还没有找到更改Canonicalization算法的方法,但问题不同 - SoapUI在使用EXC-C14N计算签名哈希时不会修剪空格。 xml中的漂亮打印破坏了安全性。作为解决方案,我们可以在SoapUI中的Request级别设置Strip Whitespaces属性,或者从body元素中手动删除它们。