Bläddra i källkod

Move tripwire functions to security menu

Bob Mottram 7 år sedan
förälder
incheckning
3309fe281a
2 ändrade filer med 179 tillägg och 173 borttagningar
  1. 32
    146
      src/freedombone-controlpanel
  2. 147
    27
      src/freedombone-sec

+ 32
- 146
src/freedombone-controlpanel Visa fil

129
 
129
 
130
 function any_key {
130
 function any_key {
131
     echo ''
131
     echo ''
132
+    # shellcheck disable=SC2034
132
     read -n1 -rsp $"Press any key to continue..." key
133
     read -n1 -rsp $"Press any key to continue..." key
133
 }
134
 }
134
 
135
 
135
-function any_key_verify {
136
-    echo ''
137
-    read -n1 -rsp $"Press any key to continue or C to check a hash..." key
138
-    if [[ "$key" != 'c' && "$key" != 'C' ]]; then
139
-        return
140
-    fi
141
-
142
-    data=$(mktemp 2>/dev/null)
143
-    dialog --title $"Check tripwire hash" \
144
-           --backtitle $"Freedombone Control Panel" \
145
-           --inputbox $"Paste your tripwire hash below and it will be checked against the current database" 12 60 2>"$data"
146
-    sel=$?
147
-    case $sel in
148
-        0)
149
-            GIVEN_HASH=$(<"$data")
150
-            if [ ${#GIVEN_HASH} -gt 8 ]; then
151
-                if [[ "$GIVEN_HASH" == *' '* ]]; then
152
-                    dialog --title $"Check tripwire" \
153
-                           --msgbox $"\\nThe hash should not contain any spaces" 10 40
154
-                else
155
-                    DBHASH=$(sha512sum "/var/lib/tripwire/${HOSTNAME}.twd" | awk -F ' ' '{print $1}')
156
-                    if [[ "$DBHASH" == "$GIVEN_HASH" ]]; then
157
-                        dialog --title $"Check tripwire" \
158
-                               --msgbox $"\\nSuccess\\n\\nThe hash you gave matches the current tripwire database" 10 40
159
-                    else
160
-                        dialog --title $"Check tripwire" \
161
-                               --msgbox $"\\nFailed\\n\\nThe hash you gave does not match the current tripwire database. This might be because you reset the tripwire, or there could have been an unauthorised modification of the system" 12 50
162
-                    fi
163
-                fi
164
-            fi
165
-            ;;
166
-    esac
167
-    rm -f "$data"
168
-}
169
-
170
 function reset_password_tries {
136
 function reset_password_tries {
171
     passwords_select_user
137
     passwords_select_user
172
     if [ ! "$SELECTED_USERNAME" ]; then
138
     if [ ! "$SELECTED_USERNAME" ]; then
1182
     "${PROJECT_NAME}-sec"
1148
     "${PROJECT_NAME}-sec"
1183
 }
1149
 }
1184
 
1150
 
1185
-function show_tripwire_verification_code {
1186
-    if [ ! -f "/var/lib/tripwire/${HOSTNAME}.twd" ]; then
1187
-        return
1188
-    fi
1189
-    clear
1190
-    echo ''
1191
-    echo $'Tripwire Verification Code'
1192
-    echo ''
1193
-    DBHASH=$(sha512sum "/var/lib/tripwire/${HOSTNAME}.twd")
1194
-    echo -n "$DBHASH" | qrencode -t UTF8
1195
-    echo ''
1196
-    echo "$DBHASH"
1197
-    echo ''
1198
-}
1199
-
1200
-function reset_tripwire {
1201
-    if [ ! -f /usr/bin/reset-tripwire ]; then
1202
-        echo $'Missing /usr/bin/reset-tripwire'
1203
-        any_key
1204
-        return
1205
-    fi
1206
-    if [ ! -f "/etc/tripwire/${HOSTNAME}-local.key" ]; then
1207
-        if [ -f "/etc/tripwire/${PROJECT_NAME}-local.key" ]; then
1208
-            # shellcheck disable=SC2086
1209
-            mv /etc/tripwire/${PROJECT_NAME}-local.key /etc/tripwire/${HOSTNAME}-local.key
1210
-            # shellcheck disable=SC2086
1211
-            mv /etc/tripwire/${PROJECT_NAME}-site.key /etc/tripwire/${HOSTNAME}-site.key
1212
-        else
1213
-            echo $'Error: missing local key'
1214
-            any_key
1215
-            return
1216
-        fi
1217
-    fi
1218
-    clear
1219
-    echo $'Turing off logging...'
1220
-    "${PROJECT_NAME}-logging" off
1221
-    echo $'Locking down permissions...'
1222
-    lockdown_permissions
1223
-    echo $'Creating configuration...'
1224
-    echo '
1225
-
1226
-       ' | twadmin --create-cfgfile -S "/etc/tripwire/${HOSTNAME}-site.key" /etc/tripwire/twcfg.txt
1227
-    echo $'Resetting policy...'
1228
-    echo '
1229
-
1230
-       ' | twadmin --create-polfile -S "/etc/tripwire/${HOSTNAME}-site.key" /etc/tripwire/twpol.txt
1231
-    echo $'Creating tripwire database'
1232
-    echo '
1233
-
1234
-' | tripwire --init --cfgfile /etc/tripwire/tw.cfg --polfile /etc/tripwire/tw.pol --dbfile "/var/lib/tripwire/${HOSTNAME}.twd"
1235
-    echo $'Resetting the Tripwire...'
1236
-    echo ''
1237
-    echo '
1238
-
1239
-                ' | reset-tripwire
1240
-    echo ''
1241
-
1242
-    # Sometimes nginx fails to restart if matrix is installed
1243
-    # Restart matrix first
1244
-    if [ -d /etc/matrix ]; then
1245
-        systemctl restart matrix
1246
-        systemctl restart nginx
1247
-    fi
1248
-
1249
-    if [ -f "/var/lib/tripwire/${HOSTNAME}.twd" ]; then
1250
-        show_tripwire_verification_code
1251
-        echo $'Tripwire is now reset. Take a note of the above hash, or record'
1252
-        echo $'the QR code using a mobile device. This will enable you to independently'
1253
-        echo $'verify the integrity of the tripwire.'
1254
-    else
1255
-        echo $'ERROR: tripwire database was not created'
1256
-    fi
1257
-    any_key
1258
-}
1259
-
1260
 function format_drive {
1151
 function format_drive {
1261
     detect_usb_drive
1152
     detect_usb_drive
1262
     dialog --title $"Format USB drive $USB_DRIVE" \
1153
     dialog --title $"Format USB drive $USB_DRIVE" \
2082
     do
1973
     do
2083
         W=(1 $"About this system"
1974
         W=(1 $"About this system"
2084
            2 $"Backup and Restore"
1975
            2 $"Backup and Restore"
2085
-           3 $"Verify Tripwire Code"
2086
-           4 $"Reset Tripwire"
2087
-           5 $"App Settings"
2088
-           6 $"Add/Remove Apps"
2089
-           7 $"Logging on/off"
2090
-           8 $"Ping enable/disable"
2091
-           9 $"Manage Users"
2092
-           10 $"Email Menu"
2093
-           11 $"Domain or User Blocking"
2094
-           12 $"Security Settings"
2095
-           13 $"Change the name of this system"
2096
-           14 $"Set a static local IP address"
2097
-           15 $"Wifi menu"
2098
-           16 $"Add Clacks"
2099
-           17 $"Check for updates"
2100
-           18 $"Power off the system"
2101
-           19 $"Restart the system")
1976
+           3 $"App Settings"
1977
+           4 $"Add/Remove Apps"
1978
+           5 $"Logging on/off"
1979
+           6 $"Ping enable/disable"
1980
+           7 $"Manage Users"
1981
+           8 $"Email Menu"
1982
+           9 $"Domain or User Blocking"
1983
+           10 $"Security Settings"
1984
+           11 $"Change the name of this system"
1985
+           12 $"Set a static local IP address"
1986
+           13 $"Wifi menu"
1987
+           14 $"Add Clacks"
1988
+           15 $"Check for updates"
1989
+           16 $"Power off the system"
1990
+           17 $"Restart the system")
2102
 
1991
 
2103
         # shellcheck disable=SC2068
1992
         # shellcheck disable=SC2068
2104
-        selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Administrator Control Panel" --menu $"Choose an operation, or ESC to exit:" 27 60 27 "${W[@]}" 3>&2 2>&1 1>&3)
1993
+        selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Administrator Control Panel" --menu $"Choose an operation, or ESC to exit:" 25 60 25 "${W[@]}" 3>&2 2>&1 1>&3)
2105
 
1994
 
2106
         if [ ! "$selection" ]; then
1995
         if [ ! "$selection" ]; then
2107
             break
1996
             break
2112
         case $selection in
2001
         case $selection in
2113
             1) show_about;;
2002
             1) show_about;;
2114
             2) menu_backup_restore;;
