aboutsummaryrefslogtreecommitdiff
path: root/test/002-test-key-name.test/run.sh
blob: f3ac770fa1d2e7ede364b6fc83bff50e97cd5c56 (plain)
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
#!/bin/sh

set -e

key="$(mktemp)"
stderr="$(mktemp)"

# Four character search should be a < 1 second CPU burst for CI runner
${EXECUTABLE} -s site > $key 2>$stderr

found="$(tr '\r' '\n' < $stderr | grep Found | cut -d ' ' -f 3)"

echo "sand-leek says it found $found..."

# Trick adapted to py3 from https://swehack.org/viewtopic.php?f=37&p=6978
real="$( \
	openssl rsa -in $key -pubout -outform DER \
	| tail -c +23 \
	| shasum \
	| head -c 20 \
	| python -c "import base64,sys,codecs; print(base64.b32encode(codecs.decode(sys.stdin.readline().strip('\n'), 'hex')).decode().lower())").onion"


echo "Key analysis shows it's for ${real}"

if [ "$found" = "$real" ] ; then
	echo "It's a match, I'm happy"
	rm $key
	rm $stderr
	exit 0
else
	echo "Error: No match. Key file contents:"
	cat "$key"
	exit 1
fi