Selaa lähdekoodia

Command for calculating DH params

Avoid duplication
Bob Mottram 9 vuotta sitten
vanhempi
commit
516519ba07
4 muutettua tiedostoa jossa 178 lisäystä ja 79 poistoa
  1. BIN
      man/freedombone-dhparam.1.gz
  2. 12
    16
      src/freedombone-addcert
  3. 117
    0
      src/freedombone-dhparam
  4. 49
    63
      src/freedombone-sec

BIN
man/freedombone-dhparam.1.gz Näytä tiedosto


+ 12
- 16
src/freedombone-addcert Näytä tiedosto

154
     cd $INSTALL_DIR
154
     cd $INSTALL_DIR
155
 
155
 
156
     # obtain the repo
156
     # obtain the repo
157
-    if [ ! -d $INSTALL_DIR/letsencrypt ]; then
157
+    if [ ! -d ${INSTALL_DIR}/letsencrypt ]; then
158
         git clone https://github.com/letsencrypt/letsencrypt
158
         git clone https://github.com/letsencrypt/letsencrypt
159
-        if [ ! -d $INSTALL_DIR/letsencrypt ]; then
159
+        if [ ! -d ${INSTALL_DIR}/letsencrypt ]; then
160
             exit 76283
160
             exit 76283
161
         fi
161
         fi
162
     else
162
     else
163
-        cd $INSTALL_DIR/letsencrypt
163
+        cd ${INSTALL_DIR}/letsencrypt
164
         git stash
164
         git stash
165
         git pull
165
         git pull
166
     fi
166
     fi
167
 
167
 
168
-    cd $INSTALL_DIR/letsencrypt
168
+    cd ${INSTALL_DIR}/letsencrypt
169
     # TODO this requires user interaction - is there a non-interactive mode?
169
     # TODO this requires user interaction - is there a non-interactive mode?
170
     ./letsencrypt-auto certonly --server $LETSENCRYPT_SERVER --standalone -d $LETSENCRYPT_HOSTNAME
170
     ./letsencrypt-auto certonly --server $LETSENCRYPT_SERVER --standalone -d $LETSENCRYPT_HOSTNAME
171
     if [ ! "$?" = "0" ]; then
171
     if [ ! "$?" = "0" ]; then
206
         CERTFILE="ca-$HOSTNAME"
206
         CERTFILE="ca-$HOSTNAME"
207
     fi
207
     fi
208
 
208
 
209
-    openssl req -x509 $EXTENSIONS -nodes -days 3650 -sha256 \
209
+    openssl req -x509 ${EXTENSIONS} -nodes -days 3650 -sha256 \
210
         -subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$HOSTNAME" \
210
         -subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$HOSTNAME" \
211
-        -newkey rsa:4096 -keyout /etc/ssl/private/$CERTFILE.key \
212
-        -out /etc/ssl/certs/$CERTFILE.crt
213
-    chmod 400 /etc/ssl/private/$CERTFILE.key
214
-    chmod 640 /etc/ssl/certs/$CERTFILE.crt
215
-    cp /etc/ssl/certs/$CERTFILE.crt /etc/ssl/mycerts
211
+        -newkey rsa:4096 -keyout /etc/ssl/private/${CERTFILE}.key \
212
+        -out /etc/ssl/certs/${CERTFILE}.crt
213
+    chmod 400 /etc/ssl/private/${CERTFILE}.key
214
+    chmod 640 /etc/ssl/certs/${CERTFILE}.crt
215
+    cp /etc/ssl/certs/${CERTFILE}.crt /etc/ssl/mycerts
216
 fi
216
 fi
217
 
217
 
218
 # generate DH params
218
 # generate DH params
219
 if [ ! $NODH ]; then
219
 if [ ! $NODH ]; then
220
-    if [ ! -f /etc/ssl/certs/$CERTFILE.dhparam ]; then
221
-        openssl dhparam -check -text -dsaparam $DH_KEYLENGTH -out /etc/ssl/certs/$CERTFILE.dhparam
222
-        if [ ! "$?" = "0" ]; then
223
-            exit 72428
224
-        fi
225
-        chmod 640 /etc/ssl/certs/$CERTFILE.dhparam
220
+    if [ ! -f /etc/ssl/certs/${CERTFILE}.dhparam ]; then
221
+        ${PROJECT_NAME}-dhparam -h ${CERTFILE}
226
     fi
