Instrumental | df9e827 | 2018-04-05 20:52:32 -0500 | [diff] [blame] | 1 | # |
| 2 | # Initialize an Intermediate CA Cert. |
| 3 | # |
| 4 | if [ -e intermediate.serial ]; then |
| 5 | ((SERIAL=`cat intermediate.serial` + 1)) |
| 6 | else |
Instrumental | c3ca46e | 2018-09-25 08:25:52 -0500 | [diff] [blame] | 7 | SERIAL=$(date +%s) |
Instrumental | df9e827 | 2018-04-05 20:52:32 -0500 | [diff] [blame] | 8 | fi |
| 9 | echo $SERIAL > intermediate.serial |
| 10 | DIR=intermediate_$SERIAL |
| 11 | |
| 12 | mkdir -p $DIR/private $DIR/certs $DIR/newcerts |
| 13 | chmod 700 $DIR/private |
| 14 | chmod 755 $DIR/certs $DIR/newcerts |
| 15 | touch $DIR/index.txt |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 16 | echo "unique_subject = no" > $DIR/index.txt.attr |
| 17 | |
Instrumental | df9e827 | 2018-04-05 20:52:32 -0500 | [diff] [blame] | 18 | if [ ! -e $DIR/serial ]; then |
| 19 | echo '01' > $DIR/serial |
| 20 | fi |
| 21 | cp manual.sh p12.sh subject.aaf cfg.pkcs11 p11.sh $DIR |
| 22 | |
| 23 | if [ "$1" == "" ]; then |
| 24 | CN=intermediateCA_$SERIAL |
| 25 | else |
| 26 | CN=$1 |
| 27 | fi |
| 28 | |
| 29 | SUBJECT="/CN=$CN`cat subject.aaf`" |
| 30 | echo $SUBJECT |
| 31 | echo "IMPORTANT: If for any reason, you kill this process, type 'stty sane'" |
| 32 | echo "Enter the PassPhrase for the Key for $CN: " |
| 33 | `stty -echo` |
| 34 | read PASSPHRASE |
| 35 | `stty echo` |
| 36 | |
| 37 | # Create a regaular rsa encrypted key |
| 38 | openssl req -new -newkey rsa:2048 -sha256 -keyout $DIR/private/ca.key \ |
| 39 | -out $DIR/$CN.csr -outform PEM -subj "$SUBJECT" \ |
| 40 | -passout stdin << EOF |
| 41 | $PASSPHRASE |
| 42 | EOF |
| 43 | |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 44 | chmod 400 $DIR/private/ca.key |
Instrumental | df9e827 | 2018-04-05 20:52:32 -0500 | [diff] [blame] | 45 | openssl req -verify -text -noout -in $DIR/$CN.csr |
| 46 | |
| 47 | # Sign it |
| 48 | openssl ca -config openssl.conf -extensions v3_intermediate_ca \ |
Instrumental | 8601af6 | 2018-06-05 04:03:49 -0500 | [diff] [blame] | 49 | -days 1826 \ |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 50 | -cert certs/ca.crt -keyfile private/ca.key -out $DIR/certs/ca.crt \ |
Instrumental | df9e827 | 2018-04-05 20:52:32 -0500 | [diff] [blame] | 51 | -infiles $DIR/$CN.csr |
| 52 | |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 53 | openssl x509 -text -noout -in $DIR/certs/ca.crt |
Instrumental | df9e827 | 2018-04-05 20:52:32 -0500 | [diff] [blame] | 54 | |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 55 | openssl verify -CAfile certs/ca.crt $DIR/certs/ca.crt |
Instrumental | df9e827 | 2018-04-05 20:52:32 -0500 | [diff] [blame] | 56 | |
| 57 | |
| 58 | # Create a Signer p12 script |
| 59 | echo openssl pkcs12 -export -name aaf_$DIR \ |
| 60 | -in certs/ca.crt -inkey private/ca.key \ |
| 61 | -out aaf_$DIR.p12 >> $DIR/signerP12.sh |
| 62 | |