freedombone-client 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. PROJECT_NAME='freedombone'
  29. export TEXTDOMAIN=${PROJECT_NAME}-client
  30. export TEXTDOMAINDIR="/usr/share/locale"
  31. CURR_USER=$USER
  32. MESH_CLIENT_INSTALL=
  33. # Version number of this script
  34. VERSION="1.01"
  35. # get the main project file, so that some values can be extracted
  36. MAIN_PROJECT_FILE=/usr/local/bin/${PROJECT_NAME}
  37. if [ ! -f $MAIN_PROJECT_FILE ]; then
  38. MAIN_PROJECT_FILE=/usr/bin/${PROJECT_NAME}
  39. fi
  40. if [ ! -f $MAIN_PROJECT_FILE ]; then
  41. echo "The main project file $MAIN_PROJECT_FILE was not found"
  42. exit 72529
  43. fi
  44. # ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
  45. SSH_CIPHERS=$(cat $MAIN_PROJECT_FILE | grep 'SSH_CIPHERS=' | head -n 1 | awk -F '"' '{print $2}')
  46. SSH_MACS=$(cat $MAIN_PROJECT_FILE | grep 'SSH_MACS=' | head -n 1 | awk -F '"' '{print $2}')
  47. SSH_KEX=$(cat $MAIN_PROJECT_FILE | grep 'SSH_KEX=' | head -n 1 | awk -F '"' '{print $2}')
  48. SSH_HOST_KEY_ALGORITHMS=$(cat $MAIN_PROJECT_FILE | grep 'SSH_HOST_KEY_ALGORITHMS=' | head -n 1 | awk -F '"' '{print $2}')
  49. # see https://stribika.github.io/2015/01/04/secure-secure-shell.html
  50. function ssh_remove_small_moduli {
  51. sudo awk '$5 > 2000' /etc/ssh/moduli > /home/$CURR_USER/moduli
  52. sudo mv /home/$CURR_USER/moduli /etc/ssh/moduli
  53. }
  54. function configure_ssh_client {
  55. #sudo sed -i 's/# PasswordAuthentication.*/ PasswordAuthentication no/g' /etc/ssh/ssh_config
  56. #sudo sed -i 's/# ChallengeResponseAuthentication.*/ ChallengeResponseAuthentication no/g' /etc/ssh/ssh_config
  57. sudo sed -i "s/# HostKeyAlgorithms.*/ HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
  58. sudo sed -i "s/# Ciphers.*/ Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
  59. sudo sed -i "s/# MACs.*/ MACs $SSH_MACS/g" /etc/ssh/ssh_config
  60. if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
  61. sudo cp /etc/ssh/ssh_config ~/ssh_config
  62. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  63. echo " HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> ~/ssh_config
  64. sudo mv ~/ssh_config /etc/ssh/ssh_config
  65. sudo chown root:root /etc/ssh/ssh_config
  66. fi
  67. sudo sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
  68. if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
  69. sudo cp /etc/ssh/ssh_config ~/ssh_config
  70. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  71. echo " Ciphers $SSH_CIPHERS" >> ~/ssh_config
  72. sudo mv ~/ssh_config /etc/ssh/ssh_config
  73. sudo chown root:root /etc/ssh/ssh_config
  74. fi
  75. sudo sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
  76. if ! grep -q "MACs " /etc/ssh/ssh_config; then
  77. sudo cp /etc/ssh/ssh_config ~/ssh_config
  78. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  79. echo " MACs $SSH_MACS" >> ~/ssh_config
  80. sudo mv ~/ssh_config /etc/ssh/ssh_config
  81. sudo chown root:root /etc/ssh/ssh_config
  82. fi
  83. # Create ssh keys
  84. if [ ! -f /home/$CURR_USER/.ssh/id_ed25519 ]; then
  85. ssh-keygen -t ed25519 -o -a 100
  86. fi
  87. if [ ! -f /home/$CURR_USER/.ssh/id_rsa ]; then
  88. ssh-keygen -t rsa -b 4096 -o -a 100
  89. fi
  90. ssh_remove_small_moduli
  91. echo 'Host *.onion
  92. ServerAliveInterval 60
  93. ServerAliveCountMax 3
  94. ProxyCommand sh -c 'monkeysphere ssh-proxycommand --no-connect %h %p ; connect -R remote -5 -S 127.0.0.1:9050 %h %p'
  95. Host *
  96. ServerAliveInterval 60
  97. ServerAliveCountMax 3
  98. ProxyCommand monkeysphere ssh-proxycommand %h %p' > ~/.ssh/config
  99. echo ''
  100. echo $'Copy the following into a file called /home/username/.ssh/authorized_keys on the Freedombone server'
  101. echo ''
  102. echo $(cat /home/$CURR_USER/.ssh/id_rsa.pub)
  103. echo $(cat /home/$CURR_USER/.ssh/id_ed25519.pub)
  104. echo ''
  105. }
  106. function configure_monkeysphere {
  107. sudo apt-get -y install tor connect-proxy monkeysphere
  108. }
  109. function show_help {
  110. echo ''
  111. echo $"${PROJECT_NAME}-client --mesh [yes|no]"
  112. echo ''
  113. exit 0
  114. }
  115. while [[ $# > 1 ]]
  116. do
  117. key="$1"
  118. case $key in
  119. -h|--help)
  120. show_help
  121. ;;
  122. --essid)
  123. shift
  124. WIFI_SSID="$1"
  125. ;;
  126. --channel)
  127. shift
  128. WIFI_CHANNEL=${1}
  129. ;;
  130. --mesh)
  131. shift
  132. MESH_CLIENT_INSTALL=${1}
  133. ;;
  134. *)
  135. # unknown option
  136. ;;
  137. esac
  138. shift
  139. done
  140. echo $'Configuring client'
  141. configure_ssh_client
  142. configure_monkeysphere
  143. if [[ $MESH_CLIENT_INSTALL == $'yes' || $MESH_CLIENT_INSTALL == $'y' || $MESH_CLIENT_INSTALL == $'on' ]]; then
  144. ${PROJECT_NAME}-mesh-install batman_client
  145. ${PROJECT_NAME}-mesh-install babel_client
  146. fi
  147. echo $'Configuration complete'
  148. exit 0