blob: 62a261d1fc1d0e6a38c7d7a6549e8603163ec05e [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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 "net/third_party/quiche/src/quic/core/quic_crypto_client_stream.h"
6
7#include <memory>
vasilvv872e7a32019-03-12 16:42:44 -07008#include <string>
bnc463f2352019-10-10 04:49:34 -07009#include <utility>
QUICHE teama6ef0a62019-03-07 20:34:33 -050010
11#include "net/third_party/quiche/src/quic/core/crypto/crypto_protocol.h"
12#include "net/third_party/quiche/src/quic/core/crypto/crypto_utils.h"
13#include "net/third_party/quiche/src/quic/core/crypto/null_encrypter.h"
renjietangf21e3852020-04-13 15:45:39 -070014#include "net/third_party/quiche/src/quic/core/crypto/quic_crypto_client_config.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050015#include "net/third_party/quiche/src/quic/core/quic_crypto_client_handshaker.h"
16#include "net/third_party/quiche/src/quic/core/quic_packets.h"
17#include "net/third_party/quiche/src/quic/core/quic_session.h"
18#include "net/third_party/quiche/src/quic/core/quic_utils.h"
19#include "net/third_party/quiche/src/quic/core/tls_client_handshaker.h"
20#include "net/third_party/quiche/src/quic/platform/api/quic_flags.h"
21#include "net/third_party/quiche/src/quic/platform/api/quic_logging.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050022
23namespace quic {
24
25const int QuicCryptoClientStream::kMaxClientHellos;
26
27QuicCryptoClientStreamBase::QuicCryptoClientStreamBase(QuicSession* session)
28 : QuicCryptoStream(session) {}
29
30QuicCryptoClientStream::QuicCryptoClientStream(
31 const QuicServerId& server_id,
32 QuicSession* session,
33 std::unique_ptr<ProofVerifyContext> verify_context,
34 QuicCryptoClientConfig* crypto_config,
renjietangbcc066a2020-04-21 18:05:57 -070035 ProofHandler* proof_handler,
36 bool has_application_state)
QUICHE teama6ef0a62019-03-07 20:34:33 -050037 : QuicCryptoClientStreamBase(session) {
38 DCHECK_EQ(Perspective::IS_CLIENT, session->connection()->perspective());
39 switch (session->connection()->version().handshake_protocol) {
40 case PROTOCOL_QUIC_CRYPTO:
vasilvv0fc587f2019-09-06 13:33:08 -070041 handshaker_ = std::make_unique<QuicCryptoClientHandshaker>(
QUICHE teama6ef0a62019-03-07 20:34:33 -050042 server_id, this, session, std::move(verify_context), crypto_config,
43 proof_handler);
44 break;
45 case PROTOCOL_TLS1_3:
vasilvv0fc587f2019-09-06 13:33:08 -070046 handshaker_ = std::make_unique<TlsClientHandshaker>(
nharperdf7a77b2019-11-11 13:12:45 -080047 server_id, this, session, std::move(verify_context), crypto_config,
renjietangbcc066a2020-04-21 18:05:57 -070048 proof_handler, has_application_state);
QUICHE teama6ef0a62019-03-07 20:34:33 -050049 break;
50 case PROTOCOL_UNSUPPORTED:
51 QUIC_BUG << "Attempting to create QuicCryptoClientStream for unknown "
52 "handshake protocol";
53 }
54}
55
56QuicCryptoClientStream::~QuicCryptoClientStream() {}
57
58bool QuicCryptoClientStream::CryptoConnect() {
59 return handshaker_->CryptoConnect();
60}
61
62int QuicCryptoClientStream::num_sent_client_hellos() const {
63 return handshaker_->num_sent_client_hellos();
64}
65
nharper02703962019-11-07 12:23:13 -080066bool QuicCryptoClientStream::IsResumption() const {
67 return handshaker_->IsResumption();
68}
69
nharper4084fc92020-02-10 14:43:35 -080070bool QuicCryptoClientStream::EarlyDataAccepted() const {
71 return handshaker_->EarlyDataAccepted();
72}
73
74bool QuicCryptoClientStream::ReceivedInchoateReject() const {
75 return handshaker_->ReceivedInchoateReject();
76}
77
QUICHE teama6ef0a62019-03-07 20:34:33 -050078int QuicCryptoClientStream::num_scup_messages_received() const {
79 return handshaker_->num_scup_messages_received();
80}
81
82bool QuicCryptoClientStream::encryption_established() const {
83 return handshaker_->encryption_established();
84}
85
fayang685367a2020-01-14 10:40:15 -080086bool QuicCryptoClientStream::one_rtt_keys_available() const {
87 return handshaker_->one_rtt_keys_available();
QUICHE teama6ef0a62019-03-07 20:34:33 -050088}
89
90const QuicCryptoNegotiatedParameters&
91QuicCryptoClientStream::crypto_negotiated_params() const {
92 return handshaker_->crypto_negotiated_params();
93}
94
95CryptoMessageParser* QuicCryptoClientStream::crypto_message_parser() {
96 return handshaker_->crypto_message_parser();
97}
98
fayang9a863cf2020-01-16 14:12:11 -080099HandshakeState QuicCryptoClientStream::GetHandshakeState() const {
100 return handshaker_->GetHandshakeState();
101}
102
nharper486a8a92019-08-28 16:25:10 -0700103size_t QuicCryptoClientStream::BufferSizeLimitForLevel(
104 EncryptionLevel level) const {
105 return handshaker_->BufferSizeLimitForLevel(level);
106}
107
vasilvvc48c8712019-03-11 13:38:16 -0700108std::string QuicCryptoClientStream::chlo_hash() const {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500109 return handshaker_->chlo_hash();
110}
111
fayang2f2915d2020-01-24 06:47:15 -0800112void QuicCryptoClientStream::OnOneRttPacketAcknowledged() {
113 handshaker_->OnOneRttPacketAcknowledged();
114}
115
fayang44ae4e92020-04-28 13:09:42 -0700116void QuicCryptoClientStream::OnHandshakePacketSent() {
117 handshaker_->OnHandshakePacketSent();
118}
119
fayanga6a85a82020-05-04 08:58:53 -0700120void QuicCryptoClientStream::OnConnectionClosed(QuicErrorCode error,
121 ConnectionCloseSource source) {
122 handshaker_->OnConnectionClosed(error, source);
123}
124
fayang01062942020-01-22 07:23:23 -0800125void QuicCryptoClientStream::OnHandshakeDoneReceived() {
126 handshaker_->OnHandshakeDoneReceived();
127}
128
nharperac52a862020-06-08 12:41:06 -0700129void QuicCryptoClientStream::SetServerApplicationStateForResumption(
renjietangf21e3852020-04-13 15:45:39 -0700130 std::unique_ptr<ApplicationState> application_state) {
nharperac52a862020-06-08 12:41:06 -0700131 handshaker_->SetServerApplicationStateForResumption(
132 std::move(application_state));
renjietangf21e3852020-04-13 15:45:39 -0700133}
134
QUICHE teama6ef0a62019-03-07 20:34:33 -0500135} // namespace quic