import_jks_certs.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. #
  3. # Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
  4. # and other contributors as indicated by the @author tags.
  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.
  17. #
  18. set -ex
  19. function import_certs() {
  20. dir=$CERT_DIR
  21. hawkular_metrics_keystore_password=$(echo $METRICS_KEYSTORE_PASSWD | base64 -d)
  22. hawkular_metrics_truststore_password=$(echo $METRICS_TRUSTSTORE_PASSWD | base64 -d)
  23. hawkular_alias=`keytool -noprompt -list -keystore $dir/hawkular-metrics.truststore -storepass ${hawkular_metrics_truststore_password} | sed -n '7~2s/,.*$//p'`
  24. if [ ! -f $dir/hawkular-metrics.keystore ]; then
  25. echo "Creating the Hawkular Metrics keystore from the PEM file"
  26. keytool -importkeystore -v \
  27. -srckeystore $dir/hawkular-metrics.pkcs12 \
  28. -destkeystore $dir/hawkular-metrics.keystore \
  29. -srcstoretype PKCS12 \
  30. -deststoretype JKS \
  31. -srcstorepass $hawkular_metrics_keystore_password \
  32. -deststorepass $hawkular_metrics_keystore_password
  33. fi
  34. cert_alias_names=(ca metricca)
  35. for cert_alias in ${cert_alias_names[*]}; do
  36. if [[ ! ${hawkular_alias[*]} =~ "$cert_alias" ]]; then
  37. echo "Importing the CA Certificate with alias $cert_alias into the Hawkular Metrics Truststore"
  38. keytool -noprompt -import -v -trustcacerts -alias $cert_alias \
  39. -file ${dir}/ca.crt \
  40. -keystore $dir/hawkular-metrics.truststore \
  41. -trustcacerts \
  42. -storepass $hawkular_metrics_truststore_password
  43. fi
  44. done
  45. }
  46. import_certs