=pod =head1 NAME SSL_set1_echstore, OSSL_ECHSTORE_new, OSSL_ECHSTORE_free, OSSL_ECHSTORE_new_config, OSSL_ECHSTORE_write_pem, OSSL_ECHSTORE_read_echconfiglist, OSSL_ECHSTORE_get1_info, OSSL_ECHSTORE_downselect, OSSL_ECHSTORE_set1_key_and_read_pem, OSSL_ECHSTORE_read_pem, OSSL_ECHSTORE_num_entries, OSSL_ECHSTORE_num_keys, OSSL_ECHSTORE_flush_keys, SSL_CTX_set1_echstore, SSL_CTX_get1_echstore, SSL_get1_echstore, SSL_ech_set1_server_names, SSL_ech_set1_outer_server_name, SSL_ech_set1_outer_alpn_protos, SSL_ech_get1_status, SSL_ech_set1_grease_suite, SSL_ech_set_grease_type, SSL_ech_set_callback, SSL_ech_get1_retry_config, SSL_CTX_ech_set1_outer_alpn_protos, SSL_CTX_ech_set_callback,SSL_set1_ech_config_list - Encrypted Client Hello (ECH) functions =head1 SYNOPSIS #include OSSL_ECHSTORE *OSSL_ECHSTORE_new(OSSL_LIB_CTX *libctx, const char *propq); void OSSL_ECHSTORE_free(OSSL_ECHSTORE *es); int OSSL_ECHSTORE_new_config(OSSL_ECHSTORE *es, uint16_t echversion, uint16_t max_name_length, const char *public_name, OSSL_HPKE_SUITE suite); int OSSL_ECHSTORE_write_pem(OSSL_ECHSTORE *es, int index, BIO *out); int OSSL_ECHSTORE_read_echconfiglist(OSSL_ECHSTORE *es, BIO *in); int OSSL_ECHSTORE_get1_info(OSSL_ECHSTORE *es, int index, time_t *loaded_secs, char **public_name, char **echconfig, int *has_private, int *for_retry); int OSSL_ECHSTORE_downselect(OSSL_ECHSTORE *es, int index); int OSSL_ECHSTORE_set1_key_and_read_pem(OSSL_ECHSTORE *es, EVP_PKEY *priv, BIO *in, int for_retry); int OSSL_ECHSTORE_read_pem(OSSL_ECHSTORE *es, BIO *in, int for_retry); int OSSL_ECHSTORE_num_entries(OSSL_ECHSTORE *es, int *numentries); int OSSL_ECHSTORE_num_keys(OSSL_ECHSTORE *es, int *numkeys); int OSSL_ECHSTORE_flush_keys(OSSL_ECHSTORE *es, time_t age); int SSL_CTX_set1_echstore(SSL_CTX *ctx, OSSL_ECHSTORE *es); int SSL_set1_echstore(SSL *s, OSSL_ECHSTORE *es); OSSL_ECHSTORE *SSL_CTX_get1_echstore(const SSL_CTX *ctx); OSSL_ECHSTORE *SSL_get1_echstore(const SSL *s); int SSL_ech_set1_server_names(SSL *s, const char *inner_name, const char *outer_name, int no_outer); int SSL_ech_set1_outer_server_name(SSL *s, const char *outer_name, int no_outer); int SSL_ech_set1_outer_alpn_protos(SSL *s, const unsigned char *protos, const size_t protos_len); int SSL_ech_get1_status(SSL *s, char **inner_sni, char **outer_sni); int SSL_ech_set1_grease_suite(SSL *s, const char *suite); int SSL_ech_set_grease_type(SSL *s, uint16_t type); void SSL_ech_set_callback(SSL *s, SSL_ech_cb_func f); int SSL_ech_get1_retry_config(SSL *s, unsigned char **ec, size_t *eclen); void SSL_CTX_ech_set_callback(SSL_CTX *ctx, SSL_ech_cb_func f); int SSL_CTX_ech_set1_outer_alpn_protos(SSL_CTX *ctx, const unsigned char *protos, const size_t protos_len); int SSL_set1_ech_config_list(SSL *ssl, const uint8_t *ecl, size_t ecl_len); =head1 DESCRIPTION The Encrypted Client Hello (ECH) APIs described here are built around the concept of an B which contains ECH configuration information relevant for an B or B connection. This release only supports ECH shared-mode and has no support for ECH split-mode. =head2 OSSL_ECHSTORE APIs The externally opaque type B allows applications to create and manage ECHConfigList values, ECH private keys and associated meta-data. The external APIs using B are: OSSL_ECHSTORE_new() and OSSL_ECHSTORE_free() create and free the internal storage required. OSSL_ECHSTORE_new_config() allows the caller to create a new private key value and a related "singleton" ECHConfigList structure. ("Singleton" meaning the ECHConfigList only contains one public key.) The I is the ECHConfig version to use, which is typically B with a value of 0xfe0d. The I specifies the maximum known DNS name length that will be present in an ECH extension (if known) and is used for ECH padding but should typically be zero, to indicate no known maximum. The I is the DNS name to use in the ECHConfig I field, and the I specifies the B to use (see L for details.) OSSL_ECHSTORE_write_pem() allows the caller to produce an ECH PEM data structure (conforming to the ECH PEM file format) from the B entry identified by the I. (An I of B will select the last entry. An I of B will output all public values, and no private values, otherwise the I selects a specific entry with zero selecting the first entry.) The output will be written to the I B. The B APIs above will typically be used via the "openssl ech" command line tool. OSSL_ECHSTORE_read_echconfiglist() reads from the I B and parses a base64-encoded ECHConfigList value normally found in the "ech=" SvcParamKey present in an SVCB or HTTPS RR retrieved from the DNS. The resulting set of ECHConfig values, are associated with the I store, and can then be associated with an B or B structure for TLS client connections. Input B values (such a I above) must not use unterminated B's. OSSL_ECHSTORE_get1_info() queries the store provided by I and finds the entry within the store specified by I. The number of seconds since that entry was first generated or loaded/decoded is stored in I, and the related public name is stored in I<*public_name>. This function also outputs a string useful for logging or display (as described in the L section) and stores that in I<*echconfig>. It is the callers responsibility to free the strings returned in I and I after they have been returned. If the specified entry has a private key associated with it then I will be set to 1, otherwise it will be set to 0. Similarly if the ECHConfig for this entry will be included in "retry-configs" then the I will be set to 1 or zero if that ECHConfig will not be included in retry-configs. The ECH fallback scheme involving retry-configs is described in Section 6.1.1 of RFC 9849. OSSL_ECHSTORE_downselect() provides the caller a way to select one particular ECHConfig value based on the zero-based I from those stored in the I, discarding the rest. This can be used by a client (via L and L or equivalent) to pick a specific ECHConfig to use in a TLS connection. OSSL_ECHSTORE_set1_key_and_read_pem() and OSSL_ECHSTORE_read_pem() can be used to load a private key value and associated ECHConfigList from the B I into an B structure. The former function pairs a previously-loaded private key (in B format) with an associated base64-encoded ECHConfigList in the I B. The latter function reads both from an ECH PEM file. Those can be used (by servers) to enable ECH for an B or B connection. In addition to loading those values, the application can also indicate via I which ECHConfig values are to be included in the I fallback scheme defined by the ECH protocol. An ECH PEM file may contain a private key and an ECHConfigList with more than one ECHConfig, for example if different public keys, I values, or AEAD/KDF settings are to be supported. When such a file is read, the resulting B will contain one entry for each ECHConfig in the ECHConfigList, so will be presented to applications as a set of "singleton" ECHConfig values, with the private key associated with each matching public key value. OSSL_ECHSTORE_num_entries() and OSSL_ECHSTORE_num_keys() allow an application to see how many ECH configs (in I) and private keys (in I) are present in the I B store. OSSL_ECHSTORE_flush_keys() allows a server to flush keys from I that were loaded more than I seconds ago. The general model is that a server can maintain an B into which it periodically loads the "latest" set of keys, e.g. hourly, and also discards the keys that are too old, e.g. more than 3 hours old. This allows for more robust private key management even if public key distribution suffers temporary failures. SSL_CTX_set1_echstore() and SSL_set1_echstore() allow clients and servers to associate I (an B) with an B or B structure. ECH will be enabled for the relevant B or B connection when these functions succeed. Any previously associated B will be freed via OSSL_ECHSTORE_free(). Internally, B values within an B or B connection are deep-copied, and are not refcounted. SSL_CTX_get1_echstore() and SSL_get1_echstore() provide access to the B associated with an B or B connection. The returned B can be modified and then re-associated with an B or B connection. =head2 Client ECH Controls SSL_set1_ech_config_list() allows clients to setup ECH by associating an ECHConfigList, I with an B connection I. This is compatible with current BoringSSL APIs, allowing for smaller code changes for clients that support OpenSSL or BoringSSL. Note that the input I here for OpenSSL can be either base64 or binary encoded, but for BoringSSL it must be binary encoded. SSL_ech_set1_server_names() and SSL_ech_set1_outer_server_name() allow clients to more directly control the values to be used for inner and outer Server Name Indication (SNI) values for an B connection, I. The I provided will be used as with L to populate the SNI value for the inner ClientHello. The I, if non-NULL, can over-ride the public_name field of the ECHConfig used for the connection. The I input allows a client to emit an outer ClientHello with no SNI at all. Providing a NULL for the I means to send the I provided from the ECHConfigList unless the I provided has the value 1. If a client has called L or L then the ALPN value will be the same in the inner and outer ClientHello messages. SSL_ech_set1_outer_alpn_protos() and SSL_CTX_ech_set1_outer_alpn_protos() allow clients to set a specific value for the ALPN sent in the outer ClientHello of the B connection, I. The I and I inputs must be provided as for L. If a client attempts ECH but that fails, or sends an ECH-GREASE'd ClientHello, to an ECH-supporting server, then that server may return a set of ECH retry-config values that the client could choose to use in a subsequent connection. The client can detect this situation if SSL_ech_get1_status() for the B connection I, returns a status of B, and can then access the ECH retry config values via SSL_ech_get1_retry_config() where the I value returned will contain a binary-encoded ECHConfigList of length I. If a client makes a real attempt at ECH that fails then the server can also return retry config values, and those can be used if they were authenticated under the outer SNI used for the session. In this case the TLS session fails returning the error B, and the ECH status of B indicates that retry config values can be accessed using SSL_ech_get1_retry_config(). The application can then choose to use those in a subsequent attempt to establish a TLS session with the server. If the TLS session fails for some other reason (e.g. a bad server Finished message), then the retry config values will not be returned to the application. "GREASEing" (defined in RFC8701) is a mechanism intended to discourage protocol ossification that can be used for ECH. SSL_ech_set1_grease_suite() allows a client to GREASE ECH for the B connection I, using a specific B as the value for I (see L). SSL_ech_set_grease_type() allows a client to add a GREASE'd ECH for the B connection I, using the specified ClientHello extension number I. Clients and servers can query the status of ECH for a B connection I, using the SSL_ech_get1_status() function. As SNI handling is core to ECH this will also return the I and I values to be used or that were used as well as a status code as the return value. These name values must be freed by the caller. The various status values returned by this function are as described in L. =head2 Callback Functions Applications can set a callback function that will be called when the outcome from an attempt at ECH has been determined. On the server, that happens early, as part of construction of the ServerHello message. On the client, the callback will happen after the SeverHello has been processed. In the event of HelloRetryRequest, the callback will only be triggered when processing the second ServerHello. The callback function will be triggered even if the client is only GREASEing. The callback function prototype is: typedef unsigned int (*SSL_ech_cb_func)(SSL *s, const char *str); To set a callback function for the B connection I, use SSL_ech_set_callback() or SSL_CTX_ech_set_callback() for a B I - the I input should match the above prototype. When the callback function is called, the I will point at a string intended for logging describing the state of ECH processing. Applications should not attempt to parse that string as the value depends on compile time settings, local configuration and the specific processing that happened prior to the callback. Applications that need to branch based on the outcome of ECH processing should instead make a call to SSL_ech_get1_status() from within their callback function. An example string I as seen on a client might be: ech_attempted=1 ech_attempted_type=0xfe0d ech_atttempted_cid=0x5d ech_done=1 ech_grease=0 ech_returned_len=0 ech_backend=0 ech_success=1 2 ECHConfig values loaded cfg(0): [fe0d,5d,cover.defo.ie,[0020,0001,0001],190984309c1a24cb944c005eb79d9c72ca9a4a979194b553dfd0bffc6b5c152d,00,00] cfg(1): [fe0d,fd,cover.defo.ie,[0020,0001,0001],46dd4e2c81bb15ef9d194c99b86983844e2a1387e4fb7e7d3b8d368c8e1b4d2a,00,00] =head2 Constants Some externally visible limits: =over 4 =item B 1500, maximum length of an ECH ciphertext to en/decode =item B 32, minimum length of an encoded ECHConfig =item B 1500, maximum length of an encoded ECHConfig =item B 512, maximum length of an ECHConfig extension =item B 255, maximum for ECHConfig max name length =item B 255, maximum length of an ECHConfig public name =item B 255, maximum overall length of an ALPN =item B 20, maximum number of extensions compressed via outer-exts =item B 32, maximum total number of extensions allowed =back ECH version - the only supported version is 0xfe0d currently. =over 4 =item B 0xfe0d, official ECHConfig version =item B OSSL_ECH_RFC9849_VERSION =back Values for I =over 4 =item B 1. use corresponding ECHConfig values =item B 0. don't use corresponding ECHConfig values =back Indexing an OSSL_ECHSTORE =over 4 =item B, -1 select the last entry in the store =item B, -2 select all entries in the store, e.g. to print public values =back =head2 String form of ECHConfig OSSL_ECHSTORE_get1_info() returns the string form of the ECH public name plus a string describing the content of the ECHConfig for example: [fe0d,4d,example.com,[0020,0001,0002],c103d20dddce9b4445829bf01f5b533b728bfa0ebe3a97da33574bc096bb846e,00,00] In the order presented in the example above, the I is 0xfe0d, the I is 0x4d, the I is "example.com", there is one ciphersuite with a I of 0x20, I is 0x01 and I is 0x02; the I is the hexadecimal string "c1...6e", the I is 0x00 and the I length is 0x00 as no ECHConfig extensions are present. =head1 RETURN VALUES SSL_set1_echstore(), SSL_set1_ech_config_list(), OSSL_ECHSTORE_new_config(), OSSL_ECHSTORE_write_pem(), OSSL_ECHSTORE_read_echconfiglist(), OSSL_ECHSTORE_get1_info(), OSSL_ECHSTORE_downselect(), OSSL_ECHSTORE_set1_key_and_read_pem(), OSSL_ECHSTORE_read_pem(), OSSL_ECHSTORE_num_keys(), OSSL_ECHSTORE_num_entries(), OSSL_ECHSTORE_flush_keys(), SSL_CTX_set1_echstore(), SSL_ech_set_server_names(), SSL_ech_set_outer_server_name(), SSL_ech_set_outer_alpn_protos(), SSL_ech_set_grease_suite(), SSL_ech_set_grease_type(), SSL_ech_get_retry_config() and SSL_CTX_ech_set1_outer_alpn_protos() all return zero on error and one on success. SSL_ech_get1_status() returns one of the following values: =over 4 =item B 4, ECH backend: saw an ech_is_inner =item B 3, GREASEd and got an ECH in return =item B 2, ECH GREASE happened =item B 1, Success =item B 0, Some internal or protocol error =item B -100, Some in/out arguments were NULL =item B -101, ECH wasn't attempted =item B -102, ECH ok but server or client cert bad =item B -103, ECH wasn't configured =item B -105, We tried, failed and got an ECH, from a verified name =item B -106, We tried, failed and got an ECH, from a bad name =back SSL_ech_set_callback(), SSL_CTX_ech_set_callback(), OSSL_ECHSTORE_free() have no return value. SSL_CTX_get1_echstore(), SSL_get1_echstore() and OSSL_ECHSTORE_new() return a pointer to an B. Note that SSL_CTX_ech_set1_outer_alpn_protos() and SSL_ech_set1_outer_alpn_protos() return zero on error and 1 on success. This is in contrast to L and L which (unusually for OpenSSL) return 0 on success and 1 on error. =head1 SEE ALSO =over 4 =item Encrypted ClientHello specification: L =item ECH PEM file format specification: L =item RFC8701: L =back ECH command line options are described in the manual pages for L, L and L. =head1 HISTORY The functionality described here was added in OpenSSL 4.0. =head1 COPYRIGHT Copyright 2025-2026 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut