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 2016/03/02 11:32:26 UTC

svn commit: r1733244 - in /webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto: Crypto.java CryptoBase.java Merlin.java

Author: coheigea
Date: Wed Mar  2 10:32:26 2016
New Revision: 1733244

URL: http://svn.apache.org/viewvc?rev=1733244&view=rev
Log:
Provides the possibility to set a trustpovider

Modified:
    webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Crypto.java
    webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoBase.java
    webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Merlin.java

Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Crypto.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Crypto.java?rev=1733244&r1=1733243&r2=1733244&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Crypto.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Crypto.java Wed Mar  2 10:32:26 2016
@@ -44,11 +44,23 @@ public interface Crypto {
 
     /**
      * Set the crypto provider associated with this implementation
-     * @param provider the crypto provider to set
+     * @param provider the crypto provider name to set
      */
     void setCryptoProvider(String provider);
 
     /**
+     * Get the crypto provider used for truststore operation associated with this implementation.
+     * @return a crypto provider name
+     */
+    String getTrustProvider();
+
+    /**
+     * Set the crypto provider used for truststore operations associated with this implementation
+     * @param provider the name of the provider
+     */
+    void setTrustProvider(String provider);
+
+    /**
      * Retrieves the identifier name of the default certificate. This should be the certificate
      * that is used for signature and encryption. This identifier corresponds to the certificate
      * that should be used whenever KeyInfo is not present in a signed or an encrypted

Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoBase.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoBase.java?rev=1733244&r1=1733243&r2=1733244&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoBase.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoBase.java Wed Mar  2 10:32:26 2016
@@ -63,6 +63,7 @@ public abstract class CryptoBase impleme
     protected CertificateFactory certificateFactory;
     private String defaultAlias;
     private String cryptoProvider;
+    private String trustProvider;
 
     static {
         Constructor<?> cons = null;
@@ -98,6 +99,22 @@ public abstract class CryptoBase impleme
     }
 
     /**
+     * Set the crypto provider used for truststore operations associated with this implementation
+     * @param provider the name of the provider
+     */
+    public void setTrustProvider(String provider) {
+        trustProvider = provider;
+    }
+
+    /**
+     * Get the crypto provider used for truststore operation associated with this implementation.
+     * @return a crypto provider name
+     */
+    public String getTrustProvider() {
+        return trustProvider;
+    }
+
+    /**
      * Retrieves the identifier name of the default certificate. This should be the certificate
      * that is used for signature and encryption. This identifier corresponds to the certificate
      * that should be used whenever KeyInfo is not present in a signed or an encrypted

Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Merlin.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Merlin.java?rev=1733244&r1=1733243&r2=1733244&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Merlin.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Merlin.java Wed Mar  2 10:32:26 2016
@@ -106,6 +106,7 @@ public class Merlin extends CryptoBase {
     public static final String TRUSTSTORE_FILE = "truststore.file";
     public static final String TRUSTSTORE_PASSWORD = "truststore.password";
     public static final String TRUSTSTORE_TYPE = "truststore.type";
+    public static final String TRUSTSTORE_PROVIDER = "truststore.provider";
 
     /*
      * CRL configuration
@@ -177,9 +178,13 @@ public class Merlin extends CryptoBase {
         //
         // Load the provider(s)
         //
-        String provider = properties.getProperty(prefix + CRYPTO_KEYSTORE_PROVIDER);
-        if (provider != null) {
-            provider = provider.trim();
+        String keystoreProvider = this.properties.getProperty(prefix + CRYPTO_KEYSTORE_PROVIDER);
+        if (keystoreProvider != null) {
+            keystoreProvider = keystoreProvider.trim();
+
+            if (keystoreProvider.length() == 0) {
+                keystoreProvider = null;
+            }
         }
         String certProvider = properties.getProperty(prefix + CRYPTO_CERT_PROVIDER);
         if (certProvider != null) {
@@ -210,7 +215,7 @@ public class Merlin extends CryptoBase {
                 if (type != null) {
                     type = type.trim();
                 }
-                keystore = load(is, passwd, provider, type);
+                keystore = load(is, passwd, keystoreProvider, type);
                 if (DO_DEBUG) {
                     LOG.debug(
                         "The KeyStore " + keyStoreLocation + " of type " + type
@@ -231,6 +236,21 @@ public class Merlin extends CryptoBase {
         //
         // Load the TrustStore
         //
+        String trustProvider = this.properties.getProperty(prefix + TRUSTSTORE_PROVIDER);
+        if (trustProvider != null) {
+            trustProvider = trustProvider.trim();
+
+            if (trustProvider.length() == 0) {
+                trustProvider = null;
+            } else {
+                setTrustProvider(trustProvider);
+            }
+        } else if (keystoreProvider != null) {
+            // Fallback to keystore provider for compatibility reason
+            trustProvider = keystoreProvider;
+            setTrustProvider(trustProvider);
+        }
+
         String trustStoreLocation = properties.getProperty(prefix + TRUSTSTORE_FILE);
         if (trustStoreLocation != null) {
             trustStoreLocation = trustStoreLocation.trim();
@@ -245,7 +265,7 @@ public class Merlin extends CryptoBase {
                 if (type != null) {
                     type = type.trim();
                 }
-                truststore = load(is, passwd, provider, type);
+                truststore = load(is, passwd, trustProvider, type);
                 if (DO_DEBUG) {
                     LOG.debug(
                         "The TrustStore " + trustStoreLocation + " of type " + type
@@ -278,6 +298,7 @@ public class Merlin extends CryptoBase {
                 }
             }
         }
+
         //
         // Load the CRL file
         //
@@ -289,7 +310,7 @@ public class Merlin extends CryptoBase {
                 CertificateFactory cf = getCertificateFactory();
                 X509CRL crl = (X509CRL)cf.generateCRL(is);
 
-                if (provider == null || provider.length() == 0) {
+                if (keystoreProvider == null || keystoreProvider.length() == 0) {
                     crlCertStore =
                         CertStore.getInstance(
                             "Collection",
@@ -300,7 +321,7 @@ public class Merlin extends CryptoBase {
                         CertStore.getInstance(
                             "Collection",
                             new CollectionCertStoreParameters(Collections.singletonList(crl)),
-                            provider
+                                keystoreProvider
                         );
                 }
                 if (DO_DEBUG) {