| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 FROM_HERE, | 135 FROM_HERE, |
| 136 method_factory_.NewRunnableMethod( | 136 method_factory_.NewRunnableMethod( |
| 137 &ClientSideDetectionService::StartClientReportPhishingRequest, | 137 &ClientSideDetectionService::StartClientReportPhishingRequest, |
| 138 verdict, callback)); | 138 verdict, callback)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 bool ClientSideDetectionService::IsPrivateIPAddress( | 141 bool ClientSideDetectionService::IsPrivateIPAddress( |
| 142 const std::string& ip_address) const { | 142 const std::string& ip_address) const { |
| 143 net::IPAddressNumber ip_number; | 143 net::IPAddressNumber ip_number; |
| 144 if (!net::ParseIPLiteralToNumber(ip_address, &ip_number)) { | 144 if (!net::ParseIPLiteralToNumber(ip_address, &ip_number)) { |
| 145 DLOG(WARNING) << "Unable to parse IP address: " << ip_address; | 145 VLOG(2) << "Unable to parse IP address: '" << ip_address << "'"; |
| 146 // Err on the side of safety and assume this might be private. | 146 // Err on the side of safety and assume this might be private. |
| 147 return true; | 147 return true; |
| 148 } | 148 } |
| 149 | 149 |
| 150 for (std::vector<AddressRange>::const_iterator it = | 150 for (std::vector<AddressRange>::const_iterator it = |
| 151 private_networks_.begin(); | 151 private_networks_.begin(); |
| 152 it != private_networks_.end(); ++it) { | 152 it != private_networks_.end(); ++it) { |
| 153 if (net::IPNumberMatchesPrefix(ip_number, it->first, it->second)) { | 153 if (net::IPNumberMatchesPrefix(ip_number, it->first, it->second)) { |
| 154 return true; | 154 return true; |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 return false; | 157 return false; |
| 158 } | 158 } |
| 159 | 159 |
| 160 bool ClientSideDetectionService::IsBadIpAddress( | 160 bool ClientSideDetectionService::IsBadIpAddress( |
| 161 const std::string& ip_address) const { | 161 const std::string& ip_address) const { |
| 162 net::IPAddressNumber ip_number; | 162 net::IPAddressNumber ip_number; |
| 163 if (!net::ParseIPLiteralToNumber(ip_address, &ip_number)) { | 163 if (!net::ParseIPLiteralToNumber(ip_address, &ip_number)) { |
| 164 DLOG(WARNING) << "Unable to parse IP address: " << ip_address; | 164 VLOG(2) << "Unable to parse IP address: '" << ip_address << "'"; |
| 165 return false; | 165 return false; |
| 166 } | 166 } |
| 167 if (ip_number.size() == net::kIPv4AddressSize) { | 167 if (ip_number.size() == net::kIPv4AddressSize) { |
| 168 ip_number = net::ConvertIPv4NumberToIPv6Number(ip_number); | 168 ip_number = net::ConvertIPv4NumberToIPv6Number(ip_number); |
| 169 } | 169 } |
| 170 if (ip_number.size() != net::kIPv6AddressSize) { | 170 if (ip_number.size() != net::kIPv6AddressSize) { |
| 171 DLOG(WARNING) << "Unable to convert IPv4 address to IPv6: " << ip_address; | 171 VLOG(2) << "Unable to convert IPv4 address to IPv6: '" << ip_address << "'"; |
| 172 return false; // better safe than sorry. | 172 return false; // better safe than sorry. |
| 173 } | 173 } |
| 174 for (BadSubnetMap::const_iterator it = bad_subnets_.begin(); | 174 for (BadSubnetMap::const_iterator it = bad_subnets_.begin(); |
| 175 it != bad_subnets_.end(); ++it) { | 175 it != bad_subnets_.end(); ++it) { |
| 176 const std::string& mask = it->first; | 176 const std::string& mask = it->first; |
| 177 DCHECK_EQ(mask.size(), ip_number.size()); | 177 DCHECK_EQ(mask.size(), ip_number.size()); |
| 178 std::string subnet(net::kIPv6AddressSize, '.'); | 178 std::string subnet(net::kIPv6AddressSize, '.'); |
| 179 for (size_t i = 0; i < net::kIPv6AddressSize; ++i) { | 179 for (size_t i = 0; i < net::kIPv6AddressSize; ++i) { |
| 180 subnet[i] = ip_number[i] & mask[i]; | 180 subnet[i] = ip_number[i] & mask[i]; |
| 181 } | 181 } |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 &whitelist_patterns); | 648 &whitelist_patterns); |
| 649 for (size_t j = 0; j < whitelist_patterns.size(); ++j) { | 649 for (size_t j = 0; j < whitelist_patterns.size(); ++j) { |
| 650 if (whitelist_patterns[j] == canonical_url_as_pattern) { | 650 if (whitelist_patterns[j] == canonical_url_as_pattern) { |
| 651 return true; | 651 return true; |
| 652 } | 652 } |
| 653 } | 653 } |
| 654 } | 654 } |
| 655 return false; | 655 return false; |
| 656 } | 656 } |
| 657 } // namespace safe_browsing | 657 } // namespace safe_browsing |
| OLD | NEW |