Author: coheigea
Date: Mon Feb 10 12:15:12 2014
New Revision: 1566589

URL: http://svn.apache.org/r1566589
Log:
Adding support for setting a Signature Derived Key Length for the DOM code

Modified:
    
webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/SignatureEncryptionActionToken.java
    
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/SignatureDerivedAction.java
    
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/handler/WSHandler.java
    
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/DerivedKeyActionTest.java

Modified: 
webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/SignatureEncryptionActionToken.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/SignatureEncryptionActionToken.java?rev=1566589&r1=1566588&r2=1566589&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/SignatureEncryptionActionToken.java
 (original)
+++ 
webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/SignatureEncryptionActionToken.java
 Mon Feb 10 12:15:12 2014
@@ -52,6 +52,7 @@ public abstract class SignatureEncryptio
     private String tokenId;
     private String sha1Value;
     private String derivedKeyTokenReference;
+    private int derivedKeyLength;
     
     public X509Certificate getCertificate() {
         return certificate;
@@ -160,5 +161,11 @@ public abstract class SignatureEncryptio
     public void setDerivedKeyTokenReference(String derivedKeyTokenReference) {
         this.derivedKeyTokenReference = derivedKeyTokenReference;
     }
+    public int getDerivedKeyLength() {
+        return derivedKeyLength;
+    }
+    public void setDerivedKeyLength(int derivedKeyLength) {
+        this.derivedKeyLength = derivedKeyLength;
+    }
 }
 

Modified: 
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/SignatureDerivedAction.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/SignatureDerivedAction.java?rev=1566589&r1=1566588&r2=1566589&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/SignatureDerivedAction.java
 (original)
+++ 
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/SignatureDerivedAction.java
 Mon Feb 10 12:15:12 2014
@@ -83,6 +83,10 @@ public class SignatureDerivedAction impl
             wsSign.setWscVersion(ConversationConstants.VERSION_05_02);
         }
         
+        if (signatureToken.getDerivedKeyLength() > 0) {
+            wsSign.setDerivedKeyLength(signatureToken.getDerivedKeyLength());
+        }
+        
         String derivedKeyTokenReference = 
signatureToken.getDerivedKeyTokenReference();
         if ("EncryptedKey".equals(derivedKeyTokenReference)) {
             encrKeyBuilder = new WSSecEncryptedKey();

Modified: 
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/handler/WSHandler.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/handler/WSHandler.java?rev=1566589&r1=1566588&r2=1566589&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/handler/WSHandler.java
 (original)
+++ 
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/handler/WSHandler.java
 Mon Feb 10 12:15:12 2014
@@ -568,6 +568,18 @@ public abstract class WSHandler {
         String derivedKeyReference = 
getString(WSHandlerConstants.DERIVED_TOKEN_REFERENCE, mc);
         actionToken.setDerivedKeyTokenReference(derivedKeyReference);
         
+        String derivedKeyLength = 
getString(WSHandlerConstants.DERIVED_SIGNATURE_KEY_LENGTH, mc);
+        if (derivedKeyLength != null) {
+            try {
+                int dKL = Integer.parseInt(derivedKeyLength);
+                if (dKL > 0) {
+                    actionToken.setDerivedKeyLength(dKL);
+                }
+            } catch (NumberFormatException e) {
+                LOG.warn("Error in configuring a derived key length: " + 
e.getMessage());
+            }
+        }
+        
         String digestAlgo = getString(WSHandlerConstants.SIG_DIGEST_ALGO, mc);
         actionToken.setDigestAlgorithm(digestAlgo);
         
@@ -670,6 +682,18 @@ public abstract class WSHandler {
         String derivedKeyReference = 
getString(WSHandlerConstants.DERIVED_TOKEN_REFERENCE, mc);
         actionToken.setDerivedKeyTokenReference(derivedKeyReference);
         
+        String derivedKeyLength = 
getString(WSHandlerConstants.DERIVED_ENCRYPTION_KEY_LENGTH, mc);
+        if (derivedKeyLength != null) {
+            try {
+                int dKL = Integer.parseInt(derivedKeyLength);
+                if (dKL > 0) {
+                    actionToken.setDerivedKeyLength(dKL);
+                }
+            } catch (NumberFormatException e) {
+                LOG.warn("Error in configuring a derived key length: " + 
e.getMessage());
+            }
+        }
+        
         boolean use200512Namespace = decodeUse200512Namespace(reqData);
         reqData.setUse200512Namespace(use200512Namespace);
         

Modified: 
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/DerivedKeyActionTest.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/DerivedKeyActionTest.java?rev=1566589&r1=1566588&r2=1566589&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/DerivedKeyActionTest.java
 (original)
+++ 
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/DerivedKeyActionTest.java
 Mon Feb 10 12:15:12 2014
@@ -160,6 +160,39 @@ public class DerivedKeyActionTest extend
         
         verify(doc);
     }
+    
+    @org.junit.Test
+    public void testSignatureThumbprintDifferentKeyLength() throws Exception {
+        final WSSConfig cfg = WSSConfig.getNewInstance();
+        final RequestData reqData = new RequestData();
+        reqData.setWssConfig(cfg);
+        reqData.setUsername("wss40");
+        
+        java.util.Map<String, Object> config = new java.util.TreeMap<String, 
Object>();
+        config.put(WSHandlerConstants.SIG_PROP_FILE, "wss40.properties");
+        config.put(WSHandlerConstants.PW_CALLBACK_REF, callbackHandler);
+        config.put(WSHandlerConstants.SIG_KEY_ID, "Thumbprint");
+        config.put(WSHandlerConstants.DERIVED_SIGNATURE_KEY_LENGTH, "16");
+        reqData.setMsgContext(config);
+        
+        final Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+        CustomHandler handler = new CustomHandler();
+        HandlerAction action = new HandlerAction(WSConstants.DKT_SIGN);
+        handler.send(
+            doc, 
+            reqData, 
+            Collections.singletonList(action),
+            true
+        );
+        String outputString = 
+            XMLUtils.PrettyDocumentToString(doc);
+        
Assert.assertTrue(outputString.contains(ConversationConstants.WSC_NS_05_12));
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(outputString);
+        }
+        
+        verify(doc);
+    }
 
     @org.junit.Test
     public void testSignatureSKI() throws Exception {


Reply via email to