簡體   English   中英

使用WCF服務或SoapUi更改規范化算法

[英]Change canonicalization algorithm with WCF service or in SoapUi

我正在嘗試使用WS-Security(簽名的HTTP和消息)開發WCF服務,基本上,它可以正常工作,並且可以通過.NET客戶端應用程序使用它,但是我需要能夠使用SoapUi測試此Web服務。 我可以生成與我的.NET客戶端應用程序幾乎相同的請求,但只有一個不同-SoapUi使用規范化xml-exc-c14n#,例如:

<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#" />

我嘗試了使用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;

那么如何更改規范化算法

我還沒有找到更改Canonicalization算法的方法,但是問題有所不同-SoapUI在使用EXC-C14N計算簽名哈希時不會修剪空格。 xml中的漂亮打印破壞了安全性。 作為解決方案,我們可以在請求級別的SoapUI中設置Strip Whitespaces屬性,或從body元素中手動刪除它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM