ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1689446 - /webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/XOPAttachmentTest.java
Date Mon, 06 Jul 2015 16:10:18 GMT
Author: coheigea
Date: Mon Jul  6 16:10:18 2015
New Revision: 1689446

URL: http://svn.apache.org/r1689446
Log:
[WSS-544] - Adding support for signature and encryption derived

Modified:
    webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/XOPAttachmentTest.java

Modified: webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/XOPAttachmentTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/XOPAttachmentTest.java?rev=1689446&r1=1689445&r2=1689446&view=diff
==============================================================================
--- webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/XOPAttachmentTest.java
(original)
+++ webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/XOPAttachmentTest.java
Mon Jul  6 16:10:18 2015
@@ -337,6 +337,104 @@ public class XOPAttachmentTest extends o
         verify(encryptedDoc, inboundAttachmentCallback);
     }
     
+    @org.junit.Test
+    public void testDerivedEncryptedSOAPBody() throws Exception {
+        Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+        WSSecHeader secHeader = new WSSecHeader(doc);
+        secHeader.insertSecurityHeader();
+        
+        AttachmentCallbackHandler outboundAttachmentCallback = new AttachmentCallbackHandler();
+        
+        //EncryptedKey
+        WSSecEncryptedKey encrKeyBuilder = new WSSecEncryptedKey();
+        encrKeyBuilder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e");
+        encrKeyBuilder.setKeyIdentifierType(WSConstants.THUMBPRINT_IDENTIFIER);
+        encrKeyBuilder.setAttachmentCallbackHandler(outboundAttachmentCallback);
+        encrKeyBuilder.setStoreBytesInAttachment(true);
+        encrKeyBuilder.prepare(doc, crypto);
+
+        //Key information from the EncryptedKey
+        byte[] ek = encrKeyBuilder.getEphemeralKey();
+        String tokenIdentifier = encrKeyBuilder.getId();  
+
+        //Derived key encryption
+        WSSecDKEncrypt encrBuilder = new WSSecDKEncrypt();
+        encrBuilder.setSymmetricEncAlgorithm(WSConstants.AES_128);
+        encrBuilder.setExternalKey(ek, tokenIdentifier);
+        encrBuilder.setAttachmentCallbackHandler(outboundAttachmentCallback);
+        encrBuilder.setStoreBytesInAttachment(true);
+        Document encryptedDoc = encrBuilder.build(doc, secHeader);
+
+        encrKeyBuilder.prependToHeader(secHeader);
+        encrKeyBuilder.prependBSTElementToHeader(secHeader);
+        
+        List<Attachment> encryptedAttachments = outboundAttachmentCallback.getResponseAttachments();
+        assertNotNull(encryptedAttachments);
+        // Should have EncryptedKey + EncryptedData stored in attachments...
+        assertTrue(encryptedAttachments.size() == 2);
+        
+        if (LOG.isDebugEnabled()) {
+            String outputString = XMLUtils.PrettyDocumentToString(encryptedDoc);
+            LOG.debug(outputString);
+            // System.out.println(outputString);
+        }
+
+        AttachmentCallbackHandler inboundAttachmentCallback = 
+            new AttachmentCallbackHandler(encryptedAttachments);
+        verify(encryptedDoc, inboundAttachmentCallback);
+        
+        String processedDoc = XMLUtils.PrettyDocumentToString(encryptedDoc);
+        assertTrue(processedDoc.contains(SOAP_BODY));
+    }
+    
+    @org.junit.Test
+    public void testDerivedSignedSOAPBody() throws Exception {
+        Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+        WSSecHeader secHeader = new WSSecHeader(doc);
+        secHeader.insertSecurityHeader();
+        
+        AttachmentCallbackHandler outboundAttachmentCallback = new AttachmentCallbackHandler();
+        
+        //EncryptedKey
+        WSSecEncryptedKey encrKeyBuilder = new WSSecEncryptedKey();
+        encrKeyBuilder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e");
+        encrKeyBuilder.setKeyIdentifierType(WSConstants.THUMBPRINT_IDENTIFIER);
+        encrKeyBuilder.setAttachmentCallbackHandler(outboundAttachmentCallback);
+        encrKeyBuilder.setStoreBytesInAttachment(true);
+        encrKeyBuilder.prepare(doc, crypto);
+
+        //Key information from the EncryptedKey
+        byte[] ek = encrKeyBuilder.getEphemeralKey();
+        String tokenIdentifier = encrKeyBuilder.getId();  
+
+        //Derived key encryption
+        WSSecDKSign sigBuilder = new WSSecDKSign();
+        sigBuilder.setExternalKey(ek, tokenIdentifier);
+        sigBuilder.setSignatureAlgorithm(WSConstants.HMAC_SHA1);
+        sigBuilder.setAttachmentCallbackHandler(outboundAttachmentCallback);
+        sigBuilder.setStoreBytesInAttachment(true);
+        Document signedDoc = sigBuilder.build(doc, secHeader);
+
+        encrKeyBuilder.prependToHeader(secHeader);
+        encrKeyBuilder.prependBSTElementToHeader(secHeader);
+        
+        List<Attachment> signedAttachments = outboundAttachmentCallback.getResponseAttachments();
+        assertNotNull(signedAttachments);
+        assertTrue(signedAttachments.size() == 1);
+        
+        if (LOG.isDebugEnabled()) {
+            String outputString = XMLUtils.PrettyDocumentToString(signedDoc);
+            LOG.debug(outputString);
+        }
+
+        AttachmentCallbackHandler inboundAttachmentCallback = 
+            new AttachmentCallbackHandler(signedAttachments);
+        verify(signedDoc, inboundAttachmentCallback);
+        
+        String processedDoc = XMLUtils.PrettyDocumentToString(signedDoc);
+        assertTrue(processedDoc.contains(SOAP_BODY));
+    }
+    
     /**
      * Verifies the soap envelope.
      * This method verifies all the signature generated.



Mime
View raw message