4 # Copyright © 2020-2021 Bell Canada
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 CERTS_DIR=${CERTS_DIR:-/certs}
20 MORE_CERTS_DIR=${MORE_CERTS_DIR:-/more_certs}
21 WORK_DIR=${WORK_DIR:-/updatedTruststore}
22 ONAP_TRUSTSTORE=${ONAP_TRUSTSTORE:-truststoreONAPall.jks}
23 JRE_TRUSTSTORE=${JRE_TRUSTSTORE:-$JAVA_HOME/lib/security/cacerts}
24 TRUSTSTORE_OUTPUT_FILENAME=${TRUSTSTORE_OUTPUT_FILENAME:-truststore.jks}
25 SSL_WORKDIR=${SSL_WORKDIR:-/usr/local/share/ca-certificates}
29 # Decrypt and move relevant files to WORK_DIR
30 for f in $CERTS_DIR/*; do
31 export canonical_name_nob64=$(echo $f | sed 's/.*\/\([^\/]*\)/\1/')
32 export canonical_name_b64=$(echo $f | sed 's/.*\/\([^\/]*\)\(\.b64\)/\1/')
33 if [ "$AAF_ENABLED" = "false" ] && [ "$canonical_name_b64" = "$ONAP_TRUSTSTORE" ]; then
34 # Dont use onap truststore when aaf is disabled
37 if [ "$AAF_ENABLED" = "false" ] && [ "$canonical_name_nob64" = "$ONAP_TRUSTSTORE" ]; then
38 # Dont use onap truststore when aaf is disabled
41 if [ ${f: -3} = ".sh" ]; then
44 if [ ${f: -4} = ".b64" ]
46 base64 -d $f > $WORK_DIR/`basename $f .b64`
52 for f in $MORE_CERTS_DIR/*; do
53 if [ ${f: -4} == ".pem" ]
59 # Prepare truststore output file
60 if [ "$AAF_ENABLED" = "true" ]
62 echo "AAF is enabled, use 'AAF' truststore"
63 export TRUSTSTORE_OUTPUT_FILENAME=${ONAP_TRUSTSTORE}
65 echo "AAF is disabled, using JRE truststore"
66 cp $JRE_TRUSTSTORE $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME
69 # Import Custom Certificates
70 for f in $WORK_DIR/*; do
71 if [ ${f: -4} = ".pem" ]; then
72 echo "importing certificate: $f"
73 keytool -import -file $f -alias `basename $f` -keystore $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME -storepass $TRUSTSTORE_PASSWORD -noprompt
75 echo "failed importing certificate: $f"
81 # Import certificates to Linux SSL Truststore
82 cp $CERTS_DIR/*.crt $SSL_WORKDIR/.
83 cp $MORE_CERTS_DIR/*.crt $SSL_WORKDIR/.
84 update-ca-certificates
87 echo "failed importing certificates"
90 cp /etc/ssl/certs/ca-certificates.crt $WORK_DIR/.