blob: dd311830e74aadfcc66171124d2529c4b918abfc [file] [log] [blame]
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -04001#!/bin/bash
2
3# Copyright © 2020 Bell Canada
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17CERTS_DIR=${CERTS_DIR:-/certs}
18WORK_DIR=${WORK_DIR:-/updatedTruststore}
19ONAP_TRUSTSTORE=${ONAP_TRUSTSTORE:-truststoreONAPall.jks}
20JRE_TRUSTSTORE=${JRE_TRUSTSTORE:-$JAVA_HOME/lib/security/cacerts}
21TRUSTSTORE_OUTPUT_FILENAME=${TRUSTSTORE_OUTPUT_FILENAME:-truststore.jks}
22
23mkdir -p $WORK_DIR
24
25# Decrypt and move relevant files to WORK_DIR
26for f in $CERTS_DIR/*; do
27 if [[ $AAF_ENABLED == false ]] && [[ $f == *$ONAP_TRUSTSTORE* ]]; then
28 # Dont use onap truststore when aaf is disabled
29 continue
30 fi
31 if [[ $f == *.sh ]]; then
32 continue
33 fi
34 if [[ $f == *.b64 ]]
35 then
36 base64 -d $f > $WORK_DIR/`basename $f .b64`
37 else
38 cp $f $WORK_DIR/.
39 fi
40done
41
42# Prepare truststore output file
43if [[ $AAF_ENABLED == true ]]
44 then
45 mv $WORK_DIR/$ONAP_TRUSTSTORE $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME
46 else
47 echo "AAF is disabled, using JRE truststore"
48 cp $JRE_TRUSTSTORE $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME
49fi
50
51# Import Custom Certificates
52for f in $WORK_DIR/*; do
53 if [[ $f == *.pem ]]; then
54 echo "importing certificate: $f"
55 keytool -import -file $f -alias `basename $f` -keystore $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME -storepass $TRUSTSTORE_PASSWORD -noprompt
56 if [[ $? != 0 ]]; then
57 echo "failed importing certificate: $f"
58 exit 1
59 fi
60 fi
61done