2012-12-27 10 views
6

मैं जो WS-सुरक्षा के लिए wss4j 1.6.8 का उपयोग करता जावा में वेब सेवा ग्राहक को लागू कर रहा हूँ पर हस्ताक्षर करने के दौरान आदेश (अधिक precize होने के लिए मैं एक सोप संदेश पर हस्ताक्षर करने की जरूरत है)। सर्वर साइड निम्नलिखित संरचना है करने के लिए अनुरोध की आवश्यकता है:WSS4j तत्वों सोप संदेश

<Envelope> 
    <Header> 
     <wsse:Security mustUnderstand="1"> 
      **<wsu:Timestamp wsu:Id="Timestamp-913ca68e-05ed-44e1-9d6c-b2f293da5a1d"> 
       <wsu:Created>2012-12-21T11:37:31Z</wsu:Created> 
       <wsu:Expires>2012-12-21T11:42:31Z</wsu:Expires> 
      </wsu:Timestamp>** 
      <wsse:BinarySecurityToken> 
       MIID2jCCAsKg... 
      </wsse:BinarySecurityToken> 
      <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="#Timestamp-913ca68e-05ed-44e1-9d6c-b2f293da5a1d"> 
         <Transforms> 
          <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 
         </Transforms> 
         <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> 
         <DigestValue>jdVY1HaDLusqO9UcxASE/GQHxyo=</DigestValue> 
        </Reference> 
        <Reference URI="#Body-e344eef1-2d8a-42d0-8a30-361ee61a8617"> 
         <Transforms> 
          <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> 
         </Transforms> 
         <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> 
         <DigestValue>L60mQelZERvXgLEgWlW50uJNqEA=</DigestValue> 
        </Reference> 
       </SignedInfo> 
       <SignatureValue> 
        NmgACUqrYYc/Kp/F... 
       </SignatureValue> 
       <KeyInfo> 
        <wsse:SecurityTokenReference xmlns=""> 
         <wsse:Reference URI="#SecurityToken-3f054298-711c-4090-95c3-105e1093f3ba" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/> 
        </wsse:SecurityTokenReference> 
       </KeyInfo> 
      </Signature> 
     </wsse:Security> 
    </S:Header> 
    <S:Body> 
     Body content... 
    </S:Body> 
</Envelope> 

मेरे समाधान दस्तावेज़ (दोनों के शरीर और टाइमस्टैम्प तत्व) पर हस्ताक्षर करता है, लेकिन किसी कारण से wss4j अनुभाग के नीचे करने के टाइमस्टैम्प तत्व डालता <wsse:BinarySecurityToken> और <Signature> तत्वों के बाद, क्या गलत है। कृपया सूत्रों काम पर हस्ताक्षर करता है कि देखो:

public static SOAPMessage signSoapMessage(SOAPMessage message, PrivateKey signingKey, X509Certificate signingCert, char[] passphrase) throws WSSecurityException { 

    final String alias = "signingKey"; 
    final int signatureValidityTime = 3600; // 1hour in seconds 

    WSSConfig config = new WSSConfig(); 
    config.setWsiBSPCompliant(false); 

    WSSecSignature builder = new WSSecSignature(config); 

    builder.setX509Certificate(signingCert); 
    builder.setUserInfo(alias, new String(passphrase)); 
    builder.setUseSingleCertificate(true); 
    builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); 

    try { 
     Document document = DanskeUtils.toDocument(message); 
     WSSecHeader secHeader = new WSSecHeader(); 
     secHeader.setMustUnderstand(true); 
     secHeader.insertSecurityHeader(document); 

     WSSecTimestamp timestamp = new WSSecTimestamp(); 
     timestamp.setTimeToLive(signatureValidityTime); 
     document = timestamp.build(document, secHeader); 

     List<WSEncryptionPart> parts = new ArrayList<WSEncryptionPart>(); 
     WSEncryptionPart timestampPart = new WSEncryptionPart("Timestamp", WSConstants.WSU_NS, ""); 
     WSEncryptionPart bodyPart = new WSEncryptionPart(WSConstants.ELEM_BODY, WSConstants.URI_SOAP11_ENV, ""); 
     parts.add(timestampPart); 
     parts.add(bodyPart); 
     builder.setParts(parts); 

     Properties properties = new Properties(); 
     properties.setProperty("org.apache.ws.security.crypto.provider", "org.apache.ws.security.components.crypto.Merlin"); 
     Crypto crypto = CryptoFactory.getInstance(properties); 
     KeyStore keystore = KeyStore.getInstance("JKS"); 
     keystore.load(null, passphrase); 
     keystore.setKeyEntry(alias, signingKey, passphrase, new Certificate[]{signingCert}); 
     ((Merlin) crypto).setKeyStore(keystore); 
     crypto.loadCertificate(new ByteArrayInputStream(signingCert.getEncoded())); 

     document = builder.build(document, crypto, secHeader); 
     return Utils.updateSoapMessage(document, message); 
    } catch (Exception e) { 
     throw new WSSecurityException(WSSecurityException.Reason.SIGNING_ISSUE, e); 
    } 
} 

आप कृपया मेरी मदद कर सकता स्पष्ट करने के लिए तत्वों का क्रम दस्तावेज़ से पहले हस्ताक्षर किए जाएंगे किस प्रकार बदलें? धन्यवाद!

+0

धन्यवाद। आपके प्रश्न ने मुझे बहुत मदद की। क्या आप कृपया मुझे बता सकते हैं कि wss4j apis का उपयोग करके साबुन संदेश के हस्ताक्षर को कैसे सत्यापित किया जाए। –

उत्तर

1

WS-एसईसी विनिर्देश कहते हैं, "तत्व एक हैडर ब्लॉक के लिए जोड़ रहे हैं, वे मौजूदा तत्वों के लिए prepended होना चाहिए।"

तो तुम पहले टाइमस्टैम्प यह WS-शीर्षक में किसी भी मौजूदा बच्चे तत्वों से ऊपर हो जाएगा जोड़ने। जब से तुम timstamp जोड़ने के बाद संदेश पर हस्ताक्षर कर रहे हैं, पर हस्ताक्षर करने की जानकारी फिर से शीर्षक के preappended किया जाएगा, इस प्रकार यह टाइमस्टैम्प तत्व ऊपर दिखाई देगा।

आप टाइमस्टैम्प तत्व की जरूरत है, बहुत शीर्ष पर दिखाई अंतिम प्रक्रिया के रूप में शीर्ष लेख में जोड़ने के लिए, तो

0

के बाद आप हस्ताक्षर का निर्माण आप इस लाइन जोड़ सकते हैं:

timestamp.prependToHeader(secHeader); 

कहीं भी होगी अपने बाइनरीसेक्चर टोकन तत्व के ऊपर टाइमस्टैम्प तत्व डालें।

संबंधित मुद्दे