blob: 010ac361ea9fea4a6a1a35bd1dd6cad50965a03f [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_server_stream.h"
6
7#include <memory>
vasilvv872e7a32019-03-12 16:42:44 -07008#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -05009
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 teama6ef0a62019-03-07 20:34:33 -050024#include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h"
25
26namespace quic {
27
28QuicCryptoServerStreamBase::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
34bool 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
49QuicCryptoServerStream::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
65QuicCryptoServerStream::~QuicCryptoServerStream() {}
66
67void QuicCryptoServerStream::CancelOutstandingCallbacks() {
68 if (handshaker()) {
69 handshaker()->CancelOutstandingCallbacks();
70 }
71}
72
73bool QuicCryptoServerStream::GetBase64SHA256ClientChannelID(
vasilvvc48c8712019-03-11 13:38:16 -070074 std::string* output) const {
QUICHE teama6ef0a62019-03-07 20:34:33 -050075 return handshaker()->GetBase64SHA256ClientChannelID(output);
76}
77
78void QuicCryptoServerStream::SendServerConfigUpdate(
79 const CachedNetworkParameters* cached_network_params) {
80 handshaker()->SendServerConfigUpdate(cached_network_params);
81}
82
83uint8_t QuicCryptoServerStream::NumHandshakeMessages() const {
84 return handshaker()->NumHandshakeMessages();
85}
86
87uint8_t QuicCryptoServerStream::NumHandshakeMessagesWithServerNonces() const {
88 return handshaker()->NumHandshakeMessagesWithServerNonces();
89}
90
91int QuicCryptoServerStream::NumServerConfigUpdateMessagesSent() const {
92 return handshaker()->NumServerConfigUpdateMessagesSent();
93}
94
95const CachedNetworkParameters*
96QuicCryptoServerStream::PreviousCachedNetworkParams() const {
97 return handshaker()->PreviousCachedNetworkParams();
98}
99
100bool QuicCryptoServerStream::UseStatelessRejectsIfPeerSupported() const {
101 return use_stateless_rejects_if_peer_supported_;
102}
103
104bool QuicCryptoServerStream::PeerSupportsStatelessRejects() const {
105 return peer_supports_stateless_rejects_;
106}
107
108bool QuicCryptoServerStream::ZeroRttAttempted() const {
109 return handshaker()->ZeroRttAttempted();
110}
111
112void QuicCryptoServerStream::SetPeerSupportsStatelessRejects(
113 bool peer_supports_stateless_rejects) {
114 peer_supports_stateless_rejects_ = peer_supports_stateless_rejects;
115}
116
117void QuicCryptoServerStream::SetPreviousCachedNetworkParams(
118 CachedNetworkParameters cached_network_params) {
119 handshaker()->SetPreviousCachedNetworkParams(cached_network_params);
120}
121
122bool QuicCryptoServerStream::ShouldSendExpectCTHeader() const {
123 return handshaker()->ShouldSendExpectCTHeader();
124}
125
126bool QuicCryptoServerStream::encryption_established() const {
127 if (!handshaker()) {
128 return false;
129 }
130 return handshaker()->encryption_established();
131}
132
133bool QuicCryptoServerStream::handshake_confirmed() const {
134 if (!handshaker()) {
135 return false;
136 }
137 return handshaker()->handshake_confirmed();
138}
139
140const QuicCryptoNegotiatedParameters&
141QuicCryptoServerStream::crypto_negotiated_params() const {
142 return handshaker()->crypto_negotiated_params();
143}
144
145CryptoMessageParser* QuicCryptoServerStream::crypto_message_parser() {
146 return handshaker()->crypto_message_parser();
147}
148
149void 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
169QuicCryptoServerStream::HandshakerDelegate* QuicCryptoServerStream::handshaker()
170 const {
171 return handshaker_.get();
172}
173
174} // namespace quic