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 | #ifndef QUICHE_QUIC_CORE_QUIC_CRYPTO_CLIENT_STREAM_H_ |
| 6 | #define QUICHE_QUIC_CORE_QUIC_CRYPTO_CLIENT_STREAM_H_ |
| 7 | |
| 8 | #include <cstdint> |
| 9 | #include <memory> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 10 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | #include "net/third_party/quiche/src/quic/core/crypto/proof_verifier.h" |
| 13 | #include "net/third_party/quiche/src/quic/core/crypto/quic_crypto_client_config.h" |
| 14 | #include "net/third_party/quiche/src/quic/core/quic_config.h" |
| 15 | #include "net/third_party/quiche/src/quic/core/quic_crypto_handshaker.h" |
| 16 | #include "net/third_party/quiche/src/quic/core/quic_crypto_stream.h" |
| 17 | #include "net/third_party/quiche/src/quic/core/quic_server_id.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 team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 20 | |
| 21 | namespace quic { |
| 22 | |
| 23 | class QUIC_EXPORT_PRIVATE QuicCryptoClientStreamBase : public QuicCryptoStream { |
| 24 | public: |
| 25 | explicit QuicCryptoClientStreamBase(QuicSession* session); |
| 26 | |
| 27 | ~QuicCryptoClientStreamBase() override {} |
| 28 | |
| 29 | // Performs a crypto handshake with the server. Returns true if the connection |
| 30 | // is still connected. |
| 31 | virtual bool CryptoConnect() = 0; |
| 32 | |
| 33 | // num_sent_client_hellos returns the number of client hello messages that |
| 34 | // have been sent. If the handshake has completed then this is one greater |
| 35 | // than the number of round-trips needed for the handshake. |
| 36 | virtual int num_sent_client_hellos() const = 0; |
| 37 | |
| 38 | // The number of server config update messages received by the |
| 39 | // client. Does not count update messages that were received prior |
| 40 | // to handshake confirmation. |
| 41 | virtual int num_scup_messages_received() const = 0; |
| 42 | }; |
| 43 | |
| 44 | class QUIC_EXPORT_PRIVATE QuicCryptoClientStream |
| 45 | : public QuicCryptoClientStreamBase { |
| 46 | public: |
| 47 | // kMaxClientHellos is the maximum number of times that we'll send a client |
QUICHE team | 8b353f3 | 2019-04-09 13:49:10 -0700 | [diff] [blame] | 48 | // hello. The value 4 accounts for: |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 49 | // * One failure due to an incorrect or missing source-address token. |
| 50 | // * One failure due the server's certificate chain being unavailible and |
| 51 | // the server being unwilling to send it without a valid source-address |
| 52 | // token. |
QUICHE team | 8b353f3 | 2019-04-09 13:49:10 -0700 | [diff] [blame] | 53 | // * One failure due to the ServerConfig private key being located on a |
| 54 | // remote oracle which has become unavailable, forcing the server to send |
| 55 | // the client a fallback ServerConfig. |
| 56 | static const int kMaxClientHellos = 4; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 57 | |
| 58 | // QuicCryptoClientStream creates a HandshakerDelegate at construction time |
| 59 | // based on the QuicTransportVersion of the connection. Different |
| 60 | // HandshakerDelegates provide implementations of different crypto handshake |
| 61 | // protocols. Currently QUIC crypto is the only protocol implemented; a future |
| 62 | // HandshakerDelegate will use TLS as the handshake protocol. |
| 63 | // QuicCryptoClientStream delegates all of its public methods to its |
| 64 | // HandshakerDelegate. |
| 65 | // |
| 66 | // This setup of the crypto stream delegating its implementation to the |
| 67 | // handshaker results in the handshaker reading and writing bytes on the |
| 68 | // crypto stream, instead of the handshaker passing the stream bytes to send. |
| 69 | class QUIC_EXPORT_PRIVATE HandshakerDelegate { |
| 70 | public: |
| 71 | virtual ~HandshakerDelegate() {} |
| 72 | |
| 73 | // Performs a crypto handshake with the server. Returns true if the |
| 74 | // connection is still connected. |
| 75 | virtual bool CryptoConnect() = 0; |
| 76 | |
| 77 | // num_sent_client_hellos returns the number of client hello messages that |
| 78 | // have been sent. If the handshake has completed then this is one greater |
| 79 | // than the number of round-trips needed for the handshake. |
| 80 | virtual int num_sent_client_hellos() const = 0; |
| 81 | |
| 82 | // The number of server config update messages received by the |
| 83 | // client. Does not count update messages that were received prior |
| 84 | // to handshake confirmation. |
| 85 | virtual int num_scup_messages_received() const = 0; |
| 86 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 87 | virtual std::string chlo_hash() const = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 88 | |
| 89 | // Returns true once any encrypter (initial/0RTT or final/1RTT) has been set |
| 90 | // for the connection. |
| 91 | virtual bool encryption_established() const = 0; |
| 92 | |
| 93 | // Returns true once the crypto handshake has completed. |
| 94 | virtual bool handshake_confirmed() const = 0; |
| 95 | |
| 96 | // Returns the parameters negotiated in the crypto handshake. |
| 97 | virtual const QuicCryptoNegotiatedParameters& crypto_negotiated_params() |
| 98 | const = 0; |
| 99 | |
| 100 | // Used by QuicCryptoStream to parse data received on this stream. |
| 101 | virtual CryptoMessageParser* crypto_message_parser() = 0; |
| 102 | }; |
| 103 | |
| 104 | // ProofHandler is an interface that handles callbacks from the crypto |
| 105 | // stream when the client has proof verification details of the server. |
| 106 | class QUIC_EXPORT_PRIVATE ProofHandler { |
| 107 | public: |
| 108 | virtual ~ProofHandler() {} |
| 109 | |
| 110 | // Called when the proof in |cached| is marked valid. If this is a secure |
| 111 | // QUIC session, then this will happen only after the proof verifier |
| 112 | // completes. |
| 113 | virtual void OnProofValid( |
| 114 | const QuicCryptoClientConfig::CachedState& cached) = 0; |
| 115 | |
| 116 | // Called when proof verification details become available, either because |
| 117 | // proof verification is complete, or when cached details are used. This |
| 118 | // will only be called for secure QUIC connections. |
| 119 | virtual void OnProofVerifyDetailsAvailable( |
| 120 | const ProofVerifyDetails& verify_details) = 0; |
| 121 | }; |
| 122 | |
| 123 | QuicCryptoClientStream(const QuicServerId& server_id, |
| 124 | QuicSession* session, |
| 125 | std::unique_ptr<ProofVerifyContext> verify_context, |
| 126 | QuicCryptoClientConfig* crypto_config, |
| 127 | ProofHandler* proof_handler); |
| 128 | QuicCryptoClientStream(const QuicCryptoClientStream&) = delete; |
| 129 | QuicCryptoClientStream& operator=(const QuicCryptoClientStream&) = delete; |
| 130 | |
| 131 | ~QuicCryptoClientStream() override; |
| 132 | |
| 133 | // From QuicCryptoClientStreamBase |
| 134 | bool CryptoConnect() override; |
| 135 | int num_sent_client_hellos() const override; |
| 136 | |
| 137 | int num_scup_messages_received() const override; |
| 138 | |
| 139 | // From QuicCryptoStream |
| 140 | bool encryption_established() const override; |
| 141 | bool handshake_confirmed() const override; |
| 142 | const QuicCryptoNegotiatedParameters& crypto_negotiated_params() |
| 143 | const override; |
| 144 | CryptoMessageParser* crypto_message_parser() override; |
| 145 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 146 | std::string chlo_hash() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 147 | |
| 148 | protected: |
| 149 | void set_handshaker(std::unique_ptr<HandshakerDelegate> handshaker) { |
| 150 | handshaker_ = std::move(handshaker); |
| 151 | } |
| 152 | |
| 153 | private: |
| 154 | std::unique_ptr<HandshakerDelegate> handshaker_; |
| 155 | }; |
| 156 | |
| 157 | } // namespace quic |
| 158 | |
| 159 | #endif // QUICHE_QUIC_CORE_QUIC_CRYPTO_CLIENT_STREAM_H_ |