2
0

70-test_tls13certcomp.t 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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_SERVER_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
  103. TLSProxy::Message::SERVER,
  104. checkhandshake::DEFAULT_EXTENSIONS],
  105. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  106. TLSProxy::Message::SERVER,
  107. checkhandshake::KEY_SHARE_HRR_EXTENSION],
  108. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
  109. TLSProxy::Message::CLIENT,
  110. checkhandshake::SERVER_NAME_CLI_EXTENSION],
  111. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
  112. TLSProxy::Message::CLIENT,
  113. checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
  114. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
  115. TLSProxy::Message::CLIENT,
  116. checkhandshake::DEFAULT_EXTENSIONS],
  117. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EC_POINT_FORMATS,
  118. TLSProxy::Message::CLIENT,
  119. checkhandshake::DEFAULT_EXTENSIONS],
  120. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
  121. TLSProxy::Message::CLIENT,
  122. checkhandshake::DEFAULT_EXTENSIONS],
  123. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
  124. TLSProxy::Message::CLIENT,
  125. checkhandshake::ALPN_CLI_EXTENSION],
  126. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
  127. TLSProxy::Message::CLIENT,
  128. checkhandshake::SCT_CLI_EXTENSION],
  129. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
  130. TLSProxy::Message::CLIENT,
  131. checkhandshake::DEFAULT_EXTENSIONS],
  132. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
  133. TLSProxy::Message::CLIENT,
  134. checkhandshake::DEFAULT_EXTENSIONS],
  135. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
  136. TLSProxy::Message::CLIENT,
  137. checkhandshake::DEFAULT_EXTENSIONS],
  138. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  139. TLSProxy::Message::CLIENT,
  140. checkhandshake::DEFAULT_EXTENSIONS],
  141. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
  142. TLSProxy::Message::CLIENT,
  143. checkhandshake::DEFAULT_EXTENSIONS],
  144. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK_KEX_MODES,
  145. TLSProxy::Message::CLIENT,
  146. checkhandshake::DEFAULT_EXTENSIONS],
  147. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK,
  148. TLSProxy::Message::CLIENT,
  149. checkhandshake::PSK_CLI_EXTENSION],
  150. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_POST_HANDSHAKE_AUTH,
  151. TLSProxy::Message::CLIENT,
  152. checkhandshake::POST_HANDSHAKE_AUTH_CLI_EXTENSION],
  153. [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_COMPRESS_CERTIFICATE,
  154. TLSProxy::Message::CLIENT,
  155. checkhandshake::CERT_COMP_CLI_EXTENSION],
  156. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
  157. TLSProxy::Message::SERVER,
  158. checkhandshake::DEFAULT_EXTENSIONS],
  159. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
  160. TLSProxy::Message::SERVER,
  161. checkhandshake::DEFAULT_EXTENSIONS],
  162. [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_PSK,
  163. TLSProxy::Message::SERVER,
  164. checkhandshake::PSK_SRV_EXTENSION],
  165. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SERVER_NAME,
  166. TLSProxy::Message::SERVER,
  167. checkhandshake::SERVER_NAME_SRV_EXTENSION],
  168. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_ALPN,
  169. TLSProxy::Message::SERVER,
  170. checkhandshake::ALPN_SRV_EXTENSION],
  171. [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
  172. TLSProxy::Message::SERVER,
  173. checkhandshake::SUPPORTED_GROUPS_SRV_EXTENSION],
  174. [TLSProxy::Message::MT_CERTIFICATE_REQUEST, TLSProxy::Message::EXT_SIG_ALGS,
  175. TLSProxy::Message::SERVER,
  176. checkhandshake::DEFAULT_EXTENSIONS],
  177. [TLSProxy::Message::MT_CERTIFICATE_REQUEST, TLSProxy::Message::EXT_COMPRESS_CERTIFICATE,
  178. TLSProxy::Message::SERVER,
  179. checkhandshake::CERT_COMP_SRV_EXTENSION],
  180. [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_STATUS_REQUEST,
  181. TLSProxy::Message::SERVER,
  182. checkhandshake::STATUS_REQUEST_SRV_EXTENSION],
  183. [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_SCT,
  184. TLSProxy::Message::SERVER,
  185. checkhandshake::SCT_SRV_EXTENSION],
  186. [0,0,0,0]
  187. );
  188. my $proxy = TLSProxy::Proxy->new(
  189. undef,
  190. cmdstr(app(["openssl"]), display => 1),
  191. srctop_file("apps", "server.pem"),
  192. (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
  193. );
  194. #Test 1: Client sends cert comp, but no client auth
  195. $proxy->serverconnects(2);
  196. $proxy->clear();
  197. $proxy->serverflags("-no_tx_cert_comp -no_rx_cert_comp");
  198. # One final skip check
  199. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  200. plan tests => 8;
  201. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  202. checkhandshake::DEFAULT_EXTENSIONS
  203. | checkhandshake::CERT_COMP_CLI_EXTENSION,
  204. "Client supports certificate compression");
  205. #Test 2: Server sends cert comp, no client auth
  206. $proxy->clear();
  207. $proxy->clientflags("-no_tx_cert_comp -no_rx_cert_comp");
  208. $proxy->serverflags("-cert_comp");
  209. $proxy->start();
  210. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  211. checkhandshake::DEFAULT_EXTENSIONS
  212. | checkhandshake::CERT_COMP_SRV_EXTENSION,
  213. "Server supports certificate compression, but no client auth");
  214. #Test 3: Both send cert comp, no client auth
  215. $proxy->clear();
  216. $proxy->serverflags("-cert_comp");
  217. $proxy->start();
  218. checkhandshake($proxy, checkhandshake::CERT_COMP_SRV_HANDSHAKE,
  219. checkhandshake::DEFAULT_EXTENSIONS
  220. | checkhandshake::CERT_COMP_CLI_EXTENSION
  221. | checkhandshake::CERT_COMP_SRV_EXTENSION,
  222. "Both support certificate compression, but no client auth");
  223. #Test 4: Both send cert comp, with client auth
  224. $proxy->clear();
  225. $proxy->clientflags("-cert ".srctop_file("apps", "server.pem"));
  226. $proxy->serverflags("-Verify 5 -cert_comp");
  227. $proxy->start();
  228. checkhandshake($proxy, checkhandshake::CERT_COMP_BOTH_HANDSHAKE,
  229. checkhandshake::DEFAULT_EXTENSIONS
  230. | checkhandshake::CERT_COMP_CLI_EXTENSION
  231. | checkhandshake::CERT_COMP_SRV_EXTENSION,
  232. "Both support certificate compression, with client auth");
  233. #Test 5: Client-to-server-only certificate compression, with client auth
  234. $proxy->clear();
  235. $proxy->clientflags("-no_rx_cert_comp -cert ".srctop_file("apps", "server.pem"));
  236. $proxy->serverflags("-no_tx_cert_comp -Verify 5 -cert_comp");
  237. $proxy->start();
  238. checkhandshake($proxy, checkhandshake::CERT_COMP_CLI_HANDSHAKE,
  239. checkhandshake::DEFAULT_EXTENSIONS
  240. | checkhandshake::CERT_COMP_SRV_EXTENSION,
  241. "Client-to-server-only certificate compression, with client auth");
  242. #Test 6: Server-to-client-only certificate compression
  243. $proxy->clear();
  244. $proxy->clientflags("-no_tx_cert_comp");
  245. $proxy->serverflags("-no_rx_cert_comp -cert_comp");
  246. $proxy->start();
  247. checkhandshake($proxy, checkhandshake::CERT_COMP_SRV_HANDSHAKE,
  248. checkhandshake::DEFAULT_EXTENSIONS
  249. | checkhandshake::CERT_COMP_CLI_EXTENSION,
  250. "Server-to-client-only certificate compression");
  251. #Test 7: Neither side wants to send a compressed cert, but will accept one
  252. $proxy->clear();
  253. $proxy->clientflags("-no_tx_cert_comp");
  254. $proxy->serverflags("-no_tx_cert_comp -cert_comp");
  255. $proxy->start();
  256. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  257. checkhandshake::DEFAULT_EXTENSIONS
  258. | checkhandshake::CERT_COMP_CLI_EXTENSION
  259. | checkhandshake::CERT_COMP_SRV_EXTENSION,
  260. "Accept but not send compressed certificates");
  261. #Test 8: Neither side wants to receive a compressed cert, but will send one
  262. $proxy->clear();
  263. $proxy->clientflags("-no_rx_cert_comp");
  264. $proxy->serverflags("-no_rx_cert_comp -cert_comp");
  265. $proxy->start();
  266. checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
  267. checkhandshake::DEFAULT_EXTENSIONS,
  268. "Send but not accept compressed certificates");