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 2015/12/19 12:11:55 UTC
svn commit: r1720895 [5/34] - in /webservices/wss4j/branches/2_1_x-fixes:
bindings/src/main/java/org/apache/wss4j/binding/wss10/
bindings/src/main/java/org/apache/wss4j/binding/wss11/
bindings/src/main/java/org/apache/wss4j/binding/wssc13/ bindings/src...
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/BouncyCastleUtils.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/BouncyCastleUtils.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/BouncyCastleUtils.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/BouncyCastleUtils.java Sat Dec 19 11:11:50 2015
@@ -26,7 +26,7 @@ import org.bouncycastle.asn1.x509.Author
import org.bouncycastle.asn1.x509.SubjectKeyIdentifier;
public final class BouncyCastleUtils {
-
+
private BouncyCastleUtils() {
// complete
}
@@ -34,26 +34,26 @@ public final class BouncyCastleUtils {
public static byte[] getAuthorityKeyIdentifierBytes(X509Certificate cert) {
byte[] extensionValue = cert.getExtensionValue("2.5.29.35"); //NOPMD
if (extensionValue != null) {
- byte[] octets = ASN1OctetString.getInstance(extensionValue).getOctets();
- AuthorityKeyIdentifier authorityKeyIdentifier =
+ byte[] octets = ASN1OctetString.getInstance(extensionValue).getOctets();
+ AuthorityKeyIdentifier authorityKeyIdentifier =
AuthorityKeyIdentifier.getInstance(octets);
return authorityKeyIdentifier.getKeyIdentifier();
}
return null;
}
-
+
public static byte[] getSubjectKeyIdentifierBytes(X509Certificate cert) {
byte[] extensionValue = cert.getExtensionValue("2.5.29.14"); //NOPMD
if (extensionValue != null) {
- byte[] subjectOctets =
- ASN1OctetString.getInstance(extensionValue).getOctets();
+ byte[] subjectOctets =
+ ASN1OctetString.getInstance(extensionValue).getOctets();
SubjectKeyIdentifier subjectKeyIdentifier =
SubjectKeyIdentifier.getInstance(subjectOctets);
return subjectKeyIdentifier.getKeyIdentifier();
}
return null;
}
-
+
}
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CertificateStore.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/CertificateStore.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CertificateStore.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CertificateStore.java Sat Dec 19 11:11:50 2015
@@ -47,23 +47,23 @@ import org.apache.wss4j.common.ext.WSSec
* supported, so this cannot be used for signature creation, or decryption.
*/
public class CertificateStore extends CryptoBase {
-
- private static final org.slf4j.Logger LOG =
+
+ private static final org.slf4j.Logger LOG =
org.slf4j.LoggerFactory.getLogger(CertificateStore.class);
-
+
private X509Certificate[] trustedCerts;
-
+
/**
* Constructor
*/
public CertificateStore(X509Certificate[] trustedCerts) {
this.trustedCerts = trustedCerts;
}
-
+
/**
* Get an X509Certificate (chain) corresponding to the CryptoType argument. The supported
* types are as follows:
- *
+ *
* TYPE.ISSUER_SERIAL - A certificate (chain) is located by the issuer name and serial number
* TYPE.THUMBPRINT_SHA1 - A certificate (chain) is located by the SHA1 of the (root) cert
* TYPE.SKI_BYTES - A certificate (chain) is located by the SKI bytes of the (root) cert
@@ -101,7 +101,7 @@ public class CertificateStore extends Cr
}
return certs;
}
-
+
/**
* Get the implementation-specific identifier corresponding to the cert parameter. In this
* case, the identifier refers to the subject DN.
@@ -112,7 +112,7 @@ public class CertificateStore extends Cr
public String getX509Identifier(X509Certificate cert) throws WSSecurityException {
return cert.getSubjectDN().toString();
}
-
+
/**
* Gets the private key corresponding to the certificate. Not supported.
*
@@ -125,7 +125,7 @@ public class CertificateStore extends Cr
) throws WSSecurityException {
return null;
}
-
+
/**
* Gets the private key corresponding to the identifier. Not supported.
*
@@ -139,7 +139,7 @@ public class CertificateStore extends Cr
) throws WSSecurityException {
return null;
}
-
+
/**
* Evaluate whether a given certificate chain should be trusted.
*
@@ -149,7 +149,7 @@ public class CertificateStore extends Cr
* @throws WSSecurityException if the certificate chain is invalid
*/
public void verifyTrust(
- X509Certificate[] certs,
+ X509Certificate[] certs,
boolean enableRevocation,
Collection<Pattern> subjectCertConstraints
) throws WSSecurityException {
@@ -159,11 +159,11 @@ public class CertificateStore extends Cr
if (!enableRevocation) {
String issuerString = certs[0].getIssuerX500Principal().getName();
BigInteger issuerSerial = certs[0].getSerialNumber();
-
+
CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ISSUER_SERIAL);
cryptoType.setIssuerSerial(issuerString, issuerSerial);
X509Certificate[] foundCerts = getX509Certificates(cryptoType);
-
+
//
// If a certificate has been found, the certificates must be compared
// to ensure against phony DNs (compare encoded form including signature)
@@ -177,10 +177,10 @@ public class CertificateStore extends Cr
return;
}
}
-
-
+
+
//
- // SECOND step - Search for the issuer cert (chain) of the transmitted certificate in the
+ // SECOND step - Search for the issuer cert (chain) of the transmitted certificate in the
// keystore or the truststore
//
CryptoType cryptoType = new CryptoType(CryptoType.TYPE.SUBJECT_DN);
@@ -194,16 +194,16 @@ public class CertificateStore extends Cr
String subjectString = certs[0].getSubjectX500Principal().getName();
if (LOG.isDebugEnabled()) {
LOG.debug(
- "No certs found in keystore for issuer " + issuerString
+ "No certs found in keystore for issuer " + issuerString
+ " of certificate for " + subjectString
);
}
throw new WSSecurityException(
- WSSecurityException.ErrorCode.FAILURE, "certpath",
+ WSSecurityException.ErrorCode.FAILURE, "certpath",
new Object[] {"No trusted certs found"}
);
}
-
+
//
// THIRD step
// Check the certificate trust path for the issuer cert chain
@@ -213,7 +213,7 @@ public class CertificateStore extends Cr
"Preparing to validate certificate path for issuer " + issuerString
);
}
-
+
//
// Form a certificate chain from the transmitted certificate
// and the certificate(s) of the issuer from the keystore/truststore
@@ -221,7 +221,7 @@ public class CertificateStore extends Cr
X509Certificate[] x509certs = new X509Certificate[foundCerts.length + 1];
x509certs[0] = certs[0];
System.arraycopy(foundCerts, 0, x509certs, 1, foundCerts.length);
-
+
try {
// Generate cert path
List<X509Certificate> certList = Arrays.asList(x509certs);
@@ -230,7 +230,7 @@ public class CertificateStore extends Cr
Set<TrustAnchor> set = new HashSet<>();
if (trustedCerts != null) {
for (X509Certificate cert : trustedCerts) {
- TrustAnchor anchor =
+ TrustAnchor anchor =
new TrustAnchor(cert, cert.getExtensionValue(NAME_CONSTRAINTS_OID));
set.add(anchor);
}
@@ -248,7 +248,7 @@ public class CertificateStore extends Cr
validator = CertPathValidator.getInstance("PKIX", provider);
}
validator.validate(path, param);
- } catch (java.security.NoSuchProviderException | NoSuchAlgorithmException
+ } catch (java.security.NoSuchProviderException | NoSuchAlgorithmException
| java.security.cert.CertificateException
| java.security.InvalidAlgorithmParameterException
| java.security.cert.CertPathValidatorException e) {
@@ -257,16 +257,16 @@ public class CertificateStore extends Cr
new Object[] {e.getMessage()}
);
}
-
+
// Finally check Cert Constraints
if (!matches(certs[0], subjectCertConstraints)) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_AUTHENTICATION);
}
}
-
+
/**
* Evaluate whether a given public key should be trusted.
- *
+ *
* @param publicKey The PublicKey to be evaluated
* @throws WSSecurityException if the PublicKey is invalid
*/
@@ -277,7 +277,7 @@ public class CertificateStore extends Cr
if (publicKey == null) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_AUTHENTICATION);
}
-
+
//
// Search the trusted certs for the transmitted public key (direct trust)
//
@@ -288,7 +288,7 @@ public class CertificateStore extends Cr
}
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_AUTHENTICATION);
}
-
+
/**
* Get an X509 Certificate (chain) according to a given serial number and issuer string.
*
@@ -298,7 +298,7 @@ public class CertificateStore extends Cr
* @throws WSSecurityException
*/
private X509Certificate[] getX509Certificates(
- String issuer,
+ String issuer,
BigInteger serialNumber
) throws WSSecurityException {
//
@@ -316,20 +316,20 @@ public class CertificateStore extends Cr
} catch (java.lang.IllegalArgumentException ex) {
issuerName = createBCX509Name(issuer);
}
-
+
for (X509Certificate trustedCert : trustedCerts) {
if (trustedCert.getSerialNumber().compareTo(serialNumber) == 0) {
- Object certName =
+ Object certName =
createBCX509Name(trustedCert.getIssuerX500Principal().getName());
if (certName.equals(issuerName)) {
return new X509Certificate[]{trustedCert};
}
}
}
-
+
return null;
}
-
+
/**
* Get an X509 Certificate (chain) according to a given Thumbprint.
*
@@ -339,11 +339,11 @@ public class CertificateStore extends Cr
*/
private X509Certificate[] getX509Certificates(byte[] thumb) throws WSSecurityException {
MessageDigest sha = null;
-
+
if (trustedCerts == null) {
return null;
}
-
+
try {
sha = MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException e) {
@@ -367,7 +367,7 @@ public class CertificateStore extends Cr
}
return null;
}
-
+
/**
* Get an X509 Certificate (chain) according to a given SubjectKeyIdentifier.
*
@@ -383,10 +383,10 @@ public class CertificateStore extends Cr
if (data.length == skiBytes.length && Arrays.equals(data, skiBytes)) {
return new X509Certificate[]{trustedCert};
}
- }
+ }
return null;
}
-
+
/**
* Get an X509 Certificate (chain) according to a given DN of the subject of the certificate
*
@@ -394,7 +394,7 @@ public class CertificateStore extends Cr
* @return An X509 Certificate (chain) with the same DN as given in the parameters
* @throws WSSecurityException
*/
- private X509Certificate[] getX509CertificatesSubjectDN(String subjectDN)
+ private X509Certificate[] getX509CertificatesSubjectDN(String subjectDN)
throws WSSecurityException {
//
// Convert the subject DN to a java X500Principal object first. This is to ensure
@@ -411,19 +411,19 @@ public class CertificateStore extends Cr
} catch (java.lang.IllegalArgumentException ex) {
subject = createBCX509Name(subjectDN);
}
-
+
if (trustedCerts != null) {
for (X509Certificate trustedCert : trustedCerts) {
X500Principal foundRDN = trustedCert.getSubjectX500Principal();
Object certName = createBCX509Name(foundRDN.getName());
-
+
if (subject.equals(certName)) {
return new X509Certificate[]{trustedCert};
}
}
}
-
+
return null;
}
-
+
}
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=1720895&r1=1720894&r2=1720895&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 Sat Dec 19 11:11:50 2015
@@ -31,51 +31,51 @@ import javax.security.auth.callback.Call
import org.apache.wss4j.common.ext.WSSecurityException;
public interface Crypto {
-
+
//
// Accessor methods
//
-
+
/**
* Get the crypto provider associated with this implementation
* @return the crypto provider
*/
String getCryptoProvider();
-
+
/**
* Set the crypto provider associated with this implementation
* @param provider the crypto provider to set
*/
void setCryptoProvider(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
+ * 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
* message. May return null. The identifier is implementation specific, e.g. it could be the
* KeyStore alias.
*
* @return name of the default X509 certificate.
*/
String getDefaultX509Identifier() throws WSSecurityException;
-
+
/**
- * Sets 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
+ * Sets 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
* message. The identifier is implementation specific, e.g. it could be the KeyStore alias.
*
* @param identifier name of the default X509 certificate.
*/
void setDefaultX509Identifier(String identifier);
-
+
/**
* Sets the CertificateFactory instance on this Crypto instance
*
* @param certFactory the CertificateFactory the CertificateFactory instance to set
*/
void setCertificateFactory(CertificateFactory certFactory);
-
+
/**
* Get the CertificateFactory instance on this Crypto instance
*
@@ -84,11 +84,11 @@ public interface Crypto {
* @throws WSSecurityException
*/
CertificateFactory getCertificateFactory() throws WSSecurityException;
-
+
//
// Base Crypto functionality methods
//
-
+
/**
* Load a X509Certificate from the input stream.
*
@@ -97,7 +97,7 @@ public interface Crypto {
* @throws WSSecurityException
*/
X509Certificate loadCertificate(InputStream in) throws WSSecurityException;
-
+
/**
* Reads the SubjectKeyIdentifier information from the certificate.
* <p/>
@@ -111,7 +111,7 @@ public interface Crypto {
* @return The byte array containing the binary SKI data
*/
byte[] getSKIBytesFromCert(X509Certificate cert) throws WSSecurityException;
-
+
/**
* Get a byte array given an array of X509 certificates.
* <p/>
@@ -130,15 +130,15 @@ public interface Crypto {
* @throws WSSecurityException
*/
X509Certificate[] getCertificatesFromBytes(byte[] data) throws WSSecurityException;
-
+
//
// Implementation-specific Crypto functionality methods
//
-
+
/**
* Get an X509Certificate (chain) corresponding to the CryptoType argument. The supported
* types are as follows:
- *
+ *
* TYPE.ISSUER_SERIAL - A certificate (chain) is located by the issuer name and serial number
* TYPE.THUMBPRINT_SHA1 - A certificate (chain) is located by the SHA1 of the (root) cert
* TYPE.SKI_BYTES - A certificate (chain) is located by the SKI bytes of the (root) cert
@@ -147,7 +147,7 @@ public interface Crypto {
* specific, for example - it could be a java KeyStore alias.
*/
X509Certificate[] getX509Certificates(CryptoType cryptoType) throws WSSecurityException;
-
+
/**
* Get the implementation-specific identifier corresponding to the cert parameter, e.g. the
* identifier could be a KeyStore alias.
@@ -156,7 +156,7 @@ public interface Crypto {
* @throws WSSecurityException
*/
String getX509Identifier(X509Certificate cert) throws WSSecurityException;
-
+
/**
* Gets the private key corresponding to the certificate.
*
@@ -167,7 +167,7 @@ public interface Crypto {
PrivateKey getPrivateKey(
X509Certificate certificate, CallbackHandler callbackHandler
) throws WSSecurityException;
-
+
/**
* Gets the private key corresponding to the identifier.
*
@@ -178,7 +178,7 @@ public interface Crypto {
PrivateKey getPrivateKey(
String identifier, String password
) throws WSSecurityException;
-
+
/**
* Evaluate whether a given certificate chain should be trusted.
*
@@ -191,10 +191,10 @@ public interface Crypto {
X509Certificate[] certs, boolean enableRevocation,
Collection<Pattern> subjectCertConstraints
) throws WSSecurityException;
-
+
/**
- * Evaluate whether a given public key should be trusted directly (located
- *
+ * Evaluate whether a given public key should be trusted directly (located
+ *
* @param certs Certificate chain to validate
* @throws WSSecurityException if the certificate chain is invalid
*/
@@ -202,7 +202,7 @@ public interface Crypto {
/**
* Evaluate whether a given public key should be trusted.
- *
+ *
* @param publicKey The PublicKey to be evaluated
* @throws WSSecurityException if the PublicKey is invalid
*/
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=1720895&r1=1720894&r2=1720895&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 Sat Dec 19 11:11:50 2015
@@ -54,16 +54,16 @@ public abstract class CryptoBase impleme
* http://www.ietf.org/rfc/rfc3280.txt (s. 4.2.1.11)
*/
public static final String NAME_CONSTRAINTS_OID = "2.5.29.30"; //NOPMD - not an IP address
-
- private static final org.slf4j.Logger LOG =
+
+ private static final org.slf4j.Logger LOG =
org.slf4j.LoggerFactory.getLogger(CryptoBase.class);
-
+
private static final Constructor<?> BC_509CLASS_CONS;
protected CertificateFactory certificateFactory;
private String defaultAlias;
private String cryptoProvider;
-
+
static {
Constructor<?> cons = null;
try {
@@ -74,13 +74,13 @@ public abstract class CryptoBase impleme
}
BC_509CLASS_CONS = cons;
}
-
+
/**
* Constructor
*/
protected CryptoBase() {
}
-
+
/**
* Get the crypto provider associated with this implementation
* @return the crypto provider
@@ -88,7 +88,7 @@ public abstract class CryptoBase impleme
public String getCryptoProvider() {
return cryptoProvider;
}
-
+
/**
* Set the crypto provider associated with this implementation
* @param provider the crypto provider to set
@@ -96,11 +96,11 @@ public abstract class CryptoBase impleme
public void setCryptoProvider(String provider) {
cryptoProvider = 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
+ * 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
* message. May return null. The identifier is implementation specific, e.g. it could be the
* KeyStore alias.
*
@@ -109,11 +109,11 @@ public abstract class CryptoBase impleme
public String getDefaultX509Identifier() throws WSSecurityException {
return defaultAlias;
}
-
+
/**
- * Sets 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
+ * Sets 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
* message. The identifier is implementation specific, e.g. it could be the KeyStore alias.
*
* @param identifier name of the default X509 certificate.
@@ -121,7 +121,7 @@ public abstract class CryptoBase impleme
public void setDefaultX509Identifier(String identifier) {
defaultAlias = identifier;
}
-
+
/**
* Sets the CertificateFactory instance on this Crypto instance
*
@@ -130,7 +130,7 @@ public abstract class CryptoBase impleme
public void setCertificateFactory(CertificateFactory certFactory) {
this.certificateFactory = certFactory;
}
-
+
/**
* Get the CertificateFactory instance on this Crypto instance
*
@@ -142,7 +142,7 @@ public abstract class CryptoBase impleme
if (certificateFactory != null) {
return certificateFactory;
}
-
+
try {
String provider = getCryptoProvider();
if (provider == null || provider.length() == 0) {
@@ -159,7 +159,7 @@ public abstract class CryptoBase impleme
WSSecurityException.ErrorCode.SECURITY_TOKEN_UNAVAILABLE, e, "noSecProvider"
);
}
-
+
return certificateFactory;
}
@@ -269,7 +269,7 @@ public abstract class CryptoBase impleme
WSSecurityException.ErrorCode.SECURITY_TOKEN_UNAVAILABLE, e, "parseError"
);
}
-
+
List<?> l = path.getCertificates();
X509Certificate[] certs = new X509Certificate[l.size()];
int i = 0;
@@ -283,7 +283,7 @@ public abstract class CryptoBase impleme
public void verifyDirectTrust(X509Certificate[] certs) throws WSSecurityException {
verifyTrust(certs, true, null);
}
-
+
protected Object createBCX509Name(String s) {
if (BC_509CLASS_CONS != null) {
try {
@@ -294,7 +294,7 @@ public abstract class CryptoBase impleme
}
return new X500Principal(s);
}
-
+
/**
* @return true if the certificate's SubjectDN matches the constraints defined in the
* subject DNConstraints; false, otherwise. The certificate subject DN only
@@ -329,8 +329,8 @@ public abstract class CryptoBase impleme
return false;
}
}
-
+
return true;
}
-
+
}
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoFactory.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/CryptoFactory.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoFactory.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoFactory.java Sat Dec 19 11:11:50 2015
@@ -32,9 +32,9 @@ import org.apache.wss4j.common.util.Load
* CryptoFactory.
*/
public abstract class CryptoFactory {
- private static final org.slf4j.Logger LOG =
+ private static final org.slf4j.Logger LOG =
org.slf4j.LoggerFactory.getLogger(CryptoFactory.class);
-
+
static {
WSProviderConfig.init();
}
@@ -67,7 +67,7 @@ public abstract class CryptoFactory {
* class name as the value of the property : org.apache.wss4j.crypto.provider
* <p/>
*
- * @param properties The Properties that are forwarded to the crypto implementation
+ * @param properties The Properties that are forwarded to the crypto implementation
* and the Crypto impl class name.
* These properties are dependent on the crypto implementation
* @return The cyrpto implementation or null if no cryptoClassName was defined
@@ -87,13 +87,13 @@ public abstract class CryptoFactory {
/**
* getInstance
* <p/>
- * Returns an instance of Crypto loaded with the given classloader.
- * The properties are handed over the the crypto implementation.
+ * Returns an instance of Crypto loaded with the given classloader.
+ * The properties are handed over the the crypto implementation.
* The properties must at least contain the Crypto implementation
* class name as the value of the property : org.apache.wss4j.crypto.provider
* <p/>
*
- * @param properties The Properties that are forwarded to the crypto implementation
+ * @param properties The Properties that are forwarded to the crypto implementation
* and the Crypto impl class name.
* These properties are dependent on the crypto implementation
* @param classLoader The class loader to use
@@ -102,7 +102,7 @@ public abstract class CryptoFactory {
* @throws WSSecurityException if there is an error in loading the crypto properties
*/
public static Crypto getInstance(
- Properties properties,
+ Properties properties,
ClassLoader classLoader,
PasswordEncryptor passwordEncryptor
) throws WSSecurityException {
@@ -118,9 +118,9 @@ public abstract class CryptoFactory {
if (cryptoClassName == null) {
cryptoClassName = properties.getProperty("org.apache.ws.security.crypto.provider");
}
-
+
Class<? extends Crypto> cryptoClass = null;
- if (cryptoClassName == null
+ if (cryptoClassName == null
|| cryptoClassName.equals("org.apache.wss4j.common.crypto.Merlin")
|| cryptoClassName.equals("org.apache.ws.security.components.crypto.Merlin")) {
try {
@@ -129,7 +129,7 @@ public abstract class CryptoFactory {
if (LOG.isDebugEnabled()) {
LOG.debug("Unable to instantiate Merlin", e);
}
- throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, e, "empty",
+ throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, e, "empty",
new Object[] {"Cannot create Crypto class " + cryptoClassName});
}
} else {
@@ -146,7 +146,7 @@ public abstract class CryptoFactory {
}
return loadClass(cryptoClass, properties, classLoader);
}
-
+
/**
* getInstance
* <p/>
@@ -158,14 +158,14 @@ public abstract class CryptoFactory {
* @param cryptoClass This is the crypto implementation class. No default is
* provided here.
* @param map The Maps that is forwarded to the crypto implementation.
- * These contents of the map are dependent on the
- * underlying crypto implementation specified in the
+ * These contents of the map are dependent on the
+ * underlying crypto implementation specified in the
* cryptoClassName parameter.
* @return The crypto implementation or null if no cryptoClassName was defined
* @throws WSSecurityException if there is an error in loading the crypto properties
*/
public static Crypto getInstance(
- Class<? extends Crypto> cryptoClass,
+ Class<? extends Crypto> cryptoClass,
Map<Object, Object> map
) throws WSSecurityException {
return loadClass(cryptoClass, map, Loader.getClassLoader(CryptoFactory.class));
@@ -189,10 +189,10 @@ public abstract class CryptoFactory {
*/
public static Crypto getInstance(String propFilename) throws WSSecurityException {
return getInstance(propFilename, Loader.getClassLoader(CryptoFactory.class));
- }
-
+ }
+
public static Crypto getInstance(
- String propFilename,
+ String propFilename,
ClassLoader customClassLoader
) throws WSSecurityException {
Properties properties = getProperties(propFilename, customClassLoader);
@@ -200,7 +200,7 @@ public abstract class CryptoFactory {
}
/**
- * This allows loading the classes with a custom class loader
+ * This allows loading the classes with a custom class loader
* @param cryptoClass
* @param map
* @param loader
@@ -208,7 +208,7 @@ public abstract class CryptoFactory {
*/
private static Crypto loadClass(
Class<? extends Crypto> cryptoClass,
- Map<Object, Object> map,
+ Map<Object, Object> map,
ClassLoader loader
) throws WSSecurityException {
if (LOG.isDebugEnabled()) {
@@ -221,7 +221,7 @@ public abstract class CryptoFactory {
c = cryptoClass.getConstructor(classes);
return c.newInstance(map, loader);
} catch (NoSuchMethodException ex) {
- Class<?>[] classes =
+ Class<?>[] classes =
new Class[]{Properties.class, Map.class, PasswordEncryptor.class};
c = cryptoClass.getConstructor(classes);
return c.newInstance(map, loader, null);
@@ -234,17 +234,17 @@ public abstract class CryptoFactory {
"empty", new Object[] {cryptoClass + " cannot create instance"});
}
}
-
+
/**
- * This allows loading the classes with a custom class loader
+ * This allows loading the classes with a custom class loader
* @param cryptoClass
* @param map
* @param loader
* @throws WSSecurityException if there is an error in loading the crypto properties
*/
private static Crypto loadClass(
- Class<? extends Crypto> cryptoClass,
- Properties map,
+ Class<? extends Crypto> cryptoClass,
+ Properties map,
ClassLoader loader
) throws WSSecurityException {
if (LOG.isDebugEnabled()) {
@@ -257,7 +257,7 @@ public abstract class CryptoFactory {
c = cryptoClass.getConstructor(classes);
return c.newInstance(map, loader);
} catch (NoSuchMethodException ex) {
- Class<?>[] classes =
+ Class<?>[] classes =
new Class[]{Properties.class, ClassLoader.class, PasswordEncryptor.class};
c = cryptoClass.getConstructor(classes);
return c.newInstance(map, loader, null);
@@ -270,7 +270,7 @@ public abstract class CryptoFactory {
"empty", new Object[] {cryptoClass + " cannot create instance"});
}
}
-
+
/**
* This allows loading the resources with a custom class loader
* @param propFilename
@@ -279,7 +279,7 @@ public abstract class CryptoFactory {
* @throws WSSecurityException if there is an error in loading the crypto properties
*/
public static Properties getProperties(
- String propFilename,
+ String propFilename,
ClassLoader loader
) throws WSSecurityException {
Properties properties = new Properties();
@@ -287,7 +287,7 @@ public abstract class CryptoFactory {
URL url = Loader.getResource(loader, propFilename);
if (url == null) {
throw new WSSecurityException(
- WSSecurityException.ErrorCode.FAILURE,
+ WSSecurityException.ErrorCode.FAILURE,
"resourceNotFound",
new Object[] {propFilename}
);
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoType.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/CryptoType.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoType.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoType.java Sat Dec 19 11:11:50 2015
@@ -24,10 +24,10 @@ import java.math.BigInteger;
/**
* This class represents a way of passing information to the Crypto.getX509Certificates() method.
* The TYPE enum describes which method to use to retrieve the Certificate(s). The corresponding
- * get accessor must be set accordingly.
+ * get accessor must be set accordingly.
*/
public class CryptoType {
-
+
/**
* TYPE.ISSUER_SERIAL - A certificate (chain) is located by the issuer name and serial number
* TYPE.THUMBPRINT_SHA1 - A certificate (chain) is located by the SHA1 of the (root) cert
@@ -39,7 +39,7 @@ public class CryptoType {
public enum TYPE {
ISSUER_SERIAL, THUMBPRINT_SHA1, SKI_BYTES, SUBJECT_DN, ALIAS, ENDPOINT
}
-
+
private TYPE type;
private String issuer;
private BigInteger serial;
@@ -47,38 +47,38 @@ public class CryptoType {
private String subjectDN;
private String alias;
private String endpoint;
-
+
/**
* Default constructor
*/
public CryptoType() {
//
}
-
+
/**
* Constructor with a TYPE argument
- * @param type describes which method to use to retrieve a certificate (chain)
+ * @param type describes which method to use to retrieve a certificate (chain)
*/
public CryptoType(TYPE type) {
this.type = type;
}
-
+
/**
* Set the type.
- * @param type describes which method to use to retrieve a certificate (chain)
+ * @param type describes which method to use to retrieve a certificate (chain)
*/
public void setType(TYPE type) {
this.type = type;
}
-
+
/**
* Get the type
- * @return which method to use to retrieve a certificate (chain)
+ * @return which method to use to retrieve a certificate (chain)
*/
public TYPE getType() {
return type;
}
-
+
/**
* Set the Issuer String, and Serial number of the cert (chain) to retrieve.
* @param issuer the issuer String
@@ -88,7 +88,7 @@ public class CryptoType {
this.issuer = issuer;
this.serial = serial;
}
-
+
/**
* Get the issuer String.
* @return the issuer String
@@ -96,7 +96,7 @@ public class CryptoType {
public String getIssuer() {
return issuer;
}
-
+
/**
* Get the serial number
* @return the serial number
@@ -104,15 +104,15 @@ public class CryptoType {
public BigInteger getSerial() {
return serial;
}
-
+
/**
* Set the byte[], which could be the SHA1 thumbprint, or SKI bytes of the cert.
- * @param bytes an array of bytes
+ * @param bytes an array of bytes
*/
public void setBytes(byte[] bytes) {
this.bytes = bytes;
}
-
+
/**
* Get the array of bytes, which could be the SHA1 thumbprint, or SKI bytes of the cert.
* @return an array of bytes
@@ -120,7 +120,7 @@ public class CryptoType {
public byte[] getBytes() {
return bytes;
}
-
+
/**
* Set the Subject DN of the cert (chain) to locate
* @param subjectDN the Subject DN of the cert (chain) to locate
@@ -128,7 +128,7 @@ public class CryptoType {
public void setSubjectDN(String subjectDN) {
this.subjectDN = subjectDN;
}
-
+
/**
* Get the Subject DN of the cert (chain) to locate
* @return the Subject DN of the cert (chain) to locate
@@ -136,7 +136,7 @@ public class CryptoType {
public String getSubjectDN() {
return subjectDN;
}
-
+
/**
* Set the alias of the cert (chain) to locate.
* @param alias the alias of the cert (chain) to locate.
@@ -144,7 +144,7 @@ public class CryptoType {
public void setAlias(String alias) {
this.alias = alias;
}
-
+
/**
* Get the alias of the cert (chain) to locate.
* @return the alias of the cert (chain) to locate.
@@ -168,5 +168,5 @@ public class CryptoType {
public String getEndpoint() {
return endpoint;
}
-
+
}
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/JasyptPasswordEncryptor.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/JasyptPasswordEncryptor.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/JasyptPasswordEncryptor.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/JasyptPasswordEncryptor.java Sat Dec 19 11:11:50 2015
@@ -30,33 +30,33 @@ import org.jasypt.encryption.pbe.Standar
/**
- * An implementation of PasswordEncryptor that relies on Jasypt's StandardPBEStringEncryptor to
+ * An implementation of PasswordEncryptor that relies on Jasypt's StandardPBEStringEncryptor to
* encrypt and decrypt passwords. The default algorithm that is used is "PBEWithMD5AndTripleDES".
*/
public class JasyptPasswordEncryptor implements PasswordEncryptor {
-
+
public static final String DEFAULT_ALGORITHM = "PBEWithMD5AndTripleDES";
-
- private static final org.slf4j.Logger LOG =
+
+ private static final org.slf4j.Logger LOG =
org.slf4j.LoggerFactory.getLogger(JasyptPasswordEncryptor.class);
-
+
private final StandardPBEStringEncryptor passwordEncryptor;
private CallbackHandler callbackHandler;
-
+
public JasyptPasswordEncryptor(String masterPassword) {
this(masterPassword, DEFAULT_ALGORITHM);
}
-
+
public JasyptPasswordEncryptor(String masterPassword, String algorithm) {
passwordEncryptor = new StandardPBEStringEncryptor();
passwordEncryptor.setPassword(masterPassword);
passwordEncryptor.setAlgorithm(algorithm);
}
-
+
public JasyptPasswordEncryptor(CallbackHandler callbackHandler) {
this(callbackHandler, DEFAULT_ALGORITHM);
}
-
+
public JasyptPasswordEncryptor(CallbackHandler callbackHandler, String algorithm) {
passwordEncryptor = new StandardPBEStringEncryptor();
passwordEncryptor.setAlgorithm(algorithm);
@@ -70,7 +70,7 @@ public class JasyptPasswordEncryptor imp
*/
public String encrypt(String password) {
if (callbackHandler != null) {
- WSPasswordCallback pwCb =
+ WSPasswordCallback pwCb =
new WSPasswordCallback("", WSPasswordCallback.PASSWORD_ENCRYPTOR_PASSWORD);
try {
callbackHandler.handle(new Callback[]{pwCb});
@@ -83,7 +83,7 @@ public class JasyptPasswordEncryptor imp
}
return passwordEncryptor.encrypt(password);
}
-
+
/**
* Decrypt the given encrypted password
* @param encryptedPassword the encrypted password to decrypt
@@ -91,7 +91,7 @@ public class JasyptPasswordEncryptor imp
*/
public String decrypt(String encryptedPassword) {
if (callbackHandler != null) {
- WSPasswordCallback pwCb =
+ WSPasswordCallback pwCb =
new WSPasswordCallback("", WSPasswordCallback.PASSWORD_ENCRYPTOR_PASSWORD);
try {
callbackHandler.handle(new Callback[]{pwCb});
@@ -104,5 +104,5 @@ public class JasyptPasswordEncryptor imp
}
return passwordEncryptor.decrypt(encryptedPassword);
}
-
+
}
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=1720895&r1=1720894&r2=1720895&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 Sat Dec 19 11:11:50 2015
@@ -72,24 +72,24 @@ import org.apache.wss4j.common.util.Load
* being the truststore.
*/
public class Merlin extends CryptoBase {
-
+
public static final String ENCRYPTED_PASSWORD_PREFIX = "ENC(";
public static final String ENCRYPTED_PASSWORD_SUFFIX = ")";
-
+
public static final String PREFIX = "org.apache.wss4j.crypto.merlin.";
public static final String OLD_PREFIX = "org.apache.ws.security.crypto.merlin.";
-
+
/*
* Deprecated types
*/
public static final String OLD_KEYSTORE_FILE = "file";
-
+
/*
* Crypto providers
*/
public static final String CRYPTO_KEYSTORE_PROVIDER = "keystore.provider";
public static final String CRYPTO_CERT_PROVIDER = "cert.provider";
-
+
/*
* KeyStore configuration types
*/
@@ -98,7 +98,7 @@ public class Merlin extends CryptoBase {
public static final String KEYSTORE_TYPE ="keystore.type";
public static final String KEYSTORE_ALIAS ="keystore.alias";
public static final String KEYSTORE_PRIVATE_PASSWORD ="keystore.private.password";
-
+
/*
* TrustStore configuration types
*/
@@ -106,13 +106,13 @@ 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";
-
+
/*
* CRL configuration
*/
public static final String X509_CRL_FILE = "x509crl.file";
-
- private static final org.slf4j.Logger LOG =
+
+ private static final org.slf4j.Logger LOG =
org.slf4j.LoggerFactory.getLogger(Merlin.class);
private static final boolean DO_DEBUG = LOG.isDebugEnabled();
@@ -121,21 +121,21 @@ public class Merlin extends CryptoBase {
protected KeyStore truststore;
protected CertStore crlCertStore;
protected boolean loadCACerts;
- protected boolean privatePasswordSet;
+ protected boolean privatePasswordSet;
protected PasswordEncryptor passwordEncryptor;
-
+
public Merlin() {
// default constructor
}
-
+
public Merlin(boolean loadCACerts, String cacertsPasswd) {
super();
if (truststore == null && loadCACerts) {
String cacertsPath = System.getProperty("java.home") + "/lib/security/cacerts";
-
+
try (InputStream cacertsIs = new FileInputStream(cacertsPath)) {
-
+
truststore = KeyStore.getInstance(KeyStore.getDefaultType());
truststore.load(cacertsIs, cacertsPasswd.toCharArray());
this.loadCACerts = true;
@@ -144,15 +144,15 @@ public class Merlin extends CryptoBase {
}
}
}
-
- public Merlin(Properties properties, ClassLoader loader, PasswordEncryptor passwordEncryptor)
+
+ public Merlin(Properties properties, ClassLoader loader, PasswordEncryptor passwordEncryptor)
throws WSSecurityException, IOException {
loadProperties(properties, loader, passwordEncryptor);
}
-
+
public void loadProperties(
- Properties properties,
- ClassLoader loader,
+ Properties properties,
+ ClassLoader loader,
PasswordEncryptor passwordEncryptor
) throws WSSecurityException, IOException {
if (properties == null) {
@@ -160,7 +160,7 @@ public class Merlin extends CryptoBase {
}
this.properties = properties;
this.passwordEncryptor = passwordEncryptor;
-
+
String prefix = PREFIX;
for (Object key : properties.keySet()) {
if (key instanceof String) {
@@ -173,7 +173,7 @@ public class Merlin extends CryptoBase {
}
}
}
-
+
//
// Load the provider(s)
//
@@ -213,7 +213,7 @@ public class Merlin extends CryptoBase {
keystore = load(is, passwd, provider, type);
if (DO_DEBUG) {
LOG.debug(
- "The KeyStore " + keyStoreLocation + " of type " + type
+ "The KeyStore " + keyStoreLocation + " of type " + type
+ " has been loaded"
);
}
@@ -227,7 +227,7 @@ public class Merlin extends CryptoBase {
LOG.debug("The KeyStore is not loaded as KEYSTORE_FILE is null");
}
}
-
+
//
// Load the TrustStore
//
@@ -248,7 +248,7 @@ public class Merlin extends CryptoBase {
truststore = load(is, passwd, provider, type);
if (DO_DEBUG) {
LOG.debug(
- "The TrustStore " + trustStoreLocation + " of type " + type
+ "The TrustStore " + trustStoreLocation + " of type " + type
+ " has been loaded"
);
}
@@ -288,15 +288,15 @@ public class Merlin extends CryptoBase {
try (InputStream is = loadInputStream(loader, crlLocation)) {
CertificateFactory cf = getCertificateFactory();
X509CRL crl = (X509CRL)cf.generateCRL(is);
-
+
if (provider == null || provider.length() == 0) {
- crlCertStore =
+ crlCertStore =
CertStore.getInstance(
"Collection",
new CollectionCertStoreParameters(Collections.singletonList(crl))
);
} else {
- crlCertStore =
+ crlCertStore =
CertStore.getInstance(
"Collection",
new CollectionCertStoreParameters(Collections.singletonList(crl)),
@@ -317,11 +317,11 @@ public class Merlin extends CryptoBase {
}
}
-
+
/**
* Load a KeyStore object as an InputStream, using the ClassLoader and location arguments
*/
- public static InputStream loadInputStream(ClassLoader loader, String location)
+ public static InputStream loadInputStream(ClassLoader loader, String location)
throws WSSecurityException, IOException {
InputStream is = null;
if (location != null) {
@@ -329,7 +329,7 @@ public class Merlin extends CryptoBase {
if (url != null) {
is = url.openStream();
}
-
+
//
// If we don't find it, then look on the file system.
//
@@ -348,7 +348,7 @@ public class Merlin extends CryptoBase {
}
return is;
}
-
+
/**
* Loads the keystore from an <code>InputStream </code>.
@@ -357,17 +357,17 @@ public class Merlin extends CryptoBase {
* @param input <code>InputStream</code> to read from
* @throws WSSecurityException
*/
- protected KeyStore load(InputStream input, String storepass, String provider, String type)
+ protected KeyStore load(InputStream input, String storepass, String provider, String type)
throws WSSecurityException {
KeyStore ks = null;
-
+
try {
if (provider == null || provider.length() == 0) {
ks = KeyStore.getInstance(type);
} else {
ks = KeyStore.getInstance(type, provider);
}
-
+
ks.load(input, storepass == null || storepass.length() == 0
? new char[0] : storepass.toCharArray());
} catch (IOException | GeneralSecurityException e) {
@@ -378,11 +378,11 @@ public class Merlin extends CryptoBase {
}
return ks;
}
-
+
//
// Accessor methods
//
-
+
/**
* Gets the Keystore that was loaded
*
@@ -391,7 +391,7 @@ public class Merlin extends CryptoBase {
public KeyStore getKeyStore() {
return keystore;
}
-
+
/**
* Set the Keystore on this Crypto instance
*
@@ -400,7 +400,7 @@ public class Merlin extends CryptoBase {
public void setKeyStore(KeyStore keyStore) {
keystore = keyStore;
}
-
+
/**
* Gets the trust store that was loaded by the underlying implementation
*
@@ -409,7 +409,7 @@ public class Merlin extends CryptoBase {
public KeyStore getTrustStore() {
return truststore;
}
-
+
/**
* Set the trust store on this Crypto instance
*
@@ -418,27 +418,27 @@ public class Merlin extends CryptoBase {
public void setTrustStore(KeyStore trustStore) {
truststore = trustStore;
}
-
+
/**
* Set the CertStore from which to obtain a list of CRLs for Certificate Revocation
* checking.
- * @param crlCertStore the CertStore from which to obtain a list of CRLs for Certificate
+ * @param crlCertStore the CertStore from which to obtain a list of CRLs for Certificate
* Revocation checking.
*/
public void setCRLCertStore(CertStore crlCertStore) {
this.crlCertStore = crlCertStore;
}
-
+
/**
* Get the CertStore from which to obtain a list of CRLs for Certificate Revocation
* checking.
- * @return the CertStore from which to obtain a list of CRLs for Certificate
+ * @return the CertStore from which to obtain a list of CRLs for Certificate
* Revocation checking.
*/
public CertStore getCRLCertStore() {
return crlCertStore;
}
-
+
/**
* Singleton certificate factory for this Crypto instance.
* <p/>
@@ -452,18 +452,18 @@ public class Merlin extends CryptoBase {
if (certificateFactory != null) {
return certificateFactory;
}
-
+
String provider = getCryptoProvider();
String keyStoreProvider = null;
if (keystore != null) {
keyStoreProvider = keystore.getProvider().getName();
}
-
+
try {
if (provider == null || provider.length() == 0) {
if (keyStoreProvider != null && keyStoreProvider.length() != 0) {
try {
- certificateFactory =
+ certificateFactory =
CertificateFactory.getInstance(
"X.509", mapKeystoreProviderToCertProvider(keyStoreProvider)
);
@@ -491,18 +491,18 @@ public class Merlin extends CryptoBase {
return certificateFactory;
}
-
+
private String mapKeystoreProviderToCertProvider(String s) {
if ("SunJSSE".equals(s)) {
return "SUN";
}
return s;
}
-
+
/**
- * 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
+ * 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
* message. May return null. The identifier is implementation specific, e.g. it could be the
* KeyStore alias.
*
@@ -513,7 +513,7 @@ public class Merlin extends CryptoBase {
if (super.getDefaultX509Identifier() != null) {
return super.getDefaultX509Identifier();
}
-
+
if (keystore != null) {
try {
Enumeration<String> as = keystore.aliases();
@@ -528,11 +528,11 @@ public class Merlin extends CryptoBase {
throw new WSSecurityException(
WSSecurityException.ErrorCode.FAILURE, ex, "keystore"
);
- }
+ }
}
return null;
}
-
+
//
// Keystore-specific Crypto functionality methods
//
@@ -540,7 +540,7 @@ public class Merlin extends CryptoBase {
/**
* Get an X509Certificate (chain) corresponding to the CryptoType argument. The supported
* types are as follows:
- *
+ *
* TYPE.ISSUER_SERIAL - A certificate (chain) is located by the issuer name and serial number
* TYPE.THUMBPRINT_SHA1 - A certificate (chain) is located by the SHA1 of the (root) cert
* TYPE.SKI_BYTES - A certificate (chain) is located by the SKI bytes of the (root) cert
@@ -583,7 +583,7 @@ public class Merlin extends CryptoBase {
}
/**
- * Get the implementation-specific identifier corresponding to the cert parameter. In this
+ * Get the implementation-specific identifier corresponding to the cert parameter. In this
* case, the identifier corresponds to a KeyStore alias.
* @param cert The X509Certificate for which to search for an identifier
* @return the identifier corresponding to the cert parameter
@@ -591,18 +591,18 @@ public class Merlin extends CryptoBase {
*/
public String getX509Identifier(X509Certificate cert) throws WSSecurityException {
String identifier = null;
-
+
if (keystore != null) {
identifier = getIdentifier(cert, keystore);
}
-
+
if (identifier == null && truststore != null) {
identifier = getIdentifier(cert, truststore);
}
-
+
return identifier;
}
-
+
/**
* Gets the private key corresponding to the certificate.
*
@@ -611,25 +611,25 @@ public class Merlin extends CryptoBase {
* @return The private key
*/
public PrivateKey getPrivateKey(
- X509Certificate certificate,
+ X509Certificate certificate,
CallbackHandler callbackHandler
) throws WSSecurityException {
if (keystore == null) {
- throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
+ throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
new Object[] {"The keystore is null"});
}
if (callbackHandler == null) {
- throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
+ throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
new Object[] {"The CallbackHandler is null"});
}
-
+
String identifier = getIdentifier(certificate, keystore);
try {
if (identifier == null || !keystore.isKeyEntry(identifier)) {
String msg = "Cannot find key for alias: [" + identifier + "]";
String logMsg = createKeyStoreErrorMessage(keystore);
LOG.error(msg + logMsg);
- throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
+ throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
new Object[] {msg});
}
String password = getPassword(identifier, callbackHandler);
@@ -643,13 +643,13 @@ public class Merlin extends CryptoBase {
password = decryptPassword(password, passwordEncryptor);
}
}
- Key keyTmp = keystore.getKey(identifier, password == null
+ Key keyTmp = keystore.getKey(identifier, password == null
? new char[]{} : password.toCharArray());
if (!(keyTmp instanceof PrivateKey)) {
String msg = "Key is not a private key, alias: [" + identifier + "]";
String logMsg = createKeyStoreErrorMessage(keystore);
LOG.error(msg + logMsg);
- throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
+ throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
new Object[]{msg});
}
return (PrivateKey) keyTmp;
@@ -659,7 +659,7 @@ public class Merlin extends CryptoBase {
);
}
}
-
+
/**
* Gets the private key corresponding to the identifier.
*
@@ -680,7 +680,7 @@ public class Merlin extends CryptoBase {
String msg = "Cannot find key for alias: [" + identifier + "]";
String logMsg = createKeyStoreErrorMessage(keystore);
LOG.error(msg + logMsg);
- throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
+ throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
new Object[] {msg});
}
String pwd = password;
@@ -693,13 +693,13 @@ public class Merlin extends CryptoBase {
pwd = pwd.trim();
}
}
- Key keyTmp = keystore.getKey(identifier, pwd == null
+ Key keyTmp = keystore.getKey(identifier, pwd == null
? new char[]{} : pwd.toCharArray());
if (!(keyTmp instanceof PrivateKey)) {
String msg = "Key is not a private key, alias: [" + identifier + "]";
String logMsg = createKeyStoreErrorMessage(keystore);
LOG.error(msg + logMsg);
- throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
+ throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
new Object[] {msg});
}
return (PrivateKey) keyTmp;
@@ -709,18 +709,18 @@ public class Merlin extends CryptoBase {
);
}
}
-
+
/**
* Evaluate whether a given certificate chain should be trusted.
*
* @param certs Certificate chain to validate
* @param enableRevocation whether to enable CRL verification or not
* @param subjectCertConstraints A set of constraints on the Subject DN of the certificates
- *
+ *
* @throws WSSecurityException if the certificate chain is invalid
*/
public void verifyTrust(
- X509Certificate[] certs,
+ X509Certificate[] certs,
boolean enableRevocation,
Collection<Pattern> subjectCertConstraints
) throws WSSecurityException {
@@ -730,11 +730,11 @@ public class Merlin extends CryptoBase {
if (certs.length == 1 && !enableRevocation) {
String issuerString = certs[0].getIssuerX500Principal().getName();
BigInteger issuerSerial = certs[0].getSerialNumber();
-
+
CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ISSUER_SERIAL);
cryptoType.setIssuerSerial(issuerString, issuerSerial);
X509Certificate[] foundCerts = getX509Certificates(cryptoType);
-
+
//
// If a certificate has been found, the certificates must be compared
// to ensure against phony DNs (compare encoded form including signature)
@@ -755,9 +755,9 @@ public class Merlin extends CryptoBase {
return;
}
}
-
+
//
- // SECOND step - Search for the issuer cert (chain) of the transmitted certificate in the
+ // SECOND step - Search for the issuer cert (chain) of the transmitted certificate in the
// keystore or the truststore
//
X509Certificate[] x509certs = certs;
@@ -766,14 +766,14 @@ public class Merlin extends CryptoBase {
CryptoType cryptoType = new CryptoType(CryptoType.TYPE.SUBJECT_DN);
cryptoType.setSubjectDN(issuerString);
X509Certificate[] foundCerts = getX509Certificates(cryptoType);
-
+
// If the certs have not been found, the issuer is not in the keystore/truststore
// As a direct result, do not trust the transmitted certificate
if (foundCerts == null || foundCerts.length < 1) {
String subjectString = certs[0].getSubjectX500Principal().getName();
if (LOG.isDebugEnabled()) {
LOG.debug(
- "No certs found in keystore for issuer " + issuerString
+ "No certs found in keystore for issuer " + issuerString
+ " of certificate for " + subjectString
);
}
@@ -781,7 +781,7 @@ public class Merlin extends CryptoBase {
WSSecurityException.ErrorCode.FAILURE, "certpath", new Object[] {"No trusted certs found"}
);
}
-
+
//
// Form a certificate chain from the transmitted certificate
// and the certificate(s) of the issuer from the keystore/truststore
@@ -790,7 +790,7 @@ public class Merlin extends CryptoBase {
x509certs[0] = certs[0];
System.arraycopy(foundCerts, 0, x509certs, 1, foundCerts.length);
}
-
+
//
// THIRD step
// Check the certificate trust path for the issuer cert chain
@@ -800,7 +800,7 @@ public class Merlin extends CryptoBase {
"Preparing to validate certificate path for issuer " + issuerString
);
}
-
+
try {
// Generate cert path
List<X509Certificate> certList = Arrays.asList(x509certs);
@@ -811,10 +811,10 @@ public class Merlin extends CryptoBase {
Enumeration<String> truststoreAliases = truststore.aliases();
while (truststoreAliases.hasMoreElements()) {
String alias = truststoreAliases.nextElement();
- X509Certificate cert =
+ X509Certificate cert =
(X509Certificate) truststore.getCertificate(alias);
if (cert != null) {
- TrustAnchor anchor =
+ TrustAnchor anchor =
new TrustAnchor(cert, cert.getExtensionValue(NAME_CONSTRAINTS_OID));
set.add(anchor);
}
@@ -830,10 +830,10 @@ public class Merlin extends CryptoBase {
Enumeration<String> aliases = keystore.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
- X509Certificate cert =
+ X509Certificate cert =
(X509Certificate) keystore.getCertificate(alias);
if (cert != null) {
- TrustAnchor anchor =
+ TrustAnchor anchor =
new TrustAnchor(cert, cert.getExtensionValue(NAME_CONSTRAINTS_OID));
set.add(anchor);
}
@@ -848,24 +848,24 @@ public class Merlin extends CryptoBase {
} else {
validator = CertPathValidator.getInstance("PKIX", provider);
}
-
+
PKIXParameters param = createPKIXParameters(set, enableRevocation);
validator.validate(path, param);
- } catch (NoSuchProviderException | NoSuchAlgorithmException
+ } catch (NoSuchProviderException | NoSuchAlgorithmException
| CertificateException | InvalidAlgorithmParameterException
- | java.security.cert.CertPathValidatorException
+ | java.security.cert.CertPathValidatorException
| KeyStoreException e) {
throw new WSSecurityException(
WSSecurityException.ErrorCode.FAILURE, e, "certpath"
);
}
-
+
// Finally check Cert Constraints
if (!matches(certs[0], subjectCertConstraints)) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_AUTHENTICATION);
}
}
-
+
// Separated out to allow subclasses to override it
protected PKIXParameters createPKIXParameters(
Set<TrustAnchor> trustAnchors, boolean enableRevocation
@@ -875,13 +875,13 @@ public class Merlin extends CryptoBase {
if (enableRevocation && crlCertStore != null) {
param.addCertStore(crlCertStore);
}
-
+
return param;
}
-
+
/**
* Evaluate whether a given public key should be trusted.
- *
+ *
* @param publicKey The PublicKey to be evaluated
* @throws WSSecurityException if the PublicKey is invalid
*/
@@ -892,7 +892,7 @@ public class Merlin extends CryptoBase {
if (publicKey == null) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_AUTHENTICATION);
}
-
+
//
// Search the keystore for the transmitted public key (direct trust). If not found
// then search the truststore for the transmitted public key (direct trust)
@@ -902,7 +902,7 @@ public class Merlin extends CryptoBase {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_AUTHENTICATION);
}
}
-
+
/**
* Get an X509 Certificate (chain) according to a given serial number and issuer string.
*
@@ -912,7 +912,7 @@ public class Merlin extends CryptoBase {
* @throws WSSecurityException
*/
private X509Certificate[] getX509Certificates(
- String issuer,
+ String issuer,
BigInteger serialNumber
) throws WSSecurityException {
//
@@ -939,24 +939,24 @@ public class Merlin extends CryptoBase {
if ((certs == null || certs.length == 0) && truststore != null) {
certs = getCertificates(issuerName, serialNumber, truststore);
}
-
+
if (certs == null || certs.length == 0) {
return null;
}
-
+
return Arrays.copyOf(certs, certs.length, X509Certificate[].class);
}
-
+
/**
- * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore
+ * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore
* @param issuerRDN either an X500Principal or a BouncyCastle X509Name instance.
* @param store The KeyStore
* @return an X509 Certificate (chain)
* @throws WSSecurityException
*/
private Certificate[] getCertificates(
- Object issuerRDN,
- BigInteger serialNumber,
+ Object issuerRDN,
+ BigInteger serialNumber,
KeyStore store
) throws WSSecurityException {
try {
@@ -970,11 +970,11 @@ public class Merlin extends CryptoBase {
certs = new Certificate[]{cert};
}
}
-
+
if (certs != null && certs.length > 0 && certs[0] instanceof X509Certificate) {
X509Certificate x509cert = (X509Certificate) certs[0];
if (x509cert.getSerialNumber().compareTo(serialNumber) == 0) {
- Object certName =
+ Object certName =
createBCX509Name(x509cert.getIssuerX500Principal().getName());
if (certName.equals(issuerRDN)) {
return certs;
@@ -989,7 +989,7 @@ public class Merlin extends CryptoBase {
}
return new Certificate[]{};
}
-
+
/**
* Get an X509 Certificate (chain) according to a given Thumbprint.
*
@@ -999,7 +999,7 @@ public class Merlin extends CryptoBase {
*/
private X509Certificate[] getX509Certificates(byte[] thumbprint) throws WSSecurityException {
MessageDigest sha = null;
-
+
try {
sha = MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException e) {
@@ -1016,23 +1016,23 @@ public class Merlin extends CryptoBase {
if ((certs == null || certs.length == 0) && truststore != null) {
certs = getCertificates(thumbprint, truststore, sha);
}
-
+
if (certs == null || certs.length == 0) {
return null;
}
-
+
return Arrays.copyOf(certs, certs.length, X509Certificate[].class);
}
/**
- * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore
+ * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore
* @param thumbprint
* @param store The KeyStore
* @return an X509 Certificate (chain)
* @throws WSSecurityException
*/
private Certificate[] getCertificates(
- byte[] thumbprint,
+ byte[] thumbprint,
KeyStore store,
MessageDigest sha
) throws WSSecurityException {
@@ -1047,7 +1047,7 @@ public class Merlin extends CryptoBase {
certs = new Certificate[]{cert};
}
}
-
+
if (certs != null && certs.length > 0 && certs[0] instanceof X509Certificate) {
X509Certificate x509cert = (X509Certificate) certs[0];
try {
@@ -1071,7 +1071,7 @@ public class Merlin extends CryptoBase {
}
return new Certificate[]{};
}
-
+
/**
* Get an X509 Certificate (chain) according to a given SubjectKeyIdentifier.
*
@@ -1088,23 +1088,23 @@ public class Merlin extends CryptoBase {
if ((certs == null || certs.length == 0) && truststore != null) {
certs = getCertificates(skiBytes, truststore);
}
-
+
if (certs == null || certs.length == 0) {
return null;
}
-
+
return Arrays.copyOf(certs, certs.length, X509Certificate[].class);
}
-
+
/**
- * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore
+ * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore
* @param skiBytes
* @param store The KeyStore
* @return an X509 Certificate (chain)
* @throws WSSecurityException
*/
private Certificate[] getCertificates(
- byte[] skiBytes,
+ byte[] skiBytes,
KeyStore store
) throws WSSecurityException {
try {
@@ -1118,7 +1118,7 @@ public class Merlin extends CryptoBase {
certs = new Certificate[]{cert};
}
}
-
+
if (certs != null && certs.length > 0 && certs[0] instanceof X509Certificate) {
X509Certificate x509cert = (X509Certificate) certs[0];
byte[] data = getSKIBytesFromCert(x509cert);
@@ -1134,7 +1134,7 @@ public class Merlin extends CryptoBase {
}
return new Certificate[]{};
}
-
+
/**
* Get an X509 Certificate (chain) according to a given DN of the subject of the certificate
*
@@ -1158,7 +1158,7 @@ public class Merlin extends CryptoBase {
} catch (java.lang.IllegalArgumentException ex) {
subject = createBCX509Name(subjectDN);
}
-
+
Certificate[] certs = null;
if (keystore != null) {
certs = getCertificates(subject, keystore);
@@ -1168,18 +1168,18 @@ public class Merlin extends CryptoBase {
if ((certs == null || certs.length == 0) && truststore != null) {
certs = getCertificates(subject, truststore);
}
-
+
if (certs == null || certs.length == 0) {
return null;
}
-
+
return Arrays.copyOf(certs, certs.length, X509Certificate[].class);
}
-
+
/**
* Get an X509 Certificate (chain) that correspond to the identifier. For this implementation,
* the identifier corresponds to the KeyStore alias.
- *
+ *
* @param identifier The identifier that corresponds to the returned certs
* @return an X509 Certificate (chain) that corresponds to the identifier
*/
@@ -1218,9 +1218,9 @@ public class Merlin extends CryptoBase {
return Arrays.copyOf(certs, certs.length, X509Certificate[].class);
}
-
+
/**
- * Find the Public Key in a keystore.
+ * Find the Public Key in a keystore.
*/
private boolean findPublicKeyInKeyStore(PublicKey publicKey, KeyStore keyStoreToSearch) {
if (keyStoreToSearch == null) {
@@ -1237,7 +1237,7 @@ public class Merlin extends CryptoBase {
certs = new Certificate[]{cert};
}
}
-
+
if (certs != null && certs.length > 0 && certs[0] instanceof X509Certificate
&& publicKey.equals(((X509Certificate)certs[0]).getPublicKey())) {
return true;
@@ -1248,15 +1248,15 @@ public class Merlin extends CryptoBase {
}
return false;
}
-
+
/**
- * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore
+ * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore
* @param subjectRDN either an X500Principal or a BouncyCastle X509Name instance.
* @param store The KeyStore
* @return an X509 Certificate (chain)
* @throws WSSecurityException
*/
- private Certificate[] getCertificates(Object subjectRDN, KeyStore store)
+ private Certificate[] getCertificates(Object subjectRDN, KeyStore store)
throws WSSecurityException {
try {
for (Enumeration<String> e = store.aliases(); e.hasMoreElements();) {
@@ -1285,7 +1285,7 @@ public class Merlin extends CryptoBase {
}
return new Certificate[]{};
}
-
+
private static String createKeyStoreErrorMessage(KeyStore keystore) throws KeyStoreException {
Enumeration<String> aliases = keystore.aliases();
StringBuilder sb = new StringBuilder(keystore.size() * 7);
@@ -1303,7 +1303,7 @@ public class Merlin extends CryptoBase {
+ sb.toString() + "}";
return msg;
}
-
+
/**
* Get an implementation-specific identifier that corresponds to the X509Certificate. In
* this case, the identifier is the KeyStore alias.
@@ -1316,7 +1316,7 @@ public class Merlin extends CryptoBase {
try {
for (Enumeration<String> e = store.aliases(); e.hasMoreElements();) {
String alias = e.nextElement();
-
+
Certificate[] certs = store.getCertificateChain(alias);
if (certs == null || certs.length == 0) {
// no cert chain, so lets check if getCertificate gives us a result.
@@ -1325,7 +1325,7 @@ public class Merlin extends CryptoBase {
certs = new Certificate[]{retrievedCert};
}
}
-
+
if (certs != null && certs.length > 0 && certs[0].equals(cert)) {
return alias;
}
@@ -1335,7 +1335,7 @@ public class Merlin extends CryptoBase {
}
return null;
}
-
+
/**
* Get a password from the CallbackHandler
* @param identifier The identifier to give to the Callback
@@ -1347,7 +1347,7 @@ public class Merlin extends CryptoBase {
String identifier,
CallbackHandler cb
) throws WSSecurityException {
- WSPasswordCallback pwCb =
+ WSPasswordCallback pwCb =
new WSPasswordCallback(identifier, WSPasswordCallback.DECRYPT);
try {
Callback[] callbacks = new Callback[]{pwCb};
@@ -1360,24 +1360,24 @@ public class Merlin extends CryptoBase {
return pwCb.getPassword();
}
-
+
protected String decryptPassword(String password, PasswordEncryptor passwordEncryptor) {
if (password.startsWith(ENCRYPTED_PASSWORD_PREFIX)
&& password.endsWith(ENCRYPTED_PASSWORD_SUFFIX)) {
if (passwordEncryptor == null) {
- String error =
+ String error =
"The Crypto properties has an encrypted password, but no PasswordEncryptor is configured!";
LOG.debug(error);
return password;
}
- String substring = password.substring(ENCRYPTED_PASSWORD_PREFIX.length(),
+ String substring = password.substring(ENCRYPTED_PASSWORD_PREFIX.length(),
password.length() - 1);
return passwordEncryptor.decrypt(substring);
}
-
+
return password;
}
-
+
public void setPasswordEncryptor(PasswordEncryptor passwordEncryptor) {
this.passwordEncryptor = passwordEncryptor;
}