Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: components/safe_browsing_db/v4_protocol_manager_util.h

Issue 2495783003: Implement support for checking bad IPs aka MatchMalwareIP (Closed)
Patch Set: shess@ and nparker@ review Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ 5 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_
6 #define COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_
7 7
8 // A class that implements the stateless methods used by the GetHashUpdate and 8 // A class that implements the stateless methods used by the GetHashUpdate and
9 // GetFullHash stubby calls made by Chrome using the SafeBrowsing V4 protocol. 9 // GetFullHash stubby calls made by Chrome using the SafeBrowsing V4 protocol.
10 10
11 #include <ostream> 11 #include <ostream>
12 #include <string> 12 #include <string>
13 13
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/hash.h" 15 #include "base/hash.h"
16 #include "base/strings/string_piece.h" 16 #include "base/strings/string_piece.h"
17 #include "components/safe_browsing_db/safebrowsing.pb.h" 17 #include "components/safe_browsing_db/safebrowsing.pb.h"
18 #include "net/url_request/url_request_status.h" 18 #include "net/url_request/url_request_status.h"
19 #include "url/gurl.h" 19 #include "url/gurl.h"
20 20
21 namespace net { 21 namespace net {
22 class HttpRequestHeaders; 22 class HttpRequestHeaders;
23 class IPAddress;
23 } // namespace net 24 } // namespace net
24 25
25 namespace safe_browsing { 26 namespace safe_browsing {
26 27
27 // The size of the hash prefix, in bytes. It should be between 4 to 32 (full 28 // The size of the hash prefix, in bytes. It should be between 4 to 32 (full
28 // hash). 29 // hash).
29 typedef size_t PrefixSize; 30 typedef size_t PrefixSize;
30 31
31 // The minimum expected size (in bytes) of a hash-prefix. 32 // The minimum expected size (in bytes) of a hash-prefix.
32 const PrefixSize kMinHashPrefixLength = 4; 33 const PrefixSize kMinHashPrefixLength = 4;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 PlatformType platform_type_; 130 PlatformType platform_type_;
130 ThreatEntryType threat_entry_type_; 131 ThreatEntryType threat_entry_type_;
131 ThreatType threat_type_; 132 ThreatType threat_type_;
132 133
133 ListIdentifier(); 134 ListIdentifier();
134 }; 135 };
135 136
136 std::ostream& operator<<(std::ostream& os, const ListIdentifier& id); 137 std::ostream& operator<<(std::ostream& os, const ListIdentifier& id);
137 138
138 PlatformType GetCurrentPlatformType(); 139 PlatformType GetCurrentPlatformType();
140 const ListIdentifier GetAnyIpMalwareId();
139 const ListIdentifier GetChromeUrlApiId(); 141 const ListIdentifier GetChromeUrlApiId();
140 const ListIdentifier GetChromeUrlClientIncidentId(); 142 const ListIdentifier GetChromeUrlClientIncidentId();
141 const ListIdentifier GetChromeUrlMalwareId(); 143 const ListIdentifier GetChromeUrlMalwareId();
142 const ListIdentifier GetUrlMalwareId(); 144 const ListIdentifier GetUrlMalwareId();
143 const ListIdentifier GetUrlMalBinId(); 145 const ListIdentifier GetUrlMalBinId();
144 const ListIdentifier GetUrlSocEngId(); 146 const ListIdentifier GetUrlSocEngId();
145 const ListIdentifier GetUrlUwsId(); 147 const ListIdentifier GetUrlUwsId();
146 148
147 // Represents the state of each store. 149 // Represents the state of each store.
148 typedef base::hash_map<ListIdentifier, std::string> StoreStateMap; 150 typedef base::hash_map<ListIdentifier, std::string> StoreStateMap;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 267
266 static bool FullHashToSmallestHashPrefix(const FullHash& full_hash, 268 static bool FullHashToSmallestHashPrefix(const FullHash& full_hash,
267 HashPrefix* hash_prefix); 269 HashPrefix* hash_prefix);
268 270
269 static bool FullHashMatchesHashPrefix(const FullHash& full_hash, 271 static bool FullHashMatchesHashPrefix(const FullHash& full_hash,
270 const HashPrefix& hash_prefix); 272 const HashPrefix& hash_prefix);
271 273
272 static void SetClientInfoFromConfig(ClientInfo* client_info, 274 static void SetClientInfoFromConfig(ClientInfo* client_info,
273 const V4ProtocolConfig& config); 275 const V4ProtocolConfig& config);
274 276
277 static bool GetIPV6AddressFromString(const std::string& ip_address,
Nathan Parker 2016/11/15 00:54:46 Is this used anywhere besides the function below?
vakh (use Gerrit instead) 2016/11/15 01:03:41 safe_browsing_database.cc
278 net::IPAddress* address);
279
280 // Converts a IPV4 or IPV6 address in |ip_address| to the SHA1 hash of the
281 // corresponding packed IPV6 address in |hashed_encoded_ip|, and adds an
282 // extra byte containing the value 128 at the end. This is done to match the
283 // server implementation for calculating the hash prefix of an IP address.
284 static bool IPAddressToEncodedIPV6Hash(const std::string& ip_address,
285 FullHash* hashed_encoded_ip);
286
275 private: 287 private:
276 V4ProtocolManagerUtil(){}; 288 V4ProtocolManagerUtil(){};
277 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, TestBackOffLogic); 289 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, TestBackOffLogic);
278 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, 290 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest,
279 TestGetRequestUrlAndUpdateHeaders); 291 TestGetRequestUrlAndUpdateHeaders);
280 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, UrlParsing); 292 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, UrlParsing);
281 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, CanonicalizeUrl); 293 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, CanonicalizeUrl);
282 294
283 // Composes a URL using |prefix|, |method| (e.g.: encodedFullHashes). 295 // Composes a URL using |prefix|, |method| (e.g.: encodedFullHashes).
284 // |request_base64|, |client_id|, |version| and |key_param|. |prefix| 296 // |request_base64|, |client_id|, |version| and |key_param|. |prefix|
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 346
335 template <> 347 template <>
336 struct hash<safe_browsing::ListIdentifier> { 348 struct hash<safe_browsing::ListIdentifier> {
337 std::size_t operator()(const safe_browsing::ListIdentifier& id) const { 349 std::size_t operator()(const safe_browsing::ListIdentifier& id) const {
338 return id.hash(); 350 return id.hash();
339 } 351 }
340 }; 352 };
341 } 353 }
342 354
343 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ 355 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698