222
     fi
227
 fi
223
 fi
228
 
224
 

+ 117
- 0
src/freedombone-dhparam Näytä tiedosto

1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# Creates or re-calculates Diffie-Hellman parameters
12
+
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU General Public License as published by
20
+# the Free Software Foundation, either version 3 of the License, or
21
+# (at your option) any later version.
22
+#
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+# GNU General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU General Public License
29
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
30
+
31
+PROJECT_NAME='freedombone'
32
+
33
+export TEXTDOMAIN=${PROJECT_NAME}-dhparam
34
+export TEXTDOMAINDIR="/usr/share/locale"
35
+
36
+HOSTNAME=
37
+KEYLENGTH=2048
38
+RECALCULATE="no"
39
+
40
+function show_help {
41
+    echo ''
42
+    echo $"${PROJECT_NAME}-dhparam -h [hostname] -l [length in bits] --recalc [yes|no]"
43
+    echo ''
44
+    exit 0
45
+}
46
+
47
+function calc_dh {
48
+    openssl dhparam -check -text -dsaparam $KEYLENGTH -out ${1}
49
+    if [ ! "$?" = "0" ]; then
50
+        exit 3674
51
+    fi
52
+    chmod 640 ${1}
53
+}
54
+
55
+function regenerate_dh_keys {
56
+    for file in /etc/ssl/mycerts/*
57
+    do
58
+        if [[ -f $file ]]; then
59
+            filename=/etc/ssl/certs/$(echo $file | awk -F '/etc/ssl/mycerts/' '{print $2}' | awk -F '.crt' '{print $1}').dhparam
60
+            if [ -f $filename ]; then
61
+                calc_dh $filename
62
+                echo $"Recalculated DH params for $filename"
63
+            fi
64
+        fi
65
+    done
66
+}
67
+
68
+while [[ $# > 1 ]]
69
+do
70
+key="$1"
71
+
72
+case $key in
73
+    --help)
74
+    show_help
75
+    ;;
76
+    -h|--hostname)
77
+    shift
78
+    HOSTNAME="$1"
79
+    ;;
80
+    -l|--dhkey)
81
+    shift
82
+    KEYLENGTH=${1}
83
+    ;;
84
+    --recalc)
85
+    shift
86
+    RECALCULATE=${1}
87
+    ;;
88
+    *)
89
+    # unknown option
90
+    ;;
91
+esac
92
+shift
93
+done
94
+
95
+if [[ $RECALCULATE == "yes" || $RECALCULATE == "y" ]]; then
96
+    regenerate_dh_keys
97
+    exit 0
98
+fi
99
+
100
+if [ ! $HOSTNAME ]; then
101
+    echo $'No hostname specified'
102
+    exit 5728
103
+fi
104
+
105
+if ! which openssl > /dev/null ;then
106
+    echo $"$0: openssl is not installed, exiting" 1>&2
107
+    exit 5689
108
+fi
109
+
110
+if [ ! -d /etc/ssl/mycerts ]; then
111
+    mkdir -p /etc/ssl/mycerts
112
+fi
113
+
114
+calc_dh /etc/ssl/certs/$HOSTNAME.dhparam
115
+
116
+systemctl reload nginx
117
+exit 0

+ 49
- 63
src/freedombone-sec Näytä tiedosto

225
   if [ $SSL_CIPHERS ]; then
225
   if [ $SSL_CIPHERS ]; then
226
       data=$(tempfile 2>/dev/null)
226
       data=$(tempfile 2>/dev/null)
227
       trap "rm -f $data" 0 1 2 5 15
227
       trap "rm -f $data" 0 1 2 5 15
228
-      dialog --backtitle "Freedombone Security Configuration" \
229
-          --form "\nWeb/IMAP Ciphers:" 10 95 2 \
230
-          "Protocols:" 1 1 "$SSL_PROTOCOLS" 1 15 90 90 \
231
-          "Ciphers:" 2 1 "$SSL_CIPHERS" 2 15 90 512 \
228
+      dialog --backtitle $"Freedombone Security Configuration" \
229
+          --form $"\nWeb/IMAP Ciphers:" 10 95 2 \
230
+          $"Protocols:" 1 1 "$SSL_PROTOCOLS" 1 15 90 90 \
231
+          $"Ciphers:" 2 1 "$SSL_CIPHERS" 2 15 90 512 \
232
           2> $data
232
           2> $data
233
       sel=$?
233
       sel=$?
234
       case $sel in
234
       case $sel in
242
   data=$(tempfile 2>/dev/null)
242
   data=$(tempfile 2>/dev/null)
243
   trap "rm -f $data" 0 1 2 5 15
243
   trap "rm -f $data" 0 1 2 5 15
244
   if [ $SSH_HOST_KEY_ALGORITHMS ]; then
244
   if [ $SSH_HOST_KEY_ALGORITHMS ]; then
245
-      dialog --backtitle "Freedombone Security Configuration" \
246
-        --form "\nSecure Shell Ciphers:" 13 95 4 \
247
-         "Ciphers:" 1 1 "$SSH_CIPHERS" 1 15 90 512 \
248
-         "MACs:" 2 1 "$SSH_MACS" 2 15 90 512 \
249
-         "KEX:" 3 1 "$SSH_KEX" 3 15 90 512 \
250
-         "Host key algorithms:" 4 1 "$SSH_HOST_KEY_ALGORITHMS" 4 15 90 512 \
245
+      dialog --backtitle $"Freedombone Security Configuration" \
246
+        --form $"\nSecure Shell Ciphers:" 13 95 4 \
247
+         $"Ciphers:" 1 1 "$SSH_CIPHERS" 1 15 90 512 \
248
+         $"MACs:" 2 1 "$SSH_MACS" 2 15 90 512 \
249
+         $"KEX:" 3 1 "$SSH_KEX" 3 15 90 512 \
250
+         $"Host key algorithms:" 4 1 "$SSH_HOST_KEY_ALGORITHMS" 4 15 90 512 \
251
          2> $data
251
          2> $data
252
       sel=$?
252
       sel=$?
253
       case $sel in
253
       case $sel in
259
           255) exit 0;;
259
           255) exit 0;;
260
       esac
260
       esac
261
   else
261
   else
262
-      dialog --backtitle "Freedombone Security Configuration" \
263
-        --form "\nSecure Shell Ciphers:" 11 95 3 \
264
-         "Ciphers:" 1 1 "$SSH_CIPHERS" 1 15 90 512 \
265
-         "MACs:" 2 1 "$SSH_MACS" 2 15 90 512 \
266
-         "KEX:" 3 1 "$SSH_KEX" 3 15 90 512 \
262
+      dialog --backtitle $"Freedombone Security Configuration" \
263
+        --form $"\nSecure Shell Ciphers:" 11 95 3 \
264
+         $"Ciphers:" 1 1 "$SSH_CIPHERS" 1 15 90 512 \
265
+         $"MACs:" 2 1 "$SSH_MACS" 2 15 90 512 \
266
+         $"KEX:" 3 1 "$SSH_KEX" 3 15 90 512 \
267
          2> $data
267
          2> $data
268
       sel=$?
268
       sel=$?
269
       case $sel in
269
       case $sel in
276
   fi
276
   fi
277
 
277
 
278
   if [[ $SSH_PASSWORDS == "yes" ]]; then
278
   if [[ $SSH_PASSWORDS == "yes" ]]; then
279
-      dialog --title "SSH Passwords" \
280
-          --backtitle "Freedombone Security Configuration" \
281
-          --yesno "\nAllow SSH login using passwords?" 7 60
279
+      dialog --title $"SSH Passwords" \
280
+          --backtitle $"Freedombone Security Configuration" \
281
+          --yesno $"\nAllow SSH login using passwords?" 7 60
282
   else
282
   else
283
-      dialog --title "SSH Passwords" \
284
-          --backtitle "Freedombone Security Configuration" \
283
+      dialog --title $"SSH Passwords" \
284
+          --backtitle $"Freedombone Security Configuration" \
285
           --defaultno \
285
           --defaultno \
286
-          --yesno "\nAllow SSH login using passwords?" 7 60
286
+          --yesno $"\nAllow SSH login using passwords?" 7 60
287
   fi
287
   fi
288
   sel=$?
288
   sel=$?
289
   case $sel in
289
   case $sel in
295
   if [ $XMPP_CIPHERS ]; then
295
   if [ $XMPP_CIPHERS ]; then
296
       data=$(tempfile 2>/dev/null)
296
       data=$(tempfile 2>/dev/null)
297
       trap "rm -f $data" 0 1 2 5 15
297
       trap "rm -f $data" 0 1 2 5 15
298
-      dialog --backtitle "Freedombone Security Configuration" \
299
-          --form "\nXMPP Ciphers:" 10 95 2 \
300
-          "Ciphers:" 1 1 "$XMPP_CIPHERS" 1 15 90 512 \
301
-          "ECC Curve:" 2 1 "$XMPP_ECC_CURVE" 2 15 50 50 \
298
+      dialog --backtitle $"Freedombone Security Configuration" \
299
+          --form $"\nXMPP Ciphers:" 10 95 2 \
300
+          $"Ciphers:" 1 1 "$XMPP_CIPHERS" 1 15 90 512 \
301
+          $"ECC Curve:" 2 1 "$XMPP_ECC_CURVE" 2 15 50 50 \
302
           2> $data
302
           2> $data
303
       sel=$?
303
       sel=$?
304
       case $sel in
304
       case $sel in
309
       esac
309
       esac
310
   fi
310
   fi
311
 
311
 
312
-  dialog --title "Final Confirmation" \
313
-      --backtitle "Freedombone Security Configuration" \
312
+  dialog --title $"Final Confirmation" \
313
+      --backtitle $"Freedombone Security Configuration" \
314
       --defaultno \
314
       --defaultno \
315
-      --yesno "\nPlease confirm that you wish your security settings to be changed?\n\nWARNING: any mistakes made in the security settings could compromise your system, so be extra careful when answering 'yes'." 12 60
315
+      --yesno $"\nPlease confirm that you wish your security settings to be changed?\n\nWARNING: any mistakes made in the security settings could compromise your system, so be extra careful when answering 'yes'." 12 60
316
   sel=$?
316
   sel=$?
317
   case $sel in
317
   case $sel in
318
       1) clear
318
       1) clear
365
           3) DH_KEYLENGTH=4096;;
365
           3) DH_KEYLENGTH=4096;;
366
       esac
366
       esac
367
 
367
 
368
-      ctr=0
369
-      for file in /etc/ssl/mycerts/*
370
-      do
371
-          if [[ -f $file ]]; then
372
-              filename=/etc/ssl/certs/$(echo $file | awk -F '/etc/ssl/mycerts/' '{print $2}' | awk -F '.crt' '{print $1}').dhparam
373
-              if [ -f $filename ]; then
374
-                  openssl dhparam -check -text -dsaparam $DH_KEYLENGTH -out $filename
375
-				  if [ ! "$?" = "0" ]; then
376
-					  exit 3674
377
-				  fi
378
-                  ctr=$((ctr + 1))
379
-              fi
380
-          fi
381
-      done
382
-      echo $"$ctr dhparam certificates were regenerated"
368
+	  ${PROJECT_NAME}-dhparam --recalc yes -l ${DH_KEYLENGTH}
383
   fi
369
   fi
384
 }
370
 }
385
 
371
 
387
   renew_domain=
373
   renew_domain=
388
   data=$(tempfile 2>/dev/null)
374
   data=$(tempfile 2>/dev/null)
389
   trap "rm -f $data" 0 1 2 5 15
375
   trap "rm -f $data" 0 1 2 5 15
390
-  dialog --title "Renew a StartSSL certificate" \
391
-         --backtitle "Freedombone Security Settings" \
392
-         --inputbox "Enter the domain name" 8 60 2>$data
376
+  dialog --title $"Renew a StartSSL certificate" \
377
+         --backtitle $"Freedombone Security Settings" \
378
+         --inputbox $"Enter the domain name" 8 60 2>$data
393
   sel=$?
379
   sel=$?
394
   case $sel in
380
   case $sel in
395
       0)
381
       0)
402
   fi
388
   fi
403
 
389
 
404
   if [[ $renew_domain == "http"* ]]; then
390
   if [[ $renew_domain == "http"* ]]; then
405
-      dialog --title "Renew a StartSSL certificate" \
406
-             --msgbox "Don't include the https://" 6 40
391
+      dialog --title $"Renew a StartSSL certificate" \
392
+             --msgbox $"Don't include the https://" 6 40
407
 	  return
393
 	  return
408
   fi
394
   fi
409
 
395
 
410
   if [ ! -f /etc/ssl/certs/${renew_domain}.dhparam ]; then
396
   if [ ! -f /etc/ssl/certs/${renew_domain}.dhparam ]; then
411
-      dialog --title "Renew a StartSSL certificate" \
412
-             --msgbox "An existing certificate for $renew_domain was not found" 6 40
397
+      dialog --title $"Renew a StartSSL certificate" \
398
+             --msgbox $"An existing certificate for $renew_domain was not found" 6 40
413
 	  return
399
 	  return
414
   fi
400
   fi
415
 
401
 
416
   if [[ $renew_domain != *"."* ]]; then
402
   if [[ $renew_domain != *"."* ]]; then
417
-      dialog --title "Renew a StartSSL certificate" \
418
-             --msgbox "Invalid domain name: $renew_domain" 6 40
403
+      dialog --title $"Renew a StartSSL certificate" \
404
+             --msgbox $"Invalid domain name: $renew_domain" 6 40
419
 	  return
405
 	  return
420
   fi
406
   fi
421
 
407
 
422
-  freedombone-renew-cert -h $renew_domain -p startssl
408
+  ${PROJECT_NAME}-renew-cert -h $renew_domain -p startssl
423
 
409
 
424
   exit 0
410
   exit 0
425
 }
411
 }
428
   renew_domain=
414
   renew_domain=
429
   data=$(tempfile 2>/dev/null)
415
   data=$(tempfile 2>/dev/null)
430
   trap "rm -f $data" 0 1 2 5 15
416
   trap "rm -f $data" 0 1 2 5 15
431
-  dialog --title "Renew a Let's Encrypt certificate" \
432
-         --backtitle "Freedombone Security Settings" \
433
-         --inputbox "Enter the domain name" 8 60 2>$data
417
+  dialog --title $"Renew a Let's Encrypt certificate" \
418
+         --backtitle $"Freedombone Security Settings" \
419
+         --inputbox $"Enter the domain name" 8 60 2>$data
434
   sel=$?
420
   sel=$?
435
   case $sel in
421
   case $sel in
436
       0)
422
       0)
443
   fi
429
   fi
444
 
430
 
445
   if [[ $renew_domain == "http"* ]]; then
431
   if [[ $renew_domain == "http"* ]]; then
446
-      dialog --title "Renew a Let's Encrypt certificate" \
447
-             --msgbox "Don't include the https://" 6 40
432
+      dialog --title $"Renew a Let's Encrypt certificate" \
433
+             --msgbox $"Don't include the https://" 6 40
448
 	  return
434
 	  return
449
   fi
435
   fi
450
 
436
 
451
   if [ ! -f /etc/ssl/certs/${renew_domain}.dhparam ]; then
437
   if [ ! -f /etc/ssl/certs/${renew_domain}.dhparam ]; then
452
-      dialog --title "Renew a Let's Encrypt certificate" \
453
-             --msgbox "An existing certificate for $renew_domain was not found" 6 40
438
+      dialog --title $"Renew a Let's Encrypt certificate" \
439
+             --msgbox $"An existing certificate for $renew_domain was not found" 6 40
454
 	  return
440
 	  return
455
   fi
441
   fi
456
 
442
 
457
   if [[ $renew_domain != *"."* ]]; then
443
   if [[ $renew_domain != *"."* ]]; then
458
-      dialog --title "Renew a Let's Encrypt certificate" \
459
-             --msgbox "Invalid domain name: $renew_domain" 6 40
444
+      dialog --title $"Renew a Let's Encrypt certificate" \
445
+             --msgbox $"Invalid domain name: $renew_domain" 6 40
460
 	  return
446
 	  return
461
   fi
447
   fi
462
 
448
 
463
-  freedombone-renew-cert -h $renew_domain -p 'letsencrypt'
449
+  ${PROJECT_NAME}-renew-cert -h $renew_domain -p 'letsencrypt'
464
 
450
 
465
   exit 0
451
   exit 0
466
 }
452
 }