2003
             2) menu_backup_restore;;
2115
-            3) show_tripwire_verification_code
2116
-               any_key_verify;;
2117
-            4) reset_tripwire;;
2118
-            5) menu_app_settings;;
2119
-            6) if ! /usr/local/bin/addremove; then
2004
+            3) menu_app_settings;;
2005
+            4) if ! /usr/local/bin/addremove; then
2120
                    any_key
2006
                    any_key
2121
                fi
2007
                fi
2122
                ;;
2008
                ;;
2123
-            7) logging_on_off;;
2124
-            8) ping_enable_disable;;
2125
-            9) menu_users;;
2126
-            10) menu_email;;
2127
-            11) domain_blocking;;
2128
-            12) security_settings;;
2129
-            13) change_system_name;;
2130
-            14) set_static_IP;;
2131
-            15) menu_wifi;;
2132
-            16) add_clacks;;
2133
-            17) check_for_updates;;
2134
-            18) shut_down_system;;
2135
-            19) restart_system;;
2009
+            5) logging_on_off;;
2010
+            6) ping_enable_disable;;
2011
+            7) menu_users;;
2012
+            8) menu_email;;
2013
+            9) domain_blocking;;
2014
+            10) security_settings;;
2015
+            11) change_system_name;;
2016
+            12) set_static_IP;;
2017
+            13) menu_wifi;;
2018
+            14) add_clacks;;
2019
+            15) check_for_updates;;
2020
+            16) shut_down_system;;
2021
+            17) restart_system;;
2136
         esac
