Go to the documentation of this file.
131 #include "../crypto/internal.h"
140 assert(!ssl->
s3->pending_hs_data);
142 assert(ssl->
s3->pending_flight_offset == 0);
144 if (ssl->
s3->pending_flight ==
nullptr) {
146 if (ssl->
s3->pending_flight ==
nullptr) {
152 size_t new_cap = ssl->
s3->pending_flight->length + max_out;
153 if (max_out <
in.size() || new_cap < max_out) {
161 (
uint8_t *)ssl->
s3->pending_flight->data +
162 ssl->
s3->pending_flight->length,
167 ssl->
s3->pending_flight->length +=
len;
198 ssl->
s3->aead_write_ctx->is_null_cipher()) {
199 while (!rest.
empty()) {
208 while (!rest.
empty()) {
210 if (ssl->
s3->pending_hs_data &&
217 ssl->
s3->pending_hs_data ? ssl->
s3->pending_hs_data->length : 0;
220 assert(!chunk.
empty());
223 if (!ssl->
s3->pending_hs_data) {
226 if (!ssl->
s3->pending_hs_data ||
237 if (ssl->
s3->hs != NULL &&
238 !ssl->
s3->hs->transcript.Update(
msg)) {
245 if (!ssl->
s3->pending_hs_data || ssl->
s3->pending_hs_data->length == 0) {
249 UniquePtr<BUF_MEM> pending_hs_data =
std::move(ssl->
s3->pending_hs_data);
252 pending_hs_data->length);
254 if ((ssl->
s3->hs ==
nullptr || !ssl->
s3->hs->hints_requested) &&
275 kChangeCipherSpec)) {
301 if (ssl->
s3->pending_flight ==
nullptr) {
310 static_assert(INT_MAX <= 0xffffffff,
"int is larger than 32 bits");
311 if (ssl->
s3->pending_flight->length > INT_MAX) {
318 if (!ssl->
s3->write_buffer.empty()) {
326 if (ssl->
wbio ==
nullptr) {
332 while (ssl->
s3->pending_flight_offset < ssl->
s3->pending_flight->length) {
335 ssl->
s3->pending_flight->data + ssl->
s3->pending_flight_offset,
336 ssl->
s3->pending_flight->length - ssl->
s3->pending_flight_offset);
342 ssl->
s3->pending_flight_offset +=
ret;
350 ssl->
s3->pending_flight.reset();
351 ssl->
s3->pending_flight_offset = 0;
360 size_t msg_length = ((
in[0] & 0x7f) << 8) |
in[1];
361 if (msg_length > (1024 * 4)) {
374 if (
in.size() < 2 + msg_length) {
375 *out_consumed = 2 + msg_length;
379 CBS v2_client_hello =
CBS(ssl->
s3->read_buffer.span().subspan(2, msg_length));
383 if (!ssl->
s3->hs->transcript.Update(v2_client_hello)) {
391 uint16_t version, cipher_spec_length, session_id_length, challenge_length;
392 CBS cipher_specs, session_id, challenge;
393 if (!
CBS_get_u8(&v2_client_hello, &msg_type) ||
395 !
CBS_get_u16(&v2_client_hello, &cipher_spec_length) ||
396 !
CBS_get_u16(&v2_client_hello, &session_id_length) ||
397 !
CBS_get_u16(&v2_client_hello, &challenge_length) ||
398 !
CBS_get_bytes(&v2_client_hello, &cipher_specs, cipher_spec_length) ||
399 !
CBS_get_bytes(&v2_client_hello, &session_id, session_id_length) ||
400 !
CBS_get_bytes(&v2_client_hello, &challenge, challenge_length) ||
401 CBS_len(&v2_client_hello) != 0) {
411 size_t rand_len =
CBS_len(&challenge);
424 CBS_len(&cipher_specs) / 3 * 2 +
426 ScopedCBB client_hello;
428 if (!ssl->
s3->hs_buf) {
431 if (!ssl->
s3->hs_buf ||
434 ssl->
s3->hs_buf->max) ||
447 while (
CBS_len(&cipher_specs) > 0) {
455 if ((cipher_spec & 0xff0000) != 0) {
467 !
CBB_finish(client_hello.get(), NULL, &ssl->
s3->hs_buf->length)) {
472 *out_consumed = 2 + msg_length;
473 ssl->
s3->is_v2_hello =
true;
478 size_t *out_bytes_needed) {
479 if (!ssl->
s3->hs_buf) {
480 *out_bytes_needed = 4;
487 ssl->
s3->hs_buf->length);
490 *out_bytes_needed = 4;
495 *out_bytes_needed = 4 +
len;
501 out->is_v2_hello = ssl->
s3->is_v2_hello;
510 if (!ssl->
s3->has_message) {
511 if (!
out->is_v2_hello) {
514 ssl->
s3->has_message =
true;
541 if (ssl->
s3->has_message) {
549 return ssl->
s3->hs_buf && ssl->
s3->hs_buf->length > msg_len;
554 if (!ssl->
s3->hs_buf) {
557 return ssl->
s3->hs_buf &&
565 if (ssl->
server && !ssl->
s3->v2_hello_done) {
577 const char *
str =
reinterpret_cast<const char*
>(
in.data());
578 if (strncmp(
"GET ",
str, 4) == 0 ||
579 strncmp(
"POST ",
str, 5) == 0 ||
580 strncmp(
"HEAD ",
str, 5) == 0 ||
581 strncmp(
"PUT ",
str, 4) == 0) {
586 if (strncmp(
"CONNE",
str, 5) == 0) {
599 ssl->
s3->v2_hello_done =
true;
604 ssl->
s3->v2_hello_done =
true;
619 ssl->
s3->aead_read_ctx->is_null_cipher()) {
653 ssl->
s3->is_v2_hello =
false;
654 ssl->
s3->has_message =
false;
659 ssl->
s3->hs_buf.reset();
671 typedef std::tuple<bool, bool, bool>
Score;
676 return Score(
false,
false,
false);
712 if (candidate ==
nullptr ||
721 if (candidate_score > best_score) {
723 best_score = candidate_score;
#define SSL3_VERSION_MAJOR
Span subspan(size_t pos=0, size_t len=npos) const
#define SSL_AD_UNEXPECTED_MESSAGE
@ ssl_open_record_partial
ssl_open_record_t tls_open_handshake(SSL *ssl, size_t *out_consumed, uint8_t *out_alert, Span< uint8_t > in)
#define SSL_CHACHA20POLY1305
enum ssl_open_record_t tls_open_record(SSL *ssl, uint8_t *out_type, Span< uint8_t > *out, size_t *out_consumed, uint8_t *out_alert, Span< uint8_t > in)
static bool parse_message(const SSL *ssl, SSLMessage *out, size_t *out_bytes_needed)
CipherScorer(uint16_t group_id)
#define SSL_R_BIO_NOT_SET
const bool security_128_is_fine_
#define OPENSSL_PUT_ERROR(library, reason)
#define CBB_add_u16_length_prefixed
int(* flush_flight)(SSL *ssl)
#define SSL_R_QUIC_INTERNAL_ERROR
#define SSL_AD_INTERNAL_ERROR
#define SSL_max_seal_overhead
static const char * cipher_suites
#define SSL_AD_ILLEGAL_PARAMETER
bool tls_init_message(const SSL *ssl, CBB *cbb, CBB *body, uint8_t type)
bool tls_get_message(const SSL *ssl, SSLMessage *out)
#define SSL3_MT_CLIENT_HELLO
static void * OPENSSL_memset(void *dst, int c, size_t n)
const SSL_QUIC_METHOD * quic_method
bool tls_has_unprocessed_handshake_data(const SSL *ssl)
int(* add_handshake_data)(SSL *ssl, enum ssl_encryption_level_t level, const uint8_t *data, size_t len)
size_t ssl_max_handshake_message_len(const SSL *ssl)
void ssl_do_msg_callback(const SSL *ssl, int is_write, int content_type, Span< const uint8_t > in)
std::tuple< bool, bool, bool > Score
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
bool tls_add_message(SSL *ssl, Array< uint8_t > msg)
static ssl_open_record_t read_v2_client_hello(SSL *ssl, size_t *out_consumed, Span< const uint8_t > in)
#define SSL_R_UNEXPECTED_RECORD
#define SSL3_HM_HEADER_LENGTH
bssl::UniquePtr< BIO > wbio
static void * OPENSSL_memcpy(void *dst, const void *src, size_t n)
#define BSSL_NAMESPACE_END
#define ERR_R_INTERNAL_ERROR
#define SSL_CIPHER_get_min_version
bool tls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out, uint8_t type, const uint8_t *in, size_t in_len)
#define SSL_ERROR_WANT_WRITE
bool tls_finish_message(const SSL *ssl, CBB *cbb, Array< uint8_t > *out_msg)
#define SSL3_RT_HANDSHAKE
#define EVP_has_aes_hardware
#define SSL_R_APPLICATION_DATA_INSTEAD_OF_HANDSHAKE
OPENSSL_EXPORT bool CBBFinishArray(CBB *cbb, Array< uint8_t > *out)
#define SSL3_RT_CHANGE_CIPHER_SPEC
@ ssl_open_record_success
bool tls_flush_pending_hs_data(SSL *ssl)
bool tls_add_change_cipher_spec(SSL *ssl)
const SSL_CIPHER * ssl_choose_tls13_cipher(CBS cipher_suites, uint16_t version, uint16_t group_id)
int tls_flush_flight(SSL *ssl)
UniquePtr< SSL_SESSION > ret
uint16_t max_send_fragment
static void * OPENSSL_memmove(void *dst, const void *src, size_t n)
static BSSL_NAMESPACE_BEGIN bool add_record_to_flight(SSL *ssl, uint8_t type, Span< const uint8_t > in)
#define SSL_R_RECORD_LENGTH_MISMATCH
#define SSL_R_HTTP_REQUEST
#define SSL_get_cipher_by_value
bool tls_append_handshake_data(SSL *ssl, Span< const uint8_t > data)
int ssl_write_buffer_flush(SSL *ssl)
#define SSL_R_HTTPS_PROXY_REQUEST
#define SSL_R_DECODE_ERROR
void tls_next_message(SSL *ssl)
bool tls_can_accept_handshake_data(const SSL *ssl, uint8_t *out_alert)
#define SSL3_RT_APPLICATION_DATA
#define SSL_R_RECORD_TOO_LARGE
Score Evaluate(const SSL_CIPHER *a) const
#define SSL2_MT_CLIENT_HELLO
#define SSL_CIPHER_get_max_version
#define SSL3_RT_HEADER_LENGTH
#define ERR_R_MALLOC_FAILURE
#define SSL_R_EXCESSIVE_MESSAGE_SIZE
#define SSL_R_PROTOCOL_IS_SHUTDOWN
constexpr Span< const T > MakeConstSpan(T *ptr, size_t size) noexcept
#define CBB_add_u24_length_prefixed
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:09