Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | 5 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/metrics/sparse_histogram.h" | 8 #include "base/metrics/sparse_histogram.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 escaped_str += c; | 55 escaped_str += c; |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 return escaped_str; | 59 return escaped_str; |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace | 62 } // namespace |
| 63 | 63 |
| 64 std::ostream& operator<<(std::ostream& os, const ListIdentifier& id) { | 64 std::ostream& operator<<(std::ostream& os, const ListIdentifier& id) { |
| 65 os << "{hash: " << id.hash() << "; platform_type: " << id.platform_type | 65 os << "{hash: " << id.hash() << "; platform_type: " << id.platform_type() |
| 66 << "; threat_entry_type: " << id.threat_entry_type | 66 << "; threat_entry_type: " << id.threat_entry_type() |
| 67 << "; threat_type: " << id.threat_type << "}"; | 67 << "; threat_type: " << id.threat_type() << "}"; |
| 68 return os; | 68 return os; |
| 69 } | 69 } |
| 70 | 70 |
| 71 PlatformType GetCurrentPlatformType() { | 71 PlatformType GetCurrentPlatformType() { |
| 72 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
| 73 return WINDOWS_PLATFORM; | 73 return WINDOWS_PLATFORM; |
| 74 #elif defined(OS_LINUX) | 74 #elif defined(OS_LINUX) |
| 75 return LINUX_PLATFORM; | 75 return LINUX_PLATFORM; |
| 76 #elif defined(OS_MACOSX) | 76 #elif defined(OS_MACOSX) |
| 77 return OSX_PLATFORM; | 77 return OSX_PLATFORM; |
| 78 #else | 78 #else |
| 79 // This should ideally never compile but it is getting compiled on Android. | 79 // This should ideally never compile but it is getting compiled on Android. |
| 80 // See: https://bugs.chromium.org/p/chromium/issues/detail?id=621647 | 80 // See: https://bugs.chromium.org/p/chromium/issues/detail?id=621647 |
| 81 // TODO(vakh): Once that bug is fixed, this should be removed. If we leave | 81 // TODO(vakh): Once that bug is fixed, this should be removed. If we leave |
| 82 // the platform_type empty, the server won't recognize the request and | 82 // the platform_type empty, the server won't recognize the request and |
| 83 // return an error response which will pollute our UMA metrics. | 83 // return an error response which will pollute our UMA metrics. |
| 84 return LINUX_PLATFORM; | 84 return LINUX_PLATFORM; |
| 85 #endif | 85 #endif |
| 86 } | 86 } |
| 87 | 87 |
| 88 const ListIdentifier GetChromeUrlApiId() { | 88 const ListIdentifier GetChromeUrlApiId() { |
| 89 return ListIdentifier(CHROME_PLATFORM, URL, API_ABUSE); | 89 return ListIdentifier(CHROME_PLATFORM, URL, API_ABUSE, |
| 90 SB_THREAT_TYPE_API_ABUSE); | |
| 90 } | 91 } |
| 91 | 92 |
| 92 const ListIdentifier GetUrlMalwareId() { | 93 const ListIdentifier GetUrlMalwareId() { |
| 93 return ListIdentifier(GetCurrentPlatformType(), URL, MALWARE_THREAT); | 94 return ListIdentifier(GetCurrentPlatformType(), URL, MALWARE_THREAT, |
| 95 SB_THREAT_TYPE_URL_MALWARE); | |
| 94 } | 96 } |
| 95 | 97 |
| 96 const ListIdentifier GetUrlSocEngId() { | 98 const ListIdentifier GetUrlSocEngId() { |
| 97 return ListIdentifier(GetCurrentPlatformType(), URL, | 99 return ListIdentifier(GetCurrentPlatformType(), URL, |
| 98 SOCIAL_ENGINEERING_PUBLIC); | 100 SOCIAL_ENGINEERING_PUBLIC, SB_THREAT_TYPE_URL_PHISHING); |
| 99 } | 101 } |
| 100 | 102 |
| 101 // The Safe Browsing V4 server URL prefix. | 103 // The Safe Browsing V4 server URL prefix. |
| 102 const char kSbV4UrlPrefix[] = "https://safebrowsing.googleapis.com/v4"; | 104 const char kSbV4UrlPrefix[] = "https://safebrowsing.googleapis.com/v4"; |
| 103 | 105 |
| 104 StoreAndHashPrefix::StoreAndHashPrefix(ListIdentifier list_id, | 106 StoreAndHashPrefix::StoreAndHashPrefix(ListIdentifier list_id, |
| 105 HashPrefix hash_prefix) | 107 HashPrefix hash_prefix) |
| 106 : list_id(list_id), hash_prefix(hash_prefix) {} | 108 : list_id(list_id), hash_prefix(hash_prefix) {} |
| 107 | 109 |
| 108 StoreAndHashPrefix::~StoreAndHashPrefix() {} | 110 StoreAndHashPrefix::~StoreAndHashPrefix() {} |
| 109 | 111 |
| 110 bool StoreAndHashPrefix::operator==(const StoreAndHashPrefix& other) const { | 112 bool StoreAndHashPrefix::operator==(const StoreAndHashPrefix& other) const { |
| 111 return list_id == other.list_id && hash_prefix == other.hash_prefix; | 113 return list_id == other.list_id && hash_prefix == other.hash_prefix; |
| 112 } | 114 } |
| 113 | 115 |
| 114 bool StoreAndHashPrefix::operator!=(const StoreAndHashPrefix& other) const { | 116 bool StoreAndHashPrefix::operator!=(const StoreAndHashPrefix& other) const { |
| 115 return !operator==(other); | 117 return !operator==(other); |
| 116 } | 118 } |
| 117 | 119 |
| 118 size_t StoreAndHashPrefix::hash() const { | 120 size_t StoreAndHashPrefix::hash() const { |
| 119 std::size_t first = list_id.hash(); | 121 std::size_t first = list_id.hash(); |
| 120 std::size_t second = std::hash<std::string>()(hash_prefix); | 122 std::size_t second = std::hash<std::string>()(hash_prefix); |
| 121 | 123 |
| 122 return base::HashInts(first, second); | 124 return base::HashInts(first, second); |
| 123 } | 125 } |
| 124 | 126 |
| 125 bool ListIdentifier::operator==(const ListIdentifier& other) const { | 127 bool ListIdentifier::operator==(const ListIdentifier& other) const { |
| 126 return platform_type == other.platform_type && | 128 return platform_type_ == other.platform_type_ && |
| 127 threat_entry_type == other.threat_entry_type && | 129 threat_entry_type_ == other.threat_entry_type_ && |
| 128 threat_type == other.threat_type; | 130 threat_type_ == other.threat_type_; |
|
Nathan Parker
2016/09/21 19:02:57
Why not compare SBThreatType as well? And in the
vakh (use Gerrit instead)
2016/09/22 00:10:36
This triad is sufficient to identify a list.
Anywa
| |
| 129 } | 131 } |
| 130 | 132 |
| 131 bool ListIdentifier::operator!=(const ListIdentifier& other) const { | 133 bool ListIdentifier::operator!=(const ListIdentifier& other) const { |
| 132 return !operator==(other); | 134 return !operator==(other); |
| 133 } | 135 } |
| 134 | 136 |
| 135 size_t ListIdentifier::hash() const { | 137 size_t ListIdentifier::hash() const { |
| 136 std::size_t first = std::hash<unsigned int>()(platform_type); | 138 std::size_t first = std::hash<unsigned int>()(platform_type_); |
| 137 std::size_t second = std::hash<unsigned int>()(threat_entry_type); | 139 std::size_t second = std::hash<unsigned int>()(threat_entry_type_); |
| 138 std::size_t third = std::hash<unsigned int>()(threat_type); | 140 std::size_t third = std::hash<unsigned int>()(threat_type_); |
| 139 | 141 |
| 140 std::size_t interim = base::HashInts(first, second); | 142 std::size_t interim = base::HashInts(first, second); |
| 141 return base::HashInts(interim, third); | 143 return base::HashInts(interim, third); |
| 142 } | 144 } |
| 143 | 145 |
| 144 ListIdentifier::ListIdentifier() {} | 146 ListIdentifier::ListIdentifier() {} |
| 145 | 147 |
| 146 ListIdentifier::ListIdentifier(PlatformType platform_type, | 148 ListIdentifier::ListIdentifier(PlatformType platform_type, |
| 147 ThreatEntryType threat_entry_type, | 149 ThreatEntryType threat_entry_type, |
| 148 ThreatType threat_type) | 150 ThreatType threat_type, |
| 149 : platform_type(platform_type), | 151 SBThreatType sb_threat_type) |
| 150 threat_entry_type(threat_entry_type), | 152 : platform_type_(platform_type), |
| 151 threat_type(threat_type) { | 153 threat_entry_type_(threat_entry_type), |
| 154 threat_type_(threat_type), | |
| 155 sb_threat_type_(sb_threat_type) { | |
| 152 DCHECK(PlatformType_IsValid(platform_type)); | 156 DCHECK(PlatformType_IsValid(platform_type)); |
| 153 DCHECK(ThreatEntryType_IsValid(threat_entry_type)); | 157 DCHECK(ThreatEntryType_IsValid(threat_entry_type)); |
| 154 DCHECK(ThreatType_IsValid(threat_type)); | 158 DCHECK(ThreatType_IsValid(threat_type)); |
| 155 } | 159 } |
| 160 ListIdentifier::ListIdentifier(PlatformType platform_type, | |
| 161 ThreatEntryType threat_entry_type, | |
| 162 ThreatType threat_type) | |
| 163 : ListIdentifier(platform_type, | |
| 164 threat_entry_type, | |
| 165 threat_type, | |
| 166 SB_THREAT_TYPE_SAFE) {} | |
| 156 | 167 |
| 157 ListIdentifier::ListIdentifier(const ListUpdateResponse& response) | 168 ListIdentifier::ListIdentifier(const ListUpdateResponse& response) |
| 158 : ListIdentifier(response.platform_type(), | 169 : ListIdentifier(response.platform_type(), |
| 159 response.threat_entry_type(), | 170 response.threat_entry_type(), |
| 160 response.threat_type()) {} | 171 response.threat_type()) {} |
| 161 | 172 |
| 162 V4ProtocolConfig::V4ProtocolConfig() : disable_auto_update(false) {} | 173 V4ProtocolConfig::V4ProtocolConfig() : disable_auto_update(false) {} |
| 163 | 174 |
| 164 V4ProtocolConfig::V4ProtocolConfig(const V4ProtocolConfig& other) = default; | 175 V4ProtocolConfig::V4ProtocolConfig(const V4ProtocolConfig& other) = default; |
| 165 | 176 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 // static | 510 // static |
| 500 void V4ProtocolManagerUtil::SetClientInfoFromConfig( | 511 void V4ProtocolManagerUtil::SetClientInfoFromConfig( |
| 501 ClientInfo* client_info, | 512 ClientInfo* client_info, |
| 502 const V4ProtocolConfig& config) { | 513 const V4ProtocolConfig& config) { |
| 503 DCHECK(client_info); | 514 DCHECK(client_info); |
| 504 client_info->set_client_id(config.client_name); | 515 client_info->set_client_id(config.client_name); |
| 505 client_info->set_client_version(config.version); | 516 client_info->set_client_version(config.version); |
| 506 } | 517 } |
| 507 | 518 |
| 508 } // namespace safe_browsing | 519 } // namespace safe_browsing |
| OLD | NEW |