Note about contribtions from the US
[openssl.git] / test / testss
1 #!/bin/sh
2
3 digest='-md5'
4 reqcmd="../apps/openssl req"
5 x509cmd="../apps/openssl x509 $digest"
6 verifycmd="../apps/openssl verify"
7 dummycnf="../apps/openssl.cnf"
8
9 CAkey="keyCA.ss"
10 CAcert="certCA.ss"
11 CAreq="reqCA.ss"
12 CAconf="CAss.cnf"
13 CAreq2="req2CA.ss"      # temp
14
15 Uconf="Uss.cnf"
16 Ukey="keyU.ss"
17 Ureq="reqU.ss"
18 Ucert="certU.ss"
19
20 echo
21 echo "make a certificate request using 'req'"
22
23 if ../apps/openssl no-rsa; then
24   req_new='-newkey dsa:../apps/dsa512.pem'
25 else
26   req_new='-new'
27 fi
28
29 $reqcmd -config $CAconf -out $CAreq -keyout $CAkey $req_new #>err.ss
30 if [ $? != 0 ]; then
31         echo "error using 'req' to generate a certificate request"
32         exit 1
33 fi
34 echo
35 echo "convert the certificate request into a self signed certificate using 'x509'"
36 $x509cmd -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey >err.ss
37 if [ $? != 0 ]; then
38         echo "error using 'x509' to self sign a certificate request"
39         exit 1
40 fi
41
42 echo
43 echo "convert a certificate into a certificate request using 'x509'"
44 $x509cmd -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >err.ss
45 if [ $? != 0 ]; then
46         echo "error using 'x509' convert a certificate to a certificate request"
47         exit 1
48 fi
49
50 $reqcmd -config $dummycnf -verify -in $CAreq -noout
51 if [ $? != 0 ]; then
52         echo first generated request is invalid
53         exit 1
54 fi
55
56 $reqcmd -config $dummycnf -verify -in $CAreq2 -noout
57 if [ $? != 0 ]; then
58         echo second generated request is invalid
59         exit 1
60 fi
61
62 $verifycmd -CAfile $CAcert $CAcert
63 if [ $? != 0 ]; then
64         echo first generated cert is invalid
65         exit 1
66 fi
67
68 echo
69 echo "make another certificate request using 'req'"
70 $reqcmd -config $Uconf -out $Ureq -keyout $Ukey $req_new >err.ss
71 if [ $? != 0 ]; then
72         echo "error using 'req' to generate a certificate request"
73         exit 1
74 fi
75
76 echo
77 echo "sign certificate request with the just created CA via 'x509'"
78 $x509cmd -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey >err.ss
79 if [ $? != 0 ]; then
80         echo "error using 'x509' to sign a certificate request"
81         exit 1
82 fi
83
84 $verifycmd -CAfile $CAcert $Ucert
85 echo
86 echo "Certificate details"
87 $x509cmd -subject -issuer -startdate -enddate -noout -in $Ucert
88
89 echo
90 echo The generated CA certificate is $CAcert
91 echo The generated CA private key is $CAkey
92
93 echo The generated user certificate is $Ucert
94 echo The generated user private key is $Ukey
95
96 /bin/rm err.ss
97 exit 0