1 // Copyright 2014 The Chromium Authors 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 NET_QUIC_QUIC_SERVER_INFO_H_ 6 #define NET_QUIC_QUIC_SERVER_INFO_H_ 7 8 #include <memory> 9 #include <string> 10 #include <vector> 11 12 #include "base/memory/weak_ptr.h" 13 #include "net/base/net_export.h" 14 #include "net/third_party/quiche/src/quiche/quic/core/quic_server_id.h" 15 16 namespace net { 17 18 // QuicServerInfo is an interface for fetching information about a QUIC server. 19 // This information may be stored on disk so does not include keys or other 20 // sensitive information. Primarily it's intended for caching the QUIC server's 21 // crypto config. 22 class NET_EXPORT_PRIVATE QuicServerInfo { 23 public: 24 // Enum to track failure reasons to read/load/write of QuicServerInfo to 25 // and from disk cache. 26 enum FailureReason { 27 WAIT_FOR_DATA_READY_INVALID_ARGUMENT_FAILURE = 0, 28 GET_BACKEND_FAILURE = 1, 29 OPEN_FAILURE = 2, 30 CREATE_OR_OPEN_FAILURE = 3, 31 PARSE_NO_DATA_FAILURE = 4, 32 PARSE_FAILURE = 5, 33 READ_FAILURE = 6, 34 READY_TO_PERSIST_FAILURE = 7, 35 PERSIST_NO_BACKEND_FAILURE = 8, 36 WRITE_FAILURE = 9, 37 NO_FAILURE = 10, 38 PARSE_DATA_DECODE_FAILURE = 11, 39 NUM_OF_FAILURES = 12, 40 }; 41 42 explicit QuicServerInfo(const quic::QuicServerId& server_id); 43 44 QuicServerInfo(const QuicServerInfo&) = delete; 45 QuicServerInfo& operator=(const QuicServerInfo&) = delete; 46 47 virtual ~QuicServerInfo(); 48 49 // Fetches the server config from the backing store, and returns true 50 // if the server config was found. 51 virtual bool Load() = 0; 52 53 // Persist allows for the server information to be updated for future uses. 54 virtual void Persist() = 0; 55 56 struct State { 57 State(); 58 59 State(const State&) = delete; 60 State& operator=(const State&) = delete; 61 62 ~State(); 63 64 void Clear(); 65 66 // This class matches QuicCryptoClientConfig::CachedState. 67 std::string server_config; // A serialized handshake message. 68 std::string source_address_token; // An opaque proof of IP ownership. 69 std::string cert_sct; // Signed timestamp of the leaf cert. 70 std::string chlo_hash; // Hash of the CHLO message. 71 std::vector<std::string> certs; // A list of certificates in leaf-first 72 // order. 73 std::string server_config_sig; // A signature of |server_config_|. 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: 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. 85 bool Parse(const std::string& data); 86 std::string Serialize(); 87 88 State state_; 89 90 // This is the QUIC server (hostname, port, is_https, privacy_mode) tuple for 91 // which we restore the crypto_config. 92 const quic::QuicServerId server_id_; 93 94 private: 95 // ParseInner is a helper function for Parse. 96 bool ParseInner(const std::string& data); 97 98 // SerializeInner is a helper function for Serialize. 99 std::string SerializeInner() const; 100 }; 101 102 } // namespace net 103 104 #endif // NET_QUIC_QUIC_SERVER_INFO_H_ 105