Pārlūkot izejas kodu

Merge branch 'stretch' of https://github.com/bashrc/freedombone

Bob Mottram 7 gadus atpakaļ
vecāks
revīzija
2bd220ab5c
4 mainītis faili ar 63 papildinājumiem un 201 dzēšanām
  1. 0
    201
      src/freedombone-base-email
  2. 10
    0
      src/freedombone-tests
  3. 2
    0
      src/freedombone-upgrade
  4. 51
    0
      src/freedombone-utils-web

+ 0
- 201
src/freedombone-base-email Parādīt failu

@@ -119,33 +119,6 @@ function email_create_template {
119 119
     fi
120 120
 }
121 121
 
122
-function email_install_tls {
123
-    # make a tls certificate for email
124
-    if [ ! -f /etc/ssl/certs/exim.dhparam ]; then
125
-        ${PROJECT_NAME}-addcert -h exim --dhkey $DH_KEYLENGTH
126
-        check_certificates exim
127
-    fi
128
-    cp /etc/ssl/private/exim.key /etc/exim4
129
-    cp /etc/ssl/certs/exim.crt /etc/exim4
130
-    cp /etc/ssl/certs/exim.dhparam /etc/exim4
131
-    chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
132
-    chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
133
-
134
-    sed -i '/login_saslauthd_server/,/.endif/ s/# *//' /etc/exim4/exim4.conf.template
135
-    if ! grep -q "MAIN_TLS_ENABLE = true" /etc/exim4/exim4.conf.template; then
136
-        sed -i "/.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME/i\MAIN_HARDCODE_PRIMARY_HOSTNAME =\nMAIN_TLS_ENABLE = true" /etc/exim4/exim4.conf.template
137
-    else
138
-        sed -i "s|MAIN_HARDCODE_PRIMARY_HOSTNAME =.*|MAIN_HARDCODE_PRIMARY_HOSTNAME =|g" /etc/exim4/exim4.conf.template
139
-    fi
140
-    sed -i "s|SMTPLISTENEROPTIONS=''|SMTPLISTENEROPTIONS='-oX 465:25:587 -oP /var/run/exim4/exim.pid'|g" /etc/default/exim4
141
-    if ! grep -q "tls_on_connect_ports=465" /etc/exim4/exim4.conf.template; then
142
-        sed -i '/SSL configuration for exim/i\tls_on_connect_ports=465' /etc/exim4/exim4.conf.template
143
-    fi
144
-    if ! grep -q "# don't send system passwords" /etc/exim4/exim4.conf.template; then
145
-        sed -i "s|don't send system passwords.*|# don't send system passwords unencrypted|g" /etc/exim4/exim4.conf.template
146
-    fi
147
-}
148
-
149 122
 function configure_email_onion {
150 123
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
151 124
         return
@@ -832,179 +805,6 @@ function remove_email {
832 805
     echo ''
833 806
 }
834 807
 
835
-function install_email_with_tor {
836
-    apt-get -yq remove postfix
837
-    apt-get -yq install exim4 sasl2-bin swaks libnet-ssleay-perl procmail xinetd
838
-
839
-    if [ ! -d /etc/exim4 ]; then
840
-        echo $"ERROR: Exim does not appear to have installed. $CHECK_MESSAGE"
841
-        exit 48
842
-    fi
843
-
844
-    onion_service_name='email'
845
-    if [ ! -d /var/lib/tor ]; then
846
-        echo $"No Tor installation found. ${onion_service_name} onion site cannot be configured."
847
-        exit 877367
848
-    fi
849
-    if ! grep -q "hidden_service_${onion_service_name}" /etc/tor/torrc; then
850
-        echo "HiddenServiceDir /var/lib/tor/hidden_service_${onion_service_name}/" >> /etc/tor/torrc
851
-        echo 'HiddenServicePort 25 127.0.0.1:25' >> /etc/tor/torrc
852
-        echo 'HiddenServicePort 587 127.0.0.1:587' >> /etc/tor/torrc
853
-        echo 'HiddenServicePort 465 127.0.0.1:465' >> /etc/tor/torrc
854
-        echo 'HiddenServicePort 993 127.0.0.1:993' >> /etc/tor/torrc
855
-        echo $"Added onion site for ${onion_service_name}"
856
-    fi
857
-
858
-    onion_update
859
-    function_check wait_for_onion_service
860
-    wait_for_onion_service ${onion_service_name}
861
-
862
-    if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
863
-        echo $"${onion_service_name} onion site hostname not found"
864
-        exit 76362
865
-    fi
866
-    EMAIL_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_${onion_service_name}/hostname)
867
-
868
-    if [[ $ONION_ONLY != "no" ]]; then
869
-        function_check set_hostname
870
-        set_hostname ${EMAIL_ONION_HOSTNAME}
871
-        MY_EMAIL_ADDRESS=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}
872
-    fi
873
-    set_completion_param "email onion domain" "${EMAIL_ONION_HOSTNAME}"
874
-
875
-    # see https://github.com/petterreinholdtsen/exim4-smtorp
876
-    echo '# tor stuff first' > /etc/exim4/conf.d/router/100_exim4-smtorp
877
-    echo '#' >> /etc/exim4/conf.d/router/100_exim4-smtorp
878
-    echo '# if were submitting mail *from* a .tor/.onion address,' >> /etc/exim4/conf.d/router/100_exim4-smtorp
879
-    echo '# make sure any header lines that may give us away is' >> /etc/exim4/conf.d/router/100_exim4-smtorp
880
-    echo '# stripped out, and add a new, cryptic Message-ID.' >> /etc/exim4/conf.d/router/100_exim4-smtorp
881
-    echo '# In address_data we store the name we should HELO as.' >> /etc/exim4/conf.d/router/100_exim4-smtorp
882
-    echo 'tor_to_any:' >> /etc/exim4/conf.d/router/100_exim4-smtorp
883
-    echo '        debug_print     = "R: manualroute from .onion to $local_part@$domain"' >> /etc/exim4/conf.d/router/100_exim4-smtorp
884
-    echo '        driver          = manualroute' >> /etc/exim4/conf.d/router/100_exim4-smtorp
885
-    echo '        domains         = ! +local_domains' >> /etc/exim4/conf.d/router/100_exim4-smtorp
886
-    echo '        condition       = ${if match {$sender_address_domain}{\N.*\.(onion|tor)$\N}}' >> /etc/exim4/conf.d/router/100_exim4-smtorp
887
-    echo '        address_data    = $sender_address_domain' >> /etc/exim4/conf.d/router/100_exim4-smtorp
888
-    echo '        transport       = remote_smtp_onion' >> /etc/exim4/conf.d/router/100_exim4-smtorp
889
-    echo '        self            = send' >> /etc/exim4/conf.d/router/100_exim4-smtorp
890
-    echo '        route_list      = * localhost' >> /etc/exim4/conf.d/router/100_exim4-smtorp
891
-    echo '        headers_remove  = Received:Message-ID:X-Mailer:User-Agent' >> /etc/exim4/conf.d/router/100_exim4-smtorp
892
-    echo '        headers_add     = Message-ID: <${lc:${sha1:$message_id}}@$sender_address_domain>' >> /etc/exim4/conf.d/router/100_exim4-smtorp
893
-    echo '' >> /etc/exim4/conf.d/router/100_exim4-smtorp
894
-    echo '# this catches the case where were submitting mail' >> /etc/exim4/conf.d/router/100_exim4-smtorp
895
-    echo '# from a regular email address where we dont need to' >> /etc/exim4/conf.d/router/100_exim4-smtorp
896
-    echo '# rewrite any headers' >> /etc/exim4/conf.d/router/100_exim4-smtorp
897
-    echo 'any_to_tor:' >> /etc/exim4/conf.d/router/100_exim4-smtorp
898
-    echo '        debug_print     = "R: manualroute for $local_part@$domain"' >> /etc/exim4/conf.d/router/100_exim4-smtorp
899
-    echo '        driver          = manualroute' >> /etc/exim4/conf.d/router/100_exim4-smtorp
900
-    echo '        domains         = ! +local_domains' >> /etc/exim4/conf.d/router/100_exim4-smtorp
901
-    echo '        transport       = remote_smtp_onion' >> /etc/exim4/conf.d/router/100_exim4-smtorp
902
-    echo '        self            = send' >> /etc/exim4/conf.d/router/100_exim4-smtorp
903
-    echo '        route_list      = *.onion localhost ; *.tor localhost' >> /etc/exim4/conf.d/router/100_exim4-smtorp
904
-    echo '        address_data    = $smtp_active_hostname' >> /etc/exim4/conf.d/router/100_exim4-smtorp
905
-
906
-    echo 'remote_smtp_onion:' > /etc/exim4/conf.d/transport/100_exim4-smtorp
907
-    echo '        debug_print = "T: remote_smtp_onion for $local_part@$original_domain"' >> /etc/exim4/conf.d/transport/100_exim4-smtorp
908
-    echo '        driver = smtp' >> /etc/exim4/conf.d/transport/100_exim4-smtorp
909
-    echo '' >> /etc/exim4/conf.d/transport/100_exim4-smtorp
910
-    echo '        # set helo_data to where we want to connect to,' >> /etc/exim4/conf.d/transport/100_exim4-smtorp
911
-    echo '        # for the proxy program tor-smtp' >> /etc/exim4/conf.d/transport/100_exim4-smtorp
912
-    echo '        helo_data = "$address_data $original_domain"' >> /etc/exim4/conf.d/transport/100_exim4-smtorp
913
-    echo '' >> /etc/exim4/conf.d/transport/100_exim4-smtorp
914
-    echo '        # wherever we configured our script at' >> /etc/exim4/conf.d/transport/100_exim4-smtorp
915
-    echo '        port = 12668' >> /etc/exim4/conf.d/transport/100_exim4-smtorp
916
-    echo '' >> /etc/exim4/conf.d/transport/100_exim4-smtorp
917
-    echo '        # cannot use TLS otherwise it will EHLO again!!' >> /etc/exim4/conf.d/transport/100_exim4-smtorp
918
-    echo '        hosts_avoid_tls = *' >> /etc/exim4/conf.d/transport/100_exim4-smtorp
919
-
920
-    if [ ! -d $INSTALL_DIR ]; then
921
-        mkdir -p $INSTALL_DIR
922
-    fi
923
-    cd $INSTALL_DIR
924
-    function_check git_clone
925
-    git_clone $EXIM_ONION_REPO $INSTALL_DIR/exim4-smtorp
926
-    cd $INSTALL_DIR/exim4-smtorp/tor-smtp
927
-    make
928
-    if [ ! -f $INSTALL_DIR/exim4-smtorp/tor-smtp/tor-smtp ]; then
929
-        echo $'Unable to make tor smtp transport'
930
-        exit 52629
931
-    fi
932
-    if [ ! -d /usr/lib/exim4-smtorp ]; then
933
-        mkdir /usr/lib/exim4-smtorp
934
-    fi
935
-    cp $INSTALL_DIR/exim4-smtorp/tor-smtp/tor-smtp /usr/lib/exim4-smtorp/tor-smtp
936
-    if [ ! -f /usr/lib/exim4-smtorp/tor-smtp ]; then
937
-        echo $'Unable to copy tor-smtp'
938
-        exit 83503
939
-    fi
940
-    cp $INSTALL_DIR/exim4-smtorp/xinetd /etc/xinetd.d/tor-smtp
941
-    if [ ! -f /etc/xinetd.d/tor-smtp ]; then
942
-        echo $'Unable to copy to xinetd.d'
943
-        exit 835954
944
-    fi
945
-    systemctl restart xinetd
946
-
947
-    # configure for Maildir format
948
-    sed -i 's/MAIL_DIR/#MAIL_DIR/g' /etc/login.defs
949
-    sed -i 's|#MAIL_FILE.*|MAIL_FILE Maildir/|g' /etc/login.defs
950
-
951
-    if ! grep -q "export MAIL" /etc/profile; then
952
-        echo 'export MAIL=~/Maildir' >> /etc/profile
953
-    fi
954
-
955
-    sed -i 's|pam_mail.so standard|pam_mail.so dir=~/Maildir standard|g' /etc/pam.d/login
956
-    sed -i 's|pam_mail.so standard noenv|pam_mail.so dir=~/Maildir standard|g' /etc/pam.d/sshd
957
-    sed -i 's|pam_mail.so nopen|pam_mail.so dir=~/Maildir nopen|g' /etc/pam.d/su
958
-
959
-    echo "dc_eximconfig_configtype='internet'" > /etc/exim4/update-exim4.conf.conf
960
-    if [[ $ONION_ONLY == "no" ]]; then
961
-        # both ICANN and onion domains
962
-        echo "dc_other_hostnames='${DEFAULT_DOMAIN_NAME};mail.${DEFAULT_DOMAIN_NAME};${EMAIL_ONION_HOSTNAME}'" >> /etc/exim4/update-exim4.conf.conf
963
-    else
964
-        echo "dc_other_hostnames='${EMAIL_ONION_HOSTNAME}'" >> /etc/exim4/update-exim4.conf.conf
965
-    fi
966
-    echo "dc_local_interfaces=''" >> /etc/exim4/update-exim4.conf.conf
967
-    echo "dc_readhost=''" >> /etc/exim4/update-exim4.conf.conf
968
-    echo "dc_relay_domains=''" >> /etc/exim4/update-exim4.conf.conf
969
-    echo "dc_minimaldns='false'" >> /etc/exim4/update-exim4.conf.conf
970
-    IPv4_address=$(get_ipv4_address)
971
-    IPv4_address_base=$(echo "$IPv4_address" | awk -F '.' '{print $1"."$2"."$3}')
972
-    RELAY_NETS="${IPv4_address_base}.0/24"
973
-    if [ $LOCAL_NETWORK_STATIC_IP_ADDRESS ]; then
974
-        RELAY_NETS=$(echo $LOCAL_NETWORK_STATIC_IP_ADDRESS | awk -F '.' '{print $1 "." $2 "." $3 ".0/24"}')
975
-    fi
976
-    echo "dc_relay_nets='$RELAY_NETS'" >> /etc/exim4/update-exim4.conf.conf
977
-    echo "dc_smarthost=''" >> /etc/exim4/update-exim4.conf.conf
978
-    echo "CFILEMODE='644'" >> /etc/exim4/update-exim4.conf.conf
979
-    echo "dc_use_split_config='false'" >> /etc/exim4/update-exim4.conf.conf
980
-    echo "dc_hide_mailname=''" >> /etc/exim4/update-exim4.conf.conf
981
-    echo "dc_mailname_in_oh='true'" >> /etc/exim4/update-exim4.conf.conf
982
-    echo "dc_localdelivery='maildir_home'" >> /etc/exim4/update-exim4.conf.conf
983
-    echo "dc_main_log_selector=-all" >> /etc/exim4/update-exim4.conf.conf
984
-    update-exim4.conf
985
-    sed -i "s/START=no/START=yes/g" /etc/default/saslauthd
986
-    systemctl start saslauthd
987
-
988
-    email_install_tls
989
-
990
-    adduser $MY_USERNAME sasl
991
-    addgroup Debian-exim sasl
992
-    systemctl restart exim4
993
-
994
-    email_create_template
995
-
996
-    if [ -f /usr/sbin/exim ]; then
997
-        chmod u+s /usr/sbin/exim
998
-    fi
999
-    if [ -f /usr/sbin/exim4 ]; then
1000
-        chmod u+s /usr/sbin/exim4
1001
-    fi
1002
-
1003
-    function_check configure_firewall_for_email
1004
-    configure_firewall_for_email
1005
-    dpkg-reconfigure --frontend noninteractive exim4-config
1006
-}
1007
-
1008 808
 function install_email_basic {
1009 809
     apt-get -yq remove postfix
1010 810
     apt-get -yq install exim4 sasl2-bin swaks libnet-ssleay-perl procmail
@@ -1710,7 +1510,6 @@ function install_email {
1710 1510
     check_email_address_exists
1711 1511
     install_email_basic
1712 1512
     configure_email_onion
1713
-    #install_email_with_tor
1714 1513
 
1715 1514
     mark_completed $FUNCNAME
1716 1515
 }

+ 10
- 0
src/freedombone-tests Parādīt failu

@@ -131,10 +131,20 @@ function stig_spinner {
131 131
     wait $1
132 132
 }
133 133
 
134
+function disallow_package {
135
+    package_name=$1
136
+
137
+    if service --status-all | grep "+.*${package_name}";then
138
+        apt-get -yq remove --purge ${package_name}
139
+        apt -yq autoremove
140
+    fi
141
+}
142
+
134 143
 function fix_stig {
135 144
     if [[ $RUN_STIG != 'fix' ]]; then
136 145
         return
137 146
     fi
147
+    disallow_package xinetd
138 148
     lockdown_permissions
139 149
 }
140 150
 

+ 2
- 0
src/freedombone-upgrade Parādīt failu

@@ -50,6 +50,7 @@ done
50 50
 
51 51
 read_config_param PROJECT_REPO
52 52
 read_config_param DEVELOPMENT_BRANCH
53
+read_config_param DEFAULT_DOMAIN_NAME
53 54
 
54 55
 DEVELOPMENT_BRANCH=master
55 56
 write_config_param "DEVELOPMENT_BRANCH" "$DEVELOPMENT_BRANCH"
@@ -92,6 +93,7 @@ if [ -d $PROJECT_DIR ]; then
92 93
             exit 453536
93 94
         fi
94 95
 
96
+        email_install_tls
95 97
         defrag_filesystem
96 98
     fi
97 99
 fi

+ 51
- 0
src/freedombone-utils-web Parādīt failu

@@ -968,4 +968,55 @@ function install_composer {
968 968
     fi
969 969
 }
970 970
 
971
+function email_install_tls {
972
+    tls_config_file=/etc/exim4/conf.d/main/03_exim4-config_tlsoptions
973
+    tls_auth_config_file=/etc/exim4/conf.d/auth/30_exim4-config_examples
974
+    email_config_changed=
975
+
976
+    if [ ! -f $tls_config_file ]; then
977
+        tls_config_file=/etc/exim4/exim4.conf.template
978
+        tls_auth_config_file=$tls_config_file
979
+    fi
980
+    if [ ! -f /etc/ssl/certs/exim.dhparam ]; then
981
+        ${PROJECT_NAME}-addcert -h exim --dhkey $DH_KEYLENGTH
982
+        check_certificates exim
983
+        cp /etc/ssl/certs/exim.dhparam /etc/exim4
984
+        chown root:Debian-exim /etc/exim4/exim.dhparam
985
+        chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
986
+        email_config_changed=1
987
+    fi
988
+    if ! grep -q 'MAIN_TLS_ENABLE = true' $tls_config_file; then
989
+        sed -i "/.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME/i\MAIN_HARDCODE_PRIMARY_HOSTNAME =\nMAIN_TLS_ENABLE = true" $tls_config_file
990
+        email_config_changed=1
991
+    fi
992
+    if ! grep -q "tls_on_connect_ports=465" $tls_config_file; then
993
+        sed -i '/SSL configuration for exim/i\tls_on_connect_ports=465' $tls_config_file
994
+        email_config_changed=1
995
+    fi
996
+    if grep -q '# login_saslauthd_server' $tls_auth_config_file; then
997
+        sed -i '/login_saslauthd_server/,/.endif/ s/# *//' $tls_auth_config_file
998
+        email_config_changed=1
999
+    fi
1000
+    if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
1001
+        if ! grep -q "MAIN_TLS_CERTKEY = /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" $tls_config_file; then
1002
+            sed -i "/.ifdef MAIN_TLS_CERTKEY/i\MAIN_TLS_CERTKEY = /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" $tls_config_file
1003
+            email_config_changed=1
1004
+        fi
1005
+    fi
1006
+    if [ -f /etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key ]; then
1007
+        if ! grep -q "MAIN_TLS_PRIVATEKEY = /etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key" $tls_config_file; then
1008
+            sed -i "/.ifndef MAIN_TLS_PRIVATEKEY/i\MAIN_TLS_PRIVATEKEY = /etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key" $tls_config_file
1009
+            email_config_changed=1
1010
+        fi
1011
+    fi
1012
+    if ! grep -q "SMTPLISTENEROPTIONS='-oX 465:25:587" /etc/default/exim4; then
1013
+        sed -i "s|SMTPLISTENEROPTIONS=.*|SMTPLISTENEROPTIONS='-oX 465:25:587 -oP /var/run/exim4/exim.pid'|g" /etc/default/exim4
1014
+        email_config_changed=1
1015
+    fi
1016
+    if [ $email_config_changed ]; then
1017
+        systemctl restart saslauthd
1018
+        systemctl restart exim4
1019
+    fi
1020
+}
1021
+
971 1022
 # NOTE: deliberately no exit 0