changed to unmaintained
[aaf/authz.git] / conf / CA / newIntermediate.sh
1 #!/bin/bash
2 #########
3 #  ============LICENSE_START====================================================
4 #  org.onap.aaf
5 #  ===========================================================================
6 #  Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
7 #  ===========================================================================
8 #  Licensed under the Apache License, Version 2.0 (the "License");
9 #  you may not use this file except in compliance with the License.
10 #  You may obtain a copy of the License at
11 #
12 #       http://www.apache.org/licenses/LICENSE-2.0
13 #
14 #  Unless required by applicable law or agreed to in writing, software
15 #  distributed under the License is distributed on an "AS IS" BASIS,
16 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 #  See the License for the specific language governing permissions and
18 #  limitations under the License.
19 #  ============LICENSE_END====================================================
20 #
21 #
22 # Initialize an Intermediate CA Cert.  
23 #
24   if [ -e intermediate.serial ]; then
25     ((SERIAL=`cat intermediate.serial` + 1))
26   else
27     SERIAL=$(date +%s)
28   fi
29   echo $SERIAL > intermediate.serial
30 DIR=intermediate_$SERIAL
31
32 mkdir -p $DIR/private $DIR/certs $DIR/newcerts
33 chmod 700 $DIR/private
34 chmod 755 $DIR/certs $DIR/newcerts
35 touch $DIR/index.txt
36 echo "unique_subject = no" > $DIR/index.txt.attr
37
38 if [ ! -e $DIR/serial ]; then
39   echo '01' > $DIR/serial
40 fi
41 cp manual.sh p12.sh subject.aaf cfg.pkcs11 p11.sh $DIR
42
43 if [  "$1" == "" ]; then
44   CN=intermediateCA_$SERIAL
45 else
46   CN=$1
47 fi
48
49 SUBJECT="/CN=$CN`cat subject.aaf`"
50 echo $SUBJECT
51   echo "IMPORTANT: If for any reason, you kill this process, type 'stty sane'"
52   echo "Enter the PassPhrase for the Key for $CN: "
53   `stty -echo`
54   read PASSPHRASE
55   `stty echo`
56  
57   # Create a regaular rsa encrypted key
58   openssl req -new -newkey rsa:2048 -sha256 -keyout $DIR/private/ca.key \
59            -out $DIR/$CN.csr -outform PEM -subj "$SUBJECT" \
60            -passout stdin  << EOF
61 $PASSPHRASE
62 EOF
63
64   chmod 400 $DIR/private/ca.key
65   openssl req -verify -text -noout -in $DIR/$CN.csr
66
67   # Sign it
68   openssl ca -config openssl.conf -extensions v3_intermediate_ca \
69         -days 1826 \
70   -cert certs/ca.crt -keyfile private/ca.key -out $DIR/certs/ca.crt \
71         -infiles $DIR/$CN.csr
72
73    openssl x509 -text -noout -in $DIR/certs/ca.crt
74
75    openssl verify -CAfile certs/ca.crt $DIR/certs/ca.crt
76
77
78 # Create a Signer p12 script
79 echo openssl pkcs12 -export -name aaf_$DIR \
80                -in certs/ca.crt -inkey private/ca.key \
81                -out aaf_$DIR.p12 >> $DIR/signerP12.sh
82