You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2011/01/10 13:35:05 UTC
svn commit: r1057172 - in /webservices/wss4j/branches/1_5_x-fixes:
src/org/apache/ws/security/CustomTokenPrincipal.java
src/org/apache/ws/security/processor/SignatureProcessor.java
test/wssec/TestWSSecurityNewDK.java
Author: coheigea
Date: Mon Jan 10 12:35:04 2011
New Revision: 1057172
URL: http://svn.apache.org/viewvc?rev=1057172&view=rev
Log:
[WSS-263] - Store secret key from SignatureProcessor
- Changed previous merge for this issue. Secret Key is now stored in the WSSecurityEngineResult object under "TAG_DECRYPTED_KEY".
Modified:
webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/CustomTokenPrincipal.java
webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/processor/SignatureProcessor.java
webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNewDK.java
Modified: webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/CustomTokenPrincipal.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/CustomTokenPrincipal.java?rev=1057172&r1=1057171&r2=1057172&view=diff
==============================================================================
--- webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/CustomTokenPrincipal.java (original)
+++ webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/CustomTokenPrincipal.java Mon Jan 10 12:35:04 2011
@@ -29,7 +29,6 @@ public class CustomTokenPrincipal implem
private Element tokenElement;
private String name;
private Object tokenObject;
- private byte[] secretKey;
public Object getTokenObject() {
return tokenObject;
@@ -55,12 +54,4 @@ public class CustomTokenPrincipal implem
this.tokenElement = tokenElement;
}
- public void setSecretKey(byte[] secretKey) {
- this.secretKey = secretKey;
- }
-
- public byte[] getSecretKey() {
- return secretKey;
- }
-
}
Modified: webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/processor/SignatureProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/processor/SignatureProcessor.java?rev=1057172&r1=1057171&r2=1057172&view=diff
==============================================================================
--- webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/processor/SignatureProcessor.java (original)
+++ webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/processor/SignatureProcessor.java Mon Jan 10 12:35:04 2011
@@ -82,6 +82,8 @@ public class SignatureProcessor implemen
private X509Certificate[] certificates;
+ private byte[] secretKey;
+
private int secretKeyLength = WSConstants.WSE_DERIVED_KEY_LEN;
private String signatureMethod;
@@ -124,12 +126,20 @@ public class SignatureProcessor implemen
WSDocInfoStore.delete(wsDocInfo);
}
}
+ byte[] storedKey = null;
+ if (secretKey != null && secretKey.length > 0) {
+ storedKey = new byte[secretKey.length];
+ for (int i = 0; i < secretKey.length; i++) {
+ storedKey[i] = secretKey[i];
+ }
+ }
if (lastPrincipalFound instanceof WSUsernameTokenPrincipal) {
WSSecurityEngineResult result = new WSSecurityEngineResult(
WSConstants.UT_SIGN, lastPrincipalFound, null,
returnElements, protectedElements, signatureValue[0]);
result.put(WSSecurityEngineResult.TAG_SIGNATURE_METHOD, signatureMethod);
result.put(WSSecurityEngineResult.TAG_CANONICALIZATION_METHOD, c14nMethod);
+ result.put(WSSecurityEngineResult.TAG_DECRYPTED_KEY, storedKey);
returnResults.add(
0,
result
@@ -141,12 +151,14 @@ public class SignatureProcessor implemen
result.put(WSSecurityEngineResult.TAG_SIGNATURE_METHOD, signatureMethod);
result.put(WSSecurityEngineResult.TAG_CANONICALIZATION_METHOD, c14nMethod);
result.put(WSSecurityEngineResult.TAG_X509_CERTIFICATES, certificates);
+ result.put(WSSecurityEngineResult.TAG_DECRYPTED_KEY, storedKey);
returnResults.add(
0,
result
);
}
signatureId = elem.getAttributeNS(null, "Id");
+ secretKey = null;
}
/**
@@ -218,7 +230,6 @@ public class SignatureProcessor implemen
sig.addResourceResolver(EnvelopeIdResolver.getInstance());
KeyInfo info = sig.getKeyInfo();
- byte[] secretKey = null;
UsernameToken ut = null;
DerivedKeyToken dkt = null;
SAMLKeyInfo samlKi = null;
@@ -613,12 +624,10 @@ public class SignatureProcessor implemen
final SAMLAssertion assertion = samlKi.getAssertion();
CustomTokenPrincipal principal = new CustomTokenPrincipal(assertion.getId());
principal.setTokenObject(assertion);
- principal.setSecretKey(secretKey);
return principal;
} else if (secretKey != null) {
// This is the custom key scenario
CustomTokenPrincipal principal = new CustomTokenPrincipal(customTokenId);
- principal.setSecretKey(secretKey);
return principal;
} else {
throw new WSSecurityException("Cannot determine principal");
Modified: webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNewDK.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNewDK.java?rev=1057172&r1=1057171&r2=1057172&view=diff
==============================================================================
--- webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNewDK.java (original)
+++ webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNewDK.java Mon Jan 10 12:35:04 2011
@@ -30,6 +30,7 @@ import org.apache.commons.logging.LogFac
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.WSPasswordCallback;
import org.apache.ws.security.WSSecurityEngine;
+import org.apache.ws.security.WSSecurityEngineResult;
import org.apache.ws.security.components.crypto.Crypto;
import org.apache.ws.security.components.crypto.CryptoFactory;
import org.apache.ws.security.message.WSSecDKEncrypt;
@@ -37,6 +38,7 @@ import org.apache.ws.security.message.WS
import org.apache.ws.security.message.WSSecEncryptedKey;
import org.apache.ws.security.message.WSSecHeader;
import org.apache.ws.security.message.token.SecurityTokenReference;
+import org.apache.ws.security.util.WSSecurityUtil;
import org.apache.xml.security.signature.XMLSignature;
import org.w3c.dom.Document;
@@ -48,6 +50,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.cert.X509Certificate;
+import java.util.Vector;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -225,7 +228,15 @@ public class TestWSSecurityNewDK extends
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
LOG.debug(outputString);
}
- verify(doc);
+
+ Vector results = verify(doc);
+
+ WSSecurityEngineResult actionResult =
+ WSSecurityUtil.fetchActionResult(results, WSConstants.SIGN);
+ assertTrue(actionResult != null);
+ assertFalse(actionResult.isEmpty());
+
+ assertTrue(actionResult.get(WSSecurityEngineResult.TAG_DECRYPTED_KEY) != null);
}
@@ -260,7 +271,15 @@ public class TestWSSecurityNewDK extends
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
LOG.debug(outputString);
}
- verify(doc);
+
+ Vector results = verify(doc);
+
+ WSSecurityEngineResult actionResult =
+ WSSecurityUtil.fetchActionResult(results, WSConstants.SIGN);
+ assertTrue(actionResult != null);
+ assertFalse(actionResult.isEmpty());
+
+ assertTrue(actionResult.get(WSSecurityEngineResult.TAG_DECRYPTED_KEY) != null);
}
@@ -294,7 +313,15 @@ public class TestWSSecurityNewDK extends
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
LOG.debug(outputString);
}
- verify(doc);
+
+ Vector results = verify(doc);
+
+ WSSecurityEngineResult actionResult =
+ WSSecurityUtil.fetchActionResult(results, WSConstants.SIGN);
+ assertTrue(actionResult != null);
+ assertFalse(actionResult.isEmpty());
+
+ assertTrue(actionResult.get(WSSecurityEngineResult.TAG_DECRYPTED_KEY) != null);
}
@@ -388,11 +415,12 @@ public class TestWSSecurityNewDK extends
* @param envelope
* @throws Exception Thrown when there is a problem in verification
*/
- private void verify(Document doc) throws Exception {
- secEngine.processSecurityHeader(doc, null, this, crypto);
+ private Vector verify(Document doc) throws Exception {
+ Vector results = secEngine.processSecurityHeader(doc, null, this, crypto);
String outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
assertTrue(outputString.indexOf("LogTestService2") > 0 ? true : false);
+ return results;
}
public void handle(Callback[] callbacks)