Repository: camel Updated Branches: refs/heads/camel-2.13.x ebf9b1fa6 -> 2c67e29d0
[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/2c67e29d Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2c67e29d Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2c67e29d Branch: refs/heads/camel-2.13.x Commit: 2c67e29d0d51659d634246a6951324275cb06ebf Parents: ebf9b1f 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:25:32 2014 +0000 ---------------------------------------------------------------------- .../xmlsecurity/XMLSecurityDataFormat.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/2c67e29d/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 14751f1..91ebf6f 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 @@ -514,15 +515,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()); } @@ -575,6 +573,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); } }