Commit 33a900145cba25066632d0bb4f8cbf977392269b

Authored by nickAS21
1 parent 84698ad5

Lwm2m: back: created sh with many certX509

1 -#!/bin/sh 1 +#!/bin/bash
2 # 2 #
3 # Copyright © 2016-2020 The Thingsboard Authors 3 # Copyright © 2016-2020 The Thingsboard Authors
4 # 4 #
@@ -15,12 +15,147 @@ @@ -15,12 +15,147 @@
15 # limitations under the License. 15 # limitations under the License.
16 # 16 #
17 17
18 -# source the properties: 18 +#p) CLIENT_CN=LwX50900000000
  19 +#s) client_start=0
  20 +#f) client_finish=1
  21 +#a) CLIENT_ALIAS=client_alias_00000000
  22 +#b) BOOTSTRAP_ALIAS=bootstrap
  23 +#d) SERVER_ALIAS=server
  24 +#j) SERVER_STORE=serverKeyStore.jks
  25 +#k) CLIENT_STORE=clientKeyStore.jks
  26 +#c) CLIENT_STORE_PWD=client_ks_password
  27 +#w) SERVER_STORE_PWD=server_ks_password
  28 +
  29 +#while test $# -gt 0; do
  30 +# case "$1" in
  31 +# -h|--help)
  32 +# echo "$package - attempt to capture frames"
  33 +# echo " "
  34 +# echo "$package [options] application [arguments]"
  35 +# echo " "
  36 +# echo "options:"
  37 +# echo "-h, --help show brief help"
  38 +# echo "-a, --action=ACTION specify an action to use"
  39 +# echo "-o, --output-dir=DIR specify a directory to store output in"
  40 +# exit 0
  41 +# ;;
  42 +# -a)
  43 +# shift
  44 +# if test $# -gt 0; then
  45 +# export PROCESS=$1
  46 +# else
  47 +# echo "no process specified"
  48 +# exit 1
  49 +# fi
  50 +# shift
  51 +# ;;
  52 +# --action*)
  53 +# export PROCESS=`echo $1 | sed -e 's/^[^=]*=//g'`
  54 +# shift
  55 +# ;;
  56 +# -o)
  57 +# shift
  58 +# if test $# -gt 0; then
  59 +# export OUTPUT=$1
  60 +# else
  61 +# echo "no output dir specified"
  62 +# exit 1
  63 +# fi
  64 +# shift
  65 +# ;;
  66 +# --output-dir*)
  67 +# export OUTPUT=`echo $1 | sed -e 's/^[^=]*=//g'`
  68 +# shift
  69 +# ;;
  70 +# *)
  71 +# break
  72 +# ;;
  73 +# esac
  74 +#done
  75 +
  76 +
  77 +while getopts p:s:f:a:b:d:j:k:c:w: flag; do
  78 + case "${flag}" in
  79 + p) client_prefix=${OPTARG} ;;
  80 + s) client_start=${OPTARG} ;;
  81 + f) client_finish=${OPTARG} ;;
  82 + a) client_alias=${OPTARG} ;;
  83 + b) bootstrap_alias=${OPTARG} ;;
  84 + d) server_alias=${OPTARG} ;;
  85 + j) key_store_server_file=${OPTARG} ;;
  86 + k) key_store_client_file=${OPTARG} ;;
  87 + c) client_key_store_pwd=${OPTARG} ;;
  88 + w) server_key_store_pwd=${OPTARG} ;;
  89 + esac
  90 +done
  91 +
  92 +# cd to dir of script
19 script_dir=$(dirname $0) 93 script_dir=$(dirname $0)
20 echo "script_dir: $script_dir" 94 echo "script_dir: $script_dir"
21 cd $script_dir 95 cd $script_dir
  96 +# source the properties:
22 . ./lwM2M_keygen.properties 97 . ./lwM2M_keygen.properties
23 98
  99 +
  100 +if [ -n "$client_prefix" ]; then
  101 + CLIENT_PREFIX=$client_prefix
  102 +fi
  103 +
  104 +if [ -z "$client_start" ]; then
  105 + client_start=0
  106 +fi
  107 +
  108 +if [ -z "$client_finish" ]; then
  109 + client_finish=1
  110 +fi
  111 +
  112 +if [ -n "$client_alias" ]; then
  113 + CLIENT_ALIAS=$client_alias
  114 +fi
  115 +
  116 +if [ -n "$bootstrap_alias" ]; then
  117 + BOOTSTRAP_ALIAS=$bootstrap_alias
  118 +fi
  119 +
  120 +if [ -n "$server_alias" ]; then
  121 + SERVER_ALIAS=$server_alias
  122 +fi
  123 +
  124 +if [ -n "$key_store_server_file" ]; then
  125 + SERVER_STORE=$key_store_server_file
  126 +fi
  127 +
  128 +if [ -n "$key_store_client_file" ]; then
  129 + CLIENT_STORE=$key_store_client_file
  130 +fi
  131 +
  132 +if [ -n "$client_key_store_pwd" ]; then
  133 + CLIENT_STORE_PWD=$client_key_store_pwd
  134 +fi
  135 +
  136 +if [ -n "$server_key_store_pwd" ]; then
  137 + SERVER_STORE_PWD=$server_key_store_pwd
  138 +fi
  139 +
  140 +echo "==Start=="
  141 +echo "CLIENT_PREFIX: $CLIENT_PREFIX"
  142 +echo "client_start: $client_start"
  143 +echo "client_finish: $client_finish"
  144 +echo "CLIENT_ALIAS: $CLIENT_ALIAS"
  145 +echo "BOOTSTRAP_ALIAS: $BOOTSTRAP_ALIAS"
  146 +echo "SERVER_ALIAS: $SERVER_ALIAS"
  147 +echo "SERVER_STORE: $SERVER_STORE"
  148 +echo "CLIENT_STORE: $CLIENT_STORE"
  149 +echo "CLIENT_STORE_PWD: $CLIENT_STORE_PWD"
  150 +echo "SERVER_STORE_PWD: $SERVER_STORE_PWD"
  151 +
  152 +end_point() {
  153 + echo "$CLIENT_PREFIX$(printf "%08d" $CLIENT_NUMBER)"
  154 +}
  155 +client_alias_point() {
  156 + echo "$CLIENT_ALIAS$(printf "%08d" $CLIENT_NUMBER)"
  157 +}
  158 +
