xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/quic_crypto_client_stream.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "quiche/quic/core/quic_crypto_client_stream.h"
6 
7 #include <memory>
8 #include <string>
9 #include <utility>
10 
11 #include "quiche/quic/core/crypto/crypto_protocol.h"
12 #include "quiche/quic/core/crypto/crypto_utils.h"
13 #include "quiche/quic/core/crypto/null_encrypter.h"
14 #include "quiche/quic/core/crypto/quic_crypto_client_config.h"
15 #include "quiche/quic/core/quic_crypto_client_handshaker.h"
16 #include "quiche/quic/core/quic_packets.h"
17 #include "quiche/quic/core/quic_session.h"
18 #include "quiche/quic/core/quic_utils.h"
19 #include "quiche/quic/core/tls_client_handshaker.h"
20 #include "quiche/quic/platform/api/quic_flags.h"
21 #include "quiche/quic/platform/api/quic_logging.h"
22 
23 namespace quic {
24 
25 const int QuicCryptoClientStream::kMaxClientHellos;
26 
QuicCryptoClientStreamBase(QuicSession * session)27 QuicCryptoClientStreamBase::QuicCryptoClientStreamBase(QuicSession* session)
28     : QuicCryptoStream(session) {}
29 
QuicCryptoClientStream(const QuicServerId & server_id,QuicSession * session,std::unique_ptr<ProofVerifyContext> verify_context,QuicCryptoClientConfig * crypto_config,ProofHandler * proof_handler,bool has_application_state)30 QuicCryptoClientStream::QuicCryptoClientStream(
31     const QuicServerId& server_id, QuicSession* session,
32     std::unique_ptr<ProofVerifyContext> verify_context,
33     QuicCryptoClientConfig* crypto_config, ProofHandler* proof_handler,
34     bool has_application_state)
35     : QuicCryptoClientStreamBase(session) {
36   QUICHE_DCHECK_EQ(Perspective::IS_CLIENT,
37                    session->connection()->perspective());
38   switch (session->connection()->version().handshake_protocol) {
39     case PROTOCOL_QUIC_CRYPTO:
40       handshaker_ = std::make_unique<QuicCryptoClientHandshaker>(
41           server_id, this, session, std::move(verify_context), crypto_config,
42           proof_handler);
43       break;
44     case PROTOCOL_TLS1_3: {
45       auto handshaker = std::make_unique<TlsClientHandshaker>(
46           server_id, this, session, std::move(verify_context), crypto_config,
47           proof_handler, has_application_state);
48       tls_handshaker_ = handshaker.get();
49       handshaker_ = std::move(handshaker);
50       break;
51     }
52     case PROTOCOL_UNSUPPORTED:
53       QUIC_BUG(quic_bug_10296_1)
54           << "Attempting to create QuicCryptoClientStream for unknown "
55              "handshake protocol";
56   }
57 }
58 
~QuicCryptoClientStream()59 QuicCryptoClientStream::~QuicCryptoClientStream() {}
60 
CryptoConnect()61 bool QuicCryptoClientStream::CryptoConnect() {
62   return handshaker_->CryptoConnect();
63 }
64 
num_sent_client_hellos() const65 int QuicCryptoClientStream::num_sent_client_hellos() const {
66   return handshaker_->num_sent_client_hellos();
67 }
68 
ResumptionAttempted() const69 bool QuicCryptoClientStream::ResumptionAttempted() const {
70   return handshaker_->ResumptionAttempted();
71 }
72 
IsResumption() const73 bool QuicCryptoClientStream::IsResumption() const {
74   return handshaker_->IsResumption();
75 }
76 
EarlyDataAccepted() const77 bool QuicCryptoClientStream::EarlyDataAccepted() const {
78   return handshaker_->EarlyDataAccepted();
79 }
80 
EarlyDataReason() const81 ssl_early_data_reason_t QuicCryptoClientStream::EarlyDataReason() const {
82   return handshaker_->EarlyDataReason();
83 }
84 
ReceivedInchoateReject() const85 bool QuicCryptoClientStream::ReceivedInchoateReject() const {
86   return handshaker_->ReceivedInchoateReject();
87 }
88 
num_scup_messages_received() const89 int QuicCryptoClientStream::num_scup_messages_received() const {
90   return handshaker_->num_scup_messages_received();
91 }
92 
encryption_established() const93 bool QuicCryptoClientStream::encryption_established() const {
94   return handshaker_->encryption_established();
95 }
96 
one_rtt_keys_available() const97 bool QuicCryptoClientStream::one_rtt_keys_available() const {
98   return handshaker_->one_rtt_keys_available();
99 }
100 
101 const QuicCryptoNegotiatedParameters&
crypto_negotiated_params() const102 QuicCryptoClientStream::crypto_negotiated_params() const {
103   return handshaker_->crypto_negotiated_params();
104 }
105 
crypto_message_parser()106 CryptoMessageParser* QuicCryptoClientStream::crypto_message_parser() {
107   return handshaker_->crypto_message_parser();
108 }
109 
GetHandshakeState() const110 HandshakeState QuicCryptoClientStream::GetHandshakeState() const {
111   return handshaker_->GetHandshakeState();
112 }
113 
BufferSizeLimitForLevel(EncryptionLevel level) const114 size_t QuicCryptoClientStream::BufferSizeLimitForLevel(
115     EncryptionLevel level) const {
116   return handshaker_->BufferSizeLimitForLevel(level);
117 }
118 
119 std::unique_ptr<QuicDecrypter>
AdvanceKeysAndCreateCurrentOneRttDecrypter()120 QuicCryptoClientStream::AdvanceKeysAndCreateCurrentOneRttDecrypter() {
121   return handshaker_->AdvanceKeysAndCreateCurrentOneRttDecrypter();
122 }
123 
124 std::unique_ptr<QuicEncrypter>
CreateCurrentOneRttEncrypter()125 QuicCryptoClientStream::CreateCurrentOneRttEncrypter() {
126   return handshaker_->CreateCurrentOneRttEncrypter();
127 }
128 
ExportKeyingMaterial(absl::string_view label,absl::string_view context,size_t result_len,std::string * result)129 bool QuicCryptoClientStream::ExportKeyingMaterial(absl::string_view label,
130                                                   absl::string_view context,
131                                                   size_t result_len,
132                                                   std::string* result) {
133   return handshaker_->ExportKeyingMaterial(label, context, result_len, result);
134 }
135 
chlo_hash() const136 std::string QuicCryptoClientStream::chlo_hash() const {
137   return handshaker_->chlo_hash();
138 }
139 
OnOneRttPacketAcknowledged()140 void QuicCryptoClientStream::OnOneRttPacketAcknowledged() {
141   handshaker_->OnOneRttPacketAcknowledged();
142 }
143 
OnHandshakePacketSent()144 void QuicCryptoClientStream::OnHandshakePacketSent() {
145   handshaker_->OnHandshakePacketSent();
146 }
147 
OnConnectionClosed(QuicErrorCode error,ConnectionCloseSource source)148 void QuicCryptoClientStream::OnConnectionClosed(QuicErrorCode error,
149                                                 ConnectionCloseSource source) {
150   handshaker_->OnConnectionClosed(error, source);
151 }
152 
OnHandshakeDoneReceived()153 void QuicCryptoClientStream::OnHandshakeDoneReceived() {
154   handshaker_->OnHandshakeDoneReceived();
155 }
156 
OnNewTokenReceived(absl::string_view token)157 void QuicCryptoClientStream::OnNewTokenReceived(absl::string_view token) {
158   handshaker_->OnNewTokenReceived(token);
159 }
160 
SetServerApplicationStateForResumption(std::unique_ptr<ApplicationState> application_state)161 void QuicCryptoClientStream::SetServerApplicationStateForResumption(
162     std::unique_ptr<ApplicationState> application_state) {
163   handshaker_->SetServerApplicationStateForResumption(
164       std::move(application_state));
165 }
166 
GetSsl() const167 SSL* QuicCryptoClientStream::GetSsl() const {
168   return tls_handshaker_ == nullptr ? nullptr : tls_handshaker_->ssl();
169 }
170 
IsCryptoFrameExpectedForEncryptionLevel(EncryptionLevel level) const171 bool QuicCryptoClientStream::IsCryptoFrameExpectedForEncryptionLevel(
172     EncryptionLevel level) const {
173   return handshaker_->IsCryptoFrameExpectedForEncryptionLevel(level);
174 }
175 
176 EncryptionLevel
GetEncryptionLevelToSendCryptoDataOfSpace(PacketNumberSpace space) const177 QuicCryptoClientStream::GetEncryptionLevelToSendCryptoDataOfSpace(
178     PacketNumberSpace space) const {
179   return handshaker_->GetEncryptionLevelToSendCryptoDataOfSpace(space);
180 }
181 
182 }  // namespace quic
183