• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2014, Google Inc.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #ifndef HEADER_TEST_CONFIG
16 #define HEADER_TEST_CONFIG
17 
18 #include <string>
19 #include <utility>
20 #include <vector>
21 
22 #include <openssl/base.h>
23 #include <openssl/x509.h>
24 
25 #include "test_state.h"
26 
27 struct TestConfig {
28   int port = 0;
29   bool is_server = false;
30   bool is_dtls = false;
31   bool is_quic = false;
32   int resume_count = 0;
33   std::string write_settings;
34   bool fallback_scsv = false;
35   std::vector<uint16_t> signing_prefs;
36   std::vector<uint16_t> verify_prefs;
37   std::vector<uint16_t> expect_peer_verify_prefs;
38   std::vector<int> curves;
39   std::string key_file;
40   std::string cert_file;
41   std::string expect_server_name;
42   bool enable_ech_grease = false;
43   std::vector<std::string> ech_server_configs;
44   std::vector<std::string> ech_server_keys;
45   std::vector<int> ech_is_retry_config;
46   bool expect_ech_accept = false;
47   std::string expect_ech_name_override;
48   bool expect_no_ech_name_override = false;
49   std::string expect_ech_retry_configs;
50   bool expect_no_ech_retry_configs = false;
51   std::string ech_config_list;
52   std::string expect_certificate_types;
53   bool require_any_client_certificate = false;
54   std::string advertise_npn;
55   std::string expect_next_proto;
56   bool false_start = false;
57   std::string select_next_proto;
58   bool async = false;
59   bool write_different_record_sizes = false;
60   bool cbc_record_splitting = false;
61   bool partial_write = false;
62   bool no_tls13 = false;
63   bool no_tls12 = false;
64   bool no_tls11 = false;
65   bool no_tls1 = false;
66   bool no_ticket = false;
67   std::string expect_channel_id;
68   bool enable_channel_id = false;
69   std::string send_channel_id;
70   bool shim_writes_first = false;
71   std::string host_name;
72   std::string advertise_alpn;
73   std::string expect_alpn;
74   std::string expect_late_alpn;
75   std::string expect_advertised_alpn;
76   std::string select_alpn;
77   bool decline_alpn = false;
78   bool reject_alpn = false;
79   bool select_empty_alpn = false;
80   bool defer_alps = false;
81   std::vector<std::pair<std::string, std::string>> application_settings;
82   std::unique_ptr<std::string> expect_peer_application_settings;
83   std::string quic_transport_params;
84   std::string expect_quic_transport_params;
85   // Set quic_use_legacy_codepoint to 0 or 1 to configure, -1 uses default.
86   int quic_use_legacy_codepoint = -1;
87   bool expect_session_miss = false;
88   bool expect_extended_master_secret = false;
89   std::string psk;
90   std::string psk_identity;
91   std::string srtp_profiles;
92   bool enable_ocsp_stapling = false;
93   std::string expect_ocsp_response;
94   bool enable_signed_cert_timestamps = false;
95   std::string expect_signed_cert_timestamps;
96   uint16_t min_version = 0;
97   uint16_t max_version = 0;
98   uint16_t expect_version = 0;
99   int mtu = 0;
100   bool implicit_handshake = false;
101   bool use_early_callback = false;
102   bool fail_early_callback = false;
103   bool install_ddos_callback = false;
104   bool fail_ddos_callback = false;
105   bool fail_cert_callback = false;
106   std::string cipher;
107   bool handshake_never_done = false;
108   int export_keying_material = 0;
109   std::string export_label;
110   std::string export_context;
111   bool use_export_context = false;
112   bool tls_unique = false;
113   bool expect_ticket_renewal = false;
114   bool expect_no_session = false;
115   bool expect_ticket_supports_early_data = false;
116   bool expect_accept_early_data = false;
117   bool expect_reject_early_data = false;
118   bool expect_no_offer_early_data = false;
119   bool use_ticket_callback = false;
120   bool renew_ticket = false;
121   bool enable_early_data = false;
122   std::string ocsp_response;
123   bool check_close_notify = false;
124   bool shim_shuts_down = false;
125   bool verify_fail = false;
126   bool verify_peer = false;
127   bool verify_peer_if_no_obc = false;
128   bool expect_verify_result = false;
129   std::string signed_cert_timestamps;
130   int expect_total_renegotiations = 0;
131   bool renegotiate_once = false;
132   bool renegotiate_freely = false;
133   bool renegotiate_ignore = false;
134   bool renegotiate_explicit = false;
135   bool forbid_renegotiation_after_handshake = false;
136   uint16_t expect_peer_signature_algorithm = 0;
137   uint16_t expect_curve_id = 0;
138   bool use_old_client_cert_callback = false;
139   int initial_timeout_duration_ms = 0;
140   std::string use_client_ca_list;
141   std::string expect_client_ca_list;
142   bool send_alert = false;
143   bool peek_then_read = false;
144   bool enable_grease = false;
145   bool permute_extensions = false;
146   int max_cert_list = 0;
147   std::string ticket_key;
148   bool use_exporter_between_reads = false;
149   uint16_t expect_cipher_aes = 0;
150   uint16_t expect_cipher_no_aes = 0;
151   uint16_t expect_cipher = 0;
152   std::string expect_peer_cert_file;
153   int resumption_delay = 0;
154   bool retain_only_sha256_client_cert = false;
155   bool expect_sha256_client_cert = false;
156   bool read_with_unfinished_write = false;
157   bool expect_secure_renegotiation = false;
158   bool expect_no_secure_renegotiation = false;
159   int max_send_fragment = 0;
160   int read_size = 0;
161   bool expect_session_id = false;
162   bool expect_no_session_id = false;
163   int expect_ticket_age_skew = 0;
164   bool no_op_extra_handshake = false;
165   bool handshake_twice = false;
166   bool allow_unknown_alpn_protos = false;
167   bool use_custom_verify_callback = false;
168   std::string expect_msg_callback;
169   bool allow_false_start_without_alpn = false;
170   bool handoff = false;
171   bool handshake_hints = false;
172   bool allow_hint_mismatch = false;
173   bool use_ocsp_callback = false;
174   bool set_ocsp_in_callback = false;
175   bool decline_ocsp_callback = false;
176   bool fail_ocsp_callback = false;
177   bool install_cert_compression_algs = false;
178   int install_one_cert_compression_alg = 0;
179   bool reverify_on_resume = false;
180   bool enforce_rsa_key_usage = false;
181   bool is_handshaker_supported = false;
182   bool handshaker_resume = false;
183   std::string handshaker_path;
184   bool jdk11_workaround = false;
185   bool server_preference = false;
186   bool export_traffic_secrets = false;
187   bool key_update = false;
188   bool expect_delegated_credential_used = false;
189   std::string delegated_credential;
190   std::string expect_early_data_reason;
191   bool expect_hrr = false;
192   bool expect_no_hrr = false;
193   bool wait_for_debugger = false;
194   std::string quic_early_data_context;
195   int early_write_after_message = 0;
196 
197   int argc;
198   char **argv;
199 
200   bssl::UniquePtr<SSL_CTX> SetupCtx(SSL_CTX *old_ctx) const;
201 
202   bssl::UniquePtr<SSL> NewSSL(SSL_CTX *ssl_ctx, SSL_SESSION *session,
203                               std::unique_ptr<TestState> test_state) const;
204 };
205 
206 bool ParseConfig(int argc, char **argv, bool is_shim, TestConfig *out_initial,
207                  TestConfig *out_resume, TestConfig *out_retry);
208 
209 bool SetTestConfig(SSL *ssl, const TestConfig *config);
210 
211 const TestConfig *GetTestConfig(const SSL *ssl);
212 
213 bool LoadCertificate(bssl::UniquePtr<X509> *out_x509,
214                      bssl::UniquePtr<STACK_OF(X509)> *out_chain,
215                      const std::string &file);
216 
217 bssl::UniquePtr<EVP_PKEY> LoadPrivateKey(const std::string &file);
218 
219 #endif  // HEADER_TEST_CONFIG
220