2012-04-24 17 views
7

Chúng tôi là đối tác kinh doanh yêu cầu chúng tôi tạo một thông báo yêu cầu dịch vụ với xác nhận SAML 2.0. Đối tác đã cung cấp hai chứng chỉ và khai thác thử nghiệm cho dịch vụ web JAVA của họ.WCF khách hàng tiêu thụ dịch vụ web JAVA - tôi có nên sử dụng WCF hoặc chỉ tạo một nhà máy phân tích cú pháp/thông điệp tùy chỉnh?

Tôi đã tạo một ứng dụng WCF với CustomBinding để thử và tạo lại yêu cầu và sử dụng dịch vụ, nhưng tôi cảm thấy thất vọng với các sắc thái của WCF (và thiếu sự hỗ trợ nội tại cho SAML 2.0). m tự hỏi tôi có nên sử dụng một cái gì đó như một số WebClient hoặc HttpWebRequest và mã hóa/xây dựng & ký yêu cầu web XML và làm tương tự cho phản hồi hay không. Tôi biết có rất nhiều công việc liên quan đến điều này nhưng ít nhất tôi sẽ được kiểm soát hoàn toàn.

lời khuyên của bạn sẽ được rất nhiều đánh giá cao, những gì tôi đang làm việc với được hiển thị bên dưới

Lưu ý: Tôi đã được cung cấp với một thử nghiệm khai thác soapUI cho các dịch vụ Java

Các nhà cung cấp cung cấp cho tôi với yêu cầu này (chạy mặc dù soapUI và trích xuất thông qua Fiddler)

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"> 
    <SOAP-ENV:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"> 
    <wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
     <xenc:EncryptedKey Id="EncKeyId-29B98C291D1FDFB39113352984774895"> 
     <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/> 
     <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> 
      <wsse:SecurityTokenReference> 
      <ds:X509Data> 
       <ds:X509IssuerSerial> 
       <ds:X509IssuerName>CN=test_server</ds:X509IssuerName> 
       <ds:X509SerialNumber>12356789</ds:X509SerialNumber> 
       </ds:X509IssuerSerial> 
      </ds:X509Data> 
      </wsse:SecurityTokenReference> 
     </ds:KeyInfo> 
     <xenc:CipherData> 
      <xenc:CipherValue> 
      <!--Omitted --> 
      </xenc:CipherValue> 
     </xenc:CipherData> 
     <xenc:ReferenceList> 
      <xenc:DataReference URI="#EncDataId-3"/> 
     </xenc:ReferenceList> 
     </xenc:EncryptedKey> 
     <wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="CertId-29B98C291D1FDFB39113352984773591" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><!--Omitted --></wsse:BinarySecurityToken> 
     <ds:Signature Id="Signature-1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> 
     <ds:SignedInfo> 
      <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 
      <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/> 
      <ds:Reference URI="#id-2"> 
      <ds:Transforms> 
       <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 
      </ds:Transforms> 
      <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> 
      <ds:DigestValue> 
       <!--Omitted --> 
      </ds:DigestValue> 
      </ds:Reference> 
     </ds:SignedInfo> 
     <ds:SignatureValue> 
      <!--Omitted --> 
     </ds:SignatureValue> 
     <ds:KeyInfo Id="KeyId-29B98C291D1FDFB39113352984773792"> 
      <wsse:SecurityTokenReference wsu:Id="STRId-29B98C291D1FDFB39113352984773893" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
      <wsse:Reference URI="#CertId-29B98C291D1FDFB39113352984773591" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/> 
      </wsse:SecurityTokenReference> 
     </ds:KeyInfo> 
     </ds:Signature> 
    </wsse:Security> 
    <saml:Assertion ID="_54d0c8395de26c3e44730df2c9e8d3e9" IssueInstant="2012-02-17T10:40:36.806Z" Version="2.0" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"> 
     <saml:Issuer>CN=test_client</saml:Issuer> 
     <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> 
     <SignedInfo> 
      <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 
      <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/> 
      <Reference URI="#_54d0c8395de26c3e44730df2c9e8d3e9"> 
      <Transforms> 
       <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/> 
       <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 
      </Transforms> 
      <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> 
      <DigestValue> 
       <!--Omitted --> 
      </DigestValue> 
      </Reference> 
     </SignedInfo> 
     <SignatureValue> 
      <!--Omitted --> 
     </SignatureValue> 
     <KeyInfo> 
      <X509Data> 
      <X509Certificate> 
       <!--Omitted --> 
      </X509Certificate> 
      </X509Data> 
     </KeyInfo> 
     </Signature> 
     <saml:Subject> 
     <saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">[email protected]</saml:NameID> 
     </saml:Subject> 
     <saml:Conditions NotBefore="2012-02-17T10:40:21.806Z" NotOnOrAfter="2012-02-17T10:41:06.806Z"/> 
    </saml:Assertion> 
    <wsa:Action SOAP-ENV:mustUnderstand="1">http://www.xxxxxxx.xxx/ws/schemas/xxxxxx1/xxxx/xxxxxxxxxxxxxx</wsa:Action> 
    <wsa:MessageID SOAP-ENV:mustUnderstand="1">uuid:bffc27ba-68d9-44e6-b1f0-e2f852df7715</wsa:MessageID> 
    </SOAP-ENV:Header> 
    <SOAP-ENV:Body wsu:Id="id-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <xenc:EncryptedData Id="EncDataId-3" Type="http://www.w3.org/2001/04/xmlenc#Content"> 
     <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/> 
     <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> 
     <wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
      <wsse:Reference URI="#EncKeyId-29B98C291D1FDFB39113352984774895"/> 
     </wsse:SecurityTokenReference> 
     </ds:KeyInfo> 
     <xenc:CipherData> 
     <xenc:CipherValue> 
      <!--Omitted --> 
     </xenc:CipherValue> 
     </xenc:CipherData> 
    </xenc:EncryptedData> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

