summaryrefslogtreecommitdiff
path: root/tor-exit-ssl-check
diff options
context:
space:
mode:
Diffstat (limited to 'tor-exit-ssl-check')
-rwxr-xr-xtor-exit-ssl-check24
1 files changed, 17 insertions, 7 deletions
diff --git a/tor-exit-ssl-check b/tor-exit-ssl-check
index ebb388b..5185830 100755
--- a/tor-exit-ssl-check
+++ b/tor-exit-ssl-check
@@ -65,7 +65,6 @@ fi
torserver="$1"; shift
declare -a targets=("$@")
-socksport=$((RANDOM % 40000 + 20000))
mapaddr="192.0.2.1"
@@ -108,7 +107,7 @@ datadir=${datadir:-$tmpdir/tor}
cat > "$tmpdir/torrc" << EOF
DataDirectory $datadir
RunAsDaemon 1
-SocksPort $socksport
+SocksPort auto
PidFile $pidfile
Log $loglevel file $torlog
SafeLogging 0
@@ -116,11 +115,6 @@ ControlSocket $tmpdir/sock
StrictNodes 1
EOF
-cat > "$tmpdir/torsocks.conf" << EOF
-server = 127.0.0.1
-server_port = $socksport
-EOF
-
mkdir -p -m 0700 "$datadir"
if [ "$verbose" -gt 0 ]; then hush=""; else hush="--hush"; fi
"$tor" $hush -f "$tmpdir/torrc"
@@ -160,6 +154,22 @@ coproc socat UNIX-CONNECT:"$tmpdir/sock" -
echo 'AUTHENTICATE' >&${COPROC[1]}
expect_ok
+echo 'GETINFO net/listeners/socks' >&${COPROC[1]}
+read line <&${COPROC[0]}
+line=$(echo "$line" | tr -d '\r')
+socksport=$( echo "$line" | sed -e 's#^250-net/listeners/socks="127.0.0.1:##; s#"$##' )
+if [ "$socksport" = "$line" ] || echo "$socksport" | grep -q '[^0-9]'; then
+ echo >&2 "Did not manage to learn listening port from tor."
+ echo >&2 "Got '$line' and parsed it into '$socksport'."
+ exit 1
+fi
+expect_ok
+
+cat > "$tmpdir/torsocks.conf" << EOF
+server = 127.0.0.1
+server_port = $socksport
+EOF
+
errors=0
while : ; do
if [ "$torserver" = "-" ]; then