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

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

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 #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/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/sha1.h"
10 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "crypto/sha2.h" 13 #include "crypto/sha2.h"
13 #include "net/base/escape.h" 14 #include "net/base/escape.h"
15 #include "net/base/ip_address.h"
14 #include "net/http/http_request_headers.h" 16 #include "net/http/http_request_headers.h"
15 #include "url/url_util.h" 17 #include "url/url_util.h"
16 18
17 using base::Time; 19 using base::Time;
18 using base::TimeDelta; 20 using base::TimeDelta;
19 21
20 namespace safe_browsing { 22 namespace safe_browsing {
21 23
22 namespace { 24 namespace {
23 25
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 #else 80 #else
79 // This should ideally never compile but it is getting compiled on Android. 81 // This should ideally never compile but it is getting compiled on Android.
80 // See: https://bugs.chromium.org/p/chromium/issues/detail?id=621647 82 // 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 83 // 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 84 // the platform_type empty, the server won't recognize the request and
83 // return an error response which will pollute our UMA metrics. 85 // return an error response which will pollute our UMA metrics.
84 return LINUX_PLATFORM; 86 return LINUX_PLATFORM;
85 #endif 87 #endif
86 } 88 }
87 89
90 const ListIdentifier GetAnyIpMalwareId() {
91 return ListIdentifier(ANY_PLATFORM, IP_RANGE, MALWARE_THREAT);
92 }
93
88 const ListIdentifier GetChromeUrlApiId() { 94 const ListIdentifier GetChromeUrlApiId() {
89 return ListIdentifier(CHROME_PLATFORM, URL, API_ABUSE); 95 return ListIdentifier(CHROME_PLATFORM, URL, API_ABUSE);
90 } 96 }
91 97
92 const ListIdentifier GetChromeUrlClientIncidentId() { 98 const ListIdentifier GetChromeUrlClientIncidentId() {
93 return ListIdentifier(CHROME_PLATFORM, URL, CLIENT_INCIDENT); 99 return ListIdentifier(CHROME_PLATFORM, URL, CLIENT_INCIDENT);
94 } 100 }
95 101
96 const ListIdentifier GetChromeUrlMalwareId() { 102 const ListIdentifier GetChromeUrlMalwareId() {
97 return ListIdentifier(CHROME_PLATFORM, URL, MALWARE_THREAT); 103 return ListIdentifier(CHROME_PLATFORM, URL, MALWARE_THREAT);
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 527
522 // static 528 // static
523 void V4ProtocolManagerUtil::SetClientInfoFromConfig( 529 void V4ProtocolManagerUtil::SetClientInfoFromConfig(
524 ClientInfo* client_info, 530 ClientInfo* client_info,
525 const V4ProtocolConfig& config) { 531 const V4ProtocolConfig& config) {
526 DCHECK(client_info); 532 DCHECK(client_info);
527 client_info->set_client_id(config.client_name); 533 client_info->set_client_id(config.client_name);
528 client_info->set_client_version(config.version); 534 client_info->set_client_version(config.version);
529 } 535 }
530 536
537 // static
538 bool V4ProtocolManagerUtil::GetIPV6AddressFromString(
539 const std::string& ip_address,
540 net::IPAddress* address) {
541 DCHECK(address);
542 if (!address->AssignFromIPLiteral(ip_address))
543 return false;
544 if (address->IsIPv4())
545 *address = net::ConvertIPv4ToIPv4MappedIPv6(*address);
546 return address->IsIPv6();
547 }
548
549 // static
550 bool V4ProtocolManagerUtil::IPAddressToEncodedIPV6Hash(
551 const std::string& ip_address,
552 FullHash* hashed_encoded_ip) {
553 net::IPAddress address;
554 if (!GetIPV6AddressFromString(ip_address, &address)) {
555 return false;
556 }
557 std::string packed_ip = net::IPAddressToPackedString(address);
558 if (packed_ip.empty()) {
559 return false;
560 }
561
562 const std::string hash = base::SHA1HashString(packed_ip);
Nathan Parker 2016/11/15 00:54:46 Maybe DCHECK that the size is 20, since that's wha
vakh (use Gerrit instead) 2016/11/15 01:03:41 Done.
563 hashed_encoded_ip->resize(hash.size() + 1);
564 hashed_encoded_ip->replace(0, hash.size(), hash);
565 (*hashed_encoded_ip)[hash.size()] = static_cast<unsigned char>(128);
566 return true;
567 }
568
531 } // namespace safe_browsing 569 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698