24 # Generation of the keystore. 159 # Generation of the keystore.
25 echo "${H0}====START========${RESET}" 160 echo "${H0}====START========${RESET}"
26 echo "${H1}Server Keystore : ${RESET}" 161 echo "${H1}Server Keystore : ${RESET}"
@@ -55,7 +190,7 @@ keytool \ @@ -55,7 +190,7 @@ keytool \
55 -exportcert \ 190 -exportcert \
56 -alias $SERVER_ALIAS \ 191 -alias $SERVER_ALIAS \
57 -keystore $SERVER_STORE \ 192 -keystore $SERVER_STORE \
58 - -storepass $SERVER_STORE_PWD | \ 193 + -storepass $SERVER_STORE_PWD |
59 keytool \ 194 keytool \
60 -importcert \ 195 -importcert \
61 -alias $SERVER_SELF_ALIAS \ 196 -alias $SERVER_SELF_ALIAS \
@@ -70,22 +205,22 @@ keytool \ @@ -70,22 +205,22 @@ keytool \
70 -alias $SERVER_ALIAS \ 205 -alias $SERVER_ALIAS \
71 -dname "CN=$SERVER_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \ 206 -dname "CN=$SERVER_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
72 -keystore $SERVER_STORE \ 207 -keystore $SERVER_STORE \
73 - -storepass $SERVER_STORE_PWD | \ 208 + -storepass $SERVER_STORE_PWD |
74 keytool \ 209 keytool \
75 -gencert \ 210 -gencert \
76 -alias $ROOT_KEY_ALIAS \ 211 -alias $ROOT_KEY_ALIAS \
77 -keystore $SERVER_STORE \ 212 -keystore $SERVER_STORE \
78 -storepass $SERVER_STORE_PWD \ 213 -storepass $SERVER_STORE_PWD \
79 -storetype $STORETYPE \ 214 -storetype $STORETYPE \
80 - -validity $VALIDITY | \  
81 - keytool \  
82 - -importcert \  
83 - -alias $SERVER_ALIAS \  
84 - -keystore $SERVER_STORE \  
85 - -storepass $SERVER_STORE_PWD 215 + -validity $VALIDITY |
  216 + keytool \
  217 + -importcert \
  218 + -alias $SERVER_ALIAS \
  219 + -keystore $SERVER_STORE \
  220 + -storepass $SERVER_STORE_PWD
86 221
87 echo 222 echo
88 -echo "${H2}Creating server key and self-signed certificate ...${RESET}" 223 +echo "${H2}Creating bootstrap key and self-signed certificate ...${RESET}"
89 keytool \ 224 keytool \
90 -genkeypair \ 225 -genkeypair \
91 -alias $BOOTSTRAP_ALIAS \ 226 -alias $BOOTSTRAP_ALIAS \
@@ -100,7 +235,7 @@ keytool \ @@ -100,7 +235,7 @@ keytool \
100 -exportcert \ 235 -exportcert \
101 -alias $BOOTSTRAP_ALIAS \ 236 -alias $BOOTSTRAP_ALIAS \
102 -keystore $SERVER_STORE \ 237 -keystore $SERVER_STORE \
103 - -storepass $SERVER_STORE_PWD | \ 238 + -storepass $SERVER_STORE_PWD |
104 keytool \ 239 keytool \
105 -importcert \ 240 -importcert \
106 -alias $BOOTSTRAP_SELF_ALIAS \ 241 -alias $BOOTSTRAP_SELF_ALIAS \
@@ -115,54 +250,53 @@ keytool \ @@ -115,54 +250,53 @@ keytool \
115 -alias $BOOTSTRAP_ALIAS \ 250 -alias $BOOTSTRAP_ALIAS \
116 -dname "CN=$BOOTSTRAP_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \ 251 -dname "CN=$BOOTSTRAP_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
117 -keystore $SERVER_STORE \ 252 -keystore $SERVER_STORE \
118 - -storepass $SERVER_STORE_PWD | \ 253 + -storepass $SERVER_STORE_PWD |
119 keytool \ 254 keytool \
120 -gencert \ 255 -gencert \
121 -alias $ROOT_KEY_ALIAS \ 256 -alias $ROOT_KEY_ALIAS \
122 -keystore $SERVER_STORE \ 257 -keystore $SERVER_STORE \
123 -storepass $SERVER_STORE_PWD \ 258 -storepass $SERVER_STORE_PWD \
124 -storetype $STORETYPE \ 259 -storetype $STORETYPE \
125 - -validity $VALIDITY | \  
126 - keytool \  
127 - -importcert \  
128 - -alias $BOOTSTRAP_ALIAS \  
129 - -keystore $SERVER_STORE \  
130 - -storepass $SERVER_STORE_PWD  
131 - 260 + -validity $VALIDITY |
  261 + keytool \
  262 + -importcert \
  263 + -alias $BOOTSTRAP_ALIAS \
  264 + -keystore $SERVER_STORE \
  265 + -storepass $SERVER_STORE_PWD
