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
IsResumption() const69 bool QuicCryptoClientStream::IsResumption() const {
70 return handshaker_->IsResumption();
71 }
72
EarlyDataAccepted() const73 bool QuicCryptoClientStream::EarlyDataAccepted() const {
74 return handshaker_->EarlyDataAccepted();
75 }
76
EarlyDataReason() const77 ssl_early_data_reason_t QuicCryptoClientStream::EarlyDataReason() const {
78 return handshaker_->EarlyDataReason();
79 }
80
ReceivedInchoateReject() const81 bool QuicCryptoClientStream::ReceivedInchoateReject() const {
82 return handshaker_->ReceivedInchoateReject();
83 }
84
num_scup_messages_received() const85 int QuicCryptoClientStream::num_scup_messages_received() const {
86 return handshaker_->num_scup_messages_received();
87 }
88
encryption_established() const89 bool QuicCryptoClientStream::encryption_established() const {
90 return handshaker_->encryption_established();
91 }
92
one_rtt_keys_available() const93 bool QuicCryptoClientStream::one_rtt_keys_available() const {
94 return handshaker_->one_rtt_keys_available();
95 }
96
97 const QuicCryptoNegotiatedParameters&
crypto_negotiated_params() const98 QuicCryptoClientStream::crypto_negotiated_params() const {
99 return handshaker_->crypto_negotiated_params();
100 }
101
crypto_message_parser()102 CryptoMessageParser* QuicCryptoClientStream::crypto_message_parser() {
103 return handshaker_->crypto_message_parser();
104 }
105
GetHandshakeState() const106 HandshakeState QuicCryptoClientStream::GetHandshakeState() const {
107 return handshaker_->GetHandshakeState();
108 }
109
BufferSizeLimitForLevel(EncryptionLevel level) const110 size_t QuicCryptoClientStream::BufferSizeLimitForLevel(
111 EncryptionLevel level) const {
112 return handshaker_->BufferSizeLimitForLevel(level);
113 }
114
115 std::unique_ptr<QuicDecrypter>
AdvanceKeysAndCreateCurrentOneRttDecrypter()116 QuicCryptoClientStream::AdvanceKeysAndCreateCurrentOneRttDecrypter() {
117 return handshaker_->AdvanceKeysAndCreateCurrentOneRttDecrypter();
118 }
119
120 std::unique_ptr<QuicEncrypter>
CreateCurrentOneRttEncrypter()121 QuicCryptoClientStream::CreateCurrentOneRttEncrypter() {
122 return handshaker_->CreateCurrentOneRttEncrypter();
123 }
124
ExportKeyingMaterial(absl::string_view label,absl::string_view context,size_t result_len,std::string * result)125 bool QuicCryptoClientStream::ExportKeyingMaterial(absl::string_view label,
126 absl::string_view context,
127 size_t result_len,
128 std::string* result) {
129 return handshaker_->ExportKeyingMaterial(label, context, result_len, result);
130 }
131
chlo_hash() const132 std::string QuicCryptoClientStream::chlo_hash() const {
133 return handshaker_->chlo_hash();
134 }
135
OnOneRttPacketAcknowledged()136 void QuicCryptoClientStream::OnOneRttPacketAcknowledged() {
137 handshaker_->OnOneRttPacketAcknowledged();
138 }
139
OnHandshakePacketSent()140 void QuicCryptoClientStream::OnHandshakePacketSent() {
141 handshaker_->OnHandshakePacketSent();
142 }
143
OnConnectionClosed(QuicErrorCode error,ConnectionCloseSource source)144 void QuicCryptoClientStream::OnConnectionClosed(QuicErrorCode error,
145 ConnectionCloseSource source) {
146 handshaker_->OnConnectionClosed(error, source);
147 }
148
OnHandshakeDoneReceived()149 void QuicCryptoClientStream::OnHandshakeDoneReceived() {
150 handshaker_->OnHandshakeDoneReceived();
151 }
152
OnNewTokenReceived(absl::string_view token)153 void QuicCryptoClientStream::OnNewTokenReceived(absl::string_view token) {
154 handshaker_->OnNewTokenReceived(token);
155 }
156
SetServerApplicationStateForResumption(std::unique_ptr<ApplicationState> application_state)157 void QuicCryptoClientStream::SetServerApplicationStateForResumption(
158 std::unique_ptr<ApplicationState> application_state) {
159 handshaker_->SetServerApplicationStateForResumption(
160 std::move(application_state));
161 }
162
GetSsl() const163 SSL* QuicCryptoClientStream::GetSsl() const {
164 return tls_handshaker_ == nullptr ? nullptr : tls_handshaker_->ssl();
165 }
166
IsCryptoFrameExpectedForEncryptionLevel(EncryptionLevel level) const167 bool QuicCryptoClientStream::IsCryptoFrameExpectedForEncryptionLevel(
168 EncryptionLevel level) const {
169 return handshaker_->IsCryptoFrameExpectedForEncryptionLevel(level);
170 }
171
172 EncryptionLevel
GetEncryptionLevelToSendCryptoDataOfSpace(PacketNumberSpace space) const173 QuicCryptoClientStream::GetEncryptionLevelToSendCryptoDataOfSpace(
174 PacketNumberSpace space) const {
175 return handshaker_->GetEncryptionLevelToSendCryptoDataOfSpace(space);
176 }
177
178 } // namespace quic
179