mrichomme | e706347 | 2020-05-14 10:08:03 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # |
| 4 | # Generate HV-VES SSL related certs. |
| 5 | # Copy the stuff to HV-VES and Robot pods. |
| 6 | # |
| 7 | NAMESPACE=${NAMESPACE:-onap} |
mrichomme | 1fbff98 | 2020-05-15 14:38:29 +0200 | [diff] [blame] | 8 | DIR=${DIR:-/tmp} |
mrichomme | e706347 | 2020-05-14 10:08:03 +0200 | [diff] [blame] | 9 | |
mrichomme | 24b8e88 | 2020-05-20 10:36:54 +0200 | [diff] [blame] | 10 | HVVESPOD=$(kubectl -n $NAMESPACE get pods --no-headers=true -o custom-columns=:metadata.name | grep dcae-hv-ves) |
mrichomme | e706347 | 2020-05-14 10:08:03 +0200 | [diff] [blame] | 11 | |
| 12 | |
| 13 | generate_ca_key_cert () { |
| 14 | openssl genrsa -out $1/ca.key 2048 |
| 15 | openssl req -new -x509 -days 36500 -key $1/ca.key -out $1/ca.pem -subj /CN=dcae-hv-ves-ca.onap |
| 16 | } |
| 17 | |
| 18 | generate_server_key_csr () { |
| 19 | openssl genrsa -out $1/server.key 2048 |
| 20 | openssl req -new -key $1/server.key -out $1/server.csr -subj /CN=dcae-hv-ves-collector.onap |
| 21 | } |
| 22 | |
| 23 | generate_client_key_csr () { |
| 24 | openssl genrsa -out $1/client.key 2048 |
| 25 | openssl req -new -key $1/client.key -out $1/client.csr -subj /CN=dcae-hv-ves-client.onap |
| 26 | } |
| 27 | |
| 28 | sign_server_and_client_cert () { |
| 29 | openssl x509 -req -days 36500 -in $1/server.csr -CA $1/ca.pem -CAkey $1/ca.key -out $1/server.pem -set_serial 00 |
| 30 | openssl x509 -req -days 36500 -in $1/client.csr -CA $1/ca.pem -CAkey $1/ca.key -out $1/client.pem -set_serial 00 |
| 31 | } |
| 32 | |
| 33 | create_pkcs12_ca_and_server () { |
| 34 | openssl pkcs12 -export -out $1/ca.p12 -inkey $1/ca.key -in $1/ca.pem -passout pass: |
| 35 | openssl pkcs12 -export -out $1/server.p12 -inkey $1/server.key -in $1/server.pem -passout pass: |
| 36 | } |
| 37 | |
| 38 | copy_server_certs_to_hvves () { |
| 39 | for f in {ca.p12,server.p12} |
| 40 | do |
| 41 | kubectl cp $1/$f $2/$3:$4 |
| 42 | done |
| 43 | } |
| 44 | |
| 45 | copy_client_certs_to_robot () { |
| 46 | for f in {ca.pem,client.key,client.pem} |
| 47 | do |
| 48 | kubectl cp $1/$f $2/$3:$4 |
| 49 | done |
| 50 | } |
| 51 | |
| 52 | cleanup () { |
| 53 | rm -f $1/{ca,server,client}.??? |
| 54 | } |
| 55 | |
| 56 | |
| 57 | generate_ca_key_cert "$DIR" |
| 58 | generate_server_key_csr "$DIR" |
| 59 | generate_client_key_csr "$DIR" |
| 60 | sign_server_and_client_cert "$DIR" |
| 61 | create_pkcs12_ca_and_server "$DIR" |
| 62 | copy_server_certs_to_hvves "$DIR" "$NAMESPACE" "$HVVESPOD" "$DIR" |