Verified Commit 91a2203a authored by Silvio Rhatto's avatar Silvio Rhatto
Browse files

Feat(test-keys): use a UNIX socket

parent 6722a9e3
......@@ -39,7 +39,7 @@ ENV_LOCAL="$POOL/local.conf"
DEPENDENCIES="gcc libsodium-dev make autoconf libpcre2-dev"
# Tor daemon, to test the generated keys
DEPENDENCIES="$DEPENDENCIES tor netcat"
DEPENDENCIES="$DEPENDENCIES tor netcat-openbsd"
# For HARICA's onion-csr
DEPENDENCIES="$DEPENDENCIES ruby-dev build-essential"
......
......@@ -25,9 +25,13 @@ source $DIRNAME/params
# Additional parameters
CANDIDATE="$2"
PORT="${3:-8080}"
WAIT="${4:-60}"
WAIT="${3:-60}"
NOUNCE="$(echo $RANDOM | sha512sum | awk '{ print $1 }')"
DAEMON_DIR="$POOL/daemon"
SOCKET="$DAEMON_DIR/nc.socket"
# Use a random TCP port for the Onion Service
PORT="$(echo $RANDOM)"
# Teardown procedure
function teardown() {
......@@ -41,18 +45,19 @@ function teardown() {
rm -f "$TMPFILE"
fi
rm -f $SOCKET
exit $1
}
function usage() {
echo "usage: $BASENAME <pool> <candidate> [port] [wait]"
echo "usage: $BASENAME <pool> <candidate> [wait]"
echo ""
echo "Test an Onion Service keypair candidate mined in a pool"
echo ""
echo " pool: the mining pool to operate on"
echo " candidate: which candidate in the pool to test"
echo " port: TCP port to bind the test web server, defaults to $PORT"
echo " wait: how many seconds to wait for service bootstrap and checking, defaults to $WAIT"
echo " wait: how many seconds to wait between service bootstrap and checking, defaults to $WAIT"
}
# Check for a config
......@@ -83,14 +88,21 @@ if ! which tor &> /dev/null; then
exit 1
fi
# Create a folder where the daemon will run
# Create a folder where the daemons will run
mkdir -p $POOL/daemon
cd $POOL/daemon
# Launch a one-time minimal web server
# Invoking netcat with -q 1 to ensure it serves only a single request
echo "Launching a minimal web server listening on $SOCKET..."
TMPFILE="`mktemp`"
echo -e "HTTP/1.1 200 OK\n\n$NOUNCE" > $TMPFILE
cat $TMPFILE | nc -l -q 1 -U $SOCKET &
# Launch Tor
echo "Launching the Tor daemon with $CANDIDATE Onion Service..."
echo "Launching the Tor daemon with $CANDIDATE Onion Service listening on port $PORT..."
tor --SocksPort 0 --RunAsDaemon 0 --HiddenServiceDir $CANDIDATES/$CANDIDATE \
--HiddenServicePort "$PORT 127.0.0.1:$PORT" & # --Log "info-err stdout"
--HiddenServicePort "$PORT unix:$SOCKET" &
# Waiting
echo "Sleeping $WAIT seconds while the Onion Service is bootstrapped..."
......@@ -98,12 +110,6 @@ sleep $WAIT
PIDS="$!"
#echo "Background tasks: $PIDS"
# Launch a one-time minimal web server
echo "Launching a minimal web server or port $PORT..."
TMPFILE="`mktemp`"
echo -e "HTTP/1.1 200 OK\n\n$NOUNCE" > $TMPFILE
cat $TMPFILE | nc -l -q 1 -p $PORT &
# Try to get the secret
echo "Trying to fetch the secret random value $NOUNCE from the Onion Service..."
NOUNCE_OFFERED="`torify curl --no-progress-meter --connect-timeout $WAIT http://$CANDIDATE:$PORT`"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment