-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.sh
executable file
·150 lines (114 loc) · 5.21 KB
/
test.sh
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/ksh
. ./tap-functions -u
plan_tests 33
# prepare
expect_env() {
file="$1"
key="$2"
expected="$3"
output="$(grep "^$key=" "$file")"
test "$key=$expected" = "$output"
ok $? "Expected $key to be $expected (found $output)"
}
tmpdir=$(mktemp -d tests_XXXXXX)
touch $tmpdir/tcps.log # prevent ENOENT in until grep loop later
#########################################################################
# plain server to client communication #
#########################################################################
./tcps -d 127.0.0.1 0 /usr/bin/env 2>$tmpdir/tcps.log &
# wait running server
until grep -q '^listen: 127.0.0.1:' $tmpdir/tcps.log; do printf . && sleep 1; done
SERVER_PORT=$(sed -ne 's/^listen: 127.0.0.1://p' $tmpdir/tcps.log | head -n 1)
# start client
./tcpc -d 127.0.0.1 $SERVER_PORT ./read6.sh $tmpdir/env.txt 2>$tmpdir/tcpc.log
CLIENT_PORT=$(sed -ne 's/^listen: 127.0.0.1://p' $tmpdir/tcpc.log | head -n 1)
ok $? "plain connection server -> client"
kill -9 %1
# server side environment
expect_env $tmpdir/env.txt "TCPREMOTEIP" "127.0.0.1"
expect_env $tmpdir/env.txt "TCPREMOTEHOST" "localhost"
expect_env $tmpdir/env.txt "TCPREMOTEPORT" "$CLIENT_PORT"
expect_env $tmpdir/env.txt "TCPLOCALIP" "127.0.0.1"
expect_env $tmpdir/env.txt "TCPLOCALHOST" "localhost"
expect_env $tmpdir/env.txt "TCPLOCALPORT" "$SERVER_PORT"
expect_env $tmpdir/env.txt "PROTO" "TCP"
rm "$tmpdir/env.txt"
#########################################################################
# plain client to server communication #
#########################################################################
./tcps -d 127.0.0.1 0 ./read0.sh "$tmpdir/env.txt" 2>$tmpdir/tcps.log &
# wait running server
until grep -q '^listen: 127.0.0.1:' $tmpdir/tcps.log; do :; done
SERVER_PORT=$(sed -ne 's/^listen: 127.0.0.1://p' $tmpdir/tcps.log | head -n 1)
./tcpc -d 127.0.0.1 $SERVER_PORT ./write.sh 2>$tmpdir/tcpc.log
CLIENT_PORT=$(sed -ne 's/^listen: 127.0.0.1://p' $tmpdir/tcpc.log | head -n 1)
ok $? "plain connection client -> server"
kill -9 %1
# client side environment
expect_env $tmpdir/env.txt "TCPREMOTEIP" "127.0.0.1"
expect_env $tmpdir/env.txt "TCPREMOTEHOST" "localhost"
expect_env $tmpdir/env.txt "TCPREMOTEPORT" "$SERVER_PORT"
expect_env $tmpdir/env.txt "TCPLOCALIP" "127.0.0.1"
expect_env $tmpdir/env.txt "TCPLOCALHOST" "localhost"
expect_env $tmpdir/env.txt "TCPLOCALPORT" "$CLIENT_PORT"
expect_env $tmpdir/env.txt "PROTO" "TCP"
#########################################################################
# cert checks #
#########################################################################
# These should have been created by 'make test'
test -f ca.crt && test -f server.crt && test -f server.key && test -f client.crt && test -f client.key
ok $? "Certificates and keys for running tests exist."
# TODO: add more tests here
#h=$(openssl x509 -outform der -in server.crt | sha256)
#printf "SHA256:${h}\n"
#########################################################################
# encrypted client to server communication #
#########################################################################
./tcps -d 127.0.0.1 0 \
./tlss -f ca.crt -c server.crt -k server.key \
./read0.sh "$tmpdir/env.txt" 2>$tmpdir/tcps.log &
# wait running server
until grep -q '^listen: 127.0.0.1:' $tmpdir/tcps.log; do printf . && sleep 1; done
SERVER_PORT=$(sed -ne 's/^listen: 127.0.0.1://p' $tmpdir/tcps.log | head -n 1)
./tcpc -d 127.0.0.1 $SERVER_PORT \
./tlsc -f ca.crt -c client.crt -k client.key \
./write.sh 2>$tmpdir/tcpc.log
CLIENT_PORT=$(sed -ne 's/^listen: 127.0.0.1://p' $tmpdir/tcpc.log | head -n 1)
ok $? "tls connection client -> server"
kill -9 %1
# client side environment
expect_env $tmpdir/env.txt "TCPREMOTEIP" "127.0.0.1"
expect_env $tmpdir/env.txt "TCPREMOTEHOST" "localhost"
expect_env $tmpdir/env.txt "TCPREMOTEPORT" "$SERVER_PORT"
expect_env $tmpdir/env.txt "TCPLOCALIP" "127.0.0.1"
expect_env $tmpdir/env.txt "TCPLOCALHOST" "localhost"
expect_env $tmpdir/env.txt "TCPLOCALPORT" "$CLIENT_PORT"
expect_env $tmpdir/env.txt "PROTO" "SSL"
rm "$tmpdir/env.txt"
#########################################################################
# encrypted server to client communication #
#########################################################################
./tcps -d 127.0.0.1 0 \
./tlss -C -f ca.crt -c server.crt -k server.key \
/usr/bin/env 2>$tmpdir/tcps.log &
# wait running server
until grep -q '^listen: 127.0.0.1:' $tmpdir/tcps.log; do :; done
SERVER_PORT=$(sed -ne 's/^listen: 127.0.0.1://p' $tmpdir/tcps.log | head -n 1)
./tcpc -d 127.0.0.1 $SERVER_PORT \
./tlsc -f ca.crt -c client.crt -k client.key \
./read6.sh "$tmpdir/env.txt" 2>$tmpdir/tcpc.log
CLIENT_PORT=$(sed -ne 's/^listen: 127.0.0.1://p' $tmpdir/tcpc.log | head -n 1)
ok $? "tls connection server -> client"
kill -9 %1
# server side environment
expect_env $tmpdir/env.txt "TCPREMOTEIP" "127.0.0.1"
expect_env $tmpdir/env.txt "TCPREMOTEHOST" "localhost"
expect_env $tmpdir/env.txt "TCPREMOTEPORT" "$CLIENT_PORT"
expect_env $tmpdir/env.txt "TCPLOCALIP" "127.0.0.1"
expect_env $tmpdir/env.txt "TCPLOCALHOST" "localhost"
expect_env $tmpdir/env.txt "TCPLOCALPORT" "$SERVER_PORT"
expect_env $tmpdir/env.txt "PROTO" "SSL"
rm "$tmpdir/env.txt"
# clean up
rm -rf $tmpdir
# vim: set spell spelllang=en: