Skip to content

Commit

Permalink
WIP process handshake message on client side
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannes Rantzsch committed Jan 14, 2022
1 parent 58f16d5 commit 465b02d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/lib/tls/tls13/tls_channel_impl_13.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ size_t Channel_Impl_13::received_data(const uint8_t input[], size_t input_size)
throw TLS_Exception(Alert::UNEXPECTED_MESSAGE, "Received handshake data after connection closure");

//TODO: Handle the plain handshake message
if(initial_record)
{
create_handshake_state(Protocol_Version::TLS_V13); // ignore version in record header
}

auto msg = m_handshake_state->get_next_handshake_msg();
process_handshake_msg(/*active_state*/ nullptr,
*m_handshake_state.get(),
msg.first, msg.second,
/*epoch0_restart*/ false);

}
else if (record.type() == CHANGE_CIPHER_SPEC)
{
Expand Down
44 changes: 41 additions & 3 deletions src/lib/tls/tls13/tls_client_impl_13.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,51 @@ void Client_Impl_13::initiate_handshake(Handshake_State& state,
BOTAN_UNUSED(state, force_full_renegotiation);
}

void Client_Impl_13::process_handshake_msg(const Handshake_State* active_state,
Handshake_State& pending_state,
void Client_Impl_13::process_handshake_msg(const Handshake_State* previous_state,
Handshake_State& state,
Handshake_Type type,
const std::vector<uint8_t>& contents,
bool epoch0_restart)
{
BOTAN_UNUSED(active_state, pending_state, type, contents, epoch0_restart);
// there cannot be a previous state in TLS 1.3 as renegotiation is not allowed
BOTAN_ASSERT_NOMSG(previous_state == nullptr);

// does not apply on client side
BOTAN_ASSERT_NOMSG(epoch0_restart == false);

BOTAN_UNUSED(type, contents);

state.confirm_transition_to(type);

if (type == SERVER_HELLO)
{
state.server_hello(new Server_Hello(contents));

if (state.server_hello()->legacy_version() != Protocol_Version::TLS_V12)
{
// RFC 8446 4.1.3:
// In TLS 1.3, the TLS server indicates
// its version using the "supported_versions" extension
// (Section 4.2.1), and the legacy_version field MUST be set to
// 0x0303, which is the version number for TLS 1.2.
throw TLS_Exception(Alert::PROTOCOL_VERSION, "legacy_version must be set to 1.2 in TLS 1.3");
}

if (auto requested = state.server_hello()->random_signals_downgrade())
{
if (requested.value() == Protocol_Version::TLS_V11)
throw TLS_Exception(Alert::PROTOCOL_VERSION, "TLS 1.1 is not supported");
if (requested.value() == Protocol_Version::TLS_V12)
throw Not_Implemented("downgrade is nyi");
}

if (state.server_hello()->random_signals_hello_retry_request())
{
throw Not_Implemented("hello retry is nyi");
}
}

throw Not_Implemented("client 13 process_handshake_msg is nyi");
}

std::unique_ptr<Handshake_State> Client_Impl_13::new_handshake_state(std::unique_ptr<Handshake_IO> io)
Expand Down
17 changes: 15 additions & 2 deletions src/tests/test_tls_rfc8448.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class Test_TLS_RFC8448 final : public Test
result.confirm("client not closed", !ctx.client.is_closed());

const auto client_hello_record = ctx.pull_send_buffer();
result.test_gte("client hello received", client_hello_record.size(), RECORD_HEADER_SIZE);
result.test_gte("client hello written", client_hello_record.size(), RECORD_HEADER_SIZE);

check_record_header(result, client_hello_record);
const auto client_hello_msg = slice(client_hello_record.begin() + RECORD_HEADER_SIZE, client_hello_record.end());
Expand Down Expand Up @@ -466,7 +466,20 @@ class Test_TLS_RFC8448 final : public Test
"1d 00 20 c9 82 88 76 11 20 95 fe 66 76 2b db f7 c6 72 e1 56 d6"
"cc 25 3b 83 3d f1 dd 69 b1 b0 4e 75 1f 0f 00 2b 00 02 03 04");

ctx.client.received_data(server_hello);
// ctx.client.received_data(server_hello);

// const auto expected_handshake_finished = Botan::hex_decode(
// "17 03 03 00 35 75 ec 4d c2 38 cc e6"
// "0b 29 80 44 a7 1e 21 9c 56 cc 77 b0 51 7f e9 b9 3c 7a 4b fc 44"
// "d8 7f 38 f8 03 38 ac 98 fc 46 de b3 84 bd 1c ae ac ab 68 67 d7"
// "26 c4 05 46");

// const auto client_handshake_finished = ctx.pull_send_buffer();
// result.test_gte("client handshake finished written", client_handshake_finished.size(),
// RECORD_HEADER_SIZE);

// result.test_eq("correct handshake finished", client_handshake_finished,
// expected_handshake_finished);

// to test:
// * server responds with cipher suite not offered by client
Expand Down

0 comments on commit 465b02d

Please sign in to comment.