Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3AE71FE4D for ; Thu, 13 Nov 2014 11:27:54 +0000 (UTC) Received: (qmail 72440 invoked by uid 500); 13 Nov 2014 11:27:54 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 72388 invoked by uid 500); 13 Nov 2014 11:27:54 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 72379 invoked by uid 99); 13 Nov 2014 11:27:54 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Nov 2014 11:27:54 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C095BA13C2F; Thu, 13 Nov 2014 11:27:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: coheigea@apache.org To: commits@camel.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: camel git commit: [CAMEL-8045] - Not possible to load a public key from a a PrivateKeyEntry in a keystore Date: Thu, 13 Nov 2014 11:27:53 +0000 (UTC) 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 Authored: Thu Nov 13 11:15:39 2014 +0000 Committer: Colm O hEigeartaigh 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); } }