2022
         esac
2137
     done
2023
     done
2138
 }
2024
 }

+ 147
- 27
src/freedombone-sec Visa fil

69
 
69
 
70
 MY_USERNAME=
70
 MY_USERNAME=
71
 
71
 
72
+function any_key_verify {
73
+    echo ''
74
+    read -n1 -rsp $"Press any key to continue or C to check a hash..." key
75
+    if [[ "$key" != 'c' && "$key" != 'C' ]]; then
76
+        return
77
+    fi
78
+
79
+    data=$(mktemp 2>/dev/null)
80
+    dialog --title $"Check tripwire hash" \
81
+           --backtitle $"Freedombone Control Panel" \
82
+           --inputbox $"Paste your tripwire hash below and it will be checked against the current database" 12 60 2>"$data"
83
+    sel=$?
84
+    case $sel in
85
+        0)
86
+            GIVEN_HASH=$(<"$data")
87
+            if [ ${#GIVEN_HASH} -gt 8 ]; then
88
+                if [[ "$GIVEN_HASH" == *' '* ]]; then
89
+                    dialog --title $"Check tripwire" \
90
+                           --msgbox $"\\nThe hash should not contain any spaces" 10 40
91
+                else
92
+                    DBHASH=$(sha512sum "/var/lib/tripwire/${HOSTNAME}.twd" | awk -F ' ' '{print $1}')
93
+                    if [[ "$DBHASH" == "$GIVEN_HASH" ]]; then
94
+                        dialog --title $"Check tripwire" \
95
+                               --msgbox $"\\nSuccess\\n\\nThe hash you gave matches the current tripwire database" 10 40
96
+                    else
97
+                        dialog --title $"Check tripwire" \
98
+                               --msgbox $"\\nFailed\\n\\nThe hash you gave does not match the current tripwire database. This might be because you reset the tripwire, or there could have been an unauthorised modification of the system" 12 50
99
+                    fi
100
+                fi
101
+            fi
102
+            ;;
103
+    esac
104
+    rm -f "$data"
105
+}
106
+
107
+function show_tripwire_verification_code {
108
+    if [ ! -f "/var/lib/tripwire/${HOSTNAME}.twd" ]; then
109
+        return
110
+    fi
111
+    clear
112
+    echo ''
113
+    echo $'Tripwire Verification Code'
114
+    echo ''
115
+    DBHASH=$(sha512sum "/var/lib/tripwire/${HOSTNAME}.twd")
116
+    echo -n "$DBHASH" | qrencode -t UTF8
117
+    echo ''
118
+    echo "$DBHASH"
119
+    echo ''
120
+}
121
+
122
+function reset_tripwire {
123
+    if [ ! -f /usr/bin/reset-tripwire ]; then
124
+        echo $'Missing /usr/bin/reset-tripwire'
125
+        any_key
126
+        return
127
+    fi
128
+    if [ ! -f "/etc/tripwire/${HOSTNAME}-local.key" ]; then
129
+        if [ -f "/etc/tripwire/${PROJECT_NAME}-local.key" ]; then
130
+            # shellcheck disable=SC2086
131
+            mv /etc/tripwire/${PROJECT_NAME}-local.key /etc/tripwire/${HOSTNAME}-local.key
132
+            # shellcheck disable=SC2086
133
+            mv /etc/tripwire/${PROJECT_NAME}-site.key /etc/tripwire/${HOSTNAME}-site.key
134
+        else
135
+            echo $'Error: missing local key'
136
+            any_key
137
+            return
138
+        fi
139
+    fi
140
+    clear
141
+    echo $'Turing off logging...'
142
+    "${PROJECT_NAME}-logging" off
143
+    echo $'Locking down permissions...'
144
+    lockdown_permissions
145
+    echo $'Creating configuration...'
146
+    echo '
147
+
148
+       ' | twadmin --create-cfgfile -S "/etc/tripwire/${HOSTNAME}-site.key" /etc/tripwire/twcfg.txt
149
+    echo $'Resetting policy...'
150
+    echo '
151
+
152
+       ' | twadmin --create-polfile -S "/etc/tripwire/${HOSTNAME}-site.key" /etc/tripwire/twpol.txt
153
+    echo $'Creating tripwire database'
154
+    echo '
155
+
156
+' | tripwire --init --cfgfile /etc/tripwire/tw.cfg --polfile /etc/tripwire/tw.pol --dbfile "/var/lib/tripwire/${HOSTNAME}.twd"
157
+    echo $'Resetting the Tripwire...'
158
+    echo ''
159
+    echo '
160
+
161
+                ' | reset-tripwire
162
+    echo ''
163
+
164
+    # Sometimes nginx fails to restart if matrix is installed
165
+    # Restart matrix first
166
+    if [ -d /etc/matrix ]; then
167
+        systemctl restart matrix
168
+        systemctl restart nginx
169
+    fi
170
+
171
+    if [ -f "/var/lib/tripwire/${HOSTNAME}.twd" ]; then
172
+        show_tripwire_verification_code
173
+        echo $'Tripwire is now reset. Take a note of the above hash, or record'
174
+        echo $'the QR code using a mobile device. This will enable you to independently'
175
+        echo $'verify the integrity of the tripwire.'
176
+    else
177
+        echo $'ERROR: tripwire database was not created'
178
+    fi
179
+    any_key
180
+}
181
+
72
 function passwords_show_apps {
182
 function passwords_show_apps {
73
     SELECTED_APP=
183
     SELECTED_APP=
74
     i=0
184
     i=0
1065
     W=(1 $"Passwords"
1175
     W=(1 $"Passwords"
1066
        2 $"Run STIG tests"
1176
        2 $"Run STIG tests"
1067
        3 $"Fix STIG test failures"
1177
        3 $"Fix STIG test failures"
1068
-       4 $"Show ssh host public key"
1069
-       5 $"Tor bridges"
1070
-       6 $"Password storage"
1071
-       7 $"Export passwords"
1072
-       8 $"Regenerate ssh host keys"
1073
-       9 $"Regenerate Diffie-Hellman keys"
1074
-       10 $"Update cipersuite"
1075
-       11 $"Create a new Let's Encrypt certificate"
1076
-       12 $"Renew Let's Encrypt certificate"
1077
-       13 $"Delete a Let's Encrypt certificate"
1078
-       14 $"Enable GPG based authentication (monkeysphere)"
1079
-       15 $"Register a website with monkeysphere"
1080
-       16 $"Allow ssh login with passwords"
1081
-       17 $"Show firewall")
1178
+       4 $"Show tripwire verification code"
1179
+       5 $"Reset tripwire"
1180
+       6 $"Show ssh host public key"
1181
+       7 $"Tor bridges"
1182
+       8 $"Password storage"
1183
+       9 $"Export passwords"
1184
+       10 $"Regenerate ssh host keys"
1185
+       11 $"Regenerate Diffie-Hellman keys"
1186
+       12 $"Update cipersuite"
1187
+       13 $"Create a new Let's Encrypt certificate"
1188
+       14 $"Renew Let's Encrypt certificate"
1189
+       15 $"Delete a Let's Encrypt certificate"
1190
+       16 $"Enable GPG based authentication (monkeysphere)"
1191
+       17 $"Register a website with monkeysphere"
1192
+       18 $"Allow ssh login with passwords"
1193
+       19 $"Show firewall")
1082
 
1194
 
1083
     # shellcheck disable=SC2068
1195
     # shellcheck disable=SC2068
1084
     selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Security Settings" --menu $"Choose an operation, or ESC to exit:" 24 76 24 "${W[@]}" 3>&2 2>&1 1>&3)
1196
     selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Security Settings" --menu $"Choose an operation, or ESC to exit:" 24 76 24 "${W[@]}" 3>&2 2>&1 1>&3)
1122
             exit 0
1234
             exit 0
1123
             ;;
1235
             ;;
1124
         4)
1236
         4)
1237
+            show_tripwire_verification_code
1238
+            any_key_verify
1239
+            ;;
1240
+        5)
1241
+            reset_tripwire
1242
+            ;;
1243
+
1244
+        6)
1125
             dialog --title $"SSH host public keys" \
