blob: ec1ce944c997d3045d0ad73f5c7373d4d6a46ed7 [file] [log] [blame]
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -04001#!/bin/bash
Jakub Latusek2eea1492020-10-21 13:36:29 +02002{{/*
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -04003
4# Copyright © 2020 Bell Canada
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
Jakub Latusek2eea1492020-10-21 13:36:29 +020017*/}}
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040018
19CERTS_DIR=${CERTS_DIR:-/certs}
Sylvain Desbureauxbd94a042021-04-19 16:00:49 +020020MORE_CERTS_DIR=${MORE_CERTS_DIR:-/more_certs}
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040021WORK_DIR=${WORK_DIR:-/updatedTruststore}
22ONAP_TRUSTSTORE=${ONAP_TRUSTSTORE:-truststoreONAPall.jks}
23JRE_TRUSTSTORE=${JRE_TRUSTSTORE:-$JAVA_HOME/lib/security/cacerts}
24TRUSTSTORE_OUTPUT_FILENAME=${TRUSTSTORE_OUTPUT_FILENAME:-truststore.jks}
25
26mkdir -p $WORK_DIR
27
28# Decrypt and move relevant files to WORK_DIR
29for f in $CERTS_DIR/*; do
Sylvain Desbureaux36389672021-01-19 14:51:24 +010030 export canonical_name_nob64=$(echo $f | sed 's/.*\/\([^\/]*\)/\1/')
31 export canonical_name_b64=$(echo $f | sed 's/.*\/\([^\/]*\)\(\.b64\)/\1/')
Guillaume Lambert5f4af052021-03-09 21:52:32 +010032 if [ "$AAF_ENABLED" = "false" ] && [ "$canonical_name_b64" = "$ONAP_TRUSTSTORE" ]; then
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040033 # Dont use onap truststore when aaf is disabled
34 continue
35 fi
Guillaume Lambert5f4af052021-03-09 21:52:32 +010036 if [ "$AAF_ENABLED" = "false" ] && [ "$canonical_name_nob64" = "$ONAP_TRUSTSTORE" ]; then
Sylvain Desbureaux36389672021-01-19 14:51:24 +010037 # Dont use onap truststore when aaf is disabled
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040038 continue
39 fi
Guillaume Lambert5f4af052021-03-09 21:52:32 +010040 if [ ${f: -3} = ".sh" ]; then
Sylvain Desbureaux36389672021-01-19 14:51:24 +010041 continue
42 fi
Guillaume Lambert5f4af052021-03-09 21:52:32 +010043 if [ ${f: -4} = ".b64" ]
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040044 then
45 base64 -d $f > $WORK_DIR/`basename $f .b64`
46 else
47 cp $f $WORK_DIR/.
48 fi
49done
50
Sylvain Desbureauxbd94a042021-04-19 16:00:49 +020051for f in $MORE_CERTS_DIR/*; do
52 if [ ${f: -4} == ".pem" ]
53 then
54 cp $f $WORK_DIR/.
55 fi
56done
57
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040058# Prepare truststore output file
Guillaume Lambert5f4af052021-03-09 21:52:32 +010059if [ "$AAF_ENABLED" = "true" ]
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040060 then
61 mv $WORK_DIR/$ONAP_TRUSTSTORE $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME
62 else
63 echo "AAF is disabled, using JRE truststore"
64 cp $JRE_TRUSTSTORE $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME
65fi
66
67# Import Custom Certificates
68for f in $WORK_DIR/*; do
Guillaume Lambert5f4af052021-03-09 21:52:32 +010069 if [ ${f: -4} = ".pem" ]; then
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040070 echo "importing certificate: $f"
71 keytool -import -file $f -alias `basename $f` -keystore $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME -storepass $TRUSTSTORE_PASSWORD -noprompt
Sylvain Desbureaux36389672021-01-19 14:51:24 +010072 if [ $? != 0 ]; then
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040073 echo "failed importing certificate: $f"
74 exit 1
75 fi
76 fi
77done