freedombone-sec 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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 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. SSL_PROTOCOLS=
  31. SSL_CIPHERS=
  32. SSH_CIPHERS=
  33. SSH_MACS=
  34. SSH_KEX=
  35. SSH_HOST_KEY_ALGORITHMS=
  36. SSH_PASSWORDS=
  37. XMPP_CIPHERS=
  38. XMPP_ECC_CURVE=
  39. WEBSITES_DIRECTORY='/etc/nginx/sites-available'
  40. DOVECOT_CIPHERS='/etc/dovecot/conf.d/10-ssl.conf'
  41. SSH_CONFIG='/etc/ssh/sshd_config'
  42. XMPP_CONFIG='/etc/prosody/conf.avail/xmpp.cfg.lua'
  43. MINIMUM_LENGTH=6
  44. IMPORT_FILE=
  45. EXPORT_FILE=
  46. CURRENT_DIR=$(pwd)
  47. REGENERATE_SSH_HOST_KEYS="no"
  48. REGENERATE_DH_KEYS="no"
  49. DH_KEYLENGTH=3072
  50. function get_protocols_from_website {
  51. if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
  52. return
  53. fi
  54. SSL_PROTOCOLS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_protocols ' | awk -F "ssl_protocols " '{print $2}' | awk -F ';' '{print $1}')
  55. }
  56. function get_ciphers_from_website {
  57. if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
  58. return
  59. fi
  60. SSL_CIPHERS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_ciphers ' | awk -F "ssl_ciphers " '{print $2}' | awk -F "'" '{print $2}')
  61. }
  62. function get_website_settings {
  63. if [ ! -d $WEBSITES_DIRECTORY ]; then
  64. return
  65. fi
  66. cd $WEBSITES_DIRECTORY
  67. for file in `dir -d *` ; do
  68. get_protocols_from_website $file
  69. if [ ${#SSL_PROTOCOLS} -gt $MINIMUM_LENGTH ]; then
  70. get_ciphers_from_website $file
  71. if [ ${#SSL_CIPHERS} -gt $MINIMUM_LENGTH ]; then
  72. break
  73. else
  74. SSL_PROTOCOLS=""
  75. fi
  76. fi
  77. done
  78. }
  79. function get_imap_settings {
  80. if [ ! -f $DOVECOT_CIPHERS ]; then
  81. return
  82. fi
  83. # clear commented out cipher list
  84. sed -i "s|#ssl_cipher_list.*||g" $DOVECOT_CIPHERS
  85. if [ $SSL_CIPHERS ]; then
  86. return
  87. fi
  88. if [ ${#SSL_CIPHERS} -gt $MINIMUM_LENGTH ]; then
  89. return
  90. fi
  91. SSL_CIPHERS=$(cat $DOVECOT_CIPHERS | grep 'ssl_cipher_list' | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')
  92. }
  93. function get_xmpp_settings {
  94. if [ ! -f $XMPP_CONFIG ]; then
  95. return
  96. fi
  97. XMPP_CIPHERS=$(cat $XMPP_CONFIG | grep 'ciphers ' | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
  98. XMPP_ECC_CURVE=$(cat $XMPP_CONFIG | grep 'curve ' | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
  99. }
  100. function get_ssh_settings {
  101. if [ -f $SSH_CONFIG ]; then
  102. SSH_CIPHERS=$(cat $SSH_CONFIG | grep 'Ciphers ' | awk -F 'Ciphers ' '{print $2}')
  103. SSH_MACS=$(cat $SSH_CONFIG | grep 'MACs ' | awk -F 'MACs ' '{print $2}')
  104. SSH_KEX=$(cat $SSH_CONFIG | grep 'KexAlgorithms ' | awk -F 'KexAlgorithms ' '{print $2}')
  105. SSH_PASSWORDS=$(cat $SSH_CONFIG | grep 'PasswordAuthentication ' | awk -F 'PasswordAuthentication ' '{print $2}')
  106. fi
  107. if [ -f /etc/ssh/ssh_config ]; then
  108. SSH_HOST_KEY_ALGORITHMS=$(cat /etc/ssh/ssh_config | grep 'HostKeyAlgorithms ' | awk -F 'HostKeyAlgorithms ' '{print $2}')
  109. if [ ! $SSH_CIPHERS ]; then
  110. SSH_CIPHERS=$(cat /etc/ssh/ssh_config | grep 'Ciphers ' | awk -F 'Ciphers ' '{print $2}')
  111. fi
  112. if [ ! $SSH_MACS ]; then
  113. SSH_MACS=$(cat /etc/ssh/ssh_config | grep 'MACs ' | awk -F 'MACs ' '{print $2}')
  114. fi
  115. fi
  116. }
  117. function change_website_settings {
  118. if [ ! "$SSL_PROTOCOLS" ]; then
  119. return
  120. fi
  121. if [ ! $SSL_CIPHERS ]; then
  122. return
  123. fi
  124. if [ ${#SSL_PROTOCOLS} -lt $MINIMUM_LENGTH ]; then
  125. return
  126. fi
  127. if [ ${#SSL_CIPHERS} -lt $MINIMUM_LENGTH ]; then
  128. return
  129. fi
  130. if [ ! -d $WEBSITES_DIRECTORY ]; then
  131. return
  132. fi
  133. cd $WEBSITES_DIRECTORY
  134. for file in `dir -d *` ; do
  135. sed -i "s|ssl_protocols .*|ssl_protocols $SSL_PROTOCOLS;|g" $WEBSITES_DIRECTORY/$file
  136. sed -i "s|ssl_ciphers .*|ssl_ciphers '$SSL_CIPHERS';|g" $WEBSITES_DIRECTORY/$file
  137. done
  138. service nginx restart
  139. echo 'Web security settings changed'
  140. }
  141. function change_imap_settings {
  142. if [ ! -f $DOVECOT_CIPHERS ]; then
  143. return
  144. fi
  145. if [ ! $SSL_CIPHERS ]; then
  146. return
  147. fi
  148. if [ ${#SSL_CIPHERS} -lt $MINIMUM_LENGTH ]; then
  149. return
  150. fi
  151. sed -i "s|ssl_cipher_list.*|ssl_cipher_list = '$SSL_CIPHERS'|g" $DOVECOT_CIPHERS
  152. sed -i "s|ssl_protocols.*|ssl_protocols = '$SSL_PROTOCOLS'|g" $DOVECOT_CIPHERS
  153. service dovecot restart
  154. echo 'imap security settings changed'
  155. }
  156. function change_ssh_settings {
  157. if [ -f /etc/ssh/ssh_config ]; then
  158. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  159. sed -i "s|HostKeyAlgorithms .*|HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS|g" /etc/ssh/ssh_config
  160. echo 'ssh client security settings changed'
  161. fi
  162. fi
  163. if [ -f $SSH_CONFIG ]; then
  164. if [ ! $SSH_CIPHERS ]; then
  165. return
  166. fi
  167. if [ ! $SSH_MACS ]; then
  168. return
  169. fi
  170. if [ ! $SSH_KEX ]; then
  171. return
  172. fi
  173. if [ ! $SSH_PASSWORDS ]; then
  174. return
  175. fi
  176. sed -i "s|Ciphers .*|Ciphers $SSH_CIPHERS|g" $SSH_CONFIG
  177. sed -i "s|MACs .*|MACs $SSH_MACS|g" $SSH_CONFIG
  178. sed -i "s|KexAlgorithms .*|KexAlgorithms $SSH_KEX|g" $SSH_CONFIG
  179. sed -i "s|PasswordAuthentication .*|PasswordAuthentication $SSH_PASSWORDS|g" $SSH_CONFIG
  180. service ssh restart
  181. echo 'ssh server security settings changed'
  182. fi
  183. }
  184. function change_xmpp_settings {
  185. if [ ! -f $XMPP_CONFIG ]; then
  186. return
  187. fi
  188. if [ ! $XMPP_CIPHERS ]; then
  189. return
  190. fi
  191. if [ ! $XMPP_ECC_CURVE ]; then
  192. return
  193. fi
  194. sed -i "s|ciphers =.*|ciphers = \"$XMPP_CIPHERS\";|g" $XMPP_CONFIG
  195. sed -i "s|curve =.*|curve = \"$XMPP_ECC_CURVE\";|g" $XMPP_CONFIG
  196. service prosody restart
  197. echo 'xmpp security settings changed'
  198. }
  199. function interactive_setup {
  200. if [ $SSL_CIPHERS ]; then
  201. data=$(tempfile 2>/dev/null)
  202. trap "rm -f $data" 0 1 2 5 15
  203. dialog --backtitle "Freedombone Security Configuration" \
  204. --form "\nWeb/IMAP Ciphers:" 10 95 2 \
  205. "Protocols:" 1 1 "$SSL_PROTOCOLS" 1 15 90 90 \
  206. "Ciphers:" 2 1 "$SSL_CIPHERS" 2 15 90 512 \
  207. 2> $data
  208. sel=$?
  209. case $sel in
  210. 1) SSL_PROTOCOLS=$(cat $data | sed -n 1p)
  211. SSL_CIPHERS=$(cat $data | sed -n 2p)
  212. ;;
  213. 255) exit 0;;
  214. esac
  215. fi
  216. data=$(tempfile 2>/dev/null)
  217. trap "rm -f $data" 0 1 2 5 15
  218. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  219. dialog --backtitle "Freedombone Security Configuration" \
  220. --form "\nSecure Shell Ciphers:" 13 95 4 \
  221. "Ciphers:" 1 1 "$SSH_CIPHERS" 1 15 90 512 \
  222. "MACs:" 2 1 "$SSH_MACS" 2 15 90 512 \
  223. "KEX:" 3 1 "$SSH_KEX" 3 15 90 512 \
  224. "Host key algorithms:" 4 1 "$SSH_HOST_KEY_ALGORITHMS" 4 15 90 512 \
  225. 2> $data
  226. sel=$?
  227. case $sel in
  228. 1) SSH_CIPHERS=$(cat $data | sed -n 1p)
  229. SSH_MACS=$(cat $data | sed -n 2p)
  230. SSH_KEX=$(cat $data | sed -n 3p)
  231. SSH_HOST_KEY_ALGORITHMS=$(cat $data | sed -n 4p)
  232. ;;
  233. 255) exit 0;;
  234. esac
  235. else
  236. dialog --backtitle "Freedombone Security Configuration" \
  237. --form "\nSecure Shell Ciphers:" 11 95 3 \
  238. "Ciphers:" 1 1 "$SSH_CIPHERS" 1 15 90 512 \
  239. "MACs:" 2 1 "$SSH_MACS" 2 15 90 512 \
  240. "KEX:" 3 1 "$SSH_KEX" 3 15 90 512 \
  241. 2> $data
  242. sel=$?
  243. case $sel in
  244. 1) SSH_CIPHERS=$(cat $data | sed -n 1p)
  245. SSH_MACS=$(cat $data | sed -n 2p)
  246. SSH_KEX=$(cat $data | sed -n 3p)
  247. ;;
  248. 255) exit 0;;
  249. esac
  250. fi
  251. if [[ $SSH_PASSWORDS == "yes" ]]; then
  252. dialog --title "SSH Passwords" \
  253. --backtitle "Freedombone Security Configuration" \
  254. --yesno "\nAllow SSH login using passwords?" 7 60
  255. else
  256. dialog --title "SSH Passwords" \
  257. --backtitle "Freedombone Security Configuration" \
  258. --defaultno \
  259. --yesno "\nAllow SSH login using passwords?" 7 60
  260. fi
  261. sel=$?
  262. case $sel in
  263. 0) SSH_PASSWORDS="yes";;
  264. 1) SSH_PASSWORDS="no";;
  265. 255) exit 0;;
  266. esac
  267. if [ $XMPP_CIPHERS ]; then
  268. data=$(tempfile 2>/dev/null)
  269. trap "rm -f $data" 0 1 2 5 15
  270. dialog --backtitle "Freedombone Security Configuration" \
  271. --form "\nXMPP Ciphers:" 10 95 2 \
  272. "Ciphers:" 1 1 "$XMPP_CIPHERS" 1 15 90 512 \
  273. "ECC Curve:" 2 1 "$XMPP_ECC_CURVE" 2 15 50 50 \
  274. 2> $data
  275. sel=$?
  276. case $sel in
  277. 1) XMPP_CIPHERS=$(cat $data | sed -n 1p)
  278. XMPP_ECC_CURVE=$(cat $data | sed -n 2p)
  279. ;;
  280. 255) exit 0;;
  281. esac
  282. fi
  283. dialog --title "Final Confirmation" \
  284. --backtitle "Freedombone Security Configuration" \
  285. --defaultno \
  286. --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
  287. sel=$?
  288. case $sel in
  289. 1) clear
  290. echo 'Exiting without changing security settings'
  291. exit 0;;
  292. 255) clear
  293. echo 'Exiting without changing security settings'
  294. exit 0;;
  295. esac
  296. clear
  297. }
  298. function regenerate_ssh_host_keys {
  299. if [[ $REGENERATE_SSH_HOST_KEYS == "yes" ]]; then
  300. rm -f /etc/ssh/ssh_host_*
  301. dpkg-reconfigure openssh-server
  302. echo 'ssh host keys regenerated'
  303. # remove small moduli
  304. awk '$5 > 2000' /etc/ssh/moduli > ~/moduli
  305. mv ~/moduli /etc/ssh/moduli
  306. echo 'ssh small moduli removed'
  307. systemctl restart ssh
  308. fi
  309. }
  310. function regenerate_dh_keys {
  311. if [[ $REGENERATE_DH_KEYS == "yes" ]]; then
  312. if [ ! -d /etc/ssl/mycerts ]; then
  313. echo 'No dhparam certificates were found'
  314. return
  315. fi
  316. data=$(tempfile 2>/dev/null)
  317. trap "rm -f $data" 0 1 2 5 15
  318. dialog --backtitle "Freedombone Security Configuration" \
  319. --title "Diffie-Hellman key length" \
  320. --radiolist "The smaller length is better suited to low power embedded systems:" 10 40 2 \
  321. 1 "1024 bits" off \
  322. 2 "3072 bits" on 2> $data
  323. sel=$?
  324. case $sel in
  325. 1) exit 1;;
  326. 255) exit 1;;
  327. esac
  328. case $(cat $data) in
  329. 1) DH_KEYLENGTH=1024;;
  330. 2) DH_KEYLENGTH=3072;;
  331. esac
  332. ctr=0
  333. for file in /etc/ssl/mycerts/*
  334. do
  335. if [[ -f $file ]]; then
  336. filename=/etc/ssl/certs/$(echo $file | awk -F '/etc/ssl/mycerts/' '{print $2}' | awk -F '.crt' '{print $1}').dhparam
  337. if [ -f $filename ]; then
  338. openssl dhparam -check -text -5 $DH_KEYLENGTH -out $filename
  339. ctr=$((ctr + 1))
  340. fi
  341. fi
  342. done
  343. echo "$ctr dhparam certificates were regenerated"
  344. fi
  345. }
  346. function housekeeping {
  347. cmd=(dialog --separate-output \
  348. --backtitle "Freedombone Security Configuration" \
  349. --title "Housekeeping options" \
  350. --checklist "If you don't need to do any of these things then just press Enter:" 10 76 16)
  351. options=(1 "Regenerate ssh host keys" off
  352. 2 "Regenerate Diffie-Hellman keys" off)
  353. choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
  354. clear
  355. for choice in $choices
  356. do
  357. case $choice in
  358. 1)
  359. REGENERATE_SSH_HOST_KEYS="yes"
  360. ;;
  361. 2)
  362. REGENERATE_DH_KEYS="yes"
  363. ;;
  364. esac
  365. done
  366. }
  367. function import_settings {
  368. cd $CURRENT_DIR
  369. if [ ! $IMPORT_FILE ]; then
  370. return
  371. fi
  372. if [ ! -f $IMPORT_FILE ]; then
  373. echo "Import file $IMPORT_FILE not found"
  374. exit 6393
  375. fi
  376. if grep -q "SSL_PROTOCOLS" $IMPORT_FILE; then
  377. TEMP_VALUE=$(grep "SSL_PROTOCOLS" $IMPORT_FILE | awk -F '=' '{print $2}')
  378. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  379. SSL_PROTOCOLS=$TEMP_VALUE
  380. fi
  381. fi
  382. if grep -q "SSL_CIPHERS" $IMPORT_FILE; then
  383. TEMP_VALUE=$(grep "SSL_CIPHERS" $IMPORT_FILE | awk -F '=' '{print $2}')
  384. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  385. SSL_CIPHERS=$TEMP_VALUE
  386. fi
  387. fi
  388. if grep -q "SSH_CIPHERS" $IMPORT_FILE; then
  389. TEMP_VALUE=$(grep "SSH_CIPHERS" $IMPORT_FILE | awk -F '=' '{print $2}')
  390. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  391. SSH_CIPHERS=$TEMP_VALUE
  392. fi
  393. fi
  394. if grep -q "SSH_MACS" $IMPORT_FILE; then
  395. TEMP_VALUE=$(grep "SSH_MACS" $IMPORT_FILE | awk -F '=' '{print $2}')
  396. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  397. SSH_MACS=$TEMP_VALUE
  398. fi
  399. fi
  400. if grep -q "SSH_KEX" $IMPORT_FILE; then
  401. TEMP_VALUE=$(grep "SSH_KEX" $IMPORT_FILE | awk -F '=' '{print $2}')
  402. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  403. SSH_KEX=$TEMP_VALUE
  404. fi
  405. fi
  406. if grep -q "SSH_HOST_KEY_ALGORITHMS" $IMPORT_FILE; then
  407. TEMP_VALUE=$(grep "SSH_HOST_KEY_ALGORITHMS" $IMPORT_FILE | awk -F '=' '{print $2}')
  408. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  409. SSH_HOST_KEY_ALGORITHMS=$TEMP_VALUE
  410. fi
  411. fi
  412. if grep -q "SSH_PASSWORDS" $IMPORT_FILE; then
  413. TEMP_VALUE=$(grep "SSH_PASSWORDS" $IMPORT_FILE | awk -F '=' '{print $2}')
  414. if [[ $TEMP_VALUE == "yes" || $TEMP_VALUE == "no" ]]; then
  415. SSH_PASSWORDS=$TEMP_VALUE
  416. fi
  417. fi
  418. if grep -q "XMPP_CIPHERS" $IMPORT_FILE; then
  419. TEMP_VALUE=$(grep "XMPP_CIPHERS" $IMPORT_FILE | awk -F '=' '{print $2}')
  420. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  421. XMPP_CIPHERS=$TEMP_VALUE
  422. fi
  423. fi
  424. if grep -q "XMPP_ECC_CURVE" $IMPORT_FILE; then
  425. TEMP_VALUE=$(grep "XMPP_ECC_CURVE" $IMPORT_FILE | awk -F '=' '{print $2}')
  426. if [ ${#TEMP_VALUE} -gt 3 ]; then
  427. XMPP_ECC_CURVE=$TEMP_VALUE
  428. fi
  429. fi
  430. }
  431. function export_settings {
  432. if [ ! $EXPORT_FILE ]; then
  433. return
  434. fi
  435. cd $CURRENT_DIR
  436. if [ ! -f $EXPORT_FILE ]; then
  437. if [ "$SSL_PROTOCOLS" ]; then
  438. echo "SSL_PROTOCOLS=$SSL_PROTOCOLS" >> $EXPORT_FILE
  439. fi
  440. if [ $SSL_CIPHERS ]; then
  441. echo "SSL_CIPHERS=$SSL_CIPHERS" >> $EXPORT_FILE
  442. fi
  443. if [ $SSH_CIPHERS ]; then
  444. echo "SSH_CIPHERS=$SSH_CIPHERS" >> $EXPORT_FILE
  445. fi
  446. if [ $SSH_MACS ]; then
  447. echo "SSH_MACS=$SSH_MACS" >> $EXPORT_FILE
  448. fi
  449. if [ $SSH_KEX ]; then
  450. echo "SSH_KEX=$SSH_KEX" >> $EXPORT_FILE
  451. fi
  452. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  453. echo "SSH_HOST_KEY_ALGORITHMS=$SSH_HOST_KEY_ALGORITHMS" >> $EXPORT_FILE
  454. fi
  455. if [ $SSH_PASSWORDS ]; then
  456. echo "SSH_PASSWORDS=$SSH_PASSWORDS" >> $EXPORT_FILE
  457. fi
  458. if [ $XMPP_CIPHERS ]; then
  459. echo "XMPP_CIPHERS=$XMPP_CIPHERS" >> $EXPORT_FILE
  460. fi
  461. if [ $XMPP_ECC_CURVE ]; then
  462. echo "XMPP_ECC_CURVE=$XMPP_ECC_CURVE" >> $EXPORT_FILE
  463. fi
  464. echo "Security settings exported to $EXPORT_FILE"
  465. exit 0
  466. fi
  467. if [ "$SSL_PROTOCOLS" ]; then
  468. if grep -q "SSL_PROTOCOLS" $EXPORT_FILE; then
  469. sed -i "s|SSL_PROTOCOLS=.*|SSL_PROTOCOLS=$SSL_PROTOCOLS|g" $EXPORT_FILE
  470. else
  471. echo "SSL_PROTOCOLS=$SSL_PROTOCOLS" >> $EXPORT_FILE
  472. fi
  473. fi
  474. if [ $SSL_CIPHERS ]; then
  475. if grep -q "SSL_CIPHERS" $EXPORT_FILE; then
  476. sed -i "s|SSL_CIPHERS=.*|SSL_CIPHERS=$SSL_CIPHERS|g" $EXPORT_FILE
  477. else
  478. echo "SSL_CIPHERS=$SSL_CIPHERS" >> $EXPORT_FILE
  479. fi
  480. fi
  481. if [ $SSH_CIPHERS ]; then
  482. if grep -q "SSH_CIPHERS" $EXPORT_FILE; then
  483. sed -i "s|SSH_CIPHERS=.*|SSH_CIPHERS=$SSH_CIPHERS|g" $EXPORT_FILE
  484. else
  485. echo "SSH_CIPHERS=$SSH_CIPHERS" >> $EXPORT_FILE
  486. fi
  487. fi
  488. if [ $SSH_MACS ]; then
  489. if grep -q "SSH_MACS" $EXPORT_FILE; then
  490. sed -i "s|SSH_MACS=.*|SSH_MACS=$SSH_MACS|g" $EXPORT_FILE
  491. else
  492. echo "SSH_MACS=$SSH_MACS" >> $EXPORT_FILE
  493. fi
  494. fi
  495. if [ $SSH_KEX ]; then
  496. if grep -q "SSH_KEX" $EXPORT_FILE; then
  497. sed -i "s|SSH_KEX=.*|SSH_KEX=$SSH_KEX|g" $EXPORT_FILE
  498. else
  499. echo "SSH_KEX=$SSH_KEX" >> $EXPORT_FILE
  500. fi
  501. fi
  502. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  503. if grep -q "SSH_HOST_KEY_ALGORITHMS" $EXPORT_FILE; then
  504. sed -i "s|SSH_HOST_KEY_ALGORITHMS=.*|SSH_HOST_KEY_ALGORITHMS=$SSH_HOST_KEY_ALGORITHMS|g" $EXPORT_FILE
  505. else
  506. echo "SSH_HOST_KEY_ALGORITHMS=$SSH_HOST_KEY_ALGORITHMS" >> $EXPORT_FILE
  507. fi
  508. fi
  509. if [ $SSH_PASSWORDS ]; then
  510. if grep -q "SSH_PASSWORDS" $EXPORT_FILE; then
  511. sed -i "s|SSH_PASSWORDS=.*|SSH_PASSWORDS=$SSH_PASSWORDS|g" $EXPORT_FILE
  512. else
  513. echo "SSH_PASSWORDS=$SSH_PASSWORDS" >> $EXPORT_FILE
  514. fi
  515. fi
  516. if [ $XMPP_CIPHERS ]; then
  517. if grep -q "XMPP_CIPHERS" $EXPORT_FILE; then
  518. sed -i "s|XMPP_CIPHERS=.*|XMPP_CIPHERS=$XMPP_CIPHERS|g" $EXPORT_FILE
  519. else
  520. echo "XMPP_CIPHERS=$XMPP_CIPHERS" >> $EXPORT_FILE
  521. fi
  522. fi
  523. if [ $XMPP_ECC_CURVE ]; then
  524. if grep -q "XMPP_ECC_CURVE" $EXPORT_FILE; then
  525. sed -i "s|XMPP_ECC_CURVE=.*|XMPP_ECC_CURVE=$XMPP_ECC_CURVE|g" $EXPORT_FILE
  526. else
  527. echo "XMPP_ECC_CURVE=$XMPP_ECC_CURVE" >> $EXPORT_FILE
  528. fi
  529. fi
  530. echo "Security settings exported to $EXPORT_FILE"
  531. exit 0
  532. }
  533. function show_help {
  534. echo ''
  535. echo 'freedombone-sec'
  536. echo ''
  537. echo 'Alters the security settings'
  538. echo ''
  539. echo ''
  540. echo ' -h --help Show help'
  541. echo ' -e --export Export security settings to a file'
  542. echo ' -i --import Import security settings from a file'
  543. echo ''
  544. exit 0
  545. }
  546. # Get the commandline options
  547. while [[ $# > 1 ]]
  548. do
  549. key="$1"
  550. case $key in
  551. -h|--help)
  552. show_help
  553. ;;
  554. # Export settings
  555. -e|--export)
  556. shift
  557. EXPORT_FILE="$1"
  558. ;;
  559. # Export settings
  560. -i|--import)
  561. shift
  562. IMPORT_FILE="$1"
  563. ;;
  564. *)
  565. # unknown option
  566. ;;
  567. esac
  568. shift
  569. done
  570. housekeeping
  571. get_website_settings
  572. get_imap_settings
  573. get_ssh_settings
  574. get_xmpp_settings
  575. import_settings
  576. export_settings
  577. interactive_setup
  578. change_website_settings
  579. change_imap_settings
  580. change_ssh_settings
  581. change_xmpp_settings
  582. regenerate_ssh_host_keys
  583. regenerate_dh_keys
  584. exit 0