Bladeren bron

Create a letsencrypt cert for a domain

Bob Mottram 9 jaren geleden
bovenliggende
commit
3fb7a127ad
1 gewijzigde bestanden met toevoegingen van 57 en 11 verwijderingen
  1. 57
    11
      src/freedombone-sec

+ 57
- 11
src/freedombone-sec Bestand weergeven

58
 REGENERATE_SSH_HOST_KEYS="no"
58
 REGENERATE_SSH_HOST_KEYS="no"
59
 REGENERATE_DH_KEYS="no"
59
 REGENERATE_DH_KEYS="no"
60
 DH_KEYLENGTH=2048
60
 DH_KEYLENGTH=2048
61
+LETSENCRYPT_SERVER='https://acme-v01.api.letsencrypt.org/directory'
61
 
62
 
62
 function get_protocols_from_website {
63
 function get_protocols_from_website {
63
   if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
64
   if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
365
           3) DH_KEYLENGTH=4096;;
366
           3) DH_KEYLENGTH=4096;;
366
       esac
367
       esac
367
 
368
 
368
-	  ${PROJECT_NAME}-dhparam --recalc yes -l ${DH_KEYLENGTH}
369
+      ${PROJECT_NAME}-dhparam --recalc yes -l ${DH_KEYLENGTH}
369
   fi
370
   fi
370
 }
371
 }
371
 
372
 
384
   esac
385
   esac
385
 
386
 
386
   if [ ! $renew_domain ]; then
387
   if [ ! $renew_domain ]; then
387
-	  return
388
+      return
388
   fi
389
   fi
389
 
390
 
390
   if [[ $renew_domain == "http"* ]]; then
391
   if [[ $renew_domain == "http"* ]]; then
391
       dialog --title $"Renew a StartSSL certificate" \
392
       dialog --title $"Renew a StartSSL certificate" \
392
              --msgbox $"Don't include the https://" 6 40
393
              --msgbox $"Don't include the https://" 6 40
393
-	  return
394
+      return
394
   fi
395
   fi
395
 
396
 
396
   if [ ! -f /etc/ssl/certs/${renew_domain}.dhparam ]; then
397
   if [ ! -f /etc/ssl/certs/${renew_domain}.dhparam ]; then
397
       dialog --title $"Renew a StartSSL certificate" \
398
       dialog --title $"Renew a StartSSL certificate" \
398
              --msgbox $"An existing certificate for $renew_domain was not found" 6 40
399
              --msgbox $"An existing certificate for $renew_domain was not found" 6 40
399
-	  return
400
+      return
400
   fi
401
   fi
401
 
402
 
402
   if [[ $renew_domain != *"."* ]]; then
403
   if [[ $renew_domain != *"."* ]]; then
403
       dialog --title $"Renew a StartSSL certificate" \
404
       dialog --title $"Renew a StartSSL certificate" \
404
              --msgbox $"Invalid domain name: $renew_domain" 6 40
405
              --msgbox $"Invalid domain name: $renew_domain" 6 40
405
-	  return
406
+      return
406
   fi
407
   fi
407
 
408
 
408
   ${PROJECT_NAME}-renew-cert -h $renew_domain -p startssl
409
   ${PROJECT_NAME}-renew-cert -h $renew_domain -p startssl
425
   esac
426
   esac
426
 
427
 
427
   if [ ! $renew_domain ]; then
428
   if [ ! $renew_domain ]; then
428
-	  return
429
+      return
429
   fi
430
   fi
430
 
431
 
431
   if [[ $renew_domain == "http"* ]]; then
432
   if [[ $renew_domain == "http"* ]]; then
432
       dialog --title $"Renew a Let's Encrypt certificate" \
433
       dialog --title $"Renew a Let's Encrypt certificate" \
433
              --msgbox $"Don't include the https://" 6 40
434
              --msgbox $"Don't include the https://" 6 40
434
-	  return
435
+      return
435
   fi
436
   fi
436
 
437
 
437
   if [ ! -f /etc/ssl/certs/${renew_domain}.dhparam ]; then
438
   if [ ! -f /etc/ssl/certs/${renew_domain}.dhparam ]; then
438
       dialog --title $"Renew a Let's Encrypt certificate" \
