Quellcode durchsuchen

Interactive security settings modification

Bob Mottram vor 10 Jahren
Ursprung
Commit
22e24ed7c7
1 geänderte Dateien mit 157 neuen und 8 gelöschten Zeilen
  1. 157
    8
      src/freedombone-sec

+ 157
- 8
src/freedombone-sec Datei anzeigen

@@ -39,9 +39,10 @@ SSH_HOST_KEY_ALGORITHMS=
39 39
 XMPP_CIPHERS=
40 40
 XMPP_ECC_CURVE=
41 41
 
42
-WIKI_DOMAIN_NAME=
43 42
 WEBSITES_DIRECTORY='/etc/nginx/sites-available'
44 43
 DOVECOT_CIPHERS='/etc/dovecot/conf.d/10-ssl.conf'
44
+SSH_CONFIG='/etc/ssh/sshd_config'
45
+XMPP_CONFIG='/etc/prosody/conf.avail/xmpp.cfg.lua'
45 46
 
46 47
 MINIMUM_LENGTH=6
47 48
 
@@ -49,14 +50,14 @@ function get_protocols_from_website {
49 50
   if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
50 51
       return
51 52
   fi
52
-  SSL_PROTOCOLS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_protocols' | awk -F "ssl_protocols" '{print $2}' | awk -F ';' '{print $1}')
53
+  SSL_PROTOCOLS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_protocols ' | awk -F "ssl_protocols " '{print $2}' | awk -F ';' '{print $1}')
53 54
 }
54 55
 
55 56
 function get_ciphers_from_website {
56 57
   if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
57 58
       return
58 59
   fi
59
-  SSL_CIPHERS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_ciphers' | awk -F "ssl_ciphers" '{print $2}' | awk -F "'" '{print $2}')
60
+  SSL_CIPHERS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_ciphers ' | awk -F "ssl_ciphers " '{print $2}' | awk -F "'" '{print $2}')
60 61
 }
61 62
 
