Author: coheigea Date: Mon Jul 20 11:21:14 2009 New Revision: 795769 URL: http://svn.apache.org/viewvc?rev=795769&view=rev Log: Backported fix to WSSecEncrypt.getKeyGenerator plus some other bits and pieces.
Modified: webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecDKEncrypt.java webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecEncrypt.java webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew3.java Modified: webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecDKEncrypt.java URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecDKEncrypt.java?rev=795769&r1=795768&r2=795769&view=diff ============================================================================== --- webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecDKEncrypt.java (original) +++ webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecDKEncrypt.java Mon Jul 20 11:21:14 2009 @@ -157,7 +157,7 @@ WSSecurityException.FAILED_ENCRYPTION, null, null, e2 ); } - encDataRefs.add(new String("#" + xencEncryptedDataId)); + encDataRefs.add("#" + xencEncryptedDataId); } return encDataRefs; } Modified: webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecEncrypt.java URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecEncrypt.java?rev=795769&r1=795768&r2=795769&view=diff ============================================================================== --- webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecEncrypt.java (original) +++ webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/message/WSSecEncrypt.java Mon Jul 20 11:21:14 2009 @@ -28,6 +28,7 @@ import org.apache.ws.security.message.token.SecurityTokenReference; import org.apache.ws.security.util.Base64; import org.apache.ws.security.util.WSSecurityUtil; +import org.apache.xml.security.algorithms.JCEMapper; import org.apache.xml.security.encryption.EncryptedData; import org.apache.xml.security.encryption.XMLCipher; import org.apache.xml.security.encryption.XMLEncryptionException; @@ -599,7 +600,7 @@ WSSecurityException.FAILED_ENCRYPTION, null, null, e2 ); } - encDataRef.add(new String("#" + xencEncryptedDataId)); + encDataRef.add("#" + xencEncryptedDataId); } return encDataRef; } @@ -692,29 +693,25 @@ } private KeyGenerator getKeyGenerator() throws WSSecurityException { - KeyGenerator keyGen = null; try { // // Assume AES as default, so initialize it // - keyGen = KeyGenerator.getInstance("AES"); - if (symEncAlgo.equalsIgnoreCase(WSConstants.TRIPLE_DES)) { - keyGen = KeyGenerator.getInstance("DESede"); - } else if (symEncAlgo.equalsIgnoreCase(WSConstants.AES_128)) { + String keyAlgorithm = JCEMapper.getJCEKeyAlgorithmFromURI(symEncAlgo); + KeyGenerator keyGen = KeyGenerator.getInstance(keyAlgorithm); + if (symEncAlgo.equalsIgnoreCase(WSConstants.AES_128)) { keyGen.init(128); } else if (symEncAlgo.equalsIgnoreCase(WSConstants.AES_192)) { keyGen.init(192); } else if (symEncAlgo.equalsIgnoreCase(WSConstants.AES_256)) { keyGen.init(256); - } else { - return null; } + return keyGen; } catch (NoSuchAlgorithmException e) { throw new WSSecurityException( WSSecurityException.UNSUPPORTED_ALGORITHM, null, null, e ); } - return keyGen; } /** Modified: webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew3.java URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew3.java?rev=795769&r1=795768&r2=795769&view=diff ============================================================================== --- webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew3.java (original) +++ webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew3.java Mon Jul 20 11:21:14 2009 @@ -27,6 +27,7 @@ import org.apache.axis.message.SOAPEnvelope; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.ws.security.WSConstants; import org.apache.ws.security.WSPasswordCallback; import org.apache.ws.security.WSSecurityEngine; import org.apache.ws.security.components.crypto.Crypto; @@ -120,7 +121,7 @@ * * @throws java.lang.Exception Thrown when there is any problem in signing or verification */ - public void testX509Signature() throws Exception { + public void testIssuerSerialSignature() throws Exception { WSSecSignature builder = new WSSecSignature(); builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security"); LOG.info("Before Signing...."); @@ -129,7 +130,39 @@ secHeader.insertSecurityHeader(doc); Document signedDoc = builder.build(doc, crypto, secHeader); - LOG.info("After Signing...."); + if (LOG.isDebugEnabled()) { + LOG.debug("After Signing...."); + String outputString = + org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc); + LOG.debug(outputString); + } + + verify(signedDoc); + } + + /** + * Test that signs and verifies a WS-Security envelope + * <p/> + * + * @throws java.lang.Exception Thrown when there is any problem in signing or verification + */ + public void testBSTSignature() throws Exception { + WSSecSignature builder = new WSSecSignature(); + builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security"); + builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); + LOG.info("Before Signing...."); + Document doc = unsignedEnvelope.getAsDocument(); + WSSecHeader secHeader = new WSSecHeader(); + secHeader.insertSecurityHeader(doc); + Document signedDoc = builder.build(doc, crypto, secHeader); + + if (LOG.isDebugEnabled()) { + LOG.debug("After Signing...."); + String outputString = + org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc); + LOG.debug(outputString); + } + verify(signedDoc); } --------------------------------------------------------------------- To unsubscribe, e-mail: wss4j-dev-unsubscr...@ws.apache.org For additional commands, e-mail: wss4j-dev-h...@ws.apache.org