Fix replacing connection IDs when initial crypters are in use

When the client uses an initial destination connection ID length different than 8 bytes, we replace that connection ID with a random 8-byte one. However, the initial crypters are still based on that original connection ID. This change makes sure that we initialize the TLS crypters with the right connection ID. This also removes the code that would set the crypters in tls_server_handshaker because that is no longer required now that we've completely removed in-connection version negotiation.

This change also makes sure we correctly check the QuicDispatcher::session_map_ for the replaced connection ID which is required to properly route subsequent long header packets after the first one.

This change is safe without flag protection because it only impacts versions that allow connection IDs of length different than 8, and all those versions are disabled by flags.

gfe-relnote: fix connection ID replacement, protected by quic_enable_v47/48/99
PiperOrigin-RevId: 257697143
Change-Id: Ifc3779e292104656abd72fae79fba8b7604cabe2
diff --git a/quic/core/quic_connection.cc b/quic/core/quic_connection.cc
index 099217a..b693db7 100644
--- a/quic/core/quic_connection.cc
+++ b/quic/core/quic_connection.cc
@@ -351,17 +351,17 @@
   MaybeEnableMultiplePacketNumberSpacesSupport();
   DCHECK(perspective_ == Perspective::IS_CLIENT ||
          supported_versions.size() == 1);
-  InstallInitialCrypters();
+  InstallInitialCrypters(server_connection_id_);
 }
 
-void QuicConnection::InstallInitialCrypters() {
+void QuicConnection::InstallInitialCrypters(QuicConnectionId connection_id) {
   if (version().handshake_protocol != PROTOCOL_TLS1_3) {
     // Initial crypters are currently only supported with TLS.
     return;
   }
   CrypterPair crypters;
   CryptoUtils::CreateTlsInitialCrypters(perspective_, transport_version(),
-                                        server_connection_id_, &crypters);
+                                        connection_id, &crypters);
   SetEncrypter(ENCRYPTION_INITIAL, std::move(crypters.encrypter));
   InstallDecrypter(ENCRYPTION_INITIAL, std::move(crypters.decrypter));
 }
@@ -618,7 +618,7 @@
   packet_generator_.SetRetryToken(retry_token);
 
   // Reinstall initial crypters because the connection ID changed.
-  InstallInitialCrypters();
+  InstallInitialCrypters(server_connection_id_);
 }
 
 bool QuicConnection::HasIncomingConnectionId(QuicConnectionId connection_id) {