Set Enveloped data version to 2 if ktri version not zero.
[openssl.git] / test / testtsa
index b135438b7d9d559fea935fa8621242a9ccc3d20c..bb653b5f73d6f5761ab564e02ddc035bd4cecb01 100644 (file)
@@ -5,15 +5,25 @@
 #
 
 SH="/bin/sh"
-PATH=../../apps:$PATH
+if test "$OSTYPE" = msdosdjgpp; then
+    PATH="../apps\;$PATH"
+else
+    PATH="../apps:$PATH"
+fi
 export SH PATH
 
 OPENSSL_CONF="../CAtsa.cnf"
 export OPENSSL_CONF
+# Because that's what ../apps/CA.sh really looks at
+SSLEAY_CONFIG="-config $OPENSSL_CONF"
+export SSLEAY_CONFIG
+
+OPENSSL="`pwd`/../util/opensslwrap.sh"
+export OPENSSL
 
 error () {
 
-    echo "ERROR DURING TSA TESTS!!!!!!!!!!!!!!!!" >&2
+    echo "TSA test failed!" >&2
     exit 1
 }
 
@@ -33,72 +43,65 @@ clean_up_dir () {
 create_ca () {
 
     echo "Creating a new CA for the TSA tests..."
-    /bin/rm -fr demoCA
-    $SH ../../apps/CA.sh -newca <<EOF
-
-HU
-Budapest
-Budapest
-Gov-CA Ltd.
-ca1
-EOF
+    TSDNSECT=ts_ca_dn
+    export TSDNSECT   
+    ../../util/shlib_wrap.sh ../../apps/openssl req -new -x509 -nodes \
+       -out tsaca.pem -keyout tsacakey.pem
     test $? != 0 && error
 }
 
 create_tsa_cert () {
 
     INDEX=$1
+    export INDEX
     EXT=$2
-    openssl req -new -out tsa_req${INDEX}.pem -keyout tsa_key${INDEX}.pem <<EOF
-HU
-Budapest
-Buda
-Hun-TSA Ltd.
-tsa${INDEX}
-EOF
-    test $? != 0 && error
+    TSDNSECT=ts_cert_dn
+    export TSDNSECT   
 
-    openssl ca -in tsa_req${INDEX}.pem -out tsa_cert${INDEX}.pem \
-       -extensions $EXT <<EOF
-y
-y
-EOF
+    ../../util/shlib_wrap.sh ../../apps/openssl req -new \
+       -out tsa_req${INDEX}.pem -keyout tsa_key${INDEX}.pem
+    test $? != 0 && error
+echo Using extension $EXT
+    ../../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 \
+       -extfile $OPENSSL_CONF -extensions $EXT
     test $? != 0 && error
 }
 
 print_request () {
 
-    openssl ts -query -in $1 -text
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -query -in $1 -text
 }
 
 create_time_stamp_request1 () {
 
-    openssl ts -query -data ../testtsa -policy tsa_policy1 -cert -out req1.tsq
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -query -data ../testtsa -policy tsa_policy1 -cert -out req1.tsq
     test $? != 0 && error
 }
 
 create_time_stamp_request2 () {
 
-    openssl ts -query -data ../testtsa -policy tsa_policy2 -no_nonce \
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -query -data ../testtsa -policy tsa_policy2 -no_nonce \
        -out req2.tsq
     test $? != 0 && error
 }
 
 create_time_stamp_request3 () {
 
-    openssl ts -query -data ../CAtsa.cnf -no_nonce -out req3.tsq
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -query -data ../CAtsa.cnf -no_nonce -out req3.tsq
     test $? != 0 && error
 }
 
 print_response () {
 
-    openssl ts -reply -in $1 -text
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $1 -text
     test $? != 0 && error
 }
 
 create_time_stamp_response () {
 
-    openssl ts -reply -section $3 -queryfile $1 -out $2
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -section $3 -queryfile $1 -out $2
     test $? != 0 && error
 }
 
@@ -106,26 +109,26 @@ time_stamp_response_token_test () {
 
     RESPONSE2=$2.copy.tsr
     TOKEN_DER=$2.token.der
-    openssl ts -reply -in $2 -out $TOKEN_DER -token_out
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $2 -out $TOKEN_DER -token_out
     test $? != 0 && error
-    openssl ts -reply -in $TOKEN_DER -token_in -out $RESPONSE2
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $TOKEN_DER -token_in -out $RESPONSE2
     test $? != 0 && error
     cmp $RESPONSE2 $2
     test $? != 0 && error
-    openssl ts -reply -in $2 -text -token_out
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $2 -text -token_out
     test $? != 0 && error
-    openssl ts -reply -in $TOKEN_DER -token_in -text -token_out
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $TOKEN_DER -token_in -text -token_out
     test $? != 0 && error
-    openssl ts -reply -queryfile $1 -text -token_out
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -queryfile $1 -text -token_out
     test $? != 0 && error
 }
 
 verify_time_stamp_response () {
 
-    openssl ts -verify -queryfile $1 -in $2 -CAfile demoCA/cacert.pem \
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -queryfile $1 -in $2 -CAfile tsaca.pem \
        -untrusted tsa_cert1.pem
     test $? != 0 && error
-    openssl ts -verify -data $3 -in $2 -CAfile demoCA/cacert.pem \
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -data $3 -in $2 -CAfile tsaca.pem \
        -untrusted tsa_cert1.pem
     test $? != 0 && error
 }
@@ -133,22 +136,23 @@ verify_time_stamp_response () {
 verify_time_stamp_token () {
 
     # create the token from the response first
-    openssl ts -reply -in $2 -out $2.token -token_out
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $2 -out $2.token -token_out
     test $? != 0 && error
-    openssl ts -verify -queryfile $1 -in $2.token -token_in \
-       -CAfile demoCA/cacert.pem -untrusted tsa_cert1.pem
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -queryfile $1 -in $2.token -token_in \
+       -CAfile tsaca.pem -untrusted tsa_cert1.pem
     test $? != 0 && error
-    openssl ts -verify -data $3 -in $2.token -token_in \
-       -CAfile demoCA/cacert.pem -untrusted tsa_cert1.pem
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -data $3 -in $2.token -token_in \
+       -CAfile tsaca.pem -untrusted tsa_cert1.pem
     test $? != 0 && error
 }
 
 verify_time_stamp_response_fail () {
 
-    openssl ts -verify -queryfile $1 -in $2 -CAfile demoCA/cacert.pem \
+    ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -queryfile $1 -in $2 -CAfile tsaca.pem \
        -untrusted tsa_cert1.pem
     # Checks if the verification failed, as it should have.
-    test $? == 0 && error
+    test $? = 0 && error
+    echo Ok
 }
 
 # main functions