You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wss4j-dev@ws.apache.org by co...@apache.org on 2010/08/23 20:38:47 UTC

svn commit: r988244 - in /webservices/wss4j/branches/1_5_x-fixes: src/org/apache/ws/security/WSSecurityEngineResult.java src/org/apache/ws/security/processor/EncryptedKeyProcessor.java test/wssec/TestWSSecurityEncryptionParts.java

Author: coheigea
Date: Mon Aug 23 18:38:46 2010
New Revision: 988244

URL: http://svn.apache.org/viewvc?rev=988244&view=rev
Log:
[WSS-237] - Provide key transport algorithm in encryption processor results
 - Thanks to David Valeri for the patch.

Modified:
    webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/WSSecurityEngineResult.java
    webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/processor/EncryptedKeyProcessor.java
    webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityEncryptionParts.java

Modified: webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/WSSecurityEngineResult.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/WSSecurityEngineResult.java?rev=988244&r1=988243&r2=988244&view=diff
==============================================================================
--- webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/WSSecurityEngineResult.java (original)
+++ webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/WSSecurityEngineResult.java Mon Aug 23 18:38:46 2010
@@ -170,6 +170,13 @@ public class WSSecurityEngineResult exte
     public static final Object TAG_ENCRYPTED_EPHEMERAL_KEY = "encrypted-ephemeral-key-bytes";
     
     /**
+     * Tag denoting the encrypted key transport algorithm.
+     *
+     * The value under this tag is of type String.
+     */
+    public static final Object TAG_ENCRYPTED_KEY_TRANSPORT_METHOD = "encrypted-key-transport-method";
+    
+    /**
      * Tag denoting the algorithm that was used to sign the message
      *
      * The value under this tag is of type String.

Modified: webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/processor/EncryptedKeyProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/processor/EncryptedKeyProcessor.java?rev=988244&r1=988243&r2=988244&view=diff
==============================================================================
--- webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/processor/EncryptedKeyProcessor.java (original)
+++ webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/processor/EncryptedKeyProcessor.java Mon Aug 23 18:38:46 2010
@@ -62,6 +62,8 @@ public class EncryptedKeyProcessor imple
     
     private String encryptedKeyId = null;
     private X509Certificate cert = null;
+    
+    private String encryptedKeyTransportMethod = null;
 
     public void handleToken(
             Element elem, 
@@ -83,16 +85,20 @@ public class EncryptedKeyProcessor imple
         }
         ArrayList dataRefUris = handleEncryptedKey((Element) elem, cb, decCrypto);
         encryptedKeyId = elem.getAttributeNS(null, "Id");
+        
+        WSSecurityEngineResult result = new WSSecurityEngineResult(
+                    WSConstants.ENCR, 
+                    this.decryptedBytes,
+                    this.encryptedEphemeralKey,
+                    this.encryptedKeyId, 
+                    dataRefUris,
+                    cert);
+        
+        result.put(WSSecurityEngineResult.TAG_ENCRYPTED_KEY_TRANSPORT_METHOD, this.encryptedKeyTransportMethod);
+        
         returnResults.add(
             0, 
-            new WSSecurityEngineResult(
-                WSConstants.ENCR, 
-                this.decryptedBytes,
-                this.encryptedEphemeralKey,
-                this.encryptedKeyId, 
-                dataRefUris,
-                cert
-            )
+            result
         );
     }
 
@@ -132,14 +138,13 @@ public class EncryptedKeyProcessor imple
             (Element) WSSecurityUtil.getDirectChild(
                 (Node) xencEncryptedKey, "EncryptionMethod", WSConstants.ENC_NS
             );
-        String keyEncAlgo = null;
         if (tmpE != null) {
-            keyEncAlgo = ((Element) tmpE).getAttribute("Algorithm");
+            this.encryptedKeyTransportMethod = ((Element) tmpE).getAttribute("Algorithm");
         }
-        if (keyEncAlgo == null) {
+        if (this.encryptedKeyTransportMethod == null) {
             throw new WSSecurityException(WSSecurityException.UNSUPPORTED_ALGORITHM, "noEncAlgo");
         }
-        Cipher cipher = WSSecurityUtil.getCipherInstance(keyEncAlgo);
+        Cipher cipher = WSSecurityUtil.getCipherInstance(this.encryptedKeyTransportMethod);
         //
         // Well, we can decrypt the session (symmetric) key. Now lookup CipherValue, this is the 
         // value of the encrypted session key (session key usually is a symmetrical key that encrypts

Modified: webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityEncryptionParts.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityEncryptionParts.java?rev=988244&r1=988243&r2=988244&view=diff
==============================================================================
--- webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityEncryptionParts.java (original)
+++ webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityEncryptionParts.java Mon Aug 23 18:38:46 2010
@@ -154,9 +154,13 @@ public class TestWSSecurityEncryptionPar
         WSSecurityEngineResult actionResult = 
             WSSecurityUtil.fetchActionResult(results, WSConstants.ENCR);
         assertTrue(actionResult != null);
+        assertFalse(actionResult.isEmpty());
+        
+        assertEquals(WSConstants.KEYTRANSPORT_RSA15, 
+                actionResult.get(WSSecurityEngineResult.TAG_ENCRYPTED_KEY_TRANSPORT_METHOD));
+        
         final java.util.List refs =
             (java.util.List) actionResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS);
-        assertTrue(actionResult != null && !actionResult.isEmpty());
         WSDataRef wsDataRef = (WSDataRef)refs.get(0);
         String xpath = wsDataRef.getXpath();
         assertEquals("/soapenv:Envelope/soapenv:Header/foo:foobar", xpath);
@@ -201,9 +205,14 @@ public class TestWSSecurityEncryptionPar
         WSSecurityEngineResult actionResult =
                 WSSecurityUtil.fetchActionResult(results, WSConstants.ENCR);
         assertTrue(actionResult != null);
+        assertFalse(actionResult.isEmpty());
+        
+        assertEquals(WSConstants.KEYTRANSPORT_RSA15, 
+                actionResult.get(WSSecurityEngineResult.TAG_ENCRYPTED_KEY_TRANSPORT_METHOD));
+        
         final java.util.List refs =
             (java.util.List) actionResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS);
-        assertTrue(actionResult != null && !actionResult.isEmpty());
+        
         WSDataRef wsDataRef = (WSDataRef)refs.get(0);
         String xpath = wsDataRef.getXpath();
         assertEquals("/soapenv:Envelope/soapenv:Header/foo:foobar", xpath);
@@ -274,7 +283,7 @@ public class TestWSSecurityEncryptionPar
     
     
     /**
-     * Test signing a custom SOAP header and the SOAP body
+     * Test encrypting a custom SOAP header and the SOAP body
      */
     public void testSOAPHeaderAndBody() throws Exception {
         SOAPEnvelope unencryptedEnvelope = message.getSOAPEnvelope();



---------------------------------------------------------------------
To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: wss4j-dev-help@ws.apache.org