freedombone-client 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. ENABLE_MONKEYSPHERE=
  34. # Version number of this script
  35. VERSION="1.01"
  36. # get the main project file, so that some values can be extracted
  37. MAIN_PROJECT_FILE=/usr/local/bin/${PROJECT_NAME}
  38. if [ ! -f $MAIN_PROJECT_FILE ]; then
  39. MAIN_PROJECT_FILE=/usr/bin/${PROJECT_NAME}
  40. fi
  41. if [ ! -f $MAIN_PROJECT_FILE ]; then
  42. echo "The main project file $MAIN_PROJECT_FILE was not found"
  43. exit 72529
  44. fi
  45. # ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
  46. SSH_CIPHERS=$(cat $MAIN_PROJECT_FILE | grep 'SSH_CIPHERS=' | head -n 1 | awk -F '"' '{print $2}')
  47. SSH_MACS=$(cat $MAIN_PROJECT_FILE | grep 'SSH_MACS=' | head -n 1 | awk -F '"' '{print $2}')
  48. SSH_KEX=$(cat $MAIN_PROJECT_FILE | grep 'SSH_KEX=' | head -n 1 | awk -F '"' '{print $2}')
  49. SSH_HOST_KEY_ALGORITHMS=$(cat $MAIN_PROJECT_FILE | grep 'SSH_HOST_KEY_ALGORITHMS=' | head -n 1 | awk -F '"' '{print $2}')
  50. # refresh gpg keys every few hours
  51. REFRESH_GPG_KEYS_HOURS=2
  52. function global_rate_limit {
  53. sudo cp /etc/sysctl.conf ~/sysctl.conf
  54. if ! grep -q "tcp_challenge_ack_limit" ~/sysctl.conf; then
  55. echo 'net.ipv4.tcp_challenge_ack_limit = 999999999' >> ~/sysctl.conf
  56. else
  57. sed -i 's|net.ipv4.tcp_challenge_ack_limit.*|net.ipv4.tcp_challenge_ack_limit = 999999999|g' ~/sysctl.conf
  58. fi
  59. sudo cp ~/sysctl.conf /etc/sysctl.conf
  60. sudo rm ~/sysctl.conf
  61. sudo sysctl -p
  62. }
  63. function refresh_gpg_keys {
  64. if [ ! -f /usr/bin/gpg ]; then
  65. sudo apt-get -y install gnupg
  66. fi
  67. sudo cp /etc/crontab ~/temp_crontab
  68. sudo chown $CURR_USER:$CURR_USER ~/temp_crontab
  69. if ! grep -q "gpg --refresh-keys" ~/temp_crontab; then
  70. echo "0 */$REFRESH_GPG_KEYS_HOURS * * * $CURR_USER /usr/bin/gpg --refresh-keys > /dev/null" >> ~/temp_crontab
  71. sudo cp ~/temp_crontab /etc/crontab
  72. sudo chown root:root /etc/crontab
  73. fi
  74. rm ~/temp_crontab
  75. }
  76. # see https://stribika.github.io/2015/01/04/secure-secure-shell.html
  77. function ssh_remove_small_moduli {
  78. sudo awk '$5 > 2000' /etc/ssh/moduli > /home/$CURR_USER/moduli
  79. sudo mv /home/$CURR_USER/moduli /etc/ssh/moduli
  80. }
  81. function configure_ssh_client {
  82. #sudo sed -i 's/# PasswordAuthentication.*/ PasswordAuthentication no/g' /etc/ssh/ssh_config
  83. #sudo sed -i 's/# ChallengeResponseAuthentication.*/ ChallengeResponseAuthentication no/g' /etc/ssh/ssh_config
  84. sudo sed -i "s/# HostKeyAlgorithms.*/ HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
  85. sudo sed -i "s/# Ciphers.*/ Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
  86. sudo sed -i "s/# MACs.*/ MACs $SSH_MACS/g" /etc/ssh/ssh_config
  87. if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
  88. sudo cp /etc/ssh/ssh_config ~/ssh_config
  89. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  90. echo " HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> ~/ssh_config
  91. sudo mv ~/ssh_config /etc/ssh/ssh_config
  92. sudo chown root:root /etc/ssh/ssh_config
  93. fi
  94. sudo sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
  95. if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
  96. sudo cp /etc/ssh/ssh_config ~/ssh_config
  97. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  98. echo " Ciphers $SSH_CIPHERS" >> ~/ssh_config
  99. sudo mv ~/ssh_config /etc/ssh/ssh_config
  100. sudo chown root:root /etc/ssh/ssh_config
  101. fi
  102. sudo sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
  103. if ! grep -q "MACs " /etc/ssh/ssh_config; then
  104. sudo cp /etc/ssh/ssh_config ~/ssh_config
  105. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  106. echo " MACs $SSH_MACS" >> ~/ssh_config
  107. sudo mv ~/ssh_config /etc/ssh/ssh_config
  108. sudo chown root:root /etc/ssh/ssh_config
  109. fi
  110. # Create ssh keys
  111. if [ ! -f /home/$CURR_USER/.ssh/id_ed25519 ]; then
  112. ssh-keygen -t ed25519 -o -a 100
  113. fi
  114. if [ ! -f /home/$CURR_USER/.ssh/id_rsa ]; then
  115. ssh-keygen -t rsa -b 4096 -o -a 100
  116. fi
  117. ssh_remove_small_moduli
  118. if [ ! -d ~/.ssh ]; then
  119. mkdir ~/.ssh
  120. fi
  121. echo 'Host *.onion' > ~/.ssh/config
  122. echo ' ServerAliveInterval 60' >> ~/.ssh/config
  123. echo ' ServerAliveCountMax 3' >> ~/.ssh/config
  124. if [[ $ENABLE_MONKEYSPHERE == $'yes' || $ENABLE_MONKEYSPHERE == $'y' ]]; then
  125. 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
  126. else
  127. echo " ProxyCommand connect -R remote -5 -S 127.0.0.1:9050 %h %p" >> ~/.ssh/config
  128. fi
  129. echo 'Host *' >> ~/.ssh/config
  130. echo ' ServerAliveInterval 60' >> ~/.ssh/config
  131. echo ' ServerAliveCountMax 3' >> ~/.ssh/config
  132. if [[ $ENABLE_MONKEYSPHERE == $'yes' || $ENABLE_MONKEYSPHERE == $'y' ]]; then
  133. echo ' ProxyCommand monkeysphere ssh-proxycommand %h %p' >> ~/.ssh/config
  134. fi
  135. echo ''
  136. echo $'Copy the following into a file called /home/username/.ssh/authorized_keys on the Freedombone server'
  137. echo ''
  138. echo $(cat /home/$CURR_USER/.ssh/id_rsa.pub)
  139. echo $(cat /home/$CURR_USER/.ssh/id_ed25519.pub)
  140. echo ''
  141. }
  142. function configure_monkeysphere {
  143. sudo apt-get -y install tor connect-proxy monkeysphere
  144. }
  145. function show_help {
  146. echo ''
  147. echo $"${PROJECT_NAME}-client --mesh [yes|no] --monkeysphere [yes|no]"
  148. echo ''
  149. exit 0
  150. }
  151. while [[ $# > 1 ]]
  152. do
  153. key="$1"
  154. case $key in
  155. -h|--help)
  156. show_help
  157. ;;
  158. --essid)
  159. shift
  160. WIFI_SSID="$1"
  161. ;;
  162. --channel)
  163. shift
  164. WIFI_CHANNEL=${1}
  165. ;;
  166. -m|--mesh)
  167. shift
  168. MESH_CLIENT_INSTALL=${1}
  169. ;;
  170. --monkeysphere|--ms|--monkey)
  171. shift
  172. ENABLE_MONKEYSPHERE=${1}
  173. ;;
  174. *)
  175. # unknown option
  176. ;;
  177. esac
  178. shift
  179. done
  180. echo $'Configuring client'
  181. refresh_gpg_keys
  182. configure_ssh_client
  183. global_rate_limit
  184. configure_monkeysphere
  185. if [[ $MESH_CLIENT_INSTALL == $'yes' || $MESH_CLIENT_INSTALL == $'y' || $MESH_CLIENT_INSTALL == $'on' ]]; then
  186. echo $'Installing mesh packages'
  187. sudo apt-get -y install avahi-utils avahi-autoipd avahi-dnsconfd
  188. sudo ${PROJECT_NAME}-mesh-install -f tox_node
  189. sudo ${PROJECT_NAME}-mesh-install -f toxic
  190. ${PROJECT_NAME}-mesh-install -f qtox
  191. sudo ${PROJECT_NAME}-mesh-install -f zeronet
  192. fi
  193. echo $'Configuration complete'
  194. exit 0