Modified JSS/JSSE inter communication tests along with JSSPackageTest

and all.pl to use platform specific cert/keystore directory.


git-svn-id: svn://10.0.0.236/trunk@175042 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sandeep.konchady%sun.com 2005-06-23 05:59:36 +00:00
parent 27e8f13ea7
commit d12ef8d85f
7 changed files with 148 additions and 125 deletions

View File

@ -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<Constants.sslciphersarray_jdk150.length;i++){
sslSock.setCipherSuite(
Constants.sslciphersarray_jdk150[i]);
Constants.sslciphersarray_jdk150[i]);
sslSock.setEOF(Constants.sslciphersarray_jdk150[i]);
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 " +
@ -561,13 +566,14 @@ public class JSSE_SSLClient {
System.out.println("Testing TLS Cipher list complete\n");
}
}
/**
* Test communication with SSL server using SSLv3
*/
public void testSslClient(String testCipher,
String testHost,
int testPort) {
public void testSslClient(String testCipher,
String testHost,
int testPort,
String keystoreLocation) {
String javaVersion = System.getProperty("java.version");
String lastCipher = null;
// Validate Ciphers supported for SSLv3
@ -576,46 +582,29 @@ public class JSSE_SSLClient {
sslSock.setSslRevision("SSLv3");
sslSock.setHost(testHost);
sslSock.setPort(testPort);
sslSock.setKeystoreLoc(keystoreLocation);
if ( javaVersion.indexOf("1.4") != -1 ) {
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<Constants.sslciphersarray_jdk142.length;i++){
lastCipher = Constants.sslciphersarray_jdk142[i];
sslSock.setCipherSuite(lastCipher);
sslSock.setEOF(Constants.sslciphersarray_jdk142[i]);
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 " +
@ -624,38 +613,26 @@ public class JSSE_SSLClient {
}
sslSock.setEOF("null");
String errStr = sslSock.validateConnection();
while (!sslSock.isHandshakeCompleted()) {
//Do nothing
}
sslSock.clearHandshakeCompleted();
} else {
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()) {
//Do nothing
}
sslSock.clearHandshakeCompleted();
} catch (Exception ex) {
System.out.println("JSSE_SSLCLient: Did not find " +
"any supported ciphers for JDK 1.5.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<Constants.sslciphersarray_jdk150.length;i++){
lastCipher = Constants.sslciphersarray_jdk150[i];
sslSock.setCipherSuite(
Constants.sslciphersarray_jdk150[i]);
Constants.sslciphersarray_jdk150[i]);
sslSock.setEOF(Constants.sslciphersarray_jdk150[i]);
String errStr = sslSock.validateConnection();
while (!sslSock.isHandshakeCompleted()) {
//Do nothing
}
sslSock.clearHandshakeCompleted();
}
} catch (Exception ex) {
System.out.println("JSSE_SSLCLient: Did not find " +
@ -664,37 +641,49 @@ public class JSSE_SSLClient {
}
sslSock.setEOF("null");
String errStr = sslSock.validateConnection();
while (!sslSock.isHandshakeCompleted()) {
//Do nothing
}
sslSock.clearHandshakeCompleted();
}
System.out.println("Testing SSLv3 Cipher list complete\n");
}
/**
* Main method for local unit testing.
*/
public static void main(String [] args) {
String testCipher = null;
String testHost = "localhost";
int testPort = 29750;
String testCipher = null;
String testHost = "localhost";
String keystoreLocation = "keystore.pfx";
int testPort = 29750;
String usage = "java org.mozilla.jss.tests.JSSE_SSLClient" +
"\n<keystore location> " +
"<test cipher> <test host> <test port>";
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);
}
}

View File

@ -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 {
* </code>
*/
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("<keystore location>");
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);

View File

@ -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");

View File

@ -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 " +
"<serverhost> <clientcertnick>";
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" +
" <test cipher> <server host> <server port>\n" +
" <cert db path> <password file>";
" <cert db path> <password file>\n" +
" <test cipher> <server host> <server port>";
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()) {

View File

@ -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 " +
"<cert db path> passwords server_name " +
"servercertnick [ true | false ]";
public void doIt(String[] args) throws Exception {

View File

@ -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`;

View File

@ -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} &