| 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_get_hash_protocol_manager.h" | 5 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 std::string V4GetHashProtocolManager::GetHashRequest( | 137 std::string V4GetHashProtocolManager::GetHashRequest( |
| 138 const std::vector<SBPrefix>& prefixes, | 138 const std::vector<SBPrefix>& prefixes, |
| 139 const std::vector<PlatformType>& platforms, | 139 const std::vector<PlatformType>& platforms, |
| 140 ThreatType threat_type) { | 140 ThreatType threat_type) { |
| 141 // Build the request. Client info and client states are not added to the | 141 // Build the request. Client info and client states are not added to the |
| 142 // request protocol buffer. Client info is passed as params in the url. | 142 // request protocol buffer. Client info is passed as params in the url. |
| 143 FindFullHashesRequest req; | 143 FindFullHashesRequest req; |
| 144 ThreatInfo* info = req.mutable_threat_info(); | 144 ThreatInfo* info = req.mutable_threat_info(); |
| 145 info->add_threat_types(threat_type); | 145 info->add_threat_types(threat_type); |
| 146 info->add_threat_entry_types(URL_EXPRESSION); | 146 info->add_threat_entry_types(URL); |
| 147 for (const PlatformType p : platforms) { | 147 for (const PlatformType p : platforms) { |
| 148 info->add_platform_types(p); | 148 info->add_platform_types(p); |
| 149 } | 149 } |
| 150 for (const SBPrefix& prefix : prefixes) { | 150 for (const SBPrefix& prefix : prefixes) { |
| 151 std::string hash(reinterpret_cast<const char*>(&prefix), sizeof(SBPrefix)); | 151 std::string hash(reinterpret_cast<const char*>(&prefix), sizeof(SBPrefix)); |
| 152 info->add_threat_entries()->set_hash(hash); | 152 info->add_threat_entries()->set_hash(hash); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Serialize and Base64 encode. | 155 // Serialize and Base64 encode. |
| 156 std::string req_data, req_base64; | 156 std::string req_data, req_base64; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 185 } | 185 } |
| 186 | 186 |
| 187 // We only expect one threat type per request, so we make sure | 187 // We only expect one threat type per request, so we make sure |
| 188 // the threat types are consistent between matches. | 188 // the threat types are consistent between matches. |
| 189 ThreatType expected_threat_type = THREAT_TYPE_UNSPECIFIED; | 189 ThreatType expected_threat_type = THREAT_TYPE_UNSPECIFIED; |
| 190 | 190 |
| 191 // Loop over the threat matches and fill in full_hashes. | 191 // Loop over the threat matches and fill in full_hashes. |
| 192 for (const ThreatMatch& match : response.matches()) { | 192 for (const ThreatMatch& match : response.matches()) { |
| 193 // Make sure the platform and threat entry type match. | 193 // Make sure the platform and threat entry type match. |
| 194 if (!(match.has_threat_entry_type() && | 194 if (!(match.has_threat_entry_type() && |
| 195 match.threat_entry_type() == URL_EXPRESSION && match.has_threat())) { | 195 match.threat_entry_type() == URL && match.has_threat())) { |
| 196 RecordParseGetHashResult(UNEXPECTED_THREAT_ENTRY_TYPE_ERROR); | 196 RecordParseGetHashResult(UNEXPECTED_THREAT_ENTRY_TYPE_ERROR); |
| 197 return false; | 197 return false; |
| 198 } | 198 } |
| 199 | 199 |
| 200 if (!match.has_threat_type()) { | 200 if (!match.has_threat_type()) { |
| 201 RecordParseGetHashResult(UNEXPECTED_THREAT_TYPE_ERROR); | 201 RecordParseGetHashResult(UNEXPECTED_THREAT_TYPE_ERROR); |
| 202 return false; | 202 return false; |
| 203 } | 203 } |
| 204 | 204 |
| 205 if (expected_threat_type == THREAT_TYPE_UNSPECIFIED) { | 205 if (expected_threat_type == THREAT_TYPE_UNSPECIFIED) { |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 next_gethash_time_ = now + next; | 403 next_gethash_time_ = now + next; |
| 404 } | 404 } |
| 405 | 405 |
| 406 GURL V4GetHashProtocolManager::GetHashUrl(const std::string& req_base64) const { | 406 GURL V4GetHashProtocolManager::GetHashUrl(const std::string& req_base64) const { |
| 407 return V4ProtocolManagerUtil::GetRequestUrl(req_base64, "encodedFullHashes", | 407 return V4ProtocolManagerUtil::GetRequestUrl(req_base64, "encodedFullHashes", |
| 408 config_); | 408 config_); |
| 409 } | 409 } |
| 410 | 410 |
| 411 | 411 |
| 412 } // namespace safe_browsing | 412 } // namespace safe_browsing |
| OLD | NEW |