2011-01-22 17 views
3

私は、.NET、C#クライアントからのCXFのWebサービスを利用したいと思います。私たちは現在、java-to-javaリクエストを処理しており、ws-security(WSS4Jライブラリ)を通じてSOAPエンベロープを保護しています。.NET WCF - CXF/WSS4J相互運用性

私の質問は:私は、次のクライアント側のJavaコードと同じSOAPリクエストを生成し、C#のWS-クライアントを実装することができますか?

//doc is the original SOAP envelope to process with WSS4J 
WSSecHeader secHeader = new WSSecHeader(); 
secHeader.insertSecurityHeader(doc); 

//add username token with password digest 
WSSecUsernameToken usrNameTok = new WSSecUsernameToken(); 
usrNameTok.setPasswordType(WSConstants.PASSWORD_DIGEST); 
usrNameTok.setUserInfo("guest",psw_guest); 
usrNameTok.prepare(doc); 
usrNameTok.appendToHeader(secHeader); 

//sign the envelope body with client key 
WSSecSignature sign = new WSSecSignature(); 
sign.setUserInfo("clientx509v1", psw_clientx509v1); 
sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); 

Document signedDoc = null;  
sign.prepare(doc, sigCrypto, secHeader); 
signedDoc = sign.build(doc, sigCrypto, secHeader); 

//encrypt envelope body with server public key 
WSSecEncrypt encrypt = new WSSecEncrypt(); 
encrypt.setUserInfo("serverx509v1"); 

// build the encrypted SOAP part 
String out = null; 
Document encryptedDoc = encrypt.build(signedDoc, encCrypto, secHeader); 
return encryptedDoc; 

誰かがMicrosoftの使い方や.NETの実例をどこから知ることができますか?

================================ EDIT ============= =======================

はあなたにラディスラフをありがとう!私はあなたの提案を適用し、私のような何かを思い付いた:私は(サーバー側)を取得結果

X509Certificate2 client_pk, server_cert; 
client_pk = new X509Certificate2(@"C:\x509\clientKey.pem", "blablabla"); 
server_cert = new X509Certificate2(@"C:\x509\server-cert.pfx", "blablabla"); 

// Create the binding. 
System.ServiceModel.WSHttpBinding myBinding = new WSHttpBinding();  
myBinding.TextEncoding = ASCIIEncoding.UTF8; 
myBinding.MessageEncoding = WSMessageEncoding.Text;    
myBinding.Security.Mode = SecurityMode.Message; 
myBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; 
myBinding.Security.Message.AlgorithmSuite =           
      System.ServiceModel.Security.SecurityAlgorithmSuite.Basic128; 

// Disable credential negotiation and the establishment of 
// a security context. 
myBinding.Security.Message.NegotiateServiceCredential = false; 
myBinding.Security.Message.EstablishSecurityContext = false;     

// Create the endpoint address. 
EndpointAddress ea = 
    new EndpointAddress(new Uri("http://bla.bla.bla"), 
      EndpointIdentity.CreateDnsIdentity("issuer")); 

// configure the username credentials on the channel factory 
UsernameClientCredentials credentials = new UsernameClientCredentials(new 
            UsernameInfo("superadmin", "secret")); 

// Create the client. 
PersistenceClient client = new PersistenceClient(myBinding, ea); 

client.Endpoint.Contract.ProtectionLevel = 
      System.Net.Security.ProtectionLevel.EncryptAndSign; 

// replace ClientCredentials with UsernameClientCredentials 
client.Endpoint.Behaviors.Remove(typeof(ClientCredentials)); 
client.Endpoint.Behaviors.Add(credentials); 

// Specify a certificate to use for authenticating the client. 
client.ClientCredentials.ClientCertificate.Certificate = client_pk; 

// Specify a default certificate for the service. 
client.ClientCredentials.ServiceCertificate.DefaultCertificate = server_cert; 

// Begin using the client. 
client.Open(); 
clientProxyNetwork[] response = client.GetAllNetwork(); 

次CXF例外:

java.security.SignatureException: Signature does not match. 
at sun.security.x509.X509CertImpl.verify(X509CertImpl.java:421) 
at sun.security.provider.certpath.BasicChecker.verifySignature(BasicChecker.java:133) 
at sun.security.provider.certpath.BasicChecker.check(BasicChecker.java:112) 
at sun.security.provider.certpath.PKIXMasterCertPathValidator.validate (PKIXMasterCertPathValidator.java:117) 

は、そのためには、キーjks-> PEMようです変換の問題...または、上記のクライアントコードに何か不足していますか?

+0

これは非常に古い質問ですが、今は似たようなことをしようとしていますが、残念ながら私はできません。私はあなたのコードを試しましたが、私は 'UsernameClientCredentials'を参照できません。これはあなたのカスタムクラスですか?基本的には、UsernameToken、BinarySecurityToken、Signatureでセキュリティヘッダーを作成する必要があります – Misiu

答えて

1

まあ、最終的に解決策は、全体のユーザー名トークンを暗号化し、署名することです。相互運用性については、wsアドレッシングはcxfでアクティブにする必要があり、c#でのカスタムバインドが必要です。このトリックを行ったカスタムバインディングは基本的には

AsymmetricSecurityBindingElement abe = 
    (AsymmetricSecurityBindingElement)SecurityBindingElement. 
CreateMutualCertificateBindingElement(MessageSecurityVersion. 
WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10); 
                

wcfはそれぞれwsのアドレス指定要素に署名するため、同じサーバー側で行う必要があります。

0

これは通常、WCF does not support UserNameToken Profile with Digested passwordので、かなり大きな問題です。私は数ヶ月前にneeded itと私たちは独自のカスタムバインディングを実装する必要があったが、そのコードは公開準備が整っていない。 Fortunatelly this blog articleは、他の実装を記述し、消化されたパスワードをサポートする新しいUserNameClientCredentialsクラスのサンプルコードを含んでいます。

Btw。同じセキュリティ構成がWSE 3.0と呼ばれる古いAPIで可能になるはずです。 WCFに置き換えられましたが、まだいくつかのWS- *スタック設定は、そのAPIと古いASMXサービスではるかに簡単です。