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