Allow running tests on macOS
[tinc] / test / security.test
1 #!/bin/sh
2
3 . "${0%/*}/testlib.sh"
4
5 # Skip this test if tools are missing
6
7 which nc >/dev/null || exit 77
8
9 if [ "$(uname)" = "Darwin" ]; then
10     alias timeout=gtimeout
11 fi
12
13 which timeout >/dev/null || exit 77
14
15 # Initialize two nodes
16
17 $tinc $c1 <<EOF
18 init foo
19 set DeviceType dummy
20 set Port 32754
21 set Address localhost
22 set PingTimeout 1
23 set AutoConnect no
24 EOF
25
26 $tinc $c2 <<EOF
27 init bar
28 set DeviceType dummy
29 set Port 32755
30 set PingTimeout 1
31 set MaxTimeout 1
32 set ExperimentalProtocol no
33 set AutoConnect no
34 EOF
35
36 # Exchange host config files
37
38 $tinc $c1 export | $tinc $c2 exchange | $tinc $c1 import
39
40 $tinc $c1 start $r1
41 $tinc $c2 start $r2
42
43 # No ID sent by responding node if we don't send an ID first, before the timeout
44
45 result=`(sleep 2; echo "0 bar 17.7") | timeout 3 nc localhost 32754` && exit 1
46 test $? = 124
47 test -z "$result"
48
49 # ID sent if initiator sends first, but still tarpitted
50
51 result=`echo "0 bar 17.7" | timeout 3 nc localhost 32754` && exit 1
52 test $? = 124
53 test "`echo "$result" | head -c 10`" = "0 foo 17.7"
54
55 # No invalid IDs allowed
56
57 result=`echo "0 foo 17.7" | timeout 1 nc localhost 32754` && exit 1
58 test $? = 124
59 test -z "$result"
60
61 result=`echo "0 baz 17.7" | timeout 1 nc localhost 32754` && exit 1
62 test $? = 124
63 test -z "$result"
64
65 # No NULL METAKEYs allowed
66
67 result=`printf "0 foo 17.0\n1 0 672 0 0 834188619F4D943FD0F4B1336F428BD4AC06171FEABA66BD2356BC9593F0ECD643F0E4B748C670D7750DFDE75DC9F1D8F65AB1026F5ED2A176466FBA4167CC567A2085ABD070C1545B180BDA86020E275EA9335F509C57786F4ED2378EFFF331869B856DDE1C05C461E4EECAF0E2FB97AF77B7BC2AD1B34C12992E45F5D1254BBF0C3FB224ABB3E8859594A83B6CA393ED81ECAC9221CE6BC71A727BCAD87DD80FC0834B87BADB5CB8FD3F08BEF90115A8DF1923D7CD9529729F27E1B8ABD83C4CF8818AE10257162E0057A658E265610B71F9BA4B365A20C70578FAC65B51B91100392171BA12A440A5E93C4AA62E0C9B6FC9B68F953514AAA7831B4B2C31C4\n" | timeout 3 nc localhost 32755` && exit 1
68 test $? = 124
69 test -z "$result" # Not even the ID should be sent when the first packet contains illegal data
70
71 # No splicing allowed
72
73 $tinc $c2 stop
74 $tinc $c2 del ExperimentalProtocol
75 $tinc $c2 start $r2
76
77 ./splice foo localhost 32754 bar localhost 32755 17.7 &
78 sleep 3
79 test `$tinc $c1 dump reachable nodes | wc -l` = 1
80 test `$tinc $c2 dump reachable nodes | wc -l` = 1
81 kill $!
82
83 $tinc $c2 stop
84 $tinc $c1 stop
85
86 # Test splicing again with legacy protocol
87
88 $tinc $c1 set ExperimentalProtocol no
89 $tinc $c2 set ExperimentalProtocol no
90
91 $tinc $c1 start $r1
92 $tinc $c2 start $r2
93
94 ./splice foo localhost 32754 bar localhost 32755 17.0 &
95 sleep 3
96 test `$tinc $c1 dump reachable nodes | wc -l` = 1
97 test `$tinc $c2 dump reachable nodes | wc -l` = 1
98 kill $!
99
100 # Clean up
101
102 $tinc $c2 stop
103 $tinc $c1 stop