Copied: 
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/security/secret/repository/FileBaseSecretRepositoryProvider.java
 (from r925986, 
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/security/secret/repository/filebased/FileBaseSecretRepositoryProvider.java)
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/security/secret/repository/FileBaseSecretRepositoryProvider.java?p2=synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/security/secret/repository/FileBaseSecretRepositoryProvider.java&p1=synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/security/secret/repository/filebased/FileBaseSecretRepositoryProvider.java&r1=925986&r2=935815&rev=935815&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/security/secret/repository/filebased/FileBaseSecretRepositoryProvider.java
 (original)
+++ 
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/security/secret/repository/FileBaseSecretRepositoryProvider.java
 Tue Apr 20 06:37:36 2010
@@ -16,12 +16,12 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.synapse.commons.security.secret.repository.filebased;
+package org.apache.synapse.commons.security.secret.repository;
 
+import org.apache.synapse.commons.security.keystore.IdentityKeyStoreWrapper;
+import org.apache.synapse.commons.security.keystore.TrustKeyStoreWrapper;
 import org.apache.synapse.commons.security.secret.SecretRepository;
 import org.apache.synapse.commons.security.secret.SecretRepositoryProvider;
-import org.apache.synapse.commons.security.wrappers.IdentityKeyStoreWrapper;
-import org.apache.synapse.commons.security.wrappers.TrustKeyStoreWrapper;
 
 
 /**

Modified: 
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/security/tool/CipherTool.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/security/tool/CipherTool.java?rev=935815&r1=935814&r2=935815&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/security/tool/CipherTool.java
 (original)
+++ 
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/security/tool/CipherTool.java
 Tue Apr 20 06:37:36 2010
@@ -21,20 +21,17 @@ package org.apache.synapse.commons.secur
 import org.apache.commons.cli.*;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.commons.security.secret.SecretInformation;
+import org.apache.synapse.commons.SynapseCommonsException;
+import org.apache.synapse.commons.security.*;
 import org.apache.synapse.commons.security.definition.CipherInformation;
 import 
org.apache.synapse.commons.security.definition.IdentityKeyStoreInformation;
 import org.apache.synapse.commons.security.definition.TrustKeyStoreInformation;
-import org.apache.synapse.commons.security.enumeration.CipherOperationMode;
-import org.apache.synapse.commons.security.enumeration.EncodingType;
-import org.apache.synapse.commons.security.enumeration.KeyStoreType;
-import org.apache.synapse.commons.security.wrappers.CipherWrapper;
-import org.apache.synapse.commons.security.wrappers.IdentityKeyStoreWrapper;
-import org.apache.synapse.commons.security.wrappers.TrustKeyStoreWrapper;
-import org.apache.synapse.commons.SynapseCommonsException;
+import org.apache.synapse.commons.security.keystore.IdentityKeyStoreWrapper;
+import org.apache.synapse.commons.security.keystore.KeyStoreWrapper;
+import org.apache.synapse.commons.security.keystore.TrustKeyStoreWrapper;
+import org.apache.synapse.commons.security.secret.SecretInformation;
 
 import javax.crypto.spec.SecretKeySpec;
-
 import java.io.*;
 import java.security.Key;
 
@@ -57,7 +54,7 @@ import java.security.Key;
  * <li>algorithm    encrypt or decrypt algorithm (default RSA)
  * <li>outencode    Currently BASE64 or BIGINTEGER16
  * <li>inencode     Currently BASE64 or BIGINTEGER16
- * 
+ * <p/>
  * <ul>
  */
 public final class CipherTool {
@@ -112,7 +109,8 @@ public final class CipherTool {
 
     private static Log log = LogFactory.getLog(CipherTool.class);
 
-    private CipherTool() {}
+    private CipherTool() {
+    }
 
     public static void main(String[] args) throws Exception {
 
@@ -137,8 +135,17 @@ public final class CipherTool {
 
             // if pass phrase is specified, use simple symmetric en-/decryption
             String passphrase = getArgument(cmd, PASSPHRASE, null);
+            boolean isEncrypt = (cipherInformation.getCipherOperationMode() ==
+                    CipherOperationMode.ENCRYPT);
+            EncryptionProvider encryptionProvider = null;
+            DecryptionProvider decryptionProvider = null;
             if (passphrase != null) {
                 key = new SecretKeySpec(passphrase.getBytes(), 
cipherInformation.getAlgorithm());
+                if (isEncrypt) {
+                    encryptionProvider = 
CipherFactory.createCipher(cipherInformation, key);
+                } else {
+                    decryptionProvider = 
CipherFactory.createCipher(cipherInformation, key);
+                }
             } else {
                 // Key information must not contain any password
                 // If Key need to be loaded from a file
@@ -147,35 +154,38 @@ public final class CipherTool {
                 boolean isTrusted = isArgumentPresent(cmd, TRUSTED);
                 if (keyFile != null) {
                     key = getKey(keyFile);
+                    if (isEncrypt) {
+                        encryptionProvider = 
CipherFactory.createCipher(cipherInformation, key);
+                    } else {
+                        decryptionProvider = 
CipherFactory.createCipher(cipherInformation, key);
+                    }
                 } else {
+                    KeyStoreWrapper keyStoreWrapper;
                     if (isTrusted) {
-                        TrustKeyStoreWrapper trustKeyStoreWrapper = new 
TrustKeyStoreWrapper();
-                        
trustKeyStoreWrapper.init(getTrustKeyStoreInformation(cmd));
-                        key = trustKeyStoreWrapper.getPublicKey();
+                        keyStoreWrapper = new TrustKeyStoreWrapper();
+                        ((TrustKeyStoreWrapper) 
keyStoreWrapper).init(getTrustKeyStoreInformation(cmd));
                     } else {
-                        IdentityKeyStoreWrapper storeWrapper = new 
IdentityKeyStoreWrapper();
+                        keyStoreWrapper = new IdentityKeyStoreWrapper();
                         //Password for access private key
                         String keyPass = getArgument(cmd, KEY_PASS, null);
                         assertEmpty(keyPass, KEY_PASS);
-                        storeWrapper.init(getIdentityKeyStoreInformation(cmd), 
keyPass);
-                        if (cipherInformation.getCipherOperationMode() == 
CipherOperationMode.ENCRYPT) {
-                            key = storeWrapper.getPublicKey();
-                        } else {
-                            key = storeWrapper.getPrivateKey();
-                        }
+                        ((IdentityKeyStoreWrapper) keyStoreWrapper).init(
+                                getIdentityKeyStoreInformation(cmd), keyPass);
+                    }
+                    if (isEncrypt) {
+                        encryptionProvider = 
CipherFactory.createCipher(cipherInformation, keyStoreWrapper);
+                    } else {
+                        decryptionProvider = 
CipherFactory.createCipher(cipherInformation, keyStoreWrapper);
                     }
                 }
             }
 
-            if (key == null) {
-                handleException("Cannot find a key ");
-            }
-
-            CipherWrapper cipherWrapper = new CipherWrapper(cipherInformation, 
key);
-            ByteArrayInputStream in = new 
ByteArrayInputStream(source.getBytes());
-
             PrintStream out = System.out;
-            out.println("Output : " + cipherWrapper.getSecret(in));
+            if (isEncrypt) {
+                out.println("Output : " + 
encryptionProvider.encrypt(source.getBytes()));
+            } else {
+                out.println("Output : " + 
decryptionProvider.decrypt(source.getBytes()));
+            }
 
         } catch (ParseException e) {
             handleException("Error passing arguments ", e);
@@ -250,10 +260,10 @@ public final class CipherTool {
         if (encInType != null) {
             
information.setInType(EncodingType.valueOf(encInType.toUpperCase()));
         }
-        
+
         String encOutType = getArgument(cmd, OUT_TYPE, null);
         if (encOutType != null) {
-            
information.setOutType(EncodingType.valueOf(encOutType.toUpperCase()));    
+            
information.setOutType(EncodingType.valueOf(encOutType.toUpperCase()));
         }
 
         information.setType(getArgument(cmd, CIPHER_TYPE, null));
@@ -321,9 +331,9 @@ public final class CipherTool {
         Option source = new Option(SOURCE_IN_LINED, true, "Plain text 
in-lined");
         Option sourceFile = new Option(SOURCE_FILE, true, "Plain text from a 
file");
 
-        Option passphrase = new Option(PASSPHRASE, true, 
+        Option passphrase = new Option(PASSPHRASE, true,
                 "Passphrase to use for symmetric en- or decryption.");
-        
+
         Option keyStore = new Option(KEY_STORE, true, "Private key entry 
KeyStore");
         Option storeType = new Option(STORE_TYPE, true, " KeyStore type");
         Option storePassword = new Option(STORE_PASS, true, "Password for 
keyStore access");
@@ -342,7 +352,7 @@ public final class CipherTool {
 
         options.addOption(source);
         options.addOption(sourceFile);
-        
+
         options.addOption(passphrase);
         options.addOption(keyStore);
         options.addOption(storeType);

Modified: 
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/util/MiscellaneousUtil.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/util/MiscellaneousUtil.java?rev=935815&r1=935814&r2=935815&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/util/MiscellaneousUtil.java
 (original)
+++ 
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/util/MiscellaneousUtil.java
 Tue Apr 20 06:37:36 2010
@@ -29,6 +29,7 @@ import java.util.Properties;
  *
  */
 public class MiscellaneousUtil {
+
     private static Log log = LogFactory.getLog(MiscellaneousUtil.class);
 
     private MiscellaneousUtil() {
@@ -182,6 +183,32 @@ public class MiscellaneousUtil {
         return result;
     }
 
+    public static byte[] asBytes(InputStream in) {
+
+          ByteArrayOutputStream out = new ByteArrayOutputStream();
+          byte[] buffer = new byte[1024];
+          int len;
+          try {
+              while ((len = in.read(buffer)) >= 0)
+                  out.write(buffer, 0, len);
+          } catch (IOException e) {
+              throw new SynapseCommonsException("Error during converting a 
inputstream " +
+                      "into a bytearray ", e, log);
+          } finally {
+              if (in != null) {
+                  try {
+                      in.close();
+                  } catch (IOException ignored) {
+                  }
+              }
+              try {
+                  out.close();
+              } catch (IOException ignored) {
+              }
+          }
+          return out.toByteArray();
+      }
+
 
     /**
      * Helper methods for handle errors.

Modified: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SecretManagerAdminMBeanImpl.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SecretManagerAdminMBeanImpl.java?rev=935815&r1=935814&r2=935815&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SecretManagerAdminMBeanImpl.java
 (original)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SecretManagerAdminMBeanImpl.java
 Tue Apr 20 06:37:36 2010
@@ -20,7 +20,7 @@ package org.apache.synapse;
 
 import org.apache.synapse.config.SynapsePropertiesLoader;
 import org.apache.synapse.commons.security.secret.SecretManager;
-import org.apache.synapse.commons.security.mbean.SecretManagerAdminMBean;
+import 
org.apache.synapse.commons.security.secret.mbean.SecretManagerAdminMBean;
 
 import javax.management.StandardMBean;
 import javax.management.NotCompliantMBeanException;

Modified: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java?rev=935815&r1=935814&r2=935815&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
 (original)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
 Tue Apr 20 06:37:36 2010
@@ -30,9 +30,8 @@ import org.apache.synapse.aspects.Aspect
 import org.apache.synapse.aspects.statistics.StatisticsCollector;
 import 
org.apache.synapse.commons.security.definition.IdentityKeyStoreInformation;
 import org.apache.synapse.commons.security.definition.KeyStoreInformation;
+import 
org.apache.synapse.commons.security.definition.KeyStoreInformationFactory;
 import org.apache.synapse.commons.security.definition.TrustKeyStoreInformation;
-import 
org.apache.synapse.commons.security.definition.factory.KeyStoreInformationFactory;
-import org.apache.synapse.config.xml.XMLConfigConstants;
 import org.apache.synapse.core.SynapseEnvironment;
 import org.apache.synapse.mediators.MediatorProperty;
 import org.apache.synapse.mediators.base.SequenceMediator;

Modified: synapse/trunk/java/repository/conf/synapse.properties
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/synapse.properties?rev=935815&r1=935814&r2=935815&view=diff
==============================================================================
--- synapse/trunk/java/repository/conf/synapse.properties (original)
+++ synapse/trunk/java/repository/conf/synapse.properties Tue Apr 20 06:37:36 
2010
@@ -52,7 +52,7 @@
 
#synapse.secretProvider=org.apache.synapse.commons.security.secret.handler.JBossEncryptionSecretCallbackHandler
 #
 #secretRepositories=file
-#secretRepositories.file.provider=org.apache.synapse.commons.security.secret.repository.filebased.FileBaseSecretRepositoryProvider
+#secretRepositories.file.provider=org.apache.synapse.commons.security.secret.repository.FileBaseSecretRepositoryProvider
 #secretRepositories.file.location=cipher-text.properties
 #
 #keystore.identity.location=lib/identity.jks

Modified: synapse/trunk/java/src/site/xdoc/Synapse_Samples_Setup.xml
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/src/site/xdoc/Synapse_Samples_Setup.xml?rev=935815&r1=935814&r2=935815&view=diff
==============================================================================
--- synapse/trunk/java/src/site/xdoc/Synapse_Samples_Setup.xml (original)
+++ synapse/trunk/java/src/site/xdoc/Synapse_Samples_Setup.xml Tue Apr 20 
06:37:36 2010
@@ -893,7 +893,7 @@ synapse.sh -sample &lt;n&gt;</pre>
     </p>
     <pre>secretRepositories=file
 
-        
secretRepositories.file.provider=org.apache.synapse.commons.security.secret.repository.filebased.FileBaseSecretRepositoryProvider
+        
secretRepositories.file.provider=org.apache.synapse.commons.security.secret.repository.FileBaseSecretRepositoryProvider
         secretRepositories.file.location=cipher-text.properties
 
     </pre>


Reply via email to