blob: 96b0c0c0c8f8168b530de2eda64b624ec9c2d7bf [file] [log] [blame]
a.sreekumarf79b6672021-05-19 12:52:14 +01001#!/bin/sh
Jakub Latusek2eea1492020-10-21 13:36:29 +02002{{/*
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -04003
a.sreekumarf79b6672021-05-19 12:52:14 +01004# Copyright © 2020-2021 Bell Canada
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -04005#
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}
Abdelmuhaimen Seaudi3dc8cc22021-09-05 16:32:22 +020025SSL_WORKDIR=${SSL_WORKDIR:-/usr/local/share/ca-certificates}
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040026
27mkdir -p $WORK_DIR
28
29# Decrypt and move relevant files to WORK_DIR
30for f in $CERTS_DIR/*; do
Sylvain Desbureaux36389672021-01-19 14:51:24 +010031 export canonical_name_nob64=$(echo $f | sed 's/.*\/\([^\/]*\)/\1/')
32 export canonical_name_b64=$(echo $f | sed 's/.*\/\([^\/]*\)\(\.b64\)/\1/')
Guillaume Lambert5f4af052021-03-09 21:52:32 +010033 if [ "$AAF_ENABLED" = "false" ] && [ "$canonical_name_b64" = "$ONAP_TRUSTSTORE" ]; then
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040034 # Dont use onap truststore when aaf is disabled
35 continue
36 fi
Guillaume Lambert5f4af052021-03-09 21:52:32 +010037 if [ "$AAF_ENABLED" = "false" ] && [ "$canonical_name_nob64" = "$ONAP_TRUSTSTORE" ]; then
Sylvain Desbureaux36389672021-01-19 14:51:24 +010038 # Dont use onap truststore when aaf is disabled
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040039 continue
40 fi
guillaume.lambert639768e2021-09-07 16:09:54 +020041 if echo $f | grep '\.sh$' >/dev/null; then
Sylvain Desbureaux36389672021-01-19 14:51:24 +010042 continue
43 fi
Bartek Grzybowski44037b92022-01-26 12:27:00 +010044 if echo $f | grep '\.b64$' >/dev/null
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040045 then
46 base64 -d $f > $WORK_DIR/`basename $f .b64`
47 else
48 cp $f $WORK_DIR/.
49 fi
50done
51
Sylvain Desbureauxbd94a042021-04-19 16:00:49 +020052for f in $MORE_CERTS_DIR/*; do
guillaume.lambert639768e2021-09-07 16:09:54 +020053 if echo $f | grep '\.pem$' >/dev/null; then
Sylvain Desbureauxbd94a042021-04-19 16:00:49 +020054 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
Sylvain Desbureauxff5947f2021-04-19 15:32:44 +020061 echo "AAF is enabled, use 'AAF' truststore"
62 export TRUSTSTORE_OUTPUT_FILENAME=${ONAP_TRUSTSTORE}
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040063 else
64 echo "AAF is disabled, using JRE truststore"
65 cp $JRE_TRUSTSTORE $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME
66fi
67
68# Import Custom Certificates
69for f in $WORK_DIR/*; do
guillaume.lambert639768e2021-09-07 16:09:54 +020070 if echo $f | grep '\.pem$' >/dev/null; then
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040071 echo "importing certificate: $f"
72 keytool -import -file $f -alias `basename $f` -keystore $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME -storepass $TRUSTSTORE_PASSWORD -noprompt
Sylvain Desbureaux36389672021-01-19 14:51:24 +010073 if [ $? != 0 ]; then
Jozsef Csongvai9d4d5af2020-07-13 11:10:25 -040074 echo "failed importing certificate: $f"
75 exit 1
76 fi
77 fi
78done
Abdelmuhaimen Seaudi3dc8cc22021-09-05 16:32:22 +020079
80# Import certificates to Linux SSL Truststore
81cp $CERTS_DIR/*.crt $SSL_WORKDIR/.
82cp $MORE_CERTS_DIR/*.crt $SSL_WORKDIR/.
83update-ca-certificates
84if [ $? != 0 ]
85 then
86 echo "failed importing certificates"
87 exit 1
88 else
89 cp /etc/ssl/certs/ca-certificates.crt $WORK_DIR/.
Bartek Grzybowski44037b92022-01-26 12:27:00 +010090fi