Đây là càng gần càng I'v e nhận được với khách hàng WCF của tôi. Các vấn đề tôi có thể immediatley là phần tử <o:SecurityTokenReference> phải chứa Tổ chức phát hành và Chuỗi nối tiếp, thay vào đó nó chứa phần tử KeyIdentifier?

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <s:Header> 
    <a:Action s:mustUnderstand="1" u:Id="_3"/> 
    <a:MessageID u:Id="_4">urn:uuid:fc8ef84b-dbf5-4150-a0c3-d4cc986333d1</a:MessageID> 
    <ActivityId CorrelationId="a9e1fec4-32bc-4633-909e-3d601c809b3c" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">d1909115-8922-46f3-a96c-db15bf91c599</ActivityId> 
    <a:ReplyTo u:Id="_5"> 
     <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address> 
    </a:ReplyTo> 
    <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo27oY4/3mnBOry0YL4StqvcAAAAA0UM+eVt4fU2AOe9/B3lPDZNf/2HmAuNEvzAoW0eKVSUACQAA</VsDebuggerCausalityData> 
    <a:To s:mustUnderstand="1" u:Id="_6">https://localhost:8089/ws</a:To> 
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
     <u:Timestamp u:Id="uuid-e5592f06-32af-40fb-996e-a0a469c7ed5e-2"> 
     <u:Created>2012-04-24T20:41:50.447Z</u:Created> 
     <u:Expires>2012-04-24T20:46:50.447Z</u:Expires> 
     </u:Timestamp> 
     <e:EncryptedKey Id="uuid-e5592f06-32af-40fb-996e-a0a469c7ed5e-1" xmlns:e="http://www.w3.org/2001/04/xmlenc#"> 
     <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/> 
     <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> 
      <o:SecurityTokenReference> 
      <o:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">lU10DQn4lSpE4fRpE9gslm5QDt0=</o:KeyIdentifier> 
      </o:SecurityTokenReference> 
     </KeyInfo> 
     <e:CipherData> 
      <e:CipherValue> 
      <!--Omitted--> 
      </e:CipherValue> 
     </e:CipherData> 
     <e:ReferenceList> 
      <e:DataReference URI="#_2"/> 
      <e:DataReference URI="#_7"/> 
      <e:DataReference URI="#_8"/> 
     </e:ReferenceList> 
     </e:EncryptedKey> 
     <o:BinarySecurityToken u:Id="uuid-fad0c01f-ab4b-4a5f-bec6-93aa8c2d5a52-1" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"><!--Omitted--></o:BinarySecurityToken> 
     <e:EncryptedData Id="_7" Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:e="http://www.w3.org/2001/04/xmlenc#"> 
     <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/> 
     <e:CipherData> 
      <e:CipherValue> 
      <!--Omitted--> 
      </e:CipherValue> 
     </e:CipherData> 
     </e:EncryptedData> 
     <e:EncryptedData Id="_8" Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:e="http://www.w3.org/2001/04/xmlenc#"> 
     <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/> 
     <e:CipherData> 
      <e:CipherValue><!--Omitted--></e:CipherValue> 
     </e:CipherData> 
     </e:EncryptedData> 
    </o:Security> 
    </s:Header> 
    <s:Body u:Id="_1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <e:EncryptedData Id="_2" Type="http://www.w3.org/2001/04/xmlenc#Content" xmlns:e="http://www.w3.org/2001/04/xmlenc#"> 
     <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/> 
     <e:CipherData> 
     <e:CipherValue><!--Omitted--></e:CipherValue> 
     </e:CipherData> 
    </e:EncryptedData> 
    </s:Body> 
