2 # ============LICENSE_START=======================================================
3 # csit-dcaegen2-collectors-hv-ves
4 # ================================================================================
5 # Copyright (C) 2018 NOKIA
6 # ================================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END=========================================================
21 set -eu -o pipefail -o xtrace
24 CN_PREFIX=dcaegen2-hvves
25 DNAME_PREFIX="C=PL,ST=DL,L=Wroclaw,O=Nokia,OU=MANO,CN=${CN_PREFIX}"
27 store_opts="-storetype PKCS12 -storepass ${STORE_PASS} -noprompt"
32 local keystore="-keystore ${key_name}.p12 ${store_opts}"
33 keytool -genkey -alias ${key_name} \
38 -dname "${DNAME_PREFIX}-${key_name}"
39 keytool -import -trustcacerts -alias ${ca} -file ${ca}.crt ${keystore}
41 keytool -certreq -alias ${key_name} -keyalg RSA ${keystore} | \
42 keytool -alias ${ca} -gencert -ext "san=dns:${CN_PREFIX}-${ca}" ${store_opts} -keystore ${ca}.p12 | \
43 keytool -alias ${key_name} -importcert ${keystore}
45 printf ${STORE_PASS} > ${key_name}.pass
51 keytool -genkeypair ${store_opts} -alias ${ca} -dname "${DNAME_PREFIX}-${ca}" -keystore ${ca}.p12 -ext bc:c
52 keytool -export -alias ${ca} -file ${ca}.crt ${store_opts} -keystore ${ca}.p12
55 function gen_truststore() {
58 keytool -import -trustcacerts -alias ca -file ${trusted_ca}.crt ${store_opts} -keystore ${name}.p12
59 printf ${STORE_PASS} > ${name}.pass
63 rm -f *.crt *.p12 *.pass
66 if [[ $# -eq 0 ]]; then
69 gen_truststore trust ca
70 gen_truststore untrustedtrust untrustedca
73 gen_key untrustedclient untrustedca
74 elif [[ $1 == "clean" ]]; then
77 echo "usage: $0 [clean]"