From 7fb3a90b0a00a65d890fa4089b0d2a8275f5540f Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Mon, 15 Jul 2013 09:25:34 +0000 Subject: Let tor find a socksport it likes git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@630 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- tor-exit-ssl-check | 24 +++++++++++++++++------- 1 file 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 -- cgit v1.2.3