Latest update - GitHub 7c2524a
This commit is contained in:
@@ -1653,6 +1653,105 @@ ngx_ssl_dhparam(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *file)
|
||||
}
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ngx_ssl_ech_files(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_array_t *filenames)
|
||||
{
|
||||
#ifdef SSL_OP_ECH_GREASE
|
||||
int numkeys;
|
||||
BIO *in;
|
||||
ngx_int_t rc;
|
||||
ngx_str_t *filename;
|
||||
ngx_uint_t i;
|
||||
OSSL_ECHSTORE *es;
|
||||
|
||||
if (filenames == NULL) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
es = OSSL_ECHSTORE_new(NULL, NULL);
|
||||
if (es == NULL) {
|
||||
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, "OSSL_ECHSTORE_new() failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
rc = NGX_ERROR;
|
||||
filename = filenames->elts;
|
||||
|
||||
for (i = 0; i < filenames->nelts; i++) {
|
||||
|
||||
if (ngx_conf_full_name(cf->cycle, &filename[i], 1) != NGX_OK) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
in = BIO_new_file((char *) filename[i].data, "r");
|
||||
if (in == NULL) {
|
||||
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
|
||||
"BIO_new_file(\"%s\") failed", filename[i].data);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/*
|
||||
* We only set the ECHConfigList from the first file read to use
|
||||
* in ECH retry-configs.
|
||||
*
|
||||
* That allows many sensible key rotation schemes so that the
|
||||
* values sent in ECH retry-configs are smaller and current.
|
||||
* For example, if the first file name has the current ECH
|
||||
* private key, and a second one has the previously used key
|
||||
* that some clients may still use due to DNS caching.
|
||||
*/
|
||||
|
||||
if (OSSL_ECHSTORE_read_pem(es, in, i ? OSSL_ECH_NO_RETRY
|
||||
: OSSL_ECH_FOR_RETRY)
|
||||
!= 1)
|
||||
{
|
||||
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
|
||||
"OSSL_ECHSTORE_read_pem(%s) failed",
|
||||
filename[i].data);
|
||||
BIO_free(in);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
BIO_free(in);
|
||||
}
|
||||
|
||||
/*
|
||||
* load the ECH store after checking there's at least one ECH
|
||||
* private key in there (the PEM file spec allows zero or one
|
||||
* private key per file)
|
||||
*/
|
||||
|
||||
if (OSSL_ECHSTORE_num_keys(es, &numkeys) != 1) {
|
||||
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
|
||||
"OSSL_ECHSTORE_num_keys(%s) failed");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (numkeys > 0 && SSL_CTX_set1_echstore(ssl->ctx, es) != 1) {
|
||||
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
|
||||
"SSL_CTX_set1_echstore() failed");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
rc = NGX_OK;
|
||||
|
||||
cleanup:
|
||||
|
||||
OSSL_ECHSTORE_free(es);
|
||||
return rc;
|
||||
|
||||
#else
|
||||
if (filenames != NULL) {
|
||||
ngx_log_error(NGX_LOG_WARN, ssl->log, 0,
|
||||
"\"ssl_ech_file\" is not supported on this platform, "
|
||||
"ignored");
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ngx_ssl_ecdh_curve(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *name)
|
||||
{
|
||||
@@ -1872,21 +1971,34 @@ ngx_ssl_new_client_session(ngx_ssl_conn_t *ssl_conn, ngx_ssl_session_t *sess)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ngx_ssl_set_client_hello_callback(SSL_CTX *ssl_ctx,
|
||||
ngx_ssl_client_hello_arg *cb)
|
||||
ngx_int_t
|
||||
ngx_ssl_set_client_hello_callback(ngx_ssl_t *ssl, ngx_ssl_client_hello_arg *cb)
|
||||
{
|
||||
#ifdef SSL_CLIENT_HELLO_SUCCESS
|
||||
|
||||
SSL_CTX_set_client_hello_cb(ssl_ctx, ngx_ssl_client_hello_callback, NULL);
|
||||
SSL_CTX_set_ex_data(ssl_ctx, ngx_ssl_client_hello_arg_index, cb);
|
||||
SSL_CTX_set_client_hello_cb(ssl->ctx, ngx_ssl_client_hello_callback, NULL);
|
||||
|
||||
if (SSL_CTX_set_ex_data(ssl->ctx, ngx_ssl_client_hello_arg_index, cb) == 0)
|
||||
{
|
||||
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
|
||||
"SSL_CTX_set_ex_data() failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
#elif defined OPENSSL_IS_BORINGSSL
|
||||
|
||||
SSL_CTX_set_select_certificate_cb(ssl_ctx, ngx_ssl_select_certificate);
|
||||
SSL_CTX_set_ex_data(ssl_ctx, ngx_ssl_client_hello_arg_index, cb);
|
||||
SSL_CTX_set_select_certificate_cb(ssl->ctx, ngx_ssl_select_certificate);
|
||||
|
||||
if (SSL_CTX_set_ex_data(ssl->ctx, ngx_ssl_client_hello_arg_index, cb) == 0)
|
||||
{
|
||||
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
|
||||
"SSL_CTX_set_ex_data() failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -5734,6 +5846,81 @@ ngx_ssl_get_alpn_protocol(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
|
||||
}
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ngx_ssl_get_ech_status(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
|
||||
{
|
||||
#ifdef SSL_OP_ECH_GREASE
|
||||
int echrv;
|
||||
char *inner_sni, *outer_sni;
|
||||
|
||||
inner_sni = NULL;
|
||||
outer_sni = NULL;
|
||||
|
||||
echrv = SSL_ech_get1_status(c->ssl->connection, &inner_sni, &outer_sni);
|
||||
|
||||
switch (echrv) {
|
||||
case SSL_ECH_STATUS_NOT_TRIED:
|
||||
ngx_str_set(s, "NOT_TRIED");
|
||||
break;
|
||||
case SSL_ECH_STATUS_SUCCESS:
|
||||
ngx_str_set(s, "SUCCESS");
|
||||
break;
|
||||
case SSL_ECH_STATUS_GREASE:
|
||||
ngx_str_set(s, "GREASE");
|
||||
break;
|
||||
case SSL_ECH_STATUS_BACKEND:
|
||||
ngx_str_set(s, "BACKEND");
|
||||
break;
|
||||
default:
|
||||
ngx_str_set(s, "FAILED");
|
||||
break;
|
||||
}
|
||||
|
||||
OPENSSL_free(inner_sni);
|
||||
OPENSSL_free(outer_sni);
|
||||
#else
|
||||
s->len = 0;
|
||||
#endif
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ngx_ssl_get_ech_outer_server_name(ngx_connection_t *c, ngx_pool_t *pool,
|
||||
ngx_str_t *s)
|
||||
{
|
||||
#if defined(SSL_OP_ECH_GREASE)
|
||||
int echrv;
|
||||
char *inner_sni, *outer_sni;
|
||||
|
||||
inner_sni = NULL;
|
||||
outer_sni = NULL;
|
||||
|
||||
echrv = SSL_ech_get1_status(c->ssl->connection, &inner_sni, &outer_sni);
|
||||
|
||||
if (echrv == SSL_ECH_STATUS_SUCCESS && outer_sni) {
|
||||
s->len = ngx_strlen(outer_sni);
|
||||
|
||||
s->data = ngx_pnalloc(pool, s->len);
|
||||
if (s->data == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ngx_memcpy(s->data, outer_sni, s->len);
|
||||
|
||||
} else {
|
||||
s->len = 0;
|
||||
}
|
||||
|
||||
OPENSSL_free(inner_sni);
|
||||
OPENSSL_free(outer_sni);
|
||||
#else
|
||||
s->len = 0;
|
||||
#endif
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ngx_ssl_get_raw_certificate(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
|
||||
{
|
||||
|
||||
@@ -285,6 +285,8 @@ ngx_array_t *ngx_ssl_read_password_file(ngx_conf_t *cf, ngx_str_t *file);
|
||||
ngx_array_t *ngx_ssl_preserve_passwords(ngx_conf_t *cf,
|
||||
ngx_array_t *passwords);
|
||||
ngx_int_t ngx_ssl_dhparam(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *file);
|
||||
ngx_int_t ngx_ssl_ech_files(ngx_conf_t *cf, ngx_ssl_t *ssl,
|
||||
ngx_array_t *filename);
|
||||
ngx_int_t ngx_ssl_ecdh_curve(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *name);
|
||||
ngx_int_t ngx_ssl_early_data(ngx_conf_t *cf, ngx_ssl_t *ssl,
|
||||
ngx_uint_t enable);
|
||||
@@ -300,7 +302,7 @@ ngx_int_t ngx_ssl_session_ticket_keys(ngx_conf_t *cf, ngx_ssl_t *ssl,
|
||||
ngx_array_t *paths);
|
||||
ngx_int_t ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data);
|
||||
|
||||
void ngx_ssl_set_client_hello_callback(SSL_CTX *ssl_ctx,
|
||||
ngx_int_t ngx_ssl_set_client_hello_callback(ngx_ssl_t *ssl,
|
||||
ngx_ssl_client_hello_arg *cb);
|
||||
#ifdef SSL_CLIENT_HELLO_SUCCESS
|
||||
int ngx_ssl_client_hello_callback(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg);
|
||||
@@ -352,6 +354,10 @@ ngx_int_t ngx_ssl_get_early_data(ngx_connection_t *c, ngx_pool_t *pool,
|
||||
ngx_str_t *s);
|
||||
ngx_int_t ngx_ssl_get_server_name(ngx_connection_t *c, ngx_pool_t *pool,
|
||||
ngx_str_t *s);
|
||||
ngx_int_t ngx_ssl_get_ech_status(ngx_connection_t *c, ngx_pool_t *pool,
|
||||
ngx_str_t *s);
|
||||
ngx_int_t ngx_ssl_get_ech_outer_server_name(ngx_connection_t *c,
|
||||
ngx_pool_t *pool, ngx_str_t *s);
|
||||
ngx_int_t ngx_ssl_get_alpn_protocol(ngx_connection_t *c, ngx_pool_t *pool,
|
||||
ngx_str_t *s);
|
||||
ngx_int_t ngx_ssl_get_raw_certificate(ngx_connection_t *c, ngx_pool_t *pool,
|
||||
|
||||
@@ -185,7 +185,13 @@ ngx_quic_cbs_release_rcd(ngx_ssl_conn_t *ssl_conn, size_t bytes_read, void *arg)
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||
"quic ngx_quic_cbs_release_rcd len:%uz", bytes_read);
|
||||
|
||||
/* already closed on handshake failure */
|
||||
|
||||
qc = ngx_quic_get_connection(c);
|
||||
if (qc == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
ctx = ngx_quic_get_send_ctx(qc, qc->read_level);
|
||||
|
||||
cl = ngx_quic_read_buffer(c, &ctx->crypto, bytes_read);
|
||||
|
||||
Reference in New Issue
Block a user