Jozsef Csongvai | 9d4d5af | 2020-07-13 11:10:25 -0400 | [diff] [blame] | 1 | #!/bin/bash |
Jakub Latusek | 2eea149 | 2020-10-21 13:36:29 +0200 | [diff] [blame] | 2 | {{/* |
Jozsef Csongvai | 9d4d5af | 2020-07-13 11:10:25 -0400 | [diff] [blame] | 3 | |
| 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 Latusek | 2eea149 | 2020-10-21 13:36:29 +0200 | [diff] [blame] | 17 | */}} |
Jozsef Csongvai | 9d4d5af | 2020-07-13 11:10:25 -0400 | [diff] [blame] | 18 | |
| 19 | CERTS_DIR=${CERTS_DIR:-/certs} |
| 20 | WORK_DIR=${WORK_DIR:-/updatedTruststore} |
| 21 | ONAP_TRUSTSTORE=${ONAP_TRUSTSTORE:-truststoreONAPall.jks} |
| 22 | JRE_TRUSTSTORE=${JRE_TRUSTSTORE:-$JAVA_HOME/lib/security/cacerts} |
| 23 | TRUSTSTORE_OUTPUT_FILENAME=${TRUSTSTORE_OUTPUT_FILENAME:-truststore.jks} |
| 24 | |
| 25 | mkdir -p $WORK_DIR |
| 26 | |
| 27 | # Decrypt and move relevant files to WORK_DIR |
| 28 | for f in $CERTS_DIR/*; do |
| 29 | if [[ $AAF_ENABLED == false ]] && [[ $f == *$ONAP_TRUSTSTORE* ]]; then |
| 30 | # Dont use onap truststore when aaf is disabled |
| 31 | continue |
| 32 | fi |
| 33 | if [[ $f == *.sh ]]; then |
| 34 | continue |
| 35 | fi |
| 36 | if [[ $f == *.b64 ]] |
| 37 | then |
| 38 | base64 -d $f > $WORK_DIR/`basename $f .b64` |
| 39 | else |
| 40 | cp $f $WORK_DIR/. |
| 41 | fi |
| 42 | done |
| 43 | |
| 44 | # Prepare truststore output file |
| 45 | if [[ $AAF_ENABLED == true ]] |
| 46 | then |
| 47 | mv $WORK_DIR/$ONAP_TRUSTSTORE $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME |
| 48 | else |
| 49 | echo "AAF is disabled, using JRE truststore" |
| 50 | cp $JRE_TRUSTSTORE $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME |
| 51 | fi |
| 52 | |
| 53 | # Import Custom Certificates |
| 54 | for f in $WORK_DIR/*; do |
| 55 | if [[ $f == *.pem ]]; then |
| 56 | echo "importing certificate: $f" |
| 57 | keytool -import -file $f -alias `basename $f` -keystore $WORK_DIR/$TRUSTSTORE_OUTPUT_FILENAME -storepass $TRUSTSTORE_PASSWORD -noprompt |
| 58 | if [[ $? != 0 ]]; then |
| 59 | echo "failed importing certificate: $f" |
| 60 | exit 1 |
| 61 | fi |
| 62 | fi |
| 63 | done |