Merge "Add upgrade/downgrade scripts for postgres in db-migrator"
[policy/docker.git] / csit / gen_truststore.sh
1 #!/bin/bash
2 #
3 # ===========LICENSE_START====================================================
4 #  Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
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 # ============LICENSE_END=====================================================
18 #
19
20 #
21 # Generates a root certificate and truststore for use by the various policy
22 # docker images.
23 #
24
25 DIR="${0%/*}/config"
26 cd "${DIR}"
27
28 OUTFILE=policy-truststore
29 ALIAS=onap.policy.csit.root.ca
30 PASS=Pol1cy_0nap
31
32 keytool -list -alias ${ALIAS} -keystore ${OUTFILE} -storepass "${PASS}" \
33     >/dev/null 2>&1
34 if [ $? -eq 0 ]
35 then
36     echo "Truststore already contains a policy root CA - not re-generating"
37     exit 0
38 fi
39
40 openssl req -new -keyout cakey.pem -out careq.pem -passout "pass:${PASS}" \
41             -subj "/C=US/ST=New Jersey/OU=ONAP/CN=policy.onap"
42
43 openssl x509 -signkey cakey.pem -req -days 3650 -in careq.pem \
44             -out caroot.cer -extensions v3_ca -passin "pass:${PASS}"
45
46 keytool -import -noprompt -trustcacerts -alias ${ALIAS} \
47             -file caroot.cer -keystore "${OUTFILE}" -storepass "${PASS}"
48
49 chmod 644 "$OUTFILE"