summaryrefslogtreecommitdiff
path: root/src/ssl/internal.h
diff options
context:
space:
mode:
authorAdam Vartanian <flooey@google.com>2018-08-10 14:55:24 +0100
committerAdam Vartanian <flooey@google.com>2018-08-10 15:32:39 +0100
commitbfcf3a72c0bcb62cfde80e932db0668a7f96c0f8 (patch)
tree3ab110046e45c25f8f69df137f8a9d4a52bf60b5 /src/ssl/internal.h
parent6120b2b9dfbe5b19fe2d0f69a4b8418ad5f7fe08 (diff)
downloadboringssl-bfcf3a72c0bcb62cfde80e932db0668a7f96c0f8.tar.gz
external/boringssl: Sync to 8625ec4b436ccb4098ed4aac10891eff8372be41.
This includes the following changes: https://boringssl.googlesource.com/boringssl/+log/c596415ec62b501523d80f9afa26b135406da6bf..8625ec4b436ccb4098ed4aac10891eff8372be41 Test: cts -m CtsLibcoreTestCases Change-Id: I47a45e6b6f46b19fcbcb6c917895867d56dcd2ca
Diffstat (limited to 'src/ssl/internal.h')
-rw-r--r--src/ssl/internal.h1364
1 files changed, 757 insertions, 607 deletions
diff --git a/src/ssl/internal.h b/src/ssl/internal.h
index b258589b..cc3e075a 100644
--- a/src/ssl/internal.h
+++ b/src/ssl/internal.h
@@ -175,8 +175,10 @@ OPENSSL_MSVC_PRAGMA(warning(pop))
namespace bssl {
+struct SSL_CONFIG;
struct SSL_HANDSHAKE;
struct SSL_PROTOCOL_METHOD;
+struct SSL_X509_METHOD;
// C++ utilities.
@@ -371,12 +373,16 @@ bool ssl_protocol_version_from_wire(uint16_t *out, uint16_t version);
// ssl_get_version_range sets |*out_min_version| and |*out_max_version| to the
// minimum and maximum enabled protocol versions, respectively.
-bool ssl_get_version_range(const SSL *ssl, uint16_t *out_min_version,
+bool ssl_get_version_range(const SSL_HANDSHAKE *hs, uint16_t *out_min_version,
uint16_t *out_max_version);
// ssl_supports_version returns whether |hs| supports |version|.
bool ssl_supports_version(SSL_HANDSHAKE *hs, uint16_t version);
+// ssl_method_supports_version returns whether |method| supports |version|.
+bool ssl_method_supports_version(const SSL_PROTOCOL_METHOD *method,
+ uint16_t version);
+
// ssl_add_supported_versions writes the supported versions of |hs| to |cbb|, in
// decreasing preference order.
bool ssl_add_supported_versions(SSL_HANDSHAKE *hs, CBB *cbb);
@@ -447,10 +453,8 @@ namespace bssl {
// Bits for |algorithm_mac| (symmetric authentication).
#define SSL_SHA1 0x00000001u
-#define SSL_SHA256 0x00000002u
-#define SSL_SHA384 0x00000004u
// SSL_AEAD is set for all AEADs.
-#define SSL_AEAD 0x00000008u
+#define SSL_AEAD 0x00000002u
// Bits for |algorithm_prf| (handshake digest).
#define SSL_HANDSHAKE_MAC_DEFAULT 0x1
@@ -520,7 +524,7 @@ const EVP_MD *ssl_get_handshake_digest(uint16_t version,
// true on success and false on failure. If |strict| is true, nonsense will be
// rejected. If false, nonsense will be silently ignored. An empty result is
// considered an error regardless of |strict|.
-bool ssl_create_cipher_list(SSLCipherPreferenceList **out_cipher_list,
+bool ssl_create_cipher_list(UniquePtr<SSLCipherPreferenceList> *out_cipher_list,
const char *rule_str, bool strict);
// ssl_cipher_get_value returns the cipher suite id of |cipher|.
@@ -602,14 +606,6 @@ class SSLTranscript {
// the number of bytes written. Otherwise, it returns false.
bool GetHash(uint8_t *out, size_t *out_len);
- // GetSSL3CertVerifyHash writes the SSL 3.0 CertificateVerify hash into the
- // bytes pointed to by |out| and writes the number of bytes to
- // |*out_len|. |out| must have room for |EVP_MAX_MD_SIZE| bytes. It returns
- // one on success and zero on failure.
- bool GetSSL3CertVerifyHash(uint8_t *out, size_t *out_len,
- const SSL_SESSION *session,
- uint16_t signature_algorithm);
-
// GetFinishedMAC computes the MAC for the Finished message into the bytes
// pointed by |out| and writes the number of bytes to |*out_len|. |out| must
// have room for |EVP_MAX_MD_SIZE| bytes. It returns true on success and false
@@ -620,12 +616,8 @@ class SSLTranscript {
private:
// buffer_, if non-null, contains the handshake transcript.
UniquePtr<BUF_MEM> buffer_;
- // hash, if initialized with an |EVP_MD|, maintains the handshake hash. For
- // TLS 1.1 and below, it is the SHA-1 half.
+ // hash, if initialized with an |EVP_MD|, maintains the handshake hash.
ScopedEVP_MD_CTX hash_;
- // md5, if initialized with an |EVP_MD|, maintains the MD5 half of the
- // handshake hash for TLS 1.1 and below.
- ScopedEVP_MD_CTX md5_;
};
// tls1_prf computes the PRF function for |ssl|. It fills |out|, using |secret|
@@ -771,9 +763,6 @@ class SSLAEADContext {
// omit_length_in_ad_ is true if the length should be omitted in the
// AEAD's ad parameter.
bool omit_length_in_ad_ : 1;
- // omit_version_in_ad_ is true if the version should be omitted
- // in the AEAD's ad parameter.
- bool omit_version_in_ad_ : 1;
// omit_ad_ is true if the AEAD's ad parameter should be omitted.
bool omit_ad_ : 1;
// ad_is_header_ is true if the AEAD's ad parameter is the record header.
@@ -908,9 +897,9 @@ enum ssl_open_record_t ssl_process_alert(SSL *ssl, uint8_t *out_alert,
// Private key operations.
-// ssl_has_private_key returns one if |ssl| has a private key
-// configured and zero otherwise.
-int ssl_has_private_key(const SSL *ssl);
+// ssl_has_private_key returns one if |cfg| has a private key configured and
+// zero otherwise.
+int ssl_has_private_key(const SSL_CONFIG *cfg);
// ssl_private_key_* perform the corresponding operation on
// |SSL_PRIVATE_KEY_METHOD|. If there is a custom private key configured, they
@@ -940,36 +929,6 @@ bool ssl_public_key_verify(SSL *ssl, Span<const uint8_t> signature,
Span<const uint8_t> in);
-// Custom extensions
-
-} // namespace bssl
-
-// |SSL_CUSTOM_EXTENSION| is a structure that contains information about
-// custom-extension callbacks. It is defined unnamespaced for compatibility with
-// |STACK_OF(SSL_CUSTOM_EXTENSION)|.
-typedef struct ssl_custom_extension {
- SSL_custom_ext_add_cb add_callback;
- void *add_arg;
- SSL_custom_ext_free_cb free_callback;
- SSL_custom_ext_parse_cb parse_callback;
- void *parse_arg;
- uint16_t value;
-} SSL_CUSTOM_EXTENSION;
-
-DEFINE_STACK_OF(SSL_CUSTOM_EXTENSION)
-
-namespace bssl {
-
-void SSL_CUSTOM_EXTENSION_free(SSL_CUSTOM_EXTENSION *custom_extension);
-
-int custom_ext_add_clienthello(SSL_HANDSHAKE *hs, CBB *extensions);
-int custom_ext_parse_serverhello(SSL_HANDSHAKE *hs, int *out_alert,
- uint16_t value, const CBS *extension);
-int custom_ext_parse_clienthello(SSL_HANDSHAKE *hs, int *out_alert,
- uint16_t value, const CBS *extension);
-int custom_ext_add_serverhello(SSL_HANDSHAKE *hs, CBB *extensions);
-
-
// Key shares.
// SSLKeyShare abstracts over Diffie-Hellman-like key exchanges.
@@ -1067,6 +1026,9 @@ bool tls_has_unprocessed_handshake_data(const SSL *ssl);
// |tls_has_unprocessed_handshake_data| for DTLS.
bool dtls_has_unprocessed_handshake_data(const SSL *ssl);
+// tls_flush_pending_hs_data flushes any handshake plaintext data.
+bool tls_flush_pending_hs_data(SSL *ssl);
+
struct DTLS_OUTGOING_MESSAGE {
DTLS_OUTGOING_MESSAGE() {}
DTLS_OUTGOING_MESSAGE(const DTLS_OUTGOING_MESSAGE &) = delete;
@@ -1175,7 +1137,7 @@ int ssl_write_buffer_flush(SSL *ssl);
// ssl_has_certificate returns one if a certificate and private key are
// configured and zero otherwise.
-int ssl_has_certificate(const SSL *ssl);
+int ssl_has_certificate(const SSL_CONFIG *cfg);
// ssl_parse_cert_chain parses a certificate list from |cbs| in the format used
// by a TLS Certificate message. On success, it advances |cbs| and returns
@@ -1194,10 +1156,10 @@ bool ssl_parse_cert_chain(uint8_t *out_alert,
uint8_t *out_leaf_sha256, CBS *cbs,
CRYPTO_BUFFER_POOL *pool);
-// ssl_add_cert_chain adds |ssl|'s certificate chain to |cbb| in the format used
-// by a TLS Certificate message. If there is no certificate chain, it emits an
-// empty certificate list. It returns one on success and zero on error.
-int ssl_add_cert_chain(SSL *ssl, CBB *cbb);
+// ssl_add_cert_chain adds |hs->ssl|'s certificate chain to |cbb| in the format
+// used by a TLS Certificate message. If there is no certificate chain, it emits
+// an empty certificate list. It returns one on success and zero on error.
+int ssl_add_cert_chain(SSL_HANDSHAKE *hs, CBB *cbb);
// ssl_cert_check_digital_signature_key_usage parses the DER-encoded, X.509
// certificate in |in| and returns one if doesn't specify a key usage or, if it
@@ -1219,12 +1181,12 @@ UniquePtr<STACK_OF(CRYPTO_BUFFER)> ssl_parse_client_CA_list(SSL *ssl,
CBS *cbs);
// ssl_has_client_CAs returns there are configured CAs.
-bool ssl_has_client_CAs(SSL *ssl);
+bool ssl_has_client_CAs(const SSL_CONFIG *cfg);
// ssl_add_client_CA_list adds the configured CA list to |cbb| in the format
// used by a TLS CertificateRequest message. It returns one on success and zero
// on error.
-int ssl_add_client_CA_list(SSL *ssl, CBB *cbb);
+int ssl_add_client_CA_list(SSL_HANDSHAKE *hs, CBB *cbb);
// ssl_check_leaf_certificate returns one if |pkey| and |leaf| are suitable as
// a server's leaf certificate for |hs|. Otherwise, it returns zero and pushes
@@ -1371,6 +1333,14 @@ enum tls12_server_hs_state_t {
state12_done,
};
+// handback_t lists the points in the state machine where a handback can occur.
+// These are the different points at which key material is no longer needed.
+enum handback_t {
+ handback_after_session_resumption,
+ handback_after_ecdhe,
+ handback_after_handshake,
+};
+
struct SSL_HANDSHAKE {
explicit SSL_HANDSHAKE(SSL *ssl);
~SSL_HANDSHAKE();
@@ -1379,6 +1349,9 @@ struct SSL_HANDSHAKE {
// ssl is a non-owning pointer to the parent |SSL| object.
SSL *ssl;
+ // config is a non-owning pointer to the handshake configuration.
+ SSL_CONFIG *config;
+
// wait contains the operation the handshake is currently blocking on or
// |ssl_hs_ok| if none.
enum ssl_hs_wait_t wait = ssl_hs_ok;
@@ -1418,17 +1391,6 @@ struct SSL_HANDSHAKE {
uint32_t received;
} extensions;
- union {
- // sent is a bitset where the bits correspond to elements of
- // |client_custom_extensions| in the |SSL_CTX|. Each bit is set if that
- // extension was sent in a ClientHello. It's not used by servers.
- uint16_t sent = 0;
- // received is a bitset, like |sent|, but is used by servers to record
- // which custom extensions were received from a client. The bits here
- // correspond to |server_custom_extensions|.
- uint16_t received;
- } custom_extensions;
-
// retry_group is the group ID selected by the server in HelloRetryRequest in
// TLS 1.3.
uint16_t retry_group = 0;
@@ -1472,6 +1434,11 @@ struct SSL_HANDSHAKE {
// sent.
uint16_t negotiated_token_binding_version;
+ // cert_compression_alg_id, for a server, contains the negotiated certificate
+ // compression algorithm for this client. It is only valid if
+ // |cert_compression_negotiated| is true.
+ uint16_t cert_compression_alg_id;
+
// server_params, in a TLS 1.2 server, stores the ServerKeyExchange
// parameters. It has client and server randoms prepended for signing
// convenience.
@@ -1524,8 +1491,6 @@ struct SSL_HANDSHAKE {
bool received_hello_retry_request:1;
bool sent_hello_retry_request:1;
- bool received_custom_extension:1;
-
// handshake_finalized is true once the handshake has completed, at which
// point accessors should use the established state.
bool handshake_finalized:1;
@@ -1586,6 +1551,14 @@ struct SSL_HANDSHAKE {
// grease_seeded is true if |grease_seed| has been initialized.
bool grease_seeded:1;
+ // handback indicates that a server should pause the handshake after
+ // finishing operations that require private key material, in such a way that
+ // |SSL_get_error| returns |SSL_HANDBACK|. It is set by |SSL_apply_handoff|.
+ bool handback:1;
+
+ // cert_compression_negotiated is true iff |cert_compression_alg_id| is valid.
+ bool cert_compression_negotiated:1;
+
// client_version is the value sent or received in the ClientHello version.
uint16_t client_version = 0;
@@ -1678,8 +1651,8 @@ bool ssl_ext_pre_shared_key_parse_clienthello(
bool ssl_ext_pre_shared_key_add_serverhello(SSL_HANDSHAKE *hs, CBB *out);
// ssl_is_sct_list_valid does a shallow parse of the SCT list in |contents| and
-// returns one iff it's valid.
-int ssl_is_sct_list_valid(const CBS *contents);
+// returns whether it's valid.
+bool ssl_is_sct_list_valid(const CBS *contents);
int ssl_write_client_hello(SSL_HANDSHAKE *hs);
@@ -1698,8 +1671,9 @@ bool tls13_get_cert_verify_signature_input(
enum ssl_cert_verify_context_t cert_verify_context);
// ssl_is_alpn_protocol_allowed returns whether |protocol| is a valid server
-// selection for |ssl|'s client preferences.
-bool ssl_is_alpn_protocol_allowed(const SSL *ssl, Span<const uint8_t> protocol);
+// selection for |hs->ssl|'s client preferences.
+bool ssl_is_alpn_protocol_allowed(const SSL_HANDSHAKE *hs,
+ Span<const uint8_t> protocol);
// ssl_negotiate_alpn negotiates the ALPN extension, if applicable. It returns
// true on successful negotiation or if nothing was negotiated. It returns false
@@ -1727,8 +1701,7 @@ enum ssl_verify_result_t ssl_verify_peer_cert(SSL_HANDSHAKE *hs);
enum ssl_hs_wait_t ssl_get_finished(SSL_HANDSHAKE *hs);
bool ssl_send_finished(SSL_HANDSHAKE *hs);
-bool ssl_output_cert_chain(SSL *ssl);
-
+bool ssl_output_cert_chain(SSL_HANDSHAKE *hs);
// SSLKEYLOGFILE functions.
@@ -1740,14 +1713,14 @@ int ssl_log_secret(const SSL *ssl, const char *label, const uint8_t *secret,
// ClientHello functions.
-int ssl_client_hello_init(SSL *ssl, SSL_CLIENT_HELLO *out,
- const SSLMessage &msg);
+bool ssl_client_hello_init(SSL *ssl, SSL_CLIENT_HELLO *out,
+ const SSLMessage &msg);
-int ssl_client_hello_get_extension(const SSL_CLIENT_HELLO *client_hello,
- CBS *out, uint16_t extension_type);
+bool ssl_client_hello_get_extension(const SSL_CLIENT_HELLO *client_hello,
+ CBS *out, uint16_t extension_type);
-int ssl_client_cipher_list_contains_cipher(const SSL_CLIENT_HELLO *client_hello,
- uint16_t id);
+bool ssl_client_cipher_list_contains_cipher(
+ const SSL_CLIENT_HELLO *client_hello, uint16_t id);
// GREASE.
@@ -1869,9 +1842,6 @@ struct CERT {
// ticket key. Only sessions with a matching value will be accepted.
uint8_t sid_ctx_length = 0;
uint8_t sid_ctx[SSL_MAX_SID_CTX_LENGTH] = {0};
-
- // If enable_early_data is true, early data can be sent and accepted.
- bool enable_early_data:1;
};
// |SSL_PROTOCOL_METHOD| abstracts between TLS and DTLS.
@@ -1951,6 +1921,62 @@ ssl_open_record_t ssl_open_app_data(SSL *ssl, Span<uint8_t> *out,
size_t *out_consumed, uint8_t *out_alert,
Span<uint8_t> in);
+struct SSL_X509_METHOD {
+ // check_client_CA_list returns one if |names| is a good list of X.509
+ // distinguished names and zero otherwise. This is used to ensure that we can
+ // reject unparsable values at handshake time when using crypto/x509.
+ int (*check_client_CA_list)(STACK_OF(CRYPTO_BUFFER) *names);
+
+ // cert_clear frees and NULLs all X509 certificate-related state.
+ void (*cert_clear)(CERT *cert);
+ // cert_free frees all X509-related state.
+ void (*cert_free)(CERT *cert);
+ // cert_flush_cached_chain drops any cached |X509|-based certificate chain
+ // from |cert|.
+ // cert_dup duplicates any needed fields from |cert| to |new_cert|.
+ void (*cert_dup)(CERT *new_cert, const CERT *cert);
+ void (*cert_flush_cached_chain)(CERT *cert);
+ // cert_flush_cached_chain drops any cached |X509|-based leaf certificate
+ // from |cert|.
+ void (*cert_flush_cached_leaf)(CERT *cert);
+
+ // session_cache_objects fills out |sess->x509_peer| and |sess->x509_chain|
+ // from |sess->certs| and erases |sess->x509_chain_without_leaf|. It returns
+ // one on success or zero on error.
+ int (*session_cache_objects)(SSL_SESSION *session);
+ // session_dup duplicates any needed fields from |session| to |new_session|.
+ // It returns one on success or zero on error.
+ int (*session_dup)(SSL_SESSION *new_session, const SSL_SESSION *session);
+ // session_clear frees any X509-related state from |session|.
+ void (*session_clear)(SSL_SESSION *session);
+ // session_verify_cert_chain verifies the certificate chain in |session|,
+ // sets |session->verify_result| and returns one on success or zero on
+ // error.
+ int (*session_verify_cert_chain)(SSL_SESSION *session, SSL_HANDSHAKE *ssl,
+ uint8_t *out_alert);
+
+ // hs_flush_cached_ca_names drops any cached |X509_NAME|s from |hs|.
+ void (*hs_flush_cached_ca_names)(SSL_HANDSHAKE *hs);
+ // ssl_new does any neccessary initialisation of |hs|. It returns one on
+ // success or zero on error.
+ int (*ssl_new)(SSL_HANDSHAKE *hs);
+ // ssl_free frees anything created by |ssl_new|.
+ void (*ssl_config_free)(SSL_CONFIG *cfg);
+ // ssl_flush_cached_client_CA drops any cached |X509_NAME|s from |ssl|.
+ void (*ssl_flush_cached_client_CA)(SSL_CONFIG *cfg);
+ // ssl_auto_chain_if_needed runs the deprecated auto-chaining logic if
+ // necessary. On success, it updates |ssl|'s certificate configuration as
+ // needed and returns one. Otherwise, it returns zero.
+ int (*ssl_auto_chain_if_needed)(SSL_HANDSHAKE *hs);
+ // ssl_ctx_new does any neccessary initialisation of |ctx|. It returns one on
+ // success or zero on error.
+ int (*ssl_ctx_new)(SSL_CTX *ctx);
+ // ssl_ctx_free frees anything created by |ssl_ctx_new|.
+ void (*ssl_ctx_free)(SSL_CTX *ctx);
+ // ssl_ctx_flush_cached_client_CA drops any cached |X509_NAME|s from |ctx|.
+ void (*ssl_ctx_flush_cached_client_CA)(SSL_CTX *ssl);
+};
+
// ssl_crypto_x509_method provides the |SSL_X509_METHOD| functions using
// crypto/x509.
extern const SSL_X509_METHOD ssl_crypto_x509_method;
@@ -1959,301 +1985,34 @@ extern const SSL_X509_METHOD ssl_crypto_x509_method;
// crypto/x509.
extern const SSL_X509_METHOD ssl_noop_x509_method;
-struct tlsext_ticket_key {
+struct TicketKey {
static constexpr bool kAllowUniquePtr = true;
- uint8_t name[SSL_TICKET_KEY_NAME_LEN];
- uint8_t hmac_key[16];
- uint8_t aes_key[16];
+ uint8_t name[SSL_TICKET_KEY_NAME_LEN] = {0};
+ uint8_t hmac_key[16] = {0};
+ uint8_t aes_key[16] = {0};
// next_rotation_tv_sec is the time (in seconds from the epoch) when the
// current key should be superseded by a new key, or the time when a previous
// key should be dropped. If zero, then the key should not be automatically
// rotated.
- uint64_t next_rotation_tv_sec;
+ uint64_t next_rotation_tv_sec = 0;
};
-} // namespace bssl
-
-DECLARE_LHASH_OF(SSL_SESSION)
-
-namespace bssl {
-
-// SSLContext backs the public |SSL_CTX| type. Due to compatibility constraints,
-// it is a base class for |ssl_ctx_st|.
-struct SSLContext {
- const SSL_PROTOCOL_METHOD *method;
- const SSL_X509_METHOD *x509_method;
-
- // lock is used to protect various operations on this object.
- CRYPTO_MUTEX lock;
-
- // conf_max_version is the maximum acceptable protocol version configured by
- // |SSL_CTX_set_max_proto_version|. Note this version is normalized in DTLS
- // and is further constrainted by |SSL_OP_NO_*|.
- uint16_t conf_max_version;
-
- // conf_min_version is the minimum acceptable protocol version configured by
- // |SSL_CTX_set_min_proto_version|. Note this version is normalized in DTLS
- // and is further constrainted by |SSL_OP_NO_*|.
- uint16_t conf_min_version;
-
- // tls13_variant is the variant of TLS 1.3 we are using for this
- // configuration.
- enum tls13_variant_t tls13_variant;
-
- SSLCipherPreferenceList *cipher_list;
-
- X509_STORE *cert_store;
- LHASH_OF(SSL_SESSION) *sessions;
- // Most session-ids that will be cached, default is
- // SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited.
- unsigned long session_cache_size;
- SSL_SESSION *session_cache_head;
- SSL_SESSION *session_cache_tail;
-
- // handshakes_since_cache_flush is the number of successful handshakes since
- // the last cache flush.
- int handshakes_since_cache_flush;
-
- // This can have one of 2 values, ored together,
- // SSL_SESS_CACHE_CLIENT,
- // SSL_SESS_CACHE_SERVER,
- // Default is SSL_SESSION_CACHE_SERVER, which means only
- // SSL_accept which cache SSL_SESSIONS.
- int session_cache_mode;
-
- // session_timeout is the default lifetime for new sessions in TLS 1.2 and
- // earlier, in seconds.
- uint32_t session_timeout;
-
- // session_psk_dhe_timeout is the default lifetime for new sessions in TLS
- // 1.3, in seconds.
- uint32_t session_psk_dhe_timeout;
-
- // If this callback is not null, it will be called each time a session id is
- // added to the cache. If this function returns 1, it means that the
- // callback will do a SSL_SESSION_free() when it has finished using it.
- // Otherwise, on 0, it means the callback has finished with it. If
- // remove_session_cb is not null, it will be called when a session-id is
- // removed from the cache. After the call, OpenSSL will SSL_SESSION_free()
- // it.
- int (*new_session_cb)(SSL *ssl, SSL_SESSION *sess);
- void (*remove_session_cb)(SSL_CTX *ctx, SSL_SESSION *sess);
- SSL_SESSION *(*get_session_cb)(SSL *ssl, const uint8_t *data, int len,
- int *copy);
-
- CRYPTO_refcount_t references;
-
- // if defined, these override the X509_verify_cert() calls
- int (*app_verify_callback)(X509_STORE_CTX *store_ctx, void *arg);
- void *app_verify_arg;
-
- enum ssl_verify_result_t (*custom_verify_callback)(SSL *ssl,
- uint8_t *out_alert);
-
- // Default password callback.
- pem_password_cb *default_passwd_callback;
-
- // Default password callback user data.
- void *default_passwd_callback_userdata;
-
- // get client cert callback
- int (*client_cert_cb)(SSL *ssl, X509 **out_x509, EVP_PKEY **out_pkey);
-
- // get channel id callback
- void (*channel_id_cb)(SSL *ssl, EVP_PKEY **out_pkey);
-
- CRYPTO_EX_DATA ex_data;
-
- // custom_*_extensions stores any callback sets for custom extensions. Note
- // that these pointers will be NULL if the stack would otherwise be empty.
- STACK_OF(SSL_CUSTOM_EXTENSION) *client_custom_extensions;
- STACK_OF(SSL_CUSTOM_EXTENSION) *server_custom_extensions;
-
- // Default values used when no per-SSL value is defined follow
-
- void (*info_callback)(const SSL *ssl, int type, int value);
-
- // what we put in client cert requests
- STACK_OF(CRYPTO_BUFFER) *client_CA;
-
- // cached_x509_client_CA is a cache of parsed versions of the elements of
- // |client_CA|.
- STACK_OF(X509_NAME) *cached_x509_client_CA;
-
-
- // Default values to use in SSL structures follow (these are copied by
- // SSL_new)
-
- uint32_t options;
- uint32_t mode;
- uint32_t max_cert_list;
-
- CERT *cert;
-
- // callback that allows applications to peek at protocol messages
- void (*msg_callback)(int write_p, int version, int content_type,
- const void *buf, size_t len, SSL *ssl, void *arg);
- void *msg_callback_arg;
-
- int verify_mode;
- int (*default_verify_callback)(
- int ok, X509_STORE_CTX *ctx); // called 'verify_callback' in the SSL
-
- X509_VERIFY_PARAM *param;
-
- // select_certificate_cb is called before most ClientHello processing and
- // before the decision whether to resume a session is made. See
- // |ssl_select_cert_result_t| for details of the return values.
- enum ssl_select_cert_result_t (*select_certificate_cb)(
- const SSL_CLIENT_HELLO *);
-
- // dos_protection_cb is called once the resumption decision for a ClientHello
- // has been made. It returns one to continue the handshake or zero to
- // abort.
- int (*dos_protection_cb) (const SSL_CLIENT_HELLO *);
-
- // Maximum amount of data to send in one fragment. actual record size can be
- // more than this due to padding and MAC overheads.
- uint16_t max_send_fragment;
-
- // TLS extensions servername callback
- int (*tlsext_servername_callback)(SSL *, int *, void *);
- void *tlsext_servername_arg;
-
- // RFC 4507 session ticket keys. |tlsext_ticket_key_current| may be NULL
- // before the first handshake and |tlsext_ticket_key_prev| may be NULL at any
- // time. Automatically generated ticket keys are rotated as needed at
- // handshake time. Hence, all access must be synchronized through |lock|.
- struct tlsext_ticket_key *tlsext_ticket_key_current;
- struct tlsext_ticket_key *tlsext_ticket_key_prev;
-
- // Callback to support customisation of ticket key setting
- int (*tlsext_ticket_key_cb)(SSL *ssl, uint8_t *name, uint8_t *iv,
- EVP_CIPHER_CTX *ectx, HMAC_CTX *hctx, int enc);
-
- // Server-only: psk_identity_hint is the default identity hint to send in
- // PSK-based key exchanges.
- char *psk_identity_hint;
-
- unsigned int (*psk_client_callback)(SSL *ssl, const char *hint,
- char *identity,
- unsigned int max_identity_len,
- uint8_t *psk, unsigned int max_psk_len);
- unsigned int (*psk_server_callback)(SSL *ssl, const char *identity,
- uint8_t *psk, unsigned int max_psk_len);
-
-
- // Next protocol negotiation information
- // (for experimental NPN extension).
-
- // For a server, this contains a callback function by which the set of
- // advertised protocols can be provided.
- int (*next_protos_advertised_cb)(SSL *ssl, const uint8_t **out,
- unsigned *out_len, void *arg);
- void *next_protos_advertised_cb_arg;
- // For a client, this contains a callback function that selects the
- // next protocol from the list provided by the server.
- int (*next_proto_select_cb)(SSL *ssl, uint8_t **out, uint8_t *out_len,
- const uint8_t *in, unsigned in_len, void *arg);
- void *next_proto_select_cb_arg;
-
- // ALPN information
- // (we are in the process of transitioning from NPN to ALPN.)
-
- // For a server, this contains a callback function that allows the
- // server to select the protocol for the connection.
- // out: on successful return, this must point to the raw protocol
- // name (without the length prefix).
- // outlen: on successful return, this contains the length of |*out|.
- // in: points to the client's list of supported protocols in
- // wire-format.
- // inlen: the length of |in|.
- int (*alpn_select_cb)(SSL *ssl, const uint8_t **out, uint8_t *out_len,
- const uint8_t *in, unsigned in_len, void *arg);
- void *alpn_select_cb_arg;
-
- // For a client, this contains the list of supported protocols in wire
- // format.
- uint8_t *alpn_client_proto_list;
- unsigned alpn_client_proto_list_len;
-
- // SRTP profiles we are willing to do from RFC 5764
- STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
-
- // Supported group values inherited by SSL structure
- size_t supported_group_list_len;
- uint16_t *supported_group_list;
-
- // The client's Channel ID private key.
- EVP_PKEY *tlsext_channel_id_private;
-
- // keylog_callback, if not NULL, is the key logging callback. See
- // |SSL_CTX_set_keylog_callback|.
- void (*keylog_callback)(const SSL *ssl, const char *line);
-
- // current_time_cb, if not NULL, is the function to use to get the current
- // time. It sets |*out_clock| to the current time. The |ssl| argument is
- // always NULL. See |SSL_CTX_set_current_time_cb|.
- void (*current_time_cb)(const SSL *ssl, struct timeval *out_clock);
-
- // pool is used for all |CRYPTO_BUFFER|s in case we wish to share certificate
- // memory.
- CRYPTO_BUFFER_POOL *pool;
-
- // ticket_aead_method contains function pointers for opening and sealing
- // session tickets.
- const SSL_TICKET_AEAD_METHOD *ticket_aead_method;
-
- // verify_sigalgs, if not empty, is the set of signature algorithms
- // accepted from the peer in decreasing order of preference.
- uint16_t *verify_sigalgs;
- size_t num_verify_sigalgs;
-
- // retain_only_sha256_of_client_certs is true if we should compute the SHA256
- // hash of the peer's certificate and then discard it to save memory and
- // session space. Only effective on the server side.
- bool retain_only_sha256_of_client_certs:1;
-
- // quiet_shutdown is true if the connection should not send a close_notify on
- // shutdown.
- bool quiet_shutdown:1;
-
- // ocsp_stapling_enabled is only used by client connections and indicates
- // whether OCSP stapling will be requested.
- bool ocsp_stapling_enabled:1;
-
- // If true, a client will request certificate timestamps.
- bool signed_cert_timestamps_enabled:1;
-
- // tlsext_channel_id_enabled is whether Channel ID is enabled. For a server,
- // means that we'll accept Channel IDs from clients. For a client, means that
- // we'll advertise support.
- bool tlsext_channel_id_enabled:1;
-
- // grease_enabled is whether draft-davidben-tls-grease-01 is enabled.
- bool grease_enabled:1;
+struct CertCompressionAlg {
+ static constexpr bool kAllowUniquePtr = true;
- // allow_unknown_alpn_protos is whether the client allows unsolicited ALPN
- // protocols from the peer.
- bool allow_unknown_alpn_protos:1;
+ ssl_cert_compression_func_t compress = nullptr;
+ ssl_cert_decompression_func_t decompress = nullptr;
+ uint16_t alg_id = 0;
+};
- // ed25519_enabled is whether Ed25519 is advertised in the handshake.
- bool ed25519_enabled:1;
+} // namespace bssl
- // rsa_pss_rsae_certs_enabled is whether rsa_pss_rsae_* are supported by the
- // certificate verifier.
- bool rsa_pss_rsae_certs_enabled:1;
+DECLARE_LHASH_OF(SSL_SESSION)
- // false_start_allowed_without_alpn is whether False Start (if
- // |SSL_MODE_ENABLE_FALSE_START| is enabled) is allowed without ALPN.
- bool false_start_allowed_without_alpn:1;
+DEFINE_NAMED_STACK_OF(CertCompressionAlg, bssl::CertCompressionAlg);
- // handoff indicates that a server should stop after receiving the
- // ClientHello and pause the handshake in such a way that |SSL_get_error|
- // returns |SSL_HANDOFF|.
- bool handoff:1;
-};
+namespace bssl {
// An ssl_shutdown_t describes the shutdown state of one end of the connection,
// whether it is alive or has been shutdown via close_notify or fatal alert.
@@ -2359,9 +2118,8 @@ struct SSL3_STATE {
// In a client, this means that the server supported Channel ID and that a
// Channel ID was sent. In a server it means that we echoed support for
- // Channel IDs and that tlsext_channel_id will be valid after the
- // handshake.
- bool tlsext_channel_id_valid:1;
+ // Channel IDs and that |channel_id| will be valid after the handshake.
+ bool channel_id_valid:1;
// key_update_pending is true if we have a KeyUpdate acknowledgment
// outstanding.
@@ -2383,6 +2141,11 @@ struct SSL3_STATE {
// hs_buf is the buffer of handshake data to process.
UniquePtr<BUF_MEM> hs_buf;
+ // pending_hs_data contains the pending handshake data that has not yet
+ // been encrypted to |pending_flight|. This allows packing the handshake into
+ // fewer records.
+ UniquePtr<BUF_MEM> pending_hs_data;
+
// pending_flight is the pending outgoing flight. This is used to flush each
// handshake flight in a single write. |write_buffer| must be written out
// before this data.
@@ -2449,10 +2212,10 @@ struct SSL3_STATE {
UniquePtr<char> hostname;
// For a server:
- // If |tlsext_channel_id_valid| is true, then this contains the
+ // If |channel_id_valid| is true, then this contains the
// verified Channel ID from the client: a P256 point, (x,y), where
// each are big-endian values.
- uint8_t tlsext_channel_id[64] = {0};
+ uint8_t channel_id[64] = {0};
// Contains the QUIC transport params received by the peer.
Array<uint8_t> peer_quic_transport_params;
@@ -2580,147 +2343,89 @@ struct DTLS1_STATE {
unsigned timeout_duration_ms = 0;
};
-// SSLConnection backs the public |SSL| type. Due to compatibility constraints,
-// it is a base class for |ssl_st|.
-struct SSLConnection {
- // method is the method table corresponding to the current protocol (DTLS or
- // TLS).
- const SSL_PROTOCOL_METHOD *method;
+// SSL_CONFIG contains configuration bits that can be shed after the handshake
+// completes. Objects of this type are not shared; they are unique to a
+// particular |SSL|.
+//
+// See SSL_shed_handshake_config() for more about the conditions under which
+// configuration can be shed.
+struct SSL_CONFIG {
+ static constexpr bool kAllowUniquePtr = true;
- // version is the protocol version.
- uint16_t version;
+ explicit SSL_CONFIG(SSL *ssl_arg);
+ ~SSL_CONFIG();
+
+ // ssl is a non-owning pointer to the parent |SSL| object.
+ SSL *const ssl = nullptr;
// conf_max_version is the maximum acceptable protocol version configured by
// |SSL_set_max_proto_version|. Note this version is normalized in DTLS and is
// further constrainted by |SSL_OP_NO_*|.
- uint16_t conf_max_version;
+ uint16_t conf_max_version = 0;
// conf_min_version is the minimum acceptable protocol version configured by
// |SSL_set_min_proto_version|. Note this version is normalized in DTLS and is
// further constrainted by |SSL_OP_NO_*|.
- uint16_t conf_min_version;
+ uint16_t conf_min_version = 0;
- uint16_t max_send_fragment;
-
- // There are 2 BIO's even though they are normally both the same. This is so
- // data can be read and written to different handlers
-
- BIO *rbio; // used by SSL_read
- BIO *wbio; // used by SSL_write
-
- // do_handshake runs the handshake. On completion, it returns |ssl_hs_ok|.
- // Otherwise, it returns a value corresponding to what operation is needed to
- // progress.
- enum ssl_hs_wait_t (*do_handshake)(SSL_HANDSHAKE *hs);
-
- SSL3_STATE *s3; // SSLv3 variables
- DTLS1_STATE *d1; // DTLSv1 variables
-
- // callback that allows applications to peek at protocol messages
- void (*msg_callback)(int write_p, int version, int content_type,
- const void *buf, size_t len, SSL *ssl, void *arg);
- void *msg_callback_arg;
-
- X509_VERIFY_PARAM *param;
+ X509_VERIFY_PARAM *param = nullptr;
// crypto
- SSLCipherPreferenceList *cipher_list;
-
- // session info
+ UniquePtr<SSLCipherPreferenceList> cipher_list;
// This is used to hold the local certificate used (i.e. the server
// certificate for a server or the client certificate for a client).
- CERT *cert;
-
- // initial_timeout_duration_ms is the default DTLS timeout duration in
- // milliseconds. It's used to initialize the timer any time it's restarted.
- unsigned initial_timeout_duration_ms;
-
- // tls13_variant is the variant of TLS 1.3 we are using for this
- // configuration.
- enum tls13_variant_t tls13_variant;
-
- // session is the configured session to be offered by the client. This session
- // is immutable.
- SSL_SESSION *session;
+ UniquePtr<CERT> cert;
int (*verify_callback)(int ok,
- X509_STORE_CTX *ctx); // fail if callback returns 0
-
- enum ssl_verify_result_t (*custom_verify_callback)(SSL *ssl,
- uint8_t *out_alert);
-
- void (*info_callback)(const SSL *ssl, int type, int value);
+ X509_STORE_CTX *ctx) =
+ nullptr; // fail if callback returns 0
+ enum ssl_verify_result_t (*custom_verify_callback)(
+ SSL *ssl, uint8_t *out_alert) = nullptr;
// Server-only: psk_identity_hint is the identity hint to send in
// PSK-based key exchanges.
- char *psk_identity_hint;
-
- unsigned int (*psk_client_callback)(SSL *ssl, const char *hint,
- char *identity,
- unsigned int max_identity_len,
- uint8_t *psk, unsigned int max_psk_len);
- unsigned int (*psk_server_callback)(SSL *ssl, const char *identity,
- uint8_t *psk, unsigned int max_psk_len);
+ UniquePtr<char> psk_identity_hint;
- SSL_CTX *ctx;
-
- // extra application data
- CRYPTO_EX_DATA ex_data;
+ unsigned (*psk_client_callback)(SSL *ssl, const char *hint, char *identity,
+ unsigned max_identity_len, uint8_t *psk,
+ unsigned max_psk_len) = nullptr;
+ unsigned (*psk_server_callback)(SSL *ssl, const char *identity, uint8_t *psk,
+ unsigned max_psk_len) = nullptr;
// for server side, keep the list of CA_dn we can use
- STACK_OF(CRYPTO_BUFFER) *client_CA;
+ UniquePtr<STACK_OF(CRYPTO_BUFFER)> client_CA;
// cached_x509_client_CA is a cache of parsed versions of the elements of
// |client_CA|.
- STACK_OF(X509_NAME) *cached_x509_client_CA;
-
- uint32_t options; // protocol behaviour
- uint32_t mode; // API behaviour
- uint32_t max_cert_list;
- uint16_t dummy_pq_padding_len;
- char *tlsext_hostname;
- size_t supported_group_list_len;
- uint16_t *supported_group_list; // our list
-
- // session_ctx is the |SSL_CTX| used for the session cache and related
- // settings.
- SSL_CTX *session_ctx;
+ STACK_OF(X509_NAME) *cached_x509_client_CA = nullptr;
- // srtp_profiles is the list of configured SRTP protection profiles for
- // DTLS-SRTP.
- STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
+ uint16_t dummy_pq_padding_len = 0;
+ Array<uint16_t> supported_group_list; // our list
// The client's Channel ID private key.
- EVP_PKEY *tlsext_channel_id_private;
+ UniquePtr<EVP_PKEY> channel_id_private;
// For a client, this contains the list of supported protocols in wire
// format.
- uint8_t *alpn_client_proto_list;
- unsigned alpn_client_proto_list_len;
+ Array<uint8_t> alpn_client_proto_list;
// Contains a list of supported Token Binding key parameters.
- uint8_t *token_binding_params;
- size_t token_binding_params_len;
+ Array<uint8_t> token_binding_params;
// Contains the QUIC transport params that this endpoint will send.
- uint8_t *quic_transport_params;
- size_t quic_transport_params_len;
+ Array<uint8_t> quic_transport_params;
- // renegotiate_mode controls how peer renegotiation attempts are handled.
- enum ssl_renegotiate_mode_t renegotiate_mode;
-
- // verify_mode is a bitmask of |SSL_VERIFY_*| values.
- uint8_t verify_mode;
+ // verify_sigalgs, if not empty, is the set of signature algorithms
+ // accepted from the peer in decreasing order of preference.
+ Array<uint16_t> verify_sigalgs;
- // server is true iff the this SSL* is the server half. Note: before the SSL*
- // is initialized by either SSL_set_accept_state or SSL_set_connect_state,
- // the side is not determined. In this state, server is always false.
- bool server:1;
+ // srtp_profiles is the list of configured SRTP protection profiles for
+ // DTLS-SRTP.
+ UniquePtr<STACK_OF(SRTP_PROTECTION_PROFILE)> srtp_profiles;
- // quiet_shutdown is true if the connection should not send a close_notify on
- // shutdown.
- bool quiet_shutdown:1;
+ // verify_mode is a bitmask of |SSL_VERIFY_*| values.
+ uint8_t verify_mode = SSL_VERIFY_NONE;
// Enable signed certificate time stamps. Currently client only.
bool signed_cert_timestamps_enabled:1;
@@ -2729,10 +2434,10 @@ struct SSLConnection {
// whether OCSP stapling will be requested.
bool ocsp_stapling_enabled:1;
- // tlsext_channel_id_enabled is copied from the |SSL_CTX|. For a server,
- // means that we'll accept Channel IDs from clients. For a client, means that
- // we'll advertise support.
- bool tlsext_channel_id_enabled:1;
+ // channel_id_enabled is copied from the |SSL_CTX|. For a server, means that
+ // we'll accept Channel IDs from clients. For a client, means that we'll
+ // advertise support.
+ bool channel_id_enabled:1;
// retain_only_sha256_of_client_certs is true if we should compute the SHA256
// hash of the peer's certificate and then discard it to save memory and
@@ -2745,15 +2450,9 @@ struct SSLConnection {
// element of the same name and may be cleared if the handoff is declined.
bool handoff:1;
- // handback indicates that a server should pause the handshake after
- // finishing operations that require private key material, in such a way that
- // |SSL_get_error| returns |SSL_HANDBACK|. It is set by |SSL_apply_handoff|.
- bool handback : 1;
-
- // did_dummy_pq_padding is only valid for a client. In that context, it is
- // true iff the client observed the server echoing a dummy PQ padding
- // extension.
- bool did_dummy_pq_padding:1;
+ // shed_handshake_config indicates that the handshake config (this object!)
+ // should be freed after the handshake completes.
+ bool shed_handshake_config : 1;
};
// From draft-ietf-tls-tls13-18, used in determining PSK modes.
@@ -2780,27 +2479,31 @@ int ssl_compare_public_and_private_key(const EVP_PKEY *pubkey,
const EVP_PKEY *privkey);
int ssl_cert_check_private_key(const CERT *cert, const EVP_PKEY *privkey);
int ssl_get_new_session(SSL_HANDSHAKE *hs, int is_server);
-int ssl_encrypt_ticket(SSL *ssl, CBB *out, const SSL_SESSION *session);
+int ssl_encrypt_ticket(SSL_HANDSHAKE *hs, CBB *out, const SSL_SESSION *session);
int ssl_ctx_rotate_ticket_encryption_key(SSL_CTX *ctx);
// ssl_session_new returns a newly-allocated blank |SSL_SESSION| or nullptr on
// error.
UniquePtr<SSL_SESSION> ssl_session_new(const SSL_X509_METHOD *x509_method);
+// ssl_hash_session_id returns a hash of |session_id|, suitable for a hash table
+// keyed on session IDs.
+uint32_t ssl_hash_session_id(Span<const uint8_t> session_id);
+
// SSL_SESSION_parse parses an |SSL_SESSION| from |cbs| and advances |cbs| over
// the parsed data.
-UniquePtr<SSL_SESSION> SSL_SESSION_parse(CBS *cbs,
- const SSL_X509_METHOD *x509_method,
- CRYPTO_BUFFER_POOL *pool);
+OPENSSL_EXPORT UniquePtr<SSL_SESSION> SSL_SESSION_parse(
+ CBS *cbs, const SSL_X509_METHOD *x509_method, CRYPTO_BUFFER_POOL *pool);
// ssl_session_serialize writes |in| to |cbb| as if it were serialising a
// session for Session-ID resumption. It returns one on success and zero on
// error.
-int ssl_session_serialize(const SSL_SESSION *in, CBB *cbb);
+OPENSSL_EXPORT int ssl_session_serialize(const SSL_SESSION *in, CBB *cbb);
// ssl_session_is_context_valid returns one if |session|'s session ID context
-// matches the one set on |ssl| and zero otherwise.
-int ssl_session_is_context_valid(const SSL *ssl, const SSL_SESSION *session);
+// matches the one set on |hs| and zero otherwise.
+int ssl_session_is_context_valid(const SSL_HANDSHAKE *hs,
+ const SSL_SESSION *session);
// ssl_session_is_time_valid returns one if |session| is still valid and zero if
// it has expired.
@@ -2827,7 +2530,7 @@ void ssl_set_session(SSL *ssl, SSL_SESSION *session);
// |ssl_hs_pending_session| and should be called again. If a ticket could not be
// decrypted immediately it returns |ssl_hs_pending_ticket| and should also
// be called again. Otherwise, it returns |ssl_hs_error|.
-enum ssl_hs_wait_t ssl_get_prev_session(SSL *ssl,
+enum ssl_hs_wait_t ssl_get_prev_session(SSL_HANDSHAKE *hs,
UniquePtr<SSL_SESSION> *out_session,
bool *out_tickets_supported,
bool *out_renew_ticket,
@@ -2856,10 +2559,6 @@ void ssl_session_rebase_time(SSL *ssl, SSL_SESSION *session);
void ssl_session_renew_timeout(SSL *ssl, SSL_SESSION *session,
uint32_t timeout);
-// ssl_get_cipher_preferences returns the cipher preference list for TLS 1.2 and
-// below.
-const SSLCipherPreferenceList *ssl_get_cipher_preferences(const SSL *ssl);
-
void ssl_update_cache(SSL_HANDSHAKE *hs, int mode);
int ssl_send_alert(SSL *ssl, int level, int desc);
@@ -2952,41 +2651,38 @@ int tls1_generate_master_secret(SSL_HANDSHAKE *hs, uint8_t *out,
Span<const uint8_t> premaster);
// tls1_get_grouplist returns the locally-configured group preference list.
-Span<const uint16_t> tls1_get_grouplist(const SSL *ssl);
+Span<const uint16_t> tls1_get_grouplist(const SSL_HANDSHAKE *ssl);
-// tls1_check_group_id returns one if |group_id| is consistent with
-// locally-configured group preferences.
-int tls1_check_group_id(const SSL *ssl, uint16_t group_id);
+// tls1_check_group_id returns whether |group_id| is consistent with locally-
+// configured group preferences.
+bool tls1_check_group_id(const SSL_HANDSHAKE *ssl, uint16_t group_id);
// tls1_get_shared_group sets |*out_group_id| to the first preferred shared
-// group between client and server preferences and returns one. If none may be
-// found, it returns zero.
-int tls1_get_shared_group(SSL_HANDSHAKE *hs, uint16_t *out_group_id);
+// group between client and server preferences and returns true. If none may be
+// found, it returns false.
+bool tls1_get_shared_group(SSL_HANDSHAKE *hs, uint16_t *out_group_id);
-// tls1_set_curves converts the array of |ncurves| NIDs pointed to by |curves|
-// into a newly allocated array of TLS group IDs. On success, the function
-// returns one and writes the array to |*out_group_ids| and its size to
-// |*out_group_ids_len|. Otherwise, it returns zero.
-int tls1_set_curves(uint16_t **out_group_ids, size_t *out_group_ids_len,
- const int *curves, size_t ncurves);
+// tls1_set_curves converts the array of NIDs in |curves| into a newly allocated
+// array of TLS group IDs. On success, the function returns true and writes the
+// array to |*out_group_ids|. Otherwise, it returns false.
+bool tls1_set_curves(Array<uint16_t> *out_group_ids, Span<const int> curves);
// tls1_set_curves_list converts the string of curves pointed to by |curves|
// into a newly allocated array of TLS group IDs. On success, the function
-// returns one and writes the array to |*out_group_ids| and its size to
-// |*out_group_ids_len|. Otherwise, it returns zero.
-int tls1_set_curves_list(uint16_t **out_group_ids, size_t *out_group_ids_len,
- const char *curves);
-
-// ssl_add_clienthello_tlsext writes ClientHello extensions to |out|. It
-// returns one on success and zero on failure. The |header_len| argument is the
-// length of the ClientHello written so far and is used to compute the padding
-// length. (It does not include the record header.)
-int ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, size_t header_len);
-
-int ssl_add_serverhello_tlsext(SSL_HANDSHAKE *hs, CBB *out);
-int ssl_parse_clienthello_tlsext(SSL_HANDSHAKE *hs,
- const SSL_CLIENT_HELLO *client_hello);
-int ssl_parse_serverhello_tlsext(SSL_HANDSHAKE *hs, CBS *cbs);
+// returns true and writes the array to |*out_group_ids|. Otherwise, it returns
+// false.
+bool tls1_set_curves_list(Array<uint16_t> *out_group_ids, const char *curves);
+
+// ssl_add_clienthello_tlsext writes ClientHello extensions to |out|. It returns
+// true on success and false on failure. The |header_len| argument is the length
+// of the ClientHello written so far and is used to compute the padding length.
+// (It does not include the record header.)
+bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, size_t header_len);
+
+bool ssl_add_serverhello_tlsext(SSL_HANDSHAKE *hs, CBB *out);
+bool ssl_parse_clienthello_tlsext(SSL_HANDSHAKE *hs,
+ const SSL_CLIENT_HELLO *client_hello);
+bool ssl_parse_serverhello_tlsext(SSL_HANDSHAKE *hs, CBS *cbs);
#define tlsext_tick_md EVP_sha256
@@ -3000,38 +2696,41 @@ int ssl_parse_serverhello_tlsext(SSL_HANDSHAKE *hs, CBS *cbs);
// Retry later.
// |ssl_ticket_aead_error|: an error occured that is fatal to the connection.
enum ssl_ticket_aead_result_t ssl_process_ticket(
- SSL *ssl, UniquePtr<SSL_SESSION> *out_session, bool *out_renew_ticket,
- const uint8_t *ticket, size_t ticket_len, const uint8_t *session_id,
- size_t session_id_len);
+ SSL_HANDSHAKE *hs, UniquePtr<SSL_SESSION> *out_session,
+ bool *out_renew_ticket, const uint8_t *ticket, size_t ticket_len,
+ const uint8_t *session_id, size_t session_id_len);
// tls1_verify_channel_id processes |msg| as a Channel ID message, and verifies
-// the signature. If the key is valid, it saves the Channel ID and returns
-// one. Otherwise, it returns zero.
-int tls1_verify_channel_id(SSL_HANDSHAKE *hs, const SSLMessage &msg);
+// the signature. If the key is valid, it saves the Channel ID and returns true.
+// Otherwise, it returns false.
+bool tls1_verify_channel_id(SSL_HANDSHAKE *hs, const SSLMessage &msg);
// tls1_write_channel_id generates a Channel ID message and puts the output in
-// |cbb|. |ssl->tlsext_channel_id_private| must already be set before calling.
-// This function returns true on success and false on error.
+// |cbb|. |ssl->channel_id_private| must already be set before calling. This
+// function returns true on success and false on error.
bool tls1_write_channel_id(SSL_HANDSHAKE *hs, CBB *cbb);
// tls1_channel_id_hash computes the hash to be signed by Channel ID and writes
// it to |out|, which must contain at least |EVP_MAX_MD_SIZE| bytes. It returns
-// one on success and zero on failure.
-int tls1_channel_id_hash(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len);
+// true on success and false on failure.
+bool tls1_channel_id_hash(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len);
-int tls1_record_handshake_hashes_for_channel_id(SSL_HANDSHAKE *hs);
+// tls1_record_handshake_hashes_for_channel_id records the current handshake
+// hashes in |hs->new_session| so that Channel ID resumptions can sign that
+// data.
+bool tls1_record_handshake_hashes_for_channel_id(SSL_HANDSHAKE *hs);
-// ssl_do_channel_id_callback checks runs |ssl->ctx->channel_id_cb| if
-// necessary. It returns one on success and zero on fatal error. Note that, on
-// success, |ssl->tlsext_channel_id_private| may be unset, in which case the
+// ssl_do_channel_id_callback checks runs |hs->ssl->ctx->channel_id_cb| if
+// necessary. It returns true on success and false on fatal error. Note that, on
+// success, |hs->ssl->channel_id_private| may be unset, in which case the
// operation should be retried later.
-int ssl_do_channel_id_callback(SSL *ssl);
+bool ssl_do_channel_id_callback(SSL_HANDSHAKE *hs);
-// ssl_can_write returns one if |ssl| is allowed to write and zero otherwise.
-int ssl_can_write(const SSL *ssl);
+// ssl_can_write returns whether |ssl| is allowed to write.
+bool ssl_can_write(const SSL *ssl);
-// ssl_can_read returns one if |ssl| is allowed to read and zero otherwise.
-int ssl_can_read(const SSL *ssl);
+// ssl_can_read returns wheter |ssl| is allowed to read.
+bool ssl_can_read(const SSL *ssl);
void ssl_get_current_time(const SSL *ssl, struct OPENSSL_timeval *out_clock);
void ssl_ctx_get_current_time(const SSL_CTX *ctx,
@@ -3063,70 +2762,521 @@ struct ssl_method_st {
const bssl::SSL_PROTOCOL_METHOD *method;
// x509_method contains pointers to functions that might deal with |X509|
// compatibility, or might be a no-op, depending on the application.
- const SSL_X509_METHOD *x509_method;
+ const bssl::SSL_X509_METHOD *x509_method;
};
-struct ssl_x509_method_st {
- // check_client_CA_list returns one if |names| is a good list of X.509
- // distinguished names and zero otherwise. This is used to ensure that we can
- // reject unparsable values at handshake time when using crypto/x509.
- int (*check_client_CA_list)(STACK_OF(CRYPTO_BUFFER) *names);
+struct ssl_ctx_st {
+ explicit ssl_ctx_st(const SSL_METHOD *ssl_method);
+ ssl_ctx_st(const ssl_ctx_st &) = delete;
+ ssl_ctx_st &operator=(const ssl_ctx_st &) = delete;
- // cert_clear frees and NULLs all X509 certificate-related state.
- void (*cert_clear)(bssl::CERT *cert);
- // cert_free frees all X509-related state.
- void (*cert_free)(bssl::CERT *cert);
- // cert_flush_cached_chain drops any cached |X509|-based certificate chain
- // from |cert|.
- // cert_dup duplicates any needed fields from |cert| to |new_cert|.
- void (*cert_dup)(bssl::CERT *new_cert, const bssl::CERT *cert);
- void (*cert_flush_cached_chain)(bssl::CERT *cert);
- // cert_flush_cached_chain drops any cached |X509|-based leaf certificate
- // from |cert|.
- void (*cert_flush_cached_leaf)(bssl::CERT *cert);
+ const bssl::SSL_PROTOCOL_METHOD *method = nullptr;
+ const bssl::SSL_X509_METHOD *x509_method = nullptr;
- // session_cache_objects fills out |sess->x509_peer| and |sess->x509_chain|
- // from |sess->certs| and erases |sess->x509_chain_without_leaf|. It returns
- // one on success or zero on error.
- int (*session_cache_objects)(SSL_SESSION *session);
- // session_dup duplicates any needed fields from |session| to |new_session|.
- // It returns one on success or zero on error.
- int (*session_dup)(SSL_SESSION *new_session, const SSL_SESSION *session);
- // session_clear frees any X509-related state from |session|.
- void (*session_clear)(SSL_SESSION *session);
- // session_verify_cert_chain verifies the certificate chain in |session|,
- // sets |session->verify_result| and returns one on success or zero on
- // error.
- int (*session_verify_cert_chain)(SSL_SESSION *session, SSL *ssl,
- uint8_t *out_alert);
+ // lock is used to protect various operations on this object.
+ CRYPTO_MUTEX lock;
- // hs_flush_cached_ca_names drops any cached |X509_NAME|s from |hs|.
- void (*hs_flush_cached_ca_names)(bssl::SSL_HANDSHAKE *hs);
- // ssl_new does any neccessary initialisation of |ssl|. It returns one on
- // success or zero on error.
- int (*ssl_new)(SSL *ssl);
- // ssl_free frees anything created by |ssl_new|.
- void (*ssl_free)(SSL *ssl);
- // ssl_flush_cached_client_CA drops any cached |X509_NAME|s from |ssl|.
- void (*ssl_flush_cached_client_CA)(SSL *ssl);
- // ssl_auto_chain_if_needed runs the deprecated auto-chaining logic if
- // necessary. On success, it updates |ssl|'s certificate configuration as
- // needed and returns one. Otherwise, it returns zero.
- int (*ssl_auto_chain_if_needed)(SSL *ssl);
- // ssl_ctx_new does any neccessary initialisation of |ctx|. It returns one on
- // success or zero on error.
- int (*ssl_ctx_new)(SSL_CTX *ctx);
- // ssl_ctx_free frees anything created by |ssl_ctx_new|.
- void (*ssl_ctx_free)(SSL_CTX *ctx);
- // ssl_ctx_flush_cached_client_CA drops any cached |X509_NAME|s from |ctx|.
- void (*ssl_ctx_flush_cached_client_CA)(SSL_CTX *ssl);
+ // conf_max_version is the maximum acceptable protocol version configured by
+ // |SSL_CTX_set_max_proto_version|. Note this version is normalized in DTLS
+ // and is further constrainted by |SSL_OP_NO_*|.
+ uint16_t conf_max_version = 0;
+
+ // conf_min_version is the minimum acceptable protocol version configured by
+ // |SSL_CTX_set_min_proto_version|. Note this version is normalized in DTLS
+ // and is further constrainted by |SSL_OP_NO_*|.
+ uint16_t conf_min_version = 0;
+
+ // tls13_variant is the variant of TLS 1.3 we are using for this
+ // configuration.
+ tls13_variant_t tls13_variant = tls13_default;
+
+ bssl::UniquePtr<bssl::SSLCipherPreferenceList> cipher_list;
+
+ X509_STORE *cert_store = nullptr;
+ LHASH_OF(SSL_SESSION) *sessions = nullptr;
+ // Most session-ids that will be cached, default is
+ // SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited.
+ unsigned long session_cache_size = SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;
+ SSL_SESSION *session_cache_head = nullptr;
+ SSL_SESSION *session_cache_tail = nullptr;
+
+ // handshakes_since_cache_flush is the number of successful handshakes since
+ // the last cache flush.
+ int handshakes_since_cache_flush = 0;
+
+ // This can have one of 2 values, ored together,
+ // SSL_SESS_CACHE_CLIENT,
+ // SSL_SESS_CACHE_SERVER,
+ // Default is SSL_SESSION_CACHE_SERVER, which means only
+ // SSL_accept which cache SSL_SESSIONS.
+ int session_cache_mode = SSL_SESS_CACHE_SERVER;
+
+ // session_timeout is the default lifetime for new sessions in TLS 1.2 and
+ // earlier, in seconds.
+ uint32_t session_timeout = SSL_DEFAULT_SESSION_TIMEOUT;
+
+ // session_psk_dhe_timeout is the default lifetime for new sessions in TLS
+ // 1.3, in seconds.
+ uint32_t session_psk_dhe_timeout = SSL_DEFAULT_SESSION_PSK_DHE_TIMEOUT;
+
+ // If this callback is not null, it will be called each time a session id is
+ // added to the cache. If this function returns 1, it means that the
+ // callback will do a SSL_SESSION_free() when it has finished using it.
+ // Otherwise, on 0, it means the callback has finished with it. If
+ // remove_session_cb is not null, it will be called when a session-id is
+ // removed from the cache. After the call, OpenSSL will SSL_SESSION_free()
+ // it.
+ int (*new_session_cb)(SSL *ssl, SSL_SESSION *sess) = nullptr;
+ void (*remove_session_cb)(SSL_CTX *ctx, SSL_SESSION *sess) = nullptr;
+ SSL_SESSION *(*get_session_cb)(SSL *ssl, const uint8_t *data, int len,
+ int *copy) = nullptr;
+
+ CRYPTO_refcount_t references = 1;
+
+ // if defined, these override the X509_verify_cert() calls
+ int (*app_verify_callback)(X509_STORE_CTX *store_ctx, void *arg) = nullptr;
+ void *app_verify_arg = nullptr;
+
+ ssl_verify_result_t (*custom_verify_callback)(SSL *ssl,
+ uint8_t *out_alert) = nullptr;
+
+ // Default password callback.
+ pem_password_cb *default_passwd_callback = nullptr;
+
+ // Default password callback user data.
+ void *default_passwd_callback_userdata = nullptr;
+
+ // get client cert callback
+ int (*client_cert_cb)(SSL *ssl, X509 **out_x509, EVP_PKEY **out_pkey) = nullptr;
+
+ // get channel id callback
+ void (*channel_id_cb)(SSL *ssl, EVP_PKEY **out_pkey) = nullptr;
+
+ CRYPTO_EX_DATA ex_data;
+
+ // Default values used when no per-SSL value is defined follow
+
+ void (*info_callback)(const SSL *ssl, int type, int value) = nullptr;
+
+ // what we put in client cert requests
+ bssl::UniquePtr<STACK_OF(CRYPTO_BUFFER)> client_CA;
+
+ // cached_x509_client_CA is a cache of parsed versions of the elements of
+ // |client_CA|.
+ STACK_OF(X509_NAME) *cached_x509_client_CA = nullptr;
+
+
+ // Default values to use in SSL structures follow (these are copied by
+ // SSL_new)
+
+ uint32_t options = 0;
+ // Disable the auto-chaining feature by default. wpa_supplicant relies on this
+ // feature, but require callers opt into it.
+ uint32_t mode = SSL_MODE_NO_AUTO_CHAIN;
+ uint32_t max_cert_list = SSL_MAX_CERT_LIST_DEFAULT;
+
+ bssl::UniquePtr<bssl::CERT> cert;
+
+ // callback that allows applications to peek at protocol messages
+ void (*msg_callback)(int write_p, int version, int content_type,
+ const void *buf, size_t len, SSL *ssl, void *arg) = nullptr;
+ void *msg_callback_arg = nullptr;
+
+ int verify_mode = SSL_VERIFY_NONE;
+ int (*default_verify_callback)(int ok, X509_STORE_CTX *ctx) =
+ nullptr; // called 'verify_callback' in the SSL
+
+ X509_VERIFY_PARAM *param = nullptr;
+
+ // select_certificate_cb is called before most ClientHello processing and
+ // before the decision whether to resume a session is made. See
+ // |ssl_select_cert_result_t| for details of the return values.
+ ssl_select_cert_result_t (*select_certificate_cb)(const SSL_CLIENT_HELLO *) =
+ nullptr;
+
+ // dos_protection_cb is called once the resumption decision for a ClientHello
+ // has been made. It returns one to continue the handshake or zero to
+ // abort.
+ int (*dos_protection_cb) (const SSL_CLIENT_HELLO *) = nullptr;
+
+ // Maximum amount of data to send in one fragment. actual record size can be
+ // more than this due to padding and MAC overheads.
+ uint16_t max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;
+
+ // TLS extensions servername callback
+ int (*servername_callback)(SSL *, int *, void *) = nullptr;
+ void *servername_arg = nullptr;
+
+ // RFC 4507 session ticket keys. |ticket_key_current| may be NULL before the
+ // first handshake and |ticket_key_prev| may be NULL at any time.
+ // Automatically generated ticket keys are rotated as needed at handshake
+ // time. Hence, all access must be synchronized through |lock|.
+ bssl::UniquePtr<bssl::TicketKey> ticket_key_current;
+ bssl::UniquePtr<bssl::TicketKey> ticket_key_prev;
+
+ // Callback to support customisation of ticket key setting
+ int (*ticket_key_cb)(SSL *ssl, uint8_t *name, uint8_t *iv,
+ EVP_CIPHER_CTX *ectx, HMAC_CTX *hctx, int enc) = nullptr;
+
+ // Server-only: psk_identity_hint is the default identity hint to send in
+ // PSK-based key exchanges.
+ bssl::UniquePtr<char> psk_identity_hint;
+
+ unsigned (*psk_client_callback)(SSL *ssl, const char *hint, char *identity,
+ unsigned max_identity_len, uint8_t *psk,
+ unsigned max_psk_len) = nullptr;
+ unsigned (*psk_server_callback)(SSL *ssl, const char *identity, uint8_t *psk,
+ unsigned max_psk_len) = nullptr;
+
+
+ // Next protocol negotiation information
+ // (for experimental NPN extension).
+
+ // For a server, this contains a callback function by which the set of
+ // advertised protocols can be provided.
+ int (*next_protos_advertised_cb)(SSL *ssl, const uint8_t **out,
+ unsigned *out_len, void *arg) = nullptr;
+ void *next_protos_advertised_cb_arg = nullptr;
+ // For a client, this contains a callback function that selects the
+ // next protocol from the list provided by the server.
+ int (*next_proto_select_cb)(SSL *ssl, uint8_t **out, uint8_t *out_len,
+ const uint8_t *in, unsigned in_len,
+ void *arg) = nullptr;
+ void *next_proto_select_cb_arg = nullptr;
+
+ // ALPN information
+ // (we are in the process of transitioning from NPN to ALPN.)
+
+ // For a server, this contains a callback function that allows the
+ // server to select the protocol for the connection.
+ // out: on successful return, this must point to the raw protocol
+ // name (without the length prefix).
+ // outlen: on successful return, this contains the length of |*out|.
+ // in: points to the client's list of supported protocols in
+ // wire-format.
+ // inlen: the length of |in|.
+ int (*alpn_select_cb)(SSL *ssl, const uint8_t **out, uint8_t *out_len,
+ const uint8_t *in, unsigned in_len,
+ void *arg) = nullptr;
+ void *alpn_select_cb_arg = nullptr;
+
+ // For a client, this contains the list of supported protocols in wire
+ // format.
+ bssl::Array<uint8_t> alpn_client_proto_list;
+
+ // SRTP profiles we are willing to do from RFC 5764
+ bssl::UniquePtr<STACK_OF(SRTP_PROTECTION_PROFILE)> srtp_profiles;
+
+ // Defined compression algorithms for certificates.
+ bssl::UniquePtr<STACK_OF(CertCompressionAlg)> cert_compression_algs;
+
+ // Supported group values inherited by SSL structure
+ bssl::Array<uint16_t> supported_group_list;
+
+ // The client's Channel ID private key.
+ bssl::UniquePtr<EVP_PKEY> channel_id_private;
+
+ // keylog_callback, if not NULL, is the key logging callback. See
+ // |SSL_CTX_set_keylog_callback|.
+ void (*keylog_callback)(const SSL *ssl, const char *line) = nullptr;
+
+ // current_time_cb, if not NULL, is the function to use to get the current
+ // time. It sets |*out_clock| to the current time. The |ssl| argument is
+ // always NULL. See |SSL_CTX_set_current_time_cb|.
+ void (*current_time_cb)(const SSL *ssl, struct timeval *out_clock) = nullptr;
+
+ // pool is used for all |CRYPTO_BUFFER|s in case we wish to share certificate
+ // memory.
+ CRYPTO_BUFFER_POOL *pool = nullptr;
+
+ // ticket_aead_method contains function pointers for opening and sealing
+ // session tickets.
+ const SSL_TICKET_AEAD_METHOD *ticket_aead_method = nullptr;
+
+ // legacy_ocsp_callback implements an OCSP-related callback for OpenSSL
+ // compatibility.
+ int (*legacy_ocsp_callback)(SSL *ssl, void *arg) = nullptr;
+ void *legacy_ocsp_callback_arg = nullptr;
+
+ // verify_sigalgs, if not empty, is the set of signature algorithms
+ // accepted from the peer in decreasing order of preference.
+ bssl::Array<uint16_t> verify_sigalgs;
+
+ // retain_only_sha256_of_client_certs is true if we should compute the SHA256
+ // hash of the peer's certificate and then discard it to save memory and
+ // session space. Only effective on the server side.
+ bool retain_only_sha256_of_client_certs:1;
+
+ // quiet_shutdown is true if the connection should not send a close_notify on
+ // shutdown.
+ bool quiet_shutdown:1;
+
+ // ocsp_stapling_enabled is only used by client connections and indicates
+ // whether OCSP stapling will be requested.
+ bool ocsp_stapling_enabled:1;
+
+ // If true, a client will request certificate timestamps.
+ bool signed_cert_timestamps_enabled:1;
+
+ // channel_id_enabled is whether Channel ID is enabled. For a server, means
+ // that we'll accept Channel IDs from clients. For a client, means that we'll
+ // advertise support.
+ bool channel_id_enabled:1;
+
+ // grease_enabled is whether draft-davidben-tls-grease-01 is enabled.
+ bool grease_enabled:1;
+
+ // allow_unknown_alpn_protos is whether the client allows unsolicited ALPN
+ // protocols from the peer.
+ bool allow_unknown_alpn_protos:1;
+
+ // ed25519_enabled is whether Ed25519 is advertised in the handshake.
+ bool ed25519_enabled:1;
+
+ // rsa_pss_rsae_certs_enabled is whether rsa_pss_rsae_* are supported by the
+ // certificate verifier.
+ bool rsa_pss_rsae_certs_enabled:1;
+
+ // false_start_allowed_without_alpn is whether False Start (if
+ // |SSL_MODE_ENABLE_FALSE_START| is enabled) is allowed without ALPN.
+ bool false_start_allowed_without_alpn:1;
+
+ // handoff indicates that a server should stop after receiving the
+ // ClientHello and pause the handshake in such a way that |SSL_get_error|
+ // returns |SSL_HANDOFF|.
+ bool handoff:1;
+
+ // If enable_early_data is true, early data can be sent and accepted.
+ bool enable_early_data : 1;
+
+ private:
+ ~ssl_ctx_st();
+ friend void SSL_CTX_free(SSL_CTX *);
+};
+
+struct ssl_st {
+ explicit ssl_st(SSL_CTX *ctx_arg);
+ ssl_st(const ssl_st &) = delete;
+ ssl_st &operator=(const ssl_st &) = delete;
+ ~ssl_st();
+
+ // method is the method table corresponding to the current protocol (DTLS or
+ // TLS).
+ const bssl::SSL_PROTOCOL_METHOD *method = nullptr;
+
+ // config is a container for handshake configuration. Accesses to this field
+ // should check for nullptr, since configuration may be shed after the
+ // handshake completes. (If you have the |SSL_HANDSHAKE| object at hand, use
+ // that instead, and skip the null check.)
+ bssl::UniquePtr<bssl::SSL_CONFIG> config;
+
+ // version is the protocol version.
+ uint16_t version = 0;
+
+ uint16_t max_send_fragment = 0;
+
+ // There are 2 BIO's even though they are normally both the same. This is so
+ // data can be read and written to different handlers
+
+ bssl::UniquePtr<BIO> rbio; // used by SSL_read
+ bssl::UniquePtr<BIO> wbio; // used by SSL_write
+
+ // do_handshake runs the handshake. On completion, it returns |ssl_hs_ok|.
+ // Otherwise, it returns a value corresponding to what operation is needed to
+ // progress.
+ bssl::ssl_hs_wait_t (*do_handshake)(bssl::SSL_HANDSHAKE *hs) = nullptr;
+
+ bssl::SSL3_STATE *s3 = nullptr; // TLS variables
+ bssl::DTLS1_STATE *d1 = nullptr; // DTLS variables
+
+ // callback that allows applications to peek at protocol messages
+ void (*msg_callback)(int write_p, int version, int content_type,
+ const void *buf, size_t len, SSL *ssl,
+ void *arg) = nullptr;
+ void *msg_callback_arg = nullptr;
+
+ // session info
+
+ // initial_timeout_duration_ms is the default DTLS timeout duration in
+ // milliseconds. It's used to initialize the timer any time it's restarted.
+ //
+ // RFC 6347 states that implementations SHOULD use an initial timer value of 1
+ // second.
+ unsigned initial_timeout_duration_ms = 1000;
+
+ // tls13_variant is the variant of TLS 1.3 we are using for this
+ // configuration.
+ tls13_variant_t tls13_variant = tls13_default;
+
+ // session is the configured session to be offered by the client. This session
+ // is immutable.
+ bssl::UniquePtr<SSL_SESSION> session;
+
+ void (*info_callback)(const SSL *ssl, int type, int value) = nullptr;
+
+ bssl::UniquePtr<SSL_CTX> ctx;
+
+ // session_ctx is the |SSL_CTX| used for the session cache and related
+ // settings.
+ bssl::UniquePtr<SSL_CTX> session_ctx;
+
+ // extra application data
+ CRYPTO_EX_DATA ex_data;
+
+ uint32_t options = 0; // protocol behaviour
+ uint32_t mode = 0; // API behaviour
+ uint32_t max_cert_list = 0;
+ bssl::UniquePtr<char> hostname;
+
+ // renegotiate_mode controls how peer renegotiation attempts are handled.
+ ssl_renegotiate_mode_t renegotiate_mode = ssl_renegotiate_never;
+
+ // server is true iff the this SSL* is the server half. Note: before the SSL*
+ // is initialized by either SSL_set_accept_state or SSL_set_connect_state,
+ // the side is not determined. In this state, server is always false.
+ bool server : 1;
+
+ // quiet_shutdown is true if the connection should not send a close_notify on
+ // shutdown.
+ bool quiet_shutdown : 1;
+
+ // did_dummy_pq_padding is only valid for a client. In that context, it is
+ // true iff the client observed the server echoing a dummy PQ padding
+ // extension.
+ bool did_dummy_pq_padding:1;
+
+ // If enable_early_data is true, early data can be sent and accepted.
+ bool enable_early_data : 1;
};
-// The following types back public C-exposed types which must live in the global
-// namespace. We use subclassing so the implementations may be C++ types with
-// methods and destructor without polluting the global namespace.
-struct ssl_ctx_st : public bssl::SSLContext {};
-struct ssl_st : public bssl::SSLConnection {};
+struct ssl_session_st {
+ explicit ssl_session_st(const bssl::SSL_X509_METHOD *method);
+ ssl_session_st(const ssl_session_st &) = delete;
+ ssl_session_st &operator=(const ssl_session_st &) = delete;
+
+ CRYPTO_refcount_t references = 1;
+ uint16_t ssl_version = 0; // what ssl version session info is being kept in here?
+
+ // group_id is the ID of the ECDH group used to establish this session or zero
+ // if not applicable or unknown.
+ uint16_t group_id = 0;
+
+ // peer_signature_algorithm is the signature algorithm used to authenticate
+ // the peer, or zero if not applicable or unknown.
+ uint16_t peer_signature_algorithm = 0;
+
+ // master_key, in TLS 1.2 and below, is the master secret associated with the
+ // session. In TLS 1.3 and up, it is the resumption secret.
+ int master_key_length = 0;
+ uint8_t master_key[SSL_MAX_MASTER_KEY_LENGTH] = {0};
+
+ // session_id - valid?
+ unsigned session_id_length = 0;
+ uint8_t session_id[SSL_MAX_SSL_SESSION_ID_LENGTH] = {0};
+ // this is used to determine whether the session is being reused in
+ // the appropriate context. It is up to the application to set this,
+ // via SSL_new
+ uint8_t sid_ctx_length = 0;
+ uint8_t sid_ctx[SSL_MAX_SID_CTX_LENGTH] = {0};
+
+ bssl::UniquePtr<char> psk_identity;
+
+ // certs contains the certificate chain from the peer, starting with the leaf
+ // certificate.
+ bssl::UniquePtr<STACK_OF(CRYPTO_BUFFER)> certs;
+
+ const bssl::SSL_X509_METHOD *x509_method = nullptr;
+
+ // x509_peer is the peer's certificate.
+ X509 *x509_peer = nullptr;
+
+ // x509_chain is the certificate chain sent by the peer. NOTE: for historical
+ // reasons, when a client (so the peer is a server), the chain includes
+ // |peer|, but when a server it does not.
+ STACK_OF(X509) *x509_chain = nullptr;
+
+ // x509_chain_without_leaf is a lazily constructed copy of |x509_chain| that
+ // omits the leaf certificate. This exists because OpenSSL, historically,
+ // didn't include the leaf certificate in the chain for a server, but did for
+ // a client. The |x509_chain| always includes it and, if an API call requires
+ // a chain without, it is stored here.
+ STACK_OF(X509) *x509_chain_without_leaf = nullptr;
+
+ // verify_result is the result of certificate verification in the case of
+ // non-fatal certificate errors.
+ long verify_result = X509_V_ERR_INVALID_CALL;
+
+ // timeout is the lifetime of the session in seconds, measured from |time|.
+ // This is renewable up to |auth_timeout|.
+ uint32_t timeout = SSL_DEFAULT_SESSION_TIMEOUT;
+
+ // auth_timeout is the non-renewable lifetime of the session in seconds,
+ // measured from |time|.
+ uint32_t auth_timeout = SSL_DEFAULT_SESSION_TIMEOUT;
+
+ // time is the time the session was issued, measured in seconds from the UNIX
+ // epoch.
+ uint64_t time = 0;
+
+ const SSL_CIPHER *cipher = nullptr;
+
+ CRYPTO_EX_DATA ex_data; // application specific data
+
+ // These are used to make removal of session-ids more efficient and to
+ // implement a maximum cache size.
+ SSL_SESSION *prev = nullptr, *next = nullptr;
+
+ bssl::Array<uint8_t> ticket;
+
+ bssl::UniquePtr<CRYPTO_BUFFER> signed_cert_timestamp_list;
+
+ // The OCSP response that came with the session.
+ bssl::UniquePtr<CRYPTO_BUFFER> ocsp_response;
+
+ // peer_sha256 contains the SHA-256 hash of the peer's certificate if
+ // |peer_sha256_valid| is true.
+ uint8_t peer_sha256[SHA256_DIGEST_LENGTH] = {0};
+
+ // original_handshake_hash contains the handshake hash (either SHA-1+MD5 or
+ // SHA-2, depending on TLS version) for the original, full handshake that
+ // created a session. This is used by Channel IDs during resumption.
+ uint8_t original_handshake_hash[EVP_MAX_MD_SIZE] = {0};
+ uint8_t original_handshake_hash_len = 0;
+
+ uint32_t ticket_lifetime_hint = 0; // Session lifetime hint in seconds
+
+ uint32_t ticket_age_add = 0;
+
+ // ticket_max_early_data is the maximum amount of data allowed to be sent as
+ // early data. If zero, 0-RTT is disallowed.
+ uint32_t ticket_max_early_data = 0;
+
+ // early_alpn is the ALPN protocol from the initial handshake. This is only
+ // stored for TLS 1.3 and above in order to enforce ALPN matching for 0-RTT
+ // resumptions.
+ bssl::Array<uint8_t> early_alpn;
+
+ // extended_master_secret is whether the master secret in this session was
+ // generated using EMS and thus isn't vulnerable to the Triple Handshake
+ // attack.
+ bool extended_master_secret:1;
+
+ // peer_sha256_valid is whether |peer_sha256| is valid.
+ bool peer_sha256_valid:1; // Non-zero if peer_sha256 is valid
+
+ // not_resumable is used to indicate that session resumption is disallowed.
+ bool not_resumable:1;
+
+ // ticket_age_add_valid is whether |ticket_age_add| is valid.
+ bool ticket_age_add_valid:1;
+
+ // is_server is whether this session was created by a server.
+ bool is_server:1;
+
+ private:
+ ~ssl_session_st();
+ friend void SSL_SESSION_free(SSL_SESSION *);
+};
#endif // OPENSSL_HEADER_SSL_INTERNAL_H