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_server_stream.h" |
| 6 | |
| 7 | #include <memory> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 8 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | |
| 10 | #include "net/third_party/quiche/src/quic/core/crypto/crypto_protocol.h" |
| 11 | #include "net/third_party/quiche/src/quic/core/crypto/crypto_utils.h" |
| 12 | #include "net/third_party/quiche/src/quic/core/crypto/quic_crypto_server_config.h" |
| 13 | #include "net/third_party/quiche/src/quic/core/crypto/quic_random.h" |
| 14 | #include "net/third_party/quiche/src/quic/core/proto/cached_network_parameters.pb.h" |
| 15 | #include "net/third_party/quiche/src/quic/core/quic_config.h" |
| 16 | #include "net/third_party/quiche/src/quic/core/quic_crypto_server_handshaker.h" |
| 17 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 18 | #include "net/third_party/quiche/src/quic/core/quic_session.h" |
| 19 | #include "net/third_party/quiche/src/quic/core/tls_server_handshaker.h" |
| 20 | #include "net/third_party/quiche/src/quic/platform/api/quic_flag_utils.h" |
| 21 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
| 22 | #include "net/third_party/quiche/src/quic/platform/api/quic_logging.h" |
| 23 | #include "net/third_party/quiche/src/quic/platform/api/quic_ptr_util.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 24 | #include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h" |
| 25 | |
| 26 | namespace quic { |
| 27 | |
| 28 | QuicCryptoServerStreamBase::QuicCryptoServerStreamBase(QuicSession* session) |
| 29 | : QuicCryptoStream(session) {} |
| 30 | |
| 31 | // TODO(jokulik): Once stateless rejects support is inherent in the version |
| 32 | // number, this function will likely go away entirely. |
| 33 | // static |
| 34 | bool QuicCryptoServerStreamBase::DoesPeerSupportStatelessRejects( |
| 35 | const CryptoHandshakeMessage& message) { |
| 36 | QuicTagVector received_tags; |
| 37 | QuicErrorCode error = message.GetTaglist(kCOPT, &received_tags); |
| 38 | if (error != QUIC_NO_ERROR) { |
| 39 | return false; |
| 40 | } |
| 41 | for (const QuicTag tag : received_tags) { |
| 42 | if (tag == kSREJ) { |
| 43 | return true; |
| 44 | } |
| 45 | } |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | QuicCryptoServerStream::QuicCryptoServerStream( |
| 50 | const QuicCryptoServerConfig* crypto_config, |
| 51 | QuicCompressedCertsCache* compressed_certs_cache, |
| 52 | bool use_stateless_rejects_if_peer_supported, |
| 53 | QuicSession* session, |
| 54 | Helper* helper) |
| 55 | : QuicCryptoServerStreamBase(session), |
| 56 | use_stateless_rejects_if_peer_supported_( |
| 57 | use_stateless_rejects_if_peer_supported), |
| 58 | peer_supports_stateless_rejects_(false), |
| 59 | crypto_config_(crypto_config), |
| 60 | compressed_certs_cache_(compressed_certs_cache), |
| 61 | helper_(helper) { |
| 62 | DCHECK_EQ(Perspective::IS_SERVER, session->connection()->perspective()); |
| 63 | } |
| 64 | |
| 65 | QuicCryptoServerStream::~QuicCryptoServerStream() {} |
| 66 | |
| 67 | void QuicCryptoServerStream::CancelOutstandingCallbacks() { |
| 68 | if (handshaker()) { |
| 69 | handshaker()->CancelOutstandingCallbacks(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | bool QuicCryptoServerStream::GetBase64SHA256ClientChannelID( |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 74 | std::string* output) const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 75 | return handshaker()->GetBase64SHA256ClientChannelID(output); |
| 76 | } |
| 77 | |
| 78 | void QuicCryptoServerStream::SendServerConfigUpdate( |
| 79 | const CachedNetworkParameters* cached_network_params) { |
| 80 | handshaker()->SendServerConfigUpdate(cached_network_params); |
| 81 | } |
| 82 | |
| 83 | uint8_t QuicCryptoServerStream::NumHandshakeMessages() const { |
| 84 | return handshaker()->NumHandshakeMessages(); |
| 85 | } |
| 86 | |
| 87 | uint8_t QuicCryptoServerStream::NumHandshakeMessagesWithServerNonces() const { |
| 88 | return handshaker()->NumHandshakeMessagesWithServerNonces(); |
| 89 | } |
| 90 | |
| 91 | int QuicCryptoServerStream::NumServerConfigUpdateMessagesSent() const { |
| 92 | return handshaker()->NumServerConfigUpdateMessagesSent(); |
| 93 | } |
| 94 | |
| 95 | const CachedNetworkParameters* |
| 96 | QuicCryptoServerStream::PreviousCachedNetworkParams() const { |
| 97 | return handshaker()->PreviousCachedNetworkParams(); |
| 98 | } |
| 99 | |
| 100 | bool QuicCryptoServerStream::UseStatelessRejectsIfPeerSupported() const { |
| 101 | return use_stateless_rejects_if_peer_supported_; |
| 102 | } |
| 103 | |
| 104 | bool QuicCryptoServerStream::PeerSupportsStatelessRejects() const { |
| 105 | return peer_supports_stateless_rejects_; |
| 106 | } |
| 107 | |
| 108 | bool QuicCryptoServerStream::ZeroRttAttempted() const { |
| 109 | return handshaker()->ZeroRttAttempted(); |
| 110 | } |
| 111 | |
| 112 | void QuicCryptoServerStream::SetPeerSupportsStatelessRejects( |
| 113 | bool peer_supports_stateless_rejects) { |
| 114 | peer_supports_stateless_rejects_ = peer_supports_stateless_rejects; |
| 115 | } |
| 116 | |
| 117 | void QuicCryptoServerStream::SetPreviousCachedNetworkParams( |
| 118 | CachedNetworkParameters cached_network_params) { |
| 119 | handshaker()->SetPreviousCachedNetworkParams(cached_network_params); |
| 120 | } |
| 121 | |
| 122 | bool QuicCryptoServerStream::ShouldSendExpectCTHeader() const { |
| 123 | return handshaker()->ShouldSendExpectCTHeader(); |
| 124 | } |
| 125 | |
| 126 | bool QuicCryptoServerStream::encryption_established() const { |
| 127 | if (!handshaker()) { |
| 128 | return false; |
| 129 | } |
| 130 | return handshaker()->encryption_established(); |
| 131 | } |
| 132 | |
| 133 | bool QuicCryptoServerStream::handshake_confirmed() const { |
| 134 | if (!handshaker()) { |
| 135 | return false; |
| 136 | } |
| 137 | return handshaker()->handshake_confirmed(); |
| 138 | } |
| 139 | |
| 140 | const QuicCryptoNegotiatedParameters& |
| 141 | QuicCryptoServerStream::crypto_negotiated_params() const { |
| 142 | return handshaker()->crypto_negotiated_params(); |
| 143 | } |
| 144 | |
| 145 | CryptoMessageParser* QuicCryptoServerStream::crypto_message_parser() { |
| 146 | return handshaker()->crypto_message_parser(); |
| 147 | } |
| 148 | |
| 149 | void QuicCryptoServerStream::OnSuccessfulVersionNegotiation( |
| 150 | const ParsedQuicVersion& version) { |
| 151 | DCHECK_EQ(version, session()->connection()->version()); |
| 152 | CHECK(!handshaker_); |
| 153 | switch (session()->connection()->version().handshake_protocol) { |
| 154 | case PROTOCOL_QUIC_CRYPTO: |
| 155 | handshaker_ = QuicMakeUnique<QuicCryptoServerHandshaker>( |
| 156 | crypto_config_, this, compressed_certs_cache_, session(), helper_); |
| 157 | break; |
| 158 | case PROTOCOL_TLS1_3: |
| 159 | handshaker_ = QuicMakeUnique<TlsServerHandshaker>( |
| 160 | this, session(), crypto_config_->ssl_ctx(), |
| 161 | crypto_config_->proof_source()); |
| 162 | break; |
| 163 | case PROTOCOL_UNSUPPORTED: |
| 164 | QUIC_BUG << "Attempting to create QuicCryptoServerStream for unknown " |
| 165 | "handshake protocol"; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | QuicCryptoServerStream::HandshakerDelegate* QuicCryptoServerStream::handshaker() |
| 170 | const { |
| 171 | return handshaker_.get(); |
| 172 | } |
| 173 | |
| 174 | } // namespace quic |