70-test_tls13messages.t 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. use strict;
  9. use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file srctop_dir bldtop_dir/;
  10. use OpenSSL::Test::Utils;
  11. use File::Temp qw(tempfile);
  12. use TLSProxy::Proxy;
  13. use checkhandshake qw(checkhandshake @handmessages @extensions);
  14. my $test_name = "test_tls13messages";
  15. setup($test_name);
  16. plan skip_all => "TLSProxy isn't usable on $^O"
  17. if $^O =~ /^(VMS)$/;
  18. plan skip_all => "$test_name needs the dynamic engine feature enabled"
  19. if disabled("engine") || disabled("dynamic-engine");
  20. plan skip_all => "$test_name needs the sock feature enabled"
  21. if disabled("sock");
  22. plan skip_all => "$test_name needs TLSv1.3 enabled"
  23. if disabled("tls1_3");
  24. plan skip_all => "$test_name needs EC enabled"
  25. if disabled("ec");
  26. $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
  27. $ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
  28. @handmessages = (
  29. [TLSProxy::Message::MT_CLIENT_HELLO,
  30. checkhandshake::ALL_HANDSHAKES],
  31. [TLSProxy::Message::MT_SERVER_HELLO,
  32. checkhandshake::HRR_HANDSHAKE | checkhandshake::HRR_RESUME_HANDSHAKE],
  33. [TLSProxy::Message::MT_CLIENT_HELLO,
  34. checkhandshake::HRR_HANDSHAKE | checkhandshake::HRR_RESUME_HANDSHAKE],
  35. [TLSProxy::Message::MT_SERVER_HELLO,
  36. checkhandshake::ALL_HANDSHAKES],
  37. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS,
  38. checkhandshake::ALL_HANDSHAKES],
  39. [TLSProxy::Message::MT_CERTIFICATE_REQUEST,
  40. checkhandshake::CLIENT_AUTH_HANDSHAKE],
  41. [TLSProxy::Message::MT_CERTIFICATE,
  42. checkhandshake::ALL_HANDSHAKES & ~(checkhandshake::RESUME_HANDSHAKE | checkhandshake::HRR_RESUME_HANDSHAKE)],
  43. [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
  44. checkhandshake::ALL_HANDSHAKES & ~(checkhandshake::RESUME_HANDSHAKE | checkhandshake::HRR_RESUME_HANDSHAKE)],
  45. [TLSProxy::Message::MT_FINISHED,
  46. checkhandshake::ALL_HANDSHAKES],
  47. [TLSProxy::Message::MT_CERTIFICATE,
  48. checkhandshake::CLIENT_AUTH_HANDSHAKE],
  49. [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
  50. checkhandshake::CLIENT_AUTH_HANDSHAKE],
  51. [TLSProxy::Message::MT_FINISHED,
  52. checkhandshake::ALL_HANDSHAKES],
  53. [0, 0]
  54. );
  55. @extensions = (
  56. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
  57. checkhandshake::SERVER_NAME_CLI_EXTENSION],
  58. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
  59. checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
  60. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
  61. checkhandshake::DEFAULT_EXTENSIONS],
  62. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EC_POINT_FORMATS,
  63. checkhandshake::DEFAULT_EXTENSIONS],
  64. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
  65. checkhandshake::DEFAULT_EXTENSIONS],
  66. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
  67. checkhandshake::ALPN_CLI_EXTENSION],
  68. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
  69. checkhandshake::SCT_CLI_EXTENSION],
  70. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
  71. checkhandshake::DEFAULT_EXTENSIONS],
  72. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
  73. checkhandshake::DEFAULT_EXTENSIONS],
  74. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
  75. checkhandshake::DEFAULT_EXTENSIONS],
  76. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  77. checkhandshake::DEFAULT_EXTENSIONS],
  78. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
  79. checkhandshake::DEFAULT_EXTENSIONS],
  80. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK_KEX_MODES,
  81. checkhandshake::DEFAULT_EXTENSIONS],
  82. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK,
  83. checkhandshake::PSK_CLI_EXTENSION],
  84. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_POST_HANDSHAKE_AUTH,
  85. checkhandshake::POST_HANDSHAKE_AUTH_CLI_EXTENSION],
  86. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
  87. checkhandshake::DEFAULT_EXTENSIONS],
  88. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  89. checkhandshake::KEY_SHARE_HRR_EXTENSION],
  90. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
  91. checkhandshake::SERVER_NAME_CLI_EXTENSION],
  92. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
  93. checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
  94. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
  95. checkhandshake::DEFAULT_EXTENSIONS],
  96. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EC_POINT_FORMATS,
  97. checkhandshake::DEFAULT_EXTENSIONS],
  98. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
  99. checkhandshake::DEFAULT_EXTENSIONS],
  100. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
  101. checkhandshake::ALPN_CLI_EXTENSION],
  102. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
  103. checkhandshake::SCT_CLI_EXTENSION],
  104. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
  105. checkhandshake::DEFAULT_EXTENSIONS],
  106. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
  107. checkhandshake::DEFAULT_EXTENSIONS],
  108. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
  109. checkhandshake::DEFAULT_EXTENSIONS],
  110. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  111. checkhandshake::DEFAULT_EXTENSIONS],
  112. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
  113. checkhandshake::DEFAULT_EXTENSIONS],
  114. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK_KEX_MODES,
  115. checkhandshake::DEFAULT_EXTENSIONS],
  116. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK,
  117. checkhandshake::PSK_CLI_EXTENSION],
  118. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_POST_HANDSHAKE_AUTH,
  119. checkhandshake::POST_HANDSHAKE_AUTH_CLI_EXTENSION],
  120. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
  121. checkhandshake::DEFAULT_EXTENSIONS],
  122. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  123. checkhandshake::DEFAULT_EXTENSIONS],
  124. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_PSK,
  125. checkhandshake::PSK_SRV_EXTENSION],
  126. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SERVER_NAME,
  127. checkhandshake::SERVER_NAME_SRV_EXTENSION],
  128. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_ALPN,
  129. checkhandshake::ALPN_SRV_EXTENSION],
  130. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
  131. checkhandshake::SUPPORTED_GROUPS_SRV_EXTENSION],
  132. [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_STATUS_REQUEST,
  133. checkhandshake::STATUS_REQUEST_SRV_EXTENSION],
  134. [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_SCT,
  135. checkhandshake::SCT_SRV_EXTENSION],
  136. [0,0,0]
  137. );
  138. my $proxy = TLSProxy::Proxy->new(
  139. undef,
  140. cmdstr(app(["openssl"]), display => 1),
  141. srctop_file("apps", "server.pem"),
  142. (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
  143. );
  144. #Test 1: Check we get all the right messages for a default handshake
  145. (undef, my $session) = tempfile();
  146. $proxy->serverconnects(2);
  147. $proxy->clientflags("-sess_out ".$session);
  148. $proxy->sessionfile($session);
  149. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  150. plan tests => 16;
  151. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  152. checkhandshake::DEFAULT_EXTENSIONS,
  153. "Default handshake test");
  154. #Test 2: Resumption handshake
  155. $proxy->clearClient();
  156. $proxy->clientflags("-sess_in ".$session);
  157. $proxy->clientstart();
  158. checkhandshake($proxy, checkhandshake::RESUME_HANDSHAKE,
  159. (checkhandshake::DEFAULT_EXTENSIONS
  160. | checkhandshake::PSK_CLI_EXTENSION
  161. | checkhandshake::PSK_SRV_EXTENSION),
  162. "Resumption handshake test");
  163. SKIP: {
  164. skip "No OCSP support in this OpenSSL build", 3
  165. if disabled("ct") || disabled("ec") || disabled("ocsp");
  166. #Test 3: A status_request handshake (client request only)
  167. $proxy->clear();
  168. $proxy->clientflags("-status");
  169. $proxy->start();
  170. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  171. checkhandshake::DEFAULT_EXTENSIONS
  172. | checkhandshake::STATUS_REQUEST_CLI_EXTENSION,
  173. "status_request handshake test (client)");
  174. #Test 4: A status_request handshake (server support only)
  175. $proxy->clear();
  176. $proxy->serverflags("-status_file "
  177. .srctop_file("test", "recipes", "ocsp-response.der"));
  178. $proxy->start();
  179. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  180. checkhandshake::DEFAULT_EXTENSIONS,
  181. "status_request handshake test (server)");
  182. #Test 5: A status_request handshake (client and server)
  183. $proxy->clear();
  184. $proxy->clientflags("-status");
  185. $proxy->serverflags("-status_file "
  186. .srctop_file("test", "recipes", "ocsp-response.der"));
  187. $proxy->start();
  188. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  189. checkhandshake::DEFAULT_EXTENSIONS
  190. | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
  191. | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
  192. "status_request handshake test");
  193. }
  194. #Test 6: A client auth handshake
  195. $proxy->clear();
  196. $proxy->clientflags("-enable_pha -cert ".srctop_file("apps", "server.pem"));
  197. $proxy->serverflags("-Verify 5");
  198. $proxy->start();
  199. checkhandshake($proxy, checkhandshake::CLIENT_AUTH_HANDSHAKE,
  200. checkhandshake::DEFAULT_EXTENSIONS |
  201. checkhandshake::POST_HANDSHAKE_AUTH_CLI_EXTENSION,
  202. "Client auth handshake test");
  203. #Test 7: Server name handshake (no client request)
  204. $proxy->clear();
  205. $proxy->clientflags("-noservername");
  206. $proxy->start();
  207. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  208. checkhandshake::DEFAULT_EXTENSIONS
  209. & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
  210. "Server name handshake test (client)");
  211. #Test 8: Server name handshake (server support only)
  212. $proxy->clear();
  213. $proxy->clientflags("-noservername");
  214. $proxy->serverflags("-servername testhost");
  215. $proxy->start();
  216. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  217. checkhandshake::DEFAULT_EXTENSIONS
  218. & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
  219. "Server name handshake test (server)");
  220. #Test 9: Server name handshake (client and server)
  221. $proxy->clear();
  222. $proxy->clientflags("-servername testhost");
  223. $proxy->serverflags("-servername testhost");
  224. $proxy->start();
  225. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  226. checkhandshake::DEFAULT_EXTENSIONS
  227. | checkhandshake::SERVER_NAME_SRV_EXTENSION,
  228. "Server name handshake test");
  229. #Test 10: ALPN handshake (client request only)
  230. $proxy->clear();
  231. $proxy->clientflags("-alpn test");
  232. $proxy->start();
  233. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  234. checkhandshake::DEFAULT_EXTENSIONS
  235. | checkhandshake::ALPN_CLI_EXTENSION,
  236. "ALPN handshake test (client)");
  237. #Test 11: ALPN handshake (server support only)
  238. $proxy->clear();
  239. $proxy->serverflags("-alpn test");
  240. $proxy->start();
  241. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  242. checkhandshake::DEFAULT_EXTENSIONS,
  243. "ALPN handshake test (server)");
  244. #Test 12: ALPN handshake (client and server)
  245. $proxy->clear();
  246. $proxy->clientflags("-alpn test");
  247. $proxy->serverflags("-alpn test");
  248. $proxy->start();
  249. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  250. checkhandshake::DEFAULT_EXTENSIONS
  251. | checkhandshake::ALPN_CLI_EXTENSION
  252. | checkhandshake::ALPN_SRV_EXTENSION,
  253. "ALPN handshake test");
  254. SKIP: {
  255. skip "No CT, EC or OCSP support in this OpenSSL build", 1
  256. if disabled("ct") || disabled("ec") || disabled("ocsp");
  257. #Test 13: SCT handshake (client request only)
  258. $proxy->clear();
  259. #Note: -ct also sends status_request
  260. $proxy->clientflags("-ct");
  261. $proxy->serverflags("-status_file "
  262. .srctop_file("test", "recipes", "ocsp-response.der")
  263. ." -serverinfo ".srctop_file("test", "serverinfo2.pem"));
  264. $proxy->start();
  265. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  266. checkhandshake::DEFAULT_EXTENSIONS
  267. | checkhandshake::SCT_CLI_EXTENSION
  268. | checkhandshake::SCT_SRV_EXTENSION
  269. | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
  270. | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
  271. "SCT handshake test");
  272. }
  273. #Test 14: HRR Handshake
  274. $proxy->clear();
  275. $proxy->serverflags("-curves P-256");
  276. $proxy->start();
  277. checkhandshake($proxy, checkhandshake::HRR_HANDSHAKE,
  278. checkhandshake::DEFAULT_EXTENSIONS
  279. | checkhandshake::KEY_SHARE_HRR_EXTENSION,
  280. "HRR handshake test");
  281. #Test 15: Resumption handshake with HRR
  282. $proxy->clear();
  283. $proxy->clientflags("-sess_in ".$session);
  284. $proxy->serverflags("-curves P-256");
  285. $proxy->start();
  286. checkhandshake($proxy, checkhandshake::HRR_RESUME_HANDSHAKE,
  287. (checkhandshake::DEFAULT_EXTENSIONS
  288. | checkhandshake::KEY_SHARE_HRR_EXTENSION
  289. | checkhandshake::PSK_CLI_EXTENSION
  290. | checkhandshake::PSK_SRV_EXTENSION),
  291. "Resumption handshake with HRR test");
  292. #Test 16: Acceptable but non preferred key_share
  293. $proxy->clear();
  294. $proxy->clientflags("-curves P-256");
  295. $proxy->start();
  296. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  297. checkhandshake::DEFAULT_EXTENSIONS
  298. | checkhandshake::SUPPORTED_GROUPS_SRV_EXTENSION,
  299. "Acceptable but non preferred key_share");
  300. unlink $session;