diff options
author | Thomas Roessler <roessler@does-not-exist.org> | 2002-03-25 10:13:28 +0000 |
---|---|---|
committer | Thomas Roessler <roessler@does-not-exist.org> | 2002-03-25 10:13:28 +0000 |
commit | 688b966518ba15620c71811863e7786d8fbb85e9 (patch) | |
tree | 8b9f7f9ca6c5ae0ee310690121d8c3875fd33ec1 /contrib | |
parent | 5a9158ac64e3062b5bc6e7af4b174cbe20364d24 (diff) |
Include a test script by Mike Schiraldi. It's perl > the one I have
installed, so I'm just putting it into contrib for now.
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/Makefile.in | 2 | ||||
-rw-r--r-- | contrib/smime_keys_test.pl | 134 |
2 files changed, 135 insertions, 1 deletions
diff --git a/contrib/Makefile.in b/contrib/Makefile.in index 7f180bce..db9376db 100644 --- a/contrib/Makefile.in +++ b/contrib/Makefile.in @@ -22,7 +22,7 @@ subdir = contrib SAMPLES = Mush.rc Pine.rc gpg.rc pgp2.rc pgp5.rc pgp6.rc Tin.rc \ sample.muttrc sample.mailcap sample.muttrc-tlr smime.rc \ - ca-bundle.crt + ca-bundle.crt smime_keys_test.pl DISTFILES = Makefile.in language.txt language50.txt \ patch.slang-1.2.2.keypad.1 \ diff --git a/contrib/smime_keys_test.pl b/contrib/smime_keys_test.pl new file mode 100644 index 00000000..79c555cc --- /dev/null +++ b/contrib/smime_keys_test.pl @@ -0,0 +1,134 @@ +#! /usr/bin/perl -W + +# by Mike Schiraldi <raldi@research.netsol.com> + +use strict; +use Expect; + +sub run ($;$ ); + +umask 077; # probably not necc. but can't hurt + +my $tmpdir = "/tmp/smime_keys_test-$$-" . time; + +mkdir $tmpdir or die; +chdir $tmpdir or die; + +open TMP, '>muttrc' or die; +print TMP <<EOF; +set smime_ca_location="$tmpdir/ca-bundle.crt" +set smime_certificates="$tmpdir/certificates" +set smime_keys="$tmpdir/keys" +EOF +close TMP; + +$ENV{MUTT_CMDLINE} = "mutt -F $tmpdir/muttrc"; + +# make a user key +run 'smime_keys init'; +run 'openssl genrsa -out user.key 1024'; + +# make a request for this key to be signed +run 'openssl req -new -key user.key -out newreq.pem', "\n\nx\n\nx\nx\nuser\@smime.mutt\n\nx\n"; + +mkdir 'demoCA' or die; +mkdir 'demoCA/certs' or die; +mkdir 'demoCA/crl' or die; +mkdir 'demoCA/newcerts' or die; +mkdir 'demoCA/private' or die; +open OUT, '>demoCA/serial' or die; +print OUT "01\n"; +close OUT; +open OUT, '>demoCA/index.txt' or die; +close OUT; + +# make the CA +run 'openssl req -new -x509 -keyout demoCA/private/cakey.pem -out demoCA/cacert.pem -days 7300 -nodes', + "\n\nx\n\nx\nx\n\n"; + +# trust it +run 'smime_keys add_root demoCA/cacert.pem', "root_CA\n"; + +# have the CA process the request +run 'openssl ca -batch -startdate 000101000000Z -enddate 200101000000Z -days 7300 ' . + '-policy policy_anything -out newcert.pem -infiles newreq.pem'; + +unlink 'newreq.pem' or die; + +# put it all in a .p12 bundle +run 'openssl pkcs12 -export -inkey user.key -in newcert.pem -out cert.p12 -CAfile demoCA/cacert.pem -chain', "pass1\n" x 2; +unlink 'newcert.pem' or die; +unlink 'demoCA/cacert.pem' or die; +unlink 'demoCA/index.txt' or die; +unlink 'demoCA/index.txt.old' or die; +unlink 'demoCA/serial' or die; +unlink 'demoCA/serial.old' or die; +unlink 'demoCA/newcerts/01.pem' or die; +unlink 'demoCA/private/cakey.pem' or die; +rmdir 'demoCA/certs' or die; +rmdir 'demoCA/crl' or die; +rmdir 'demoCA/private' or die; +rmdir 'demoCA/newcerts' or die; +rmdir 'demoCA' or die; + +# have smime_keys process it +run 'smime_keys add_p12 cert.p12', "pass1\n" . "pass2\n" x 2 . "old_label\n"; +unlink 'cert.p12' or die; + +# make sure it showed up +run 'smime_keys list > list'; + +open IN, 'list' or die; +<IN> eq "\n" or die; +<IN> =~ /^(.*)\: Issued for\: user\@smime\.mutt \"old_label\" \(Unverified\)\n/ or die; +close IN; + +my $keyid = $1; + +# see if we can rename it +run "smime_keys label $keyid", "new_label\n"; + +# make sure it worked +run 'smime_keys list > list'; + +open IN, 'list' or die; +<IN> eq "\n" or die; +<IN> =~ /^$keyid\: Issued for\: user\@smime\.mutt \"new_label\" \(Unverified\)\n/ or die; +close IN; + +unlink 'list' or die; + +# try signing something +run "openssl smime -sign -signer certificates/$keyid -inkey user.key -in /etc/passwd -certfile certificates/37adefc3.0 > signed"; +unlink 'user.key' or die; + +# verify it +run 'openssl smime -verify -out /dev/null -in signed -CAfile ca-bundle.crt'; +unlink 'signed' or die; + +# clean up +unlink 'ca-bundle.crt' or die; +unlink 'muttrc' or die; +unlink 'keys/.index' or die; +unlink 'certificates/.index' or die; +unlink <keys/*> or die; +unlink <certificates/*> or die; +rmdir 'keys' or die; +rmdir 'certificates' or die; +chdir '/' or die; +rmdir $tmpdir or die; + + +sub run ($;$) { + my $cmd = shift or die; + my $input = shift; + + print "\n\nRunning [$cmd]\n"; + + my $exp = Expect->spawn ($cmd); + if (defined $input) { + print $exp $input; + } + $exp->soft_close; + $? and die "$cmd returned $?"; +} |