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