132 266
133 echo 267 echo
134 echo "${H1}Client Keystore : ${RESET}" 268 echo "${H1}Client Keystore : ${RESET}"
135 echo "${H1}==================${RESET}" 269 echo "${H1}==================${RESET}"
136 -echo "${H2}Creating client key and self-signed certificate with expected CN...${RESET}"  
137 -keytool \  
138 - -genkeypair \  
139 - -alias $CLIENT_ALIAS \  
140 - -keyalg EC \  
141 - -dname "CN=$CLIENT_SELF_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \  
142 - -validity $VALIDITY \  
143 - -storetype $STORETYPE \  
144 - -keypass $CLIENT_STORE_PWD \  
145 - -keystore $CLIENT_STORE \  
146 - -storepass $CLIENT_STORE_PWD  
147 -keytool \  
148 - -exportcert \  
149 - -alias $CLIENT_ALIAS \  
150 - -keystore $CLIENT_STORE \  
151 - -storepass $CLIENT_STORE_PWD | \  
152 - keytool \  
153 - -importcert \  
154 - -alias $CLIENT_SELF_ALIAS \  
155 - -keystore $CLIENT_STORE \  
156 - -storepass $CLIENT_STORE_PWD \  
157 - -noprompt 270 +#echo "${H2}Creating client key and self-signed certificate with expected CN...${RESET}"
  271 +#keytool \
  272 +# -genkeypair \
  273 +# -alias $CLIENT_ALIAS \
  274 +# -keyalg EC \
  275 +# -dname "CN=$CLIENT_SELF_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
  276 +# -validity $VALIDITY \
  277 +# -storetype $STORETYPE \
  278 +# -keypass $CLIENT_STORE_PWD \
  279 +# -keystore $CLIENT_STORE \
  280 +# -storepass $CLIENT_STORE_PWD
  281 +#keytool \
  282 +# -exportcert \
  283 +# -alias $CLIENT_ALIAS \
  284 +# -keystore $CLIENT_STORE \
  285 +# -storepass $CLIENT_STORE_PWD | \
  286 +# keytool \
  287 +# -importcert \
  288 +# -alias $CLIENT_SELF_ALIAS \
  289 +# -keystore $CLIENT_STORE \
  290 +# -storepass $CLIENT_STORE_PWD \
  291 +# -noprompt
158 292
159 echo 293 echo
160 -echo "${H2}Import root certificate just to be able to import ned by root CA with expected CN...${RESET}" 294 +echo "${H2}Import root certificate just to be able to import need by root CA with expected CN...${RESET}"
161 keytool \ 295 keytool \
162 -exportcert \ 296 -exportcert \
163 -alias $ROOT_KEY_ALIAS \ 297 -alias $ROOT_KEY_ALIAS \
164 -keystore $SERVER_STORE \ 298 -keystore $SERVER_STORE \
165 - -storepass $SERVER_STORE_PWD | \ 299 + -storepass $SERVER_STORE_PWD |
166 keytool \ 300 keytool \
167 -importcert \ 301 -importcert \
168 -alias $ROOT_KEY_ALIAS \ 302 -alias $ROOT_KEY_ALIAS \
@@ -170,27 +304,85 @@ keytool \ @@ -170,27 +304,85 @@ keytool \
170 -storepass $CLIENT_STORE_PWD \ 304 -storepass $CLIENT_STORE_PWD \
171 -noprompt 305 -noprompt
172 306
173 -echo  
174 -echo "${H2}Creating client certificate signed by root CA with expected CN...${RESET}"  
175 -keytool \  
176 - -certreq \  
177 - -alias $CLIENT_ALIAS \  
178 - -dname "CN=$CLIENT_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \  
179 - -keystore $CLIENT_STORE \  
180 - -storepass $CLIENT_STORE_PWD | \ 307 +#echo
  308 +#echo "${H2}Creating client certificate signed by root CA with expected CN...${RESET}"
  309 +#keytool \
  310 +# -certreq \
  311 +# -alias $CLIENT_ALIAS \
  312 +# -dname "CN=$CLIENT_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
  313 +# -keystore $CLIENT_STORE \
  314 +# -storepass $CLIENT_STORE_PWD | \
  315 +# keytool \
  316 +# -gencert \
  317 +# -alias $ROOT_KEY_ALIAS \
  318 +# -keystore $SERVER_STORE \
  319 +# -storepass $SERVER_STORE_PWD \
  320 +# -storetype $STORETYPE \
  321 +# -validity $VALIDITY | \
  322 +# keytool \
  323 +# -importcert \
  324 +# -alias $CLIENT_ALIAS \
  325 +# -keystore $CLIENT_STORE \
  326 +# -storepass $CLIENT_STORE_PWD \
  327 +# -noprompt
  328 +
  329 +cert_end_point() {
  330 + echo "${H2}Creating client key and self-signed certificate with expected CN $CLIENT_SELF_CN ${RESET}"
181 keytool \ 331 keytool \
182 - -gencert \  
183 - -alias $ROOT_KEY_ALIAS \  
184 - -keystore $SERVER_STORE \  
185 - -storepass $SERVER_STORE_PWD \ 332 + -genkeypair \
  333 + -alias $CLIENT_CN_ALIAS \
  334 + -keyalg EC \
  335 + -dname "CN=$CLIENT_SELF_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
  336 + -validity $VALIDITY \
186 -storetype $STORETYPE \ 337 -storetype $STORETYPE \
187 - -validity $VALIDITY | \ 338 + -keypass $CLIENT_STORE_PWD \
  339 + -keystore $CLIENT_STORE \
  340 + -storepass $CLIENT_STORE_PWD
  341 + keytool \
  342 + -exportcert \
  343 + -alias $CLIENT_CN_ALIAS \
  344 + -keystore $CLIENT_STORE \
  345 + -storepass $CLIENT_STORE_PWD |
  346 + keytool \
  347 + -importcert \
  348 + -alias $CLIENT_SELF_ALIAS \
  349 + -keystore $CLIENT_STORE \
  350 + -storepass $CLIENT_STORE_PWD \
  351 + -noprompt
  352 +
  353 + echo
  354 + echo "${H2}Creating client certificate signed by root CA with expected $CLIENT_CN_NAME ${RESET}"
  355 + keytool \
  356 + -certreq \
  357 + -alias $CLIENT_CN_ALIAS \
  358 + -dname "CN=$CLIENT_CN_NAME, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
  359 + -keystore $CLIENT_STORE \
  360 + -storepass $CLIENT_STORE_PWD |
  361 + keytool \
  362 + -gencert \
  363 + -alias $ROOT_KEY_ALIAS \
  364 + -keystore $SERVER_STORE \
  365 + -storepass $SERVER_STORE_PWD \
  366 + -storetype $STORETYPE \
  367 + -validity $VALIDITY |
188 keytool \ 368 keytool \
189 -importcert \ 369 -importcert \
190 - -alias $CLIENT_ALIAS \ 370 + -alias $CLIENT_CN_ALIAS \
191 -keystore $CLIENT_STORE \ 371 -keystore $CLIENT_STORE \
192 -storepass $CLIENT_STORE_PWD \ 372 -storepass $CLIENT_STORE_PWD \
193 -noprompt 373 -noprompt
  374 +}
  375 +
  376 +while [ "$CLIENT_NUMBER" != "$client_finish" ]; do
  377 + CLIENT_CN_NAME=$(end_point)
  378 + CLIENT_CN_ALIAS=$(client_alias_point)
  379 + echo "$CLIENT_CN_NAME"
  380 + echo "$CLIENT_CN_ALIAS"
  381 + cert_end_point
  382 + CLIENT_NUMBER=$(($CLIENT_NUMBER + 1))
  383 + echo "number $CLIENT_NUMBER"
  384 + echo "finish $client_finish"
  385 +done
