4
my $base_path = "\\openssl";
6
my $output_path = "$base_path\\test_out";
7
my $cert_path = "$base_path\\certs";
8
my $test_path = "$base_path\\test";
9
my $app_path = "$base_path\\apps";
11
my $tmp_cert = "$output_path\\cert.tmp";
12
my $OpenSSL_config = "$app_path\\openssl.cnf";
13
my $log_file = "$output_path\\tests.log";
18
# process the command line args to see if they wanted us to pause
19
# between executing each command
31
############################################################################
34
# delete all the output files in the output directory
35
unlink <$output_path\\*.*>;
37
# open the main log file
38
open(OUT, ">$log_file") || die "unable to open $log_file\n";
50
print("\nCompleted running tests.\n\n");
51
print("Check log file for errors: $log_file\n");
54
############################################################################
59
my @tests = ( rsa_test, destest, ideatest, bftest, shatest, sha1test,
60
md5test, dsatest, md2test, mdc2test, rc2test, rc4test, randtest,
63
print( "\nRUNNING CRYPTO ALGORITHM TESTS:\n\n");
65
print( OUT "\n========================================================\n");
66
print( OUT "CRYPTO ALGORITHM TESTS:\n\n");
70
if (-e "$base_path\\$i.nlm")
72
$outFile = "$output_path\\$i.out";
73
system("$i > $outFile");
74
log_desc("Test: $i\.nlm:");
75
log_output("", $outFile );
79
log_desc("Test: $i\.nlm: file not found");
84
############################################################################
89
my @enc_tests = ( "enc", "rc4", "des-cfb", "des-ede-cfb", "des-ede3-cfb",
90
"des-ofb", "des-ede-ofb", "des-ede3-ofb",
91
"des-ecb", "des-ede", "des-ede3", "des-cbc",
92
"des-ede-cbc", "des-ede3-cbc", "idea-ecb", "idea-cfb",
93
"idea-ofb", "idea-cbc", "rc2-ecb", "rc2-cfb",
94
"rc2-ofb", "rc2-cbc", "bf-ecb", "bf-cfb",
97
my $input = "$base_path\\do_tests.pl";
98
my $cipher = "$output_path\\cipher.out";
99
my $clear = "$output_path\\clear.out";
101
print( "\nRUNNING ENCRYPTION & DECRYPTION TESTS:\n\n");
103
print( OUT "\n========================================================\n");
104
print( OUT "FILE ENCRYPTION & DECRYPTION TESTS:\n\n");
106
foreach $i (@enc_tests)
108
log_desc("Testing: $i");
111
$outFile = "$output_path\\enc.out";
112
system("openssl2 $i -e -bufsize 113 -k test -in $input -out $cipher > $outFile" );
113
log_output("Encrypting: $input --> $cipher", $outFile);
116
$outFile = "$output_path\\dec.out";
117
system("openssl2 $i -d -bufsize 157 -k test -in $cipher -out $clear > $outFile");
118
log_output("Decrypting: $cipher --> $clear", $outFile);
121
$x = compare_files( $input, $clear, 1);
124
print( "SUCCESS - files match: $input, $clear\n");
125
print( OUT "SUCCESS - files match: $input, $clear\n");
129
print( "ERROR: files don't match\n");
130
print( OUT "ERROR: files don't match\n");
135
# Now do the same encryption but use Base64
138
$outFile = "$output_path\\B64enc.out";
139
system("openssl2 $i -a -e -bufsize 113 -k test -in $input -out $cipher > $outFile");
140
log_output("Encrypting(B64): $cipher --> $clear", $outFile);
143
$outFile = "$output_path\\B64dec.out";
144
system("openssl2 $i -a -d -bufsize 157 -k test -in $cipher -out $clear > $outFile");
145
log_output("Decrypting(B64): $cipher --> $clear", $outFile);
148
$x = compare_files( $input, $clear, 1);
151
print( "SUCCESS - files match: $input, $clear\n");
152
print( OUT "SUCCESS - files match: $input, $clear\n");
156
print( "ERROR: files don't match\n");
157
print( OUT "ERROR: files don't match\n");
164
# delete the temporary files
170
############################################################################
175
my $outFile = "$output_path\\pem.out";
178
"crl" => "testcrl.pem",
179
"pkcs7" => "testp7.pem",
180
"req" => "testreq2.pem",
181
"rsa" => "testrsa.pem",
182
"x509" => "testx509.pem",
183
"x509" => "v3-cert1.pem",
184
"sess_id" => "testsid.pem" );
187
print( "\nRUNNING PEM TESTS:\n\n");
189
print( OUT "\n========================================================\n");
190
print( OUT "PEM TESTS:\n\n");
192
foreach $i (keys(%pem_tests))
194
log_desc( "Testing: $i");
196
my $input = "$test_path\\$pem_tests{$i}";
198
$tmp_out = "$output_path\\$pem_tests{$i}";
202
system("openssl2 $i -in $input -out $tmp_out > $outFile");
203
log_output( "openssl2 $i -in $input -out $tmp_out", $outFile);
207
system("openssl2 $i -in $input -out $tmp_out -config $OpenSSL_config > $outFile");
208
log_output( "openssl2 $i -in $input -out $tmp_out -config $OpenSSL_config", $outFile );
211
$x = compare_files( $input, $tmp_out);
214
print( "SUCCESS - files match: $input, $tmp_out\n");
215
print( OUT "SUCCESS - files match: $input, $tmp_out\n");
219
print( "ERROR: files don't match\n");
220
print( OUT "ERROR: files don't match\n");
228
############################################################################
232
my $outFile = "$output_path\\verify.out";
234
my @cert_files = <$cert_path\\*.pem>;
236
print( "\nRUNNING VERIFY TESTS:\n\n");
238
print( OUT "\n========================================================\n");
239
print( OUT "VERIFY TESTS:\n\n");
241
make_tmp_cert_file();
243
foreach $i (@cert_files)
245
system("openssl2 verify -CAfile $tmp_cert $i >$outFile");
246
log_desc("Verifying cert: $i");
247
log_output("openssl2 verify -CAfile $tmp_cert $i", $outFile);
252
############################################################################
255
my $outFile = "$output_path\\ssl_tst.out";
256
my($CAcert) = "$output_path\\certCA.ss";
257
my($Ukey) = "$output_path\\keyU.ss";
258
my($Ucert) = "$output_path\\certU.ss";
259
my($ssltest)= "ssltest -key $Ukey -cert $Ucert -c_key $Ukey -c_cert $Ucert -CAfile $CAcert";
261
print( "\nRUNNING SSL TESTS:\n\n");
263
print( OUT "\n========================================================\n");
264
print( OUT "SSL TESTS:\n\n");
266
system("ssltest -ssl2 >$outFile");
267
log_desc("Testing sslv2:");
268
log_output("ssltest -ssl2", $outFile);
270
system("$ssltest -ssl2 -server_auth >$outFile");
271
log_desc("Testing sslv2 with server authentication:");
272
log_output("$ssltest -ssl2 -server_auth", $outFile);
274
system("$ssltest -ssl2 -client_auth >$outFile");
275
log_desc("Testing sslv2 with client authentication:");
276
log_output("$ssltest -ssl2 -client_auth", $outFile);
278
system("$ssltest -ssl2 -server_auth -client_auth >$outFile");
279
log_desc("Testing sslv2 with both client and server authentication:");
280
log_output("$ssltest -ssl2 -server_auth -client_auth", $outFile);
282
system("ssltest -ssl3 >$outFile");
283
log_desc("Testing sslv3:");
284
log_output("ssltest -ssl3", $outFile);
286
system("$ssltest -ssl3 -server_auth >$outFile");
287
log_desc("Testing sslv3 with server authentication:");
288
log_output("$ssltest -ssl3 -server_auth", $outFile);
290
system("$ssltest -ssl3 -client_auth >$outFile");
291
log_desc("Testing sslv3 with client authentication:");
292
log_output("$ssltest -ssl3 -client_auth", $outFile);
294
system("$ssltest -ssl3 -server_auth -client_auth >$outFile");
295
log_desc("Testing sslv3 with both client and server authentication:");
296
log_output("$ssltest -ssl3 -server_auth -client_auth", $outFile);
298
system("ssltest >$outFile");
299
log_desc("Testing sslv2/sslv3:");
300
log_output("ssltest", $outFile);
302
system("$ssltest -server_auth >$outFile");
303
log_desc("Testing sslv2/sslv3 with server authentication:");
304
log_output("$ssltest -server_auth", $outFile);
306
system("$ssltest -client_auth >$outFile");
307
log_desc("Testing sslv2/sslv3 with client authentication:");
308
log_output("$ssltest -client_auth ", $outFile);
310
system("$ssltest -server_auth -client_auth >$outFile");
311
log_desc("Testing sslv2/sslv3 with both client and server authentication:");
312
log_output("$ssltest -server_auth -client_auth", $outFile);
314
system("ssltest -bio_pair -ssl2 >$outFile");
315
log_desc("Testing sslv2 via BIO pair:");
316
log_output("ssltest -bio_pair -ssl2", $outFile);
318
system("ssltest -bio_pair -dhe1024dsa -v >$outFile");
319
log_desc("Testing sslv2/sslv3 with 1024 bit DHE via BIO pair:");
320
log_output("ssltest -bio_pair -dhe1024dsa -v", $outFile);
322
system("$ssltest -bio_pair -ssl2 -server_auth >$outFile");
323
log_desc("Testing sslv2 with server authentication via BIO pair:");
324
log_output("$ssltest -bio_pair -ssl2 -server_auth", $outFile);
326
system("$ssltest -bio_pair -ssl2 -client_auth >$outFile");
327
log_desc("Testing sslv2 with client authentication via BIO pair:");
328
log_output("$ssltest -bio_pair -ssl2 -client_auth", $outFile);
330
system("$ssltest -bio_pair -ssl2 -server_auth -client_auth >$outFile");
331
log_desc("Testing sslv2 with both client and server authentication via BIO pair:");
332
log_output("$ssltest -bio_pair -ssl2 -server_auth -client_auth", $outFile);
334
system("ssltest -bio_pair -ssl3 >$outFile");
335
log_desc("Testing sslv3 via BIO pair:");
336
log_output("ssltest -bio_pair -ssl3", $outFile);
338
system("$ssltest -bio_pair -ssl3 -server_auth >$outFile");
339
log_desc("Testing sslv3 with server authentication via BIO pair:");
340
log_output("$ssltest -bio_pair -ssl3 -server_auth", $outFile);
342
system("$ssltest -bio_pair -ssl3 -client_auth >$outFile");
343
log_desc("Testing sslv3 with client authentication via BIO pair:");
344
log_output("$ssltest -bio_pair -ssl3 -client_auth", $outFile);
346
system("$ssltest -bio_pair -ssl3 -server_auth -client_auth >$outFile");
347
log_desc("Testing sslv3 with both client and server authentication via BIO pair:");
348
log_output("$ssltest -bio_pair -ssl3 -server_auth -client_auth", $outFile);
350
system("ssltest -bio_pair >$outFile");
351
log_desc("Testing sslv2/sslv3 via BIO pair:");
352
log_output("ssltest -bio_pair", $outFile);
354
system("$ssltest -bio_pair -server_auth >$outFile");
355
log_desc("Testing sslv2/sslv3 with server authentication via BIO pair:");
356
log_output("$ssltest -bio_pair -server_auth", $outFile);
358
system("$ssltest -bio_pair -client_auth >$outFile");
359
log_desc("Testing sslv2/sslv3 with client authentication via BIO pair:");
360
log_output("$ssltest -bio_pair -client_auth", $outFile);
362
system("$ssltest -bio_pair -server_auth -client_auth >$outFile");
363
log_desc("Testing sslv2/sslv3 with both client and server authentication via BIO pair:");
364
log_output("$ssltest -bio_pair -server_auth -client_auth", $outFile);
368
############################################################################
371
my $outFile = "$output_path\\ca_tst.out";
373
my($CAkey) = "$output_path\\keyCA.ss";
374
my($CAcert) = "$output_path\\certCA.ss";
375
my($CAserial) = "$output_path\\certCA.srl";
376
my($CAreq) = "$output_path\\reqCA.ss";
377
my($CAreq2) = "$output_path\\req2CA.ss";
379
my($CAconf) = "$test_path\\CAss.cnf";
381
my($Uconf) = "$test_path\\Uss.cnf";
383
my($Ukey) = "$output_path\\keyU.ss";
384
my($Ureq) = "$output_path\\reqU.ss";
385
my($Ucert) = "$output_path\\certU.ss";
387
print( "\nRUNNING CA TESTS:\n\n");
389
print( OUT "\n========================================================\n");
390
print( OUT "CA TESTS:\n");
392
system("openssl2 req -config $CAconf -out $CAreq -keyout $CAkey -new >$outFile");
393
log_desc("Make a certificate request using req:");
394
log_output("openssl2 req -config $CAconf -out $CAreq -keyout $CAkey -new", $outFile);
396
system("openssl2 x509 -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey >$outFile");
397
log_desc("Convert the certificate request into a self signed certificate using x509:");
398
log_output("openssl2 x509 -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey", $outFile);
400
system("openssl2 x509 -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >$outFile");
401
log_desc("Convert a certificate into a certificate request using 'x509':");
402
log_output("openssl2 x509 -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2", $outFile);
404
system("openssl2 req -config $OpenSSL_config -verify -in $CAreq -noout >$outFile");
405
log_output("openssl2 req -config $OpenSSL_config -verify -in $CAreq -noout", $outFile);
407
system("openssl2 req -config $OpenSSL_config -verify -in $CAreq2 -noout >$outFile");
408
log_output( "openssl2 req -config $OpenSSL_config -verify -in $CAreq2 -noout", $outFile);
410
system("openssl2 verify -CAfile $CAcert $CAcert >$outFile");
411
log_output("openssl2 verify -CAfile $CAcert $CAcert", $outFile);
413
system("openssl2 req -config $Uconf -out $Ureq -keyout $Ukey -new >$outFile");
414
log_desc("Make another certificate request using req:");
415
log_output("openssl2 req -config $Uconf -out $Ureq -keyout $Ukey -new", $outFile);
417
system("openssl2 x509 -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey -CAserial $CAserial >$outFile");
418
log_desc("Sign certificate request with the just created CA via x509:");
419
log_output("openssl2 x509 -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey -CAserial $CAserial", $outFile);
421
system("openssl2 verify -CAfile $CAcert $Ucert >$outFile");
422
log_output("openssl2 verify -CAfile $CAcert $Ucert", $outFile);
424
system("openssl2 x509 -subject -issuer -startdate -enddate -noout -in $Ucert >$outFile");
425
log_desc("Certificate details");
426
log_output("openssl2 x509 -subject -issuer -startdate -enddate -noout -in $Ucert", $outFile);
429
print(OUT "The generated CA certificate is $CAcert\n");
430
print(OUT "The generated CA private key is $CAkey\n");
431
print(OUT "The current CA signing serial number is in $CAserial\n");
433
print(OUT "The generated user certificate is $Ucert\n");
434
print(OUT "The generated user private key is $Ukey\n");
438
############################################################################
439
sub log_output( $ $ )
441
my( $desc, $file ) = @_;
449
print(OUT "$desc\n");
452
# loop waiting for test program to complete
453
while ( stat($file) == 0)
454
{ print(". "); sleep(1); }
457
# copy test output to log file
467
# close and delete the temporary test output file
473
$msg = "Test Succeeded";
477
$msg = "Test Failed";
484
print("$msg - press ENTER to continue...");
489
# Several of the testing scripts run a loop loading the
490
# same NLM with different options.
491
# On slow NetWare machines there appears to be some delay in the
492
# OS actually unloading the test nlms and the OS complains about.
493
# the NLM already being loaded. This additional pause is to
494
# to help provide a little more time for unloading before trying to
500
############################################################################
509
print(OUT "$desc\n");
510
print(OUT "======================================\n");
513
############################################################################
514
sub compare_files( $ $ $ )
516
my( $file1, $file2, $binary ) = @_;
517
my( $n1, $n2, $b1, $b2 );
520
open(IN0, $file1) || die "\nunable to open $file1\n";
521
open(IN1, $file2) || die "\nunable to open $file2\n";
531
$n1 = read(IN0, $b1, 512);
532
$n2 = read(IN1, $b2, 512);
534
if ($n1 != $n2) {last;}
535
if ($b1 != $b2) {last;}
548
############################################################################
555
print("Press ENTER to continue...");
562
############################################################################
563
sub make_tmp_cert_file()
565
my @cert_files = <$cert_path\\*.pem>;
567
# delete the file if it already exists
570
open( TMP_CERT, ">$tmp_cert") || die "\nunable to open $tmp_cert\n";
572
print("building temporary cert file\n");
574
# create a temporary cert file that contains all the certs
575
foreach $i (@cert_files)
577
open( IN_CERT, $i ) || die "\nunable to open $i\n";
581
$n = sysread(IN_CERT, $data, 1024);
589
syswrite(TMP_CERT, $data, $n);