1245
             dialog --title $"SSH host public keys" \
1126
                    --msgbox "\\n$(get_ssh_server_key)" 12 60
1246
                    --msgbox "\\n$(get_ssh_server_key)" 12 60
1127
             exit 0
1247
             exit 0
1128
             ;;
1248
             ;;
1129
-        5)
1249
+        7)
1130
             menu_tor_bridges
1250
             menu_tor_bridges
1131
             exit 0
1251
             exit 0
1132
             ;;
1252
             ;;
1133
-        6)
1253
+        8)
1134
             store_passwords
1254
             store_passwords
1135
             exit 0
1255
             exit 0
1136
             ;;
1256
             ;;
1137
-        7)
1257
+        9)
1138
             export_passwords
1258
             export_passwords
1139
             exit 0
1259
             exit 0
1140
             ;;
1260
             ;;
1141
-        8)
1261
+        10)
1142
             regenerate_ssh_host_keys
1262
             regenerate_ssh_host_keys
1143
             ;;
1263
             ;;
1144
-        9)
1264
+        11)
1145
             regenerate_dh_keys
1265
             regenerate_dh_keys
1146
             ;;
1266
             ;;
1147
-        10)
1267
+        12)
1148
             interactive_setup
1268
             interactive_setup
1149
             update_ciphersuite
1269
             update_ciphersuite
1150
             ;;
1270
             ;;
1151
-        11)
1271
+        13)
1152
             create_letsencrypt
1272
             create_letsencrypt
1153
             ;;
1273
             ;;
1154
-        12)
1274
+        14)
1155
             renew_letsencrypt
1275
             renew_letsencrypt
1156
             ;;
1276
             ;;
1157
-        13)
1277
+        15)
1158
             delete_letsencrypt
1278
             delete_letsencrypt
1159
             ;;
1279
             ;;
1160
-        14)
1280
+        16)
1161
             enable_monkeysphere
1281
             enable_monkeysphere
1162
             ;;
1282
             ;;
1163
-        15)
1283
+        17)
1164
             register_website
1284
             register_website
1165
             ;;
1285
             ;;
1166
-        16)
1286
+        18)
1167
             allow_ssh_passwords
1287
             allow_ssh_passwords
1168
             change_ssh_settings
1288
             change_ssh_settings
1169
             exit 0
1289
             exit 0
1170
             ;;
1290
             ;;
1171
-        17)
1291
+        19)
1172
             show_firewall
1292
             show_firewall
1173
             exit 0
1293
             exit 0
1174
             ;;
1294
             ;;