testtsa 4.0 KB
Newer Older
U
Ulf Möller 已提交
1 2 3 4 5 6 7
#!/bin/sh

#
# A few very basic tests for the 'ts' time stamping authority command.
#

SH="/bin/sh"
8 9 10 11 12
if test "$OSTYPE" = msdosdjgpp; then
    PATH="../apps\;$PATH"
else
    PATH="../apps:$PATH"
fi
U
Ulf Möller 已提交
13 14 15 16
export SH PATH

OPENSSL_CONF="../CAtsa.cnf"
export OPENSSL_CONF
R
Rich Salz 已提交
17
# Because that's what ../apps/CA.pl really looks at
18
SSLEAY_CONFIG="-config $OPENSSL_CONF"
19
export SSLEAY_CONFIG
U
Ulf Möller 已提交
20

U
oops  
Ulf Möller 已提交
21
OPENSSL="`pwd`/../util/opensslwrap.sh"
U
Ulf Möller 已提交
22 23
export OPENSSL

R
Rich Salz 已提交
24 25
RUN () {
    ../../util/shlib_wrap.sh ../../apps/openssl ts $*
U
Ulf Möller 已提交
26 27 28 29
}

create_tsa_cert () {
    INDEX=$1
30
    export INDEX
U
Ulf Möller 已提交
31
    EXT=$2
32
    TSDNSECT=ts_cert_dn
R
Rich Salz 已提交
33
    export TSDNSECT
U
Ulf Möller 已提交
34

35
    ../../util/shlib_wrap.sh ../../apps/openssl req -new \
R
Rich Salz 已提交
36 37
	-out tsa_req${INDEX}.pem -keyout tsa_key${INDEX}.pem || exit 1
    echo using extension $EXT
38 39 40
    ../../util/shlib_wrap.sh ../../apps/openssl x509 -req \
	-in tsa_req${INDEX}.pem -out tsa_cert${INDEX}.pem \
	-CA tsaca.pem -CAkey tsacakey.pem -CAcreateserial \
R
Rich Salz 已提交
41
	-extfile $OPENSSL_CONF -extensions $EXT || exit 1
U
Ulf Möller 已提交
42 43 44
}

create_time_stamp_response () {
R
Rich Salz 已提交
45
    RUN -reply -section $3 -queryfile $1 -out $2 || exit 1
U
Ulf Möller 已提交
46 47 48
}

verify_time_stamp_response () {
R
Rich Salz 已提交
49
    RUN -verify -queryfile $1 -in $2 -CAfile tsaca.pem \
R
Rich Salz 已提交
50
	-untrusted tsa_cert1.pem || exit 1
R
Rich Salz 已提交
51
    RUN -verify -data $3 -in $2 -CAfile tsaca.pem \
R
Rich Salz 已提交
52
	-untrusted tsa_cert1.pem || exit 1
U
Ulf Möller 已提交
53 54 55
}

verify_time_stamp_response_fail () {
R
Rich Salz 已提交
56
    RUN -verify -queryfile $1 -in $2 -CAfile tsaca.pem \
R
Rich Salz 已提交
57 58
	-untrusted tsa_cert1.pem && exit 1
    echo ok
U
Ulf Möller 已提交
59 60 61 62
}

# main functions

R
Rich Salz 已提交
63
echo setting up TSA test directory
R
Rich Salz 已提交
64 65 66 67 68 69 70 71 72
rm -rf tsa 2>/dev/null
mkdir tsa
cd ./tsa

echo creating a new CA for the TSA tests
TSDNSECT=ts_ca_dn
export TSDNSECT
../../util/shlib_wrap.sh ../../apps/openssl req -new -x509 -nodes \
	-out tsaca.pem -keyout tsacakey.pem || exit 1
U
Ulf Möller 已提交
73

R
Rich Salz 已提交
74
echo creating tsa_cert1.pem TSA server cert
U
Ulf Möller 已提交
75 76
create_tsa_cert 1 tsa_cert

R
Rich Salz 已提交
77
echo creating tsa_cert2.pem non-TSA server cert
U
Ulf Möller 已提交
78 79
create_tsa_cert 2 non_tsa_cert

R
Rich Salz 已提交
80
echo creating req1.req time stamp request for file testtsa
R
Rich Salz 已提交
81
RUN -query -data ../testtsa -policy tsa_policy1 -cert -out req1.tsq || exit 1
U
Ulf Möller 已提交
82

