Repository: camel Updated Branches: refs/heads/master 6663813ee -> 6bd3ad920
[CAMEL-8045] - Not possible to load a public key from a a PrivateKeyEntry in a keystore Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6bd3ad92 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6bd3ad92 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6bd3ad92 Branch: refs/heads/master Commit: 6bd3ad92090ab24dfb7856456c742b0823539f80 Parents: 6663813 Author: Colm O hEigeartaigh <cohei...@apache.org> Authored: Thu Nov 13 11:15:39 2014 +0000 Committer: Colm O hEigeartaigh <cohei...@apache.org> Committed: Thu Nov 13 11:16:09 2014 +0000 ---------------------------------------------------------------------- .../xmlsecurity/XMLSecurityDataFormat.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/6bd3ad92/components/camel-xmlsecurity/src/main/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-xmlsecurity/src/main/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormat.java b/components/camel-xmlsecurity/src/main/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormat.java index 8705015..3e816c5 100755 --- a/components/camel-xmlsecurity/src/main/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormat.java +++ b/components/camel-xmlsecurity/src/main/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormat.java @@ -29,7 +29,6 @@ import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PrivilegedAction; import java.security.PrivilegedExceptionAction; -import java.security.PublicKey; import java.security.spec.InvalidKeySpecException; import java.util.Arrays; import java.util.Map; @@ -459,7 +458,9 @@ public class XMLSecurityDataFormat implements DataFormat, CamelContextAware { throw new IllegalStateException("A trust store must be defined for asymmetric key encryption."); } - Key keyEncryptionKey = getPublicKey(this.trustStore, exchangeRecipientAlias, this.trustStorePassword); + String password = + this.keyPassword != null ? this.keyPassword : this.trustStorePassword; + Key keyEncryptionKey = getPublicKey(this.trustStore, exchangeRecipientAlias, password); if (null == keyEncryptionKey) { throw new IllegalStateException("No key for the alias [ " + exchangeRecipientAlias @@ -520,15 +521,12 @@ public class XMLSecurityDataFormat implements DataFormat, CamelContextAware { */ // TODO Move this to a crypto utility class private Key getPublicKey(KeyStore keystore, String alias, String password) throws Exception { - Key key = keystore.getKey(alias, password.toCharArray()); - if (key instanceof PublicKey) { - return key; - } else { - java.security.cert.Certificate cert = keystore.getCertificate(alias); + java.security.cert.Certificate cert = keystore.getCertificate(alias); + if (cert != null) { // Get public key - PublicKey publicKey = cert.getPublicKey(); - return publicKey; + return cert.getPublicKey(); } + return keystore.getKey(alias, password.toCharArray()); } @@ -581,6 +579,8 @@ public class XMLSecurityDataFormat implements DataFormat, CamelContextAware { || keyCipherAlgorithm.equals(XMLCipher.RSA_OAEP_11))) { return decodeWithAsymmetricKey(exchange, encodedDocument); } else { + LOG.debug("No (known) asymmetric keyCipherAlgorithm specified. Attempting to " + + "decrypt using a symmetric key"); return decodeWithSymmetricKey(exchange, encodedDocument); } }