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

Side by Side Diff: chrome/browser/safe_browsing/client_side_detection_service.cc

Issue 42553002: Mostly integrate new malware IP blacklist with the csd client. When (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix leaks in the unit-tests Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/safe_browsing/client_side_detection_service.h" 5 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 for (std::vector<AddressRange>::const_iterator it = 199 for (std::vector<AddressRange>::const_iterator it =
200 private_networks_.begin(); 200 private_networks_.begin();
201 it != private_networks_.end(); ++it) { 201 it != private_networks_.end(); ++it) {
202 if (net::IPNumberMatchesPrefix(ip_number, it->first, it->second)) { 202 if (net::IPNumberMatchesPrefix(ip_number, it->first, it->second)) {
203 return true; 203 return true;
204 } 204 }
205 } 205 }
206 return false; 206 return false;
207 } 207 }
208 208
209 bool ClientSideDetectionService::IsBadIpAddress(
210 const std::string& ip_address) const {
211 net::IPAddressNumber ip_number;
212 if (!net::ParseIPLiteralToNumber(ip_address, &ip_number)) {
213 VLOG(2) << "Unable to parse IP address: '" << ip_address << "'";
214 return false;
215 }
216 if (ip_number.size() == net::kIPv4AddressSize) {
217 ip_number = net::ConvertIPv4NumberToIPv6Number(ip_number);
218 }
219 if (ip_number.size() != net::kIPv6AddressSize) {
220 VLOG(2) << "Unable to convert IPv4 address to IPv6: '" << ip_address << "'";
221 return false; // better safe than sorry.
222 }
223 for (BadSubnetMap::const_iterator it = bad_subnets_.begin();
224 it != bad_subnets_.end(); ++it) {
225 const std::string& mask = it->first;
226 DCHECK_EQ(mask.size(), ip_number.size());
227 std::string subnet(net::kIPv6AddressSize, '.');
228 for (size_t i = 0; i < net::kIPv6AddressSize; ++i) {
229 subnet[i] = ip_number[i] & mask[i];
230 }
231 if (it->second.count(crypto::SHA256HashString(subnet)) > 0) {
232 return true;
233 }
234 }
235 return false;
236 }
237
238 void ClientSideDetectionService::OnURLFetchComplete( 209 void ClientSideDetectionService::OnURLFetchComplete(
239 const net::URLFetcher* source) { 210 const net::URLFetcher* source) {
240 std::string data; 211 std::string data;
241 source->GetResponseAsString(&data); 212 source->GetResponseAsString(&data);
242 if (source == model_fetcher_.get()) { 213 if (source == model_fetcher_.get()) {
243 HandleModelResponse( 214 HandleModelResponse(
244 source, source->GetURL(), source->GetStatus(), 215 source, source->GetURL(), source->GetStatus(),
245 source->GetResponseCode(), source->GetCookies(), data); 216 source->GetResponseCode(), source->GetCookies(), data);
246 } else if (client_phishing_reports_.find(source) != 217 } else if (client_phishing_reports_.find(source) !=
247 client_phishing_reports_.end()) { 218 client_phishing_reports_.end()) {
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 GURL ClientSideDetectionService::GetClientReportUrl( 680 GURL ClientSideDetectionService::GetClientReportUrl(
710 const std::string& report_url) { 681 const std::string& report_url) {
711 GURL url(report_url); 682 GURL url(report_url);
712 std::string api_key = google_apis::GetAPIKey(); 683 std::string api_key = google_apis::GetAPIKey();
713 if (!api_key.empty()) 684 if (!api_key.empty())
714 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); 685 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true));
715 686
716 return url; 687 return url;
717 } 688 }
718 } // namespace safe_browsing 689 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698