#!/bin/sh # # # Copyright (C) 2007 Paul Wouters # Copyright (C) 2012 Paul Wouters # # Setup a variety of X509 certificates for testcases OUTDIR=`dirname $0` pushd $OUTDIR TOUCH=`which touch` EXPECT=`which expect` if [ -z $TOUCH ] then echo "touch needed for dist_certs, not found in path" exit 1 fi if [ -z $EXPECT ] then echo "expect needed for dist_certs, not found in path" exit 1 fi # Clean rm -f reqs/* certs/* keys/* newcerts/* cacerts/* crls/* pkcs12/mainca/* pkcs12/otherca/* pkcs12/curveca/* index.txt* serial* nss-pw crlnumber echo -n "foobar" > nss-pw # Prep mkdir -p certs crls newcerts keys reqs pkcs12/mainca pkcs12/otherca pkcs12/curveca cacerts $TOUCH index.txt echo "01" > serial echo "01" > crlnumber export OPENSSL_CONF=./openssl.cnf # Get some useful dates. Blame openssl for not being Y2K compatible with its -startdate YEAR=`date +%y` MONTH=`date +%m` MONTHMINONE=$MONTH DAY=`date +%d` DAYMINONE=`expr $DAY - 2` if [ $DAYMINONE -lt 10 ] then DAYMINONE="0$DAYMINONE" if [ $DAYMINONE = "00" ] then # we dont care about 30 vs 31 or 28 DAYMINONE="28" MONTHMINONE=`expr $MONTH - 1` if [ $MONTHMINONE -lt 10 ] then MONTHMINONE="0$MONTHMINONE" if [ $MONTHMINONE = "00" ] then MONTHMINONE="12" # 2001 is fine - why check the tests on New Year anyway? YEAR="01" fi fi fi fi TODAY="$YEAR$MONTH$DAY" TWODAYSAGO="$YEAR$MONTHMINONE$DAYMINONE" START="$TWODAYSAGO"000000Z END="$TWODAYSAGO"235959Z # future < 10*365 (length of CA validity) FUTURE="$[ $YEAR + 1]$MONTH$DAY"000000Z FUTUREEND="$[ $YEAR + 2]$MONTH$DAY"000000Z echo "------------------------------------------" echo "Certificate dates being used for this run:" echo "" echo "Today: $TODAY" echo "Two days ago: $TWODAYSAGO" echo "Start: $START" echo "End: $END" echo "Future: $FUTURE" echo "Year: $YEAR" echo "Month: $MONTH" echo "Day: $DAY" echo "Month-1: $MONTHMINONE" echo "Day-1: $DAYMINONE" echo "------------------------------------------" echo "" # Generate CA's for cauth in mainca otherca do openssl genrsa -passout pass:foobar -des3 -out keys/$cauth.key 1024 openssl rsa -in keys/$cauth.key -out keys/$cauth.key -passin pass:foobar # use defaults to ensure the same values for all certs based on openssl.cnf # req -x509 does not accept -startdate, this might invalidate certs? $EXPECT <.testing.libreswan.org\n" expect "Email" send "testing@libreswan.org\n" expect "challenge" send "\n" expect "optional" send "\n" wait EOF openssl ca -batch -in reqs/unwisechar.req -startdate $START -days 365 -out certs/unwisechar.crt -notext -cert cacerts/mainca.crt -keyfile keys/mainca.key -passin pass:foobar openssl pkcs12 -export -inkey keys/unwisechar.key -in certs/unwisechar.crt -name "unwisechar" -certfile cacerts/mainca.crt -caname "mainca" -out pkcs12/mainca/unwisechar.p12 -passin pass:foobar -passout pass:foobar # Using SHA2 $EXPECT </dev/null openssl crl -text -in crls/crl-leading-zero-byte.pem -noout | grep -A1 "Signature Algorithm:"|tail -1| sed "s/ //g" |grep ^00 > /dev/null RETVAL=$? if [ $RETVAL -eq 0 ] then echo "Found leading zero CRL signature for days=$days" break else days=$((days+1)) fi; done echo "X509 test material generation complete" popd