-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-bridge-line
50 lines (41 loc) · 1.47 KB
/
get-bridge-line
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
#
# This script extracts the pieces that we need to compile our bridge line.
# This will have to do until the following bug is fixed:
# <https://gitlab.torproject.org/tpo/core/tor/-/issues/29128>
TOR_LOG=/var/log/tor/log
PT_STATE=/var/lib/tor/pt_state/obfs4_bridgeline.txt
FINGERPRINT=/var/lib/tor/fingerprint
if [ ! -r "$TOR_LOG" ]
then
echo "Cannot read Tor's log file ${TOR_LOG}. This is a bug."
exit 1
fi
if [ ! -r "$PT_STATE" ]
then
echo "Cannot read PT state file ${TOR_LOG}. This is a bug."
exit 1
fi
addr="$OBFS4V_Address"
if [ -z "$addr" ]; then
addr=$(grep 'Our IP Address has changed from' "$TOR_LOG" | \
sed 's/.* \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\); .*/\1/' | \
tail -1)
fi
if [ -z "$addr" ]; then
addr=$(grep 'External address seen and suggested by a directory authority:' "$TOR_LOG" | \
sed 's/.*: \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)/\1/' | \
tail -1)
fi
port=$(grep "Registered server transport 'obfs4' at" "$TOR_LOG" | \
sed "s/.*:\([0-9]\{1,5\}\)'$/\1/" | \
tail -1)
fingerprint=$(sed 's/.* //' "$FINGERPRINT")
obfs4_args=$(grep '^Bridge obfs4' "$PT_STATE" | sed 's/.*\(cert=.*\)/\1/' | \
tail -1)
if [[ "$addr" = "" || "$port" = "" || "$fingerprint" = "" || "$obfs4_args" = "" ]]
then
echo "Could not create bridge line. Tor's log format may have changed. This is a bug."
exit 1
fi
echo "obfs4 ${addr}:${port} ${fingerprint} ${obfs4_args}"