</s:Envelope> 

Sử dụng cấu hình này cho WCF CustomBinding

<system.serviceModel>   
     <bindings> 
      <customBinding> 
      <binding name="WSHttpBinding_IEnquiryRequest" > 
       <transactionFlow /> 
       <security defaultAlgorithmSuite="TripleDesRsa15" 
         authenticationMode="MutualCertificate" 
         messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" 
         requireDerivedKeys="false" 
         > 

         <secureConversationBootstrap authenticationMode="CertificateOverTransport" 
              messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" 
              requireDerivedKeys="false" /> 
       </security> 
       <textMessageEncoding messageVersion="Soap11WSAddressing10" /> 
       <!--<mtomMessageEncoding messageVersion="Soap11WSAddressing10" />--> 
       <httpsTransport requireClientCertificate="true" /> 
      </binding> 
      </customBinding>    
     </bindings> 
     <behaviors> 
     <endpointBehaviors> 
      <behavior name="certBehaviour">    
       <clientCredentials> 
       <!-- clientCertificate not defaultCertificate --> 
       <clientCertificate x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" findValue="test_client" /> 
       <serviceCertificate> 
        <defaultCertificate x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" findValue="test_server"/> 
        <authentication revocationMode="NoCheck" certificateValidationMode="None" /> 
       </serviceCertificate> 
       </clientCredentials>    
      </behavior> 
     </endpointBehaviors> 
     </behaviors> 
     <client> 
      <endpoint 
       address="https://localhost:8089/pvs/ws" 
       binding="customBinding" 
       bindingConfiguration="WSHttpBinding_IEnquiryRequest" 
       contract="XXXService.enquiryRequest" 
       name="WSHttpBinding_IEnquiryRequest" 
       behaviorConfiguration="certBehaviour" 
       > 
      <identity> 
       <dns value="test_server"/> 
      </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 

Tôi không biết làm thế nào để chèn khẳng định SAML 2.0 trong đó trước khi nó được ký kết. Điều đó và vấn đề chính/vấn đề nối tiếp ở trên là nơi mà vấn đề chính của tôi nằm trong yêu cầu.

Bất kỳ và tất cả sự giúp đỡ đánh giá cao

+0

Nếu bạn có thể lấy nó làm việc với WCF, chắc chắn đi với điều đó. Bạn có thể thêm tiêu đề địa chỉ tùy chỉnh của riêng mình, tôi phải làm điều đó cho một khách hàng WCF WS-Security. Hoặc thử một khung công tác dịch vụ web khác. Không thực hiện của riêng bạn trừ khi nó là một phương sách cuối cùng. – jrummell

+0

