Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

as client, send legacy_session_id only when sending CCS #305

Merged
merged 1 commit into from
Apr 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/picotls.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ struct st_ptls_t {
*/
union {
struct {
uint8_t legacy_session_id[32];
ptls_iovec_t legacy_session_id;
uint8_t legacy_session_id_buf[32];
ptls_key_exchange_context_t *key_share_ctx;
unsigned offered_psk : 1;
/**
Expand Down Expand Up @@ -1955,7 +1956,7 @@ static int send_client_hello(ptls_t *tls, ptls_message_emitter_t *emitter, ptls_
ptls_buffer_pushv(sendbuf, tls->client_random, sizeof(tls->client_random));
/* lecagy_session_id */
ptls_buffer_push_block(
sendbuf, 1, { ptls_buffer_pushv(sendbuf, tls->client.legacy_session_id, sizeof(tls->client.legacy_session_id)); });
sendbuf, 1, { ptls_buffer_pushv(sendbuf, tls->client.legacy_session_id.base, tls->client.legacy_session_id.len); });
/* cipher_suites */
ptls_buffer_push_block(sendbuf, 2, {
ptls_cipher_suite_t **cs = tls->ctx->cipher_suites;
Expand Down Expand Up @@ -2316,8 +2317,8 @@ static int client_handle_hello(ptls_t *tls, ptls_message_emitter_t *emitter, ptl

if ((ret = decode_server_hello(tls, &sh, message.base + PTLS_HANDSHAKE_HEADER_SIZE, message.base + message.len)) != 0)
goto Exit;
if (!(sh.legacy_session_id.len == sizeof(tls->client.legacy_session_id) &&
ptls_mem_equal(sh.legacy_session_id.base, tls->client.legacy_session_id, sizeof(tls->client.legacy_session_id)))) {
if (!(sh.legacy_session_id.len == tls->client.legacy_session_id.len &&
ptls_mem_equal(sh.legacy_session_id.base, tls->client.legacy_session_id.base, tls->client.legacy_session_id.len))) {
ret = PTLS_ALERT_ILLEGAL_PARAMETER;
goto Exit;
}
Expand Down Expand Up @@ -4207,7 +4208,11 @@ ptls_t *ptls_client_new(ptls_context_t *ctx)
tls->state = PTLS_STATE_CLIENT_HANDSHAKE_START;
tls->ctx->random_bytes(tls->client_random, sizeof(tls->client_random));
log_client_random(tls);
tls->ctx->random_bytes(tls->client.legacy_session_id, sizeof(tls->client.legacy_session_id));
if (tls->send_change_cipher_spec) {
tls->client.legacy_session_id =
ptls_iovec_init(tls->client.legacy_session_id_buf, sizeof(tls->client.legacy_session_id_buf));
tls->ctx->random_bytes(tls->client.legacy_session_id.base, tls->client.legacy_session_id.len);
}

PTLS_PROBE(NEW, tls, 0);
return tls;
Expand Down