From 1af321be7771cf05e347dcdf609043ba68f18f5d Mon Sep 17 00:00:00 2001 From: olszomal Date: Fri, 6 Dec 2019 12:11:06 +0100 Subject: [PATCH] make certs with faketime --- tests/certs/makecerts.sh | 69 ++++++++++++++++++++++++++----------- tests/certs/openssltest.cnf | 2 ++ 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/tests/certs/makecerts.sh b/tests/certs/makecerts.sh index 1c5f57f..38247c8 100755 --- a/tests/certs/makecerts.sh +++ b/tests/certs/makecerts.sh @@ -9,7 +9,6 @@ if [ "$1" == 0 ] fi } -ddays=1461 password=passme result_path=$(pwd) @@ -37,26 +36,38 @@ $OPENSSL version 2>> "makecerts.log" 1>&2 echo -n "$password" > "password.txt" printf "\nGenerate root CA certificate\n" >> "makecerts.log" -$OPENSSL genrsa -out demoCA/CA.key 1>&2 2>> "makecerts.log" -$OPENSSL req -config $CONF -new -x509 -days $ddays -key demoCA/CA.key -out tmp/CACert.pem \ - -subj "/C=PL/O=osslsigncode/OU=Root CA/CN=CA/emailAddress=CA@example.com" \ +$OPENSSL genrsa -out demoCA/CA.key \ 2>> "makecerts.log" 1>&2 +TZ=GMT faketime -f '@2017-01-01 00:00:00' /bin/bash -c ' + script_path=$(pwd) + OPENSSL=openssl + CONF="${script_path}/openssltest.cnf" + $OPENSSL req -config $CONF -new -x509 -days 1800 -key demoCA/CA.key -out tmp/CACert.pem \ + -subj "/C=PL/O=osslsigncode/OU=Root CA/CN=CA/emailAddress=CA@example.com" \ + 2>> "makecerts.log" 1>&2' test_result $? printf "\nGenerate CSP Cross-Certificate\n" >> "makecerts.log" -$OPENSSL genrsa -out demoCA/cross.key 1>&2 2>> "makecerts.log" -$OPENSSL req -config $CONF -new -x509 -days $ddays -key demoCA/cross.key -out tmp/crosscert.pem \ - -subj "/C=PL/O=osslsigncode/OU=CSP/CN=crosscert/emailAddress=CA@example.com" \ +$OPENSSL genrsa -out demoCA/cross.key \ 2>> "makecerts.log" 1>&2 +TZ=GMT faketime -f '@2018-01-01 00:00:00' /bin/bash -c ' + script_path=$(pwd) + OPENSSL=openssl + CONF="${script_path}/openssltest.cnf" +$OPENSSL req -config $CONF -new -x509 -days 900 -key demoCA/cross.key -out tmp/crosscert.pem \ + -subj "/C=PL/O=osslsigncode/OU=CSP/CN=crosscert/emailAddress=CA@example.com" \ + 2>> "makecerts.log" 1>&2' test_result $? printf "\nGenerate private RSA encrypted key\n" >> "makecerts.log" -$OPENSSL genrsa -des3 -out demoCA/private.key -passout pass:$password 1>&2 2>> "makecerts.log" +$OPENSSL genrsa -des3 -out demoCA/private.key -passout pass:$password \ + 2>> "makecerts.log" 1>&2 test_result $? cat demoCA/private.key >> tmp/keyp.pem 2>> "makecerts.log" printf "\nGenerate private RSA decrypted key\n" >> "makecerts.log" -$OPENSSL rsa -in demoCA/private.key -passin pass:$password -out tmp/key.pem 1>&2 2>> "makecerts.log" +$OPENSSL rsa -in demoCA/private.key -passin pass:$password -out tmp/key.pem \ + 2>> "makecerts.log" 1>&2 test_result $? printf "\nGenerate code signing certificate\n" >> "makecerts.log" @@ -64,29 +75,47 @@ $OPENSSL req -config $CONF -new -key demoCA/private.key -passin pass:$password - -subj "/C=PL/ST=Mazovia Province/L=Warsaw/O=osslsigncode/OU=CA/CN=localhost/emailAddress=osslsigncode@example.com" \ 2>> "makecerts.log" 1>&2 test_result $? -$OPENSSL ca -config $CONF -batch -days $ddays -in demoCA/cert.csr -out demoCA/cert.cer 1>&2 2>> "makecerts.log" +$OPENSSL ca -config $CONF -batch -in demoCA/cert.csr -out demoCA/cert.cer \ + 2>> "makecerts.log" 1>&2 test_result $? -$OPENSSL x509 -in demoCA/cert.cer -out tmp/cert.pem 1>&2 2>> "makecerts.log" +$OPENSSL x509 -in demoCA/cert.cer -out tmp/cert.pem \ + 2>> "makecerts.log" 1>&2 test_result $? -printf "\nConverting the key to DER format\n" >> "makecerts.log" -$OPENSSL rsa -in tmp/key.pem -outform DER -out tmp/key.der -passout pass:$password 2>> "makecerts.log" 1>&2 +printf "\nConvert the key to DER format\n" >> "makecerts.log" +$OPENSSL rsa -in tmp/key.pem -outform DER -out tmp/key.der -passout pass:$password \ + 2>> "makecerts.log" 1>&2 test_result $? -printf "\nConverting the certificate to DER format\n" >> "makecerts.log" -$OPENSSL x509 -in tmp/cert.pem -outform DER -out tmp/cert.der +printf "\nConvert the certificate to DER format\n" >> "makecerts.log" +$OPENSSL x509 -in tmp/cert.pem -outform DER -out tmp/cert.der \ + 2>> "makecerts.log" 1>&2 test_result $? -printf "\nConverting the certificate to SPC format\n" >> "makecerts.log" -$OPENSSL crl2pkcs7 -nocrl -certfile tmp/cert.pem -outform DER -out tmp/cert.spc 2>> "makecerts.log" 1>&2 +printf "\nConvert the certificate to SPC format\n" >> "makecerts.log" +$OPENSSL crl2pkcs7 -nocrl -certfile tmp/cert.pem -outform DER -out tmp/cert.spc \ + 2>> "makecerts.log" 1>&2 test_result $? -printf "\nConverting the certificate and the key into a PKCS#12 container\n" >> "makecerts.log" -$OPENSSL pkcs12 -export -in tmp/cert.pem -inkey tmp/key.pem -out tmp/cert.p12 -passout pass:$password 2>> "makecerts.log" 1>&2 +printf "\nConvert the certificate and the key into a PKCS#12 container\n" >> "makecerts.log" +$OPENSSL pkcs12 -export -in tmp/cert.pem -inkey tmp/key.pem -out tmp/cert.p12 -passout pass:$password \ + 2>> "makecerts.log" 1>&2 +test_result $? + +printf "\nGenerate expired certificate\n" >> "makecerts.log" +$OPENSSL req -config $CONF -new -key demoCA/private.key -passin pass:$password -out demoCA/expired.csr \ + -subj "/C=PL/ST=Mazovia Province/L=Warsaw/O=osslsigncode/OU=CA/CN=expired/emailAddress=expired@example.com" \ + 2>> "makecerts.log" 1>&2 +test_result $? +$OPENSSL ca -config $CONF -enddate "190101000000Z" -batch -in demoCA/expired.csr -out demoCA/expired.cer \ + 2>> "makecerts.log" 1>&2 +test_result $? +$OPENSSL x509 -in demoCA/expired.cer -out tmp/expired.pem \ + 2>> "makecerts.log" 1>&2 test_result $? # copy new files -if [ -s tmp/CACert.pem ] && [ -s tmp/crosscert.pem ] && [ -s tmp/cert.pem ] && \ +if [ -s tmp/CACert.pem ] && [ -s tmp/crosscert.pem ] && [ -s tmp/expired.pem ] && [ -s tmp/cert.pem ] && \ [ -s tmp/key.pem ] && [ -s tmp/keyp.pem ] && [ -s tmp/key.der ] && \ [ -s tmp/cert.der ] && [ -s tmp/cert.spc ] && [ -s tmp/cert.p12 ] then diff --git a/tests/certs/openssltest.cnf b/tests/certs/openssltest.cnf index dd97517..6521df0 100644 --- a/tests/certs/openssltest.cnf +++ b/tests/certs/openssltest.cnf @@ -18,6 +18,8 @@ policy = policy_match x509_extensions = usr_cert private_key = $dir/demoCA/CA.key certificate = $dir/tmp/CACert.pem +default_startdate = 180101000000Z +default_enddate = 280101000000Z [ req ] encrypt_key = no