QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 "net/third_party/quiche/src/quic/core/quic_crypto_client_stream.h" |
| 6 | |
| 7 | #include <memory> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 8 | #include <string> |
bnc | 463f235 | 2019-10-10 04:49:34 -0700 | [diff] [blame] | 9 | #include <utility> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | |
| 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" |
renjietang | f21e385 | 2020-04-13 15:45:39 -0700 | [diff] [blame] | 14 | #include "net/third_party/quiche/src/quic/core/crypto/quic_crypto_client_config.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 15 | #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 team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 22 | |
| 23 | namespace quic { |
| 24 | |
| 25 | const int QuicCryptoClientStream::kMaxClientHellos; |
| 26 | |
| 27 | QuicCryptoClientStreamBase::QuicCryptoClientStreamBase(QuicSession* session) |
| 28 | : QuicCryptoStream(session) {} |
| 29 | |
| 30 | QuicCryptoClientStream::QuicCryptoClientStream( |
| 31 | const QuicServerId& server_id, |
| 32 | QuicSession* session, |
| 33 | std::unique_ptr<ProofVerifyContext> verify_context, |
| 34 | QuicCryptoClientConfig* crypto_config, |
renjietang | bcc066a | 2020-04-21 18:05:57 -0700 | [diff] [blame] | 35 | ProofHandler* proof_handler, |
| 36 | bool has_application_state) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 37 | : QuicCryptoClientStreamBase(session) { |
| 38 | DCHECK_EQ(Perspective::IS_CLIENT, session->connection()->perspective()); |
| 39 | switch (session->connection()->version().handshake_protocol) { |
| 40 | case PROTOCOL_QUIC_CRYPTO: |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 41 | handshaker_ = std::make_unique<QuicCryptoClientHandshaker>( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 42 | server_id, this, session, std::move(verify_context), crypto_config, |
| 43 | proof_handler); |
| 44 | break; |
| 45 | case PROTOCOL_TLS1_3: |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 46 | handshaker_ = std::make_unique<TlsClientHandshaker>( |
nharper | df7a77b | 2019-11-11 13:12:45 -0800 | [diff] [blame] | 47 | server_id, this, session, std::move(verify_context), crypto_config, |
renjietang | bcc066a | 2020-04-21 18:05:57 -0700 | [diff] [blame] | 48 | proof_handler, has_application_state); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 49 | break; |
| 50 | case PROTOCOL_UNSUPPORTED: |
| 51 | QUIC_BUG << "Attempting to create QuicCryptoClientStream for unknown " |
| 52 | "handshake protocol"; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | QuicCryptoClientStream::~QuicCryptoClientStream() {} |
| 57 | |
| 58 | bool QuicCryptoClientStream::CryptoConnect() { |
| 59 | return handshaker_->CryptoConnect(); |
| 60 | } |
| 61 | |
| 62 | int QuicCryptoClientStream::num_sent_client_hellos() const { |
| 63 | return handshaker_->num_sent_client_hellos(); |
| 64 | } |
| 65 | |
nharper | 0270396 | 2019-11-07 12:23:13 -0800 | [diff] [blame] | 66 | bool QuicCryptoClientStream::IsResumption() const { |
| 67 | return handshaker_->IsResumption(); |
| 68 | } |
| 69 | |
nharper | 4084fc9 | 2020-02-10 14:43:35 -0800 | [diff] [blame] | 70 | bool QuicCryptoClientStream::EarlyDataAccepted() const { |
| 71 | return handshaker_->EarlyDataAccepted(); |
| 72 | } |
| 73 | |
| 74 | bool QuicCryptoClientStream::ReceivedInchoateReject() const { |
| 75 | return handshaker_->ReceivedInchoateReject(); |
| 76 | } |
| 77 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 78 | int QuicCryptoClientStream::num_scup_messages_received() const { |
| 79 | return handshaker_->num_scup_messages_received(); |
| 80 | } |
| 81 | |
| 82 | bool QuicCryptoClientStream::encryption_established() const { |
| 83 | return handshaker_->encryption_established(); |
| 84 | } |
| 85 | |
fayang | 685367a | 2020-01-14 10:40:15 -0800 | [diff] [blame] | 86 | bool QuicCryptoClientStream::one_rtt_keys_available() const { |
| 87 | return handshaker_->one_rtt_keys_available(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | const QuicCryptoNegotiatedParameters& |
| 91 | QuicCryptoClientStream::crypto_negotiated_params() const { |
| 92 | return handshaker_->crypto_negotiated_params(); |
| 93 | } |
| 94 | |
| 95 | CryptoMessageParser* QuicCryptoClientStream::crypto_message_parser() { |
| 96 | return handshaker_->crypto_message_parser(); |
| 97 | } |
| 98 | |
fayang | 9a863cf | 2020-01-16 14:12:11 -0800 | [diff] [blame] | 99 | HandshakeState QuicCryptoClientStream::GetHandshakeState() const { |
| 100 | return handshaker_->GetHandshakeState(); |
| 101 | } |
| 102 | |
nharper | 486a8a9 | 2019-08-28 16:25:10 -0700 | [diff] [blame] | 103 | size_t QuicCryptoClientStream::BufferSizeLimitForLevel( |
| 104 | EncryptionLevel level) const { |
| 105 | return handshaker_->BufferSizeLimitForLevel(level); |
| 106 | } |
| 107 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 108 | std::string QuicCryptoClientStream::chlo_hash() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 109 | return handshaker_->chlo_hash(); |
| 110 | } |
| 111 | |
fayang | 2f2915d | 2020-01-24 06:47:15 -0800 | [diff] [blame] | 112 | void QuicCryptoClientStream::OnOneRttPacketAcknowledged() { |
| 113 | handshaker_->OnOneRttPacketAcknowledged(); |
| 114 | } |
| 115 | |
fayang | 44ae4e9 | 2020-04-28 13:09:42 -0700 | [diff] [blame] | 116 | void QuicCryptoClientStream::OnHandshakePacketSent() { |
| 117 | handshaker_->OnHandshakePacketSent(); |
| 118 | } |
| 119 | |
fayang | a6a85a8 | 2020-05-04 08:58:53 -0700 | [diff] [blame] | 120 | void QuicCryptoClientStream::OnConnectionClosed(QuicErrorCode error, |
| 121 | ConnectionCloseSource source) { |
| 122 | handshaker_->OnConnectionClosed(error, source); |
| 123 | } |
| 124 | |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 125 | void QuicCryptoClientStream::OnHandshakeDoneReceived() { |
| 126 | handshaker_->OnHandshakeDoneReceived(); |
| 127 | } |
| 128 | |
nharper | ac52a86 | 2020-06-08 12:41:06 -0700 | [diff] [blame] | 129 | void QuicCryptoClientStream::SetServerApplicationStateForResumption( |
renjietang | f21e385 | 2020-04-13 15:45:39 -0700 | [diff] [blame] | 130 | std::unique_ptr<ApplicationState> application_state) { |
nharper | ac52a86 | 2020-06-08 12:41:06 -0700 | [diff] [blame] | 131 | handshaker_->SetServerApplicationStateForResumption( |
| 132 | std::move(application_state)); |
renjietang | f21e385 | 2020-04-13 15:45:39 -0700 | [diff] [blame] | 133 | } |
| 134 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 135 | } // namespace quic |