Bạn đã thử thực hiện tham chiếu dịch vụ _classic_ thay vì tham chiếu dịch vụ chuẩn mới chưa? Xem phần [Cách thêm tài liệu tham khảo vào một dịch vụ web] (http://msdn.microsoft.com/en-us/library/bb628649.aspx) để biết thêm thông tin. Tôi đã tìm thấy proxy được tạo ra bởi phương pháp này để tương thích hơn với các dịch vụ không .NET và có nhiều may mắn hơn khi chỉnh sửa chúng khi cần thiết. –

+0

Cảm ơn Joshua. Tôi đoán lớp proxy chỉ tạo ra các hợp đồng chia sẻ dữ liệu, v.v ...? - Tôi đã làm việc này OK. Vấn đề là với tiêu đề SOAP không có trong WSDL – StickyMcGinty

Trả lời

0

Tôi đã sử dụng mẫu XML mẫu thay vì làm tất cả trong mã, nhưng điều đó cũng có thể.

Lưu ý: Bạn cần phải thêm này để được thông báo sử dụng một Custom Encoder - cách mà bạn có thể chỉ khe trong token SAML vào tiêu đề (chỉ yếu tố tiêu đề được ký kết, không phải là nội dung)

Tôi đang ở một chút vội vàng, cho tôi biết nếu bạn cần thêm thông tin

private void SignSaml() 
    { 
     RSACryptoServiceProvider rsaProvider = (RSACryptoServiceProvider)SecurityController.ClientCertificate.PrivateKey; 


     //Load the private key from xml file 
     XmlDocument xmlDocument = new XmlDocument(); 
     xmlDocument.LoadXml(_samlTextWithElementValues);    

     // Create a SignedXml object. 
     SignedXml signedXml = new SignedXml(xmlDocument); 

     //Specify the canonicalization method 
     signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl; 
     // Add the key to the SignedXml document. 
     signedXml.SigningKey = rsaProvider; 

     // Add the x509 data to the signature 
     KeyInfo keyInfo = new KeyInfo(); 
     KeyInfoX509Data keyInfoClause = new KeyInfoX509Data(SecurityController.ClientCertificate, X509IncludeOption.None); 
     keyInfoClause.AddCertificate(SecurityController.ClientCertificate); 
     keyInfo.AddClause(keyInfoClause); 
     signedXml.KeyInfo = keyInfo; 
     // Create a reference to be signed. 
     Reference reference = new Reference("#_54d0c8395de26c3e44730df2c9e8d3e9"); 

     //reference.Uri = ; 

     // Add an enveloped transformation to the reference. 
     XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform(); 
     reference.AddTransform(env); 
     reference.AddTransform(new XmlDsigExcC14NTransform()); 

     // Add the reference to the SignedXml object. 
     signedXml.AddReference(reference); 

     // Compute the signature. 
     signedXml.ComputeSignature(); 

     // Get the XML representation of the signature and save 
     // it to an XmlElement object. 
     XmlElement xmlDigitalSignature = signedXml.GetXml(); 

     // Append the element to the XML document. 
     xmlDocument.DocumentElement.AppendChild(xmlDocument.ImportNode(xmlDigitalSignature, true)); 
     _samlSignedWithCertificate = xmlDocument.InnerXml; 
    } 

Added cấu hình theo yêu cầu

<customBinding> 
    <binding name="BINDING" > 
     <transactionFlow /> 
     <security defaultAlgorithmSuite="TripleDesRsa15" 
       authenticationMode="MutualCertificate" 
       messageSecurityVersion="WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10" 
       requireDerivedKeys="false" 
       messageProtectionOrder="SignBeforeEncrypt"> 
     <secureConversationBootstrap authenticationMode="CertificateOverTransport" 
       messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" 
       requireDerivedKeys="false" /> 
     </security> 
     <httpsTransport requireClientCertificate="true" /> 
    </binding> 
    </customBinding> 
0

WIF hỗ trợ SAML 2.0 định dạng thẻ nếu bạn không chạy trên XP.

+0

Cảm ơn. Đã được xem xét các tài liệu hướng dẫn cho WIF và nó không phải là tốt nhất. Sẽ có một cái nhìn khác – StickyMcGinty

2

Đã có thể đạt được điều đó cuối cùng với sự giúp đỡ từ Yaron qua trên các diễn đàn WCF

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/9a1db0bb-d632-4f11-80b4-fab78be3a3ee

Đã khó khăn nhưng đã có cuối cùng, suy nghĩ tôi sẽ viết nó từ đầu tại một điểm!

+0

Xin chào @StickyMcGinty, tôi có cùng hoàn cảnh. Bạn có thể chia sẻ một ví dụ về giải pháp của mình với mã thông báo bảo mật không? – Quintium

+0

Tôi chỉ cần tạo mã thông báo SAML mẫu qua XML và ký tên, mẫu bên dưới – StickyMcGinty

+0

Cảm ơn bạn đã trả lời. Tôi sẽ xem xét nó. Trước khi bạn trả lời, chúng tôi có thể làm cho một khách hàng làm việc, nhưng bây giờ gặp vấn đề trên một dịch vụ web Java khác không thích cách WCF tham chiếu một tiêu đề tùy chỉnh trong khối chữ ký. Trường hợp SoapUI tạo ra một "InclusiveNamespaces PrefixList" vào phần đầu bên trong khối tham chiếu của cơ thể. – Quintium

Các vấn đề liên quan