ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1171055 - in /webservices/wss4j/trunk: ./ src/main/java/org/apache/ws/security/components/crypto/ src/test/java/org/apache/ws/security/message/ src/test/resources/ src/test/resources/keys/
Date Thu, 15 Sep 2011 11:08:51 GMT
Author: coheigea
Date: Thu Sep 15 11:08:51 2011
New Revision: 1171055

URL: http://svn.apache.org/viewvc?rev=1171055&view=rev
Log:
[WSS-314] - Added a "org.apache.ws.security.crypto.merlin.keystore.private.password" property
for this.

Added:
    webservices/wss4j/trunk/src/test/resources/alice.properties
    webservices/wss4j/trunk/src/test/resources/keys/alice.p12
Modified:
    webservices/wss4j/trunk/pom.xml
    webservices/wss4j/trunk/src/main/java/org/apache/ws/security/components/crypto/Merlin.java
    webservices/wss4j/trunk/src/test/java/org/apache/ws/security/message/SignatureTest.java

Modified: webservices/wss4j/trunk/pom.xml
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/pom.xml?rev=1171055&r1=1171054&r2=1171055&view=diff
==============================================================================
--- webservices/wss4j/trunk/pom.xml (original)
+++ webservices/wss4j/trunk/pom.xml Thu Sep 15 11:08:51 2011
@@ -431,6 +431,10 @@
                     <artifactId>xercesImpl</artifactId>
                 </exclusion>
                 <exclusion>
+                    <groupId>xml-apis</groupId>
+                    <artifactId>xml-apis</artifactId>
+                </exclusion>
+                <exclusion>
                     <groupId>xalan</groupId>
                     <artifactId>xalan</artifactId>
                 </exclusion>

Modified: webservices/wss4j/trunk/src/main/java/org/apache/ws/security/components/crypto/Merlin.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/main/java/org/apache/ws/security/components/crypto/Merlin.java?rev=1171055&r1=1171054&r2=1171055&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/main/java/org/apache/ws/security/components/crypto/Merlin.java
(original)
+++ webservices/wss4j/trunk/src/main/java/org/apache/ws/security/components/crypto/Merlin.java
Thu Sep 15 11:08:51 2011
@@ -93,6 +93,8 @@ public class Merlin extends CryptoBase {
         "org.apache.ws.security.crypto.merlin.keystore.type";
     public static final String KEYSTORE_ALIAS =
         "org.apache.ws.security.crypto.merlin.keystore.alias";
+    public static final String KEYSTORE_PRIVATE_PASSWORD =
+        "org.apache.ws.security.crypto.merlin.keystore.private.password";
     
     /*
      * TrustStore configuration types
@@ -122,6 +124,7 @@ public class Merlin extends CryptoBase {
     protected KeyStore truststore = null;
     protected CertStore crlCertStore = null;
     protected boolean loadCACerts = false;
+    protected boolean privatePasswordSet = false; 
     
     public Merlin() {
         // default constructor
@@ -191,6 +194,10 @@ public class Merlin extends CryptoBase {
                         + " has been loaded"
                     );
                 }
+                String privatePasswd = properties.getProperty(KEYSTORE_PRIVATE_PASSWORD);
+                if (privatePasswd != null) {
+                    privatePasswordSet = true;
+                }
             } finally {
                 if (is != null) {
                     is.close();
@@ -644,6 +651,12 @@ public class Merlin extends CryptoBase {
                 throw new WSSecurityException(msg);
             }
             String password = getPassword(identifier, callbackHandler);
+            if (password == null && privatePasswordSet) {
+                password = properties.getProperty(KEYSTORE_PRIVATE_PASSWORD);
+                if (password != null) {
+                    password = password.trim();
+                }
+            }
             Key keyTmp = keystore.getKey(identifier, password == null 
                                          ? new char[]{} : password.toCharArray());
             if (!(keyTmp instanceof PrivateKey)) {
@@ -689,6 +702,12 @@ public class Merlin extends CryptoBase {
                 log.error(msg + logMsg);
                 throw new WSSecurityException(msg);
             }
+            if (password == null && privatePasswordSet) {
+                password = properties.getProperty(KEYSTORE_PRIVATE_PASSWORD);
+                if (password != null) {
+                    password = password.trim();
+                }
+            }
             Key keyTmp = keystore.getKey(identifier, password == null 
                                          ? new char[]{} : password.toCharArray());
             if (!(keyTmp instanceof PrivateKey)) {

Modified: webservices/wss4j/trunk/src/test/java/org/apache/ws/security/message/SignatureTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/test/java/org/apache/ws/security/message/SignatureTest.java?rev=1171055&r1=1171054&r2=1171055&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/test/java/org/apache/ws/security/message/SignatureTest.java
(original)
+++ webservices/wss4j/trunk/src/test/java/org/apache/ws/security/message/SignatureTest.java
Thu Sep 15 11:08:51 2011
@@ -616,6 +616,36 @@ public class SignatureTest extends org.j
             LOG.debug(outputString);
         }
     }
+    
+    /**
+     * The test uses the Issuer Serial key identifier type.
+     * <p/>
+     * 
+     * @throws java.lang.Exception Thrown when there is any problem in signing or verification
+     */
+    @org.junit.Test
+    public void testX509SignatureDefaultPassword() throws Exception {
+        Crypto passwordCrypto = CryptoFactory.getInstance("alice.properties");
+        
+        WSSecSignature builder = new WSSecSignature();
+        builder.setUserInfo(passwordCrypto.getDefaultX509Identifier(), null);
+        builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
+        LOG.info("Before Signing IS....");
+        Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+        WSSecHeader secHeader = new WSSecHeader();
+        secHeader.insertSecurityHeader(doc);
+        Document signedDoc = builder.build(doc, passwordCrypto, secHeader);
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Signed message with IssuerSerial key identifier:");
+            String outputString = 
+                org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc);
+            LOG.debug(outputString);
+        }
+        LOG.info("After Signing IS....");
+        WSSecurityEngine newEngine = new WSSecurityEngine();
+        newEngine.processSecurityHeader(doc, null, null, passwordCrypto);
+    }
 
     /**
      * Verifies the soap envelope.

Added: webservices/wss4j/trunk/src/test/resources/alice.properties
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/test/resources/alice.properties?rev=1171055&view=auto
==============================================================================
--- webservices/wss4j/trunk/src/test/resources/alice.properties (added)
+++ webservices/wss4j/trunk/src/test/resources/alice.properties Thu Sep 15 11:08:51 2011
@@ -0,0 +1,5 @@
+org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
+org.apache.ws.security.crypto.merlin.keystore.type=pkcs12
+org.apache.ws.security.crypto.merlin.keystore.password=password
+org.apache.ws.security.crypto.merlin.keystore.alias=alice
+org.apache.ws.security.crypto.merlin.keystore.file=keys/alice.p12

Added: webservices/wss4j/trunk/src/test/resources/keys/alice.p12
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/test/resources/keys/alice.p12?rev=1171055&view=auto
==============================================================================
Files webservices/wss4j/trunk/src/test/resources/keys/alice.p12 (added) and webservices/wss4j/trunk/src/test/resources/keys/alice.p12
Thu Sep 15 11:08:51 2011 differ



Mime
View raw message