194 386
195 echo 387 echo
196 echo "${H0}!!! Warning ${H2}Migrate ${H1}${SERVER_STORE} ${H2}to ${H1}PKCS12 ${H2}which is an industry standard format..${RESET}" 388 echo "${H0}!!! Warning ${H2}Migrate ${H1}${SERVER_STORE} ${H2}to ${H1}PKCS12 ${H2}which is an industry standard format..${RESET}"
@@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
17 # Keystore common parameters 17 # Keystore common parameters
18 ROOT_KEY_ALIAS=rootCA 18 ROOT_KEY_ALIAS=rootCA
19 DOMAIN_SUFFIX="$(hostname)" 19 DOMAIN_SUFFIX="$(hostname)"
20 -ROOT_CN="$DOMAIN_SUFFIX rootCA" 20 +ROOT_CN="$DOMAIN_SUFFIX $ROOT_KEY_ALIAS"
21 ORGANIZATIONAL_UNIT=Thingsboard 21 ORGANIZATIONAL_UNIT=Thingsboard
22 ORGANIZATION=Thingsboard 22 ORGANIZATION=Thingsboard
23 CITY=SF 23 CITY=SF
@@ -27,23 +27,22 @@ VALIDITY=36500 #days @@ -27,23 +27,22 @@ VALIDITY=36500 #days
27 STORETYPE="JKS" 27 STORETYPE="JKS"
28 28
29 #Server 29 #Server
30 -SERVER_STORE=serverKeyStore.jks  
31 -SERVER_STORE_PWD=server_ks_password  
32 -SERVER_ALIAS=server 30 +SERVER_STORE=serverKeyStore1.jks
  31 +SERVER_STORE_PWD=server_ks_password1
  32 +SERVER_ALIAS=server1
33 SERVER_CN="$DOMAIN_SUFFIX server LwM2M signed by root CA" 33 SERVER_CN="$DOMAIN_SUFFIX server LwM2M signed by root CA"
34 SERVER_SELF_ALIAS=server_self_signed 34 SERVER_SELF_ALIAS=server_self_signed
35 SERVER_SELF_CN="$DOMAIN_SUFFIX server LwM2M self-signed" 35 SERVER_SELF_CN="$DOMAIN_SUFFIX server LwM2M self-signed"
36 -BOOTSTRAP_ALIAS=bootstrap 36 +BOOTSTRAP_ALIAS=bootstrap1
37 BOOTSTRAP_CN="$DOMAIN_SUFFIX bootstrap server LwM2M signed by root CA" 37 BOOTSTRAP_CN="$DOMAIN_SUFFIX bootstrap server LwM2M signed by root CA"
38 BOOTSTRAP_SELF_ALIAS=bootstrap_self_signed 38 BOOTSTRAP_SELF_ALIAS=bootstrap_self_signed
39 BOOTSTRAP_SELF_CN="$DOMAIN_SUFFIX bootstrap server LwM2M self-signed" 39 BOOTSTRAP_SELF_CN="$DOMAIN_SUFFIX bootstrap server LwM2M self-signed"
40 40
41 # Client 41 # Client
42 -CLIENT_STORE=clientKeyStore.jks  
43 -CLIENT_STORE_PWD=client_ks_password  
44 -CLIENT_ALIAS=client  
45 -#CLIENT_CN=client_lwm2m_x509  
46 -CLIENT_CN=LwX50900000000 42 +CLIENT_STORE=clientKeyStore1.jks
  43 +CLIENT_STORE_PWD=client_ks_password1
  44 +CLIENT_ALIAS=client_alias_1
  45 +CLIENT_PREFIX=LwX509_
