瀏覽代碼

Functions for tor bridges

Bob Mottram 8 年之前
父節點
當前提交
e36c962b7d
共有 2 個檔案被更改,包括 134 行新增21 行删除
  1. 73
    21
      src/freedombone-sec
  2. 61
    0
      src/freedombone-utils-onion

+ 73
- 21
src/freedombone-sec 查看文件

751
     esac
751
     esac
752
 }
752
 }
753
 
753
 
754
+function show_tor_bridges {
755
+    echo -n ''
756
+}
757
+
758
+function add_tor_bridge {
759
+    echo -n ''
760
+}
761
+
762
+function remove_tor_bridge {
763
+    echo -n ''
764
+}
765
+
766
+function menu_security_settings {
767
+    data=$(tempfile 2>/dev/null)
768
+    trap "rm -f $data" 0 1 2 5 15
769
+    dialog --backtitle $"Freedombone Control Panel" \
770
+           --title $"Tor Bridges" \
771
+           --radiolist $"Choose an operation:" 12 50 4 \
772
+           1 $"Show bridges" off \
773
+           2 $"Add a bridge" off \
774
+           3 $"Remove a bridge" off \
775
+           4 $"Go Back/Exit" on 2> $data
776
+    sel=$?
777
+    case $sel in
778
+        1) exit 1;;
779
+        255) exit 1;;
780
+    esac
781
+
782
+    case $(cat $data) in
783
+        1)
784
+            show_tor_bridges
785
+            exit 0
786
+            ;;
787
+        2)
788
+            add_tor_bridge
789
+            exit 0
790
+            ;;
791
+        3)
792
+            remove_tor_bridge
793
+            exit 0
794
+            ;;
795
+        4)
796
+            exit 0
797
+            ;;
798
+    esac
799
+}
800
+
754
 function menu_security_settings {
801
 function menu_security_settings {
755
     data=$(tempfile 2>/dev/null)
802
     data=$(tempfile 2>/dev/null)
756
     trap "rm -f $data" 0 1 2 5 15
803
     trap "rm -f $data" 0 1 2 5 15
759
            --radiolist $"Choose an operation:" 20 76 20 \
806
            --radiolist $"Choose an operation:" 20 76 20 \
760
            1 $"Run STIG tests" off \
807
            1 $"Run STIG tests" off \
761
            2 $"Show ssh host public key" off \
808
            2 $"Show ssh host public key" off \
762
-           3 $"Password storage" off \
763
-           4 $"Export passwords" off \
764
-           5 $"Regenerate ssh host keys" off \
765
-           6 $"Regenerate Diffie-Hellman keys" off \
766
-           7 $"Update cipersuite" off \
767
-           8 $"Create a new Let's Encrypt certificate" off \
768
-           9 $"Renew Let's Encrypt certificate" off \
769
-           10 $"Enable GPG based authentication (monkeysphere)" off \
770
-           11 $"Register a website with monkeysphere" off \
771
-           12 $"Allow ssh login with passwords" off \
772
-           13 $"Go Back/Exit" on 2> $data
809
+           3 $"Tor bridges" off \
810
+           4 $"Password storage" off \
811
+           5 $"Export passwords" off \
812
+           6 $"Regenerate ssh host keys" off \
813
+           7 $"Regenerate Diffie-Hellman keys" off \
814
+           8 $"Update cipersuite" off \
815
+           9 $"Create a new Let's Encrypt certificate" off \
816
+           10 $"Renew Let's Encrypt certificate" off \
817
+           11 $"Enable GPG based authentication (monkeysphere)" off \
818
+           12 $"Register a website with monkeysphere" off \
819
+           13 $"Allow ssh login with passwords" off \
820
+           14 $"Go Back/Exit" on 2> $data
773
     sel=$?
821
     sel=$?
774
     case $sel in
822
     case $sel in
775
         1) exit 1;;
823
         1) exit 1;;
804
             exit 0
852
             exit 0
805
             ;;
853
             ;;
806
         3)
854
         3)
807
-            store_passwords
855
+            menu_tor_bridges
808
             exit 0
856
             exit 0
809
             ;;
857
             ;;
810
         4)
858
         4)
811
-            export_passwords
859
+            store_passwords
812
             exit 0
860
             exit 0
813
             ;;
861
             ;;
814
         5)
862
         5)
815
-            regenerate_ssh_host_keys
863
+            export_passwords
864
+            exit 0
816
             ;;
865
             ;;
817
         6)
866
         6)
