You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ge...@apache.org on 2011/09/07 11:21:11 UTC

svn commit: r1166076 - /geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandUnlockKeystore.java

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<AbstractName> 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<AbstractName> 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<AbstractName> 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) {