c846b772514d705639c217db28d92d6f683510f6
[openssl.git] / test / testss
1 #!/bin/sh
2
3 digest='-sha1'
4 reqcmd="../util/shlib_wrap.sh ../apps/openssl req"
5 x509cmd="../util/shlib_wrap.sh ../apps/openssl x509 $digest"
6 verifycmd="../util/shlib_wrap.sh ../apps/openssl verify"
7 dummycnf="../apps/openssl.cnf"
8 OPENSSL_CONF=/dev/null ; export OPENSSL_CONF
9
10 CAkey="keyCA.ss"
11 CAcert="certCA.ss"
12 CAreq="reqCA.ss"
13 CAconf="CAss.cnf"
14 CAreq2="req2CA.ss"      # temp
15
16 Uconf="Uss.cnf"
17 Ukey="keyU.ss"
18 Ureq="reqU.ss"
19 Ucert="certU.ss"
20
21 P1conf="P1ss.cnf"
22 P1key="keyP1.ss"
23 P1req="reqP1.ss"
24 P1cert="certP1.ss"
25 P1intermediate="tmp_intP1.ss"
26
27 P2conf="P2ss.cnf"
28 P2key="keyP2.ss"
29 P2req="reqP2.ss"
30 P2cert="certP2.ss"
31 P2intermediate="tmp_intP2.ss"
32
33 echo
34 echo "make a certificate request using 'req'"
35
36 echo "string to make the random number generator think it has entropy" >> ./.rnd
37
38 if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
39   req_new='-newkey dsa:../apps/dsa512.pem'
40 else
41   req_new='-new'
42 fi
43
44 $reqcmd -config $CAconf -out $CAreq -keyout $CAkey $req_new
45 if [ $? != 0 ]; then
46         echo "error using 'req' to generate a certificate request"
47         exit 1
48 fi
49 echo
50 echo "convert the certificate request into a self signed certificate using 'x509'"
51 $x509cmd -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey -extfile $CAconf -extensions v3_ca >err.ss
52 if [ $? != 0 ]; then
53         echo "error using 'x509' to self sign a certificate request"
54         exit 1
55 fi
56
57 echo
58 echo "convert a certificate into a certificate request using 'x509'"
59 $x509cmd -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >err.ss
60 if [ $? != 0 ]; then
61         echo "error using 'x509' convert a certificate to a certificate request"
62         exit 1
63 fi
64
65 $reqcmd -config $dummycnf -verify -in $CAreq -noout
66 if [ $? != 0 ]; then
67         echo first generated request is invalid
68         exit 1
69 fi
70
71 $reqcmd -config $dummycnf -verify -in $CAreq2 -noout
72 if [ $? != 0 ]; then
73         echo second generated request is invalid
74         exit 1
75 fi
76
77 $verifycmd -CAfile $CAcert $CAcert
78 if [ $? != 0 ]; then
79         echo first generated cert is invalid
80         exit 1
81 fi
82
83 echo
84 echo "make a user certificate request using 'req'"
85 $reqcmd -config $Uconf -out $Ureq -keyout $Ukey $req_new >err.ss
86 if [ $? != 0 ]; then
87         echo "error using 'req' to generate a user certificate request"
88         exit 1
89 fi
90
91 echo
92 echo "sign user certificate request with the just created CA via 'x509'"
93 $x509cmd -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey -extfile $Uconf -extensions v3_ee >err.ss
94 if [ $? != 0 ]; then
95         echo "error using 'x509' to sign a user certificate request"
96         exit 1
97 fi
98
99 $verifycmd -CAfile $CAcert $Ucert
100 echo
101 echo "Certificate details"
102 $x509cmd -subject -issuer -startdate -enddate -noout -in $Ucert
103
104 echo
105 echo "make a proxy certificate request using 'req'"
106 $reqcmd -config $P1conf -out $P1req -keyout $P1key $req_new >err.ss
107 if [ $? != 0 ]; then
108         echo "error using 'req' to generate a proxy certificate request"
109         exit 1
110 fi
111
112 echo
113 echo "sign proxy certificate request with the just created user certificate via 'x509'"
114 $x509cmd -CAcreateserial -in $P1req -days 30 -req -out $P1cert -CA $Ucert -CAkey $Ukey -extfile $P1conf -extensions v3_proxy >err.ss
115 if [ $? != 0 ]; then
116         echo "error using 'x509' to sign a proxy certificate request"
117         exit 1
118 fi
119
120 cat $Ucert > $P1intermediate
121 $verifycmd -CAfile $CAcert -untrusted $P1intermediate $P1cert
122 echo
123 echo "Certificate details"
124 $x509cmd -subject -issuer -startdate -enddate -noout -in $P1cert
125
126 echo
127 echo "make another proxy certificate request using 'req'"
128 $reqcmd -config $P2conf -out $P2req -keyout $P2key $req_new >err.ss
129 if [ $? != 0 ]; then
130         echo "error using 'req' to generate another proxy certificate request"
131         exit 1
132 fi
133
134 echo
135 echo "sign second proxy certificate request with the first proxy certificate via 'x509'"
136 $x509cmd -CAcreateserial -in $P2req -days 30 -req -out $P2cert -CA $P1cert -CAkey $P1key -extfile $P2conf -extensions v3_proxy >err.ss
137 if [ $? != 0 ]; then
138         echo "error using 'x509' to sign a second proxy certificate request"
139         exit 1
140 fi
141
142 cat $Ucert $P1cert > $P2intermediate
143 $verifycmd -CAfile $CAcert -untrusted $P2intermediate $P2cert
144 echo
145 echo "Certificate details"
146 $x509cmd -subject -issuer -startdate -enddate -noout -in $P2cert
147
148 echo
149 echo The generated CA certificate is $CAcert
150 echo The generated CA private key is $CAkey
151
152 echo The generated user certificate is $Ucert
153 echo The generated user private key is $Ukey
154
155 echo The first generated proxy certificate is $P1cert
156 echo The first generated proxy private key is $P1key
157
158 echo The second generated proxy certificate is $P2cert
159 echo The second generated proxy private key is $P2key
160
161 /bin/rm err.ss
162 exit 0