47 CLIENT_SELF_ALIAS=client_self_signed 46 CLIENT_SELF_ALIAS=client_self_signed
48 CLIENT_SELF_CN="$DOMAIN_SUFFIX client LwM2M self-signed" 47 CLIENT_SELF_CN="$DOMAIN_SUFFIX client LwM2M self-signed"
49 48
  1 +#!/bin/bash
  2 +#
  3 +# Copyright © 2016-2020 The Thingsboard Authors
  4 +#
  5 +# Licensed under the Apache License, Version 2.0 (the "License");
  6 +# you may not use this file except in compliance with the License.
  7 +# You may obtain a copy of the License at
  8 +#
  9 +# http://www.apache.org/licenses/LICENSE-2.0
  10 +#
  11 +# Unless required by applicable law or agreed to in writing, software
  12 +# distributed under the License is distributed on an "AS IS" BASIS,
  13 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14 +# See the License for the specific language governing permissions and
  15 +# limitations under the License.
  16 +#
  17 +
  18 +#p) CLIENT_CN=LwX50900000000
  19 +#s) client_start=0
  20 +#f) client_finish=1
  21 +#a) CLIENT_ALIAS=client_alias_00000000
  22 +#b) BOOTSTRAP_ALIAS=bootstrap
  23 +#d) SERVER_ALIAS=server
  24 +#j) SERVER_STORE=serverKeyStore.jks
  25 +#k) CLIENT_STORE=clientKeyStore.jks
  26 +#c) CLIENT_STORE_PWD=client_ks_password
  27 +#w) SERVER_STORE_PWD=server_ks_password
  28 +
  29 +#while test $# -gt 0; do
  30 +# case "$1" in
  31 +# -h|--help)
  32 +# echo "$package - attempt to capture frames"
  33 +# echo " "
  34 +# echo "$package [options] application [arguments]"
  35 +# echo " "
  36 +# echo "options:"
  37 +# echo "-h, --help show brief help"
  38 +# echo "-a, --action=ACTION specify an action to use"
  39 +# echo "-o, --output-dir=DIR specify a directory to store output in"
  40 +# exit 0
  41 +# ;;
  42 +# -a)
  43 +# shift
  44 +# if test $# -gt 0; then
  45 +# export PROCESS=$1
  46 +# else
  47 +# echo "no process specified"
  48 +# exit 1
  49 +# fi
  50 +# shift
  51 +# ;;
  52 +# --action*)
  53 +# export PROCESS=`echo $1 | sed -e 's/^[^=]*=//g'`
  54 +# shift
  55 +# ;;
  56 +# -o)
  57 +# shift
  58 +# if test $# -gt 0; then
  59 +# export OUTPUT=$1
  60 +# else
  61 +# echo "no output dir specified"
  62 +# exit 1
  63 +# fi
  64 +# shift
  65 +# ;;
  66 +# --output-dir*)
  67 +# export OUTPUT=`echo $1 | sed -e 's/^[^=]*=//g'`
  68 +# shift
  69 +# ;;
  70 +# *)
  71 +# break
  72 +# ;;
  73 +# esac
  74 +#done
  75 +
  76 +
  77 +while getopts p:s:f:a:b:d:j:k:c:w: flag; do
  78 + case "${flag}" in
  79 + p) client_prefix=${OPTARG} ;;
  80 + s) client_start=${OPTARG} ;;
  81 + f) client_finish=${OPTARG} ;;
  82 + a) client_alias=${OPTARG} ;;
  83 + b) bootstrap_alias=${OPTARG} ;;
  84 + d) server_alias=${OPTARG} ;;
  85 + j) key_store_server_file=${OPTARG} ;;
  86 + k) key_store_client_file=${OPTARG} ;;
  87 + c) client_key_store_pwd=${OPTARG} ;;
  88 + w) server_key_store_pwd=${OPTARG} ;;
  89 + esac
  90 +done
  91 +
  92 +# cd to dir of script
  93 +script_dir=$(dirname $0)
  94 +echo "script_dir: $script_dir"
  95 +cd $script_dir
  96 +# source the properties:
  97 +. ./lwM2M_keygen.properties
  98 +
  99 +
  100 +if [ -n "$client_prefix" ]; then
  101 + CLIENT_PREFIX=$client_prefix
  102 +fi
  103 +
  104 +if [ -z "$client_start" ]; then
  105 + client_start=0
  106 +fi
  107 +
  108 +if [ -z "$client_finish" ]; then
  109 + client_finish=1
  110 +fi
  111 +
  112 +if [ -n "$client_alias" ]; then
  113 + CLIENT_ALIAS=$client_alias
  114 +fi
  115 +
  116 +if [ -n "$bootstrap_alias" ]; then
  117 + BOOTSTRAP_ALIAS=$bootstrap_alias
  118 +fi
  119 +
  120 +if [ -n "$server_alias" ]; then
  121 + SERVER_ALIAS=$server_alias
  122 +fi
  123 +
  124 +if [ -n "$key_store_server_file" ]; then
  125 + SERVER_STORE=$key_store_server_file
  126 +fi
  127 +
  128 +if [ -n "$key_store_client_file" ]; then
  129 + CLIENT_STORE=$key_store_client_file
  130 +fi
  131 +
  132 +if [ -n "$client_key_store_pwd" ]; then
  133 + CLIENT_STORE_PWD=$client_key_store_pwd
  134 +fi
  135 +
  136 +if [ -n "$server_key_store_pwd" ]; then
  137 + SERVER_STORE_PWD=$server_key_store_pwd
  138 +fi
  139 +
  140 +echo "==Start=="
  141 +echo "CLIENT_PREFIX: $CLIENT_PREFIX"
  142 +echo "client_start: $client_start"
  143 +echo "client_finish: $client_finish"
  144 +echo "CLIENT_ALIAS: $CLIENT_ALIAS"
  145 +echo "BOOTSTRAP_ALIAS: $BOOTSTRAP_ALIAS"
  146 +echo "SERVER_ALIAS: $SERVER_ALIAS"
  147 +echo "SERVER_STORE: $SERVER_STORE"
  148 +echo "CLIENT_STORE: $CLIENT_STORE"
  149 +echo "CLIENT_STORE_PWD: $CLIENT_STORE_PWD"
  150 +echo "SERVER_STORE_PWD: $SERVER_STORE_PWD"
  151 +
  152 +end_point() {
  153 + echo "$CLIENT_PREFIX$(printf "%08d" $CLIENT_NUMBER)"
  154 +}
  155 +client_alias_point() {
  156 + echo "$CLIENT_ALIAS$(printf "%08d" $CLIENT_NUMBER)"
  157 +}
  158 +
  159 +# Generation of the keystore.
  160 +echo "${H0}====START========${RESET}"
  161 +echo "${H1}Server Keystore : ${RESET}"
  162 +echo "${H1}==================${RESET}"
  163 +echo "${H2}Creating the trusted root CA key and certificate...${RESET}"
  164 +# -keysize
  165 +# 1024 (when using -genkeypair)
  166 +keytool \
  167 + -genkeypair \
  168 + -alias $ROOT_KEY_ALIAS \
  169 + -keyalg EC \
  170 + -dname "CN=$ROOT_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
  171 + -validity $VALIDITY \
  172 + -storetype $STORETYPE \
  173 + -keypass $SERVER_STORE_PWD \
  174 + -keystore $SERVER_STORE \
  175 + -storepass $SERVER_STORE_PWD
  176 +
  177 +echo
  178 +echo "${H2}Creating server key and self-signed certificate ...${RESET}"
  179 +keytool \
  180 + -genkeypair \
  181 + -alias $SERVER_ALIAS \
  182 + -keyalg EC \
  183 + -dname "CN=$SERVER_SELF_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
  184 + -validity $VALIDITY \
  185 + -storetype $STORETYPE \
  186 + -keypass $SERVER_STORE_PWD \
  187 + -keystore $SERVER_STORE \
  188 + -storepass $SERVER_STORE_PWD
  189 +keytool \
  190 + -exportcert \
  191 + -alias $SERVER_ALIAS \
  192 + -keystore $SERVER_STORE \
  193 + -storepass $SERVER_STORE_PWD |
  194 + keytool \
  195 + -importcert \
  196 + -alias $SERVER_SELF_ALIAS \
  197 + -keystore $SERVER_STORE \
  198 + -storepass $SERVER_STORE_PWD \
  199 + -noprompt
  200 +
  201 +echo
  202 +echo "${H2}Creating server certificate signed by root CA...${RESET}"
  203 +keytool \
  204 + -certreq \
  205 + -alias $SERVER_ALIAS \
  206 + -dname "CN=$SERVER_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
  207 + -keystore $SERVER_STORE \
  208 + -storepass $SERVER_STORE_PWD |
  209 + keytool \
  210 + -gencert \
  211 + -alias $ROOT_KEY_ALIAS \
  212 + -keystore $SERVER_STORE \
  213 + -storepass $SERVER_STORE_PWD \
  214 + -storetype $STORETYPE \
  215 + -validity $VALIDITY |
  216 + keytool \
  217 + -importcert \
  218 + -alias $SERVER_ALIAS \
  219 + -keystore $SERVER_STORE \
  220 + -storepass $SERVER_STORE_PWD
  221 +
  222 +echo
  223 +echo "${H2}Creating bootstrap key and self-signed certificate ...${RESET}"
  224 +keytool \
  225 + -genkeypair \
  226 + -alias $BOOTSTRAP_ALIAS \
  227 + -keyalg EC \
  228 + -dname "CN=$BOOTSTRAP_SELF_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
  229 + -validity $VALIDITY \
  230 + -storetype $STORETYPE \
  231 + -keypass $SERVER_STORE_PWD \
  232 + -keystore $SERVER_STORE \
  233 + -storepass $SERVER_STORE_PWD
  234 +keytool \
  235 + -exportcert \
  236 + -alias $BOOTSTRAP_ALIAS \
  237 + -keystore $SERVER_STORE \
  238 + -storepass $SERVER_STORE_PWD |
  239 + keytool \
  240 + -importcert \
  241 + -alias $BOOTSTRAP_SELF_ALIAS \
  242 + -keystore $SERVER_STORE \
  243 + -storepass $SERVER_STORE_PWD \
  244 + -noprompt
  245 +
  246 +echo
  247 +echo "${H2}Creating bootstrap certificate signed by root CA...${RESET}"
  248 +keytool \
  249 + -certreq \
  250 + -alias $BOOTSTRAP_ALIAS \
  251 + -dname "CN=$BOOTSTRAP_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
  252 + -keystore $SERVER_STORE \
  253 + -storepass $SERVER_STORE_PWD |
  254 + keytool \
  255 + -gencert \
  256 + -alias $ROOT_KEY_ALIAS \
  257 + -keystore $SERVER_STORE \
  258 + -storepass $SERVER_STORE_PWD \
  259 + -storetype $STORETYPE \
  260 + -validity $VALIDITY |
  261 + keytool \
  262 + -importcert \
  263 + -alias $BOOTSTRAP_ALIAS \
  264 + -keystore $SERVER_STORE \
  265 + -storepass $SERVER_STORE_PWD
  266 +
  267 +echo
  268 +echo "${H1}Client Keystore : ${RESET}"
  269 +echo "${H1}==================${RESET}"
  270 +#echo "${H2}Creating client key and self-signed certificate with expected CN...${RESET}"
  271 +#keytool \
  272 +# -genkeypair \
  273 +# -alias $CLIENT_ALIAS \
  274 +# -keyalg EC \
  275 +# -dname "CN=$CLIENT_SELF_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
  276 +# -validity $VALIDITY \
  277 +# -storetype $STORETYPE \
  278 +# -keypass $CLIENT_STORE_PWD \
  279 +# -keystore $CLIENT_STORE \
  280 +# -storepass $CLIENT_STORE_PWD
  281 +#keytool \
  282 +# -exportcert \
  283 +# -alias $CLIENT_ALIAS \
  284 +# -keystore $CLIENT_STORE \
  285 +# -storepass $CLIENT_STORE_PWD | \
  286 +# keytool \
  287 +# -importcert \
  288 +# -alias $CLIENT_SELF_ALIAS \
  289 +# -keystore $CLIENT_STORE \
  290 +# -storepass $CLIENT_STORE_PWD \
  291 +# -noprompt
  292 +
  293 +echo
  294 +echo "${H2}Import root certificate just to be able to import need by root CA with expected CN...${RESET}"
  295 +keytool \
  296 + -exportcert \
  297 + -alias $ROOT_KEY_ALIAS \
  298 + -keystore $SERVER_STORE \
  299 + -storepass $SERVER_STORE_PWD |
  300 + keytool \
  301 + -importcert \
  302 + -alias $ROOT_KEY_ALIAS \
  303 + -keystore $CLIENT_STORE \
  304 + -storepass $CLIENT_STORE_PWD \
  305 + -noprompt
  306 +
  307 +#echo
  308 +#echo "${H2}Creating client certificate signed by root CA with expected CN...${RESET}"
  309 +#keytool \
  310 +# -certreq \
  311 +# -alias $CLIENT_ALIAS \
  312 +# -dname "CN=$CLIENT_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
  313 +# -keystore $CLIENT_STORE \
  314 +# -storepass $CLIENT_STORE_PWD | \
  315 +# keytool \
  316 +# -gencert \
  317 +# -alias $ROOT_KEY_ALIAS \
  318 +# -keystore $SERVER_STORE \
  319 +# -storepass $SERVER_STORE_PWD \
  320 +# -storetype $STORETYPE \
  321 +# -validity $VALIDITY | \
  322 +# keytool \
  323 +# -importcert \
  324 +# -alias $CLIENT_ALIAS \
  325 +# -keystore $CLIENT_STORE \
  326 +# -storepass $CLIENT_STORE_PWD \
  327 +# -noprompt
  328 +
  329 +cert_end_point() {
  330 + echo "${H2}Creating client key and self-signed certificate with expected CN $CLIENT_SELF_CN ${RESET}"
  331 + keytool \
  332 + -genkeypair \
  333 + -alias $CLIENT_CN_ALIAS \
  334 + -keyalg EC \
  335 + -dname "CN=$CLIENT_SELF_CN, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
  336 + -validity $VALIDITY \
  337 + -storetype $STORETYPE \
  338 + -keypass $CLIENT_STORE_PWD \
  339 + -keystore $CLIENT_STORE \
  340 + -storepass $CLIENT_STORE_PWD
  341 + keytool \
  342 + -exportcert \
  343 + -alias $CLIENT_CN_ALIAS \
  344 + -keystore $CLIENT_STORE \
  345 + -storepass $CLIENT_STORE_PWD |
  346 + keytool \
  347 + -importcert \
  348 + -alias $CLIENT_SELF_ALIAS \
  349 + -keystore $CLIENT_STORE \
  350 + -storepass $CLIENT_STORE_PWD \
  351 + -noprompt
  352 +
  353 + echo
  354 + echo "${H2}Creating client certificate signed by root CA with expected $CLIENT_CN_NAME ${RESET}"
  355 + keytool \
  356 + -certreq \
  357 + -alias $CLIENT_CN_ALIAS \
  358 + -dname "CN=$CLIENT_CN_NAME, OU=$ORGANIZATIONAL_UNIT, O=$ORGANIZATION, L=$CITY, ST=$STATE_OR_PROVINCE, C=$TWO_LETTER_COUNTRY_CODE" \
  359 + -keystore $CLIENT_STORE \
  360 + -storepass $CLIENT_STORE_PWD |
  361 + keytool \
  362 + -gencert \
  363 + -alias $ROOT_KEY_ALIAS \
  364 + -keystore $SERVER_STORE \
  365 + -storepass $SERVER_STORE_PWD \
  366 + -storetype $STORETYPE \
  367 + -validity $VALIDITY |
  368 + keytool \
  369 + -importcert \
  370 + -alias $CLIENT_CN_ALIAS \
  371 + -keystore $CLIENT_STORE \
  372 + -storepass $CLIENT_STORE_PWD \
  373 + -noprompt
  374 +}
  375 +
  376 +while [ "$CLIENT_NUMBER" != "$client_finish" ]; do
  377 + CLIENT_CN_NAME=$(end_point)
  378 + CLIENT_CN_ALIAS=$(client_alias_point)
  379 + echo "$CLIENT_CN_NAME"
  380 + echo "$CLIENT_CN_ALIAS"
  381 + cert_end_point
  382 + CLIENT_NUMBER=$(($CLIENT_NUMBER + 1))
  383 + echo "number $CLIENT_NUMBER"
  384 + echo "finish $client_finish"
  385 +done
  386 +
  387 +echo
  388 +echo "${H0}!!! Warning ${H2}Migrate ${H1}${SERVER_STORE} ${H2}to ${H1}PKCS12 ${H2}which is an industry standard format..${RESET}"
  389 +keytool \
  390 + -importkeystore \
  391 + -srckeystore $SERVER_STORE \
  392 + -destkeystore $SERVER_STORE \
  393 + -deststoretype pkcs12 \
  394 + -srcstorepass $SERVER_STORE_PWD
  395 +
  396 +echo
  397 +echo "${H0}!!! Warning ${H2}Migrate ${H1}${CLIENT_STORE} ${H2}to ${H1}PKCS12 ${H2}which is an industry standard format..${RESET}"
  398 +keytool \
  399 + -importkeystore \
  400 + -srckeystore $CLIENT_STORE \
  401 + -destkeystore $CLIENT_STORE \
  402 + -deststoretype pkcs12 \
  403 + -srcstorepass $CLIENT_STORE_PWD
  1 +#
  2 +# Copyright © 2016-2017 The Thingsboard Authors
  3 +#
  4 +# Licensed under the Apache License, Version 2.0 (the "License");
  5 +# you may not use this file except in compliance with the License.
  6 +# You may obtain a copy of the License at
  7 +#
  8 +# http://www.apache.org/licenses/LICENSE-2.0
  9 +#
  10 +# Unless required by applicable law or agreed to in writing, software
  11 +# distributed under the License is distributed on an "AS IS" BASIS,
  12 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 +# See the License for the specific language governing permissions and
  14 +# limitations under the License.
  15 +#
  16 +
  17 +# Keystore common parameters
  18 +ROOT_KEY_ALIAS=rootCA
  19 +DOMAIN_SUFFIX="$(hostname)"
  20 +ROOT_CN="$DOMAIN_SUFFIX $ROOT_KEY_ALIAS"
  21 +ORGANIZATIONAL_UNIT=Thingsboard
  22 +ORGANIZATION=Thingsboard
  23 +CITY=SF
  24 +STATE_OR_PROVINCE=CA
  25 +TWO_LETTER_COUNTRY_CODE=US
  26 +VALIDITY=36500 #days
  27 +STORETYPE="JKS"
  28 +
  29 +#Server
  30 +SERVER_STORE=serverKeyStore1.jks
  31 +SERVER_STORE_PWD=server_ks_password1
  32 +SERVER_ALIAS=server1
  33 +SERVER_CN="$DOMAIN_SUFFIX server LwM2M signed by root CA"
  34 +SERVER_SELF_ALIAS=server_self_signed
  35 +SERVER_SELF_CN="$DOMAIN_SUFFIX server LwM2M self-signed"
  36 +BOOTSTRAP_ALIAS=bootstrap1
  37 +BOOTSTRAP_CN="$DOMAIN_SUFFIX bootstrap server LwM2M signed by root CA"
  38 +BOOTSTRAP_SELF_ALIAS=bootstrap_self_signed
  39 +BOOTSTRAP_SELF_CN="$DOMAIN_SUFFIX bootstrap server LwM2M self-signed"
  40 +
  41 +# Client
  42 +CLIENT_STORE=clientKeyStore1.jks
  43 +CLIENT_STORE_PWD=client_ks_password1
  44 +CLIENT_ALIAS=client_alias_1
  45 +CLIENT_PREFIX=LwX509_
  46 +CLIENT_SELF_ALIAS=client_self_signed
  47 +CLIENT_SELF_CN="$DOMAIN_SUFFIX client LwM2M self-signed"
  48 +
  49 +# Color output stuff
  50 +red=`tput setaf 1`
  51 +green=`tput setaf 2`
  52 +blue=`tput setaf 4`
  53 +bold=`tput bold`
  54 +H0=${red}${bold}
  55 +H1=${green}${bold}
  56 +H2=${blue}
  57 +RESET=`tput sgr0`
1 -<!--  
2 -  
3 - Copyright © 2016-2020 The Thingsboard Authors  
4 -  
5 - Licensed under the Apache License, Version 2.0 (the "License");  
6 - you may not use this file except in compliance with the License.  
7 - You may obtain a copy of the License at  
8 -  
9 - http://www.apache.org/licenses/LICENSE-2.0  
10 -  
11 - Unless required by applicable law or agreed to in writing, software  
12 - distributed under the License is distributed on an "AS IS" BASIS,  
13 - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
14 - See the License for the specific language governing permissions and  
15 - limitations under the License.  
16 -  
17 --->  
18 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
19 <!-- 2 <!--
20 FILE INFORMATION 3 FILE INFORMATION