AT&T 2.0.19 Code drop, stage 6
[aaf/authz.git] / conf / CA / newca.sh
1 #
2 # NOTE: This README is "bash" capable.  bash README.txt
3 #
4 # create simple but reasonable directory structure
5 mkdir -p private certs newcerts 
6 chmod 700 private
7 chmod 755 certs newcerts
8 touch index.txt
9 if [ ! -e serial ]; then
10   echo '01' > serial
11 fi
12
13 if [  "$1" == "" ]; then
14   CN=$1
15 else
16   CN=RootCA
17 fi
18
19 echo "IMPORTANT: If for any reason, you kill this process, type 'stty sane'"
20 echo "Enter the PassPhrase for your Key: "
21 `stty -echo`
22 read PASSPHRASE
23 `stty echo`
24
25 if [ ! -e /private/ca.ekey ]; then
26   # Create a regaular rsa encrypted key
27   openssl genrsa -aes256 -out private/ca.ekey -passout stdin 4096 << EOF
28 $PASSPHRASE
29 EOF
30 fi
31
32 if [ ! -e /private/ca.key ]; then
33   # Move to a Java/Filesystem readable key. Note that this one is NOT Encrypted.
34   openssl pkcs8 -in private/ca.ekey -topk8 -nocrypt -out private/ca.key -passin stdin << EOF
35 $PASSPHRASE
36 EOF
37 fi
38 chmod 400 private/ca.key private/ca.ekey
39
40
41 if [ -e subject.aaf ]; then
42   SUBJECT="-subj /CN=$CN`cat subject.aaf`"
43 else
44   SUBJECT=""
45 fi
46
47 # Generate a CA Certificate
48 openssl req -config openssl.conf \
49       -key private/ca.key \
50       -new -x509 -days 7300 -sha256 -extensions v3_ca \
51       $SUBJECT \
52       -out certs/ca.crt 
53
54 if [ -e certs/ca.crt ]; then
55   # All done, print result
56   openssl x509 -text -noout -in certs/ca.crt
57 fi