1 # perl script to run OpenSSL tests
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 $outFile = "$output_path\\$i.out";
71 system("$i > $outFile");
72 log_desc("Test: $i\.nlm:");
73 log_output("", $outFile );
77 ############################################################################
82 my @enc_tests = ( "enc", "rc4", "des-cfb", "des-ede-cfb", "des-ede3-cfb",
83 "des-ofb", "des-ede-ofb", "des-ede3-ofb",
84 "des-ecb", "des-ede", "des-ede3", "des-cbc",
85 "des-ede-cbc", "des-ede3-cbc", "idea-ecb", "idea-cfb",
86 "idea-ofb", "idea-cbc", "rc2-ecb", "rc2-cfb",
87 "rc2-ofb", "rc2-cbc", "bf-ecb", "bf-cfb",
90 my $input = "$base_path\\do_tests.pl";
91 my $cipher = "$output_path\\cipher.out";
92 my $clear = "$output_path\\clear.out";
94 print( "\nRUNNING ENCRYPTION & DECRYPTION TESTS:\n\n");
96 print( OUT "\n========================================================\n");
97 print( OUT "FILE ENCRYPTION & DECRYPTION TESTS:\n\n");
99 foreach $i (@enc_tests)
101 log_desc("Testing: $i");
104 $outFile = "$output_path\\enc.out";
105 system("openssl2 $i -e -bufsize 113 -k test -in $input -out $cipher > $outFile" );
106 log_output("Encrypting: $input --> $cipher", $outFile);
109 $outFile = "$output_path\\dec.out";
110 system("openssl2 $i -d -bufsize 157 -k test -in $cipher -out $clear > $outFile");
111 log_output("Decrypting: $cipher --> $clear", $outFile);
114 $x = compare_files( $input, $clear, 1);
117 print( "SUCCESS - files match: $input, $clear\n");
118 print( OUT "SUCCESS - files match: $input, $clear\n");
122 print( "ERROR: files don't match\n");
123 print( OUT "ERROR: files don't match\n");
128 # Now do the same encryption but use Base64
131 $outFile = "$output_path\\B64enc.out";
132 system("openssl2 $i -a -e -bufsize 113 -k test -in $input -out $cipher > $outFile");
133 log_output("Encrypting(B64): $cipher --> $clear", $outFile);
136 $outFile = "$output_path\\B64dec.out";
137 system("openssl2 $i -a -d -bufsize 157 -k test -in $cipher -out $clear > $outFile");
138 log_output("Decrypting(B64): $cipher --> $clear", $outFile);
141 $x = compare_files( $input, $clear, 1);
144 print( "SUCCESS - files match: $input, $clear\n");
145 print( OUT "SUCCESS - files match: $input, $clear\n");
149 print( "ERROR: files don't match\n");
150 print( OUT "ERROR: files don't match\n");
157 # delete the temporary files
163 ############################################################################
168 my $outFile = "$output_path\\pem.out";
171 "crl" => "testcrl.pem",
172 "pkcs7" => "testp7.pem",
173 "req" => "testreq2.pem",
174 "rsa" => "testrsa.pem",
175 "x509" => "testx509.pem",
176 "x509" => "v3-cert1.pem",
177 "sess_id" => "testsid.pem" );
180 print( "\nRUNNING PEM TESTS:\n\n");
182 print( OUT "\n========================================================\n");
183 print( OUT "PEM TESTS:\n\n");
185 foreach $i (keys(%pem_tests))
187 log_desc( "Testing: $i");
189 my $input = "$test_path\\$pem_tests{$i}";
191 $tmp_out = "$output_path\\$pem_tests{$i}";
195 system("openssl2 $i -in $input -out $tmp_out > $outFile");
196 log_output( "openssl2 $i -in $input -out $tmp_out", $outFile);
200 system("openssl2 $i -in $input -out $tmp_out -config $OpenSSL_config > $outFile");
201 log_output( "openssl2 $i -in $input -out $tmp_out -config $OpenSSL_config", $outFile );
204 $x = compare_files( $input, $tmp_out);
207 print( "SUCCESS - files match: $input, $tmp_out\n");
208 print( OUT "SUCCESS - files match: $input, $tmp_out\n");
212 print( "ERROR: files don't match\n");
213 print( OUT "ERROR: files don't match\n");
221 ############################################################################
225 my $outFile = "$output_path\\verify.out";
227 my @cert_files = <$cert_path\\*.pem>;
229 print( "\nRUNNING VERIFY TESTS:\n\n");
231 print( OUT "\n========================================================\n");
232 print( OUT "VERIFY TESTS:\n\n");
234 make_tmp_cert_file();
236 foreach $i (@cert_files)
238 system("openssl2 verify -CAfile $tmp_cert $i >$outFile");
239 log_desc("Verifying cert: $i");
240 log_output("openssl2 verify -CAfile $tmp_cert $i", $outFile);
245 ############################################################################
248 my $outFile = "$output_path\\ssl_tst.out";
250 print( "\nRUNNING SSL TESTS:\n\n");
252 print( OUT "\n========================================================\n");
253 print( OUT "SSL TESTS:\n\n");
255 make_tmp_cert_file();
257 system("ssltest -ssl2 >$outFile");
258 log_desc("Testing sslv2:");
259 log_output("ssltest -ssl2", $outFile);
261 system("ssltest -ssl2 -server_auth -CAfile $tmp_cert >$outFile");
262 log_desc("Testing sslv2 with server authentication:");
263 log_output("ssltest -ssl2 -server_auth -CAfile $tmp_cert", $outFile);
265 system("ssltest -ssl2 -client_auth -CAfile $tmp_cert >$outFile");
266 log_desc("Testing sslv2 with client authentication:");
267 log_output("ssltest -ssl2 -client_auth -CAfile $tmp_cert", $outFile);
269 system("ssltest -ssl2 -server_auth -client_auth -CAfile $tmp_cert >$outFile");
270 log_desc("Testing sslv2 with both client and server authentication:");
271 log_output("ssltest -ssl2 -server_auth -client_auth -CAfile $tmp_cert", $outFile);
273 system("ssltest -ssl3 >$outFile");
274 log_desc("Testing sslv3:");
275 log_output("ssltest -ssl3", $outFile);
277 system("ssltest -ssl3 -server_auth -CAfile $tmp_cert >$outFile");
278 log_desc("Testing sslv3 with server authentication:");
279 log_output("ssltest -ssl3 -server_auth -CAfile $tmp_cert", $outFile);
281 system("ssltest -ssl3 -client_auth -CAfile $tmp_cert >$outFile");
282 log_desc("Testing sslv3 with client authentication:");
283 log_output("ssltest -ssl3 -client_auth -CAfile $tmp_cert", $outFile);
285 system("ssltest -ssl3 -server_auth -client_auth -CAfile $tmp_cert >$outFile");
286 log_desc("Testing sslv3 with both client and server authentication:");
287 log_output("ssltest -ssl3 -server_auth -client_auth -CAfile $tmp_cert", $outFile);
289 system("ssltest >$outFile");
290 log_desc("Testing sslv2/sslv3:");
291 log_output("ssltest", $outFile);
293 system("ssltest -server_auth -CAfile $tmp_cert >$outFile");
294 log_desc("Testing sslv2/sslv3 with server authentication:");
295 log_output("ssltest -server_auth -CAfile $tmp_cert", $outFile);
297 system("ssltest -client_auth -CAfile $tmp_cert >$outFile");
298 log_desc("Testing sslv2/sslv3 with client authentication:");
299 log_output("ssltest -client_auth -CAfile $tmp_cert", $outFile);
301 system("ssltest -server_auth -client_auth -CAfile $tmp_cert >$outFile");
302 log_desc("Testing sslv2/sslv3 with both client and server authentication:");
303 log_output("ssltest -server_auth -client_auth -CAfile $tmp_cert", $outFile);
305 system("ssltest -bio_pair -ssl2 >$outFile");
306 log_desc("Testing sslv2 via BIO pair:");
307 log_output("ssltest -bio_pair -ssl2", $outFile);
309 system("ssltest -bio_pair -dhe1024dsa -v >$outFile");
310 log_desc("Testing sslv2/sslv3 with 1024 bit DHE via BIO pair:");
311 log_output("ssltest -bio_pair -dhe1024dsa -v", $outFile);
313 system("ssltest -bio_pair -ssl2 -server_auth -CAfile $tmp_cert >$outFile");
314 log_desc("Testing sslv2 with server authentication via BIO pair:");
315 log_output("ssltest -bio_pair -ssl2 -server_auth -CAfile $tmp_cert", $outFile);
317 system("ssltest -bio_pair -ssl2 -client_auth -CAfile $tmp_cert >$outFile");
318 log_desc("Testing sslv2 with client authentication via BIO pair:");
319 log_output("ssltest -bio_pair -ssl2 -client_auth -CAfile $tmp_cert", $outFile);
321 system("ssltest -bio_pair -ssl2 -server_auth -client_auth -CAfile $tmp_cert >$outFile");
322 log_desc("Testing sslv2 with both client and server authentication via BIO pair:");
323 log_output("ssltest -bio_pair -ssl2 -server_auth -client_auth -CAfile $tmp_cert", $outFile);
325 system("ssltest -bio_pair -ssl3 >$outFile");
326 log_desc("Testing sslv3 via BIO pair:");
327 log_output("ssltest -bio_pair -ssl3", $outFile);
329 system("ssltest -bio_pair -ssl3 -server_auth -CAfile $tmp_cert >$outFile");
330 log_desc("Testing sslv3 with server authentication via BIO pair:");
331 log_output("ssltest -bio_pair -ssl3 -server_auth -CAfile $tmp_cert", $outFile);
333 system("ssltest -bio_pair -ssl3 -client_auth -CAfile $tmp_cert >$outFile");
334 log_desc("Testing sslv3 with client authentication via BIO pair:");
335 log_output("ssltest -bio_pair -ssl3 -client_auth -CAfile $tmp_cert", $outFile);
337 system("ssltest -bio_pair -ssl3 -server_auth -client_auth -CAfile $tmp_cert >$outFile");
338 log_desc("Testing sslv3 with both client and server authentication via BIO pair:");
339 log_output("ssltest -bio_pair -ssl3 -server_auth -client_auth -CAfile $tmp_cert", $outFile);
341 system("ssltest -bio_pair >$outFile");
342 log_desc("Testing sslv2/sslv3 via BIO pair:");
343 log_output("ssltest -bio_pair", $outFile);
345 system("ssltest -bio_pair -server_auth -CAfile $tmp_cert >$outFile");
346 log_desc("Testing sslv2/sslv3 with server authentication via BIO pair:");
347 log_output("ssltest -bio_pair -server_auth -CAfile $tmp_cert", $outFile);
349 system("ssltest -bio_pair -client_auth -CAfile $tmp_cert >$outFile");
350 log_desc("Testing sslv2/sslv3 with client authentication via BIO pair:");
351 log_output("ssltest -bio_pair -client_auth -CAfile $tmp_cert", $outFile);
353 system("ssltest -bio_pair -server_auth -client_auth -CAfile $tmp_cert >$outFile");
354 log_desc("Testing sslv2/sslv3 with both client and server authentication via BIO pair:");
355 log_output("ssltest -bio_pair -server_auth -client_auth -CAfile $tmp_cert", $outFile);
359 ############################################################################
362 my $outFile = "$output_path\\ca_tst.out";
364 my($CAkey) = "$output_path\\keyCA.ss";
365 my($CAcert) = "$output_path\\certCA.ss";
366 my($CAserial) = "$output_path\\certCA.srl";
367 my($CAreq) = "$output_path\\reqCA.ss";
368 my($CAreq2) = "$output_path\\req2CA.ss";
370 my($CAconf) = "$test_path\\CAss.cnf";
372 my($Uconf) = "$test_path\\Uss.cnf";
374 my($Ukey) = "$output_path\\keyU.ss";
375 my($Ureq) = "$output_path\\reqU.ss";
376 my($Ucert) = "$output_path\\certU.ss";
378 print( "\nRUNNING CA TESTS:\n\n");
380 print( OUT "\n========================================================\n");
381 print( OUT "CA TESTS:\n");
383 system("openssl2 req -config $CAconf -out $CAreq -keyout $CAkey -new >$outFile");
384 log_desc("Make a certificate request using req:");
385 log_output("openssl2 req -config $CAconf -out $CAreq -keyout $CAkey -new", $outFile);
387 system("openssl2 x509 -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey >$outFile");
388 log_desc("Convert the certificate request into a self signed certificate using x509:");
389 log_output("openssl2 x509 -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey", $outFile);
391 system("openssl2 x509 -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >$outFile");
392 log_desc("Convert a certificate into a certificate request using 'x509':");
393 log_output("openssl2 x509 -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2", $outFile);
395 system("openssl2 req -config $OpenSSL_config -verify -in $CAreq -noout >$outFile");
396 log_output("openssl2 req -config $OpenSSL_config -verify -in $CAreq -noout", $outFile);
398 system("openssl2 req -config $OpenSSL_config -verify -in $CAreq2 -noout >$outFile");
399 log_output( "openssl2 req -config $OpenSSL_config -verify -in $CAreq2 -noout", $outFile);
401 system("openssl2 verify -CAfile $CAcert $CAcert >$outFile");
402 log_output("openssl2 verify -CAfile $CAcert $CAcert", $outFile);
404 system("openssl2 req -config $Uconf -out $Ureq -keyout $Ukey -new >$outFile");
405 log_desc("Make another certificate request using req:");
406 log_output("openssl2 req -config $Uconf -out $Ureq -keyout $Ukey -new", $outFile);
408 system("openssl2 x509 -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey -CAserial $CAserial >$outFile");
409 log_desc("Sign certificate request with the just created CA via x509:");
410 log_output("openssl2 x509 -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey -CAserial $CAserial", $outFile);
412 system("openssl2 verify -CAfile $CAcert $Ucert >$outFile");
413 log_output("openssl2 verify -CAfile $CAcert $Ucert", $outFile);
415 system("openssl2 x509 -subject -issuer -startdate -enddate -noout -in $Ucert >$outFile");
416 log_desc("Certificate details");
417 log_output("openssl2 x509 -subject -issuer -startdate -enddate -noout -in $Ucert", $outFile);
420 print(OUT "The generated CA certificate is $CAcert\n");
421 print(OUT "The generated CA private key is $CAkey\n");
422 print(OUT "The current CA signing serial number is in $CAserial\n");
424 print(OUT "The generated user certificate is $Ucert\n");
425 print(OUT "The generated user private key is $Ukey\n");
429 ############################################################################
430 sub log_output( $ $ )
432 my( $desc, $file ) = @_;
440 print(OUT "$desc\n");
443 # loop waiting for test program to complete
444 while ( stat($file) == 0)
445 { print(". "); sleep(1); }
448 # copy test output to log file
458 # close and delete the temporary test output file
464 $msg = "Test Succeeded";
468 $msg = "Test Failed";
475 print("$msg - press ENTER to continue...");
480 # Several of the testing scripts run a loop loading the
481 # same NLM with different options.
482 # On slow NetWare machines there appears to be some delay in the
483 # OS actually unloading the test nlms and the OS complains about.
484 # the NLM already being loaded. This additional pause is to
485 # to help provide a little more time for unloading before trying to
491 ############################################################################
500 print(OUT "$desc\n");
501 print(OUT "======================================\n");
504 ############################################################################
505 sub compare_files( $ $ $ )
507 my( $file1, $file2, $binary ) = @_;
508 my( $n1, $n2, $b1, $b2 );
511 open(IN0, $file1) || die "\nunable to open $file1\n";
512 open(IN1, $file2) || die "\nunable to open $file2\n";
522 $n1 = read(IN0, $b1, 512);
523 $n2 = read(IN1, $b2, 512);
525 if ($n1 != $n2) {last;}
526 if ($b1 != $b2) {last;}
539 ############################################################################
546 print("Press ENTER to continue...");
553 ############################################################################
554 sub make_tmp_cert_file()
556 my @cert_files = <$cert_path\\*.pem>;
558 # delete the file if it already exists
561 open( TMP_CERT, ">$tmp_cert") || die "\nunable to open $tmp_cert\n";
563 print("building temporary cert file\n");
565 # create a temporary cert file that contains all the certs
566 foreach $i (@cert_files)
568 open( IN_CERT, $i ) || die "\nunable to open $i\n";
572 $n = sysread(IN_CERT, $data, 1024);
580 syswrite(TMP_CERT, $data, $n);