s2n_config.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License").
  5. * You may not use this file except in compliance with the License.
  6. * A copy of the License is located at
  7. *
  8. * http://aws.amazon.com/apache2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #pragma once
  16. #include <sys/param.h>
  17. #include "api/s2n.h"
  18. #include "crypto/s2n_certificate.h"
  19. #include "crypto/s2n_dhe.h"
  20. #include "tls/s2n_crl.h"
  21. #include "tls/s2n_key_update.h"
  22. #include "tls/s2n_psk.h"
  23. #include "tls/s2n_record.h"
  24. #include "tls/s2n_renegotiate.h"
  25. #include "tls/s2n_resume.h"
  26. #include "tls/s2n_tls_parameters.h"
  27. #include "tls/s2n_x509_validator.h"
  28. #include "utils/s2n_blob.h"
  29. #include "utils/s2n_set.h"
  30. #define S2N_MAX_TICKET_KEYS 48
  31. #define S2N_MAX_TICKET_KEY_HASHES 500 /* 10KB */
  32. /*
  33. * TLS1.3 does not allow alert messages to be fragmented, and some TLS
  34. * implementations (for example, GnuTLS) reject fragmented TLS1.2 alerts.
  35. * The send buffer must be able to hold an unfragmented alert message.
  36. *
  37. * We choose not to fragment KeyUpdate messages to keep our post-handshake
  38. * fragmentation logic simple and consistent across message types.
  39. * The send buffer must be able to hold an unfragmented KeyUpdate message.
  40. */
  41. #define S2N_MIN_SEND_BUFFER_FRAGMENT_SIZE MAX(S2N_KEY_UPDATE_MESSAGE_SIZE, S2N_ALERT_LENGTH)
  42. #define S2N_MIN_SEND_BUFFER_SIZE S2N_TLS_MAX_RECORD_LEN_FOR(S2N_MIN_SEND_BUFFER_FRAGMENT_SIZE)
  43. struct s2n_cipher_preferences;
  44. typedef enum {
  45. S2N_NOT_OWNED = 0,
  46. S2N_APP_OWNED,
  47. S2N_LIB_OWNED,
  48. } s2n_cert_ownership;
  49. struct s2n_config {
  50. unsigned use_tickets : 1;
  51. /* Whether a connection can be used by a QUIC implementation.
  52. * See s2n_quic_support.h */
  53. unsigned quic_enabled : 1;
  54. unsigned default_certs_are_explicit : 1;
  55. unsigned use_session_cache : 1;
  56. /* if this is FALSE, server will ignore client's Maximum Fragment Length request */
  57. unsigned accept_mfl : 1;
  58. unsigned check_ocsp : 1;
  59. unsigned disable_x509_time_validation : 1;
  60. unsigned disable_x509_validation : 1;
  61. unsigned max_verify_cert_chain_depth_set : 1;
  62. /* Whether to add dss cert type during a server certificate request.
  63. * See https://github.com/aws/s2n-tls/blob/main/docs/USAGE-GUIDE.md */
  64. unsigned cert_req_dss_legacy_compat_enabled : 1;
  65. /* Whether any RSA certificates have been configured server-side to send to clients. This is needed so that the
  66. * server knows whether or not to self-downgrade to TLS 1.2 if the server is compiled with Openssl 1.0.2 and does
  67. * not support RSA PSS signing (which is required for TLS 1.3). */
  68. unsigned is_rsa_cert_configured : 1;
  69. /* It's possible to use a certificate without loading the private key,
  70. * but async signing must be enabled. Use this flag to enforce that restriction.
  71. */
  72. unsigned no_signing_key : 1;
  73. /*
  74. * Whether to verify signatures locally before sending them over the wire.
  75. * See s2n_config_set_verify_after_sign.
  76. */
  77. unsigned verify_after_sign : 1;
  78. /* Indicates support for the npn extension */
  79. unsigned npn_supported : 1;
  80. /* Indicates s2n_recv should read as much as it can into the output buffer
  81. *
  82. * Note: This defaults to false to ensure backwards compatability with
  83. * applications which relied on s2n_recv returning a single record.
  84. */
  85. unsigned recv_multi_record : 1;
  86. /* Indicates whether the user has enabled OCSP status requests */
  87. unsigned ocsp_status_requested_by_user : 1;
  88. /* Indicates whether s2n has enabled OCSP status requests, for backwards compatibility */
  89. unsigned ocsp_status_requested_by_s2n : 1;
  90. struct s2n_dh_params *dhparams;
  91. /* Needed until we can deprecate s2n_config_add_cert_chain_and_key. This is
  92. * used to release memory allocated only in the deprecated API that the application
  93. * does not have a reference to. */
  94. struct s2n_map *domain_name_to_cert_map;
  95. struct certs_by_type default_certs_by_type;
  96. struct s2n_blob application_protocols;
  97. s2n_clock_time_nanoseconds wall_clock;
  98. s2n_clock_time_nanoseconds monotonic_clock;
  99. const struct s2n_security_policy *security_policy;
  100. void *sys_clock_ctx;
  101. void *monotonic_clock_ctx;
  102. s2n_client_hello_fn *client_hello_cb;
  103. s2n_client_hello_cb_mode client_hello_cb_mode;
  104. void *client_hello_cb_ctx;
  105. uint64_t session_state_lifetime_in_nanos;
  106. struct s2n_set *ticket_keys;
  107. struct s2n_set *ticket_key_hashes;
  108. uint64_t encrypt_decrypt_key_lifetime_in_nanos;
  109. uint64_t decrypt_key_lifetime_in_nanos;
  110. /* If session cache is being used, these must all be set */
  111. s2n_cache_store_callback cache_store;
  112. void *cache_store_data;
  113. s2n_cache_retrieve_callback cache_retrieve;
  114. void *cache_retrieve_data;
  115. s2n_cache_delete_callback cache_delete;
  116. void *cache_delete_data;
  117. s2n_ct_support_level ct_type;
  118. s2n_cert_auth_type client_cert_auth_type;
  119. s2n_alert_behavior alert_behavior;
  120. /* Return TRUE if the host should be trusted, If FALSE this will likely be called again for every host/alternative name
  121. * in the certificate. If any respond TRUE. If none return TRUE, the cert will be considered untrusted. */
  122. s2n_verify_host_fn verify_host_fn;
  123. void *data_for_verify_host;
  124. s2n_crl_lookup_callback crl_lookup_cb;
  125. void *crl_lookup_ctx;
  126. s2n_cert_validation_callback cert_validation_cb;
  127. void *cert_validation_ctx;
  128. /* Application supplied callback to resolve domain name conflicts when loading certs. */
  129. s2n_cert_tiebreak_callback cert_tiebreak_cb;
  130. uint8_t mfl_code;
  131. uint8_t initial_tickets_to_send;
  132. struct s2n_x509_trust_store trust_store;
  133. uint16_t max_verify_cert_chain_depth;
  134. s2n_async_pkey_fn async_pkey_cb;
  135. s2n_psk_selection_callback psk_selection_cb;
  136. void *psk_selection_ctx;
  137. s2n_key_log_fn key_log_cb;
  138. void *key_log_ctx;
  139. s2n_session_ticket_fn session_ticket_cb;
  140. void *session_ticket_ctx;
  141. s2n_early_data_cb early_data_cb;
  142. uint32_t server_max_early_data_size;
  143. s2n_psk_mode psk_mode;
  144. s2n_async_pkey_validation_mode async_pkey_validation_mode;
  145. /* The user defined context associated with config */
  146. void *context;
  147. s2n_cert_ownership cert_ownership;
  148. /* Used to override the stuffer size for a connection's `out` stuffer. */
  149. uint32_t send_buffer_size_override;
  150. void *renegotiate_request_ctx;
  151. s2n_renegotiate_request_cb renegotiate_request_cb;
  152. };
  153. S2N_CLEANUP_RESULT s2n_config_ptr_free(struct s2n_config **config);
  154. int s2n_config_defaults_init(void);
  155. struct s2n_config *s2n_fetch_default_config(void);
  156. int s2n_config_set_unsafe_for_testing(struct s2n_config *config);
  157. int s2n_config_init_session_ticket_keys(struct s2n_config *config);
  158. int s2n_config_free_session_ticket_keys(struct s2n_config *config);
  159. void s2n_wipe_static_configs(void);
  160. struct s2n_cert_chain_and_key *s2n_config_get_single_default_cert(struct s2n_config *config);
  161. int s2n_config_get_num_default_certs(struct s2n_config *config);
  162. S2N_RESULT s2n_config_wall_clock(struct s2n_config *config, uint64_t *output);