3 # by Mike Schiraldi <raldi@research.netsol.com>
10 umask 077; # probably not necc. but can't hurt
12 my $tmpdir = "/tmp/smime_keys_test-$$-" . time;
17 open TMP, '>muttrc' or die;
19 set smime_ca_location="$tmpdir/ca-bundle.crt"
20 set smime_certificates="$tmpdir/certificates"
21 set smime_keys="$tmpdir/keys"
25 $ENV{MUTT_CMDLINE} = "mutt -F $tmpdir/muttrc";
28 run 'smime_keys init';
29 run 'openssl genrsa -out user.key 1024';
31 # make a request for this key to be signed
32 run 'openssl req -new -key user.key -out newreq.pem', "\n\nx\n\nx\nx\nuser\@smime.mutt\n\nx\n";
34 mkdir 'demoCA' or die;
35 mkdir 'demoCA/certs' or die;
36 mkdir 'demoCA/crl' or die;
37 mkdir 'demoCA/newcerts' or die;
38 mkdir 'demoCA/private' or die;
39 open OUT, '>demoCA/serial' or die;
42 open OUT, '>demoCA/index.txt' or die;
46 run 'openssl req -new -x509 -keyout demoCA/private/cakey.pem -out demoCA/cacert.pem -days 7300 -nodes',
50 run 'smime_keys add_root demoCA/cacert.pem', "root_CA\n";
52 # have the CA process the request
53 run 'openssl ca -batch -startdate 000101000000Z -enddate 200101000000Z -days 7300 ' .
54 '-policy policy_anything -out newcert.pem -infiles newreq.pem';
56 unlink 'newreq.pem' or die;
58 # put it all in a .p12 bundle
59 run 'openssl pkcs12 -export -inkey user.key -in newcert.pem -out cert.p12 -CAfile demoCA/cacert.pem -chain', "pass1\n" x 2;
60 unlink 'newcert.pem' or die;
61 unlink 'demoCA/cacert.pem' or die;
62 unlink 'demoCA/index.txt' or die;
63 unlink 'demoCA/index.txt.old' or die;
64 unlink 'demoCA/serial' or die;
65 unlink 'demoCA/serial.old' or die;
66 unlink 'demoCA/newcerts/01.pem' or die;
67 unlink 'demoCA/private/cakey.pem' or die;
68 rmdir 'demoCA/certs' or die;
69 rmdir 'demoCA/crl' or die;
70 rmdir 'demoCA/private' or die;
71 rmdir 'demoCA/newcerts' or die;
72 rmdir 'demoCA' or die;
74 # have smime_keys process it
75 run 'smime_keys add_p12 cert.p12', "pass1\n" . "pass2\n" x 2 . "old_label\n";
76 unlink 'cert.p12' or die;
78 # make sure it showed up
79 run 'smime_keys list > list';
81 open IN, 'list' or die;
83 <IN> =~ /^(.*)\: Issued for\: user\@smime\.mutt \"old_label\" \(Unverified\)\n/ or die;
88 # see if we can rename it
89 run "smime_keys label $keyid", "new_label\n";
92 run 'smime_keys list > list';
94 open IN, 'list' or die;
96 <IN> =~ /^$keyid\: Issued for\: user\@smime\.mutt \"new_label\" \(Unverified\)\n/ or die;
101 # try signing something
102 run "openssl smime -sign -signer certificates/$keyid -inkey user.key -in /etc/passwd -certfile certificates/37adefc3.0 > signed";
103 unlink 'user.key' or die;
106 run 'openssl smime -verify -out /dev/null -in signed -CAfile ca-bundle.crt';
107 unlink 'signed' or die;
110 unlink 'ca-bundle.crt' or die;
111 unlink 'muttrc' or die;
112 unlink 'keys/.index' or die;
113 unlink 'certificates/.index' or die;
114 unlink <keys/*> or die;
115 unlink <certificates/*> or die;
117 rmdir 'certificates' or die;
119 rmdir $tmpdir or die;
123 my $cmd = shift or die;
126 print "\n\nRunning [$cmd]\n";
128 my $exp = Expect->spawn ($cmd);
129 if (defined $input) {
133 $? and die "$cmd returned $?";