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