70-test_sslmessages.t 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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_sslmessages";
  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 TLS enabled"
  23. if alldisabled(available_protocols("tls"));
  24. $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
  25. $ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
  26. my $proxy = TLSProxy::Proxy->new(
  27. undef,
  28. cmdstr(app(["openssl"]), display => 1),
  29. srctop_file("apps", "server.pem"),
  30. (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
  31. );
  32. @handmessages = (
  33. [TLSProxy::Message::MT_CLIENT_HELLO,
  34. checkhandshake::ALL_HANDSHAKES],
  35. [TLSProxy::Message::MT_SERVER_HELLO,
  36. checkhandshake::ALL_HANDSHAKES],
  37. [TLSProxy::Message::MT_CERTIFICATE,
  38. checkhandshake::ALL_HANDSHAKES
  39. & ~checkhandshake::RESUME_HANDSHAKE],
  40. (disabled("ec") ? () :
  41. [TLSProxy::Message::MT_SERVER_KEY_EXCHANGE,
  42. checkhandshake::EC_HANDSHAKE]),
  43. [TLSProxy::Message::MT_CERTIFICATE_STATUS,
  44. checkhandshake::OCSP_HANDSHAKE],
  45. #ServerKeyExchange handshakes not currently supported by TLSProxy
  46. [TLSProxy::Message::MT_CERTIFICATE_REQUEST,
  47. checkhandshake::CLIENT_AUTH_HANDSHAKE],
  48. [TLSProxy::Message::MT_SERVER_HELLO_DONE,
  49. checkhandshake::ALL_HANDSHAKES
  50. & ~checkhandshake::RESUME_HANDSHAKE],
  51. [TLSProxy::Message::MT_CERTIFICATE,
  52. checkhandshake::CLIENT_AUTH_HANDSHAKE],
  53. [TLSProxy::Message::MT_CLIENT_KEY_EXCHANGE,
  54. checkhandshake::ALL_HANDSHAKES
  55. & ~checkhandshake::RESUME_HANDSHAKE],
  56. [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
  57. checkhandshake::CLIENT_AUTH_HANDSHAKE],
  58. [TLSProxy::Message::MT_NEXT_PROTO,
  59. checkhandshake::NPN_HANDSHAKE],
  60. [TLSProxy::Message::MT_FINISHED,
  61. checkhandshake::ALL_HANDSHAKES],
  62. [TLSProxy::Message::MT_NEW_SESSION_TICKET,
  63. checkhandshake::ALL_HANDSHAKES
  64. & ~checkhandshake::RESUME_HANDSHAKE],
  65. [TLSProxy::Message::MT_FINISHED,
  66. checkhandshake::ALL_HANDSHAKES],
  67. [TLSProxy::Message::MT_CLIENT_HELLO,
  68. checkhandshake::RENEG_HANDSHAKE],
  69. [TLSProxy::Message::MT_SERVER_HELLO,
  70. checkhandshake::RENEG_HANDSHAKE],
  71. [TLSProxy::Message::MT_CERTIFICATE,
  72. checkhandshake::RENEG_HANDSHAKE],
  73. [TLSProxy::Message::MT_SERVER_HELLO_DONE,
  74. checkhandshake::RENEG_HANDSHAKE],
  75. [TLSProxy::Message::MT_CLIENT_KEY_EXCHANGE,
  76. checkhandshake::RENEG_HANDSHAKE],
  77. [TLSProxy::Message::MT_FINISHED,
  78. checkhandshake::RENEG_HANDSHAKE],
  79. [TLSProxy::Message::MT_NEW_SESSION_TICKET,
  80. checkhandshake::RENEG_HANDSHAKE],
  81. [TLSProxy::Message::MT_FINISHED,
  82. checkhandshake::RENEG_HANDSHAKE],
  83. [0, 0]
  84. );
  85. @extensions = (
  86. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
  87. checkhandshake::SERVER_NAME_CLI_EXTENSION],
  88. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
  89. checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
  90. (disabled("ec") ? () :
  91. [TLSProxy::Message::MT_CLIENT_HELLO,
  92. TLSProxy::Message::EXT_SUPPORTED_GROUPS,
  93. checkhandshake::DEFAULT_EXTENSIONS]),
  94. (disabled("ec") ? () :
  95. [TLSProxy::Message::MT_CLIENT_HELLO,
  96. TLSProxy::Message::EXT_EC_POINT_FORMATS,
  97. checkhandshake::DEFAULT_EXTENSIONS]),
  98. (disabled("tls1_2") ? () :
  99. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
  100. checkhandshake::DEFAULT_EXTENSIONS]),
  101. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
  102. checkhandshake::ALPN_CLI_EXTENSION],
  103. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
  104. checkhandshake::SCT_CLI_EXTENSION],
  105. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
  106. checkhandshake::DEFAULT_EXTENSIONS],
  107. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
  108. checkhandshake::DEFAULT_EXTENSIONS],
  109. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
  110. checkhandshake::DEFAULT_EXTENSIONS],
  111. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_RENEGOTIATE,
  112. checkhandshake::RENEGOTIATE_CLI_EXTENSION],
  113. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_NPN,
  114. checkhandshake::NPN_CLI_EXTENSION],
  115. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SRP,
  116. checkhandshake::SRP_CLI_EXTENSION],
  117. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_RENEGOTIATE,
  118. checkhandshake::DEFAULT_EXTENSIONS],
  119. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
  120. checkhandshake::DEFAULT_EXTENSIONS],
  121. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
  122. checkhandshake::DEFAULT_EXTENSIONS],
  123. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
  124. checkhandshake::SESSION_TICKET_SRV_EXTENSION],
  125. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
  126. checkhandshake::SERVER_NAME_SRV_EXTENSION],
  127. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
  128. checkhandshake::STATUS_REQUEST_SRV_EXTENSION],
  129. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_ALPN,
  130. checkhandshake::ALPN_SRV_EXTENSION],
  131. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SCT,
  132. checkhandshake::SCT_SRV_EXTENSION],
  133. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_NPN,
  134. checkhandshake::NPN_SRV_EXTENSION],
  135. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_EC_POINT_FORMATS,
  136. checkhandshake::EC_POINT_FORMAT_SRV_EXTENSION],
  137. [0,0,0]
  138. );
  139. #Test 1: Check we get all the right messages for a default handshake
  140. (undef, my $session) = tempfile();
  141. $proxy->serverconnects(2);
  142. $proxy->clientflags("-no_tls1_3 -sess_out ".$session);
  143. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  144. plan tests => 21;
  145. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  146. checkhandshake::DEFAULT_EXTENSIONS,
  147. "Default handshake test");
  148. #Test 2: Resumption handshake
  149. $proxy->clearClient();
  150. $proxy->clientflags("-no_tls1_3 -sess_in ".$session);
  151. $proxy->clientstart();
  152. checkhandshake($proxy, checkhandshake::RESUME_HANDSHAKE,
  153. checkhandshake::DEFAULT_EXTENSIONS
  154. & ~checkhandshake::SESSION_TICKET_SRV_EXTENSION,
  155. "Resumption handshake test");
  156. unlink $session;
  157. SKIP: {
  158. skip "No OCSP support in this OpenSSL build", 3
  159. if disabled("ocsp");
  160. #Test 3: A status_request handshake (client request only)
  161. $proxy->clear();
  162. $proxy->clientflags("-no_tls1_3 -status");
  163. $proxy->start();
  164. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  165. checkhandshake::DEFAULT_EXTENSIONS
  166. | checkhandshake::STATUS_REQUEST_CLI_EXTENSION,
  167. "status_request handshake test (client)");
  168. #Test 4: A status_request handshake (server support only)
  169. $proxy->clear();
  170. $proxy->clientflags("-no_tls1_3");
  171. $proxy->serverflags("-status_file "
  172. .srctop_file("test", "recipes", "ocsp-response.der"));
  173. $proxy->start();
  174. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  175. checkhandshake::DEFAULT_EXTENSIONS,
  176. "status_request handshake test (server)");
  177. #Test 5: A status_request handshake (client and server)
  178. $proxy->clear();
  179. $proxy->clientflags("-no_tls1_3 -status");
  180. $proxy->serverflags("-status_file "
  181. .srctop_file("test", "recipes", "ocsp-response.der"));
  182. $proxy->start();
  183. checkhandshake($proxy, checkhandshake::OCSP_HANDSHAKE,
  184. checkhandshake::DEFAULT_EXTENSIONS
  185. | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
  186. | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
  187. "status_request handshake test");
  188. }
  189. #Test 6: A client auth handshake
  190. $proxy->clear();
  191. $proxy->clientflags("-no_tls1_3 -cert ".srctop_file("apps", "server.pem"));
  192. $proxy->serverflags("-Verify 5");
  193. $proxy->start();
  194. checkhandshake($proxy, checkhandshake::CLIENT_AUTH_HANDSHAKE,
  195. checkhandshake::DEFAULT_EXTENSIONS,
  196. "Client auth handshake test");
  197. #Test 7: A handshake with a renegotiation
  198. $proxy->clear();
  199. $proxy->clientflags("-no_tls1_3");
  200. $proxy->reneg(1);
  201. $proxy->start();
  202. checkhandshake($proxy, checkhandshake::RENEG_HANDSHAKE,
  203. checkhandshake::DEFAULT_EXTENSIONS,
  204. "Rengotiation handshake test");
  205. #Test 8: Server name handshake (no client request)
  206. $proxy->clear();
  207. $proxy->clientflags("-no_tls1_3 -noservername");
  208. $proxy->start();
  209. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  210. checkhandshake::DEFAULT_EXTENSIONS
  211. & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
  212. "Server name handshake test (client)");
  213. #Test 9: Server name handshake (server support only)
  214. $proxy->clear();
  215. $proxy->clientflags("-no_tls1_3 -noservername");
  216. $proxy->serverflags("-servername testhost");
  217. $proxy->start();
  218. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  219. checkhandshake::DEFAULT_EXTENSIONS
  220. & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
  221. "Server name handshake test (server)");
  222. #Test 10: Server name handshake (client and server)
  223. $proxy->clear();
  224. $proxy->clientflags("-no_tls1_3 -servername testhost");
  225. $proxy->serverflags("-servername testhost");
  226. $proxy->start();
  227. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  228. checkhandshake::DEFAULT_EXTENSIONS
  229. | checkhandshake::SERVER_NAME_SRV_EXTENSION,
  230. "Server name handshake test");
  231. #Test 11: ALPN handshake (client request only)
  232. $proxy->clear();
  233. $proxy->clientflags("-no_tls1_3 -alpn test");
  234. $proxy->start();
  235. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  236. checkhandshake::DEFAULT_EXTENSIONS
  237. | checkhandshake::ALPN_CLI_EXTENSION,
  238. "ALPN handshake test (client)");
  239. #Test 12: ALPN handshake (server support only)
  240. $proxy->clear();
  241. $proxy->clientflags("-no_tls1_3");
  242. $proxy->serverflags("-alpn test");
  243. $proxy->start();
  244. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  245. checkhandshake::DEFAULT_EXTENSIONS,
  246. "ALPN handshake test (server)");
  247. #Test 13: ALPN handshake (client and server)
  248. $proxy->clear();
  249. $proxy->clientflags("-no_tls1_3 -alpn test");
  250. $proxy->serverflags("-alpn test");
  251. $proxy->start();
  252. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  253. checkhandshake::DEFAULT_EXTENSIONS
  254. | checkhandshake::ALPN_CLI_EXTENSION
  255. | checkhandshake::ALPN_SRV_EXTENSION,
  256. "ALPN handshake test");
  257. SKIP: {
  258. skip "No CT, EC or OCSP support in this OpenSSL build", 1
  259. if disabled("ct") || disabled("ec") || disabled("ocsp");
  260. #Test 14: SCT handshake (client request only)
  261. $proxy->clear();
  262. #Note: -ct also sends status_request
  263. $proxy->clientflags("-no_tls1_3 -ct");
  264. $proxy->serverflags("-status_file "
  265. .srctop_file("test", "recipes", "ocsp-response.der"));
  266. $proxy->start();
  267. checkhandshake($proxy, checkhandshake::OCSP_HANDSHAKE,
  268. checkhandshake::DEFAULT_EXTENSIONS
  269. | checkhandshake::SCT_CLI_EXTENSION
  270. | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
  271. | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
  272. "SCT handshake test (client)");
  273. }
  274. SKIP: {
  275. skip "No OCSP support in this OpenSSL build", 1
  276. if disabled("ocsp");
  277. #Test 15: SCT handshake (server support only)
  278. $proxy->clear();
  279. #Note: -ct also sends status_request
  280. $proxy->clientflags("-no_tls1_3");
  281. $proxy->serverflags("-status_file "
  282. .srctop_file("test", "recipes", "ocsp-response.der"));
  283. $proxy->start();
  284. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  285. checkhandshake::DEFAULT_EXTENSIONS,
  286. "SCT handshake test (server)");
  287. }
  288. SKIP: {
  289. skip "No CT, EC or OCSP support in this OpenSSL build", 1
  290. if disabled("ct") || disabled("ec") || disabled("ocsp");
  291. #Test 16: SCT handshake (client and server)
  292. #There is no built-in server side support for this so we are actually also
  293. #testing custom extensions here
  294. $proxy->clear();
  295. #Note: -ct also sends status_request
  296. $proxy->clientflags("-no_tls1_3 -ct");
  297. $proxy->serverflags("-status_file "
  298. .srctop_file("test", "recipes", "ocsp-response.der")
  299. ." -serverinfo ".srctop_file("test", "serverinfo.pem"));
  300. $proxy->start();
  301. checkhandshake($proxy, checkhandshake::OCSP_HANDSHAKE,
  302. checkhandshake::DEFAULT_EXTENSIONS
  303. | checkhandshake::SCT_CLI_EXTENSION
  304. | checkhandshake::SCT_SRV_EXTENSION
  305. | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
  306. | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
  307. "SCT handshake test");
  308. }
  309. SKIP: {
  310. skip "No NPN support in this OpenSSL build", 3
  311. if disabled("nextprotoneg");
  312. #Test 17: NPN handshake (client request only)
  313. $proxy->clear();
  314. $proxy->clientflags("-no_tls1_3 -nextprotoneg test");
  315. $proxy->start();
  316. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  317. checkhandshake::DEFAULT_EXTENSIONS
  318. | checkhandshake::NPN_CLI_EXTENSION,
  319. "NPN handshake test (client)");
  320. #Test 18: NPN handshake (server support only)
  321. $proxy->clear();
  322. $proxy->clientflags("-no_tls1_3");
  323. $proxy->serverflags("-nextprotoneg test");
  324. $proxy->start();
  325. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  326. checkhandshake::DEFAULT_EXTENSIONS,
  327. "NPN handshake test (server)");
  328. #Test 19: NPN handshake (client and server)
  329. $proxy->clear();
  330. $proxy->clientflags("-no_tls1_3 -nextprotoneg test");
  331. $proxy->serverflags("-nextprotoneg test");
  332. $proxy->start();
  333. checkhandshake($proxy, checkhandshake::NPN_HANDSHAKE,
  334. checkhandshake::DEFAULT_EXTENSIONS
  335. | checkhandshake::NPN_CLI_EXTENSION
  336. | checkhandshake::NPN_SRV_EXTENSION,
  337. "NPN handshake test");
  338. }
  339. SKIP: {
  340. skip "No SRP support in this OpenSSL build", 1
  341. if disabled("srp");
  342. #Test 20: SRP extension
  343. #Note: We are not actually going to perform an SRP handshake (TLSProxy
  344. #does not support it). However it is sufficient for us to check that the
  345. #SRP extension gets added on the client side. There is no SRP extension
  346. #generated on the server side anyway.
  347. $proxy->clear();
  348. $proxy->clientflags("-no_tls1_3 -srpuser user -srppass pass:pass");
  349. $proxy->start();
  350. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  351. checkhandshake::DEFAULT_EXTENSIONS
  352. | checkhandshake::SRP_CLI_EXTENSION,
  353. "SRP extension test");
  354. }
  355. #Test 21: EC handshake
  356. SKIP: {
  357. skip "No EC support in this OpenSSL build", 1 if disabled("ec");
  358. $proxy->clear();
  359. $proxy->clientflags("-no_tls1_3");
  360. $proxy->serverflags("-no_tls1_3");
  361. $proxy->ciphers("ECDHE-RSA-AES128-SHA");
  362. $proxy->start();
  363. checkhandshake($proxy, checkhandshake::EC_HANDSHAKE,
  364. checkhandshake::DEFAULT_EXTENSIONS
  365. | checkhandshake::EC_POINT_FORMAT_SRV_EXTENSION,
  366. "EC handshake test");
  367. }