forked from younix/ucspi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·141 lines (106 loc) · 4.83 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
#!/bin/ksh
. ./tap-functions -u
plan_tests 32
# prepare
file_grep() {
file=$1
regex=$2
grep -q "$regex" $file
ok $? "environment variable: \"$regex\""
}
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 :; 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
file_grep $tmpdir/env.txt "^TCPREMOTEIP=127.0.0.1\$"
file_grep $tmpdir/env.txt "^TCPREMOTEHOST=localhost\$"
file_grep $tmpdir/env.txt "^TCPREMOTEPORT=$CLIENT_PORT\$"
file_grep $tmpdir/env.txt "^TCPLOCALIP=127.0.0.1\$"
file_grep $tmpdir/env.txt "^TCPLOCALHOST=localhost\$"
file_grep $tmpdir/env.txt "^TCPLOCALPORT=$SERVER_PORT\$"
file_grep $tmpdir/env.txt "^PROTO=TCP\$"
#########################################################################
# 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
file_grep $tmpdir/env.txt "^TCPREMOTEIP=127.0.0.1\$"
file_grep $tmpdir/env.txt "^TCPREMOTEHOST=localhost\$"
file_grep $tmpdir/env.txt "^TCPREMOTEPORT=$SERVER_PORT\$"
file_grep $tmpdir/env.txt "^TCPLOCALIP=127.0.0.1\$"
file_grep $tmpdir/env.txt "^TCPLOCALHOST=localhost\$"
file_grep $tmpdir/env.txt "^TCPLOCALPORT=$CLIENT_PORT\$"
file_grep $tmpdir/env.txt "^PROTO=TCP\$"
#########################################################################
# cert checks #
#########################################################################
# TODO: add a test 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 :; 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
file_grep $tmpdir/env.txt "^TCPREMOTEIP=127.0.0.1\$"
file_grep $tmpdir/env.txt "^TCPREMOTEHOST=localhost\$"
file_grep $tmpdir/env.txt "^TCPREMOTEPORT=$SERVER_PORT\$"
file_grep $tmpdir/env.txt "^TCPLOCALIP=127.0.0.1\$"
file_grep $tmpdir/env.txt "^TCPLOCALHOST=localhost\$"
file_grep $tmpdir/env.txt "^TCPLOCALPORT=$CLIENT_PORT\$"
file_grep $tmpdir/env.txt "^PROTO=SSL\$"
#########################################################################
# 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
file_grep $tmpdir/env.txt "^TCPREMOTEIP=127.0.0.1\$"
file_grep $tmpdir/env.txt "^TCPREMOTEHOST=localhost\$"
file_grep $tmpdir/env.txt "^TCPREMOTEPORT=$CLIENT_PORT\$"
file_grep $tmpdir/env.txt "^TCPLOCALIP=127.0.0.1\$"
file_grep $tmpdir/env.txt "^TCPLOCALHOST=localhost\$"
file_grep $tmpdir/env.txt "^TCPLOCALPORT=$SERVER_PORT\$"
file_grep $tmpdir/env.txt "^PROTO=SSL\$"
# clean up
rm -rf $tmpdir
# vim: set spell spelllang=en: