freedombone-sec 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Alters the security settings
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2015-2016 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 Affero 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 Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. PROJECT_NAME='freedombone'
  31. export TEXTDOMAIN=${PROJECT_NAME}-sec
  32. export TEXTDOMAINDIR="/usr/share/locale"
  33. CONFIGURATION_FILE=/root/${PROJECT_NAME}.cfg
  34. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  35. SSL_PROTOCOLS=
  36. SSL_CIPHERS=
  37. SSH_CIPHERS=
  38. SSH_MACS=
  39. SSH_KEX=
  40. SSH_HOST_KEY_ALGORITHMS=
  41. SSH_PASSWORDS=
  42. XMPP_CIPHERS=
  43. XMPP_ECC_CURVE=
  44. WEBSITES_DIRECTORY='/etc/nginx/sites-available'
  45. DOVECOT_CIPHERS='/etc/dovecot/conf.d/10-ssl.conf'
  46. SSH_CONFIG='/etc/ssh/sshd_config'
  47. XMPP_CONFIG='/etc/prosody/conf.avail/xmpp.cfg.lua'
  48. MINIMUM_LENGTH=6
  49. IMPORT_FILE=
  50. EXPORT_FILE=
  51. CURRENT_DIR=$(pwd)
  52. REGENERATE_SSH_HOST_KEYS="no"
  53. REGENERATE_DH_KEYS="no"
  54. DH_KEYLENGTH=2048
  55. LETSENCRYPT_SERVER='https://acme-v01.api.letsencrypt.org/directory'
  56. MY_USERNAME=
  57. function get_protocols_from_website {
  58. if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
  59. return
  60. fi
  61. SSL_PROTOCOLS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_protocols ' | awk -F "ssl_protocols " '{print $2}' | awk -F ';' '{print $1}')
  62. }
  63. function get_ciphers_from_website {
  64. if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
  65. return
  66. fi
  67. SSL_CIPHERS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_ciphers ' | awk -F "ssl_ciphers " '{print $2}' | awk -F "'" '{print $2}')
  68. }
  69. function get_website_settings {
  70. if [ ! -d $WEBSITES_DIRECTORY ]; then
  71. return
  72. fi
  73. cd $WEBSITES_DIRECTORY
  74. for file in `dir -d *` ; do
  75. get_protocols_from_website $file
  76. if [ ${#SSL_PROTOCOLS} -gt $MINIMUM_LENGTH ]; then
  77. get_ciphers_from_website $file
  78. if [ ${#SSL_CIPHERS} -gt $MINIMUM_LENGTH ]; then
  79. break
  80. else
  81. SSL_PROTOCOLS=""
  82. fi
  83. fi
  84. done
  85. }
  86. function get_imap_settings {
  87. if [ ! -f $DOVECOT_CIPHERS ]; then
  88. return
  89. fi
  90. # clear commented out cipher list
  91. sed -i "s|#ssl_cipher_list.*||g" $DOVECOT_CIPHERS
  92. if [ $SSL_CIPHERS ]; then
  93. return
  94. fi
  95. if [ ${#SSL_CIPHERS} -gt $MINIMUM_LENGTH ]; then
  96. return
  97. fi
  98. SSL_CIPHERS=$(cat $DOVECOT_CIPHERS | grep 'ssl_cipher_list' | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')
  99. }
  100. function get_xmpp_settings {
  101. if [ ! -f $XMPP_CONFIG ]; then
  102. return
  103. fi
  104. XMPP_CIPHERS=$(cat $XMPP_CONFIG | grep 'ciphers ' | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
  105. XMPP_ECC_CURVE=$(cat $XMPP_CONFIG | grep 'curve ' | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
  106. }
  107. function get_ssh_settings {
  108. if [ -f $SSH_CONFIG ]; then
  109. SSH_CIPHERS=$(cat $SSH_CONFIG | grep 'Ciphers ' | awk -F 'Ciphers ' '{print $2}')
  110. SSH_MACS=$(cat $SSH_CONFIG | grep 'MACs ' | awk -F 'MACs ' '{print $2}')
  111. SSH_KEX=$(cat $SSH_CONFIG | grep 'KexAlgorithms ' | awk -F 'KexAlgorithms ' '{print $2}')
  112. SSH_PASSWORDS=$(cat $SSH_CONFIG | grep 'PasswordAuthentication ' | awk -F 'PasswordAuthentication ' '{print $2}')
  113. fi
  114. if [ -f /etc/ssh/ssh_config ]; then
  115. SSH_HOST_KEY_ALGORITHMS=$(cat /etc/ssh/ssh_config | grep 'HostKeyAlgorithms ' | awk -F 'HostKeyAlgorithms ' '{print $2}')
  116. if [ ! $SSH_CIPHERS ]; then
  117. SSH_CIPHERS=$(cat /etc/ssh/ssh_config | grep 'Ciphers ' | awk -F 'Ciphers ' '{print $2}')
  118. fi
  119. if [ ! $SSH_MACS ]; then
  120. SSH_MACS=$(cat /etc/ssh/ssh_config | grep 'MACs ' | awk -F 'MACs ' '{print $2}')
  121. fi
  122. fi
  123. }
  124. function change_website_settings {
  125. if [ ! "$SSL_PROTOCOLS" ]; then
  126. return
  127. fi
  128. if [ ! $SSL_CIPHERS ]; then
  129. return
  130. fi
  131. if [ ${#SSL_PROTOCOLS} -lt $MINIMUM_LENGTH ]; then
  132. return
  133. fi
  134. if [ ${#SSL_CIPHERS} -lt $MINIMUM_LENGTH ]; then
  135. return
  136. fi
  137. if [ ! -d $WEBSITES_DIRECTORY ]; then
  138. return
  139. fi
  140. cd $WEBSITES_DIRECTORY
  141. for file in `dir -d *` ; do
  142. sed -i "s|ssl_protocols .*|ssl_protocols $SSL_PROTOCOLS;|g" $WEBSITES_DIRECTORY/$file
  143. sed -i "s|ssl_ciphers .*|ssl_ciphers '$SSL_CIPHERS';|g" $WEBSITES_DIRECTORY/$file
  144. done
  145. systemctl restart nginx
  146. echo $'Web security settings changed'
  147. }
  148. function change_imap_settings {
  149. if [ ! -f $DOVECOT_CIPHERS ]; then
  150. return
  151. fi
  152. if [ ! $SSL_CIPHERS ]; then
  153. return
  154. fi
  155. if [ ${#SSL_CIPHERS} -lt $MINIMUM_LENGTH ]; then
  156. return
  157. fi
  158. sed -i "s|ssl_cipher_list.*|ssl_cipher_list = '$SSL_CIPHERS'|g" $DOVECOT_CIPHERS
  159. sed -i "s|ssl_protocols.*|ssl_protocols = '$SSL_PROTOCOLS'|g" $DOVECOT_CIPHERS
  160. systemctl restart dovecot
  161. echo $'imap security settings changed'
  162. }
  163. function change_ssh_settings {
  164. if [ -f /etc/ssh/ssh_config ]; then
  165. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  166. sed -i "s|HostKeyAlgorithms .*|HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS|g" /etc/ssh/ssh_config
  167. echo $'ssh client security settings changed'
  168. fi
  169. fi
  170. if [ -f $SSH_CONFIG ]; then
  171. if [ ! $SSH_CIPHERS ]; then
  172. return
  173. fi
  174. if [ ! $SSH_MACS ]; then
  175. return
  176. fi
  177. if [ ! $SSH_KEX ]; then
  178. return
  179. fi
  180. if [ ! $SSH_PASSWORDS ]; then
  181. return
  182. fi
  183. sed -i "s|Ciphers .*|Ciphers $SSH_CIPHERS|g" $SSH_CONFIG
  184. sed -i "s|MACs .*|MACs $SSH_MACS|g" $SSH_CONFIG
  185. sed -i "s|KexAlgorithms .*|KexAlgorithms $SSH_KEX|g" $SSH_CONFIG
  186. sed -i "s|PasswordAuthentication .*|PasswordAuthentication $SSH_PASSWORDS|g" $SSH_CONFIG
  187. systemctl restart ssh
  188. echo $'ssh server security settings changed'
  189. fi
  190. }
  191. function change_xmpp_settings {
  192. if [ ! -f $XMPP_CONFIG ]; then
  193. return
  194. fi
  195. if [ ! $XMPP_CIPHERS ]; then
  196. return
  197. fi
  198. if [ ! $XMPP_ECC_CURVE ]; then
  199. return
  200. fi
  201. sed -i "s|ciphers =.*|ciphers = \"$XMPP_CIPHERS\";|g" $XMPP_CONFIG
  202. sed -i "s|curve =.*|curve = \"$XMPP_ECC_CURVE\";|g" $XMPP_CONFIG
  203. systemctl restart prosody
  204. echo $'xmpp security settings changed'
  205. }
  206. function interactive_setup {
  207. if [ $SSL_CIPHERS ]; then
  208. data=$(tempfile 2>/dev/null)
  209. trap "rm -f $data" 0 1 2 5 15
  210. dialog --backtitle $"Freedombone Security Configuration" \
  211. --form $"\nWeb/IMAP Ciphers:" 10 95 2 \
  212. $"Protocols:" 1 1 "$SSL_PROTOCOLS" 1 15 90 90 \
  213. $"Ciphers:" 2 1 "$SSL_CIPHERS" 2 15 90 512 \
  214. 2> $data
  215. sel=$?
  216. case $sel in
  217. 1) SSL_PROTOCOLS=$(cat $data | sed -n 1p)
  218. SSL_CIPHERS=$(cat $data | sed -n 2p)
  219. ;;
  220. 255) exit 0;;
  221. esac
  222. fi
  223. data=$(tempfile 2>/dev/null)
  224. trap "rm -f $data" 0 1 2 5 15
  225. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  226. dialog --backtitle $"Freedombone Security Configuration" \
  227. --form $"\nSecure Shell Ciphers:" 13 95 4 \
  228. $"Ciphers:" 1 1 "$SSH_CIPHERS" 1 15 90 512 \
  229. $"MACs:" 2 1 "$SSH_MACS" 2 15 90 512 \
  230. $"KEX:" 3 1 "$SSH_KEX" 3 15 90 512 \
  231. $"Host key algorithms:" 4 1 "$SSH_HOST_KEY_ALGORITHMS" 4 15 90 512 \
  232. 2> $data
  233. sel=$?
  234. case $sel in
  235. 1) SSH_CIPHERS=$(cat $data | sed -n 1p)
  236. SSH_MACS=$(cat $data | sed -n 2p)
  237. SSH_KEX=$(cat $data | sed -n 3p)
  238. SSH_HOST_KEY_ALGORITHMS=$(cat $data | sed -n 4p)
  239. ;;
  240. 255) exit 0;;
  241. esac
  242. else
  243. dialog --backtitle $"Freedombone Security Configuration" \
  244. --form $"\nSecure Shell Ciphers:" 11 95 3 \
  245. $"Ciphers:" 1 1 "$SSH_CIPHERS" 1 15 90 512 \
  246. $"MACs:" 2 1 "$SSH_MACS" 2 15 90 512 \
  247. $"KEX:" 3 1 "$SSH_KEX" 3 15 90 512 \
  248. 2> $data
  249. sel=$?
  250. case $sel in
  251. 1) SSH_CIPHERS=$(cat $data | sed -n 1p)
  252. SSH_MACS=$(cat $data | sed -n 2p)
  253. SSH_KEX=$(cat $data | sed -n 3p)
  254. ;;
  255. 255) exit 0;;
  256. esac
  257. fi
  258. if [[ $SSH_PASSWORDS == "yes" ]]; then
  259. dialog --title $"SSH Passwords" \
  260. --backtitle $"Freedombone Security Configuration" \
  261. --yesno $"\nAllow SSH login using passwords?" 7 60
  262. else
  263. dialog --title $"SSH Passwords" \
  264. --backtitle $"Freedombone Security Configuration" \
  265. --defaultno \
  266. --yesno $"\nAllow SSH login using passwords?" 7 60
  267. fi
  268. sel=$?
  269. case $sel in
  270. 0) SSH_PASSWORDS="yes";;
  271. 1) SSH_PASSWORDS="no";;
  272. 255) exit 0;;
  273. esac
  274. if [ $XMPP_CIPHERS ]; then
  275. data=$(tempfile 2>/dev/null)
  276. trap "rm -f $data" 0 1 2 5 15
  277. dialog --backtitle $"Freedombone Security Configuration" \
  278. --form $"\nXMPP Ciphers:" 10 95 2 \
  279. $"Ciphers:" 1 1 "$XMPP_CIPHERS" 1 15 90 512 \
  280. $"ECC Curve:" 2 1 "$XMPP_ECC_CURVE" 2 15 50 50 \
  281. 2> $data
  282. sel=$?
  283. case $sel in
  284. 1) XMPP_CIPHERS=$(cat $data | sed -n 1p)
  285. XMPP_ECC_CURVE=$(cat $data | sed -n 2p)
  286. ;;
  287. 255) exit 0;;
  288. esac
  289. fi
  290. dialog --title $"Final Confirmation" \
  291. --backtitle $"Freedombone Security Configuration" \
  292. --defaultno \
  293. --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
  294. sel=$?
  295. case $sel in
  296. 1) clear
  297. echo $'Exiting without changing security settings'
  298. exit 0;;
  299. 255) clear
  300. echo $'Exiting without changing security settings'
  301. exit 0;;
  302. esac
  303. clear
  304. }
  305. function send_monkeysphere_server_keys_to_users {
  306. monkeysphere_server_keys=$(monkeysphere-host show-key | grep $"OpenPGP fingerprint" | awk -F ' ' '{print $3}')
  307. for d in /home/*/ ; do
  308. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  309. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  310. if [ ! -d /home/$USERNAME/.monkeysphere ]; then
  311. mkdir /home/$USERNAME/.monkeysphere
  312. fi
  313. echo $monkeysphere_server_keys > /home/$USERNAME/.monkeysphere/server_keys
  314. chown -R $USERNAME:$USERNAME /home/$USERNAME/.monkeysphere
  315. fi
  316. done
  317. }
  318. function regenerate_ssh_host_keys {
  319. if [[ $REGENERATE_SSH_HOST_KEYS == "yes" ]]; then
  320. rm -f /etc/ssh/ssh_host_*
  321. dpkg-reconfigure openssh-server
  322. echo $'ssh host keys regenerated'
  323. # remove small moduli
  324. awk '$5 > 2000' /etc/ssh/moduli > ~/moduli
  325. mv ~/moduli /etc/ssh/moduli
  326. echo $'ssh small moduli removed'
  327. # update monkeysphere
  328. DEFAULT_DOMAIN_NAME=
  329. if grep -q "DEFAULT_DOMAIN_NAME" $CONFIGURATION_FILE; then
  330. DEFAULT_DOMAIN_NAME=$(grep "DEFAULT_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  331. fi
  332. monkeysphere-host import-key /etc/ssh/ssh_host_rsa_key ssh://$DEFAULT_DOMAIN_NAME
  333. SSH_ONION_HOSTNAME=$(cat ${COMPLETION_FILE} | grep 'ssh onion domain' | awk -F ':' '{print $2}')
  334. monkeysphere-host import-key /etc/ssh/ssh_host_rsa_key ssh://$SSH_ONION_HOSTNAME
  335. monkeysphere-host publish-key
  336. send_monkeysphere_server_keys_to_users
  337. echo $'updated monkeysphere ssh host key'
  338. systemctl restart ssh
  339. fi
  340. }
  341. function regenerate_dh_keys {
  342. if [[ $REGENERATE_DH_KEYS == "yes" ]]; then
  343. if [ ! -d /etc/ssl/mycerts ]; then
  344. echo $'No dhparam certificates were found'
  345. return
  346. fi
  347. data=$(tempfile 2>/dev/null)
  348. trap "rm -f $data" 0 1 2 5 15
  349. dialog --backtitle "Freedombone Security Configuration" \
  350. --title "Diffie-Hellman key length" \
  351. --radiolist "The smaller length is better suited to low power embedded systems:" 12 40 3 \
  352. 1 "2048 bits" off \
  353. 2 "3072 bits" on \
  354. 3 "4096 bits" off 2> $data
  355. sel=$?
  356. case $sel in
  357. 1) exit 1;;
  358. 255) exit 1;;
  359. esac
  360. case $(cat $data) in
  361. 1) DH_KEYLENGTH=2048;;
  362. 2) DH_KEYLENGTH=3072;;
  363. 3) DH_KEYLENGTH=4096;;
  364. esac
  365. ${PROJECT_NAME}-dhparam --recalc yes -l ${DH_KEYLENGTH}
  366. fi
  367. }
  368. function renew_startssl {
  369. renew_domain=
  370. data=$(tempfile 2>/dev/null)
  371. trap "rm -f $data" 0 1 2 5 15
  372. dialog --title $"Renew a StartSSL certificate" \
  373. --backtitle $"Freedombone Security Settings" \
  374. --inputbox $"Enter the domain name" 8 60 2>$data
  375. sel=$?
  376. case $sel in
  377. 0)
  378. renew_domain=$(<$data)
  379. ;;
  380. esac
  381. if [ ! $renew_domain ]; then
  382. return
  383. fi
  384. if [[ $renew_domain == "http"* ]]; then
  385. dialog --title $"Renew a StartSSL certificate" \
  386. --msgbox $"Don't include the https://" 6 40
  387. return
  388. fi
  389. if [ ! -f /etc/ssl/certs/${renew_domain}.dhparam ]; then
  390. dialog --title $"Renew a StartSSL certificate" \
  391. --msgbox $"An existing certificate for $renew_domain was not found" 6 40
  392. return
  393. fi
  394. if [[ $renew_domain != *"."* ]]; then
  395. dialog --title $"Renew a StartSSL certificate" \
  396. --msgbox $"Invalid domain name: $renew_domain" 6 40
  397. return
  398. fi
  399. ${PROJECT_NAME}-renew-cert -h $renew_domain -p startssl
  400. exit 0
  401. }
  402. function renew_letsencrypt {
  403. renew_domain=
  404. data=$(tempfile 2>/dev/null)
  405. trap "rm -f $data" 0 1 2 5 15
  406. dialog --title $"Renew a Let's Encrypt certificate" \
  407. --backtitle $"Freedombone Security Settings" \
  408. --inputbox $"Enter the domain name" 8 60 2>$data
  409. sel=$?
  410. case $sel in
  411. 0)
  412. renew_domain=$(<$data)
  413. ;;
  414. esac
  415. if [ ! $renew_domain ]; then
  416. return
  417. fi
  418. if [[ $renew_domain == "http"* ]]; then
  419. dialog --title $"Renew a Let's Encrypt certificate" \
  420. --msgbox $"Don't include the https://" 6 40
  421. return
  422. fi
  423. if [ ! -f /etc/ssl/certs/${renew_domain}.dhparam ]; then
  424. dialog --title $"Renew a Let's Encrypt certificate" \
  425. --msgbox $"An existing certificate for $renew_domain was not found" 6 40
  426. return
  427. fi
  428. if [[ $renew_domain != *"."* ]]; then
  429. dialog --title $"Renew a Let's Encrypt certificate" \
  430. --msgbox $"Invalid domain name: $renew_domain" 6 40
  431. return
  432. fi
  433. ${PROJECT_NAME}-renew-cert -h $renew_domain -p 'letsencrypt'
  434. exit 0
  435. }
  436. function create_letsencrypt {
  437. new_domain=
  438. data=$(tempfile 2>/dev/null)
  439. trap "rm -f $data" 0 1 2 5 15
  440. dialog --title $"Create a new Let's Encrypt certificate" \
  441. --backtitle $"Freedombone Security Settings" \
  442. --inputbox $"Enter the domain name" 8 60 2>$data
  443. sel=$?
  444. case $sel in
  445. 0)
  446. new_domain=$(<$data)
  447. ;;
  448. esac
  449. if [ ! $new_domain ]; then
  450. return
  451. fi
  452. if [[ $new_domain == "http"* ]]; then
  453. dialog --title $"Create a new Let's Encrypt certificate" \
  454. --msgbox $"Don't include the https://" 6 40
  455. return
  456. fi
  457. if [[ $new_domain != *"."* ]]; then
  458. dialog --title $"Create a new Let's Encrypt certificate" \
  459. --msgbox $"Invalid domain name: $new_domain" 6 40
  460. return
  461. fi
  462. if [ ! -d /var/www/${new_domain} ]; then
  463. dialog --title $"Create a new Let's Encrypt certificate" \
  464. --msgbox $'Domain not found within /var/www' 6 40
  465. return
  466. fi
  467. ${PROJECT_NAME}-addcert -e $new_domain -s $LETSENCRYPT_SERVER --dhkey $DH_KEYLENGTH
  468. exit 0
  469. }
  470. function update_ciphersuite {
  471. project_filename=/usr/local/bin/${PROJECT_NAME}
  472. if [ ! -f $project_filename ]; then
  473. project_filename=/usr/bin/${PROJECT_NAME}
  474. fi
  475. RECOMMENDED_SSL_CIPHERS=$(cat $project_filename | grep 'SSL_CIPHERS=' | head -n 1 | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
  476. if [ ! "$RECOMMENDED_SSL_CIPHERS" ]; then
  477. return
  478. fi
  479. if [ ${#RECOMMENDED_SSL_CIPHERS} -lt 5 ]; then
  480. return
  481. fi
  482. RECOMMENDED_SSL_PROTOCOLS=$(cat $project_filename | grep 'SSL_PROTOCOLS=' | head -n 1 | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
  483. if [ ! "$RECOMMENDED_SSL_PROTOCOLS" ]; then
  484. return
  485. fi
  486. if [ ${#RECOMMENDED_SSL_PROTOCOLS} -lt 5 ]; then
  487. return
  488. fi
  489. RECOMMENDED_SSH_CIPHERS=$(cat $project_filename | grep 'SSH_CIPHERS=' | head -n 1 | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
  490. if [ ! "$RECOMMENDED_SSH_CIPHERS" ]; then
  491. return
  492. fi
  493. if [ ${#RECOMMENDED_SSH_CIPHERS} -lt 5 ]; then
  494. return
  495. fi
  496. RECOMMENDED_SSH_MACS=$(cat $project_filename | grep 'SSH_MACS=' | head -n 1 | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
  497. if [ ! "$RECOMMENDED_SSH_MACS" ]; then
  498. return
  499. fi
  500. if [ ${#RECOMMENDED_SSH_MACS} -lt 5 ]; then
  501. return
  502. fi
  503. RECOMMENDED_SSH_KEX=$(cat $project_filename | grep 'SSH_KEX=' | head -n 1 | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
  504. if [ ! "$RECOMMENDED_SSH_KEX" ]; then
  505. return
  506. fi
  507. if [ ${#RECOMMENDED_SSH_KEX} -lt 5 ]; then
  508. return
  509. fi
  510. cd $WEBSITES_DIRECTORY
  511. for file in `dir -d *` ; do
  512. sed -i "s|ssl_protocols .*|ssl_protocols $RECOMMENDED_SSL_PROTOCOLS;|g" $WEBSITES_DIRECTORY/$file
  513. sed -i "s|ssl_ciphers .*|ssl_ciphers '$RECOMMENDED_SSL_CIPHERS';|g" $WEBSITES_DIRECTORY/$file
  514. done
  515. systemctl restart nginx
  516. sed -i "s|Ciphers .*|Ciphers $RECOMMENDED_SSH_CIPHERS|g" $SSH_CONFIG
  517. sed -i "s|MACs .*|MACs $RECOMMENDED_SSH_MACS|g" $SSH_CONFIG
  518. sed -i "s|KexAlgorithms .*|KexAlgorithms $RECOMMENDED_SSH_KEX|g" $SSH_CONFIG
  519. systemctl restart ssh
  520. dialog --title $"Update ciphersuite" \
  521. --msgbox $"The ciphersuite has been updated to recommended versions" 6 40
  522. exit 0
  523. }
  524. function gpg_pubkey_from_email {
  525. key_owner_username=$1
  526. key_email_address=$2
  527. key_id=
  528. if [[ $key_owner_username != "root" ]]; then
  529. key_id=$(su -c "gpg --list-keys $key_email_address | grep 'pub '" - $key_owner_username | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  530. else
  531. key_id=$(gpg --list-keys $key_email_address | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  532. fi
  533. echo $key_id
  534. }
  535. function enable_monkeysphere {
  536. monkey=
  537. dialog --title $"GPG based authentication" \
  538. --backtitle $"Freedombone Security Configuration" \
  539. --defaultno \
  540. --yesno $"\nEnable GPG based authentication with monkeysphere ?" 7 60
  541. sel=$?
  542. case $sel in
  543. 0) monkey='yes';;
  544. 255) exit 0;;
  545. esac
  546. if [ $monkey ]; then
  547. if grep -q "MY_USERNAME" $CONFIGURATION_FILE; then
  548. MY_USERNAME=$(grep "MY_USERNAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  549. fi
  550. if [ ! -f /home/$MY_USERNAME/.monkeysphere/authorized_user_ids ]; then
  551. dialog --title $"GPG based authentication" \
  552. --msgbox $"$MY_USERNAME does not currently have any ids within ~/.monkeysphere/authorized_user_ids" 6 40
  553. exit 0
  554. fi
  555. MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$MY_USERNAME" "$MY_USERNAME@$HOSTNAME")
  556. if [ ${#MY_GPG_PUBLIC_KEY_ID} -lt 4 ]; then
  557. echo $'monkeysphere unable to get GPG key ID for user $MY_USERNAME'
  558. exit 52825
  559. fi
  560. sed -i 's|#AuthorizedKeysFile|AuthorizedKeysFile|g' /etc/ssh/sshd_config
  561. sed -i 's|AuthorizedKeysFile.*|AuthorizedKeysFile /var/lib/monkeysphere/authorized_keys/%u|g' /etc/ssh/sshd_config
  562. monkeysphere-authentication update-users
  563. # The admin user is the identity certifier
  564. fpr=$(gpg --with-colons --fingerprint $MY_GPG_PUBLIC_KEY_ID | grep fpr | head -n 1 | awk -F ':' '{print $10}')
  565. monkeysphere-authentication add-identity-certifier $fpr
  566. monkeysphere-host publish-key
  567. send_monkeysphere_server_keys_to_users
  568. else
  569. sed -i 's|#AuthorizedKeysFile|AuthorizedKeysFile|g' /etc/ssh/sshd_config
  570. sed -i 's|AuthorizedKeysFile.*|AuthorizedKeysFile %h/.ssh/authorized_keys|g' /etc/ssh/sshd_config
  571. fi
  572. systemctl restart ssh
  573. if [ $monkey ]; then
  574. dialog --title $"GPG based authentication" \
  575. --msgbox $"GPG based authentication was enabled" 6 40
  576. else
  577. dialog --title $"GPG based authentication" \
  578. --msgbox $"GPG based authentication was disabled" 6 40
  579. fi
  580. exit 0
  581. }
  582. function register_website {
  583. domain="$1"
  584. if [[ ${domain} == *".local" ]]; then
  585. echo $"Can't register local domains"
  586. return
  587. fi
  588. if [ ! -f /etc/ssl/private/${domain}.key ]; then
  589. echo $"No SSL/TLS private key found for ${domain}"
  590. return
  591. fi
  592. if [ ! -f /etc/nginx/sites-available/${domain} ]; then
  593. echo $"No virtual host found for ${domain}"
  594. return
  595. fi
  596. monkeysphere-host import-key /etc/ssl/private/${domain}.key https://${domain}
  597. monkeysphere-host publish-key
  598. echo "0"
  599. }
  600. function register_website_interactive {
  601. data=$(tempfile 2>/dev/null)
  602. trap "rm -f $data" 0 1 2 5 15
  603. dialog --title $"Register a website with monkeysphere" \
  604. --backtitle $"Freedombone Security Settings" \
  605. --inputbox $"Enter the website domain name (without https://)" 8 60 2>$data
  606. sel=$?
  607. case $sel in
  608. 0)
  609. domain=$(<$data)
  610. register_website "$domain"
  611. if [ ! "$?" = "0" ]; then
  612. dialog --title $"Register a website with monkeysphere" \
  613. --msgbox "$?" 6 40
  614. else
  615. dialog --title $"Register a website with monkeysphere" \
  616. --msgbox $"$domain has been registered" 6 40
  617. fi
  618. ;;
  619. esac
  620. }
  621. function housekeeping {
  622. cmd=(dialog --separate-output \
  623. --backtitle "Freedombone Security Configuration" \
  624. --title "Housekeeping options" \
  625. --checklist "If you don't need to do any of these things then just press Enter:" 17 76 17)
  626. options=(1 "Regenerate ssh host keys" off
  627. 2 "Regenerate Diffie-Hellman keys" off
  628. 3 "Renew a StartSSL certificate" off
  629. 4 "Update cipersuite" off
  630. 5 "Create a new Let's Encrypt certificate" off
  631. 6 "Renew Let's Encrypt certificate" off
  632. 7 "Enable GPG based authentication (monkeysphere)" off
  633. 8 "Register a website with monkeysphere" off
  634. 9 "Go Back/Exit" on)
  635. choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
  636. clear
  637. for choice in $choices
  638. do
  639. case $choice in
  640. 1)
  641. REGENERATE_SSH_HOST_KEYS="yes"
  642. ;;
  643. 2)
  644. REGENERATE_DH_KEYS="yes"
  645. ;;
  646. 3)
  647. renew_startssl
  648. ;;
  649. 4)
  650. update_ciphersuite
  651. ;;
  652. 5)
  653. create_letsencrypt
  654. ;;
  655. 6)
  656. renew_letsencrypt
  657. ;;
  658. 7)
  659. enable_monkeysphere
  660. ;;
  661. 8)
  662. register_website
  663. ;;
  664. 9)
  665. exit 0
  666. ;;
  667. esac
  668. done
  669. }
  670. function import_settings {
  671. cd $CURRENT_DIR
  672. if [ ! $IMPORT_FILE ]; then
  673. return
  674. fi
  675. if [ ! -f $IMPORT_FILE ]; then
  676. echo $"Import file $IMPORT_FILE not found"
  677. exit 6393
  678. fi
  679. if grep -q "SSL_PROTOCOLS" $IMPORT_FILE; then
  680. TEMP_VALUE=$(grep "SSL_PROTOCOLS" $IMPORT_FILE | awk -F '=' '{print $2}')
  681. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  682. SSL_PROTOCOLS=$TEMP_VALUE
  683. fi
  684. fi
  685. if grep -q "SSL_CIPHERS" $IMPORT_FILE; then
  686. TEMP_VALUE=$(grep "SSL_CIPHERS" $IMPORT_FILE | awk -F '=' '{print $2}')
  687. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  688. SSL_CIPHERS=$TEMP_VALUE
  689. fi
  690. fi
  691. if grep -q "SSH_CIPHERS" $IMPORT_FILE; then
  692. TEMP_VALUE=$(grep "SSH_CIPHERS" $IMPORT_FILE | awk -F '=' '{print $2}')
  693. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  694. SSH_CIPHERS=$TEMP_VALUE
  695. fi
  696. fi
  697. if grep -q "SSH_MACS" $IMPORT_FILE; then
  698. TEMP_VALUE=$(grep "SSH_MACS" $IMPORT_FILE | awk -F '=' '{print $2}')
  699. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  700. SSH_MACS=$TEMP_VALUE
  701. fi
  702. fi
  703. if grep -q "SSH_KEX" $IMPORT_FILE; then
  704. TEMP_VALUE=$(grep "SSH_KEX" $IMPORT_FILE | awk -F '=' '{print $2}')
  705. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  706. SSH_KEX=$TEMP_VALUE
  707. fi
  708. fi
  709. if grep -q "SSH_HOST_KEY_ALGORITHMS" $IMPORT_FILE; then
  710. TEMP_VALUE=$(grep "SSH_HOST_KEY_ALGORITHMS" $IMPORT_FILE | awk -F '=' '{print $2}')
  711. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  712. SSH_HOST_KEY_ALGORITHMS=$TEMP_VALUE
  713. fi
  714. fi
  715. if grep -q "SSH_PASSWORDS" $IMPORT_FILE; then
  716. TEMP_VALUE=$(grep "SSH_PASSWORDS" $IMPORT_FILE | awk -F '=' '{print $2}')
  717. if [[ $TEMP_VALUE == "yes" || $TEMP_VALUE == "no" ]]; then
  718. SSH_PASSWORDS=$TEMP_VALUE
  719. fi
  720. fi
  721. if grep -q "XMPP_CIPHERS" $IMPORT_FILE; then
  722. TEMP_VALUE=$(grep "XMPP_CIPHERS" $IMPORT_FILE | awk -F '=' '{print $2}')
  723. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  724. XMPP_CIPHERS=$TEMP_VALUE
  725. fi
  726. fi
  727. if grep -q "XMPP_ECC_CURVE" $IMPORT_FILE; then
  728. TEMP_VALUE=$(grep "XMPP_ECC_CURVE" $IMPORT_FILE | awk -F '=' '{print $2}')
  729. if [ ${#TEMP_VALUE} -gt 3 ]; then
  730. XMPP_ECC_CURVE=$TEMP_VALUE
  731. fi
  732. fi
  733. }
  734. function export_settings {
  735. if [ ! $EXPORT_FILE ]; then
  736. return
  737. fi
  738. cd $CURRENT_DIR
  739. if [ ! -f $EXPORT_FILE ]; then
  740. if [ "$SSL_PROTOCOLS" ]; then
  741. echo "SSL_PROTOCOLS=$SSL_PROTOCOLS" >> $EXPORT_FILE
  742. fi
  743. if [ $SSL_CIPHERS ]; then
  744. echo "SSL_CIPHERS=$SSL_CIPHERS" >> $EXPORT_FILE
  745. fi
  746. if [ $SSH_CIPHERS ]; then
  747. echo "SSH_CIPHERS=$SSH_CIPHERS" >> $EXPORT_FILE
  748. fi
  749. if [ $SSH_MACS ]; then
  750. echo "SSH_MACS=$SSH_MACS" >> $EXPORT_FILE
  751. fi
  752. if [ $SSH_KEX ]; then
  753. echo "SSH_KEX=$SSH_KEX" >> $EXPORT_FILE
  754. fi
  755. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  756. echo "SSH_HOST_KEY_ALGORITHMS=$SSH_HOST_KEY_ALGORITHMS" >> $EXPORT_FILE
  757. fi
  758. if [ $SSH_PASSWORDS ]; then
  759. echo "SSH_PASSWORDS=$SSH_PASSWORDS" >> $EXPORT_FILE
  760. fi
  761. if [ $XMPP_CIPHERS ]; then
  762. echo "XMPP_CIPHERS=$XMPP_CIPHERS" >> $EXPORT_FILE
  763. fi
  764. if [ $XMPP_ECC_CURVE ]; then
  765. echo "XMPP_ECC_CURVE=$XMPP_ECC_CURVE" >> $EXPORT_FILE
  766. fi
  767. echo "Security settings exported to $EXPORT_FILE"
  768. exit 0
  769. fi
  770. if [ "$SSL_PROTOCOLS" ]; then
  771. if grep -q "SSL_PROTOCOLS" $EXPORT_FILE; then
  772. sed -i "s|SSL_PROTOCOLS=.*|SSL_PROTOCOLS=$SSL_PROTOCOLS|g" $EXPORT_FILE
  773. else
  774. echo "SSL_PROTOCOLS=$SSL_PROTOCOLS" >> $EXPORT_FILE
  775. fi
  776. fi
  777. if [ $SSL_CIPHERS ]; then
  778. if grep -q "SSL_CIPHERS" $EXPORT_FILE; then
  779. sed -i "s|SSL_CIPHERS=.*|SSL_CIPHERS=$SSL_CIPHERS|g" $EXPORT_FILE
  780. else
  781. echo "SSL_CIPHERS=$SSL_CIPHERS" >> $EXPORT_FILE
  782. fi
  783. fi
  784. if [ $SSH_CIPHERS ]; then
  785. if grep -q "SSH_CIPHERS" $EXPORT_FILE; then
  786. sed -i "s|SSH_CIPHERS=.*|SSH_CIPHERS=$SSH_CIPHERS|g" $EXPORT_FILE
  787. else
  788. echo "SSH_CIPHERS=$SSH_CIPHERS" >> $EXPORT_FILE
  789. fi
  790. fi
  791. if [ $SSH_MACS ]; then
  792. if grep -q "SSH_MACS" $EXPORT_FILE; then
  793. sed -i "s|SSH_MACS=.*|SSH_MACS=$SSH_MACS|g" $EXPORT_FILE
  794. else
  795. echo "SSH_MACS=$SSH_MACS" >> $EXPORT_FILE
  796. fi
  797. fi
  798. if [ $SSH_KEX ]; then
  799. if grep -q "SSH_KEX" $EXPORT_FILE; then
  800. sed -i "s|SSH_KEX=.*|SSH_KEX=$SSH_KEX|g" $EXPORT_FILE
  801. else
  802. echo "SSH_KEX=$SSH_KEX" >> $EXPORT_FILE
  803. fi
  804. fi
  805. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  806. if grep -q "SSH_HOST_KEY_ALGORITHMS" $EXPORT_FILE; then
  807. sed -i "s|SSH_HOST_KEY_ALGORITHMS=.*|SSH_HOST_KEY_ALGORITHMS=$SSH_HOST_KEY_ALGORITHMS|g" $EXPORT_FILE
  808. else
  809. echo "SSH_HOST_KEY_ALGORITHMS=$SSH_HOST_KEY_ALGORITHMS" >> $EXPORT_FILE
  810. fi
  811. fi
  812. if [ $SSH_PASSWORDS ]; then
  813. if grep -q "SSH_PASSWORDS" $EXPORT_FILE; then
  814. sed -i "s|SSH_PASSWORDS=.*|SSH_PASSWORDS=$SSH_PASSWORDS|g" $EXPORT_FILE
  815. else
  816. echo "SSH_PASSWORDS=$SSH_PASSWORDS" >> $EXPORT_FILE
  817. fi
  818. fi
  819. if [ $XMPP_CIPHERS ]; then
  820. if grep -q "XMPP_CIPHERS" $EXPORT_FILE; then
  821. sed -i "s|XMPP_CIPHERS=.*|XMPP_CIPHERS=$XMPP_CIPHERS|g" $EXPORT_FILE
  822. else
  823. echo "XMPP_CIPHERS=$XMPP_CIPHERS" >> $EXPORT_FILE
  824. fi
  825. fi
  826. if [ $XMPP_ECC_CURVE ]; then
  827. if grep -q "XMPP_ECC_CURVE" $EXPORT_FILE; then
  828. sed -i "s|XMPP_ECC_CURVE=.*|XMPP_ECC_CURVE=$XMPP_ECC_CURVE|g" $EXPORT_FILE
  829. else
  830. echo "XMPP_ECC_CURVE=$XMPP_ECC_CURVE" >> $EXPORT_FILE
  831. fi
  832. fi
  833. echo $"Security settings exported to $EXPORT_FILE"
  834. exit 0
  835. }
  836. function refresh_gpg_keys {
  837. for d in /home/*/ ; do
  838. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  839. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  840. su -c 'gpg --refresh-keys' - $USERNAME
  841. fi
  842. done
  843. exit 0
  844. }
  845. function monkeysphere_sign_server_keys {
  846. server_keys_file=/home/$USER/.monkeysphere/server_keys
  847. if [ ! -f $server_keys_file ]; then
  848. exit 0
  849. fi
  850. keys_signed=
  851. while read line; do
  852. echo $line
  853. if [ ${#line} -gt 2 ]; then
  854. fpr=$(gpg --with-colons --fingerprint "$line" | grep fpr | head -n 1 | awk -F ':' '{print $10}')
  855. if [ ${#fpr} -gt 2 ]; then
  856. gpg --sign-key $fpr
  857. if [ "$?" = "0" ]; then
  858. gpg --update-trustdb
  859. keys_signed=1
  860. fi
  861. fi
  862. fi
  863. done <$server_keys_file
  864. if [ $keys_signed ]; then
  865. rm $server_keys_file
  866. fi
  867. exit 0
  868. }
  869. function blog_hash {
  870. # produces a hash corresponding to a blog password
  871. pass="$1"
  872. BLOGHASH_FILENAME=/usr/bin/bloghash
  873. echo '<?php' > $BLOGHASH_FILENAME
  874. echo 'parse_str(implode("&", array_slice($argv, 1)), $_GET);' >> $BLOGHASH_FILENAME
  875. echo '$password = $_GET["password"];' >> $BLOGHASH_FILENAME
  876. echo '$hash = password_hash($password, PASSWORD_BCRYPT);' >> $BLOGHASH_FILENAME
  877. echo 'if (password_verify($password, $hash)) {' >> $BLOGHASH_FILENAME
  878. echo ' echo $hash;' >> $BLOGHASH_FILENAME
  879. echo '}' >> $BLOGHASH_FILENAME
  880. echo '?>' >> $BLOGHASH_FILENAME
  881. php $BLOGHASH_FILENAME password="$pass"
  882. }
  883. function show_help {
  884. echo ''
  885. echo "${PROJECT_NAME}-sec"
  886. echo ''
  887. echo $'Alters the security settings'
  888. echo ''
  889. echo ''
  890. echo $' -h --help Show help'
  891. echo $' -e --export Export security settings to a file'
  892. echo $' -i --import Import security settings from a file'
  893. echo $' -r --refresh Refresh GPG keys for all users'
  894. echo $' -s --sign Sign monkeysphere server keys'
  895. echo $' --register [domain] Register a https domain with monkeysphere'
  896. echo $' -b --bloghash [password] Returns the hash of a password for the blog'
  897. echo ''
  898. exit 0
  899. }
  900. # Get the commandline options
  901. while [[ $# > 1 ]]
  902. do
  903. key="$1"
  904. case $key in
  905. -h|--help)
  906. show_help
  907. ;;
  908. # Export settings
  909. -e|--export)
  910. shift
  911. EXPORT_FILE="$1"
  912. ;;
  913. # Export settings
  914. -i|--import)
  915. shift
  916. IMPORT_FILE="$1"
  917. ;;
  918. # Refresh GPG keys
  919. -r|--refresh)
  920. shift
  921. refresh_gpg_keys
  922. ;;
  923. # register a website
  924. --register|--reg|--site)
  925. shift
  926. register_website "$1"
  927. ;;
  928. # user signs monkeysphere server keys
  929. -s|--sign)
  930. shift
  931. monkeysphere_sign_server_keys
  932. ;;
  933. # get a hash of the given blog password
  934. -b|--bloghash)
  935. shift
  936. blog_hash "$1"
  937. exit 0
  938. ;;
  939. *)
  940. # unknown option
  941. ;;
  942. esac
  943. shift
  944. done
  945. housekeeping
  946. get_website_settings
  947. get_imap_settings
  948. get_ssh_settings
  949. get_xmpp_settings
  950. import_settings
  951. export_settings
  952. interactive_setup
  953. change_website_settings
  954. change_imap_settings
  955. change_ssh_settings
  956. change_xmpp_settings
  957. regenerate_ssh_host_keys
  958. regenerate_dh_keys
  959. exit 0