Pārlūkot izejas kodu

ssh improvements

Bob Mottram 10 gadus atpakaļ
vecāks
revīzija
7128f45540
1 mainītis faili ar 41 papildinājumiem un 4 dzēšanām
  1. 41
    4
      src/freedombone

+ 41
- 4
src/freedombone Parādīt failu

@@ -226,10 +226,11 @@ SSL_PROTOCOLS="TLSv1 TLSv1.1 TLSv1.2"
226 226
 # list of ciphers to use.  See bettercrypto.org recommendations
227 227
 SSL_CIPHERS="EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA"
228 228
 
229
-# ssh ciphers
230
-SSH_CIPHERS="aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes128-ctr"
231
-SSH_MACS="hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160"
232
-SSH_KEX="diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1"
229
+# ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
230
+SSH_CIPHERS="chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr"
231
+SSH_MACS="hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,umac-128@openssh.com"
232
+SSH_KEX="curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256"
233
+SSH_HOST_KEY_ALGORITHMS="ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-ed25519,ssh-rsa"
233 234
 
234 235
 # xmpp ciphers and curve
235 236
 XMPP_CIPHERS='"EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA"'
@@ -4256,12 +4257,48 @@ function configure_ssh {
4256 4257
   reboot
4257 4258
 }
4258 4259
 
4260
+# see https://stribika.github.io/2015/01/04/secure-secure-shell.html
4261
+function ssh_remove_small_moduli {
4262
+  awk '$5 > 2000' /etc/ssh/moduli > ~/moduli
4263
+  if [[ $((wc -l ~/moduli | awk -F ' ' '{print $1}')) < 150 ]]; then
4264
+      echo 'Not enough moduli > 2000'
4265
+      exit 57824
4266
+  fi
4267
+  mv ~/moduli /etc/ssh/moduli
4268
+}
4269
+
4270
+function configure_ssh_client {
4271
+  if grep -Fxq "configure_ssh_client" $COMPLETION_FILE; then
4272
+      return
4273
+  fi
4274
+  #sed 's/#   PasswordAuthentication.*/   PasswordAuthentication no/g' /etc/ssh/ssh_config
4275
+  #sed 's/#   ChallengeResponseAuthentication.*/   ChallengeResponseAuthentication no/g' /etc/ssh/ssh_config
4276
+  sed "s/#   HostKeyAlgorithms.*/   HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
4277
+  sed "s/#   Ciphers.*/   Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
4278
+  sed "s/#   MACs.*/   MACs $SSH_MACS/g" /etc/ssh/ssh_config
4279
+  if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
4280
+      echo "   HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> /etc/ssh/ssh_config
4281
+  fi
4282
+  sed "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
4283
+  if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
4284
+      echo "   Ciphers $SSH_CIPHERS" >> /etc/ssh/ssh_config
4285
+  fi
4286
+  sed "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
4287
+  if ! grep -q "MACs " /etc/ssh/ssh_config; then
4288
+      echo "   MACs $SSH_MACS" >> /etc/ssh/ssh_config
4289
+  fi
4290
+  ssh-keygen -t ed25519 -o -a 100
4291
+  ssh-keygen -t rsa -b 4096 -o -a 100
4292
+  echo 'configure_ssh_client' >> $COMPLETION_FILE
4293
+}
4294
+
4259 4295
 function regenerate_ssh_keys {
4260 4296
   if grep -Fxq "regenerate_ssh_keys" $COMPLETION_FILE; then
4261 4297
       return
4262 4298
   fi
4263 4299
   rm -f /etc/ssh/ssh_host_*
4264 4300
   dpkg-reconfigure openssh-server
4301
+  ssh_remove_small_moduli
4265 4302
   service ssh restart
4266 4303
   echo 'regenerate_ssh_keys' >> $COMPLETION_FILE
4267 4304
 }