818
-            regenerate_dh_keys
867
+            regenerate_ssh_host_keys
819
             ;;
868
             ;;
820
         7)
869
         7)
870
+            regenerate_dh_keys
871
+            ;;
872
+        8)
821
             interactive_setup
873
             interactive_setup
822
             update_ciphersuite
874
             update_ciphersuite
823
             ;;
875
             ;;
824
-        8)
876
+        9)
825
             create_letsencrypt
877
             create_letsencrypt
826
             ;;
878
             ;;
827
-        9)
879
+        10)
828
             renew_letsencrypt
880
             renew_letsencrypt
829
             ;;
881
             ;;
830
-        10)
882
+        11)
831
             enable_monkeysphere
883
             enable_monkeysphere
832
             ;;
884
             ;;
833
-        11)
885
+        12)
834
             register_website
886
             register_website
835
             ;;
887
             ;;
836
-        12)
888
+        13)
837
             allow_ssh_passwords
889
             allow_ssh_passwords
838
             change_ssh_settings
890
             change_ssh_settings
839
             exit 0
891
             exit 0
840
             ;;
892
             ;;
841
-        13)
893
+        14)
842
             exit 0
894
             exit 0
843
             ;;
895
             ;;
844
     esac
896
     esac

+ 61
- 0
src/freedombone-utils-onion 查看文件

402
     echo ""
402
     echo ""
403
 }
403
 }
404
 
404
 
405
+function tor_add_bridge {
406
+    bridge_ip_address="$1"
407
+    bridge_port="$2"
408
+    bridge_key="$3"
409
+    bridge_type='obfs4'
410
+
411
+    if [[ "$bridge_ip_address" != *"."* ]]; then
412
+        return
413
+    fi
414
+    if [ ${#bridge_port} -eq 0 ]; then
415
+        return
416
+    fi
417
+    if [ ${#bridge_key} -eq 0 ]; then
418
+        return
419
+    fi
420
+
421
+    apt-get install obfs4proxy
422
+
423
+    if grep "ClientTransportPlugin" /etc/tor/torrc; then
424
+        sed -i 's|#ClientTransportPlugin|ClientTransportPlugin|g' /etc/tor/torrc
425
+        sed -i 's|# ClientTransportPlugin|ClientTransportPlugin|g' /etc/tor/torrc
426
+        sed -i 's|ClientTransportPlugin.*|ClientTransportPlugin obfs4 exec /usr/bin/obfs4proxy managed|g' /etc/tor/torrc
427
+    else
428
+        echo 'ClientTransportPlugin obfs4 exec /usr/bin/obfs4proxy managed' >> /etc/tor/torrc
429
+    fi
430
+    if grep "UseBridges" /etc/tor/torrc; then
431
+        sed -i 's|#UseBridges|UseBridges|g' /etc/tor/torrc
432
+        sed -i 's|# UseBridges|UseBridges|g' /etc/tor/torrc
433
+        sed -i 's|UseBridges.*|UseBridges 1|g' /etc/tor/torrc
434
+    else
435
+        echo 'UseBridges 1' >> /etc/tor/torrc
436
+    fi
437
+
438
+    bridge_str="bridge $bridge_type ${bridge_ip_address}:${bridge_port} ${bridge_key}"
439
+    if ! grep "${bridge_str}" /etc/tor/torrc; then
440
+        sed -i "/UseBridges/a ${bridge_str}" >> /etc/tor/torrc
441
+    fi
442
+
443
+    systemctl restart tor
444
+}
445
+
446
+function tor_remove_bridge {
447
+    bridge_ip_address="$1"
448
+    bridge_type='obfs4'
449
+
450
+    bridge_str="bridge $bridge_type ${bridge_ip_address}"
451
+    if grep "${bridge_str}" /etc/tor/torrc; then
452
+        sed -i "/${bridge_str}/d" /etc/tor/torrc
453
+    fi
454
+    if ! grep "bridge " /etc/tor/torrc; then
455
+        if ! grep "#UseBridges" /etc/tor/torrc; then
456
+            sed -i 's|UseBridges|#UseBridges|g' /etc/tor/torrc
457
+        fi
458
+        if ! grep "#ClientTransportPlugin" /etc/tor/torrc; then
459
+            sed -i 's|ClientTransportPlugin|#ClientTransportPlugin|g' /etc/tor/torrc
460
+        fi
461
+    fi
462
+
463
+    systemctl restart tor
464
+}
465
+
405
 # NOTE: deliberately no exit 0
466
 # NOTE: deliberately no exit 0