aboutsummaryrefslogtreecommitdiff
path: root/src/event/quic/ngx_event_quic_openssl_compat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/event/quic/ngx_event_quic_openssl_compat.c')
-rw-r--r--src/event/quic/ngx_event_quic_openssl_compat.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/event/quic/ngx_event_quic_openssl_compat.c b/src/event/quic/ngx_event_quic_openssl_compat.c
index 75981338b..a6121f5a6 100644
--- a/src/event/quic/ngx_event_quic_openssl_compat.c
+++ b/src/event/quic/ngx_event_quic_openssl_compat.c
@@ -54,9 +54,10 @@ struct ngx_quic_compat_s {
static void ngx_quic_compat_keylog_callback(const SSL *ssl, const char *line);
-static ngx_int_t ngx_quic_compat_set_encryption_secret(ngx_log_t *log,
+static ngx_int_t ngx_quic_compat_set_encryption_secret(ngx_connection_t *c,
ngx_quic_compat_keys_t *keys, enum ssl_encryption_level_t level,
const SSL_CIPHER *cipher, const uint8_t *secret, size_t secret_len);
+static void ngx_quic_compat_cleanup_encryption_secret(void *data);
static int ngx_quic_compat_add_transport_params_callback(SSL *ssl,
unsigned int ext_type, unsigned int context, const unsigned char **out,
size_t *outlen, X509 *x, size_t chainidx, int *al, void *add_arg);
@@ -214,14 +215,14 @@ ngx_quic_compat_keylog_callback(const SSL *ssl, const char *line)
com->method->set_read_secret((SSL *) ssl, level, cipher, secret, n);
com->read_record = 0;
- (void) ngx_quic_compat_set_encryption_secret(c->log, &com->keys, level,
+ (void) ngx_quic_compat_set_encryption_secret(c, &com->keys, level,
cipher, secret, n);
}
}
static ngx_int_t
-ngx_quic_compat_set_encryption_secret(ngx_log_t *log,
+ngx_quic_compat_set_encryption_secret(ngx_connection_t *c,
ngx_quic_compat_keys_t *keys, enum ssl_encryption_level_t level,
const SSL_CIPHER *cipher, const uint8_t *secret, size_t secret_len)
{
@@ -231,6 +232,7 @@ ngx_quic_compat_set_encryption_secret(ngx_log_t *log,
ngx_quic_hkdf_t seq[2];
ngx_quic_secret_t *peer_secret;
ngx_quic_ciphers_t ciphers;
+ ngx_pool_cleanup_t *cln;
peer_secret = &keys->secret;
@@ -239,12 +241,12 @@ ngx_quic_compat_set_encryption_secret(ngx_log_t *log,
key_len = ngx_quic_ciphers(keys->cipher, &ciphers, level);
if (key_len == NGX_ERROR) {
- ngx_ssl_error(NGX_LOG_INFO, log, 0, "unexpected cipher");
+ ngx_ssl_error(NGX_LOG_INFO, c->log, 0, "unexpected cipher");
return NGX_ERROR;
}
if (sizeof(peer_secret->secret.data) < secret_len) {
- ngx_log_error(NGX_LOG_ALERT, log, 0,
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
"unexpected secret len: %uz", secret_len);
return NGX_ERROR;
}
@@ -262,15 +264,43 @@ ngx_quic_compat_set_encryption_secret(ngx_log_t *log,
ngx_quic_hkdf_set(&seq[1], "tls13 iv", &peer_secret->iv, &secret_str);
for (i = 0; i < (sizeof(seq) / sizeof(seq[0])); i++) {
- if (ngx_quic_hkdf_expand(&seq[i], ciphers.d, log) != NGX_OK) {
+ if (ngx_quic_hkdf_expand(&seq[i], ciphers.d, c->log) != NGX_OK) {
return NGX_ERROR;
}
}
+ /* register cleanup handler once */
+
+ if (peer_secret->ctx) {
+ ngx_quic_crypto_cleanup(peer_secret);
+
+ } else {
+ cln = ngx_pool_cleanup_add(c->pool, 0);
+ if (cln == NULL) {
+ return NGX_ERROR;
+ }
+
+ cln->handler = ngx_quic_compat_cleanup_encryption_secret;
+ cln->data = peer_secret;
+ }
+
+ if (ngx_quic_crypto_init(ciphers.c, peer_secret, 1, c->log) == NGX_ERROR) {
+ return NGX_ERROR;
+ }
+
return NGX_OK;
}
+static void
+ngx_quic_compat_cleanup_encryption_secret(void *data)
+{
+ ngx_quic_secret_t *secret = data;
+
+ ngx_quic_crypto_cleanup(secret);
+}
+
+
static int
ngx_quic_compat_add_transport_params_callback(SSL *ssl, unsigned int ext_type,
unsigned int context, const unsigned char **out, size_t *outlen, X509 *x,
@@ -578,8 +608,7 @@ ngx_quic_compat_create_record(ngx_quic_compat_record_t *rec, ngx_str_t *res)
ngx_memcpy(nonce, secret->iv.data, secret->iv.len);
ngx_quic_compute_nonce(nonce, sizeof(nonce), rec->number);
- if (ngx_quic_crypto_seal(ciphers.c, secret, &out,
- nonce, &rec->payload, &ad, rec->log)
+ if (ngx_quic_crypto_seal(secret, &out, nonce, &rec->payload, &ad, rec->log)
!= NGX_OK)
{
return NGX_ERROR;