Ticket #13111: zero_length_keys.sh

File zero_length_keys.sh, 2.4 KB (added by teor, 5 years ago)

Test #13111 behaviour, use "-d" for deleted files, default is zero-length files

Line 
1#!/bin/sh
2# Check that tor regenerates keys when key files are zero-length
3# Test for bug #13111 - Tor fails to start if onion keys are zero length
4#
5# Usage:
6#  ./zero_length_keys.sh
7#    Check tor will launch and regenerate zero-length keys
8#  ./zero_length_keys.sh -d
9#    Check tor will launch and regenerate deleted keys
10#
11# Exit Statuses:
12#  -2: test failed - tor did not generate the key files on first run
13#  -1: a command failed - the test could not be completed
14#   0: test succeeded - tor regenerated the files
15#   1: test failed - tor did not regenerate the files
16#
17
18export DATA_DIR=`mktemp -d -t tor_zero_length_keys`
19
20# schedule ^C after the keys have been regenerated
21(sleep 5; cat $DATA_DIR/pid | xargs kill;) &
22src/or/tor --DisableNetwork 1 --ShutdownWaitLength 0 --DataDirectory $DATA_DIR --ORPort 12345 --PidFile $DATA_DIR/pid || echo "Initial tor key generation run failed" || exit -1
23# ^C occurs here, hopefully after the keys have been regenerated
24
25# tor must successfully generate non-zero-length key files
26if [ -s $DATA_DIR/keys/secret_id_key -a -s $DATA_DIR/keys/secret_onion_key -a -s $DATA_DIR/keys/secret_onion_key_ntor ]; then
27  echo "tor generated the initial key files"
28else
29  echo "tor failed to generate the initial key files"
30  exit -2
31fi
32
33# List, delete, and optionally create zero-length files for the keys
34ls -lh  $DATA_DIR/keys/ || exit -1
35rm $DATA_DIR/keys/secret_id_key || exit -1
36rm $DATA_DIR/keys/secret_onion_key || exit -1
37rm $DATA_DIR/keys/secret_onion_key_ntor || exit -1
38
39FILE_DESC="deleted"
40if [ "$1" != "-d" ]; then
41  FILE_DESC="zero-length"
42  touch $DATA_DIR/keys/secret_id_key || exit -1
43  touch $DATA_DIR/keys/secret_onion_key || exit -1
44  touch $DATA_DIR/keys/secret_onion_key_ntor || exit -1
45fi
46
47# schedule ^C after the keys have been regenerated
48(sleep 5; cat $DATA_DIR/pid | xargs kill;) &
49src/or/tor --DisableNetwork 1 --ShutdownWaitLength 0 --DataDirectory $DATA_DIR --ORPort 12345 --PidFile $DATA_DIR/pid || echo "Subsequent tor key regeneration run failed" || exit -1
50# ^C occurs here, hopefully after the keys have been regenerated
51ls -lh $DATA_DIR/keys/ || exit -1
52
53# tor must successfully regenerate non-zero-length key files
54if [ -s $DATA_DIR/keys/secret_id_key -a -s $DATA_DIR/keys/secret_onion_key -a -s $DATA_DIR/keys/secret_onion_key_ntor ]; then
55  echo "tor regenerated the $FILE_DESC key files"
56  exit 0
57else
58  echo "tor failed to regenerate the $FILE_DESC key files"
59  exit 1
60fi