| OLD | NEW |
| 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/safe_browsing_database.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <iterator> | 11 #include <iterator> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 19 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
| 20 #include "base/process/process_handle.h" | 20 #include "base/process/process_handle.h" |
| 21 #include "base/process/process_metrics.h" | 21 #include "base/process/process_metrics.h" |
| 22 #include "base/sha1.h" | 22 #include "base/sha1.h" |
| 23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 28 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" | 28 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" |
| 29 #include "components/safe_browsing_db/prefix_set.h" | 29 #include "components/safe_browsing_db/prefix_set.h" |
| 30 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
| 30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 31 #include "crypto/sha2.h" | 32 #include "crypto/sha2.h" |
| 32 #include "net/base/ip_address.h" | 33 #include "net/base/ip_address.h" |
| 33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 34 | 35 |
| 35 #if defined(OS_MACOSX) | 36 #if defined(OS_MACOSX) |
| 36 #include "base/mac/mac_util.h" | 37 #include "base/mac/mac_util.h" |
| 37 #endif | 38 #endif |
| 38 | 39 |
| 39 using content::BrowserThread; | 40 using content::BrowserThread; |
| (...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 | 952 |
| 952 if (!extension_blacklist_store_) | 953 if (!extension_blacklist_store_) |
| 953 return false; | 954 return false; |
| 954 | 955 |
| 955 return MatchAddPrefixes(extension_blacklist_store_.get(), | 956 return MatchAddPrefixes(extension_blacklist_store_.get(), |
| 956 EXTENSIONBLACKLIST % 2, prefixes, prefix_hits); | 957 EXTENSIONBLACKLIST % 2, prefixes, prefix_hits); |
| 957 } | 958 } |
| 958 | 959 |
| 959 bool SafeBrowsingDatabaseNew::ContainsMalwareIP(const std::string& ip_address) { | 960 bool SafeBrowsingDatabaseNew::ContainsMalwareIP(const std::string& ip_address) { |
| 960 net::IPAddress address; | 961 net::IPAddress address; |
| 961 if (!address.AssignFromIPLiteral(ip_address)) | 962 if (!V4ProtocolManagerUtil::GetIPV6AddressFromString(ip_address, &address)) { |
| 962 return false; | 963 return false; |
| 963 if (address.IsIPv4()) | 964 } |
| 964 address = net::ConvertIPv4ToIPv4MappedIPv6(address); | |
| 965 if (!address.IsIPv6()) | |
| 966 return false; // better safe than sorry. | |
| 967 | 965 |
| 968 std::unique_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction(); | 966 std::unique_ptr<ReadTransaction> txn = state_manager_.BeginReadTransaction(); |
| 969 const IPBlacklist* ip_blacklist = txn->ip_blacklist(); | 967 const IPBlacklist* ip_blacklist = txn->ip_blacklist(); |
| 970 for (IPBlacklist::const_iterator it = ip_blacklist->begin(); | 968 for (IPBlacklist::const_iterator it = ip_blacklist->begin(); |
| 971 it != ip_blacklist->end(); ++it) { | 969 it != ip_blacklist->end(); ++it) { |
| 972 const std::string& mask = it->first; | 970 const std::string& mask = it->first; |
| 973 DCHECK_EQ(mask.size(), address.size()); | 971 DCHECK_EQ(mask.size(), address.size()); |
| 974 std::string subnet(net::IPAddress::kIPv6AddressSize, '\0'); | 972 std::string subnet(net::IPAddress::kIPv6AddressSize, '\0'); |
| 975 for (size_t i = 0; i < net::IPAddress::kIPv6AddressSize; ++i) { | 973 for (size_t i = 0; i < net::IPAddress::kIPv6AddressSize; ++i) { |
| 976 subnet[i] = address.bytes()[i] & mask[i]; | 974 subnet[i] = address.bytes()[i] & mask[i]; |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1877 | 1875 |
| 1878 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. | 1876 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. |
| 1879 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( | 1877 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( |
| 1880 histogram_name, 1, 1000000, 50, | 1878 histogram_name, 1, 1000000, 50, |
| 1881 base::HistogramBase::kUmaTargetedHistogramFlag); | 1879 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 1882 | 1880 |
| 1883 histogram_pointer->Add(file_size_kilobytes); | 1881 histogram_pointer->Add(file_size_kilobytes); |
| 1884 } | 1882 } |
| 1885 | 1883 |
| 1886 } // namespace safe_browsing | 1884 } // namespace safe_browsing |
| OLD | NEW |