Avi Drissman | 6459548 | 2022-09-14 20:52:29 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 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 | #include "net/quic/quic_session_key.h" |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6 | |
Matt Menke | 26e4154 | 2019-06-05 01:09:51 | [diff] [blame] | 7 | #include "base/feature_list.h" |
| 8 | #include "net/base/features.h" |
Ben Schwartz | 3ff4dc1e6 | 2021-04-27 21:15:23 | [diff] [blame] | 9 | #include "net/dns/public/secure_dns_policy.h" |
Matt Menke | 26e4154 | 2019-06-05 01:09:51 | [diff] [blame] | 10 | |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 11 | namespace net { |
| 12 | |
dalyk | a9286397 | 2019-10-14 20:25:58 | [diff] [blame] | 13 | QuicSessionKey::QuicSessionKey() = default; |
| 14 | |
Brianna Goldstein | 793995c | 2022-09-27 04:27:37 | [diff] [blame] | 15 | QuicSessionKey::QuicSessionKey( |
| 16 | const HostPortPair& host_port_pair, |
| 17 | PrivacyMode privacy_mode, |
| 18 | const SocketTag& socket_tag, |
| 19 | const NetworkAnonymizationKey& network_anonymization_key, |
| 20 | SecureDnsPolicy secure_dns_policy, |
| 21 | bool require_dns_https_alpn) |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 22 | : QuicSessionKey(host_port_pair.host(), |
| 23 | host_port_pair.port(), |
| 24 | privacy_mode, |
Matt Menke | 26e4154 | 2019-06-05 01:09:51 | [diff] [blame] | 25 | socket_tag, |
Brianna Goldstein | 793995c | 2022-09-27 04:27:37 | [diff] [blame] | 26 | network_anonymization_key, |
Tsuyoshi Horo | 7acebce | 2022-05-12 06:13:23 | [diff] [blame] | 27 | secure_dns_policy, |
| 28 | require_dns_https_alpn) {} |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 29 | |
Brianna Goldstein | 793995c | 2022-09-27 04:27:37 | [diff] [blame] | 30 | QuicSessionKey::QuicSessionKey( |
| 31 | const std::string& host, |
| 32 | uint16_t port, |
| 33 | PrivacyMode privacy_mode, |
| 34 | const SocketTag& socket_tag, |
| 35 | const NetworkAnonymizationKey& network_anonymization_key, |
| 36 | SecureDnsPolicy secure_dns_policy, |
| 37 | bool require_dns_https_alpn) |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 38 | : QuicSessionKey( |
Rayan Kanso | 90e6b60 | 2020-07-09 18:15:54 | [diff] [blame] | 39 | // TODO(crbug.com/1103350): Handle non-boolean privacy modes. |
Dylan Cutler | 86f47b0 | 2022-01-21 01:12:22 | [diff] [blame] | 40 | quic::QuicServerId(host, port, privacy_mode != PRIVACY_MODE_DISABLED), |
Matt Menke | 26e4154 | 2019-06-05 01:09:51 | [diff] [blame] | 41 | socket_tag, |
Brianna Goldstein | 793995c | 2022-09-27 04:27:37 | [diff] [blame] | 42 | network_anonymization_key, |
Tsuyoshi Horo | 7acebce | 2022-05-12 06:13:23 | [diff] [blame] | 43 | secure_dns_policy, |
| 44 | require_dns_https_alpn) {} |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 45 | |
Brianna Goldstein | 793995c | 2022-09-27 04:27:37 | [diff] [blame] | 46 | QuicSessionKey::QuicSessionKey( |
| 47 | const quic::QuicServerId& server_id, |
| 48 | const SocketTag& socket_tag, |
| 49 | const NetworkAnonymizationKey& network_anonymization_key, |
| 50 | SecureDnsPolicy secure_dns_policy, |
| 51 | bool require_dns_https_alpn) |
Matt Menke | 26e4154 | 2019-06-05 01:09:51 | [diff] [blame] | 52 | : server_id_(server_id), |
| 53 | socket_tag_(socket_tag), |
Brianna Goldstein | 793995c | 2022-09-27 04:27:37 | [diff] [blame] | 54 | network_anonymization_key_( |
Dustin J. Mitchell | 5624da4 | 2023-04-20 18:26:17 | [diff] [blame] | 55 | NetworkAnonymizationKey::IsPartitioningEnabled() |
Brianna Goldstein | 793995c | 2022-09-27 04:27:37 | [diff] [blame] | 56 | ? network_anonymization_key |
| 57 | : NetworkAnonymizationKey()), |
Tsuyoshi Horo | 7acebce | 2022-05-12 06:13:23 | [diff] [blame] | 58 | secure_dns_policy_(secure_dns_policy), |
| 59 | require_dns_https_alpn_(require_dns_https_alpn) {} |
dalyk | a9286397 | 2019-10-14 20:25:58 | [diff] [blame] | 60 | |
| 61 | QuicSessionKey::QuicSessionKey(const QuicSessionKey& other) = default; |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 62 | |
| 63 | bool QuicSessionKey::operator<(const QuicSessionKey& other) const { |
Brianna Goldstein | 793995c | 2022-09-27 04:27:37 | [diff] [blame] | 64 | return std::tie(server_id_, socket_tag_, network_anonymization_key_, |
Tsuyoshi Horo | 7acebce | 2022-05-12 06:13:23 | [diff] [blame] | 65 | secure_dns_policy_, require_dns_https_alpn_) < |
Matt Menke | 26e4154 | 2019-06-05 01:09:51 | [diff] [blame] | 66 | std::tie(other.server_id_, other.socket_tag_, |
Brianna Goldstein | 793995c | 2022-09-27 04:27:37 | [diff] [blame] | 67 | other.network_anonymization_key_, other.secure_dns_policy_, |
Tsuyoshi Horo | 7acebce | 2022-05-12 06:13:23 | [diff] [blame] | 68 | other.require_dns_https_alpn_); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 69 | } |
| 70 | bool QuicSessionKey::operator==(const QuicSessionKey& other) const { |
Matt Menke | 26e4154 | 2019-06-05 01:09:51 | [diff] [blame] | 71 | return server_id_ == other.server_id_ && socket_tag_ == other.socket_tag_ && |
Brianna Goldstein | 793995c | 2022-09-27 04:27:37 | [diff] [blame] | 72 | network_anonymization_key_ == other.network_anonymization_key_ && |
Tsuyoshi Horo | 7acebce | 2022-05-12 06:13:23 | [diff] [blame] | 73 | secure_dns_policy_ == other.secure_dns_policy_ && |
| 74 | require_dns_https_alpn_ == other.require_dns_https_alpn_; |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 75 | } |
| 76 | |
Matt Menke | 4697318e | 2020-07-16 22:12:00 | [diff] [blame] | 77 | bool QuicSessionKey::CanUseForAliasing(const QuicSessionKey& other) const { |
| 78 | return server_id_.privacy_mode_enabled() == |
| 79 | other.server_id_.privacy_mode_enabled() && |
| 80 | socket_tag_ == other.socket_tag_ && |
Brianna Goldstein | 793995c | 2022-09-27 04:27:37 | [diff] [blame] | 81 | network_anonymization_key_ == other.network_anonymization_key_ && |
Tsuyoshi Horo | 7acebce | 2022-05-12 06:13:23 | [diff] [blame] | 82 | secure_dns_policy_ == other.secure_dns_policy_ && |
| 83 | require_dns_https_alpn_ == other.require_dns_https_alpn_; |
Matt Menke | 4697318e | 2020-07-16 22:12:00 | [diff] [blame] | 84 | } |
| 85 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 86 | } // namespace net |