blob: ad2689e87435a831c1a5e98d93c22f87d5f35a4a [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#ifndef QUICHE_QUIC_CORE_QUIC_CRYPTO_SERVER_STREAM_H_
6#define QUICHE_QUIC_CORE_QUIC_CRYPTO_SERVER_STREAM_H_
7
8#include <cstdint>
9#include <memory>
vasilvv872e7a32019-03-12 16:42:44 -070010#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050011
QUICHE teama6ef0a62019-03-07 20:34:33 -050012#include "net/third_party/quiche/src/quic/core/crypto/crypto_handshake.h"
13#include "net/third_party/quiche/src/quic/core/crypto/quic_compressed_certs_cache.h"
14#include "net/third_party/quiche/src/quic/core/crypto/quic_crypto_server_config.h"
15#include "net/third_party/quiche/src/quic/core/quic_config.h"
16#include "net/third_party/quiche/src/quic/core/quic_crypto_handshaker.h"
17#include "net/third_party/quiche/src/quic/core/quic_crypto_stream.h"
18#include "net/third_party/quiche/src/quic/core/quic_session.h"
19#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050020
21namespace quic {
22
23class CachedNetworkParameters;
24class CryptoHandshakeMessage;
25class QuicCryptoServerConfig;
26class QuicCryptoServerStreamBase;
27
28// TODO(alyssar) see what can be moved out of QuicCryptoServerStream with
29// various code and test refactoring.
30class QUIC_EXPORT_PRIVATE QuicCryptoServerStreamBase : public QuicCryptoStream {
31 public:
32 explicit QuicCryptoServerStreamBase(QuicSession* session);
33
nharper5f23a2d2020-02-20 10:44:09 -080034 class QUIC_EXPORT_PRIVATE Helper {
35 public:
36 virtual ~Helper() {}
37
38 // Returns true if |message|, which was received on |self_address| is
39 // acceptable according to the visitor's policy. Otherwise, returns false
40 // and populates |error_details|.
41 virtual bool CanAcceptClientHello(const CryptoHandshakeMessage& message,
42 const QuicSocketAddress& client_address,
43 const QuicSocketAddress& peer_address,
44 const QuicSocketAddress& self_address,
45 std::string* error_details) const = 0;
46 };
47
QUICHE teama6ef0a62019-03-07 20:34:33 -050048 ~QuicCryptoServerStreamBase() override {}
49
50 // Cancel any outstanding callbacks, such as asynchronous validation of client
51 // hello.
52 virtual void CancelOutstandingCallbacks() = 0;
53
54 // GetBase64SHA256ClientChannelID sets |*output| to the base64 encoded,
55 // SHA-256 hash of the client's ChannelID key and returns true, if the client
56 // presented a ChannelID. Otherwise it returns false.
vasilvvc48c8712019-03-11 13:38:16 -070057 virtual bool GetBase64SHA256ClientChannelID(std::string* output) const = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -050058
59 virtual int NumServerConfigUpdateMessagesSent() const = 0;
60
61 // Sends the latest server config and source-address token to the client.
62 virtual void SendServerConfigUpdate(
63 const CachedNetworkParameters* cached_network_params) = 0;
64
65 // These are all accessors and setters to their respective counters.
66 virtual uint8_t NumHandshakeMessages() const = 0;
67 virtual uint8_t NumHandshakeMessagesWithServerNonces() const = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -050068 virtual bool ZeroRttAttempted() const = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -050069 virtual const CachedNetworkParameters* PreviousCachedNetworkParams()
70 const = 0;
71 virtual void SetPreviousCachedNetworkParams(
72 CachedNetworkParameters cached_network_params) = 0;
nharper23d40742020-01-03 14:55:01 -080073
74 // NOTE: Indicating that the Expect-CT header should be sent here presents
75 // a layering violation to some extent. The Expect-CT header only applies to
76 // HTTP connections, while this class can be used for non-HTTP applications.
77 // However, it is exposed here because that is the only place where the
78 // configuration for the certificate used in the connection is accessible.
79 virtual bool ShouldSendExpectCTHeader() const = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -050080};
81
nharpere5e28f92020-01-03 14:10:07 -080082// Creates an appropriate QuicCryptoServerStream for the provided parameters,
83// including the version used by |session|. |crypto_config|, |session|, and
84// |helper| must all outlive the stream. The caller takes ownership of the
85// returned object.
ianswett1f4fe2d2020-01-10 13:01:17 -080086QUIC_EXPORT_PRIVATE std::unique_ptr<QuicCryptoServerStreamBase>
87CreateCryptoServerStream(const QuicCryptoServerConfig* crypto_config,
88 QuicCompressedCertsCache* compressed_certs_cache,
89 QuicSession* session,
nharper5f23a2d2020-02-20 10:44:09 -080090 QuicCryptoServerStreamBase::Helper* helper);
nharpere5e28f92020-01-03 14:10:07 -080091
QUICHE teama6ef0a62019-03-07 20:34:33 -050092} // namespace quic
93
94#endif // QUICHE_QUIC_CORE_QUIC_CRYPTO_SERVER_STREAM_H_