freedombone/src/freedombone-client

333 lines
10 KiB
Plaintext
Raw Permalink Normal View History

2015-01-24 21:02:39 +01:00
#!/bin/bash
2018-04-08 14:30:21 +02:00
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
2015-01-24 21:02:39 +01:00
#
2018-04-08 14:30:21 +02:00
# Freedom in the Cloud
2015-01-24 21:02:39 +01:00
#
2018-05-10 21:37:16 +02:00
# This is an optional command for setting up a client machine
# to then be able to log into a server. It installs a few packages
# for things like IRC and twiddles crypto settings.
#
# It may not be necessary to run this on client machines, and
# is provided for some extra convenience on a Debian or Arch
# based system.
#
2015-01-24 21:02:39 +01:00
# License
# =======
#
2018-02-21 20:32:13 +01:00
# Copyright (C) 2015-2018 Bob Mottram <bob@freedombone.net>
2015-01-24 21:02:39 +01:00
#
# This program is free software: you can redistribute it and/or modify
2016-02-13 23:09:27 +01:00
# it under the terms of the GNU Affero General Public License as published by
2015-01-24 21:02:39 +01:00
# 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
2016-02-13 23:09:27 +01:00
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
2015-01-24 21:02:39 +01:00
#
2016-02-13 23:09:27 +01:00
# 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/>.
2015-01-24 21:02:39 +01:00
2015-11-27 12:42:16 +01:00
PROJECT_NAME='freedombone'
2015-11-27 17:52:23 +01:00
export TEXTDOMAIN=${PROJECT_NAME}-client
2015-11-27 12:42:16 +01:00
export TEXTDOMAINDIR="/usr/share/locale"
2015-01-24 21:02:39 +01:00
CURR_USER=$USER
2016-09-20 23:02:18 +02:00
CURR_GROUP=$USER
if [ -f /usr/bin/pacman ]; then
CURR_GROUP='users'
fi
2015-01-24 21:02:39 +01:00
2016-11-01 23:31:30 +01:00
# setup for a specific app
SETUP_CLIENT_APP_NAME=
2015-01-24 21:02:39 +01:00
# Version number of this script
2018-04-14 20:52:42 +02:00
VERSION="3.1"
2015-01-24 21:02:39 +01:00
# 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
2016-05-28 23:30:06 +02:00
MAIN_PROJECT_FILE=/usr/bin/${PROJECT_NAME}
fi
if [ ! -f $MAIN_PROJECT_FILE ]; then
2016-05-28 23:30:06 +02:00
echo "The main project file $MAIN_PROJECT_FILE was not found"
exit 72529
fi
2015-01-24 21:02:39 +01:00
# ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
2018-03-02 20:17:02 +01:00
UTILS_SSH="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-ssh"
SSH_CIPHERS=$(grep 'SSH_CIPHERS=' "$UTILS_SSH" | head -n 1 | awk -F '"' '{print $2}')
SSH_MACS=$(grep 'SSH_MACS=' "$UTILS_SSH" | head -n 1 | awk -F '"' '{print $2}')
SSH_KEX=$(grep 'SSH_KEX=' "$UTILS_SSH" | head -n 1 | awk -F '"' '{print $2}')
SSH_HOST_KEY_ALGORITHMS=$(grep 'SSH_HOST_KEY_ALGORITHMS=' "$UTILS_SSH" | head -n 1 | awk -F '"' '{print $2}')
2015-01-24 21:02:39 +01:00
2016-05-01 20:51:00 +02:00
# refresh gpg keys every few hours
REFRESH_GPG_KEYS_HOURS=2
2016-08-10 23:22:05 +02:00
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
2018-03-02 20:17:02 +01:00
sudo chown "$CURR_USER":"$CURR_GROUP" ~/sysctl.conf
2016-08-10 23:22:05 +02:00
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
2016-08-10 23:22:05 +02:00
sudo rm ~/sysctl.conf
2016-09-29 13:50:00 +02:00
sudo sysctl -p -q $SYSCTL_FILE
2016-08-10 23:22:05 +02:00
}
2016-05-01 20:51:00 +02:00
function refresh_gpg_keys {
2016-05-28 23:30:06 +02:00
if [ ! -f /usr/bin/gpg ]; then
if [ ! -f /usr/bin/pacman ]; then
2016-10-23 20:38:14 +02:00
sudo apt-get -yq install gnupg
else
sudo pacman -S --noconfirm gnupg
fi
2016-05-28 23:30:06 +02:00
fi
sudo cp /etc/crontab ~/temp_crontab
if [ -f ~/temp_crontab ]; then
2018-04-07 19:40:48 +02:00
sudo chown "$CURR_USER":"$CURR_GROUP" ~/temp_crontab
if grep -q 'test' ~/temp_crontab; then
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
fi
rm ~/temp_crontab
2016-05-28 23:30:06 +02:00
fi
2016-05-01 20:51:00 +02:00
}
2015-01-24 21:02:39 +01:00
# see https://stribika.github.io/2015/01/04/secure-secure-shell.html
function ssh_remove_small_moduli {
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2024
sudo awk '$5 > 2000' /etc/ssh/moduli > "/home/$CURR_USER/moduli"
# shellcheck disable=SC2086
sudo mv /home/$CURR_USER/moduli /etc/ssh/moduli
2015-01-24 21:02:39 +01:00
}
function configure_ssh_client {
2016-09-28 21:35:18 +02:00
if [ -f /usr/bin/pacman ]; then
2016-10-09 20:10:36 +02:00
sudo pacman --noconfirm -S openbsd-netcat
2016-09-28 21:35:18 +02:00
else
sudo apt-get -yq install tor connect-proxy vim-common
2016-09-28 21:35:18 +02:00
fi
2016-05-28 23:30:06 +02:00
#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
2016-09-20 23:02:18 +02:00
sudo sed -i "s/HostKeyAlgorithms.*/HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
2016-05-28 23:30:06 +02:00
if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
sudo cp /etc/ssh/ssh_config ~/ssh_config
2018-03-02 20:17:02 +01:00
sudo chown "$CURR_USER":"$CURR_GROUP" ~/ssh_config
2016-05-28 23:30:06 +02:00
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
2016-05-28 23:30:06 +02:00
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
2018-03-02 20:17:02 +01:00
sudo chown "$CURR_USER":"$CURR_GROUP" ~/ssh_config
2016-05-28 23:30:06 +02:00
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
2018-03-02 20:17:02 +01:00
sudo chown "$CURR_USER":"$CURR_GROUP" ~/ssh_config
2016-05-28 23:30:06 +02:00
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
2018-03-02 20:17:02 +01:00
if [ ! -f "/home/$CURR_USER/.ssh/id_ed25519" ]; then
2016-05-28 23:30:06 +02:00
ssh-keygen -t ed25519 -o -a 100
fi
2018-03-02 20:17:02 +01:00
if [ ! -f "/home/$CURR_USER/.ssh/id_rsa" ]; then
2017-06-14 19:14:39 +02:00
ssh-keygen -t rsa -b 2048 -o -a 100
2016-05-28 23:30:06 +02:00
fi
ssh_remove_small_moduli
if [ ! -d ~/.ssh ]; then
mkdir ~/.ssh
fi
2017-03-07 19:27:53 +01:00
if [ ! -f ~/.ssh/config ]; then
touch ~/.ssh/config
fi
2016-10-09 20:10:36 +02:00
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
2017-03-07 19:27:53 +01:00
if ! grep -q "# ${PROJECT_NAME} settings" ~/.ssh/config; then
2017-03-07 19:33:38 +01:00
if ! grep -q 'ProxyCommand' ~/.ssh/config; then
2018-03-02 20:17:02 +01:00
{ echo "# ${PROJECT_NAME} settings start";
echo 'Host *.onion';
echo ' ServerAliveInterval 60';
2018-05-10 21:50:12 +02:00
echo ' ServerAliveCountMax 3';
echo " ProxyCommand $proxycmd";
echo 'Host *';
2018-03-02 20:17:02 +01:00
echo ' ServerAliveInterval 60';
2018-05-10 21:50:12 +02:00
echo ' ServerAliveCountMax 3';
echo "# ${PROJECT_NAME} settings end"; } >> ~/.ssh/config
2017-03-07 19:27:53 +01:00
fi
2016-05-28 23:30:06 +02:00
fi
echo ''
echo $'Go to the Administrator Control Panel, select "Manage Users", '
echo $'"Change user ssh public key" then "yes" and paste the following:'
2016-05-28 23:30:06 +02:00
echo ''
2018-03-02 20:17:02 +01:00
cat "/home/$CURR_USER/.ssh/id_rsa.pub"
cat "/home/$CURR_USER/.ssh/id_ed25519.pub"
2016-05-28 23:30:06 +02:00
echo ''
echo $'Then go to "Security Settings", select "Allow ssh login with passwords"'
echo $'and set it to "no".'
2015-01-24 21:02:39 +01:00
}
function show_help {
2016-05-28 23:30:06 +02:00
echo ''
2018-05-10 21:50:12 +02:00
echo $"${PROJECT_NAME}-client"
2016-05-28 23:30:06 +02:00
echo ''
exit 0
}
2016-11-01 23:31:30 +01:00
function setup_client_app_irc {
echo $'Setting up hexchat'
if [ ! -f /usr/bin/pacman ]; then
sudo apt-get -yq install tor hexchat tor
else
sudo pacman -S --noconfirm hexchat tor
fi
2018-03-02 20:17:02 +01:00
if [ ! -d "/home/$CURR_USER/.config/hexchat" ]; then
mkdir -p "/home/$CURR_USER/.config/hexchat"
2016-11-01 23:31:30 +01:00
fi
2018-03-02 20:17:02 +01:00
{ echo 'net_proxy_host = 127.0.0.1';
echo 'net_proxy_port = 9050';
echo 'net_proxy_type = 3';
echo 'net_proxy_use = 0';
2016-11-01 23:31:30 +01:00
2018-03-02 20:17:02 +01:00
echo 'net_proxy_auth = 1';
echo 'net_proxy_pass = HexChat';
echo 'net_proxy_user = HexChat';
2016-11-01 23:31:30 +01:00
2018-03-02 20:17:02 +01:00
echo 'dcc_auto_chat = 0';
echo 'dcc_auto_resume = 0';
echo 'dcc_auto_send = 0';
echo 'irc_hide_version = 1';
echo 'identd = 0';
2016-11-01 23:31:30 +01:00
2018-03-02 20:17:02 +01:00
echo 'away_reason =';
echo 'irc_part_reason =';
echo 'irc_quit_reason =';
2016-11-01 23:31:30 +01:00
2018-03-02 20:17:02 +01:00
echo "irc_real_name = ${USER}";
echo "irc_user_name = ${USER}";
echo "irc_nick1 = ${USER}";
echo "irc_nick2 = ${USER}_";
echo "irc_nick3 = ${USER}__";
2016-11-01 23:31:30 +01:00
2018-03-02 20:17:02 +01:00
echo 'completion_suffix = :';
2016-11-01 23:31:30 +01:00
2018-03-02 20:17:02 +01:00
echo 'gui_slist_skip = 1'; } > "/home/$CURR_USER/.config/hexchat/hexchat.conf"
2016-11-01 23:31:30 +01:00
echo $'hexchat configured'
}
function setup_client_app {
if [ ! $SETUP_CLIENT_APP_NAME ]; then
return
fi
case $SETUP_CLIENT_APP_NAME in
hexchat|xchat|irc)
setup_client_app_irc
;;
esac
exit 0
}
function remove_known_hosts_entries {
# remove any previous freedombone entries from known hosts
2018-03-02 20:17:02 +01:00
if [ -f "/home/$CURR_USER/.ssh/known_hosts" ]; then
sed -i "/${PROJECT_NAME}.local/d" "/home/$CURR_USER/.ssh/known_hosts"
fi
}
function setup_avahi_client {
echo $'Configuring Avahi'
if [ ! -f /usr/bin/pacman ]; then
2018-01-15 13:29:06 +01:00
sudo apt-get -yq install avahi-utils 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
}
function verify_ssh_server_key {
ssh -o VisualHostKey=yes -o FingerprintHash=sha256 ${PROJECT_NAME}.local -p 2222 &
pid=$!
sleep 15
kill ${pid}
}
2018-03-02 23:34:33 +01:00
while [ $# -gt 0 ]
do
2016-05-28 23:30:06 +02:00
key="$1"
case $key in
-h|--help)
show_help
;;
--essid)
shift
WIFI_SSID="$1"
;;
--channel)
shift
WIFI_CHANNEL=${1}
;;
2016-11-01 23:31:30 +01:00
-s|--setup)
shift
SETUP_CLIENT_APP_NAME=${1}
;;
-v|--verify|--verifykeys)
verify_ssh_server_key
exit 0
;;
2016-05-28 23:30:06 +02:00
*)
# unknown option
;;
esac
shift
done
2015-11-27 16:29:43 +01:00
echo $'Configuring client'
setup_avahi_client
2016-11-01 23:31:30 +01:00
setup_client_app
2016-05-01 20:51:00 +02:00
refresh_gpg_keys
2015-01-24 21:02:39 +01:00
configure_ssh_client
2016-08-10 23:22:05 +02:00
global_rate_limit
remove_known_hosts_entries
2015-11-27 16:29:43 +01:00
echo $'Configuration complete'
exit 0