Commit 044f2a204dcc9f9a7481e17a79c6f56a68786c20

Authored by Valerii Sosliuk
1 parent 3ffb970e

keygen scripts - input arguments and usage added

... ... @@ -15,8 +15,51 @@
15 15 # limitations under the License.
16 16 #
17 17
  18 +usage() {
  19 + echo "This script generates thingsboard server's ssl certificate"
  20 + echo "and optionally copies it to the server's resource directory."
  21 + echo "usage: ./keygen.sh [-c flag] [-d directory]"
  22 + echo " -c | --copy flag Set if copy keystore to server directory needed. Default value is true"
  23 + echo " -d | --dir directory Server keystore directory, where the generated keystore file will be copied."
  24 + echo " Default value is SERVER_KEYSTORE_DIR property from properties file"
  25 + echo " -p | --props | --properties file Properties file. default value is ./keygen.properties"
  26 + echo " -h | --help | ? Show this message"
  27 +}
18 28
19   -. keygen.properties
  29 +COPY=true;
  30 +COPY_DIR="d"
  31 +PROPERTIES_FILE=keygen.properties
  32 +
  33 +while true; do
  34 + case "$1" in
  35 + -c | --copy) COPY=$2 ;
  36 + shift
  37 + ;;
  38 + -d | --dir | --directory) COPY_DIR=$2 ;
  39 + shift
  40 + ;;
  41 + -p | --props | --properties) PROPERTIES_FILE=$2 ;
  42 + shift
  43 + ;;
  44 + -h | --help | ?) usage
  45 + exit 0
  46 + ;;
  47 + -- ) shift;
  48 + break
  49 + ;;
  50 + * ) break
  51 + ;;
  52 + esac
  53 + shift
  54 +done
  55 +
  56 +if [[ "$COPY" != true ]] && [[ "$COPY" != false ]]; then
  57 + usage
  58 +fi
  59 +
  60 +echo "copy: $COPY; copy_dir: $COPY_DIR; PROPERTIES_FILE=$PROPERTIES_FILE";
  61 +
  62 +. $PROPERTIES_FILE
20 63
21 64 echo "Generating SSL Key Pair..."
22 65
... ... @@ -30,29 +73,46 @@ keytool -genkeypair -v \
30 73 -keysize 2048 \
31 74 -validity 9999
32 75
  76 +status=$?
  77 +if [[ $status != 0 ]]; then
  78 + exit $status;
  79 +fi
  80 +
33 81 keytool -export \
34 82 -alias $SERVER_KEY_ALIAS \
35 83 -keystore $SERVER_FILE_PREFIX.jks \
36 84 -file $CLIENT_TRUSTSTORE -rfc \
37 85 -storepass $PASSWORD
38 86
39   -read -p "Do you want to copy $SERVER_FILE_PREFIX.jks to server directory? " yn
40   - case $yn in
41   - [Yy]) echo "Please, specify destination dir: "
42   - read -p "(Default: $SERVER_KEYSTORE_DIR): " dir
43   - if [[ ! -z $dir ]]; then
44   - DESTINATION=$dir;
45   - else
46   - DESTINATION=$SERVER_KEYSTORE_DIR
47   - fi;
48   - mkdir -p $SERVER_KEYSTORE_DIR
49   - cp $SERVER_FILE_PREFIX.jks $DESTINATION
50   - if [ $? -ne 0 ]; then
51   - echo "Failed to copy keystore file."
52   - else
53   - echo "File copied successfully."
54   - fi
55   - break;;
56   - * ) ;;
57   - esac
58   -echo "Done."
  87 +status=$?
  88 +if [[ $status != 0 ]]; then
  89 + exit $status;
  90 +fi
  91 +
  92 +
  93 +if [[ $COPY = true ]]; then
  94 + if [[ -z "$COPY_DIR" ]]; then
  95 + read -p "Do you want to copy $SERVER_FILE_PREFIX.jks to server directory? " yn
  96 + case $yn in
  97 + [Yy]) echo "Please, specify destination dir: "
  98 + read -p "(Default: copy_dir): " dir
  99 + if [[ ! -z $dir ]]; then
  100 + DESTINATION=$dir;
  101 + else
  102 + DESTINATION=$SERVER_KEYSTORE_DIR
  103 + fi;
  104 + break;;
  105 + * ) ;;
  106 + esac
  107 + else
  108 + DESTINATION=$COPY_DIR
  109 + fi
  110 + mkdir -p $DESTINATION
  111 + cp $SERVER_FILE_PREFIX.jks $DESTINATION
  112 + if [ $? -ne 0 ]; then
  113 + echo "Failed to copy keystore file."
  114 + else
  115 + echo "File copied successfully."
  116 + fi
  117 +fi
  118 +echo "Done."
\ No newline at end of file
... ...
... ... @@ -15,8 +15,34 @@
15 15 # limitations under the License.
16 16 #
17 17
  18 +usage() {
  19 + echo "This script generates client public/private rey pair, extracts them to a no-password RSA pem file,"
  20 + echo "and also imports server public key to client trust store"
  21 + echo "usage: ./securemqttclient.keygen.sh [-p file]"
  22 + echo " -p | --props | --properties file Properties file. default value is ./keygen.properties"
  23 + echo " -h | --help | ? Show this message"
  24 +}
18 25
19   -. keygen.properties
  26 +PROPERTIES_FILE=keygen.properties
  27 +
  28 +while true; do
  29 + case "$1" in
  30 + -p | --props | --properties) PROPERTIES_FILE=$2 ;
  31 + shift
  32 + ;;
  33 + -h | --help | ?) usage
  34 + exit 0
  35 + ;;
  36 + -- ) shift;
  37 + break
  38 + ;;
  39 + * ) break
  40 + ;;
  41 + esac
  42 + shift
  43 +done
  44 +
  45 +. $PROPERTIES_FILE
20 46
21 47 echo "Generating SSL Key Pair..."
22 48
... ...
1 1 /**
2 2 * Copyright © 2016-2017 The Thingsboard Authors
3   - * <p>
  3 + *
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
6 6 * You may obtain a copy of the License at
7   - * <p>
8   - * http://www.apache.org/licenses/LICENSE-2.0
9   - * <p>
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
10 10 * Unless required by applicable law or agreed to in writing, software
11 11 * distributed under the License is distributed on an "AS IS" BASIS,
12 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
... ...