70-test_tls13messages.t 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the OpenSSL license (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|MSWin32)$/;
  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. $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
  25. $ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
  26. @handmessages = (
  27. [TLSProxy::Message::MT_CLIENT_HELLO,
  28. checkhandshake::ALL_HANDSHAKES],
  29. [TLSProxy::Message::MT_HELLO_RETRY_REQUEST,
  30. checkhandshake::HRR_HANDSHAKE | checkhandshake::HRR_RESUME_HANDSHAKE],
  31. [TLSProxy::Message::MT_CLIENT_HELLO,
  32. checkhandshake::HRR_HANDSHAKE | checkhandshake::HRR_RESUME_HANDSHAKE],
  33. [TLSProxy::Message::MT_SERVER_HELLO,
  34. checkhandshake::ALL_HANDSHAKES],
  35. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS,
  36. checkhandshake::ALL_HANDSHAKES],
  37. [TLSProxy::Message::MT_CERTIFICATE_REQUEST,
  38. checkhandshake::CLIENT_AUTH_HANDSHAKE],
  39. [TLSProxy::Message::MT_CERTIFICATE,
  40. checkhandshake::ALL_HANDSHAKES & ~(checkhandshake::RESUME_HANDSHAKE | checkhandshake::HRR_RESUME_HANDSHAKE)],
  41. [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
  42. checkhandshake::ALL_HANDSHAKES & ~(checkhandshake::RESUME_HANDSHAKE | checkhandshake::HRR_RESUME_HANDSHAKE)],
  43. [TLSProxy::Message::MT_FINISHED,
  44. checkhandshake::ALL_HANDSHAKES],
  45. [TLSProxy::Message::MT_CERTIFICATE,
  46. checkhandshake::CLIENT_AUTH_HANDSHAKE],
  47. [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
  48. checkhandshake::CLIENT_AUTH_HANDSHAKE],
  49. [TLSProxy::Message::MT_FINISHED,
  50. checkhandshake::ALL_HANDSHAKES],
  51. [0, 0]
  52. );
  53. @extensions = (
  54. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
  55. checkhandshake::SERVER_NAME_CLI_EXTENSION],
  56. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
  57. checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
  58. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
  59. checkhandshake::DEFAULT_EXTENSIONS],
  60. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EC_POINT_FORMATS,
  61. checkhandshake::DEFAULT_EXTENSIONS],
  62. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
  63. checkhandshake::DEFAULT_EXTENSIONS],
  64. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
  65. checkhandshake::ALPN_CLI_EXTENSION],
  66. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
  67. checkhandshake::SCT_CLI_EXTENSION],
  68. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
  69. checkhandshake::DEFAULT_EXTENSIONS],
  70. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
  71. checkhandshake::DEFAULT_EXTENSIONS],
  72. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
  73. checkhandshake::DEFAULT_EXTENSIONS],
  74. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  75. checkhandshake::DEFAULT_EXTENSIONS],
  76. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
  77. checkhandshake::DEFAULT_EXTENSIONS],
  78. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK_KEX_MODES,
  79. checkhandshake::DEFAULT_EXTENSIONS],
  80. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK,
  81. checkhandshake::PSK_CLI_EXTENSION],
  82. [TLSProxy::Message::MT_HELLO_RETRY_REQUEST, TLSProxy::Message::EXT_KEY_SHARE,
  83. checkhandshake::KEY_SHARE_HRR_EXTENSION],
  84. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
  85. checkhandshake::SERVER_NAME_CLI_EXTENSION],
  86. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
  87. checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
  88. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
  89. checkhandshake::DEFAULT_EXTENSIONS],
  90. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
  91. checkhandshake::DEFAULT_EXTENSIONS],
  92. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
  93. checkhandshake::ALPN_CLI_EXTENSION],
  94. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
  95. checkhandshake::SCT_CLI_EXTENSION],
  96. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  97. checkhandshake::DEFAULT_EXTENSIONS],
  98. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
  99. checkhandshake::DEFAULT_EXTENSIONS],
  100. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK_KEX_MODES,
  101. checkhandshake::DEFAULT_EXTENSIONS],
  102. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK,
  103. checkhandshake::PSK_CLI_EXTENSION],
  104. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  105. checkhandshake::DEFAULT_EXTENSIONS],
  106. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_PSK,
  107. checkhandshake::PSK_SRV_EXTENSION],
  108. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SERVER_NAME,
  109. checkhandshake::SERVER_NAME_SRV_EXTENSION],
  110. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_ALPN,
  111. checkhandshake::ALPN_SRV_EXTENSION],
  112. [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_STATUS_REQUEST,
  113. checkhandshake::STATUS_REQUEST_SRV_EXTENSION],
  114. [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_SCT,
  115. checkhandshake::SCT_SRV_EXTENSION],
  116. [0,0,0]
  117. );
  118. my $proxy = TLSProxy::Proxy->new(
  119. undef,
  120. cmdstr(app(["openssl"]), display => 1),
  121. srctop_file("apps", "server.pem"),
  122. (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
  123. );
  124. #Test 1: Check we get all the right messages for a default handshake
  125. (undef, my $session) = tempfile();
  126. $proxy->serverconnects(2);
  127. $proxy->clientflags("-sess_out ".$session);
  128. $proxy->sessionfile($session);
  129. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  130. plan tests => 15;
  131. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  132. checkhandshake::DEFAULT_EXTENSIONS,
  133. "Default handshake test");
  134. #Test 2: Resumption handshake
  135. $proxy->clearClient();
  136. $proxy->clientflags("-sess_in ".$session);
  137. $proxy->clientstart();
  138. checkhandshake($proxy, checkhandshake::RESUME_HANDSHAKE,
  139. checkhandshake::DEFAULT_EXTENSIONS
  140. | checkhandshake::PSK_CLI_EXTENSION
  141. | checkhandshake::PSK_SRV_EXTENSION,
  142. "Resumption handshake test");
  143. #Test 3: A status_request handshake (client request only)
  144. $proxy->clear();
  145. $proxy->clientflags("-status");
  146. $proxy->start();
  147. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  148. checkhandshake::DEFAULT_EXTENSIONS
  149. | checkhandshake::STATUS_REQUEST_CLI_EXTENSION,
  150. "status_request handshake test (client)");
  151. #Test 4: A status_request handshake (server support only)
  152. $proxy->clear();
  153. $proxy->serverflags("-status_file "
  154. .srctop_file("test", "recipes", "ocsp-response.der"));
  155. $proxy->start();
  156. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  157. checkhandshake::DEFAULT_EXTENSIONS,
  158. "status_request handshake test (server)");
  159. #Test 5: A status_request handshake (client and server)
  160. #TODO(TLS1.3): TLS1.3 doesn't actually have CertificateStatus messages. This is
  161. #a temporary test until such time as we do proper TLS1.3 style certificate
  162. #status
  163. $proxy->clear();
  164. $proxy->clientflags("-status");
  165. $proxy->serverflags("-status_file "
  166. .srctop_file("test", "recipes", "ocsp-response.der"));
  167. $proxy->start();
  168. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  169. checkhandshake::DEFAULT_EXTENSIONS
  170. | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
  171. | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
  172. "status_request handshake test");
  173. #Test 6: A client auth handshake
  174. $proxy->clear();
  175. $proxy->clientflags("-cert ".srctop_file("apps", "server.pem"));
  176. $proxy->serverflags("-Verify 5");
  177. $proxy->start();
  178. checkhandshake($proxy, checkhandshake::CLIENT_AUTH_HANDSHAKE,
  179. checkhandshake::DEFAULT_EXTENSIONS,
  180. "Client auth handshake test");
  181. #Test 7: Server name handshake (no client request)
  182. $proxy->clear();
  183. $proxy->clientflags("-noservername");
  184. $proxy->start();
  185. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  186. checkhandshake::DEFAULT_EXTENSIONS
  187. & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
  188. "Server name handshake test (client)");
  189. #Test 8: Server name handshake (server support only)
  190. $proxy->clear();
  191. $proxy->clientflags("-noservername");
  192. $proxy->serverflags("-servername testhost");
  193. $proxy->start();
  194. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  195. checkhandshake::DEFAULT_EXTENSIONS
  196. & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
  197. "Server name handshake test (server)");
  198. #Test 9: Server name handshake (client and server)
  199. $proxy->clear();
  200. $proxy->clientflags("-servername testhost");
  201. $proxy->serverflags("-servername testhost");
  202. $proxy->start();
  203. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  204. checkhandshake::DEFAULT_EXTENSIONS
  205. | checkhandshake::SERVER_NAME_SRV_EXTENSION,
  206. "Server name handshake test");
  207. #Test 10: ALPN handshake (client request only)
  208. $proxy->clear();
  209. $proxy->clientflags("-alpn test");
  210. $proxy->start();
  211. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  212. checkhandshake::DEFAULT_EXTENSIONS
  213. | checkhandshake::ALPN_CLI_EXTENSION,
  214. "ALPN handshake test (client)");
  215. #Test 11: ALPN handshake (server support only)
  216. $proxy->clear();
  217. $proxy->serverflags("-alpn test");
  218. $proxy->start();
  219. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  220. checkhandshake::DEFAULT_EXTENSIONS,
  221. "ALPN handshake test (server)");
  222. #Test 12: ALPN handshake (client and server)
  223. $proxy->clear();
  224. $proxy->clientflags("-alpn test");
  225. $proxy->serverflags("-alpn test");
  226. $proxy->start();
  227. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  228. checkhandshake::DEFAULT_EXTENSIONS
  229. | checkhandshake::ALPN_CLI_EXTENSION
  230. | checkhandshake::ALPN_SRV_EXTENSION,
  231. "ALPN handshake test");
  232. SKIP: {
  233. skip "No CT, EC or OCSP support in this OpenSSL build", 1
  234. if disabled("ct") || disabled("ec") || disabled("ocsp");
  235. #Test 13: SCT handshake (client request only)
  236. $proxy->clear();
  237. #Note: -ct also sends status_request
  238. $proxy->clientflags("-ct");
  239. $proxy->serverflags("-status_file "
  240. .srctop_file("test", "recipes", "ocsp-response.der")
  241. ." -serverinfo ".srctop_file("test", "serverinfo2.pem"));
  242. $proxy->start();
  243. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  244. checkhandshake::DEFAULT_EXTENSIONS
  245. | checkhandshake::SCT_CLI_EXTENSION
  246. | checkhandshake::SCT_SRV_EXTENSION
  247. | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
  248. | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
  249. "SCT handshake test");
  250. }
  251. #Test 14: HRR Handshake
  252. $proxy->clear();
  253. $proxy->serverflags("-curves P-256");
  254. $proxy->start();
  255. checkhandshake($proxy, checkhandshake::HRR_HANDSHAKE,
  256. checkhandshake::DEFAULT_EXTENSIONS
  257. | checkhandshake::KEY_SHARE_HRR_EXTENSION,
  258. "HRR handshake test");
  259. #Test 15: Resumption handshake with HRR
  260. $proxy->clear();
  261. $proxy->clientflags("-sess_in ".$session);
  262. $proxy->serverflags("-curves P-256");
  263. $proxy->start();
  264. checkhandshake($proxy, checkhandshake::HRR_RESUME_HANDSHAKE,
  265. checkhandshake::DEFAULT_EXTENSIONS
  266. | checkhandshake::KEY_SHARE_HRR_EXTENSION
  267. | checkhandshake::PSK_CLI_EXTENSION
  268. | checkhandshake::PSK_SRV_EXTENSION,
  269. "Resumption handshake with HRR test");
  270. unlink $session;