#include <openssl/ssl.h>
#include <openssl/ech.h>
-#include "../ssl_local.h"
-#include "ech_local.h"
#include <openssl/rand.h>
-#include "../statem/statem_local.h"
-#include "internal/ech_helpers.h"
#include <openssl/kdf.h>
+#include "internal/ech_helpers.h"
+#include "internal/ssl_unwrap.h"
+#include "../ssl_local.h"
+#include "../statem/statem_local.h"
+#include "ech_local.h"
#ifndef OPENSSL_NO_ECH
size_t cipher_len = 0, cipher_len_jitter = 0;
unsigned char cid, senderpub[OSSL_ECH_MAX_GREASE_PUB];
unsigned char cipher[OSSL_ECH_MAX_GREASE_CT];
+ SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
- if (s == NULL)
- return 0;
- if (s->ssl.ctx == NULL) {
- SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
- return 0;
- }
WPACKET_get_total_written(pkt, &pp_at_start);
/* randomly select cipher_len to be one of 144, 176, 208, 244 */
- if (RAND_bytes_ex(s->ssl.ctx->libctx, &cid, 1, 0) <= 0) {
+ if (RAND_bytes_ex(sctx->libctx, &cid, 1, 0) <= 0) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return 0;
}
cipher_len = 144;
cipher_len += 32 * cipher_len_jitter;
/* generate a random (1 octet) client id */
- if (RAND_bytes_ex(s->ssl.ctx->libctx, &cid, 1, 0) <= 0) {
+ if (RAND_bytes_ex(sctx->libctx, &cid, 1, 0) <= 0) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return 0;
}
if (OSSL_HPKE_get_grease_value(hpke_suite_in_p, &hpke_suite,
senderpub, &senderpub_len,
cipher, cipher_len,
- s->ssl.ctx->libctx, NULL) != 1) {
+ sctx->libctx, sctx->propq) != 1) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return 0;
}
+ SSL3_RANDOM_SIZE - OSSL_ECH_SIGNAL_LEN;
unsigned int hashlen = 0;
unsigned char hashval[EVP_MAX_MD_SIZE];
+ SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
if ((md = (EVP_MD *)ssl_handshake_md(s)) == NULL) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_ECH_REQUIRED);
} else {
if (s->ext.ech.hrrsignal_p == NULL) {
/* No ECH found so we'll exit, but set random output */
- if (RAND_bytes_ex(s->ssl.ctx->libctx, acbuf,
+ if (RAND_bytes_ex(sctx->libctx, acbuf,
OSSL_ECH_SIGNAL_LEN, 0) <= 0) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_ECH_REQUIRED);
goto end;
size_t info_len = OSSL_ECH_MAX_INFO_LEN;
int rv = 0;
OSSL_HPKE_CTX *hctx = NULL;
+ SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
# ifdef OSSL_ECH_SUPERVERBOSE
size_t publen = 0;
unsigned char *pub = NULL;
ERR_set_mark();
/* Use OSSL_HPKE_* APIs */
hctx = OSSL_HPKE_CTX_new(hpke_mode, hpke_suite, OSSL_HPKE_ROLE_RECEIVER,
- NULL, NULL);
+ sctx->libctx, sctx->propq);
if (hctx == NULL)
goto clearerrs;
rv = OSSL_HPKE_decap(hctx, senderpub, senderpublen, ee->keyshare,
return EXT_RETURN_FAIL;
}
/* for outer CH allocate a similar sized random value */
- if (RAND_bytes_ex(s->ssl.ctx->libctx, rndbuf, totalrndsize, 0) <= 0) {
+ if (RAND_bytes_ex(sctx->libctx, rndbuf, totalrndsize, 0) <= 0) {
OPENSSL_free(rndbuf);
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return EXT_RETURN_FAIL;
size_t chainidx)
{
int rv = 0, hpke_mode = OSSL_HPKE_MODE_BASE;
+ SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
OSSL_ECHSTORE_ENTRY *ee = NULL;
OSSL_HPKE_SUITE hpke_suite = OSSL_HPKE_SUITE_DEFAULT;
unsigned char config_id_to_use = 0x00, info[OSSL_ECH_MAX_INFO_LEN];
} OSSL_TRACE_END(TLS);
config_id_to_use = ee->config_id; /* if requested, use a random config_id instead */
if ((s->options & SSL_OP_ECH_IGNORE_CID) != 0) {
- if (RAND_bytes_ex(s->ssl.ctx->libctx, &config_id_to_use, 1, 0) <= 0) {
+ if (RAND_bytes_ex(sctx->libctx, &config_id_to_use, 1, 0) <= 0) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return 0;
}
# endif
s->ext.ech.hpke_ctx = OSSL_HPKE_CTX_new(hpke_mode, hpke_suite,
OSSL_HPKE_ROLE_SENDER,
- NULL, NULL);
+ sctx->libctx, sctx->propq);
if (s->ext.ech.hpke_ctx == NULL) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
goto err;
BUF_MEM *inner_mem = NULL;
PACKET rpkt; /* we'll decode back the inner ch to help make the outer */
SSL_SESSION *sess = NULL;
+ SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
size_t sess_id_len = 0, innerlen = 0;
int mt = SSL3_MT_CLIENT_HELLO, rv = 0;
OSSL_HPKE_SUITE suite;
sess_id_len = sizeof(s->tmp_session_id);
s->tmp_session_id_len = sess_id_len;
if (s->hello_retry_request == SSL_HRR_NONE
- && RAND_bytes_ex(s->ssl.ctx->libctx, s->tmp_session_id,
+ && RAND_bytes_ex(sctx->libctx, s->tmp_session_id,
sess_id_len, 0) <= 0) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return 0;