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==================================================== |
| 20 | # |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 21 | # |
| 22 | # Initialize a manual Cert. This is NOT entered in Certman Records |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 23 | # $1 - CN (Common Name) |
| 24 | # $2 - FQI (Fully Qualified Identity) |
| 25 | # $3-$n - SANs (Service Alias Names) |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 26 | # |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 27 | |
| 28 | if [ "$2" = "" ]; then |
| 29 | echo "FQI (Fully Qualified Identity): " |
| 30 | read FQI |
| 31 | fi |
| 32 | |
| 33 | if [ "$1" = "" -o "$1" = "-local" ]; then |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 34 | echo "Personal Certificate" |
| 35 | SUBJECT="/CN=$FQI/OU=V1`cat subject.aaf`" |
Instrumental | 97083ef | 2018-04-25 15:22:38 -0500 | [diff] [blame] | 36 | NAME=$FQI |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 37 | else |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 38 | echo "Application Certificate" |
| 39 | SUBJECT="/CN=$1/OU=$FQI`cat subject.aaf`" |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 40 | NAME=$1 |
Instrumental | 68b2315 | 2018-05-01 15:03:25 -0500 | [diff] [blame] | 41 | |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 42 | if [ "$3" = "" ]; then |
| 43 | echo "Enter any SANS, delimited by spaces: " |
| 44 | read SANS |
| 45 | else |
| 46 | SANS="" |
| 47 | while [ ! "$3" = "" ]; do |
| 48 | SANS=${SANS}" "$3 |
| 49 | shift |
| 50 | done |
| 51 | fi |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 52 | fi |
Instrumental | 68b2315 | 2018-05-01 15:03:25 -0500 | [diff] [blame] | 53 | |
| 54 | # Do SANs |
| 55 | if [ "$SANS" = "" ]; then |
| 56 | echo no SANS |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 57 | if [ -e $NAME.san ]; then |
Instrumental | 68b2315 | 2018-05-01 15:03:25 -0500 | [diff] [blame] | 58 | rm $NAME.san |
| 59 | fi |
| 60 | else |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 61 | echo some SANS: $SANS |
Instrumental | 68b2315 | 2018-05-01 15:03:25 -0500 | [diff] [blame] | 62 | cp ../san.conf $NAME.san |
| 63 | NUM=1 |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 64 | for D in $SANS; do |
Instrumental | 68b2315 | 2018-05-01 15:03:25 -0500 | [diff] [blame] | 65 | echo "DNS.$NUM = $D" >> $NAME.san |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 66 | NUM=$((NUM+1)) |
Instrumental | 68b2315 | 2018-05-01 15:03:25 -0500 | [diff] [blame] | 67 | done |
| 68 | fi |
| 69 | |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 70 | echo $SUBJECT |
| 71 | |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 72 | if [ ! -e $NAME.csr ]; then |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 73 | if [ "$1" = "-local" ]; then |
| 74 | echo "IMPORTANT: If for any reason, you kill this process, type 'stty sane'" |
| 75 | echo "Enter the PassPhrase for the Key for $FQI: " |
| 76 | `stty -echo` |
| 77 | read PASSPHRASE |
| 78 | `stty echo` |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 79 | |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 80 | # remove any previous Private key |
Instrumental | 97083ef | 2018-04-25 15:22:38 -0500 | [diff] [blame] | 81 | rm private/$NAME.key |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 82 | # Create regular rsa encrypted key |
Instrumental | 97083ef | 2018-04-25 15:22:38 -0500 | [diff] [blame] | 83 | openssl req -new -newkey rsa:2048 -sha256 -keyout private/$NAME.key \ |
| 84 | -out $NAME.csr -outform PEM -subj "$SUBJECT" \ |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 85 | -passout stdin << EOF |
| 86 | $PASSPHRASE |
| 87 | EOF |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 88 | chmod 400 private/$NAME.key |
| 89 | else |
| 90 | openssl req -newkey rsa:2048 -sha256 -keyout private/$NAME.key -out $NAME.csr -outform PEM -subj "$SUBJECT" |
| 91 | chmod 400 $NAME.key |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 92 | echo "# All done, print result" |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 93 | openssl req -verify -text -noout -in $NAME.csr |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 94 | fi |
| 95 | fi |
| 96 | |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 97 | # Sign it |
Instrumental | 68b2315 | 2018-05-01 15:03:25 -0500 | [diff] [blame] | 98 | if [ -e $NAME.san ]; then |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 99 | openssl ca -config ../openssl.conf -extensions server_cert -out certs/$NAME.crt \ |
Instrumental | 68b2315 | 2018-05-01 15:03:25 -0500 | [diff] [blame] | 100 | -cert certs/ca.crt -keyfile private/ca.key \ |
| 101 | -policy policy_loose \ |
| 102 | -days 360 \ |
| 103 | -extfile $NAME.san \ |
| 104 | -infiles $NAME.csr |
Maciej Wejs | 02c1970 | 2018-08-17 13:56:31 +0200 | [diff] [blame] | 105 | else |
| 106 | openssl ca -config ../openssl.conf -extensions server_cert -out certs/$NAME.crt \ |
Instrumental | 31d847e | 2018-03-26 14:17:19 -0700 | [diff] [blame] | 107 | -cert certs/ca.crt -keyfile private/ca.key \ |
Instrumental | 924b18d | 2018-04-05 20:17:18 -0500 | [diff] [blame] | 108 | -policy policy_loose \ |
| 109 | -days 360 \ |
Instrumental | 97083ef | 2018-04-25 15:22:38 -0500 | [diff] [blame] | 110 | -infiles $NAME.csr |
Instrumental | 68b2315 | 2018-05-01 15:03:25 -0500 | [diff] [blame] | 111 | fi |