You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juddi.apache.org by al...@apache.org on 2014/02/17 14:40:44 UTC
svn commit: r1568990 - in /juddi/trunk/juddi-client: ./
src/main/java/org/apache/juddi/v3/client/cryptor/
src/test/java/org/apache/juddi/v3/client/cryptor/
src/test/resources/JUDDI-808/
Author: alexoree
Date: Mon Feb 17 13:40:44 2014
New Revision: 1568990
URL: http://svn.apache.org/r1568990
Log:
JUDDI-808 implemented and tested
Added:
juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/
juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/AES128CryptorTest.java
juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/DefaultCryptorTest.java
juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/TripleDESCrytorTest.java
juddi/trunk/juddi-client/src/test/resources/JUDDI-808/
juddi/trunk/juddi-client/src/test/resources/JUDDI-808/3des.key
juddi/trunk/juddi-client/src/test/resources/JUDDI-808/aes128.key
juddi/trunk/juddi-client/src/test/resources/JUDDI-808/aes256.key
Modified:
juddi/trunk/juddi-client/pom.xml
juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AES128Cryptor.java
juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AES256Cryptor.java
juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AESCryptorAbstract.java
juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/Cryptor.java
juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/CryptorFactory.java
juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/CryptorUtil.java
juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/DefaultCryptor.java
juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/TripleDESCrytor.java
Modified: juddi/trunk/juddi-client/pom.xml
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/pom.xml?rev=1568990&r1=1568989&r2=1568990&view=diff
==============================================================================
--- juddi/trunk/juddi-client/pom.xml (original)
+++ juddi/trunk/juddi-client/pom.xml Mon Feb 17 13:40:44 2014
@@ -74,6 +74,15 @@
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
Modified: juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AES128Cryptor.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AES128Cryptor.java?rev=1568990&r1=1568989&r2=1568990&view=diff
==============================================================================
--- juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AES128Cryptor.java (original)
+++ juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AES128Cryptor.java Mon Feb 17 13:40:44 2014
@@ -27,35 +27,45 @@ import javax.crypto.IllegalBlockSizeExce
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
-
-/** AES 128 bit encryption
+/**
+ * AES 128 bit encryption
+ *
* @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
*/
-public class AES128Cryptor extends AESCryptorAbstract {
-
- /**
- * Constructor for DefaultCryptor.
- */
- public AES128Cryptor()
- throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException {
- super();
- }
-
- @Override
- protected String getKey()
- {
- return "72d93747ba0162f2f2985f5cb3e24b30";
- }
-
- @Override
- public String encrypt(String str) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
- return super.encrypt(str);
- }
-
- @Override
- public String decrypt(String str) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
- return super.decrypt(str);
- }
+public class AES128Cryptor extends AESCryptorAbstract {
+ /**
+ * Constructor for DefaultCryptor.
+ */
+ public AES128Cryptor()
+ throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException {
+ super();
+ }
+
+ @Override
+ protected String getKey() {
+ //JUDDI-808
+ String key = CryptorFactory.loadKeyFromFile("AES128Cryptor");
+ if (key != null) {
+ return key;
+ } else {
+ return "72d93747ba0162f2f2985f5cb3e24b30";
+ }
+ }
+
+ @Override
+ public String encrypt(String str) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
+ return super.encrypt(str);
+ }
+
+ @Override
+ public String decrypt(String str) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
+ return super.decrypt(str);
+ }
+
+ @Override
+ public String newKey() {
+ return GEN(128);
+ }
}
Modified: juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AES256Cryptor.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AES256Cryptor.java?rev=1568990&r1=1568989&r2=1568990&view=diff
==============================================================================
--- juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AES256Cryptor.java (original)
+++ juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AES256Cryptor.java Mon Feb 17 13:40:44 2014
@@ -35,26 +35,38 @@ import javax.crypto.spec.SecretKeySpec;
*/
public class AES256Cryptor extends AESCryptorAbstract {
- /**
- * Constructor for DefaultCryptor.
- */
- public AES256Cryptor()
- throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException {
- super();
- }
-
- @Override
- protected String getKey() {
- return "ef057ce3abd9dd9a161a2888c9d7025f104a42eceda5947b083186e7190fcc46";
- }
-
- @Override
- public String encrypt(String str) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
- return super.encrypt(str);
- }
-
- @Override
- public String decrypt(String str) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
- return super.decrypt(str);
- }
-}
\ No newline at end of file
+ /**
+ * Constructor for DefaultCryptor.
+ */
+ public AES256Cryptor()
+ throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException {
+ super();
+ }
+
+ @Override
+ protected String getKey() {
+ //JUDDI-808
+ String key = CryptorFactory.loadKeyFromFile("AES256Cryptor");
+ if (key != null) {
+ return key;
+ } else {
+ return "ef057ce3abd9dd9a161a2888c9d7025f104a42eceda5947b083186e7190fcc46";
+ }
+ }
+
+ @Override
+ public String encrypt(String str) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
+ return super.encrypt(str);
+ }
+
+ @Override
+ public String decrypt(String str) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
+ return super.decrypt(str);
+ }
+
+ @Override
+ public String newKey() {
+ return GEN(256);
+
+ }
+}
Modified: juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AESCryptorAbstract.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AESCryptorAbstract.java?rev=1568990&r1=1568989&r2=1568990&view=diff
==============================================================================
--- juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AESCryptorAbstract.java (original)
+++ juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/AESCryptorAbstract.java Mon Feb 17 13:40:44 2014
@@ -24,7 +24,9 @@ import java.security.spec.InvalidKeySpec
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
+import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
/**
@@ -126,4 +128,17 @@ public abstract class AESCryptorAbstract
return strbuf.toString();
}
+
+ public static String GEN(int keysize) {
+ KeyGenerator kgen;
+ try {
+ kgen = KeyGenerator.getInstance("AES");
+ kgen.init(keysize);
+ SecretKey skey = kgen.generateKey();
+ byte[] raw = skey.getEncoded();
+ return asHex(raw);
+ } catch (Exception ex) {
+ }
+ return null;
+ }
}
\ No newline at end of file
Modified: juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/Cryptor.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/Cryptor.java?rev=1568990&r1=1568989&r2=1568990&view=diff
==============================================================================
--- juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/Cryptor.java (original)
+++ juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/Cryptor.java Mon Feb 17 13:40:44 2014
@@ -70,4 +70,5 @@ public interface Cryptor {
IllegalBlockSizeException,
BadPaddingException;
+ public String newKey();
}
Modified: juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/CryptorFactory.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/CryptorFactory.java?rev=1568990&r1=1568989&r2=1568990&view=diff
==============================================================================
--- juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/CryptorFactory.java (original)
+++ juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/CryptorFactory.java Mon Feb 17 13:40:44 2014
@@ -16,8 +16,14 @@
*/
package org.apache.juddi.v3.client.cryptor;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.juddi.v3.client.ClassUtil;
@@ -34,92 +40,133 @@ import org.apache.juddi.v3.client.config
*/
public abstract class CryptorFactory {
- private static final Log log = LogFactory.getLog(CryptorFactory.class);
- // the shared Cryptor instance
- private static Cryptor cryptor = null;
- private static Map<String, Cryptor> cache = new HashMap<String, Cryptor>();
-
- /**
- * Returns a crypto provider with the matching classname, throws if not possible
- * @param className
- * @return a Cryptor instance
- * @throws Exception
- */
- public static Cryptor getCryptor(String className) throws Exception {
- if (cache.containsKey(className)) {
- return cache.get(className);
+ private static final Log log = LogFactory.getLog(CryptorFactory.class);
+ // the shared Cryptor instance
+ private static Cryptor cryptor = null;
+ private static Map<String, Cryptor> cache = new HashMap<String, Cryptor>();
+
+ /**
+ * Returns a crypto provider with the matching classname, throws if not
+ * possible
+ *
+ * @param className
+ * @return a Cryptor instance
+ * @throws Exception
+ */
+ public static Cryptor getCryptor(String className) throws Exception {
+ if (cache.containsKey(className)) {
+ return cache.get(className);
+ }
+ Class<?> cryptorClass = null;
+ try {
+ // Use Loader to locate & load the Cryptor implementation
+ cryptorClass = ClassUtil.forName(className, CryptorFactory.class);
+ } catch (ClassNotFoundException e) {
+ log.error("The specified Cryptor class '" + className + "' was not found in classpath.");
+ log.error(e);
+ throw e;
+ }
+
+ try {
+ // try to instantiate the Cryptor implementation
+ cryptor = (Cryptor) cryptorClass.newInstance();
+ cache.put(className, cryptor);
+ } catch (Exception e) {
+ log.error("Exception while attempting to instantiate the implementation of Cryptor: " + cryptorClass.getName() + "\n" + e.getMessage());
+ log.error(e);
+ throw e;
+ }
+
+ return cryptor;
+ }
+
+ /**
+ * Returns a new instance of a CryptorFactory.
+ *
+ * @return Cryptor
+ */
+ public static synchronized Cryptor getCryptor() {
+ if (cryptor == null) {
+ cryptor = createCryptor();
+ }
+ return cryptor;
+ }
+
+ /*
+ * Returns a new instance of a Cryptor.
+ *
+ * @return Cryptor
+ */
+ private static synchronized Cryptor createCryptor() {
+ if (cryptor != null) {
+ return cryptor;
+ }
+
+ // grab class name of the Cryptor implementation to create
+ String className = Property.DEFAULT_CRYPTOR;
+
+ // write the Cryptor implementation name to the log
+ log.debug("Cryptor Implementation = " + className);
+
+ Class<?> cryptorClass = null;
+ try {
+ // Use Loader to locate & load the Cryptor implementation
+ cryptorClass = ClassUtil.forName(className, CryptorFactory.class);
+ } catch (ClassNotFoundException e) {
+ log.error("The specified Cryptor class '" + className + "' was not found in classpath.");
+ log.error(e);
+ }
+
+ if (cryptorClass != null) {
+ try {
+ // try to instantiate the Cryptor implementation
+ cryptor = (Cryptor) cryptorClass.newInstance();
+ } catch (Exception e) {
+ log.error("Exception while attempting to instantiate the implementation of Cryptor: " + cryptorClass.getName() + "\n" + e.getMessage());
+ log.error(e);
+ }
+ }
+
+ return cryptor;
+ }
+
+ protected static String loadKeyFromFile(String provider) {
+ String fs = System.getProperty("juddi.encryptionKeyFile." + provider);
+ if (fs == null || fs.length() == 0) {
+ return null;
+ }
+ File cwd = new File(".");
+ log.debug("CWD="+cwd.getAbsolutePath());
+ File f = new File(fs);
+ if (f.exists() && f.isFile()) {
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new FileReader(f));
+ String line = null;
+ StringBuilder stringBuilder = new StringBuilder();
+ String ls = System.getProperty("line.separator");
+
+ while ((line = reader.readLine()) != null) {
+ stringBuilder.append(line);
+ stringBuilder.append(ls);
+ }
+ reader.close();
+
+ return stringBuilder.toString().trim();
+ } catch (Exception ex) {
+ log.warn("the system property juddi.encryptionKeyFile." + provider+" is defined, however there was an error reading the file!", ex);
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (Exception ex) {
+
+ }
+ }
+ }
+ } else {
+ log.warn("the system property juddi.encryptionKeyFile." + provider+" is defined, however that file either couldn't be found or isn't a file");
+ }
+ return null;
}
- Class<?> cryptorClass = null;
- try {
- // Use Loader to locate & load the Cryptor implementation
- cryptorClass = ClassUtil.forName(className, CryptorFactory.class);
- } catch (ClassNotFoundException e) {
- log.error("The specified Cryptor class '" + className + "' was not found in classpath.");
- log.error(e);
- throw e;
- }
-
- try {
- // try to instantiate the Cryptor implementation
- cryptor = (Cryptor) cryptorClass.newInstance();
- cache.put(className, cryptor);
- } catch (Exception e) {
- log.error("Exception while attempting to instantiate the implementation of Cryptor: " + cryptorClass.getName() + "\n" + e.getMessage());
- log.error(e);
- throw e;
- }
-
- return cryptor;
- }
-
-
- /**
- * Returns a new instance of a CryptorFactory.
- *
- * @return Cryptor
- */
- public static synchronized Cryptor getCryptor() {
- if (cryptor == null) {
- cryptor = createCryptor();
- }
- return cryptor;
- }
-
- /*
- * Returns a new instance of a Cryptor.
- *
- * @return Cryptor
- */
- private static synchronized Cryptor createCryptor() {
- if (cryptor != null) {
- return cryptor;
- }
-
- // grab class name of the Cryptor implementation to create
- String className = Property.DEFAULT_CRYPTOR;
-
- // write the Cryptor implementation name to the log
- log.debug("Cryptor Implementation = " + className);
-
- Class<?> cryptorClass = null;
- try {
- // Use Loader to locate & load the Cryptor implementation
- cryptorClass = ClassUtil.forName(className, CryptorFactory.class);
- } catch (ClassNotFoundException e) {
- log.error("The specified Cryptor class '" + className + "' was not found in classpath.");
- log.error(e);
- }
-
- if (cryptorClass != null) {
- try {
- // try to instantiate the Cryptor implementation
- cryptor = (Cryptor) cryptorClass.newInstance();
- } catch (Exception e) {
- log.error("Exception while attempting to instantiate the implementation of Cryptor: " + cryptorClass.getName() + "\n" + e.getMessage());
- log.error(e);
- }
- }
-
- return cryptor;
- }
-}
\ No newline at end of file
+}
Modified: juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/CryptorUtil.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/CryptorUtil.java?rev=1568990&r1=1568989&r2=1568990&view=diff
==============================================================================
--- juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/CryptorUtil.java (original)
+++ juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/CryptorUtil.java Mon Feb 17 13:40:44 2014
@@ -15,36 +15,46 @@
*/
package org.apache.juddi.v3.client.cryptor;
-
/**
* A static entry point for encrypting text via CLI
+ *
* @since 3.1.5
* @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
* @see CryptorFactory
*/
public class CryptorUtil {
- public static void main(String[] args) throws Exception{
- if (args.length == 0) {
- PrintUsage();
- return;
+ public static void main(String[] args) throws Exception {
+ if (args.length == 0) {
+ PrintUsage();
+ return;
+ }
+ Cryptor cryptor = CryptorFactory.getCryptor(args[0]);
+ if (System.getProperty("generate", "false").equalsIgnoreCase("true")) {
+ System.out.println("Generating new key...");
+ System.out.println(cryptor.newKey());
+ } else {
+ System.out.print("Password: ");
+ char[] readPassword = System.console().readPassword();
+ System.out.println("Cipher: " + cryptor.encrypt(new String(readPassword)));
+ }
}
- Cryptor cryptor = CryptorFactory.getCryptor(args[0]);
- System.out.print("Password: ");
- char[] readPassword = System.console().readPassword();
- System.out.println("Cipher: " + cryptor.encrypt(new String(readPassword)));
- }
- private static void PrintUsage() {
- System.out.println("Encrypts a password using the specified crypto provider");
- System.out.println("Usage: java -cp (classpath) org.apache.juddi.v3.auth.CrytorUtil (CryptoProvider)");
-
- System.out.println("Provided crypto providers:");
- System.out.println("\torg.apache.juddi.v3.client.cryptor.DefaultCryptor - uses PBEWithMD5AndDES");
- System.out.println("\torg.apache.juddi.v3.client.cryptor.TripleDESCrytor - uses TripleDES");
- System.out.println("\torg.apache.juddi.v3.client.cryptor.AES128Cryptor - uses AES128");
- System.out.println("\torg.apache.juddi.v3.client.cryptor.AES256Cryptor - uses AES256*");
- System.out.println();
- System.out.println("* Requires Unlimited Strength JCE *");
- }
+ private static void PrintUsage() {
+ System.out.println("Encrypts a password using the specified crypto provider");
+ System.out.println("Usage: java (options) -cp (classpath) " + CryptorUtil.class.getCanonicalName() + " (CryptoProvider)");
+
+ System.out.println("Provided crypto providers:");
+ System.out.println("\t" + DefaultCryptor.class.getCanonicalName() + " - uses PBEWithMD5AndDES");
+ System.out.println("\t" + TripleDESCrytor.class.getCanonicalName() + " - uses TripleDES");
+ System.out.println("\t" + AES128Cryptor.class.getCanonicalName() + " - uses AES128");
+ System.out.println("\t" + AES256Cryptor.class.getCanonicalName() + " - uses AES256*");
+ System.out.println();
+ System.out.println("* Requires Unlimited Strength JCE *");
+ System.out.println();
+ System.out.println("Available options:");
+ System.out.println("\t-Dgenerate=true - generates a new encryption key and writes to std out");
+ System.out.println("\t-Djuddi.encryptionKeyFile.(providerClassName)=path - encrypts a password using the specified key");
+ System.out.println("(e.g. -Djuddi.encryptionKeyFile.TripleDESCrytor,-Djuddi.encryptionKeyFile.AES128Cryptor, etc ");
+ }
}
Modified: juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/DefaultCryptor.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/DefaultCryptor.java?rev=1568990&r1=1568989&r2=1568990&view=diff
==============================================================================
--- juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/DefaultCryptor.java (original)
+++ juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/DefaultCryptor.java Mon Feb 17 13:40:44 2014
@@ -14,7 +14,6 @@
* limitations under the License.
*
*/
-
package org.apache.juddi.v3.client.cryptor;
import java.security.InvalidAlgorithmParameterException;
@@ -36,89 +35,85 @@ import org.apache.commons.codec.binary.B
/**
* @author Anou Manavalan
*/
-public class DefaultCryptor implements Cryptor
-{
- private PBEKeySpec pbeKeySpec = null;
- private PBEParameterSpec pbeParamSpec = null;
- private SecretKeyFactory keyFac = null;
- private SecretKey pbeKey = null;
-
- // Salt
- private byte[] salt = {
- (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
- (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
- };
-
- // Iteration count
- private int count = 20;
-
- /**
- * Constructor for DefaultCryptor.
- */
- public DefaultCryptor()
- throws NoSuchAlgorithmException,InvalidKeySpecException
- {
- // Create PBE parameter set
- pbeParamSpec = new PBEParameterSpec(salt,count);
- pbeKeySpec = new PBEKeySpec("saagar".toCharArray());
- keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
- pbeKey = keyFac.generateSecret(pbeKeySpec);
- }
-
- /**
- * Encrypt the string
- */
- private byte[] crypt(int cipherMode,byte[] text)
- throws NoSuchPaddingException,
- NoSuchAlgorithmException,
- InvalidAlgorithmParameterException,
- InvalidKeyException,
- IllegalBlockSizeException,
- BadPaddingException
-
- {
- // Create PBE Cipher
- Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
+public class DefaultCryptor implements Cryptor {
+
+ private PBEKeySpec pbeKeySpec = null;
+ private PBEParameterSpec pbeParamSpec = null;
+ private SecretKeyFactory keyFac = null;
+ private SecretKey pbeKey = null;
+
+ // Salt
+ private byte[] salt = {
+ (byte) 0xc7, (byte) 0x73, (byte) 0x21, (byte) 0x8c,
+ (byte) 0x7e, (byte) 0xc8, (byte) 0xee, (byte) 0x99
+ };
+
+ // Iteration count
+ private int count = 20;
+
+ /**
+ * Constructor for DefaultCryptor.
+ */
+ public DefaultCryptor()
+ throws NoSuchAlgorithmException, InvalidKeySpecException {
+ // Create PBE parameter set
+ pbeParamSpec = new PBEParameterSpec(salt, count);
+ pbeKeySpec = new PBEKeySpec("saagar".toCharArray());
+ keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
+ pbeKey = keyFac.generateSecret(pbeKeySpec);
+ }
+
+ /**
+ * Encrypt the string
+ */
+ private byte[] crypt(int cipherMode, byte[] text)
+ throws NoSuchPaddingException,
+ NoSuchAlgorithmException,
+ InvalidAlgorithmParameterException,
+ InvalidKeyException,
+ IllegalBlockSizeException,
+ BadPaddingException {
+ // Create PBE Cipher
+ Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
- // Initialize PBE Cipher with key and parameters
- pbeCipher.init(cipherMode,pbeKey,pbeParamSpec);
+ // Initialize PBE Cipher with key and parameters
+ pbeCipher.init(cipherMode, pbeKey, pbeParamSpec);
//byte[] text = str.getBytes();
+ // Encrypt/Decrypt the string
+ byte[] cryptext = pbeCipher.doFinal(text);
- // Encrypt/Decrypt the string
- byte[] cryptext = pbeCipher.doFinal(text);
+ return cryptext;
+ }
- return cryptext;
- }
+ /**
+ * Encrypt the string
+ */
+ public String encrypt(String str)
+ throws NoSuchPaddingException,
+ NoSuchAlgorithmException,
+ InvalidAlgorithmParameterException,
+ InvalidKeyException,
+ IllegalBlockSizeException,
+ BadPaddingException {
+ byte[] encs = crypt(Cipher.ENCRYPT_MODE, str.getBytes());
+ encs = Base64.encodeBase64(encs);
+ return new String(encs);
+ }
+
+ public String decrypt(String str) throws NoSuchPaddingException,
+ NoSuchAlgorithmException,
+ InvalidAlgorithmParameterException,
+ InvalidKeyException,
+ IllegalBlockSizeException,
+ BadPaddingException {
+ byte[] encs = crypt(Cipher.DECRYPT_MODE, Base64.decodeBase64(str.getBytes()));
+ return new String(encs);
+ }
+
+ @Override
+ public String newKey() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
- /**
- * Encrypt the string
- */
- public String encrypt(String str)
- throws NoSuchPaddingException,
- NoSuchAlgorithmException,
- InvalidAlgorithmParameterException,
- InvalidKeyException,
- IllegalBlockSizeException,
- BadPaddingException
- {
- byte[] encs = crypt(Cipher.ENCRYPT_MODE,str.getBytes());
- encs = Base64.encodeBase64(encs);
- return new String(encs);
- }
-
-
- public String decrypt(String str) throws NoSuchPaddingException,
- NoSuchAlgorithmException,
- InvalidAlgorithmParameterException,
- InvalidKeyException,
- IllegalBlockSizeException,
- BadPaddingException{
- byte[] encs = crypt(Cipher.DECRYPT_MODE,Base64.decodeBase64(str.getBytes()));
- return new String(encs);
- }
-
-
-
-
-}
\ No newline at end of file
+}
Modified: juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/TripleDESCrytor.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/TripleDESCrytor.java?rev=1568990&r1=1568989&r2=1568990&view=diff
==============================================================================
--- juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/TripleDESCrytor.java (original)
+++ juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/cryptor/TripleDESCrytor.java Mon Feb 17 13:40:44 2014
@@ -44,13 +44,17 @@ public class TripleDESCrytor implements
private String myEncryptionKey;
private String myEncryptionScheme;
SecretKey key;
-
+
/**
*default constructor
* @throws Exception
*/
public TripleDESCrytor() throws Exception {
- myEncryptionKey = "rioTEBCe/RAHRs6tTyYxDqettnVbZA6z";
+ String keyfromfile = CryptorFactory.loadKeyFromFile("TripleDESCrytor");
+ if (keyfromfile!=null)
+ myEncryptionKey=keyfromfile;
+ else
+ myEncryptionKey = "rioTEBCe/RAHRs6tTyYxDqettnVbZA6z";
myEncryptionScheme = DESEDE_ENCRYPTION_SCHEME;
arrayBytes = myEncryptionKey.getBytes(UNICODE_FORMAT);
ks = new DESedeKeySpec(arrayBytes);
@@ -104,4 +108,9 @@ public class TripleDESCrytor implements
}
return encryptedString;
}
+
+ @Override
+ public String newKey() {
+ return GEN();
+ }
}
Added: juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/AES128CryptorTest.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/AES128CryptorTest.java?rev=1568990&view=auto
==============================================================================
--- juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/AES128CryptorTest.java (added)
+++ juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/AES128CryptorTest.java Mon Feb 17 13:40:44 2014
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.juddi.v3.client.cryptor;
+
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.crypto.NoSuchPaddingException;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author Daddy
+ */
+public class AES128CryptorTest {
+
+ public AES128CryptorTest() {
+ }
+
+ /**
+ * Test of getKey method, of class AES128Cryptor.
+ */
+ @Test
+ public void testGetKey() {
+ try {
+ System.out.println("getKey");
+ AES128Cryptor instance = new AES128Cryptor();
+ String result = instance.getKey();
+ assertNotNull(result);
+ } catch (NoSuchAlgorithmException ex) {
+ Logger.getLogger(AES128CryptorTest.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (InvalidKeySpecException ex) {
+ Logger.getLogger(AES128CryptorTest.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (NoSuchPaddingException ex) {
+ Logger.getLogger(AES128CryptorTest.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (InvalidKeyException ex) {
+ Logger.getLogger(AES128CryptorTest.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ /**
+ * Test of encrypt method, of class AES128Cryptor.
+ */
+ @Test
+ public void testEncrypt() throws Exception {
+ System.out.println("encrypt");
+ String str = "test";
+ AES128Cryptor instance = new AES128Cryptor();
+ String result = instance.encrypt(str);
+ assertNotEquals(str, result);
+ }
+
+ /**
+ * Test of decrypt method, of class AES128Cryptor. EXTERNAL KEY
+ */
+ @Test
+ public void testExternalKey() throws Exception {
+ System.out.println("testExternalKey");
+ AES128Cryptor instance = new AES128Cryptor();
+ String result = instance.getKey();
+ System.getProperties().put("juddi.encryptionKeyFile.AES128Cryptor", "./src/test/resources/JUDDI-808/aes128.key");
+ String expResult = instance.getKey();
+ System.getProperties().remove("juddi.encryptionKeyFile.AES128Cryptor");
+ assertNotEquals("loading of external key failed", expResult, result);
+ String enc = instance.decrypt(instance.encrypt("test"));
+ assertEquals(enc, "test");
+ }
+
+ /**
+ * Test of decrypt method, of class AES128Cryptor.
+ */
+ @Test
+ public void testDecrypt() throws Exception {
+ System.out.println("testDecrypt");
+ String str = "test";
+ AES128Cryptor instance = new AES128Cryptor();
+ String expResult = "test";
+ String result = instance.decrypt(instance.encrypt(str));
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of newKey method, of class AES128Cryptor.
+ */
+ @Test
+ public void testNewKey() throws Exception{
+ System.out.println("newKey");
+ AES128Cryptor instance = new AES128Cryptor();
+ String result = instance.newKey();
+ assertNotNull(result);
+ }
+
+}
Added: juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/DefaultCryptorTest.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/DefaultCryptorTest.java?rev=1568990&view=auto
==============================================================================
--- juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/DefaultCryptorTest.java (added)
+++ juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/DefaultCryptorTest.java Mon Feb 17 13:40:44 2014
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.juddi.v3.client.cryptor;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author Daddy
+ */
+public class DefaultCryptorTest {
+
+ public DefaultCryptorTest() {
+ }
+
+ /**
+ * Test of encrypt method, of class DefaultCryptor.
+ */
+ @Test
+ public void testEncrypt() throws Exception {
+ System.out.println("encrypt");
+ String str = "test";
+ DefaultCryptor instance = new DefaultCryptor();
+ String expResult = "test";
+ String result =instance.decrypt(instance.encrypt(str));
+ assertEquals(expResult, result);
+ }
+
+}
Added: juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/TripleDESCrytorTest.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/TripleDESCrytorTest.java?rev=1568990&view=auto
==============================================================================
--- juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/TripleDESCrytorTest.java (added)
+++ juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/cryptor/TripleDESCrytorTest.java Mon Feb 17 13:40:44 2014
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.juddi.v3.client.cryptor;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author Alex O'Ree
+ */
+public class TripleDESCrytorTest {
+
+ public TripleDESCrytorTest() {
+ }
+
+ /**
+ * Test of encrypt method, of class TripleDESCrytor.
+ */
+ @Test
+ public void testEncrypt() throws Exception {
+ System.out.println("encrypt");
+ String clear = "test";
+ TripleDESCrytor instance = new TripleDESCrytor();
+ String expResult = "test";
+ String result =instance.decrypt(instance.encrypt(clear));
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of decrypt method, of class AES128Cryptor. EXTERNAL KEY
+ */
+ @Test
+ public void testExternalKey() throws Exception {
+ System.out.println("testExternalKey");
+ TripleDESCrytor instance = new TripleDESCrytor();
+ String defaultKey=instance.encrypt("test");
+
+ System.getProperties().put("juddi.encryptionKeyFile.TripleDESCrytor", "./src/test/resources/JUDDI-808/3des.key");
+ instance = new TripleDESCrytor();
+ String externalKey=instance.encrypt("test");
+
+ System.getProperties().remove("juddi.encryptionKeyFile.TripleDESCrytor");
+ assertNotEquals("loading of external key failed", defaultKey, externalKey);
+ String str=instance.decrypt(externalKey);
+ assertEquals(str, "test");
+
+
+ }
+
+ /**
+ * Test of newKey method, of class TripleDESCrytor.
+ */
+ @Test
+ public void testNewKey() throws Exception{
+ System.out.println("newKey");
+ TripleDESCrytor instance = new TripleDESCrytor();
+ String result = instance.newKey();
+ assertNotNull(result);
+ }
+
+}
Added: juddi/trunk/juddi-client/src/test/resources/JUDDI-808/3des.key
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/test/resources/JUDDI-808/3des.key?rev=1568990&view=auto
==============================================================================
--- juddi/trunk/juddi-client/src/test/resources/JUDDI-808/3des.key (added)
+++ juddi/trunk/juddi-client/src/test/resources/JUDDI-808/3des.key Mon Feb 17 13:40:44 2014
@@ -0,0 +1 @@
+9LPLPcHyLBVidstRoUWPBNxzTEDglHUO
\ No newline at end of file
Added: juddi/trunk/juddi-client/src/test/resources/JUDDI-808/aes128.key
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/test/resources/JUDDI-808/aes128.key?rev=1568990&view=auto
==============================================================================
--- juddi/trunk/juddi-client/src/test/resources/JUDDI-808/aes128.key (added)
+++ juddi/trunk/juddi-client/src/test/resources/JUDDI-808/aes128.key Mon Feb 17 13:40:44 2014
@@ -0,0 +1 @@
+e53e20bf8eec690074eff4e74b5cdd31
\ No newline at end of file
Added: juddi/trunk/juddi-client/src/test/resources/JUDDI-808/aes256.key
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/test/resources/JUDDI-808/aes256.key?rev=1568990&view=auto
==============================================================================
--- juddi/trunk/juddi-client/src/test/resources/JUDDI-808/aes256.key (added)
+++ juddi/trunk/juddi-client/src/test/resources/JUDDI-808/aes256.key Mon Feb 17 13:40:44 2014
@@ -0,0 +1 @@
+2a68d531289dd3a1590c381bfbf7f10c4c499114bc666a2de3439570e945ea47
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@juddi.apache.org
For additional commands, e-mail: commits-help@juddi.apache.org