freedombone-client 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. # refresh gpg keys every few hours
  50. REFRESH_GPG_KEYS_HOURS=2
  51. function refresh_gpg_keys {
  52. if [ ! -f /usr/bin/gpg ]; then
  53. sudo apt-get -y install gnupg
  54. fi
  55. sudo cp /etc/crontab ~/temp_crontab
  56. sudo chown $CURR_USER:$CURR_USER ~/temp_crontab
  57. if ! grep -q "gpg --refresh-keys" ~/temp_crontab; then
  58. echo "0 */$REFRESH_GPG_KEYS_HOURS * * * $CURR_USER /usr/bin/gpg --refresh-keys > /dev/null" >> ~/temp_crontab
  59. sudo cp ~/temp_crontab /etc/crontab
  60. chown root:root /etc/crontab
  61. fi
  62. rm ~/temp_crontab
  63. }
  64. # see https://stribika.github.io/2015/01/04/secure-secure-shell.html
  65. function ssh_remove_small_moduli {
  66. sudo awk '$5 > 2000' /etc/ssh/moduli > /home/$CURR_USER/moduli
  67. sudo mv /home/$CURR_USER/moduli /etc/ssh/moduli
  68. }
  69. function configure_ssh_client {
  70. #sudo sed -i 's/# PasswordAuthentication.*/ PasswordAuthentication no/g' /etc/ssh/ssh_config
  71. #sudo sed -i 's/# ChallengeResponseAuthentication.*/ ChallengeResponseAuthentication no/g' /etc/ssh/ssh_config
  72. sudo sed -i "s/# HostKeyAlgorithms.*/ HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
  73. sudo sed -i "s/# Ciphers.*/ Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
  74. sudo sed -i "s/# MACs.*/ MACs $SSH_MACS/g" /etc/ssh/ssh_config
  75. if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
  76. sudo cp /etc/ssh/ssh_config ~/ssh_config
  77. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  78. echo " HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> ~/ssh_config
  79. sudo mv ~/ssh_config /etc/ssh/ssh_config
  80. sudo chown root:root /etc/ssh/ssh_config
  81. fi
  82. sudo sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
  83. if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
  84. sudo cp /etc/ssh/ssh_config ~/ssh_config
  85. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  86. echo " Ciphers $SSH_CIPHERS" >> ~/ssh_config
  87. sudo mv ~/ssh_config /etc/ssh/ssh_config
  88. sudo chown root:root /etc/ssh/ssh_config
  89. fi
  90. sudo sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
  91. if ! grep -q "MACs " /etc/ssh/ssh_config; then
  92. sudo cp /etc/ssh/ssh_config ~/ssh_config
  93. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  94. echo " MACs $SSH_MACS" >> ~/ssh_config
  95. sudo mv ~/ssh_config /etc/ssh/ssh_config
  96. sudo chown root:root /etc/ssh/ssh_config
  97. fi
  98. # Create ssh keys
  99. if [ ! -f /home/$CURR_USER/.ssh/id_ed25519 ]; then
  100. ssh-keygen -t ed25519 -o -a 100
  101. fi
  102. if [ ! -f /home/$CURR_USER/.ssh/id_rsa ]; then
  103. ssh-keygen -t rsa -b 4096 -o -a 100
  104. fi
  105. ssh_remove_small_moduli
  106. if [ ! -d ~/.ssh ]; then
  107. mkdir ~/.ssh
  108. fi
  109. echo 'Host *.onion' > ~/.ssh/config
  110. echo ' ServerAliveInterval 60' >> ~/.ssh/config
  111. echo ' ServerAliveCountMax 3' >> ~/.ssh/config
  112. echo " ProxyCommand connect -R remote -5 -S 127.0.0.1:9050 %h %p" >> ~/.ssh/config
  113. echo "# ProxyCommand sh -c 'monkeysphere ssh-proxycommand --no-connect %h %p ; connect -R remote -5 -S 127.0.0.1:9050 %h %p'" >> ~/.ssh/config
  114. echo 'Host *' >> ~/.ssh/config
  115. echo ' ServerAliveInterval 60' >> ~/.ssh/config
  116. echo ' ServerAliveCountMax 3' >> ~/.ssh/config
  117. echo '# ProxyCommand monkeysphere ssh-proxycommand %h %p' >> ~/.ssh/config
  118. echo ''
  119. echo $'Copy the following into a file called /home/username/.ssh/authorized_keys on the Freedombone server'
  120. echo ''
  121. echo $(cat /home/$CURR_USER/.ssh/id_rsa.pub)
  122. echo $(cat /home/$CURR_USER/.ssh/id_ed25519.pub)
  123. echo ''
  124. }
  125. function configure_monkeysphere {
  126. sudo apt-get -y install tor connect-proxy monkeysphere
  127. }
  128. function show_help {
  129. echo ''
  130. echo $"${PROJECT_NAME}-client --mesh [yes|no]"
  131. echo ''
  132. exit 0
  133. }
  134. while [[ $# > 1 ]]
  135. do
  136. key="$1"
  137. case $key in
  138. -h|--help)
  139. show_help
  140. ;;
  141. --essid)
  142. shift
  143. WIFI_SSID="$1"
  144. ;;
  145. --channel)
  146. shift
  147. WIFI_CHANNEL=${1}
  148. ;;
  149. --mesh)
  150. shift
  151. MESH_CLIENT_INSTALL=${1}
  152. ;;
  153. *)
  154. # unknown option
  155. ;;
  156. esac
  157. shift
  158. done
  159. echo $'Configuring client'
  160. refresh_gpg_keys
  161. configure_ssh_client
  162. configure_monkeysphere
  163. if [[ $MESH_CLIENT_INSTALL == $'yes' || $MESH_CLIENT_INSTALL == $'y' || $MESH_CLIENT_INSTALL == $'on' ]]; then
  164. ${PROJECT_NAME}-mesh-install batman_client
  165. ${PROJECT_NAME}-mesh-install babel_client
  166. fi
  167. echo $'Configuration complete'
  168. exit 0