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