gfe-relnote: Use HandshakerDelegateInterface in QUIC handshakers. Abstract keys installation, keys discarding, default encryption level change and mark handshake complete to HandshakerDelegateInterface. Protected by gfe2_reloadable_flag_quic_use_handshaker_delegate.
The final goal is remove session pointer from handshakers.
PiperOrigin-RevId: 282826263
Change-Id: I9b379ccfcebd174df1850f7df45069d388460173
diff --git a/quic/core/quic_crypto_client_handshaker.cc b/quic/core/quic_crypto_client_handshaker.cc
index a6f531a..eaeabfe 100644
--- a/quic/core/quic_crypto_client_handshaker.cc
+++ b/quic/core/quic_crypto_client_handshaker.cc
@@ -56,6 +56,7 @@
: QuicCryptoHandshaker(stream, session),
stream_(stream),
session_(session),
+ delegate_(session),
next_state_(STATE_IDLE),
num_client_hellos_(0),
crypto_config_(crypto_config),
@@ -317,6 +318,17 @@
crypto_config_->pad_full_hello());
SendHandshakeMessage(out);
// Be prepared to decrypt with the new server write key.
+ if (session()->use_handshake_delegate()) {
+ delegate_->OnNewKeysAvailable(
+ ENCRYPTION_ZERO_RTT,
+ std::move(crypto_negotiated_params_->initial_crypters.decrypter),
+ /*set_alternative_decrypter=*/true,
+ /*latch_once_used=*/true,
+ std::move(crypto_negotiated_params_->initial_crypters.encrypter));
+ encryption_established_ = true;
+ delegate_->SetDefaultEncryptionLevel(ENCRYPTION_ZERO_RTT);
+ return;
+ }
if (session()->connection()->version().KnowsWhichDecrypterToUse()) {
session()->connection()->InstallDecrypter(
ENCRYPTION_ZERO_RTT,
@@ -376,7 +388,11 @@
// Receipt of a REJ message means that the server received the CHLO
// so we can cancel and retransmissions.
- session()->NeuterUnencryptedData();
+ if (session()->use_handshake_delegate()) {
+ delegate_->NeuterUnencryptedData();
+ } else {
+ session()->NeuterUnencryptedData();
+ }
std::string error_details;
QuicErrorCode error = crypto_config_->ProcessRejection(
@@ -536,6 +552,18 @@
// has been floated that the server shouldn't send packets encrypted
// with the FORWARD_SECURE key until it receives a FORWARD_SECURE
// packet from the client.
+ if (session()->use_handshake_delegate()) {
+ delegate_->OnNewKeysAvailable(
+ ENCRYPTION_FORWARD_SECURE, std::move(crypters->decrypter),
+ /*set_alternative_decrypter=*/true,
+ /*latch_once_used=*/false, std::move(crypters->encrypter));
+ handshake_confirmed_ = true;
+ delegate_->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
+ delegate_->DiscardOldEncryptionKey(ENCRYPTION_INITIAL);
+ delegate_->NeuterHandshakeData();
+ return;
+ }
+
if (session()->connection()->version().KnowsWhichDecrypterToUse()) {
session()->connection()->InstallDecrypter(ENCRYPTION_FORWARD_SECURE,
std::move(crypters->decrypter));