|
@@ -31,8 +31,6 @@ PROJECT_NAME='freedombone'
|
31
|
31
|
export TEXTDOMAIN=${PROJECT_NAME}-image-mesh
|
32
|
32
|
export TEXTDOMAINDIR="/usr/share/locale"
|
33
|
33
|
|
34
|
|
-source /usr/local/bin/${PROJECT_NAME}-app-vpn
|
35
|
|
-
|
36
|
34
|
# The browser application to use
|
37
|
35
|
BROWSER=midori
|
38
|
36
|
BROWSER_OPTIONS='-p'
|
|
@@ -74,6 +72,17 @@ IPFS_PORT=4001
|
74
|
72
|
|
75
|
73
|
CURRENT_BLOG_INDEX=/home/$MY_USERNAME/.blog-index
|
76
|
74
|
|
|
75
|
+OPENVPN_SERVER_NAME="server"
|
|
76
|
+OPENVPN_KEY_FILENAME='client.ovpn'
|
|
77
|
+VPN_COUNTRY_CODE="US"
|
|
78
|
+VPN_AREA="Apparent Free Speech Zone"
|
|
79
|
+VPN_LOCATION="Freedomville"
|
|
80
|
+VPN_ORGANISATION="Freedombone"
|
|
81
|
+VPN_UNIT="Freedombone Unit"
|
|
82
|
+STUNNEL_PORT=3439
|
|
83
|
+VPN_TLS_PORT=553
|
|
84
|
+VPN_MESH_TLS_PORT=653
|
|
85
|
+
|
77
|
86
|
# Debian stretch has a problem where the formerly predictable wlan0 and eth0
|
78
|
87
|
# device names get assigned random names. This is a hacky workaround.
|
79
|
88
|
# Also adding net.ifnames=0 to kernel options on bootloader may work.
|
|
@@ -556,6 +565,198 @@ function setup_tahoelafs {
|
556
|
565
|
echo $'Configured Tahoe-LAFS' >> $INSTALL_LOG
|
557
|
566
|
}
|
558
|
567
|
|
|
568
|
+function create_user_vpn_key {
|
|
569
|
+ username=$1
|
|
570
|
+
|
|
571
|
+ if [ ! -d /home/$username ]; then
|
|
572
|
+ return
|
|
573
|
+ fi
|
|
574
|
+
|
|
575
|
+ echo $"Creating VPN key for $username" >> /var/log/${PROJECT_NAME}.log
|
|
576
|
+
|
|
577
|
+ cd /etc/openvpn/easy-rsa
|
|
578
|
+
|
|
579
|
+ if [ -f /etc/openvpn/easy-rsa/keys/$username.crt ]; then
|
|
580
|
+ rm /etc/openvpn/easy-rsa/keys/$username.crt
|
|
581
|
+ fi
|
|
582
|
+ if [ -f /etc/openvpn/easy-rsa/keys/$username.key ]; then
|
|
583
|
+ rm /etc/openvpn/easy-rsa/keys/$username.key
|
|
584
|
+ fi
|
|
585
|
+ if [ -f /etc/openvpn/easy-rsa/keys/$username.csr ]; then
|
|
586
|
+ rm /etc/openvpn/easy-rsa/keys/$username.csr
|
|
587
|
+ fi
|
|
588
|
+
|
|
589
|
+ sed -i 's| --interact||g' build-key
|
|
590
|
+ ./build-key "$username"
|
|
591
|
+
|
|
592
|
+ if [ ! -f /etc/openvpn/easy-rsa/keys/$username.crt ]; then
|
|
593
|
+ echo $'VPN user cert not generated' >> /var/log/${PROJECT_NAME}.log
|
|
594
|
+ exit 783528
|
|
595
|
+ fi
|
|
596
|
+ user_cert=$(cat /etc/openvpn/easy-rsa/keys/$username.crt)
|
|
597
|
+ if [ ${#user_cert} -lt 10 ]; then
|
|
598
|
+ cat /etc/openvpn/easy-rsa/keys/$username.crt
|
|
599
|
+ echo $'User cert generation failed' >> /var/log/${PROJECT_NAME}.log
|
|
600
|
+ exit 634659
|
|
601
|
+ fi
|
|
602
|
+ if [ ! -f /etc/openvpn/easy-rsa/keys/$username.key ]; then
|
|
603
|
+ echo $'VPN user key not generated'
|
|
604
|
+ exit 682523
|
|
605
|
+ fi
|
|
606
|
+ user_key=$(cat /etc/openvpn/easy-rsa/keys/$username.key)
|
|
607
|
+ if [ ${#user_key} -lt 10 ]; then
|
|
608
|
+ cat /etc/openvpn/easy-rsa/keys/$username.key
|
|
609
|
+ echo $'User key generation failed'
|
|
610
|
+ exit 285838
|
|
611
|
+ fi
|
|
612
|
+
|
|
613
|
+ user_vpn_cert_file=/home/$username/$OPENVPN_KEY_FILENAME
|
|
614
|
+
|
|
615
|
+ echo 'client' > $user_vpn_cert_file
|
|
616
|
+ echo 'dev tun' >> $user_vpn_cert_file
|
|
617
|
+ echo 'proto tcp' >> $user_vpn_cert_file
|
|
618
|
+ echo "remote localhost $STUNNEL_PORT" >> $user_vpn_cert_file
|
|
619
|
+ echo "route $DEFAULT_DOMAIN_NAME 255.255.255.255 net_gateway" >> $user_vpn_cert_file
|
|
620
|
+ echo 'resolv-retry infinite' >> $user_vpn_cert_file
|
|
621
|
+ echo 'nobind' >> $user_vpn_cert_file
|
|
622
|
+ echo 'tun-mtu 1500' >> $user_vpn_cert_file
|
|
623
|
+ echo 'tun-mtu-extra 32' >> $user_vpn_cert_file
|
|
624
|
+ echo 'mssfix 1450' >> $user_vpn_cert_file
|
|
625
|
+ echo 'persist-key' >> $user_vpn_cert_file
|
|
626
|
+ echo 'persist-tun' >> $user_vpn_cert_file
|
|
627
|
+ echo 'auth-nocache' >> $user_vpn_cert_file
|
|
628
|
+ echo 'remote-cert-tls server' >> $user_vpn_cert_file
|
|
629
|
+ echo 'comp-lzo' >> $user_vpn_cert_file
|
|
630
|
+ echo 'verb 3' >> $user_vpn_cert_file
|
|
631
|
+ echo '' >> $user_vpn_cert_file
|
|
632
|
+
|
|
633
|
+ echo '<ca>' >> $user_vpn_cert_file
|
|
634
|
+ cat /etc/openvpn/ca.crt >> $user_vpn_cert_file
|
|
635
|
+ echo '</ca>' >> $user_vpn_cert_file
|
|
636
|
+
|
|
637
|
+ echo '<cert>' >> $user_vpn_cert_file
|
|
638
|
+ cat /etc/openvpn/easy-rsa/keys/$username.crt >> $user_vpn_cert_file
|
|
639
|
+ echo '</cert>' >> $user_vpn_cert_file
|
|
640
|
+
|
|
641
|
+ echo '<key>' >> $user_vpn_cert_file
|
|
642
|
+ cat /etc/openvpn/easy-rsa/keys/$username.key >> $user_vpn_cert_file
|
|
643
|
+ echo '</key>' >> $user_vpn_cert_file
|
|
644
|
+
|
|
645
|
+ chown $username:$username $user_vpn_cert_file
|
|
646
|
+
|
|
647
|
+ # keep a backup
|
|
648
|
+ cp $user_vpn_cert_file /etc/openvpn/easy-rsa/keys/$username.ovpn
|
|
649
|
+
|
|
650
|
+ #rm /etc/openvpn/easy-rsa/keys/$username.crt
|
|
651
|
+ #rm /etc/openvpn/easy-rsa/keys/$username.csr
|
|
652
|
+ shred -zu /etc/openvpn/easy-rsa/keys/$username.key
|
|
653
|
+
|
|
654
|
+ echo $"VPN key created at $user_vpn_cert_file" >> /var/log/${PROJECT_NAME}.log
|
|
655
|
+}
|
|
656
|
+
|
|
657
|
+function vpn_generate_keys {
|
|
658
|
+ # generate host keys
|
|
659
|
+ if [ ! -f /etc/openvpn/dh2048.pem ]; then
|
|
660
|
+ ${PROJECT_NAME}-dhparam -o /etc/openvpn/dh2048.pem
|
|
661
|
+ fi
|
|
662
|
+ if [ ! -f /etc/openvpn/dh2048.pem ]; then
|
|
663
|
+ echo $'vpn dhparams were not generated' >> /var/log/${PROJECT_NAME}.log
|
|
664
|
+ exit 73724523
|
|
665
|
+ fi
|
|
666
|
+ cp /etc/openvpn/dh2048.pem /etc/openvpn/easy-rsa/keys/dh2048.pem
|
|
667
|
+
|
|
668
|
+ cd /etc/openvpn/easy-rsa
|
|
669
|
+ . ./vars
|
|
670
|
+ ./clean-all
|
|
671
|
+ vpn_openssl_version='1.0.0'
|
|
672
|
+ if [ ! -f openssl-${vpn_openssl_version}.cnf ]; then
|
|
673
|
+ echo $"openssl-${vpn_openssl_version}.cnf was not found" >> /var/log/${PROJECT_NAME}.log
|
|
674
|
+ exit 7392353
|
|
675
|
+ fi
|
|
676
|
+ cp openssl-${vpn_openssl_version}.cnf openssl.cnf
|
|
677
|
+
|
|
678
|
+ if [ -f /etc/openvpn/easy-rsa/keys/${OPENVPN_SERVER_NAME}.crt ]; then
|
|
679
|
+ rm /etc/openvpn/easy-rsa/keys/${OPENVPN_SERVER_NAME}.crt
|
|
680
|
+ fi
|
|
681
|
+ if [ -f /etc/openvpn/easy-rsa/keys/${OPENVPN_SERVER_NAME}.key ]; then
|
|
682
|
+ rm /etc/openvpn/easy-rsa/keys/${OPENVPN_SERVER_NAME}.key
|
|
683
|
+ fi
|
|
684
|
+ if [ -f /etc/openvpn/easy-rsa/keys/${OPENVPN_SERVER_NAME}.csr ]; then
|
|
685
|
+ rm /etc/openvpn/easy-rsa/keys/${OPENVPN_SERVER_NAME}.csr
|
|
686
|
+ fi
|
|
687
|
+ sed -i 's| --interact||g' build-key-server
|
|
688
|
+ sed -i 's| --interact||g' build-ca
|
|
689
|
+ ./build-ca
|
|
690
|
+ ./build-key-server ${OPENVPN_SERVER_NAME}
|
|
691
|
+ if [ ! -f /etc/openvpn/easy-rsa/keys/${OPENVPN_SERVER_NAME}.crt ]; then
|
|
692
|
+ echo $'OpenVPN crt not found' >> /var/log/${PROJECT_NAME}.log
|
|
693
|
+ exit 7823352
|
|
694
|
+ fi
|
|
695
|
+ server_cert=$(cat /etc/openvpn/easy-rsa/keys/${OPENVPN_SERVER_NAME}.crt)
|
|
696
|
+ if [ ${#server_cert} -lt 10 ]; then
|
|
697
|
+ cat /etc/openvpn/easy-rsa/keys/${OPENVPN_SERVER_NAME}.crt
|
|
698
|
+ echo $'Server cert generation failed' >> /var/log/${PROJECT_NAME}.log
|
|
699
|
+ exit 3284682
|
|
700
|
+ fi
|
|
701
|
+
|
|
702
|
+ if [ ! -f /etc/openvpn/easy-rsa/keys/${OPENVPN_SERVER_NAME}.key ]; then
|
|
703
|
+ echo $'OpenVPN key not found' >> /var/log/${PROJECT_NAME}.log
|
|
704
|
+ exit 6839436
|
|
705
|
+ fi
|
|
706
|
+ if [ ! -f /etc/openvpn/easy-rsa/keys/ca.key ]; then
|
|
707
|
+ echo $'OpenVPN ca not found' >> /var/log/${PROJECT_NAME}.log
|
|
708
|
+ exit 7935203
|
|
709
|
+ fi
|
|
710
|
+ cp /etc/openvpn/easy-rsa/keys/{$OPENVPN_SERVER_NAME.crt,$OPENVPN_SERVER_NAME.key,ca.crt} /etc/openvpn
|
|
711
|
+
|
|
712
|
+ create_user_vpn_key ${MY_USERNAME}
|
|
713
|
+}
|
|
714
|
+
|
|
715
|
+function generate_stunnel_keys {
|
|
716
|
+ echo "Creating stunnel keys" >> /var/log/${PROJECT_NAME}.log
|
|
717
|
+ openssl req -x509 -nodes -days 3650 -sha256 \
|
|
718
|
+ -subj "/O=$VPN_ORGANISATION/OU=$VPN_UNIT/C=$VPN_COUNTRY_CODE/ST=$VPN_AREA/L=$VPN_LOCATION/CN=$HOSTNAME" \
|
|
719
|
+ -newkey rsa:2048 -keyout /etc/stunnel/key.pem \
|
|
720
|
+ -out /etc/stunnel/cert.pem
|
|
721
|
+ if [ ! -f /etc/stunnel/key.pem ]; then
|
|
722
|
+ echo $'stunnel key not created' >> /var/log/${PROJECT_NAME}.log
|
|
723
|
+ exit 793530
|
|
724
|
+ fi
|
|
725
|
+ if [ ! -f /etc/stunnel/cert.pem ]; then
|
|
726
|
+ echo $'stunnel cert not created' >> /var/log/${PROJECT_NAME}.log
|
|
727
|
+ exit 204587
|
|
728
|
+ fi
|
|
729
|
+ chmod 400 /etc/stunnel/key.pem
|
|
730
|
+ chmod 640 /etc/stunnel/cert.pem
|
|
731
|
+
|
|
732
|
+ cat /etc/stunnel/key.pem /etc/stunnel/cert.pem >> /etc/stunnel/stunnel.pem
|
|
733
|
+ chmod 640 /etc/stunnel/stunnel.pem
|
|
734
|
+
|
|
735
|
+ openssl pkcs12 -export -out /etc/stunnel/stunnel.p12 -inkey /etc/stunnel/key.pem -in /etc/stunnel/cert.pem -passout pass:
|
|
736
|
+ if [ ! -f /etc/stunnel/stunnel.p12 ]; then
|
|
737
|
+ echo $'stunnel pkcs12 not created' >> /var/log/${PROJECT_NAME}.log
|
|
738
|
+ exit 639353
|
|
739
|
+ fi
|
|
740
|
+ chmod 640 /etc/stunnel/stunnel.p12
|
|
741
|
+
|
|
742
|
+ cp /etc/stunnel/stunnel.pem /home/$MY_USERNAME/stunnel.pem
|
|
743
|
+ cp /etc/stunnel/stunnel.p12 /home/$MY_USERNAME/stunnel.p12
|
|
744
|
+ chown $MY_USERNAME:$MY_USERNAME $prefix$userhome/stunnel*
|
|
745
|
+ echo "stunnel keys created" >> /var/log/${PROJECT_NAME}.log
|
|
746
|
+}
|
|
747
|
+
|
|
748
|
+function mesh_setup_vpn {
|
|
749
|
+ vpn_generate_keys
|
|
750
|
+
|
|
751
|
+ cp /etc/stunnel/stunnel-client.conf /home/$MY_USERNAME/stunnel-client.conf
|
|
752
|
+ chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/stunnel*
|
|
753
|
+
|
|
754
|
+ generate_stunnel_keys
|
|
755
|
+
|
|
756
|
+ systemctl restart openvpn
|
|
757
|
+}
|
|
758
|
+
|
|
759
|
+
|
559
|
760
|
# whether to reset the identity
|
560
|
761
|
set_new_identity=
|
561
|
762
|
if [ $2 ]; then
|
|
@@ -596,6 +797,11 @@ if [ -f $MESH_INSTALL_SETUP ]; then
|
596
|
797
|
rm -rf /home/$MY_USERNAME/.ssb
|
597
|
798
|
fi
|
598
|
799
|
|
|
800
|
+ # Remove vpn keys
|
|
801
|
+ if [ -d /etc/openvpn/easy-rsa/keys ]; then
|
|
802
|
+ rm -rf /etc/openvpn/easy-rsa/keys/*
|
|
803
|
+ fi
|
|
804
|
+
|
599
|
805
|
echo $'Beginning mesh node setup' >> $INSTALL_LOG
|
600
|
806
|
|
601
|
807
|
if [ -d /home/$MY_USERNAME/.config ]; then
|