tls13.test 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. #!/bin/sh
  2. # tls13.test
  3. # copyright wolfSSL 2016
  4. # if we can, isolate the network namespace to eliminate port collisions.
  5. if [ "${AM_BWRAPPED-}" != "yes" ]; then
  6. bwrap_path="$(command -v bwrap)"
  7. if [ -n "$bwrap_path" ]; then
  8. export AM_BWRAPPED=yes
  9. exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
  10. fi
  11. unset AM_BWRAPPED
  12. fi
  13. # getting unique port is modeled after resume.test script
  14. # need a unique port since may run the same time as testsuite
  15. # use server port zero hack to get one
  16. port=0
  17. no_pid=-1
  18. server_pid=$no_pid
  19. counter=0
  20. # let's use absolute path to a local dir (make distcheck may be in sub dir)
  21. # also let's add some randomness by adding pid in case multiple 'make check's
  22. # per source tree
  23. ready_file=`pwd`/wolfssl_tls13_ready$$
  24. client_file=`pwd`/wolfssl_tls13_client$$
  25. # Server output
  26. server_out_file=`pwd`/wolfssl_tls13_server_out$$
  27. # Client output
  28. client_out_file=`pwd`/wolfssl_tls13_client_out$$
  29. echo "ready file $ready_file"
  30. create_port() {
  31. while [ ! -s $ready_file ]; do
  32. if [ "$counter" -gt 50 ]; then
  33. break
  34. fi
  35. echo -e "waiting for ready file..."
  36. sleep 0.1
  37. counter=$((counter+ 1))
  38. done
  39. if [ -e $ready_file ]; then
  40. echo -e "found ready file, starting client..."
  41. # get created port 0 ephemeral port
  42. port=`cat $ready_file`
  43. else
  44. echo -e "NO ready file ending test..."
  45. do_cleanup
  46. fi
  47. }
  48. remove_ready_file() {
  49. if [ -e $ready_file ]; then
  50. echo -e "removing existing ready file"
  51. rm $ready_file
  52. fi
  53. }
  54. do_cleanup() {
  55. echo "in cleanup"
  56. if [ $server_pid != $no_pid ]
  57. then
  58. echo "killing server"
  59. kill -9 $server_pid
  60. server_pid=$no_pid
  61. fi
  62. remove_ready_file
  63. if [ -e $client_file ]; then
  64. echo -e "removing existing client file"
  65. rm $client_file
  66. fi
  67. if [ -e $server_out_file ]; then
  68. echo -e "removing existing server output file"
  69. rm $server_out_file
  70. fi
  71. if [ -e $client_out_file ]; then
  72. echo -e "removing existing client output file"
  73. rm $client_out_file
  74. fi
  75. }
  76. do_trap() {
  77. echo "got trap"
  78. do_cleanup
  79. exit -1
  80. }
  81. trap do_trap INT TERM
  82. [ ! -x ./examples/client/client ] && echo -e "\n\nClient doesn't exist" && exit 1
  83. ./examples/client/client '-?' 2>&1 | grep -- 'Client not compiled in!'
  84. if [ $? -eq 0 ]; then
  85. exit 0
  86. fi
  87. ./examples/server/server '-?' 2>&1 | grep -- 'Server not compiled in!'
  88. if [ $? -eq 0 ]; then
  89. exit 0
  90. fi
  91. # Usual TLS v1.3 server / TLS v1.3 client.
  92. echo -e "\n\nTLS v1.3 server with TLS v1.3 client"
  93. port=0
  94. ./examples/server/server -v 4 -R $ready_file -p $port &
  95. server_pid=$!
  96. create_port
  97. ./examples/client/client -v 4 -p $port | tee $client_file
  98. RESULT=$?
  99. remove_ready_file
  100. if [ $RESULT -ne 0 ]; then
  101. echo -e "\n\nTLS v1.3 not enabled"
  102. do_cleanup
  103. exit 1
  104. fi
  105. echo ""
  106. # TLS 1.3 cipher suites server / client.
  107. echo -e "\n\nTLS v1.3 cipher suite mismatch"
  108. port=0
  109. ./examples/server/server -v 4 -R $ready_file -p $port -l TLS13-CHACHA20-POLY1305-SHA256 &
  110. server_pid=$!
  111. create_port
  112. ./examples/client/client -v 4 -p $port -l TLS13-AES256-GCM-SHA384
  113. RESULT=$?
  114. remove_ready_file
  115. if [ $RESULT -eq 0 ]; then
  116. echo -e "\n\nIssue with mismatched TLS v1.3 cipher suites"
  117. do_cleanup
  118. exit 1
  119. fi
  120. do_cleanup
  121. echo ""
  122. cat ./wolfssl/options.h | grep -- 'NO_CERTS'
  123. NO_CERTS=$?
  124. cat ./wolfssl/options.h | grep -- 'WOLFSSL_NO_CLIENT_AUTH'
  125. NO_CLIENT_AUTH=$?
  126. if [ $NO_CERTS -ne 0 -a $NO_CLIENT_AUTH -ne 0 ]; then
  127. # TLS 1.3 mutual auth required but client doesn't send certificates.
  128. echo -e "\n\nTLS v1.3 mutual auth fail"
  129. port=0
  130. ./examples/server/server -v 4 -F -R $ready_file -p $port &
  131. server_pid=$!
  132. create_port
  133. ./examples/client/client -v 4 -x -p $port
  134. RESULT=$?
  135. remove_ready_file
  136. if [ $RESULT -eq 0 ]; then
  137. echo -e "\n\nIssue with requiring mutual authentication"
  138. do_cleanup
  139. exit 1
  140. fi
  141. do_cleanup
  142. echo ""
  143. fi
  144. # Check for TLS 1.2 support
  145. ./examples/client/client -v 3 2>&1 | grep -- 'Bad SSL version'
  146. if [ $? -ne 0 ]; then
  147. # TLS 1.3 server / TLS 1.2 client.
  148. echo -e "\n\nTLS v1.3 server downgrading to TLS v1.2"
  149. port=0
  150. ./examples/server/server -v 4 -R $ready_file -p $port &
  151. server_pid=$!
  152. create_port
  153. ./examples/client/client -v 3 -p $port
  154. RESULT=$?
  155. remove_ready_file
  156. if [ $RESULT -eq 0 ]; then
  157. echo -e "\n\nIssue with TLS v1.3 server downgrading to TLS v1.2"
  158. do_cleanup
  159. exit 1
  160. fi
  161. do_cleanup
  162. echo ""
  163. # TLS 1.2 server / TLS 1.3 client.
  164. echo -e "\n\nTLS v1.3 client upgrading server to TLS v1.3"
  165. port=0
  166. ./examples/server/server -v 3 -R $ready_file -p $port &
  167. server_pid=$!
  168. create_port
  169. ./examples/client/client -v 4 -p $port
  170. RESULT=$?
  171. remove_ready_file
  172. if [ $RESULT -eq 0 ]; then
  173. echo -e "\n\nIssue with TLS v1.3 client upgrading server to TLS v1.3"
  174. do_cleanup
  175. exit 1
  176. fi
  177. do_cleanup
  178. echo ""
  179. echo "Find usable TLS 1.2 cipher suite"
  180. for CS in ECDHE-RSA-AES128-GCM-SHA256 DHE-RSA-AES128-GCM-SHA256
  181. do
  182. echo $CS
  183. ./examples/client/client -e | grep $CS >/dev/null
  184. if [ "$?" = "0" ]; then
  185. TLS12_CS=$CS
  186. break
  187. fi
  188. do_cleanup
  189. done
  190. if [ "$TLS12_CS" != "" ]; then
  191. # TLS 1.3 downgrade server and client - no common TLS 1.3 ciphers
  192. echo -e "\n\nTLS v1.3 downgrade server and client - no common TLS 1.3 ciphers"
  193. port=0
  194. SERVER_CS="TLS13-AES256-GCM-SHA384:$TLS12_CS"
  195. CLIENT_CS="TLS13-AES128-GCM-SHA256:$TLS12_CS"
  196. ./examples/server/server -v d -l $SERVER_CS -R $ready_file -p $port &
  197. server_pid=$!
  198. create_port
  199. ./examples/client/client -v d -l $CLIENT_CS -p $port
  200. RESULT=$?
  201. remove_ready_file
  202. if [ $RESULT -eq 0 ]; then
  203. echo -e "\n\nTLS v1.3 downgrading to TLS v1.2 due to ciphers"
  204. do_cleanup
  205. exit 1
  206. fi
  207. do_cleanup
  208. echo ""
  209. else
  210. echo "No usable TLS 1.2 cipher suite found"
  211. fi
  212. fi
  213. # Check for EarlyData support
  214. ./examples/client/client -? 2>&1 | grep -- 'Early data'
  215. if [ $? -eq 0 ]; then
  216. early_data=yes
  217. fi
  218. ./examples/client/client -? 2>&1 | grep -- 'Shared keys'
  219. if [ $? -eq 0 ]; then
  220. psk=yes
  221. fi
  222. if [ "$early_data" = "yes" ]; then
  223. echo -e "\n\nTLS v1.3 Early Data - session ticket"
  224. port=0
  225. (./examples/server/server -v 4 -r -0 -R $ready_file -p $port 2>&1 | \
  226. tee $server_out_file) &
  227. server_pid=$!
  228. create_port
  229. ./examples/client/client -v 4 -r -0 -p $port 2>&1 >$client_out_file
  230. RESULT=$?
  231. cat $client_out_file
  232. remove_ready_file
  233. grep 'Session Ticket' $client_out_file
  234. session_ticket=$?
  235. early_data_cnt=`grep 'Early Data' $server_out_file | wc -l`
  236. if [ $session_ticket -eq 0 -a $early_data_cnt -ne 2 ]; then
  237. RESULT=1
  238. fi
  239. if [ $RESULT -ne 0 ]; then
  240. echo -e "\n\nIssue with TLS v1.3 Early DAta - session ticket"
  241. do_cleanup
  242. exit 1
  243. fi
  244. do_cleanup
  245. echo ""
  246. fi
  247. if [ "$early_data" = "yes" -a "$psk" = "yes" ]; then
  248. echo -e "\n\nTLS v1.3 Early Data - PSK"
  249. port=0
  250. (./examples/server/server -v 4 -s -0 -R $ready_file -p $port 2>&1 | \
  251. tee $server_out_file) &
  252. server_pid=$!
  253. create_port
  254. ./examples/client/client -v 4 -s -0 -p $port
  255. RESULT=$?
  256. remove_ready_file
  257. early_data_cnt=`grep 'Early Data' $server_out_file | wc -l`
  258. if [ $early_data_cnt -ne 2 ]; then
  259. RESULT=1
  260. fi
  261. if [ $RESULT -ne 0 ]; then
  262. echo -e "\n\nIssue with TLS v1.3 Early DAta - session ticket"
  263. do_cleanup
  264. exit 1
  265. fi
  266. else
  267. echo "Early data not available"
  268. fi
  269. do_cleanup
  270. echo -e "\nALL Tests Passed"
  271. exit 0