diff --git a/mozilla/security/jss/org/mozilla/jss/tests/JSSE_SSLClient.java b/mozilla/security/jss/org/mozilla/jss/tests/JSSE_SSLClient.java index 44f3c856eef..944e3b6e7a6 100755 --- a/mozilla/security/jss/org/mozilla/jss/tests/JSSE_SSLClient.java +++ b/mozilla/security/jss/org/mozilla/jss/tests/JSSE_SSLClient.java @@ -61,6 +61,7 @@ public class JSSE_SSLClient { private int debug_level = 0; private boolean handshakeCompleted = false; private String EOF = "test"; + private String keystoreLoc = "keystore.pfx"; /** * Set the protocol type and revision @@ -144,6 +145,22 @@ public class JSSE_SSLClient { this.EOF = fEof; } + /** + * Set the location of keystore.pfx + * @param String fKeystoreLoc + */ + public void setKeystoreLoc(String fKeystoreLoc) { + keystoreLoc = fKeystoreLoc + "/" + keystoreLoc; + } + + /** + * Get the location of keystore.pfx + * @return String fKeystoreLoc + */ + public String getKeystoreLoc() { + return keystoreLoc; + } + /** * Return true or false based on * tunnel parameters being set. @@ -282,7 +299,11 @@ public class JSSE_SSLClient { // Load the keystore that contains the certificate kmf = KeyManagerFactory.getInstance("SunX509"); ks = KeyStore.getInstance("PKCS12"); - ks.load(new FileInputStream("keystore.pfx"), passphrase); + try { + ks.load(new FileInputStream(getKeystoreLoc()), passphrase); + } catch (Exception keyEx) { + System.out.println("DEBUG 306: Exception : " + keyEx.getMessage()); + } kmf.init(ks, passphrase); // trust manager that trusts all cetificates @@ -498,10 +519,11 @@ public class JSSE_SSLClient { /** * Test communication with SSL server using TLS */ - public void testTlsClient(String testCipher, - String testHost, - int testPort) { - + public void testTlsClient(String testCipher, + String testHost, + int testPort, + String keystoreLocation) { + String javaVersion = System.getProperty("java.version"); String lastCipher = null; System.out.println("\nUsing java version " + javaVersion + "\n"); @@ -510,48 +532,31 @@ public class JSSE_SSLClient { sslSock.setSslRevision("TLS"); sslSock.setHost(testHost); sslSock.setPort(testPort); + sslSock.setKeystoreLoc(keystoreLocation); if ( javaVersion.indexOf("1.4") == -1 ) { // Validate Ciphers supported for TLS if ( testCipher != null ) { - // This try is for catching non supported cipher exception + // This try is for catching non supported cipher exception try { sslSock.setCipherSuite(testCipher); sslSock.setEOF(testCipher); String errStr = sslSock.validateConnection(); - while (!sslSock.isHandshakeCompleted()) { - // Put the main thread to sleep. In case we do not get - // any response within 10 sec, then we shutdown. - try { - Thread.currentThread().sleep(1000); - } catch (InterruptedException e) { - System.out.println("Thread Interrupted ...\n"); - } - } - sslSock.clearHandshakeCompleted(); + Thread.currentThread().sleep(1000); } catch (Exception ex) { System.out.println("JSSE_SSLCLient: Did not find " + "any supported ciphers for JDK 1.4.x"); } } else { - // This try is for catching non supported cipher exception + // This try is for catching non supported cipher exception try { for(int i=0;i " + + " "; try { + if ( args[0].toLowerCase().equals("-h") ) { + System.out.println(usage); + System.exit(0); + } + if ( args.length >= 1 ) { - testCipher = (String)args[0]; - testHost = (String)args[1]; - testPort = new Integer(args[2]).intValue(); + keystoreLocation = (String)args[0]; + testCipher = (String)args[1]; + testHost = (String)args[2]; + testPort = new Integer(args[3]).intValue(); } } catch (Exception e) { } JSSE_SSLClient sslSock = new JSSE_SSLClient(); - + // Call TLS client cipher test - sslSock.testTlsClient(testCipher, testHost, testPort); - + try { + Thread.currentThread().sleep(1000); + } catch (Exception e) { } + sslSock.testTlsClient(testCipher, testHost, testPort, keystoreLocation); + // Call SSLv3 client cipher test - sslSock.testSslClient(testCipher, testHost, testPort); + try { + Thread.currentThread().sleep(1000); + } catch (Exception e) { } + sslSock.testSslClient(testCipher, testHost, testPort, keystoreLocation); } } diff --git a/mozilla/security/jss/org/mozilla/jss/tests/JSSE_SSLServer.java b/mozilla/security/jss/org/mozilla/jss/tests/JSSE_SSLServer.java index 1a98fe0cb96..b280bc4ed43 100755 --- a/mozilla/security/jss/org/mozilla/jss/tests/JSSE_SSLServer.java +++ b/mozilla/security/jss/org/mozilla/jss/tests/JSSE_SSLServer.java @@ -48,6 +48,7 @@ public class JSSE_SSLServer extends ClassServer { private static int DefaultServerPort = 29753; private static int port = DefaultServerPort; private static String type = "SSLv3"; + private static String keystoreLoc = "keystore.pfx"; /** * Constructs a JSSE_SSLServer. @@ -58,6 +59,22 @@ public class JSSE_SSLServer extends ClassServer { super(ss); } + /** + * Set the location of keystore file. + * @param String fKeystoreLoc + */ + public static void setKeystoreLoc(String fKeystoreLoc) { + keystoreLoc = fKeystoreLoc + "/" + keystoreLoc; + } + + /** + * Get the location of keystore file. + * @return String keystoreLoc + */ + public static String getKeystoreLoc() { + return keystoreLoc; + } + /** * Main method to create the class server. This takes * one command line arguments, the port on which the @@ -70,12 +87,13 @@ public class JSSE_SSLServer extends ClassServer { * */ public static void main(String args[]) { + String keystoreLoc = "keystore.pfx"; if ( args.length <= 1 ) { System.out.println( "USAGE: java JSSE_SSLServer port [TLS | SSLv3 [true]]"); - System.out.println(""); + System.out.println(""); System.out.println( - "If the second argument is TLS, it will start as a\n" + + "\nIf the second argument is TLS, it will start as a\n" + "TLS server, otherwise, it will be started in SSLv3 mode." + "\nIf the third argument is true,it will require\n" + "client authentication as well."); @@ -85,6 +103,9 @@ public class JSSE_SSLServer extends ClassServer { if (args.length >= 2) { port = Integer.parseInt(args[0]); type = args[1]; + keystoreLoc = args[3]; + if ( keystoreLoc != null ) + setKeystoreLoc(keystoreLoc); } try { @@ -115,9 +136,9 @@ public class JSSE_SSLServer extends ClassServer { } // Put the main thread to sleep. In case we do not get any - // response within 35 sec, then we shutdown the server. + // response within 5 sec, then we shutdown the server. try { - Thread.currentThread().sleep(3500); + Thread.currentThread().sleep(5000); } catch (InterruptedException e) { System.out.println("Thread Interrupted, exiting normally ...\n"); System.exit(0); @@ -167,7 +188,7 @@ public class JSSE_SSLServer extends ClassServer { kmf = KeyManagerFactory.getInstance("SunX509"); ks = KeyStore.getInstance("PKCS12"); - ks.load(new FileInputStream("keystore.pfx"), passphrase); + ks.load(new FileInputStream(getKeystoreLoc()), passphrase); kmf.init(ks, passphrase); ctx.init(kmf.getKeyManagers(), trustAllCerts, null); @@ -183,7 +204,7 @@ public class JSSE_SSLServer extends ClassServer { kmf = KeyManagerFactory.getInstance("SunX509"); ks = KeyStore.getInstance("PKCS12"); - ks.load(new FileInputStream("keystore.pfx"), passphrase); + ks.load(new FileInputStream("./" + getKeystoreLoc()), passphrase); kmf.init(ks, passphrase); ctx.init(kmf.getKeyManagers(), trustAllCerts, null); diff --git a/mozilla/security/jss/org/mozilla/jss/tests/JSSPackageTest.java b/mozilla/security/jss/org/mozilla/jss/tests/JSSPackageTest.java index fc6078a95ba..18defc4ac32 100644 --- a/mozilla/security/jss/org/mozilla/jss/tests/JSSPackageTest.java +++ b/mozilla/security/jss/org/mozilla/jss/tests/JSSPackageTest.java @@ -50,10 +50,12 @@ public class JSSPackageTest { private static CryptoManager cm = null; public static void main(String[] args) { + String certDbPath = "."; try { try { - CryptoManager.initialize("."); + certDbPath = (String)args[0]; } catch (Exception e) { } + CryptoManager.initialize(certDbPath); Package pkg = Package.getPackage("org.mozilla.jss"); diff --git a/mozilla/security/jss/org/mozilla/jss/tests/JSS_SSLClient.java b/mozilla/security/jss/org/mozilla/jss/tests/JSS_SSLClient.java index 0b5ffb84833..c4603058e4a 100755 --- a/mozilla/security/jss/org/mozilla/jss/tests/JSS_SSLClient.java +++ b/mozilla/security/jss/org/mozilla/jss/tests/JSS_SSLClient.java @@ -67,10 +67,7 @@ public class JSS_SSLClient { private CryptoToken tok = null; private PasswordCallback cb = null; private String fPasswordFile = "passwords"; - private String fCertDbPath = "."; - - private static String usage = "USAGE: java JSS_SSLClient " + - " "; + private static String fCertDbPath = "."; /** * Default Constructor, do not use. @@ -123,10 +120,18 @@ public class JSS_SSLClient { * Initialize the cert db path name * @param String CertDbPath */ - public void setCertDbPath(String aCertDbPath) { + public static void setCertDbPath(String aCertDbPath) { fCertDbPath = aCertDbPath; } + /** + * Fetch the cert db path name + * @return String CertDbPath + */ + public static String getCertDbPath() { + return fCertDbPath; + } + /** * Enable/disable Test Cert Callback. * @param boolean @@ -302,35 +307,43 @@ public class JSS_SSLClient { public static void main(String[] args) { String certnick = "JSSCATestCert"; - String testCipher = null; + int testCipher = 0; String testhost = "localhost"; int testport = 29753; String certDbPath = null; - String passwdFile = null; + String passwdFile = "passwords"; String usage = "USAGE:\n" + "java org.mozilla.jss.tests.JSS_SSLClient" + - " \n" + - " "; + " \n" + + " "; try { - if ( args.length >= 1 ) { - testCipher = (String)args[0]; - if ( testCipher.toLowerCase().equals("-h")) - System.out.println(usage); + if ( ((String)args[0]).toLowerCase().equals("-h") ) { + System.out.println(usage); + System.exit(0); } + if ( args.length >= 2 ) { + certDbPath = (String)args[0]; + passwdFile = (String)args[1]; + } + + if ( certDbPath != null) + setCertDbPath(certDbPath); + if ( args.length >= 3 ) { - testhost = (String)args[1]; - testport = new Integer(args[2]).intValue(); + testCipher = new Integer(args[2]).intValue(); } if ( args.length >= 5 ) { - certDbPath = (String)args[3]; - passwdFile = (String)args[4]; + testhost = (String)args[3]; + testport = new Integer(args[4]).intValue(); } Thread.sleep(5000); } catch (Exception e) { + System.out.println("Exception caught " + e.toString()); + e.printStackTrace(); } JSS_SSLClient jssTest = new JSS_SSLClient(); @@ -344,16 +357,13 @@ public class JSS_SSLClient { jssTest.setTestCertCallback(true); jssTest.setClientCertNick(certnick); - if ( certDbPath != null ) - jssTest.setCertDbPath(certDbPath); - if ( passwdFile != null ) jssTest.setPasswordFile(passwdFile); - if ( testCipher != null ) { + if ( testCipher != 0 ) { try { - jssTest.setCipher(new Integer(testCipher).intValue()); - jssTest.setEOF(testCipher); + jssTest.setCipher(testCipher); + jssTest.setEOF(new Integer(testCipher).toString()); jssTest.doIt(); while (!jssTest.isHandshakeCompleted()) { // Put the main thread to sleep. In case we do not @@ -366,9 +376,11 @@ public class JSS_SSLClient { } jssTest.clearHandshakeCompleted(); } catch (Exception ex) { + System.out.println("Exception caught " + ex.getMessage()); + ex.printStackTrace(); } // Set EOF to null to trigger server socket close - jssTest.setCipher(new Integer(testCipher).intValue()); + jssTest.setCipher(testCipher); jssTest.setEOF("null"); jssTest.doIt(); while (!jssTest.isHandshakeCompleted()) { diff --git a/mozilla/security/jss/org/mozilla/jss/tests/JSS_SSLServer.java b/mozilla/security/jss/org/mozilla/jss/tests/JSS_SSLServer.java index b0ae7c2394c..5c75085219e 100755 --- a/mozilla/security/jss/org/mozilla/jss/tests/JSS_SSLServer.java +++ b/mozilla/security/jss/org/mozilla/jss/tests/JSS_SSLServer.java @@ -85,12 +85,12 @@ public class JSS_SSLServer { } private String serverCertNick = null; - private String serverHost = null; + private String serverHost = "localhost"; private boolean TestInetAddress = false; private boolean success = true; public static int port = 29750; - public static String usage = "USAGE: java JSS_SSLServer . " + - "passwords server_name " + + public static String usage = "USAGE: java JSS_SSLServer " + + " passwords server_name " + "servercertnick [ true | false ]"; public void doIt(String[] args) throws Exception { diff --git a/mozilla/security/jss/org/mozilla/jss/tests/all.pl b/mozilla/security/jss/org/mozilla/jss/tests/all.pl index b15ce0b28cb..c43a801ff89 100644 --- a/mozilla/security/jss/org/mozilla/jss/tests/all.pl +++ b/mozilla/security/jss/org/mozilla/jss/tests/all.pl @@ -195,7 +195,7 @@ if( ! -d $testdir ) { { chdir "$testdir" or die; my @dbfiles = - ("./cert8.db", "./key3.db", "./secmod.db"); + ("./cert8.db", "./key3.db", "./secmod.db, ./keystore.pfx"); unlink @dbfiles; (grep{ -f } @dbfiles) and die "Unable to delete old database files"; # if dbdir exists delete it @@ -286,7 +286,7 @@ $result and print "Generate known cert pair for testing returned $result\n"; # Create keystore.pfx from generated cert db # for "JSSCATestCert" print "============= convert PKCS11 cert to PKCS12 format\n"; -$result = system("$nss_lib_dir/../bin/pk12util$exe_suffix -o keystore.pfx -n JSSCATestCert -d ./$testdir -K netscape -W netscape"); +$result = system("$nss_lib_dir/../bin/pk12util$exe_suffix -o $testdir/keystore.pfx -n JSSCATestCert -d ./$testdir -K netscape -W netscape"); $result >>=8; $result and print "Convert PKCS11 to PKCS12 returned $result\n"; @@ -302,8 +302,7 @@ $result and print "JSSE servers returned $result\n"; # Test JSS client communication # print "============= Start JSS client tests\n"; -$result = system("cp $testdir/*.db ."); -$result = system("$java org.mozilla.jss.tests.JSS_SSLClient"); +$result = system("$java org.mozilla.jss.tests.JSS_SSLClient $testdir $pwfile"); $result >>=8; $result and print "JSS client returned $result\n"; print_case_result ($result,"JSSE server / JSS client"); @@ -320,7 +319,7 @@ $result and print "JSS servers returned $result\n"; # Test JSSE client communication # print "============= Start JSSE client tests\n"; -$result = system("$java org.mozilla.jss.tests.JSSE_SSLClient"); +$result = system("$java org.mozilla.jss.tests.JSSE_SSLClient $testdir"); $result >>=8; $result and print "JSSE client returned $result\n"; print_case_result ($result,"JSS server / JSSE client"); @@ -329,7 +328,7 @@ print_case_result ($result,"JSS server / JSSE client"); # Test for JSS jar and library revision # print "============= Check JSS jar version\n"; -$result = system("$java org.mozilla.jss.tests.JSSPackageTest"); +$result = system("$java org.mozilla.jss.tests.JSSPackageTest $testdir"); $result >>=8; my $LIB = "$lib_jss"."4"."$lib_suffix"; my $strings_exist = `which strings`; diff --git a/mozilla/security/jss/org/mozilla/jss/tests/startJsseServ.sh b/mozilla/security/jss/org/mozilla/jss/tests/startJsseServ.sh index 199ff8c0f26..7c58beb7af9 100755 --- a/mozilla/security/jss/org/mozilla/jss/tests/startJsseServ.sh +++ b/mozilla/security/jss/org/mozilla/jss/tests/startJsseServ.sh @@ -50,5 +50,5 @@ then JAVA_BIN_AND_OPT=${JAVA_HOME}/bin/java fi -${JAVA_BIN_AND_OPT} -classpath ${JSS_CLASSPATH} org.mozilla.jss.tests.JSSE_SSLServer 29753 SSLv3 false & +${JAVA_BIN_AND_OPT} -classpath ${JSS_CLASSPATH} org.mozilla.jss.tests.JSSE_SSLServer 29753 SSLv3 false ${TESTDIR} &