blob: b5a1d57649a00f50ecbc1b88ae82613af7f65bac [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}
20WORK_DIR=${WORK_DIR:-/updatedTruststore}
21ONAP_TRUSTSTORE=${ONAP_TRUSTSTORE:-truststoreONAPall.jks}
22JRE_TRUSTSTORE=${JRE_TRUSTSTORE:-$JAVA_HOME/lib/security/cacerts}
23TRUSTSTORE_OUTPUT_FILENAME=${TRUSTSTORE_OUTPUT_FILENAME:-truststore.jks}
24
25mkdir -p $WORK_DIR
26
27# Decrypt and move relevant files to WORK_DIR
28for f in $CERTS_DIR/*; do
Sylvain Desbureaux36389672021-01-19 14:51:24 +010029 export canonical_name_nob64=$(echo $f | sed 's/.*\/\([^\/]*\)/\1/')
30 export canonical_name_b64=$(echo $f | sed 's/.*\/\([^\/]*\)\(\.b64\)/\1/')
31 if [ "$AAF_ENABLED" == "false" ] && [ "$canonical_name_b64" == "$ONAP_TRUSTSTORE" ]; then
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040032 # Dont use onap truststore when aaf is disabled
33 continue
34 fi
Sylvain Desbureaux36389672021-01-19 14:51:24 +010035 if [ "$AAF_ENABLED" == "false" ] && [ "$canonical_name_nob64" == "$ONAP_TRUSTSTORE" ]; then
36 # Dont use onap truststore when aaf is disabled
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040037 continue
38 fi
Sylvain Desbureaux36389672021-01-19 14:51:24 +010039 if [ ${f: -3} == ".sh" ]; then
40 continue
41 fi
42 if [ ${f: -4} == ".b64" ]
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040043 then
44 base64 -d $f > $WORK_DIR/`basename $f .b64`
45 else
46 cp $f $WORK_DIR/.
47 fi
48done
49
50# Prepare truststore output file
Sylvain Desbureaux36389672021-01-19 14:51:24 +010051if [ "$AAF_ENABLED" == "true" ]
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040052 then
Sylvain Desbureauxff5947f2021-04-19 15:32:44 +020053 echo "AAF is enabled, use 'AAF' truststore"
54 export TRUSTSTORE_OUTPUT_FILENAME=${ONAP_TRUSTSTORE}
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040055 else
56 echo "AAF is disabled, using JRE truststore"
57 cp $JRE_TRUSTSTORE $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME
58fi
59
60# Import Custom Certificates
61for f in $WORK_DIR/*; do
Sylvain Desbureaux36389672021-01-19 14:51:24 +010062 if [ ${f: -4} == ".pem" ]; then
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040063 echo "importing certificate: $f"
64 keytool -import -file $f -alias `basename $f` -keystore $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME -storepass $TRUSTSTORE_PASSWORD -noprompt
Sylvain Desbureaux36389672021-01-19 14:51:24 +010065 if [ $? != 0 ]; then
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040066 echo "failed importing certificate: $f"
67 exit 1
68 fi
69 fi
70done