62 63
 function get_website_settings {
@@ -84,17 +85,42 @@ function get_imap_settings {
84 85
   fi
85 86
   # clear commented out cipher list
86 87
   sed -i "s|#ssl_cipher_list.*||g" $DOVECOT_CIPHERS
87
-  if [ ! $SSL_CIPHERS ]; then
88
+  if [ $SSL_CIPHERS ]; then
88 89
       return
89 90
   fi
90
-  if [ ${#SSL_CIPHERS} -lt $MINIMUM_LENGTH ]; then
91
+  if [ ${#SSL_CIPHERS} -gt $MINIMUM_LENGTH ]; then
91 92
       return
92 93
   fi
93 94
   SSL_CIPHERS=$(cat $DOVECOT_CIPHERS | grep 'ssl_cipher_list' | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')
94 95
 }
95 96
 
97
+function get_xmpp_settings {
98
+  if [ ! -f $XMPP_CONFIG ]; then
99
+      return
100
+  fi
101
+  XMPP_CIPHERS=$(cat $XMPP_CONFIG | grep 'ciphers ' | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
102
+  XMPP_ECC_CURVE=$(cat $XMPP_CONFIG | grep 'curve ' | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
103
+}
104
+
105
+function get_ssh_settings {
106
+  if [ -f $SSH_CONFIG ]; then
107
+      SSH_CIPHERS=$(cat $SSH_CONFIG | grep 'Ciphers ' | awk -F 'Ciphers ' '{print $2}')
108
+      SSH_MACS=$(cat $SSH_CONFIG | grep 'MACs ' | awk -F 'MACs ' '{print $2}')
109
+      SSH_KEX=$(cat $SSH_CONFIG | grep 'KexAlgorithms ' | awk -F 'KexAlgorithms ' '{print $2}')
110
+  fi
111
+  if [ -f /etc/ssh/ssh_config ]; then
112
+      SSH_HOST_KEY_ALGORITHMS=$(cat /etc/ssh/ssh_config | grep 'HostKeyAlgorithms ' | awk -F 'HostKeyAlgorithms ' '{print $2}')
113
+      if [ ! $SSH_CIPHERS ]; then
114
+          SSH_CIPHERS=$(cat /etc/ssh/ssh_config | grep 'Ciphers ' | awk -F 'Ciphers ' '{print $2}')
115
+      fi
116
+      if [ ! $SSH_MACS ]; then
117
+          SSH_MACS=$(cat /etc/ssh/ssh_config | grep 'MACs ' | awk -F 'MACs ' '{print $2}')
118
+      fi
119
+  fi
120
+}
121
+
96 122
 function change_website_settings {
97
-  if [ ! $SSL_PROTOCOLS ]; then
123
+  if [ ! "$SSL_PROTOCOLS" ]; then
98 124
       return
99 125
   fi
100 126
   if [ ! $SSL_CIPHERS ]; then
@@ -116,6 +142,7 @@ function change_website_settings {
116 142
       sed -i "s|ssl_ciphers .*|ssl_ciphers '$SSL_CIPHERS';|g" $WEBSITES_DIRECTORY/$file
117 143
   done
118 144
   service nginx restart
145
+  echo 'Web security settings changed'
119 146
 }
120 147
 
121 148
 function change_imap_settings {
@@ -130,6 +157,122 @@ function change_imap_settings {
130 157
   fi
131 158
   sed -i "s|ssl_cipher_list.*|ssl_cipher_list = '$SSL_CIPHERS'|g" $DOVECOT_CIPHERS
132 159
   service dovecot restart
160
+  echo 'imap security settings changed'
161
+}
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
+
181
+      sed -i "s|Ciphers .*|Ciphers $SSH_CIPHERS|g" $SSH_CONFIG
182
+      sed -i "s|MACs .*|MACs $SSH_MACS|g" $SSH_CONFIG
183
+      sed -i "s|KexAlgorithms .*|KexAlgorithms $SSH_KEX|g" $SSH_CONFIG
184
+      service ssh restart
185
+      echo 'ssh server security settings changed'
186
+  fi
187
+}
188
+
189
+function change_xmpp_settings {
190
+  if [ ! -f $XMPP_CONFIG ]; then
191
+      return
192
+  fi
193
+  if [ ! $XMPP_CIPHERS ]; then
194
+      return
195
+  fi
196
+  if [ ! $XMPP_ECC_CURVE ]; then
197
+      return
198
+  fi
199
+  sed -i "s|ciphers =.*|ciphers = \"$XMPP_CIPHERS\";|g" $XMPP_CONFIG
200
+  sed -i "s|curve =.*|curve = \"$XMPP_ECC_CURVE\";|g" $XMPP_CONFIG
201
+  service prosody restart
202
+  echo 'xmpp security settings changed'
203
+}
204
+
205
+function interactive_setup {
206
+  if [ $SSL_CIPHERS ]; then
207
+      data=$(tempfile 2>/dev/null)
208
+      trap "rm -f $data" 0 1 2 5 15
209
+      dialog --backtitle "Freedombone Security Configuration" \
210
+          --form "\nWeb/IMAP Ciphers:" 10 95 2 \
211
+          "Protocols:" 1 1 "$SSL_PROTOCOLS" 1 15 90 90 \
212
+          "Ciphers:" 2 1 "$SSL_CIPHERS" 2 15 90 512 \
213
+          2> $data
214
+      sel=$?
215
+      case $sel in
216
+          1) SSL_PROTOCOLS=$(cat $data | sed -n 1p)
217
+             SSL_CIPHERS=$(cat $data | sed -n 2p)
218
+             ;;
219
+          255) exit 0;;
220
+      esac
221
+  fi
222
+
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
+
259
+  if [ $XMPP_CIPHERS ]; then
260
+      data=$(tempfile 2>/dev/null)
261
+      trap "rm -f $data" 0 1 2 5 15
262
+      dialog --backtitle "Freedombone Security Configuration" \
263
+          --form "\nXMPP Ciphers:" 10 95 2 \
264
+          "Ciphers:" 1 1 "$XMPP_CIPHERS" 1 15 90 512 \
265
+          "ECC Curve:" 2 1 "$XMPP_ECC_CURVE" 2 15 50 50 \
266
+          2> $data
267
+      sel=$?
268
+      case $sel in
269
+          1) XMPP_CIPHERS=$(cat $data | sed -n 1p)
270
+             XMPP_ECC_CURVE=$(cat $data | sed -n 2p)
271
+             ;;
272
+          255) exit 0;;
273
+      esac
274
+  fi
275
+  clear
133 276
 }
134 277
 
135 278
 while [[ $# > 1 ]]
@@ -153,6 +296,12 @@ shift
153 296
 done
154 297
 
155 298
 get_website_settings
156
-#change_website_settings
157
-#change_imap_settings
299
+get_imap_settings
300
+get_ssh_settings
301
+get_xmpp_settings
302
+interactive_setup
303
+change_website_settings
304
+change_imap_settings
305
+change_ssh_settings
306
+change_xmpp_settings
158 307
 exit 0