439
       dialog --title $"Renew a Let's Encrypt certificate" \
439
              --msgbox $"An existing certificate for $renew_domain was not found" 6 40
440
              --msgbox $"An existing certificate for $renew_domain was not found" 6 40
440
-	  return
441
+      return
441
   fi
442
   fi
442
 
443
 
443
   if [[ $renew_domain != *"."* ]]; then
444
   if [[ $renew_domain != *"."* ]]; then
444
       dialog --title $"Renew a Let's Encrypt certificate" \
445
       dialog --title $"Renew a Let's Encrypt certificate" \
445
              --msgbox $"Invalid domain name: $renew_domain" 6 40
446
              --msgbox $"Invalid domain name: $renew_domain" 6 40
446
-	  return
447
+      return
447
   fi
448
   fi
448
 
449
 
449
   ${PROJECT_NAME}-renew-cert -h $renew_domain -p 'letsencrypt'
450
   ${PROJECT_NAME}-renew-cert -h $renew_domain -p 'letsencrypt'
451
   exit 0
452
   exit 0
452
 }
453
 }
453
 
454
 
455
+function create_letsencrypt {
456
+  new_domain=
457
+  data=$(tempfile 2>/dev/null)
458
+  trap "rm -f $data" 0 1 2 5 15
459
+  dialog --title $"Create a new Let's Encrypt certificate" \
460
+         --backtitle $"Freedombone Security Settings" \
461
+         --inputbox $"Enter the domain name" 8 60 2>$data
462
+  sel=$?
463
+  case $sel in
464
+      0)
465
+          new_domain=$(<$data)
466
+          ;;
467
+  esac
468
+
469
+  if [ ! $new_domain ]; then
470
+      return
471
+  fi
472
+
473
+  if [[ $new_domain == "http"* ]]; then
474
+      dialog --title $"Create a new Let's Encrypt certificate" \
475
+             --msgbox $"Don't include the https://" 6 40
476
+      return
477
+  fi
478
+
479
+  if [[ $new_domain != *"."* ]]; then
480
+      dialog --title $"Create a new Let's Encrypt certificate" \
481
+             --msgbox $"Invalid domain name: $new_domain" 6 40
482
+      return
483
+  fi
484
+
485
+  if [ ! -d /var/www/${new_domain} ]; then
486
+      dialog --title $"Create a new Let's Encrypt certificate" \
487
+             --msgbox $'Domain not found within /var/www' 6 40
488
+      return
489
+  fi
490
+
491
+  ${PROJECT_NAME}-addcert -e $new_domain -s $LETSENCRYPT_SERVER --dhkey $DH_KEYLENGTH
492
+
493
+  exit 0
494
+}
495
+
454
 function housekeeping {
496
 function housekeeping {
455
   cmd=(dialog --separate-output \
497
   cmd=(dialog --separate-output \
456
               --backtitle "Freedombone Security Configuration" \
498
               --backtitle "Freedombone Security Configuration" \
457
               --title "Housekeeping options" \
499
               --title "Housekeeping options" \
458
-              --checklist "If you don't need to do any of these things then just press Enter:" 12 76 16)
500
+              --checklist "If you don't need to do any of these things then just press Enter:" 13 76 16)
459
   options=(1 "Regenerate ssh host keys" off
501
   options=(1 "Regenerate ssh host keys" off
460
            2 "Regenerate Diffie-Hellman keys" off
502
            2 "Regenerate Diffie-Hellman keys" off
461
            3 "Renew a StartSSL certificate" off
503
            3 "Renew a StartSSL certificate" off
462
-           4 "Renew Let's Encrypt certificate" off)
504
+           4 "Create a new Let's Encrypt certificate" off
505
+           5 "Renew Let's Encrypt certificate" off)
463
   choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
506
   choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
464
   clear
507
   clear
465
   for choice in $choices
508
   for choice in $choices
475
         renew_startssl
518
         renew_startssl
476
         ;;
519
         ;;
477
       4)
520
       4)
521
+        create_letsencrypt
522
+        ;;
523
+      5)
478
         renew_letsencrypt
524
         renew_letsencrypt
479
         ;;
525
         ;;
480
     esac
526
     esac