From scm-return-47283-apmail-geronimo-scm-archive=geronimo.apache.org@geronimo.apache.org Wed Sep 7 09:22:05 2011 Return-Path: X-Original-To: apmail-geronimo-scm-archive@www.apache.org Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 38E728B93 for ; Wed, 7 Sep 2011 09:22:05 +0000 (UTC) Received: (qmail 1143 invoked by uid 500); 7 Sep 2011 09:22:00 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 981 invoked by uid 500); 7 Sep 2011 09:21:36 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 965 invoked by uid 99); 7 Sep 2011 09:21:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Sep 2011 09:21:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Sep 2011 09:21:31 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3FEB2238889B; Wed, 7 Sep 2011 09:21:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1166076 - /geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandUnlockKeystore.java Date: Wed, 07 Sep 2011 09:21:11 -0000 To: scm@geronimo.apache.org From: genspring@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110907092111.3FEB2238889B@eris.apache.org> Author: genspring Date: Wed Sep 7 09:21:10 2011 New Revision: 1166076 URL: http://svn.apache.org/viewvc?rev=1166076&view=rev Log: GERONIMO-5708 Track: Unlock keystore command line utility does not work with Configured Encryption. Patch from Yi Xiao Modified: geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandUnlockKeystore.java Modified: geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandUnlockKeystore.java URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandUnlockKeystore.java?rev=1166076&r1=1166075&r2=1166076&view=diff ============================================================================== --- geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandUnlockKeystore.java (original) +++ geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandUnlockKeystore.java Wed Sep 7 09:21:10 2011 @@ -118,12 +118,28 @@ public class CommandUnlockKeystore exten /* * Returns the password for private key alias */ - private String getKeyAliasPassword(Properties properties, String keyStoreName, String aliasName) throws DeploymentException { + private String getKeyAliasPassword(Properties properties, String keyStoreName, String aliasName, Kernel kernel) throws DeploymentException { String aliasPassword = properties.getProperty(aliasName); + AbstractName abstractName=null; + String decryptedPassword=null; if (aliasPassword == null) { throw new DeploymentException("No alias with the name " + aliasName + " exists in the kyeStoreTruststore password properties file::" + System.getProperty(KEYSTORE_TRUSTSTORE_PASSWORD_FILE, DEFAULT_KEYSTORE_TRUSTSTORE_PASSWORD_FILE)); } - return (String) EncryptionManager.decrypt(aliasPassword); + AbstractNameQuery abstractNameQuery = new AbstractNameQuery("org.apache.geronimo.system.util.EncryptionManagerWrapperGBean"); + Iterator it = kernel.listGBeans(abstractNameQuery).iterator(); + abstractName = it.next(); + try { + decryptedPassword=(String)kernel.invoke(abstractName,"decrypt",new Object[]{aliasPassword},new String[] {"java.lang.String"}); + } catch (GBeanNotFoundException e) { + throw new DeploymentException("Unable to find the gbean with the abstractname:: " + abstractName, e); + } catch (NoSuchOperationException e) { + throw new DeploymentException("No method decrypt available with:: " + abstractName, e); + } catch (InternalKernelException e) { + throw new DeploymentException(); + } catch (Exception e) { + throw new DeploymentException(); + } + return decryptedPassword; } /* @@ -131,8 +147,8 @@ public class CommandUnlockKeystore exten */ public AbstractName getKeyStoreAbstractName(Kernel kernel, String keyStoreName) throws DeploymentException { AbstractNameQuery abstractNameQuery = new AbstractNameQuery("org.apache.geronimo.management.geronimo.KeystoreInstance"); - for (Iterator it = kernel.listGBeans(abstractNameQuery).iterator(); it.hasNext();) { - AbstractName abstractName = (AbstractName) it.next(); + for (Iterator it = kernel.listGBeans(abstractNameQuery).iterator(); it.hasNext();) { + AbstractName abstractName = it.next(); String curKeyStoreName; try { curKeyStoreName = (String) kernel.getAttribute(abstractName, "keystoreName"); @@ -149,20 +165,36 @@ public class CommandUnlockKeystore exten /* * Returns the key store password */ - private String getKeyStorePassword(Properties properties, String keyStoreName) throws DeploymentException { + private String getKeyStorePassword(Properties properties, String keyStoreName, Kernel kernel) throws DeploymentException { String keyStorePassword = properties.getProperty(keyStoreName); + AbstractName abstractName=null; + String decryptedPassword=null; if (keyStorePassword == null) { throw new DeploymentException("No keyStorePassword attribute named " + keyStoreName + " exists in the kyeStoreTruststore password properties file::" + System.getProperty(KEYSTORE_TRUSTSTORE_PASSWORD_FILE, DEFAULT_KEYSTORE_TRUSTSTORE_PASSWORD_FILE)); } - return (String) EncryptionManager.decrypt(keyStorePassword); + AbstractNameQuery abstractNameQuery = new AbstractNameQuery("org.apache.geronimo.system.util.EncryptionManagerWrapperGBean"); + Iterator it = kernel.listGBeans(abstractNameQuery).iterator(); + abstractName = it.next(); + try { + decryptedPassword=(String)kernel.invoke(abstractName,"decrypt",new Object[]{keyStorePassword},new String[] {"java.lang.String"}); + } catch (GBeanNotFoundException e) { + throw new DeploymentException("Unable to find the gbean with the abstractname:: " + abstractName, e); + } catch (NoSuchOperationException e) { + throw new DeploymentException("No method decrypt available with:: " + abstractName, e); + } catch (InternalKernelException e) { + throw new DeploymentException(); + } catch (Exception e) { + throw new DeploymentException(); + } + return decryptedPassword; } /* * method to unlock a private key */ public boolean unlockKeyAlias(Kernel kernel, AbstractName keyStoreAbName, Properties properties, String keyStoreName, String aliasName) throws DeploymentException, FileNotFoundException { - char[] aliasPassword = getKeyAliasPassword(properties, keyStoreName, aliasName).toCharArray(); - char[] keyStorePassword = getKeyStorePassword(properties, keyStoreName).toCharArray(); + char[] aliasPassword = getKeyAliasPassword(properties, keyStoreName, aliasName,kernel).toCharArray(); + char[] keyStorePassword = getKeyStorePassword(properties, keyStoreName,kernel).toCharArray(); boolean success = false; Object[] argsVariable = new Object[] { aliasName, keyStorePassword, aliasPassword }; String[] argsType = new String[] { aliasName.getClass().getName(), keyStorePassword.getClass().getName(), aliasPassword.getClass().getName() }; @@ -183,7 +215,7 @@ public class CommandUnlockKeystore exten * Method to unlock a keystore */ public void unLockKeyStore(Kernel kernel, AbstractName keyStoreAbName, Properties properties, String keyStoreName) throws DeploymentException { - char[] keyStorepassword = getKeyStorePassword(properties, keyStoreName).toCharArray(); + char[] keyStorepassword = getKeyStorePassword(properties, keyStoreName,kernel).toCharArray(); try { kernel.invoke(keyStoreAbName, "unlockKeystore", new Object[] { keyStorepassword }, new String[] { keyStorepassword.getClass().getName() }); } catch (GBeanNotFoundException e) {