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