Add compression.test
[tinc] / test / security.test
1 #!/bin/sh
2
3 . ./testlib.sh
4
5 echo [STEP] Skip this test if tools are missing
6
7 command -v nc >/dev/null || exit $EXIT_SKIP_TEST
8 command -v timeout >/dev/null || exit $EXIT_SKIP_TEST
9
10 foo_port=30050
11 bar_port=30051
12
13 # usage: splice protocol_version
14 splice() {
15   ./splice foo localhost $foo_port bar localhost $bar_port "$1" &
16   sleep 10
17 }
18
19 # usage: send_with_timeout "data to send" "data expected to receive"
20 send_with_timeout() {
21   data=$1
22   expected=$3
23
24   result=$(
25     (
26       sleep 6
27       printf "%s\n" "$data"
28     ) | timeout 10 nc localhost $foo_port
29   ) && exit 1
30
31   test $? = $EXIT_TIMEOUT
32
33   if [ -z "$expected" ]; then
34     test -z "$result"
35   else
36     echo "$result" | grep -q "^$expected"
37   fi
38 }
39
40 echo [STEP] Initialize two nodes
41
42 tinc foo <<EOF
43 init foo
44 set DeviceType dummy
45 set Port $foo_port
46 set Address localhost
47 set PingTimeout 3
48 set AutoConnect no
49 set Subnet 10.96.96.1
50 EOF
51
52 tinc bar <<EOF
53 init bar
54 set DeviceType dummy
55 set Port $bar_port
56 set PingTimeout 3
57 set MaxTimeout 3
58 set ExperimentalProtocol no
59 set AutoConnect no
60 set Subnet 10.96.96.2
61 EOF
62
63 echo [STEP] Exchange host config files
64
65 tinc foo export | tinc bar exchange | tinc foo import
66
67 create_script foo subnet-up
68 start_tinc foo
69 wait_script foo subnet-up
70
71 create_script bar subnet-up
72 start_tinc bar
73 wait_script bar subnet-up
74
75 echo "[STEP] No ID sent by responding node if we don't send an ID first, before the timeout"
76 send_with_timeout "0 bar 17.7" ""
77
78 echo [STEP] ID sent if initiator sends first, but still tarpitted
79 send_with_timeout "0 bar 17.7" "0 foo 17.7"
80
81 echo [STEP] No invalid IDs allowed
82 send_with_timeout "0 foo 17.7" ""
83 send_with_timeout "0 baz 17.7" ""
84
85 echo [STEP] No NULL METAKEYs allowed
86 data="0 foo 17.0\n1 0 672 0 0 834188619F4D943FD0F4B1336F428BD4AC06171FEABA66BD2356BC9593F0ECD643F0E4B748C670D7750DFDE75DC9F1D8F65AB1026F5ED2A176466FBA4167CC567A2085ABD070C1545B180BDA86020E275EA9335F509C57786F4ED2378EFFF331869B856DDE1C05C461E4EECAF0E2FB97AF77B7BC2AD1B34C12992E45F5D1254BBF0C3FB224ABB3E8859594A83B6CA393ED81ECAC9221CE6BC71A727BCAD87DD80FC0834B87BADB5CB8FD3F08BEF90115A8DF1923D7CD9529729F27E1B8ABD83C4CF8818AE10257162E0057A658E265610B71F9BA4B365A20C70578FAC65B51B91100392171BA12A440A5E93C4AA62E0C9B6FC9B68F953514AAA7831B4B2C31C4\n"
87 send_with_timeout "$data" "" # Not even the ID should be sent when the first packet contains illegal data
88
89 echo [STEP] No splicing allowed
90
91 tinc bar stop
92 tinc bar del ExperimentalProtocol
93
94 create_script bar subnet-up
95 start_tinc bar
96 wait_script bar subnet-up
97
98 splice 17.7
99 pid=$!
100
101 require_nodes foo 1
102 require_nodes bar 1
103
104 kill $pid
105
106 tinc bar stop
107 tinc foo stop
108
109 echo [STEP] Test splicing again with legacy protocol
110
111 tinc foo set ExperimentalProtocol no
112 tinc bar set ExperimentalProtocol no
113
114 create_script foo subnet-up
115 start_tinc foo
116 wait_script foo subnet-up
117
118 create_script bar subnet-up
119 start_tinc bar
120 wait_script bar subnet-up
121
122 splice 17.0
123 pid=$!
124
125 require_nodes foo 1
126 require_nodes bar 1
127
128 kill $pid