Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 36 additions & 21 deletions src/lib/tls/tls13/msg_client_hello_13.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,11 @@ void Client_Hello_13::retry(const Hello_Retry_Request& hrr,
}
}

void Client_Hello_13::validate_updates(const Client_Hello_13& new_ch) {
// RFC 8446 4.1.2
void Client_Hello_13::validate_updates(const Client_Hello_13& new_ch, const Hello_Retry_Request& hrr) const {
// RFC 9846 4.2.2
// The client will also send a ClientHello when the server has responded
// to its ClientHello with a HelloRetryRequest. In that case, the client
// MUST send the same ClientHello without modification, except as follows:

if(m_data->legacy_version() != new_ch.m_data->legacy_version() ||
m_data->session_id() != new_ch.m_data->session_id() || m_data->random() != new_ch.m_data->random() ||
m_data->ciphersuites() != new_ch.m_data->ciphersuites() ||
Expand All @@ -386,27 +385,27 @@ void Client_Hello_13::validate_updates(const Client_Hello_13& new_ch) {
const auto oldexts = extension_types();
const auto newexts = new_ch.extension_types();

// Check that extension omissions are justified. RFC 8446 4.1.2 lists the
// Check that extension omissions are justified. RFC 9846 4.2.2 lists the
// only mutations the client may make between CH1 and CH2; any other
// extension removal is an illegal parameter regardless of whether the
// extension is one this implementation recognizes.
for(const auto oldext : oldexts) {
if(!newexts.contains(oldext)) {
// RFC 8446 4.1.2
// RFC 9846 4.2.2
// Removing the "early_data" extension (Section 4.2.10) if one was
// present. Early data is not permitted after a HelloRetryRequest.
if(oldext == EarlyDataIndication::static_type()) {
continue;
}

// RFC 8446 4.1.2
// RFC 9846 4.2.2
// Optionally adding, removing, or changing the length of the
// "padding" extension.
if(oldext == Extension_Code::Padding) {
continue;
}

// RFC 8446 4.1.2
// RFC 9846 4.2.2
// Updating the "pre_shared_key" extension if present by
// recomputing the "obfuscated_ticket_age" and binder values
// and (optionally) removing any PSKs which are incompatible
Expand All @@ -425,14 +424,14 @@ void Client_Hello_13::validate_updates(const Client_Hello_13& new_ch) {
// RFC-listed mutations are allowed, including for unknown extension codes.
for(const auto newext : newexts) {
if(!oldexts.contains(newext)) {
// RFC 8446 4.1.2
// RFC 9846 4.2.2
// Including a "cookie" extension if one was provided in the
// HelloRetryRequest.
if(newext == Cookie::static_type()) {
continue;
}

// RFC 8446 4.1.2
// RFC 9846 4.2.2
// Optionally adding, removing, or changing the length of the
// "padding" extension.
if(newext == Extension_Code::Padding) {
Expand All @@ -443,26 +442,42 @@ void Client_Hello_13::validate_updates(const Client_Hello_13& new_ch) {
}
}

// RFC 8446 4.1.2
// RFC 9846 4.2.2
// Removing the "early_data" extension (Section 4.2.10) if one was
// present. Early data is not permitted after a HelloRetryRequest.
if(new_ch.extensions().has<EarlyDataIndication>()) {
throw TLS_Exception(Alert::IllegalParameter, "Updated Client Hello indicates early data");
}

// RFC 8446 4.1.2
// The client MUST send the same ClientHello without modification,
// except as follows: [key_share, pre_shared_key, early_data, cookie, padding]
//
// Verify that extensions whose content must not change between the
// initial and retried Client Hello have identical wire encodings.
const std::set<Extension_Code> extensions_allowed_to_change = {
Extension_Code::KeyShare,
Extension_Code::PresharedKey,
Extension_Code::EarlyData,
Extension_Code::Cookie,
Extension_Code::Padding,
};
const auto extensions_allowed_to_change = [&] {
// RFC 9846 4.2.2
// [...], the client MUST send the same ClientHello without
// modification, except as follows:
// * Removing the "early_data" extension [...]
// * Including a "cookie" extension [...]
// * Updating the "pre_shared_key" extension [...]
// * [...] adding, removing, or changing [...] the "padding"
std::set<Extension_Code> result{
Extension_Code::PresharedKey,
Extension_Code::EarlyData,
Extension_Code::Cookie,
Extension_Code::Padding,
};

// RFC 9846 4.2.2
// [...], the client MUST send the same ClientHello without modification,
// except as follows:
// * If a "key_share" extension was supplied in the
// HelloRetryRequest, replacing the list of shares with a list
// containing a single KeyShareEntry from the indicated group.
if(hrr.extensions().has<Key_Share>()) {
result.insert(Extension_Code::KeyShare);
}

return result;
}();

// As quoted above, PSKs may only be removed. Their identities must
// otherwise be retained in the same order.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tls/tls13/tls_handshake_state_13.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Client_Hello_13& Handshake_State_13_Base::store(Client_Hello_13 client_hello, co
if(m_client_hello) {
// Make sure that the updated Client Hello is compatible to the initial one.
BOTAN_STATE_CHECK(has_hello_retry_request());
m_client_hello->validate_updates(client_hello);
m_client_hello->validate_updates(client_hello, *m_hello_retry_request);
}

m_client_hello = std::move(client_hello);
Expand Down
7 changes: 5 additions & 2 deletions src/lib/tls/tls13/tls_messages_13.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ class BOTAN_UNSTABLE_API Client_Hello_13 final : public Client_Hello {

/**
* This validates that a Client Hello received after sending a Hello
* Retry Request was updated in accordance with RFC 8446 4.1.2. If issues
* Retry Request was updated in accordance with RFC 9846 4.2.2. If issues
* are found, this method throws accordingly.
*
* @param new_ch Client Hello received after sending Hello Retry Request
* @param hrr Hello Retry Request that was sent to the peer
*/
void validate_updates(const Client_Hello_13& new_ch);
void validate_updates(const Client_Hello_13& new_ch, const Hello_Retry_Request& hrr) const;

private:
explicit Client_Hello_13(std::unique_ptr<Client_Hello_Internal> data);
Expand Down
Loading