/src/botan/build/include/public/botan/tls_policy.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Hooks for application level policies on TLS connections |
3 | | * (C) 2004-2006,2013 Jack Lloyd |
4 | | * 2017 Harry Reimann, Rohde & Schwarz Cybersecurity |
5 | | * 2022 René Meusel, Rohde & Schwarz Cybersecurity |
6 | | * |
7 | | * Botan is released under the Simplified BSD License (see license.txt) |
8 | | */ |
9 | | |
10 | | #ifndef BOTAN_TLS_POLICY_H_ |
11 | | #define BOTAN_TLS_POLICY_H_ |
12 | | |
13 | | #include <botan/tls_ciphersuite.h> |
14 | | #include <botan/tls_extensions.h> |
15 | | #include <botan/tls_signature_scheme.h> |
16 | | #include <botan/tls_version.h> |
17 | | #include <chrono> |
18 | | #include <map> |
19 | | #include <optional> |
20 | | #include <vector> |
21 | | |
22 | | namespace Botan { |
23 | | |
24 | | class Public_Key; |
25 | | |
26 | | namespace TLS { |
27 | | |
28 | | /** |
29 | | * TLS Policy Base Class |
30 | | * Inherit and overload as desired to suit local policy concerns |
31 | | */ |
32 | | class BOTAN_PUBLIC_API(2, 0) Policy { |
33 | | public: |
34 | | /** |
35 | | * Allow ssl key log file |
36 | | * @note If function returns true, then Callbacks::tls_ssl_key_log_data |
37 | | * will be invoked containing secret information for logging purposes |
38 | | */ |
39 | | virtual bool allow_ssl_key_log_file() const; |
40 | | |
41 | | /** |
42 | | * Returns a list of ciphers we are willing to negotiate, in |
43 | | * order of preference. |
44 | | */ |
45 | | virtual std::vector<std::string> allowed_ciphers() const; |
46 | | |
47 | | /** |
48 | | * Returns a list of hash algorithms we are willing to use for |
49 | | * signatures, in order of preference. |
50 | | */ |
51 | | virtual std::vector<std::string> allowed_signature_hashes() const; |
52 | | |
53 | | /** |
54 | | * Returns a list of MAC algorithms we are willing to use. |
55 | | */ |
56 | | virtual std::vector<std::string> allowed_macs() const; |
57 | | |
58 | | /** |
59 | | * Returns a list of key exchange algorithms we are willing to |
60 | | * use, in order of preference. Allowed values: DH, empty string |
61 | | * (representing RSA using server certificate key) |
62 | | */ |
63 | | virtual std::vector<std::string> allowed_key_exchange_methods() const; |
64 | | |
65 | | /** |
66 | | * Returns a list of signature algorithms we are willing to |
67 | | * use, in order of preference. |
68 | | */ |
69 | | virtual std::vector<std::string> allowed_signature_methods() const; |
70 | | |
71 | | virtual std::vector<Signature_Scheme> allowed_signature_schemes() const; |
72 | | |
73 | | /** |
74 | | * Return a list of schemes we are willing to accept |
75 | | */ |
76 | | virtual std::vector<Signature_Scheme> acceptable_signature_schemes() const; |
77 | | |
78 | | /** |
79 | | * Return a list of schemes we are willing to accept for signatures in |
80 | | * certificates. |
81 | | * |
82 | | * By default, the same restrictions as in acceptable_signature_schemes() |
83 | | * apply. |
84 | | * |
85 | | * @return std::nullopt if the same restrictions as defined in |
86 | | * acceptable_signature_schemes() should apply |
87 | | */ |
88 | | virtual std::optional<std::vector<Signature_Scheme>> acceptable_certificate_signature_schemes() const; |
89 | | |
90 | | /** |
91 | | * The minimum signature strength we will accept |
92 | | * |
93 | | * Returning 80 allows RSA 1024 and SHA-1. Values larger than 80 disable |
94 | | * SHA-1 support. Returning 110 allows RSA 2048. Return 128 to force ECC |
95 | | * (P-256) or large (~3000 bit) RSA keys. |
96 | | * |
97 | | * Default is 110 |
98 | | */ |
99 | | virtual size_t minimum_signature_strength() const; |
100 | | |
101 | | /** |
102 | | * Return if certificate revocation info (CRL/OCSP) is required |
103 | | * |
104 | | * If true, certificates won't be trusted unless a valid CRL or OCSP |
105 | | * response was examined. |
106 | | * |
107 | | * Default: true |
108 | | */ |
109 | | virtual bool require_cert_revocation_info() const; |
110 | | |
111 | | bool allowed_signature_method(std::string_view sig_method) const; |
112 | | bool allowed_signature_hash(std::string_view hash) const; |
113 | | |
114 | | /** |
115 | | * Return a list of ECC curve and DH group TLS identifiers we are willing |
116 | | * to use, in order of preference. The default ordering puts the best |
117 | | * performing ECC first. |
118 | | * |
119 | | * Default: Group_Params::X25519, Group_Params::SECP256R1, |
120 | | * Group_Params::BRAINPOOL256R1, Group_Params::SECP384R1, |
121 | | * Group_Params::BRAINPOOL384R1, Group_Params::SECP521R1, |
122 | | * Group_Params::BRAINPOOL512R1, Group_Params::FFDHE_2048, |
123 | | * Group_Params::FFDHE_3072, Group_Params::FFDHE_4096, |
124 | | * Group_Params::FFDHE_6144, Group_Params::FFDHE_8192 |
125 | | * |
126 | | * No other values are currently defined. |
127 | | */ |
128 | | virtual std::vector<Group_Params> key_exchange_groups() const; |
129 | | |
130 | | /** |
131 | | * Return a list of groups to provide prepared key share offers in the |
132 | | * initial client hello for. Groups in this list must be reflected in |
133 | | * key_exchange_groups() and in the same order. |
134 | | * If an empty list is returned, no prepared key share offers are sent |
135 | | * and the decision of the group to use is left to the server. |
136 | | * |
137 | | * Default: the most preferred group from key_exchange_groups(). |
138 | | * |
139 | | * @note Has an effect on TLS 1.3 clients, only. |
140 | | */ |
141 | | virtual std::vector<Group_Params> key_exchange_groups_to_offer() const; |
142 | | |
143 | | /** |
144 | | * Request that ECC curve points are sent compressed |
145 | | * |
146 | | * Signals that we prefer ECC points to be compressed when transmitted to |
147 | | * us. The other party may not support ECC point compression and therefore |
148 | | * may still send points uncompressed. |
149 | | * |
150 | | * Note that the certificate used during authentication must also follow |
151 | | * the other party's preference. |
152 | | * |
153 | | * @note Support for EC point compression is deprecated and will be removed |
154 | | * in a future major release. TLS 1.3 does not support point compression |
155 | | * at all (see RFC 8446 4.2.8.2) |
156 | | */ |
157 | | virtual bool use_ecc_point_compression() const; |
158 | | |
159 | | /** |
160 | | * Select a key exchange group to use, from the list of groups sent by the |
161 | | * peer. In TLS 1.3 handshakes the peer might have provided cryptographic material |
162 | | * for a subset of its available groups. Choosing a group for which no share was |
163 | | * provided will result in an additional round trip. If none are acceptable, return |
164 | | * Group_Params::NONE. |
165 | | * |
166 | | * By default this will try to optimize for less round trips even if this results |
167 | | * in the usage of a less preferred group. |
168 | | */ |
169 | | virtual Group_Params choose_key_exchange_group(const std::vector<Group_Params>& supported_by_peer, |
170 | | const std::vector<Group_Params>& offered_by_peer) const; |
171 | | |
172 | | /** |
173 | | * Allow renegotiation even if the counterparty doesn't support the secure |
174 | | * renegotiation extension. |
175 | | * |
176 | | * Default: false |
177 | | * |
178 | | * @warning Changing this to true exposes you to injected plaintext |
179 | | * attacks. Read RFC 5746 for background. |
180 | | * |
181 | | * @note Has no effect for TLS 1.3 connections. |
182 | | */ |
183 | | virtual bool allow_insecure_renegotiation() const; |
184 | | |
185 | | /** |
186 | | * The protocol dictates that the first 32 bits of the random |
187 | | * field are the current time in seconds. However this allows |
188 | | * client fingerprinting attacks. Set to false to disable, in |
189 | | * which case random bytes will be used instead. |
190 | | * |
191 | | * Default: true |
192 | | */ |
193 | | virtual bool include_time_in_hello_random() const; |
194 | | |
195 | | /** |
196 | | * Consulted by server side. If true, allows clients to initiate a new |
197 | | * handshake |
198 | | * |
199 | | * If this function returns true, a server will accept a client-initiated |
200 | | * renegotiation attempt. Otherwise it will send the client a non-fatal |
201 | | * TLS::AlertType::NoRenegotiation alert. |
202 | | * |
203 | | * Default: false |
204 | | * |
205 | | * @note Has no effect for TLS 1.3 connections. |
206 | | */ |
207 | | virtual bool allow_client_initiated_renegotiation() const; |
208 | | |
209 | | /** |
210 | | * Consulted by client side. If true, allows servers to initiate a new |
211 | | * handshake |
212 | | * |
213 | | * If this function returns true, a client will accept a server-initiated |
214 | | * renegotiation attempt. Otherwise it will send the server a non-fatal |
215 | | * TLS::AlertType::NoRenegotiation alert. |
216 | | * |
217 | | * Default: false |
218 | | * |
219 | | * @note Has no effect for TLS 1.3 connections. |
220 | | */ |
221 | | virtual bool allow_server_initiated_renegotiation() const; |
222 | | |
223 | | /** |
224 | | * If true, a request to renegotiate will close the connection with |
225 | | * a fatal alert. Otherwise, a warning alert is sent. |
226 | | * |
227 | | * @sa allow_client_initiated_renegotiation |
228 | | * @sa allow_server_initiated_renegotiation |
229 | | * |
230 | | * Default: false |
231 | | * |
232 | | * @note Has no effect for TLS 1.3 connections. |
233 | | */ |
234 | | virtual bool abort_connection_on_undesired_renegotiation() const; |
235 | | |
236 | | /** |
237 | | * Only resume sessions when their original protocol version matches |
238 | | * the current version exactly. |
239 | | * |
240 | | * Default: true |
241 | | */ |
242 | | virtual bool only_resume_with_exact_version() const; |
243 | | |
244 | | /** |
245 | | * Allow TLS v1.2 |
246 | | */ |
247 | | virtual bool allow_tls12() const; |
248 | | |
249 | | /** |
250 | | * Allow TLS v1.3 |
251 | | */ |
252 | | virtual bool allow_tls13() const; |
253 | | |
254 | | /** |
255 | | * Allow DTLS v1.2 |
256 | | */ |
257 | | virtual bool allow_dtls12() const; |
258 | | |
259 | | /** |
260 | | * For ephemeral Diffie-Hellman key exchange, the server sends a group |
261 | | * parameter. Return the 2 Byte TLS group identifier specifying the group |
262 | | * parameter a server should use. |
263 | | * |
264 | | * Default: 2048 bit IETF IPsec group ("modp/ietf/2048") |
265 | | * |
266 | | * @note Has no effect for TLS 1.3 connections. |
267 | | */ |
268 | | virtual Group_Params default_dh_group() const; |
269 | | |
270 | | /** |
271 | | * Return the minimum DH group size we're willing to use |
272 | | * |
273 | | * Return the minimum size in bits for a Diffie-Hellman group that a client |
274 | | * will accept. Due to the design of the protocol the client has only two |
275 | | * options - accept the group, or reject it with a fatal alert then attempt |
276 | | * to reconnect after disabling ephemeral Diffie-Hellman. |
277 | | * |
278 | | * Default: 2048 bits |
279 | | */ |
280 | | virtual size_t minimum_dh_group_size() const; |
281 | | |
282 | | /** |
283 | | * For ECDSA authenticated ciphersuites, the smallest key size the |
284 | | * client will accept. |
285 | | * This policy is currently only enforced on the server by the client. |
286 | | * |
287 | | * Default: 256 |
288 | | */ |
289 | | virtual size_t minimum_ecdsa_group_size() const; |
290 | | |
291 | | /** |
292 | | * Return the minimum ECDH group size we're willing to use |
293 | | * for key exchange |
294 | | * |
295 | | * Default 255, allowing x25519 and larger |
296 | | * x25519 is the smallest curve we will negotiate |
297 | | * P-521 is the largest |
298 | | */ |
299 | | virtual size_t minimum_ecdh_group_size() const; |
300 | | |
301 | | /** |
302 | | * Return the minimum bit size we're willing to accept for RSA |
303 | | * key exchange or server signatures. |
304 | | * |
305 | | * It does not place any requirements on the size of any RSA signature(s) |
306 | | * which were used to check the server certificate. This is only |
307 | | * concerned with the server's public key. |
308 | | * |
309 | | * Default is 2048 which is smallest RSA key size still secure |
310 | | * for medium term security. |
311 | | */ |
312 | | virtual size_t minimum_rsa_bits() const; |
313 | | |
314 | | /** |
315 | | * Allows the policy to examine peer public keys. Throw an exception if the |
316 | | * key should be rejected. Default implementation checks against policy |
317 | | * values minimum_dh_group_size(), minimum_rsa_bits(), |
318 | | * minimum_ecdsa_group_size(), and minimum_ecdh_group_size(). |
319 | | * |
320 | | * Override if you'd like to perform some other kind of test on (or logging |
321 | | * of) the peer's keys. |
322 | | */ |
323 | | virtual void check_peer_key_acceptable(const Public_Key& public_key) const; |
324 | | |
325 | | /** |
326 | | * The PSK suites work using an identifier along with a shared secret. If |
327 | | * this function returns true, when an identifier that the server does not |
328 | | * recognize is provided by a client, a random shared secret will be |
329 | | * generated in such a way that a client should not be able to tell the |
330 | | * difference between the identifier not being known and the secret being |
331 | | * wrong. This can help protect against some username probing attacks. If |
332 | | * it returns false, the server will instead send an |
333 | | * TLS::AlertType::UnknownPSKIdentity alert when an unknown identifier is |
334 | | * used. |
335 | | * |
336 | | * Default: false |
337 | | */ |
338 | | virtual bool hide_unknown_users() const; |
339 | | |
340 | | /** |
341 | | * Defines the maximum number of session tickets a client might |
342 | | * offer in a single resumption attempt. Must be greater than 0. |
343 | | * |
344 | | * TODO: Currently, the TLS 1.3 client implementation supports |
345 | | * exactly one ticket per handshake. RFC 8446 allows for |
346 | | * an arbitrary amount, though. |
347 | | * |
348 | | * Default: 1 |
349 | | * |
350 | | * @note Has an effect on TLS 1.3 connections, only. |
351 | | */ |
352 | | virtual size_t maximum_session_tickets_per_client_hello() const; |
353 | | |
354 | | /** |
355 | | * Return the allowed lifetime of a session ticket. If 0, session |
356 | | * tickets do not expire until the session ticket key rolls over. |
357 | | * For TLS 1.3 session tickets the lifetime must not be longer than |
358 | | * seven days. Expired session tickets cannot be used to resume a |
359 | | * session. |
360 | | * |
361 | | * Default: 1 day |
362 | | */ |
363 | | virtual std::chrono::seconds session_ticket_lifetime() const; |
364 | | |
365 | | /** |
366 | | * Decides whether stored session tickets should be used multiple |
367 | | * times (until their lifetime runs out). This might allow passive |
368 | | * observers to correlate connections (RFC 8446 Appendix C.4). This |
369 | | * has no effect on TLS 1.2 resumptions based on session IDs as those |
370 | | * are negotiated in the clear anyway. |
371 | | * |
372 | | * Default: false |
373 | | */ |
374 | | virtual bool reuse_session_tickets() const; |
375 | | |
376 | | /** |
377 | | * Return the number of new session tickets a TLS 1.3 server should issue |
378 | | * automatically upon a successful handshake. Note that applications can |
379 | | * use `TLS::Server::send_new_session_tickets()` regardless of this policy. |
380 | | * |
381 | | * For convenience (and compatibility with the TLS 1.2 behaviour), this |
382 | | * returns '1' by default. |
383 | | * |
384 | | * @note Has an effect on TLS 1.3 connections, only. |
385 | | */ |
386 | | virtual size_t new_session_tickets_upon_handshake_success() const; |
387 | | |
388 | | /** |
389 | | * If this returns a non-empty vector, and DTLS is negotiated, |
390 | | * then we will also attempt to negotiate the SRTP extension from |
391 | | * RFC 5764 using the returned values as the profile ids. |
392 | | */ |
393 | | virtual std::vector<uint16_t> srtp_profiles() const; |
394 | | |
395 | | /** |
396 | | * @return true if and only if we are willing to accept this version |
397 | | * Default accepts TLS v1.2 and later or DTLS v1.2 or later. |
398 | | */ |
399 | | virtual bool acceptable_protocol_version(Protocol_Version version) const; |
400 | | |
401 | | /** |
402 | | * Returns the most recent protocol version we are willing to |
403 | | * use, for either TLS or DTLS depending on datagram param. |
404 | | * Shouldn't ever need to override this unless you want to allow |
405 | | * a user to disable specific TLS versions. |
406 | | */ |
407 | | virtual Protocol_Version latest_supported_version(bool datagram) const; |
408 | | |
409 | | /** |
410 | | * Allows policy to reject any ciphersuites which are undesirable |
411 | | * for whatever reason without having to reimplement ciphersuite_list |
412 | | */ |
413 | | virtual bool acceptable_ciphersuite(const Ciphersuite& suite) const; |
414 | | |
415 | | /** |
416 | | * Default: true |
417 | | * |
418 | | * @return true if servers should choose the ciphersuite matching |
419 | | * their highest preference, rather than the clients. |
420 | | * Has no effect on client side. |
421 | | */ |
422 | | virtual bool server_uses_own_ciphersuite_preferences() const; |
423 | | |
424 | | /** |
425 | | * Indicates whether the encrypt-then-MAC extension should be negotiated |
426 | | * (RFC 7366) |
427 | | * |
428 | | * @note Has no effect for TLS 1.3 connections. |
429 | | */ |
430 | | virtual bool negotiate_encrypt_then_mac() const; |
431 | | |
432 | | /** |
433 | | * Defines the maximum TLS record length for TLS connections. |
434 | | * This is based on the Record Size Limit extension described in RFC 8449. |
435 | | * By default (i.e. if std::nullopt is returned), TLS clients will omit |
436 | | * this extension altogether. |
437 | | * |
438 | | * This value may be between 64 and 16385 (TLS 1.3) or 16384 (TLS 1.2). |
439 | | * |
440 | | * @note This is currently not implemented for TLS 1.2, hence the limit |
441 | | * won't be negotiated by TLS 1.3 clients that support downgrading |
442 | | * to TLS 1.2 (i.e. #allow_tls12() returning true). |
443 | | */ |
444 | | virtual std::optional<uint16_t> record_size_limit() const; |
445 | | |
446 | | /** |
447 | | * Indicates whether certificate status messages should be supported |
448 | | */ |
449 | | virtual bool support_cert_status_message() const; |
450 | | |
451 | | /** |
452 | | * Indicate if client certificate authentication is required. |
453 | | * If true, then a cert will be requested and if the client does |
454 | | * not send a certificate the connection will be closed. |
455 | | */ |
456 | | virtual bool require_client_certificate_authentication() const; |
457 | | |
458 | | /** |
459 | | * Indicate if client certificate authentication is requested. |
460 | | * If true, then a cert will be requested. |
461 | | */ |
462 | | virtual bool request_client_certificate_authentication() const; |
463 | | |
464 | | /** |
465 | | * Returns a list of accepted certificate types for client authentication |
466 | | * in order of preference. See RFC 7250 and RFC 8446 4.4.2 for details. |
467 | | * Defaults to X509 only. |
468 | | * |
469 | | * Note that it is the application's responsibility to provide public keys |
470 | | * and/or certificates according to the specification in this list via the |
471 | | * Credentials_Manager. |
472 | | */ |
473 | | virtual std::vector<Certificate_Type> accepted_client_certificate_types() const; |
474 | | |
475 | | /** |
476 | | * Returns a list of accepted certificate types for server authentication |
477 | | * in order of preference. See RFC 7250 and RFC 8446 4.4.2 for details. |
478 | | * Defaults to X509 only. |
479 | | * |
480 | | * Note that it is the application's responsibility to provide public keys |
481 | | * and/or certificates according to the specification in this list via the |
482 | | * Credentials_Manager. |
483 | | */ |
484 | | virtual std::vector<Certificate_Type> accepted_server_certificate_types() const; |
485 | | |
486 | | /** |
487 | | * If true, then allow a DTLS client to restart a connection to the |
488 | | * same server association as described in section 4.2.8 of the DTLS RFC |
489 | | */ |
490 | | virtual bool allow_dtls_epoch0_restart() const; |
491 | | |
492 | | /** |
493 | | * Return allowed ciphersuites, in order of preference for the provided |
494 | | * protocol version. |
495 | | * |
496 | | * @param version the exact protocol version to select supported and allowed |
497 | | * ciphersuites for |
498 | | */ |
499 | | virtual std::vector<uint16_t> ciphersuite_list(Protocol_Version version) const; |
500 | | |
501 | | /** |
502 | | * @return the default MTU for DTLS |
503 | | */ |
504 | | virtual size_t dtls_default_mtu() const; |
505 | | |
506 | | /** |
507 | | * @return the initial timeout for DTLS |
508 | | */ |
509 | | virtual size_t dtls_initial_timeout() const; |
510 | | |
511 | | /** |
512 | | * @return the maximum timeout for DTLS |
513 | | */ |
514 | | virtual size_t dtls_maximum_timeout() const; |
515 | | |
516 | | /** |
517 | | * @return the maximum size of the certificate chain, in bytes. |
518 | | * Return 0 to disable this and accept any size. |
519 | | */ |
520 | | virtual size_t maximum_certificate_chain_size() const; |
521 | | |
522 | | /** |
523 | | * @note Has no effect for TLS 1.3 connections. |
524 | | */ |
525 | | virtual bool allow_resumption_for_renegotiation() const; |
526 | | |
527 | | /** |
528 | | * Defines whether or not the middlebox compatibility mode should be |
529 | | * used. Enabled by default. |
530 | | * |
531 | | * RFC 8446 Appendix D.4 |
532 | | * [This makes] the TLS 1.3 handshake resemble TLS 1.2 session resumption, |
533 | | * which improves the chance of successfully connecting through middleboxes. |
534 | | * |
535 | | * Default: true |
536 | | * |
537 | | * @note Has an effect on TLS 1.3 connections, only. |
538 | | */ |
539 | | virtual bool tls_13_middlebox_compatibility_mode() const; |
540 | | |
541 | | /** |
542 | | * Hash the RNG output for the client/server hello random. This is a pre-caution |
543 | | * to avoid writing "raw" RNG output to the wire. |
544 | | * |
545 | | * There's not normally a reason to disable this, except when deterministic output |
546 | | * is required for testing. |
547 | | * |
548 | | * Default: true |
549 | | */ |
550 | | virtual bool hash_hello_random() const; |
551 | | |
552 | | /** |
553 | | * Convert this policy to a printable format. |
554 | | * @param o stream to be printed to |
555 | | */ |
556 | | virtual void print(std::ostream& o) const; |
557 | | |
558 | | /** |
559 | | * Convert this policy to a printable format. |
560 | | * Same as calling `print` on a ostringstream and reading o.str() |
561 | | */ |
562 | | std::string to_string() const; |
563 | | |
564 | 9.79k | virtual ~Policy() = default; |
565 | | }; |
566 | | |
567 | | typedef Policy Default_Policy; |
568 | | |
569 | | /** |
570 | | * NSA Suite B 128-bit security level (RFC 6460) |
571 | | * |
572 | | * @warning As of August 2015 NSA indicated only the 192-bit Suite B |
573 | | * should be used for all classification levels. |
574 | | */ |
575 | | class BOTAN_PUBLIC_API(2, 0) NSA_Suite_B_128 : public Policy { |
576 | | public: |
577 | | BOTAN_DEPRECATED("This suite is no longer approved") NSA_Suite_B_128() = default; |
578 | | |
579 | 0 | std::vector<std::string> allowed_ciphers() const override { return std::vector<std::string>({"AES-128/GCM"}); } |
580 | | |
581 | 0 | std::vector<std::string> allowed_signature_hashes() const override { |
582 | 0 | return std::vector<std::string>({"SHA-256"}); |
583 | 0 | } |
584 | | |
585 | 0 | std::vector<std::string> allowed_macs() const override { return std::vector<std::string>({"AEAD"}); } |
586 | | |
587 | 0 | std::vector<std::string> allowed_key_exchange_methods() const override { |
588 | 0 | return std::vector<std::string>({"ECDH"}); |
589 | 0 | } |
590 | | |
591 | 0 | std::vector<std::string> allowed_signature_methods() const override { |
592 | 0 | return std::vector<std::string>({"ECDSA"}); |
593 | 0 | } |
594 | | |
595 | 0 | std::vector<Group_Params> key_exchange_groups() const override { return {Group_Params::SECP256R1}; } |
596 | | |
597 | 0 | size_t minimum_signature_strength() const override { return 128; } |
598 | | |
599 | 0 | bool allow_tls12() const override { return true; } |
600 | | |
601 | 0 | bool allow_tls13() const override { return false; } |
602 | | |
603 | 0 | bool allow_dtls12() const override { return false; } |
604 | | }; |
605 | | |
606 | | /** |
607 | | * NSA Suite B 192-bit security level (RFC 6460) |
608 | | */ |
609 | | class BOTAN_PUBLIC_API(2, 7) NSA_Suite_B_192 : public Policy { |
610 | | public: |
611 | 0 | std::vector<std::string> allowed_ciphers() const override { return std::vector<std::string>({"AES-256/GCM"}); } |
612 | | |
613 | 0 | std::vector<std::string> allowed_signature_hashes() const override { |
614 | 0 | return std::vector<std::string>({"SHA-384"}); |
615 | 0 | } |
616 | | |
617 | 0 | std::vector<std::string> allowed_macs() const override { return std::vector<std::string>({"AEAD"}); } |
618 | | |
619 | 0 | std::vector<std::string> allowed_key_exchange_methods() const override { |
620 | 0 | return std::vector<std::string>({"ECDH"}); |
621 | 0 | } |
622 | | |
623 | 0 | std::vector<std::string> allowed_signature_methods() const override { |
624 | 0 | return std::vector<std::string>({"ECDSA"}); |
625 | 0 | } |
626 | | |
627 | 0 | std::vector<Group_Params> key_exchange_groups() const override { return {Group_Params::SECP384R1}; } |
628 | | |
629 | 0 | size_t minimum_signature_strength() const override { return 192; } |
630 | | |
631 | 0 | bool allow_tls12() const override { return true; } |
632 | | |
633 | 0 | bool allow_tls13() const override { return false; } |
634 | | |
635 | 0 | bool allow_dtls12() const override { return false; } |
636 | | }; |
637 | | |
638 | | /** |
639 | | * BSI TR-02102-2 Policy |
640 | | */ |
641 | | class BOTAN_PUBLIC_API(2, 0) BSI_TR_02102_2 : public Policy { |
642 | | public: |
643 | 0 | std::vector<std::string> allowed_ciphers() const override { |
644 | 0 | return std::vector<std::string>( |
645 | 0 | {"AES-256/GCM", "AES-128/GCM", "AES-256/CCM", "AES-128/CCM", "AES-256", "AES-128"}); |
646 | 0 | } |
647 | | |
648 | 0 | std::vector<std::string> allowed_signature_hashes() const override { |
649 | 0 | return std::vector<std::string>({"SHA-512", "SHA-384", "SHA-256"}); |
650 | 0 | } |
651 | | |
652 | 0 | std::vector<std::string> allowed_macs() const override { |
653 | 0 | return std::vector<std::string>({"AEAD", "SHA-384", "SHA-256"}); |
654 | 0 | } |
655 | | |
656 | 0 | std::vector<std::string> allowed_key_exchange_methods() const override { |
657 | 0 | return std::vector<std::string>({"ECDH", "DH", "ECDHE_PSK"}); |
658 | 0 | } |
659 | | |
660 | 0 | std::vector<std::string> allowed_signature_methods() const override { |
661 | 0 | return std::vector<std::string>({"ECDSA", "RSA", "DSA"}); |
662 | 0 | } |
663 | | |
664 | 0 | std::vector<Group_Params> key_exchange_groups() const override { |
665 | 0 | return std::vector<Group_Params>({Group_Params::BRAINPOOL512R1, |
666 | 0 | Group_Params::BRAINPOOL384R1, |
667 | 0 | Group_Params::BRAINPOOL256R1, |
668 | 0 | Group_Params::SECP521R1, |
669 | 0 | Group_Params::SECP384R1, |
670 | 0 | Group_Params::SECP256R1, |
671 | 0 | Group_Params::FFDHE_4096, |
672 | 0 | Group_Params::FFDHE_3072}); |
673 | 0 | } |
674 | | |
675 | 0 | size_t minimum_signature_strength() const override { return 120; } |
676 | | |
677 | 0 | bool allow_insecure_renegotiation() const override { return false; } |
678 | | |
679 | 0 | bool allow_server_initiated_renegotiation() const override { return true; } |
680 | | |
681 | 0 | bool server_uses_own_ciphersuite_preferences() const override { return true; } |
682 | | |
683 | 0 | bool negotiate_encrypt_then_mac() const override { return true; } |
684 | | |
685 | 0 | size_t minimum_rsa_bits() const override { return 3000; } |
686 | | |
687 | 0 | size_t minimum_dh_group_size() const override { return 3000; } |
688 | | |
689 | 0 | size_t minimum_ecdh_group_size() const override { return 250; } |
690 | | |
691 | 0 | size_t minimum_ecdsa_group_size() const override { return 250; } |
692 | | |
693 | 0 | bool allow_tls12() const override { return true; } |
694 | | |
695 | 0 | bool allow_tls13() const override { return true; } |
696 | | |
697 | 0 | bool allow_dtls12() const override { return false; } |
698 | | }; |
699 | | |
700 | | /** |
701 | | * Policy for DTLS. We require DTLS v1.2 and an AEAD mode. |
702 | | */ |
703 | | class BOTAN_PUBLIC_API(2, 0) Datagram_Policy : public Policy { |
704 | | public: |
705 | 0 | std::vector<std::string> allowed_macs() const override { return std::vector<std::string>({"AEAD"}); } |
706 | | |
707 | 0 | bool allow_tls12() const override { return false; } |
708 | | |
709 | 0 | bool allow_tls13() const override { return false; } |
710 | | |
711 | 0 | bool allow_dtls12() const override { return true; } |
712 | | }; |
713 | | |
714 | | /* |
715 | | * This policy requires a secure version of TLS and disables all insecure |
716 | | * algorithms. It is compatible with other botan TLSes (including those using the |
717 | | * default policy) and with many other recent implementations. It is a great idea |
718 | | * to use if you control both sides of the protocol and don't have to worry |
719 | | * about ancient and/or bizarre TLS implementations. |
720 | | */ |
721 | | class BOTAN_PUBLIC_API(2, 0) Strict_Policy : public Policy { |
722 | | public: |
723 | | std::vector<std::string> allowed_ciphers() const override; |
724 | | |
725 | | std::vector<std::string> allowed_signature_hashes() const override; |
726 | | |
727 | | std::vector<std::string> allowed_macs() const override; |
728 | | |
729 | | std::vector<std::string> allowed_key_exchange_methods() const override; |
730 | | }; |
731 | | |
732 | | class BOTAN_PUBLIC_API(2, 0) Text_Policy : public Policy { |
733 | | public: |
734 | | bool allow_ssl_key_log_file() const override; |
735 | | |
736 | | std::vector<std::string> allowed_ciphers() const override; |
737 | | |
738 | | std::vector<std::string> allowed_signature_hashes() const override; |
739 | | |
740 | | std::vector<std::string> allowed_macs() const override; |
741 | | |
742 | | std::vector<std::string> allowed_key_exchange_methods() const override; |
743 | | |
744 | | std::vector<std::string> allowed_signature_methods() const override; |
745 | | |
746 | | std::vector<Group_Params> key_exchange_groups() const override; |
747 | | |
748 | | std::vector<Group_Params> key_exchange_groups_to_offer() const override; |
749 | | |
750 | | bool use_ecc_point_compression() const override; |
751 | | |
752 | | bool allow_tls12() const override; |
753 | | |
754 | | bool allow_tls13() const override; |
755 | | |
756 | | bool allow_dtls12() const override; |
757 | | |
758 | | bool allow_insecure_renegotiation() const override; |
759 | | |
760 | | bool include_time_in_hello_random() const override; |
761 | | |
762 | | bool allow_client_initiated_renegotiation() const override; |
763 | | bool allow_server_initiated_renegotiation() const override; |
764 | | |
765 | | bool server_uses_own_ciphersuite_preferences() const override; |
766 | | |
767 | | bool negotiate_encrypt_then_mac() const override; |
768 | | |
769 | | std::optional<uint16_t> record_size_limit() const override; |
770 | | |
771 | | bool support_cert_status_message() const override; |
772 | | |
773 | | bool require_client_certificate_authentication() const override; |
774 | | |
775 | | std::vector<Certificate_Type> accepted_client_certificate_types() const override; |
776 | | std::vector<Certificate_Type> accepted_server_certificate_types() const override; |
777 | | |
778 | | size_t minimum_ecdh_group_size() const override; |
779 | | |
780 | | size_t minimum_ecdsa_group_size() const override; |
781 | | |
782 | | size_t minimum_dh_group_size() const override; |
783 | | |
784 | | size_t minimum_rsa_bits() const override; |
785 | | |
786 | | size_t minimum_signature_strength() const override; |
787 | | |
788 | | size_t dtls_default_mtu() const override; |
789 | | |
790 | | size_t dtls_initial_timeout() const override; |
791 | | |
792 | | size_t dtls_maximum_timeout() const override; |
793 | | |
794 | | bool require_cert_revocation_info() const override; |
795 | | |
796 | | bool hide_unknown_users() const override; |
797 | | |
798 | | size_t maximum_session_tickets_per_client_hello() const override; |
799 | | |
800 | | std::chrono::seconds session_ticket_lifetime() const override; |
801 | | |
802 | | bool reuse_session_tickets() const override; |
803 | | |
804 | | size_t new_session_tickets_upon_handshake_success() const override; |
805 | | |
806 | | bool tls_13_middlebox_compatibility_mode() const override; |
807 | | |
808 | | bool hash_hello_random() const override; |
809 | | |
810 | | std::vector<uint16_t> srtp_profiles() const override; |
811 | | |
812 | | void set(const std::string& key, const std::string& value); |
813 | | |
814 | | explicit Text_Policy(std::string_view s); |
815 | | |
816 | | explicit Text_Policy(std::istream& in); |
817 | | |
818 | | protected: |
819 | | std::vector<std::string> get_list(const std::string& key, const std::vector<std::string>& def) const; |
820 | | |
821 | | std::vector<Group_Params> read_group_list(std::string_view group_str) const; |
822 | | std::vector<Certificate_Type> read_cert_type_list(const std::string& cert_type_str) const; |
823 | | |
824 | | size_t get_len(const std::string& key, size_t def) const; |
825 | | |
826 | | std::chrono::seconds get_duration(const std::string& key, std::chrono::seconds def) const; |
827 | | |
828 | | bool get_bool(const std::string& key, bool def) const; |
829 | | |
830 | | std::string get_str(const std::string& key, const std::string& def = "") const; |
831 | | |
832 | | bool set_value(const std::string& key, std::string_view val, bool overwrite); |
833 | | |
834 | | private: |
835 | | std::map<std::string, std::string> m_kv; |
836 | | }; |
837 | | |
838 | | } // namespace TLS |
839 | | |
840 | | } // namespace Botan |
841 | | |
842 | | #endif |