1 // Copyright 2018 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_SESSION_KEY_H_ 6 #define NET_QUIC_QUIC_SESSION_KEY_H_ 7 8 #include "net/base/host_port_pair.h" 9 #include "net/base/network_anonymization_key.h" 10 #include "net/base/privacy_mode.h" 11 #include "net/base/proxy_chain.h" 12 #include "net/base/session_usage.h" 13 #include "net/dns/public/secure_dns_policy.h" 14 #include "net/socket/socket_tag.h" 15 #include "net/third_party/quiche/src/quiche/quic/core/quic_server_id.h" 16 17 namespace net { 18 19 // The key used to identify sessions. Includes the quic::QuicServerId and socket 20 // tag. 21 class NET_EXPORT_PRIVATE QuicSessionKey { 22 public: 23 QuicSessionKey(); 24 QuicSessionKey(const HostPortPair& host_port_pair, 25 PrivacyMode privacy_mode, 26 const ProxyChain& proxy_chain, 27 SessionUsage session_usage, 28 const SocketTag& socket_tag, 29 const NetworkAnonymizationKey& network_anonymization_key, 30 SecureDnsPolicy secure_dns_policy, 31 bool require_dns_https_alpn); 32 QuicSessionKey(const std::string& host, 33 uint16_t port, 34 PrivacyMode privacy_mode, 35 const ProxyChain& proxy_chain, 36 SessionUsage session_usage, 37 const SocketTag& socket_tag, 38 const NetworkAnonymizationKey& network_anonymization_key, 39 SecureDnsPolicy secure_dns_policy, 40 bool require_dns_https_alpn); 41 QuicSessionKey(const quic::QuicServerId& server_id, 42 const ProxyChain& proxy_chain, 43 SessionUsage session_usage, 44 const SocketTag& socket_tag, 45 const NetworkAnonymizationKey& network_anonymization_key, 46 SecureDnsPolicy secure_dns_policy, 47 bool require_dns_https_alpn); 48 QuicSessionKey(const QuicSessionKey& other); 49 ~QuicSessionKey() = default; 50 51 // Needed to be an element of std::set. 52 bool operator<(const QuicSessionKey& other) const; 53 bool operator==(const QuicSessionKey& other) const; 54 55 // Checks if requests using QuicSessionKey can potentially be used to service 56 // requests using another. Returns true if all fields except QuicServerId's 57 // host and port match. The caller *MUST* also make sure that the session 58 // associated with one key has been verified for use with the host/port of the 59 // other. 60 // 61 // Note that this method is symmetric, so it doesn't matter which key's method 62 // is called on the other. 63 bool CanUseForAliasing(const QuicSessionKey& other) const; 64 host()65 const std::string& host() const { return server_id_.host(); } 66 privacy_mode()67 PrivacyMode privacy_mode() const { 68 return server_id_.privacy_mode_enabled() ? PRIVACY_MODE_ENABLED 69 : PRIVACY_MODE_DISABLED; 70 } 71 server_id()72 const quic::QuicServerId& server_id() const { return server_id_; } 73 proxy_chain()74 const ProxyChain& proxy_chain() const { return proxy_chain_; } 75 session_usage()76 SessionUsage session_usage() const { return session_usage_; } 77 socket_tag()78 SocketTag socket_tag() const { return socket_tag_; } 79 network_anonymization_key()80 const NetworkAnonymizationKey& network_anonymization_key() const { 81 return network_anonymization_key_; 82 } 83 secure_dns_policy()84 SecureDnsPolicy secure_dns_policy() const { return secure_dns_policy_; } 85 require_dns_https_alpn()86 bool require_dns_https_alpn() const { return require_dns_https_alpn_; } 87 88 private: 89 quic::QuicServerId server_id_; 90 ProxyChain proxy_chain_; 91 SessionUsage session_usage_; 92 SocketTag socket_tag_; 93 // Used to separate requests made in different contexts. 94 NetworkAnonymizationKey network_anonymization_key_; 95 SecureDnsPolicy secure_dns_policy_; 96 bool require_dns_https_alpn_ = false; 97 }; 98 99 } // namespace net 100 101 #endif // NET_QUIC_QUIC_SESSION_KEY_H_ 102