Author: rareddy
Date: 2009-07-08 13:51:32 -0400 (Wed, 08 Jul 2009)
New Revision: 1110
Added:
trunk/build/kit-embedded/bin/encrypt.bat
trunk/build/kit-embedded/bin/encrypt.sh
Modified:
trunk/build/kit-embedded/bin/run.bat
trunk/build/kit-embedded/bin/run.sh
trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/CryptoUtil.java
Log:
TEIID-702: providing scripts to encrypt passwords
Added: trunk/build/kit-embedded/bin/encrypt.bat
===================================================================
--- trunk/build/kit-embedded/bin/encrypt.bat (rev 0)
+++ trunk/build/kit-embedded/bin/encrypt.bat 2009-07-08 17:51:32 UTC (rev 1110)
@@ -0,0 +1,45 @@
+@echo off
+rem
+rem This script file encrypts the passed in clear text and spits out encypted form
+rem
+
+@if not "%ECHO%" == "" echo %ECHO%
+@if "%OS%" == "Windows_NT" setlocal
+
+if "%OS%" == "Windows_NT" (
+ set "DIRNAME=%~dp0%"
+) else (
+ set DIRNAME=.\
+)
+
+pushd %DIRNAME%..
+if "x%TEIID_HOME%" == "x" (
+ set "TEIID_HOME=%CD%"
+)
+popd
+
+set DIRNAME=
+
+if "x%JAVA_HOME%" == "x" (
+ set JAVA=java
+ echo JAVA_HOME is not set. Unexpected results may occur.
+ echo Set JAVA_HOME to the directory of your local JDK to avoid this message.
+) else (
+ set "JAVA=%JAVA_HOME%\bin\java"
+ if exist "%JAVA_HOME%\lib\tools.jar" (
+ set "JAVAC_JAR=%JAVA_HOME%\lib\tools.jar"
+ )
+)
+
+set
TEIID_CLASSPATH=%TEIID_HOME%\lib\patches\*;%TEIID_HOME%\deploy;%TEIID_HOME%\client\*;%TEIID_HOME%\lib\*;
+set KEYSTORE_FILE=%TEIID_HOME%\deploy\teiid.keystore
+if not exist %KEYSTORE_FILE (
+ %JAVA%" -classpath "%TEIID_CLASSPATH%"
com.metamatrix.common.util.crypto.CryptoUtil -genkey %KEYSTORE_FILE%
+ echo A new key with keystore generated at %KEYSTORE_FILE%
+)
+
+if "x%1%" == "x"(
+ echo Provide text phrase to encrypt.
+) else (
+ %JAVA%" -classpath "%TEIID_CLASSPATH%"
com.metamatrix.common.util.crypto.CryptoUtil -key %KEYSTORE_FILE% -encrypt %1%
+)
Added: trunk/build/kit-embedded/bin/encrypt.sh
===================================================================
--- trunk/build/kit-embedded/bin/encrypt.sh (rev 0)
+++ trunk/build/kit-embedded/bin/encrypt.sh 2009-07-08 17:51:32 UTC (rev 1110)
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+DIRNAME=`dirname $0`
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false;
+linux=false;
+case "`uname`" in
+ CYGWIN*)
+ cygwin=true
+ ;;
+
+ Linux)
+ linux=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+ [ -n "$TEIID_HOME" ] &&
+ TEIID_HOME=`cygpath --unix "$TEIID_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Setup TEIID_HOME
+if [ "x$TEIID_HOME" = "x" ]; then
+ # get the full path (without any relative bits)
+ TEIID_HOME=`cd $DIRNAME/..; pwd`
+fi
+export TEIID_HOME
+
+# Setup the JVM
+if [ "x$JAVA" = "x" ]; then
+ if [ "x$JAVA_HOME" != "x" ]; then
+ JAVA="$JAVA_HOME/bin/java"
+ else
+ JAVA="java"
+ fi
+fi
+
+TEIID_CLASSPATH="$TEIID_HOME/lib/patches/*:$TEIID_HOME/deploy:$TEIID_HOME/client/*:$TEIID_HOME/lib/*"
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+ TEIID_HOME=`cygpath --path --windows "$TEIID_HOME"`
+ JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+ TEIID_CLASSPATH=`cygpath --path --windows "$TEIID_CLASSPATH"`
+fi
+
+# generate teiid.keystore if does not exist.
+KEYSTORE_FILE=$TEIID_HOME/deploy/teiid.keystore
+if [ ! -f $KEYSTORE_FILE ]; then
+ "$JAVA" -classpath $TEIID_CLASSPATH
com.metamatrix.common.util.crypto.CryptoUtil -genkey $KEYSTORE_FILE
+ echo "A new key with keystore generated at $KEYSTORE_FILE"
+fi
+
+if [ "x$1" = "x" ]; then
+ echo "Provide text phrase to encrypt."
+else
+ "$JAVA" -classpath $TEIID_CLASSPATH
com.metamatrix.common.util.crypto.CryptoUtil -key $KEYSTORE_FILE -encrypt $1
+fi
\ No newline at end of file
Modified: trunk/build/kit-embedded/bin/run.bat
===================================================================
--- trunk/build/kit-embedded/bin/run.bat 2009-07-08 15:37:10 UTC (rev 1109)
+++ trunk/build/kit-embedded/bin/run.bat 2009-07-08 17:51:32 UTC (rev 1110)
@@ -47,6 +47,13 @@
rem JPDA options. Uncomment and modify as appropriate to enable remote debugging.
rem set JAVA_OPTS=%JAVA_OPTS% -Xdebug
-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y
+rem Generate teiid.keystore file
+set KEYSTORE_FILE = %TEIID_HOME%\deploy\teiid.keystore
+if not exist %KEYSTORE_FILE% (
+ %JAVA%" -classpath "%TEIID_CLASSPATH%"
com.metamatrix.common.util.crypto.CryptoUtil -genkey %KEYSTORE_FILE%
+ echo A new key with keystore generated at %KEYSTORE_FILE%
+)
+
echo ===============================================================================
echo.
echo Teiid Bootstrap Environment
Modified: trunk/build/kit-embedded/bin/run.sh
===================================================================
--- trunk/build/kit-embedded/bin/run.sh 2009-07-08 15:37:10 UTC (rev 1109)
+++ trunk/build/kit-embedded/bin/run.sh 2009-07-08 17:51:32 UTC (rev 1110)
@@ -66,6 +66,13 @@
TEIID_CLASSPATH=`cygpath --path --windows "$TEIID_CLASSPATH"`
fi
+# generate teiid.keystore if does not exist.
+KEYSTORE_FILE = $TEIID_HOME/deploy/teiid.keystore
+if [ ! -f $KEYSTORE_FILE ]
+ "$JAVA" -classpath $TEIID_CLASSPATH
com.metamatrix.common.util.crypto.CryptoUtil -genkey $KEYSTORE_FILE
+ echo "A new key with keystore generated at $KEYSTORE_FILE"
+fi
+
# Display our environment
echo
"========================================================================="
echo ""
Modified:
trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/CryptoUtil.java
===================================================================
---
trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/CryptoUtil.java 2009-07-08
15:37:10 UTC (rev 1109)
+++
trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/CryptoUtil.java 2009-07-08
17:51:32 UTC (rev 1110)
@@ -22,6 +22,7 @@
package com.metamatrix.common.util.crypto;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
@@ -366,5 +367,53 @@
public static synchronized boolean isInitialized() {
return CRYPTOR == null;
}
-
+
+ public static void main(String[] args) throws Exception {
+ if (args.length < 1) {
+ printUsage();
+ }
+
+ int i = 0;
+ if (args.length == 2 && args[i].equals("-genkey")) { //$NON-NLS-1$
+ String keyName = args[++i];
+ if (keyName == null) {
+ printUsage();
+ }
+ SymmetricCryptor.generateAndSaveKey(keyName);
+ return;
+ }
+ else if (args.length == 4 && args[i].equals("-key")) { //$NON-NLS-1$
+ String keyFile = args[++i];
+ if (keyFile == null) {
+ printUsage();
+ }
+
+ File key = new File(keyFile);
+ if (!key.exists()) {
+ System.out.println("Key file does not exist at "+keyFile); //$NON-NLS-1$
+ }
+ else {
+ CryptoUtil.init(key.toURI().toURL());
+ }
+
+ ++i;
+ if (args[i].equals("-encrypt")) { //$NON-NLS-1$
+ String clearText = args[++i];
+ if (clearText == null) {
+ printUsage();
+ }
+ System.out.println("Encypted Text:"+stringEncrypt(clearText));
//$NON-NLS-1$
+ return;
+ }
+ }
+ printUsage();
+ }
+
+ private static void printUsage() {
+ System.out.println("java CryptoUtil <option>"); //$NON-NLS-1$
+ System.out.println("options:"); //$NON-NLS-1$
+ System.out.println("\t-genkey <filename> # Generates password key
file"); //$NON-NLS-1$
+ System.out.println("\t-key <keyfile> -encrypt <cleartext> # Encrypts
the given clear text string"); //$NON-NLS-1$
+ System.exit(0);
+ }
}