Instrumental | 7a1817b | 2018-11-05 11:11:15 -0600 | [diff] [blame^] | 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==================================================== |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 20 | # |
| 21 | # NOTE: This README is "bash" capable. bash README.txt |
| 22 | # |
| 23 | # create simple but reasonable directory structure |
| 24 | mkdir -p private certs newcerts |
| 25 | chmod 700 private |
| 26 | chmod 755 certs newcerts |
| 27 | touch index.txt |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 28 | echo "unique_subject = no" > index.txt.attr |
| 29 | |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 30 | if [ ! -e serial ]; then |
Instrumental | c3ca46e | 2018-09-25 08:25:52 -0500 | [diff] [blame] | 31 | echo $(date +%s) > serial |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 32 | fi |
| 33 | |
| 34 | if [ "$1" == "" ]; then |
| 35 | CN=$1 |
| 36 | else |
| 37 | CN=RootCA |
| 38 | fi |
| 39 | |
| 40 | echo "IMPORTANT: If for any reason, you kill this process, type 'stty sane'" |
| 41 | echo "Enter the PassPhrase for your Key: " |
| 42 | `stty -echo` |
| 43 | read PASSPHRASE |
| 44 | `stty echo` |
| 45 | |
| 46 | if [ ! -e /private/ca.ekey ]; then |
| 47 | # Create a regaular rsa encrypted key |
| 48 | openssl genrsa -aes256 -out private/ca.ekey -passout stdin 4096 << EOF |
| 49 | $PASSPHRASE |
| 50 | EOF |
| 51 | fi |
| 52 | |
| 53 | if [ ! -e /private/ca.key ]; then |
| 54 | # Move to a Java/Filesystem readable key. Note that this one is NOT Encrypted. |
| 55 | openssl pkcs8 -in private/ca.ekey -topk8 -nocrypt -out private/ca.key -passin stdin << EOF |
| 56 | $PASSPHRASE |
| 57 | EOF |
| 58 | fi |
| 59 | chmod 400 private/ca.key private/ca.ekey |
| 60 | |
| 61 | |
| 62 | if [ -e subject.aaf ]; then |
| 63 | SUBJECT="-subj /CN=$CN`cat subject.aaf`" |
| 64 | else |
| 65 | SUBJECT="" |
| 66 | fi |
| 67 | |
| 68 | # Generate a CA Certificate |
| 69 | openssl req -config openssl.conf \ |
| 70 | -key private/ca.key \ |
| 71 | -new -x509 -days 7300 -sha256 -extensions v3_ca \ |
| 72 | $SUBJECT \ |
| 73 | -out certs/ca.crt |
| 74 | |
| 75 | if [ -e certs/ca.crt ]; then |
| 76 | # All done, print result |
| 77 | openssl x509 -text -noout -in certs/ca.crt |
| 78 | fi |