R
Rich Salz 已提交
83
echo printing req1.req
R
Rich Salz 已提交
84
RUN -query -in req1.tsq -text
U
Ulf Möller 已提交
85

R
Rich Salz 已提交
86
echo generating valid response for req1.req
U
Ulf Möller 已提交
87 88
create_time_stamp_response req1.tsq resp1.tsr tsa_config1

R
Rich Salz 已提交
89
echo printing response
R
Rich Salz 已提交
90
RUN -reply -in resp1.tsr -text || exit 1
U
Ulf Möller 已提交
91

R
Rich Salz 已提交
92
echo verifying valid response
U
Ulf Möller 已提交
93 94
verify_time_stamp_response req1.tsq resp1.tsr ../testtsa

R
Rich Salz 已提交
95
echo verifying valid token
R
Rich Salz 已提交
96 97 98 99 100
RUN -reply -in resp1.tsr -out resp1.tsr.token -token_out || exit 1
RUN -verify -queryfile req1.tsq -in resp1.tsr.token -token_in \
    -CAfile tsaca.pem -untrusted tsa_cert1.pem || exit 1
RUN -verify -data ../testtsa -in resp1.tsr.token -token_in \
    -CAfile tsaca.pem -untrusted tsa_cert1.pem || exit 1
U
Ulf Möller 已提交
101

R
Rich Salz 已提交
102
echo creating req2.req time stamp request for file testtsa
R
Rich Salz 已提交
103 104
RUN -query -data ../testtsa -policy tsa_policy2 -no_nonce \
    -out req2.tsq || exit 1
U
Ulf Möller 已提交
105

R
Rich Salz 已提交
106
echo printing req2.req
R
Rich Salz 已提交
107
RUN -query -in req2.tsq -text
U
Ulf Möller 已提交
108

R
Rich Salz 已提交
109
echo generating valid response for req2.req
U
Ulf Möller 已提交
110 111
create_time_stamp_response req2.tsq resp2.tsr tsa_config1

R
Rich Salz 已提交
112
echo checking -token_in and -token_out options with -reply
R
Rich Salz 已提交
113 114 115 116 117 118 119 120
RESPONSE2=resp2.tsr.copy.tsr
TOKEN_DER=resp2.tsr.token.der
RUN -reply -in resp2.tsr -out $TOKEN_DER -token_out || exit 1
RUN -reply -in $TOKEN_DER -token_in -out $RESPONSE2 || exit 1
cmp $RESPONSE2 resp2.tsr || exit 1
RUN -reply -in resp2.tsr -text -token_out || exit 1
RUN -reply -in $TOKEN_DER -token_in -text -token_out || exit 1
RUN -reply -queryfile req2.tsq -text -token_out || exit 1
U
Ulf Möller 已提交
121

R
Rich Salz 已提交
122
echo printing response
R
Rich Salz 已提交
123
RUN -reply -in resp2.tsr -text || exit 1
U
Ulf Möller 已提交
124

R
Rich Salz 已提交
125
echo verifying valid response
U
Ulf Möller 已提交
126 127
verify_time_stamp_response req2.tsq resp2.tsr ../testtsa

R
Rich Salz 已提交
128
echo verifying response against wrong request, it should fail
U
Ulf Möller 已提交
129 130
verify_time_stamp_response_fail req1.tsq resp2.tsr

R
Rich Salz 已提交
131
echo verifying response against wrong request, it should fail
U
Ulf Möller 已提交
132 133
verify_time_stamp_response_fail req2.tsq resp1.tsr

R
Rich Salz 已提交
134
echo creating req3.req time stamp request for file CAtsa.cnf
R
Rich Salz 已提交
135
RUN -query -data ../CAtsa.cnf -no_nonce -out req3.tsq || exit 1
U
Ulf Möller 已提交
136

R
Rich Salz 已提交
137
echo printing req3.req
R
Rich Salz 已提交
138
RUN -query -in req3.tsq -text
U
Ulf Möller 已提交
139

R
Rich Salz 已提交
140
echo verifying response against wrong request, it should fail
U
Ulf Möller 已提交
141 142
verify_time_stamp_response_fail req3.tsq resp1.tsr

R
Rich Salz 已提交
143
echo cleaning up
R
Rich Salz 已提交
144 145
cd ..
rm -rf tsa
U
Ulf Möller 已提交
146 147

exit 0