You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

255 lines
8.6 KiB

#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# License
# =======
#
# Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PROJECT_NAME='freedombone'
export TEXTDOMAIN=${PROJECT_NAME}-client
export TEXTDOMAINDIR="/usr/share/locale"
CURR_USER=$USER
CURR_GROUP=$USER
if [ -f /usr/bin/pacman ]; then
CURR_GROUP='users'
fi
MESH_CLIENT_INSTALL=
ENABLE_MONKEYSPHERE=
# Version number of this script
VERSION="1.01"
# get the main project file, so that some values can be extracted
MAIN_PROJECT_FILE=/usr/local/bin/${PROJECT_NAME}
if [ ! -f $MAIN_PROJECT_FILE ]; then
MAIN_PROJECT_FILE=/usr/bin/${PROJECT_NAME}
fi
if [ ! -f $MAIN_PROJECT_FILE ]; then
echo "The main project file $MAIN_PROJECT_FILE was not found"
exit 72529
fi
# ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
UTILS_SSH=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-ssh
SSH_CIPHERS=$(cat $UTILS_SSH | grep 'SSH_CIPHERS=' | head -n 1 | awk -F '"' '{print $2}')
SSH_MACS=$(cat $UTILS_SSH | grep 'SSH_MACS=' | head -n 1 | awk -F '"' '{print $2}')
SSH_KEX=$(cat $UTILS_SSH | grep 'SSH_KEX=' | head -n 1 | awk -F '"' '{print $2}')
SSH_HOST_KEY_ALGORITHMS=$(cat $UTILS_SSH | grep 'SSH_HOST_KEY_ALGORITHMS=' | head -n 1 | awk -F '"' '{print $2}')
# refresh gpg keys every few hours
REFRESH_GPG_KEYS_HOURS=2
function global_rate_limit {
SYSCTL_FILE=/etc/sysctl.conf
if [ -f /usr/bin/pacman ]; then
SYSCTL_FILE=/etc/sysctl.d/99-sysctl.conf
fi
if [ ! -f $SYSCTL_FILE ]; then
sudo touch $SYSCTL_FILE
fi
sudo cp $SYSCTL_FILE ~/sysctl.conf
sudo chown $CURR_USER:$CURR_GROUP ~/sysctl.conf
if ! grep -q "tcp_challenge_ack_limit" ~/sysctl.conf; then
echo 'net.ipv4.tcp_challenge_ack_limit = 999999999' >> ~/sysctl.conf
else
sed -i 's|net.ipv4.tcp_challenge_ack_limit.*|net.ipv4.tcp_challenge_ack_limit = 999999999|g' ~/sysctl.conf
fi
sudo cp ~/sysctl.conf $SYSCTL_FILE
sudo rm ~/sysctl.conf
sudo sysctl -p -q $SYSCTL_FILE
}
function refresh_gpg_keys {
if [ ! -f /usr/bin/gpg ]; then
if [ ! -f /usr/bin/pacman ]; then
sudo apt-get -yq install gnupg
else
sudo pacman -S --noconfirm gnupg
fi
fi
sudo cp /etc/crontab ~/temp_crontab
sudo chown $CURR_USER:$CURR_GROUP ~/temp_crontab
if ! grep -q "gpg --refresh-keys" ~/temp_crontab; then
echo "0 */$REFRESH_GPG_KEYS_HOURS * * * $CURR_USER /usr/bin/gpg --refresh-keys > /dev/null" >> ~/temp_crontab
sudo cp ~/temp_crontab /etc/crontab
sudo chown root:root /etc/crontab
fi
rm ~/temp_crontab
}
# see https://stribika.github.io/2015/01/04/secure-secure-shell.html
function ssh_remove_small_moduli {
sudo awk '$5 > 2000' /etc/ssh/moduli > /home/$CURR_USER/moduli
sudo mv /home/$CURR_USER/moduli /etc/ssh/moduli
}
function configure_ssh_client {
if [ -f /usr/bin/pacman ]; then
sudo pacman --noconfirm -S openbsd-netcat
else
sudo apt-get -yq install tor connect-proxy
fi
#sudo sed -i 's/# PasswordAuthentication.*/ PasswordAuthentication no/g' /etc/ssh/ssh_config
#sudo sed -i 's/# ChallengeResponseAuthentication.*/ ChallengeResponseAuthentication no/g' /etc/ssh/ssh_config
sudo sed -i "s/# HostKeyAlgorithms.*/ HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
sudo sed -i "s/# Ciphers.*/ Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
sudo sed -i "s/# MACs.*/ MACs $SSH_MACS/g" /etc/ssh/ssh_config
sudo sed -i "s/HostKeyAlgorithms.*/HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
sudo cp /etc/ssh/ssh_config ~/ssh_config
sudo chown $CURR_USER:$CURR_GROUP ~/ssh_config
echo " HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> ~/ssh_config
sudo mv ~/ssh_config /etc/ssh/ssh_config
sudo chown root:root /etc/ssh/ssh_config
fi
sudo sed -i "s/HostKeyAlgorithms.*/#HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
sudo sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
sudo cp /etc/ssh/ssh_config ~/ssh_config
sudo chown $CURR_USER:$CURR_GROUP ~/ssh_config
echo " Ciphers $SSH_CIPHERS" >> ~/ssh_config
sudo mv ~/ssh_config /etc/ssh/ssh_config
sudo chown root:root /etc/ssh/ssh_config
fi
sudo sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
if ! grep -q "MACs " /etc/ssh/ssh_config; then
sudo cp /etc/ssh/ssh_config ~/ssh_config
sudo chown $CURR_USER:$CURR_GROUP ~/ssh_config
echo " MACs $SSH_MACS" >> ~/ssh_config
sudo mv ~/ssh_config /etc/ssh/ssh_config
sudo chown root:root /etc/ssh/ssh_config
fi
# Create ssh keys
if [ ! -f /home/$CURR_USER/.ssh/id_ed25519 ]; then
ssh-keygen -t ed25519 -o -a 100
fi
if [ ! -f /home/$CURR_USER/.ssh/id_rsa ]; then
ssh-keygen -t rsa -b 4096 -o -a 100
fi
ssh_remove_small_moduli
if [ ! -d ~/.ssh ]; then
mkdir ~/.ssh
fi
echo 'Host *.onion' > ~/.ssh/config
echo ' ServerAliveInterval 60' >> ~/.ssh/config
echo ' ServerAliveCountMax 3' >> ~/.ssh/config
proxycmd="connect -R remote -5 -S 127.0.0.1:9050 %h %p"
if [ -f /usr/bin/pacman ]; then
proxycmd="/usr/bin/nc -X 5 -x 127.0.0.1:9050 %h %p"
fi
if [[ $ENABLE_MONKEYSPHERE == $'yes' || $ENABLE_MONKEYSPHERE == $'y' ]]; then
echo " ProxyCommand sh -c 'monkeysphere ssh-proxycommand --no-connect %h %p ; $proxycmd'" >> ~/.ssh/config
else
echo " ProxyCommand $proxycmd" >> ~/.ssh/config
fi
echo 'Host *' >> ~/.ssh/config
echo ' ServerAliveInterval 60' >> ~/.ssh/config
echo ' ServerAliveCountMax 3' >> ~/.ssh/config
if [[ $ENABLE_MONKEYSPHERE == $'yes' || $ENABLE_MONKEYSPHERE == $'y' ]]; then
echo ' ProxyCommand monkeysphere ssh-proxycommand %h %p' >> ~/.ssh/config
fi
echo ''
echo $'Copy the following into a file called /home/username/.ssh/authorized_keys on the Freedombone server'
echo ''
echo $(cat /home/$CURR_USER/.ssh/id_rsa.pub)
echo $(cat /home/$CURR_USER/.ssh/id_ed25519.pub)
echo ''
}
function configure_monkeysphere {
if [ -f /usr/bin/pacman ]; then
return
fi
sudo apt-get -yq install monkeysphere
}
function show_help {
echo ''
echo $"${PROJECT_NAME}-client --mesh [yes|no] --monkeysphere [yes|no]"
echo ''
exit 0
}
while [[ $# > 1 ]]
do
key="$1"
case $key in
-h|--help)
show_help
;;
--essid)
shift
WIFI_SSID="$1"
;;
--channel)
shift
WIFI_CHANNEL=${1}
;;
-m|--mesh)
shift
MESH_CLIENT_INSTALL=${1}
;;
--monkeysphere|--ms|--monkey)
shift
ENABLE_MONKEYSPHERE=${1}
;;
*)
# unknown option
;;
esac
shift
done
echo $'Configuring client'
refresh_gpg_keys
configure_ssh_client
global_rate_limit
configure_monkeysphere
if [[ $MESH_CLIENT_INSTALL == $'yes' || $MESH_CLIENT_INSTALL == $'y' || $MESH_CLIENT_INSTALL == $'on' ]]; then
echo $'Installing mesh packages'
if [ ! -f /usr/bin/pacman ]; then
sudo apt-get -yq install avahi-utils avahi-autoipd avahi-dnsconfd
else
sudo pacman -S --noconfirm avahi nss-mdns
sudo sed -i 's|hosts:.*|hosts: files mdns_minimal [NOTFOUND=return] dns myhostname|g' /etc/nsswitch.conf
fi
sudo ${PROJECT_NAME}-mesh-install -f tox_node
sudo ${PROJECT_NAME}-mesh-install -f toxic
${PROJECT_NAME}-mesh-install -f qtox
sudo ${PROJECT_NAME}-mesh-install -f zeronet
fi
echo $'Configuration complete'
exit 0