[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 1 | // Copyright 2014 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 | |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 5 | #ifndef NET_QUIC_QUIC_SERVER_INFO_H_ |
| 6 | #define NET_QUIC_QUIC_SERVER_INFO_H_ |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 7 | |
xunjieli | 3a41b46 | 2017-01-24 14:41:39 | [diff] [blame] | 8 | #include <memory> |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 12 | #include "base/macros.h" |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 13 | #include "base/memory/weak_ptr.h" |
| 14 | #include "base/time/time.h" |
Victor Vasiliev | 6bb59d2 | 2019-03-08 21:34:51 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/quic/core/quic_server_id.h" |
| 16 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 17 | |
| 18 | namespace net { |
| 19 | |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 20 | // QuicServerInfo is an interface for fetching information about a QUIC server. |
| 21 | // This information may be stored on disk so does not include keys or other |
| 22 | // sensitive information. Primarily it's intended for caching the QUIC server's |
| 23 | // crypto config. |
rch | 175b117 | 2016-12-09 04:28:39 | [diff] [blame] | 24 | class QUIC_EXPORT_PRIVATE QuicServerInfo { |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 25 | public: |
rtenneti | c79d3f5 | 2016-08-10 18:34:56 | [diff] [blame] | 26 | // Enum to track failure reasons to read/load/write of QuicServerInfo to |
| 27 | // and from disk cache. |
| 28 | enum FailureReason { |
| 29 | WAIT_FOR_DATA_READY_INVALID_ARGUMENT_FAILURE = 0, |
| 30 | GET_BACKEND_FAILURE = 1, |
| 31 | OPEN_FAILURE = 2, |
| 32 | CREATE_OR_OPEN_FAILURE = 3, |
| 33 | PARSE_NO_DATA_FAILURE = 4, |
| 34 | PARSE_FAILURE = 5, |
| 35 | READ_FAILURE = 6, |
| 36 | READY_TO_PERSIST_FAILURE = 7, |
| 37 | PERSIST_NO_BACKEND_FAILURE = 8, |
| 38 | WRITE_FAILURE = 9, |
| 39 | NO_FAILURE = 10, |
| 40 | PARSE_DATA_DECODE_FAILURE = 11, |
| 41 | NUM_OF_FAILURES = 12, |
| 42 | }; |
| 43 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 44 | explicit QuicServerInfo(const quic::QuicServerId& server_id); |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 45 | virtual ~QuicServerInfo(); |
| 46 | |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 47 | // Fetches the server config from the backing store, and returns true |
| 48 | // if the server config was found. |
| 49 | virtual bool Load() = 0; |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 50 | |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 51 | // Persist allows for the server information to be updated for future uses. |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 52 | virtual void Persist() = 0; |
| 53 | |
xunjieli | 48e4f10 | 2017-04-11 23:06:53 | [diff] [blame] | 54 | // Returns the size of dynamically allocated memory in bytes. |
| 55 | virtual size_t EstimateMemoryUsage() const = 0; |
| 56 | |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 57 | struct State { |
| 58 | State(); |
| 59 | ~State(); |
| 60 | |
| 61 | void Clear(); |
| 62 | |
David Benjamin | 0a0c9c0f | 2019-06-21 23:00:46 | [diff] [blame] | 63 | // This class matches QuicCryptoClientConfig::CachedState. |
[email protected] | f9ca77a | 2014-02-20 18:02:30 | [diff] [blame] | 64 | std::string server_config; // A serialized handshake message. |
| 65 | std::string source_address_token; // An opaque proof of IP ownership. |
rtenneti | 61de368 | 2016-03-24 00:50:02 | [diff] [blame] | 66 | std::string cert_sct; // Signed timestamp of the leaf cert. |
| 67 | std::string chlo_hash; // Hash of the CHLO message. |
[email protected] | f9ca77a | 2014-02-20 18:02:30 | [diff] [blame] | 68 | std::vector<std::string> certs; // A list of certificates in leaf-first |
| 69 | // order. |
| 70 | std::string server_config_sig; // A signature of |server_config_|. |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 71 | |
| 72 | private: |
| 73 | DISALLOW_COPY_AND_ASSIGN(State); |
| 74 | }; |
| 75 | |
| 76 | // Once the data is ready, it can be read using the following members. These |
| 77 | // members can then be updated before calling |Persist|. |
| 78 | const State& state() const; |
| 79 | State* mutable_state(); |
| 80 | |
| 81 | protected: |
[email protected] | f9ca77a | 2014-02-20 18:02:30 | [diff] [blame] | 82 | // Parse parses pickled data and fills out the public member fields of this |
| 83 | // object. It returns true iff the parse was successful. The public member |
| 84 | // fields will be set to something sane in any case. |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 85 | bool Parse(const std::string& data); |
[email protected] | db1505e | 2014-02-26 15:23:17 | [diff] [blame] | 86 | std::string Serialize(); |
rtenneti | f5e4592 | 2015-10-09 05:23:16 | [diff] [blame] | 87 | |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 88 | State state_; |
| 89 | |
rtenneti | f5e4592 | 2015-10-09 05:23:16 | [diff] [blame] | 90 | // This is the QUIC server (hostname, port, is_https, privacy_mode) tuple for |
| 91 | // which we restore the crypto_config. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 92 | const quic::QuicServerId server_id_; |
rtenneti | f5e4592 | 2015-10-09 05:23:16 | [diff] [blame] | 93 | |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 94 | private: |
| 95 | // ParseInner is a helper function for Parse. |
| 96 | bool ParseInner(const std::string& data); |
| 97 | |
[email protected] | db1505e | 2014-02-26 15:23:17 | [diff] [blame] | 98 | // SerializeInner is a helper function for Serialize. |
| 99 | std::string SerializeInner() const; |
| 100 | |
[email protected] | b99c0fc | 2014-04-22 07:56:52 | [diff] [blame] | 101 | DISALLOW_COPY_AND_ASSIGN(QuicServerInfo); |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 102 | }; |
| 103 | |
[email protected] | 66262664 | 2014-01-25 00:54:41 | [diff] [blame] | 104 | } // namespace net |
| 105 | |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 106 | #endif // NET_QUIC_QUIC_SERVER_INFO_H_ |