• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2014 The BoringSSL Authors
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 <optional>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 #include <openssl/base.h>
24 #include <openssl/x509.h>
25 
26 #include "test_state.h"
27 
28 enum class CredentialConfigType {
29   kX509,
30   kDelegated,
31   kSPAKE2PlusV1,
32 };
33 
34 struct CredentialConfig {
35   CredentialConfigType type;
36   std::string cert_file;
37   std::string key_file;
38   std::vector<uint16_t> signing_prefs;
39   std::vector<uint8_t> delegated_credential;
40   std::vector<uint8_t> ocsp_response;
41   std::vector<uint8_t> signed_cert_timestamps;
42   std::vector<uint8_t> pake_context;
43   std::vector<uint8_t> pake_client_id;
44   std::vector<uint8_t> pake_server_id;
45   std::vector<uint8_t> pake_password;
46   bool wrong_pake_role = false;
47 };
48 
49 struct TestConfig {
50   int port = 0;
51   bool ipv6 = false;
52   uint64_t shim_id = 0;
53   bool is_server = false;
54   bool is_dtls = false;
55   bool is_quic = false;
56   int resume_count = 0;
57   std::string write_settings;
58   bool fallback_scsv = false;
59   std::vector<uint16_t> signing_prefs;
60   std::vector<uint16_t> verify_prefs;
61   std::vector<uint16_t> expect_peer_verify_prefs;
62   std::vector<uint16_t> curves;
63   std::string key_file;
64   std::string cert_file;
65   std::string trust_cert;
66   std::string expect_server_name;
67   bool enable_ech_grease = false;
68   std::vector<std::vector<uint8_t>> ech_server_configs;
69   std::vector<std::vector<uint8_t>> ech_server_keys;
70   std::vector<int> ech_is_retry_config;
71   bool expect_ech_accept = false;
72   std::string expect_ech_name_override;
73   bool expect_no_ech_name_override = false;
74   std::vector<uint8_t> expect_ech_retry_configs;
75   bool expect_no_ech_retry_configs = false;
76   std::vector<uint8_t> ech_config_list;
77   std::vector<uint8_t> expect_certificate_types;
78   bool require_any_client_certificate = false;
79   std::string advertise_npn;
80   bool advertise_empty_npn = false;
81   std::string expect_next_proto;
82   bool expect_no_next_proto = false;
83   bool false_start = false;
84   std::string select_next_proto;
85   bool select_empty_next_proto = false;
86   bool async = false;
87   bool write_different_record_sizes = false;
88   bool cbc_record_splitting = false;
89   bool partial_write = false;
90   bool no_tls13 = false;
91   bool no_tls12 = false;
92   bool no_tls11 = false;
93   bool no_tls1 = false;
94   bool no_ticket = false;
95   std::vector<uint8_t> expect_channel_id;
96   bool enable_channel_id = false;
97   std::string send_channel_id;
98   bool shim_writes_first = false;
99   std::string host_name;
100   std::string advertise_alpn;
101   std::string expect_alpn;
102   std::string expect_advertised_alpn;
103   std::string select_alpn;
104   bool decline_alpn = false;
105   bool reject_alpn = false;
106   bool select_empty_alpn = false;
107   bool defer_alps = false;
108   std::vector<std::pair<std::string, std::string>> application_settings;
109   std::optional<std::string> expect_peer_application_settings;
110   bool alps_use_new_codepoint = false;
111   std::vector<uint8_t> quic_transport_params;
112   std::vector<uint8_t> expect_quic_transport_params;
113   // Set quic_use_legacy_codepoint to 0 or 1 to configure, -1 uses default.
114   int quic_use_legacy_codepoint = -1;
115   bool expect_session_miss = false;
116   bool expect_extended_master_secret = false;
117   std::string psk;
118   std::string psk_identity;
119   std::string srtp_profiles;
120   bool enable_ocsp_stapling = false;
121   std::vector<uint8_t> expect_ocsp_response;
122   bool enable_signed_cert_timestamps = false;
123   std::vector<uint8_t> expect_signed_cert_timestamps;
124   uint16_t min_version = 0;
125   uint16_t max_version = 0;
126   uint16_t expect_version = 0;
127   int mtu = 0;
128   bool implicit_handshake = false;
129   bool use_early_callback = false;
130   bool fail_early_callback = false;
131   bool fail_early_callback_ech_rewind = false;
132   bool install_ddos_callback = false;
133   bool fail_ddos_callback = false;
134   bool fail_cert_callback = false;
135   std::string cipher;
136   bool handshake_never_done = false;
137   int export_keying_material = 0;
138   std::string export_label;
139   std::string export_context;
140   bool use_export_context = false;
141   bool tls_unique = false;
142   bool expect_ticket_renewal = false;
143   bool expect_no_session = false;
144   bool expect_ticket_supports_early_data = false;
145   bool expect_accept_early_data = false;
146   bool expect_reject_early_data = false;
147   bool expect_no_offer_early_data = false;
148   bool expect_no_server_name = false;
149   bool use_ticket_callback = false;
150   bool use_ticket_aead_callback = false;
151   bool renew_ticket = false;
152   bool skip_ticket = false;
153   bool enable_early_data = false;
154   std::vector<uint8_t> ocsp_response;
155   bool check_close_notify = false;
156   bool shim_shuts_down = false;
157   bool verify_fail = false;
158   bool verify_peer = false;
159   bool verify_peer_if_no_obc = false;
160   bool expect_verify_result = false;
161   std::vector<uint8_t> signed_cert_timestamps;
162   int expect_total_renegotiations = 0;
163   bool renegotiate_once = false;
164   bool renegotiate_freely = false;
165   bool renegotiate_ignore = false;
166   bool renegotiate_explicit = false;
167   bool forbid_renegotiation_after_handshake = false;
168   uint16_t expect_peer_signature_algorithm = 0;
169   uint16_t expect_curve_id = 0;
170   bool use_old_client_cert_callback = false;
171   int initial_timeout_duration_ms = 0;
172   std::string use_client_ca_list;
173   std::string expect_client_ca_list;
174   bool send_alert = false;
175   bool peek_then_read = false;
176   bool enable_grease = false;
177   bool permute_extensions = false;
178   int max_cert_list = 0;
179   std::vector<uint8_t> ticket_key;
180   bool use_exporter_between_reads = false;
181   uint16_t expect_cipher_aes = 0;
182   uint16_t expect_cipher_no_aes = 0;
183   uint16_t expect_cipher = 0;
184   std::string expect_peer_cert_file;
185   int resumption_delay = 0;
186   bool retain_only_sha256_client_cert = false;
187   bool expect_sha256_client_cert = false;
188   bool read_with_unfinished_write = false;
189   bool expect_secure_renegotiation = false;
190   bool expect_no_secure_renegotiation = false;
191   int max_send_fragment = 0;
192   int read_size = 0;
193   bool expect_session_id = false;
194   bool expect_no_session_id = false;
195   int expect_ticket_age_skew = 0;
196   bool no_op_extra_handshake = false;
197   bool handshake_twice = false;
198   bool allow_unknown_alpn_protos = false;
199   bool use_custom_verify_callback = false;
200   std::string expect_msg_callback;
201   bool allow_false_start_without_alpn = false;
202   bool handoff = false;
203   bool handshake_hints = false;
204   bool allow_hint_mismatch = false;
205   bool use_ocsp_callback = false;
206   bool set_ocsp_in_callback = false;
207   bool decline_ocsp_callback = false;
208   bool fail_ocsp_callback = false;
209   bool install_cert_compression_algs = false;
210   int install_one_cert_compression_alg = 0;
211   bool reverify_on_resume = false;
212   bool ignore_rsa_key_usage = false;
213   bool expect_key_usage_invalid = false;
214   bool is_handshaker_supported = false;
215   bool handshaker_resume = false;
216   std::string handshaker_path;
217   bool jdk11_workaround = false;
218   bool server_preference = false;
219   bool export_traffic_secrets = false;
220   bool key_update = false;
221   bool key_update_before_read = false;
222   std::string expect_early_data_reason;
223   bool expect_hrr = false;
224   bool expect_no_hrr = false;
225   bool wait_for_debugger = false;
226   std::string quic_early_data_context;
227   int early_write_after_message = 0;
228   bool fips_202205 = false;
229   bool wpa_202304 = false;
230   bool cnsa_202407 = false;
231   bool no_check_client_certificate_type = false;
232   bool no_check_ecdsa_curve = false;
233   std::optional<int> expect_selected_credential;
234   std::vector<CredentialConfig> credentials;
235   int private_key_delay_ms = 0;
236 
237   std::vector<const char *> handshaker_args;
238 
239   bssl::UniquePtr<SSL_CTX> SetupCtx(SSL_CTX *old_ctx) const;
240 
241   bssl::UniquePtr<SSL> NewSSL(SSL_CTX *ssl_ctx, SSL_SESSION *session,
242                               std::unique_ptr<TestState> test_state) const;
243 };
244 
245 bool ParseConfig(int argc, char **argv, bool is_shim, TestConfig *out_initial,
246                  TestConfig *out_resume, TestConfig *out_retry);
247 
248 bool SetTestConfig(SSL *ssl, const TestConfig *config);
249 
250 const TestConfig *GetTestConfig(const SSL *ssl);
251 
252 bool LoadCertificate(bssl::UniquePtr<X509> *out_x509,
253                      bssl::UniquePtr<STACK_OF(X509)> *out_chain,
254                      const std::string &file);
255 
256 bssl::UniquePtr<EVP_PKEY> LoadPrivateKey(const std::string &file);
257 
258 #endif  // HEADER_TEST_CONFIG
259