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