70-test_tls13certcomp.t 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2020 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_tls13certcomp";
  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. plan skip_all => "$test_name needs compression and algorithms enabled"
  27. if disabled("comp") || (disabled("brotli") && disabled("zlib") && disabled("zstd"));
  28. @handmessages = (
  29. [TLSProxy::Message::MT_CLIENT_HELLO,
  30. checkhandshake::ALL_HANDSHAKES],
  31. [TLSProxy::Message::MT_SERVER_HELLO,
  32. checkhandshake::ALL_HANDSHAKES],
  33. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS,
  34. checkhandshake::ALL_HANDSHAKES],
  35. [TLSProxy::Message::MT_CERTIFICATE_REQUEST,
  36. checkhandshake::CERT_COMP_CLI_HANDSHAKE | checkhandshake::CERT_COMP_BOTH_HANDSHAKE],
  37. [TLSProxy::Message::MT_CERTIFICATE,
  38. checkhandshake::ALL_HANDSHAKES & ~(checkhandshake::CERT_COMP_SRV_HANDSHAKE | checkhandshake::CERT_COMP_BOTH_HANDSHAKE)],
  39. [TLSProxy::Message::MT_COMPRESSED_CERTIFICATE,
  40. checkhandshake::CERT_COMP_SRV_HANDSHAKE | checkhandshake::CERT_COMP_BOTH_HANDSHAKE],
  41. [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
  42. checkhandshake::ALL_HANDSHAKES],
  43. [TLSProxy::Message::MT_FINISHED,
  44. checkhandshake::ALL_HANDSHAKES],
  45. [TLSProxy::Message::MT_COMPRESSED_CERTIFICATE,
  46. checkhandshake::CERT_COMP_CLI_HANDSHAKE | checkhandshake::CERT_COMP_BOTH_HANDSHAKE],
  47. [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
  48. checkhandshake::CERT_COMP_CLI_HANDSHAKE | checkhandshake::CERT_COMP_BOTH_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. TLSProxy::Message::CLIENT,
  56. checkhandshake::SERVER_NAME_CLI_EXTENSION],
  57. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
  58. TLSProxy::Message::CLIENT,
  59. checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
  60. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
  61. TLSProxy::Message::CLIENT,
  62. checkhandshake::DEFAULT_EXTENSIONS],
  63. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EC_POINT_FORMATS,
  64. TLSProxy::Message::CLIENT,
  65. checkhandshake::DEFAULT_EXTENSIONS],
  66. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
  67. TLSProxy::Message::CLIENT,
  68. checkhandshake::DEFAULT_EXTENSIONS],
  69. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
  70. TLSProxy::Message::CLIENT,
  71. checkhandshake::ALPN_CLI_EXTENSION],
  72. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
  73. TLSProxy::Message::CLIENT,
  74. checkhandshake::SCT_CLI_EXTENSION],
  75. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
  76. TLSProxy::Message::CLIENT,
  77. checkhandshake::DEFAULT_EXTENSIONS],
  78. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
  79. TLSProxy::Message::CLIENT,
  80. checkhandshake::DEFAULT_EXTENSIONS],
  81. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
  82. TLSProxy::Message::CLIENT,
  83. checkhandshake::DEFAULT_EXTENSIONS],
  84. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  85. TLSProxy::Message::CLIENT,
  86. checkhandshake::DEFAULT_EXTENSIONS],
  87. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
  88. TLSProxy::Message::CLIENT,
  89. checkhandshake::DEFAULT_EXTENSIONS],
  90. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK_KEX_MODES,
  91. TLSProxy::Message::CLIENT,
  92. checkhandshake::DEFAULT_EXTENSIONS],
  93. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK,
  94. TLSProxy::Message::CLIENT,
  95. checkhandshake::PSK_CLI_EXTENSION],
  96. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_POST_HANDSHAKE_AUTH,
  97. TLSProxy::Message::CLIENT,
  98. checkhandshake::POST_HANDSHAKE_AUTH_CLI_EXTENSION],
  99. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_COMPRESS_CERTIFICATE,
  100. TLSProxy::Message::CLIENT,
  101. checkhandshake::CERT_COMP_CLI_EXTENSION],
  102. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_RENEGOTIATE,
  103. TLSProxy::Message::CLIENT,
  104. checkhandshake::DEFAULT_EXTENSIONS],
  105. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
  106. TLSProxy::Message::SERVER,
  107. checkhandshake::DEFAULT_EXTENSIONS],
  108. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  109. TLSProxy::Message::SERVER,
  110. checkhandshake::KEY_SHARE_HRR_EXTENSION],
  111. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
  112. TLSProxy::Message::CLIENT,
  113. checkhandshake::SERVER_NAME_CLI_EXTENSION],
  114. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
  115. TLSProxy::Message::CLIENT,
  116. checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
  117. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
  118. TLSProxy::Message::CLIENT,
  119. checkhandshake::DEFAULT_EXTENSIONS],
  120. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EC_POINT_FORMATS,
  121. TLSProxy::Message::CLIENT,
  122. checkhandshake::DEFAULT_EXTENSIONS],
  123. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
  124. TLSProxy::Message::CLIENT,
  125. checkhandshake::DEFAULT_EXTENSIONS],
  126. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
  127. TLSProxy::Message::CLIENT,
  128. checkhandshake::ALPN_CLI_EXTENSION],
  129. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
  130. TLSProxy::Message::CLIENT,
  131. checkhandshake::SCT_CLI_EXTENSION],
  132. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
  133. TLSProxy::Message::CLIENT,
  134. checkhandshake::DEFAULT_EXTENSIONS],
  135. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
  136. TLSProxy::Message::CLIENT,
  137. checkhandshake::DEFAULT_EXTENSIONS],
  138. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
  139. TLSProxy::Message::CLIENT,
  140. checkhandshake::DEFAULT_EXTENSIONS],
  141. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  142. TLSProxy::Message::CLIENT,
  143. checkhandshake::DEFAULT_EXTENSIONS],
  144. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
  145. TLSProxy::Message::CLIENT,
  146. checkhandshake::DEFAULT_EXTENSIONS],
  147. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK_KEX_MODES,
  148. TLSProxy::Message::CLIENT,
  149. checkhandshake::DEFAULT_EXTENSIONS],
  150. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK,
  151. TLSProxy::Message::CLIENT,
  152. checkhandshake::PSK_CLI_EXTENSION],
  153. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_POST_HANDSHAKE_AUTH,
  154. TLSProxy::Message::CLIENT,
  155. checkhandshake::POST_HANDSHAKE_AUTH_CLI_EXTENSION],
  156. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_COMPRESS_CERTIFICATE,
  157. TLSProxy::Message::CLIENT,
  158. checkhandshake::CERT_COMP_CLI_EXTENSION],
  159. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
  160. TLSProxy::Message::SERVER,
  161. checkhandshake::DEFAULT_EXTENSIONS],
  162. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  163. TLSProxy::Message::SERVER,
  164. checkhandshake::DEFAULT_EXTENSIONS],
  165. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_PSK,
  166. TLSProxy::Message::SERVER,
  167. checkhandshake::PSK_SRV_EXTENSION],
  168. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SERVER_NAME,
  169. TLSProxy::Message::SERVER,
  170. checkhandshake::SERVER_NAME_SRV_EXTENSION],
  171. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_ALPN,
  172. TLSProxy::Message::SERVER,
  173. checkhandshake::ALPN_SRV_EXTENSION],
  174. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
  175. TLSProxy::Message::SERVER,
  176. checkhandshake::SUPPORTED_GROUPS_SRV_EXTENSION],
  177. [TLSProxy::Message::MT_CERTIFICATE_REQUEST, TLSProxy::Message::EXT_SIG_ALGS,
  178. TLSProxy::Message::SERVER,
  179. checkhandshake::DEFAULT_EXTENSIONS],
  180. [TLSProxy::Message::MT_CERTIFICATE_REQUEST, TLSProxy::Message::EXT_COMPRESS_CERTIFICATE,
  181. TLSProxy::Message::SERVER,
  182. checkhandshake::CERT_COMP_SRV_EXTENSION],
  183. [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_STATUS_REQUEST,
  184. TLSProxy::Message::SERVER,
  185. checkhandshake::STATUS_REQUEST_SRV_EXTENSION],
  186. [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_SCT,
  187. TLSProxy::Message::SERVER,
  188. checkhandshake::SCT_SRV_EXTENSION],
  189. [0,0,0,0]
  190. );
  191. my $proxy = TLSProxy::Proxy->new(
  192. undef,
  193. cmdstr(app(["openssl"]), display => 1),
  194. srctop_file("apps", "server.pem"),
  195. (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
  196. );
  197. #Test 1: Client sends cert comp, but no client auth
  198. $proxy->serverconnects(2);
  199. $proxy->clear();
  200. $proxy->serverflags("-no_tx_cert_comp -no_rx_cert_comp");
  201. # One final skip check
  202. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  203. plan tests => 8;
  204. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  205. checkhandshake::DEFAULT_EXTENSIONS
  206. | checkhandshake::CERT_COMP_CLI_EXTENSION,
  207. "Client supports certificate compression");
  208. #Test 2: Server sends cert comp, no client auth
  209. $proxy->clear();
  210. $proxy->clientflags("-no_tx_cert_comp -no_rx_cert_comp");
  211. $proxy->serverflags("-cert_comp");
  212. $proxy->start();
  213. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  214. checkhandshake::DEFAULT_EXTENSIONS
  215. | checkhandshake::CERT_COMP_SRV_EXTENSION,
  216. "Server supports certificate compression, but no client auth");
  217. #Test 3: Both send cert comp, no client auth
  218. $proxy->clear();
  219. $proxy->serverflags("-cert_comp");
  220. $proxy->start();
  221. checkhandshake($proxy, checkhandshake::CERT_COMP_SRV_HANDSHAKE,
  222. checkhandshake::DEFAULT_EXTENSIONS
  223. | checkhandshake::CERT_COMP_CLI_EXTENSION
  224. | checkhandshake::CERT_COMP_SRV_EXTENSION,
  225. "Both support certificate compression, but no client auth");
  226. #Test 4: Both send cert comp, with client auth
  227. $proxy->clear();
  228. $proxy->clientflags("-cert ".srctop_file("apps", "server.pem"));
  229. $proxy->serverflags("-Verify 5 -cert_comp");
  230. $proxy->start();
  231. checkhandshake($proxy, checkhandshake::CERT_COMP_BOTH_HANDSHAKE,
  232. checkhandshake::DEFAULT_EXTENSIONS
  233. | checkhandshake::CERT_COMP_CLI_EXTENSION
  234. | checkhandshake::CERT_COMP_SRV_EXTENSION,
  235. "Both support certificate compression, with client auth");
  236. #Test 5: Client-to-server-only certificate compression, with client auth
  237. $proxy->clear();
  238. $proxy->clientflags("-no_rx_cert_comp -cert ".srctop_file("apps", "server.pem"));
  239. $proxy->serverflags("-no_tx_cert_comp -Verify 5 -cert_comp");
  240. $proxy->start();
  241. checkhandshake($proxy, checkhandshake::CERT_COMP_CLI_HANDSHAKE,
  242. checkhandshake::DEFAULT_EXTENSIONS
  243. | checkhandshake::CERT_COMP_SRV_EXTENSION,
  244. "Client-to-server-only certificate compression, with client auth");
  245. #Test 6: Server-to-client-only certificate compression
  246. $proxy->clear();
  247. $proxy->clientflags("-no_tx_cert_comp");
  248. $proxy->serverflags("-no_rx_cert_comp -cert_comp");
  249. $proxy->start();
  250. checkhandshake($proxy, checkhandshake::CERT_COMP_SRV_HANDSHAKE,
  251. checkhandshake::DEFAULT_EXTENSIONS
  252. | checkhandshake::CERT_COMP_CLI_EXTENSION,
  253. "Server-to-client-only certificate compression");
  254. #Test 7: Neither side wants to send a compressed cert, but will accept one
  255. $proxy->clear();
  256. $proxy->clientflags("-no_tx_cert_comp");
  257. $proxy->serverflags("-no_tx_cert_comp -cert_comp");
  258. $proxy->start();
  259. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  260. checkhandshake::DEFAULT_EXTENSIONS
  261. | checkhandshake::CERT_COMP_CLI_EXTENSION
  262. | checkhandshake::CERT_COMP_SRV_EXTENSION,
  263. "Accept but not send compressed certificates");
  264. #Test 8: Neither side wants to receive a compressed cert, but will send one
  265. $proxy->clear();
  266. $proxy->clientflags("-no_rx_cert_comp");
  267. $proxy->serverflags("-no_rx_cert_comp -cert_comp");
  268. $proxy->start();
  269. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  270. checkhandshake::DEFAULT_EXTENSIONS,
  271. "Send but not accept compressed certificates");