| 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 // Utilities for the SafeBrowsing code. | 5 // Utilities for the SafeBrowsing code. |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_ | 7 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_ |
| 8 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_ | 8 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_ |
| 9 | 9 |
| 10 #include <cstring> | 10 #include <cstring> |
| 11 #include <set> | |
| 12 #include <string> | 11 #include <string> |
| 13 #include <vector> | 12 #include <vector> |
| 14 | 13 |
| 15 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 16 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
| 18 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 19 #include "chrome/browser/safe_browsing/chunk_range.h" | 18 #include "chrome/browser/safe_browsing/chunk_range.h" |
| 19 #include "components/safe_browsing_db/safe_browsing_db_util.h" |
| 20 | 20 |
| 21 namespace safe_browsing { | 21 namespace safe_browsing { |
| 22 class ChunkData; | 22 class ChunkData; |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 class GURL; | 25 class GURL; |
| 26 | 26 |
| 27 // A truncated hash's type. | |
| 28 typedef uint32 SBPrefix; | |
| 29 | |
| 30 // Container for holding a chunk URL and the list it belongs to. | 27 // Container for holding a chunk URL and the list it belongs to. |
| 31 struct ChunkUrl { | 28 struct ChunkUrl { |
| 32 std::string url; | 29 std::string url; |
| 33 std::string list_name; | 30 std::string list_name; |
| 34 }; | 31 }; |
| 35 | 32 |
| 36 // A full hash. | |
| 37 union SBFullHash { | |
| 38 char full_hash[32]; | |
| 39 SBPrefix prefix; | |
| 40 }; | |
| 41 | |
| 42 inline bool SBFullHashEqual(const SBFullHash& a, const SBFullHash& b) { | |
| 43 return !memcmp(a.full_hash, b.full_hash, sizeof(a.full_hash)); | |
| 44 } | |
| 45 | |
| 46 inline bool SBFullHashLess(const SBFullHash& a, const SBFullHash& b) { | |
| 47 return memcmp(a.full_hash, b.full_hash, sizeof(a.full_hash)) < 0; | |
| 48 } | |
| 49 | |
| 50 // Generate full hash for the given string. | |
| 51 SBFullHash SBFullHashForString(const base::StringPiece& str); | |
| 52 | |
| 53 // Data for an individual chunk sent from the server. | 33 // Data for an individual chunk sent from the server. |
| 54 class SBChunkData { | 34 class SBChunkData { |
| 55 public: | 35 public: |
| 56 SBChunkData(); | 36 SBChunkData(); |
| 57 ~SBChunkData(); | 37 ~SBChunkData(); |
| 58 | 38 |
| 59 // Create with manufactured data, for testing only. | 39 // Create with manufactured data, for testing only. |
| 60 // TODO(shess): Right now the test code calling this is in an anonymous | 40 // TODO(shess): Right now the test code calling this is in an anonymous |
| 61 // namespace. Figure out how to shift this into private:. | 41 // namespace. Figure out how to shift this into private:. |
| 62 explicit SBChunkData(safe_browsing::ChunkData* chunk_data); | 42 explicit SBChunkData(safe_browsing::ChunkData* chunk_data); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // Container for deleting chunks from the database. | 95 // Container for deleting chunks from the database. |
| 116 struct SBChunkDelete { | 96 struct SBChunkDelete { |
| 117 SBChunkDelete(); | 97 SBChunkDelete(); |
| 118 ~SBChunkDelete(); | 98 ~SBChunkDelete(); |
| 119 | 99 |
| 120 std::string list_name; | 100 std::string list_name; |
| 121 bool is_sub_del; | 101 bool is_sub_del; |
| 122 std::vector<ChunkRange> chunk_del; | 102 std::vector<ChunkRange> chunk_del; |
| 123 }; | 103 }; |
| 124 | 104 |
| 125 // Different types of threats that SafeBrowsing protects against. | |
| 126 enum SBThreatType { | |
| 127 // No threat at all. | |
| 128 SB_THREAT_TYPE_SAFE, | |
| 129 | |
| 130 // The URL is being used for phishing. | |
| 131 SB_THREAT_TYPE_URL_PHISHING, | |
| 132 | |
| 133 // The URL hosts malware. | |
| 134 SB_THREAT_TYPE_URL_MALWARE, | |
| 135 | |
| 136 // The URL hosts unwanted programs. | |
| 137 SB_THREAT_TYPE_URL_UNWANTED, | |
| 138 | |
| 139 // The download URL is malware. | |
| 140 SB_THREAT_TYPE_BINARY_MALWARE_URL, | |
| 141 | |
| 142 // Url detected by the client-side phishing model. Note that unlike the | |
| 143 // above values, this does not correspond to a downloaded list. | |
| 144 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, | |
| 145 | |
| 146 // The Chrome extension or app (given by its ID) is malware. | |
| 147 SB_THREAT_TYPE_EXTENSION, | |
| 148 | |
| 149 // Url detected by the client-side malware IP list. This IP list is part | |
| 150 // of the client side detection model. | |
| 151 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL, | |
| 152 }; | |
| 153 | |
| 154 // Utility functions ----------------------------------------------------------- | 105 // Utility functions ----------------------------------------------------------- |
| 155 | 106 |
| 156 namespace safe_browsing_util { | 107 namespace safe_browsing_util { |
| 157 | 108 |
| 158 // SafeBrowsing list names. | 109 // SafeBrowsing list names. |
| 159 extern const char kMalwareList[]; | 110 extern const char kMalwareList[]; |
| 160 extern const char kPhishingList[]; | 111 extern const char kPhishingList[]; |
| 161 // Binary Download list name. | 112 // Binary Download list name. |
| 162 extern const char kBinUrlList[]; | 113 extern const char kBinUrlList[]; |
| 163 // SafeBrowsing client-side detection whitelist list name. | 114 // SafeBrowsing client-side detection whitelist list name. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 // Given a URL, returns all the hosts we need to check. They are returned | 167 // Given a URL, returns all the hosts we need to check. They are returned |
| 217 // in order of size (i.e. b.c is first, then a.b.c). | 168 // in order of size (i.e. b.c is first, then a.b.c). |
| 218 void GenerateHostsToCheck(const GURL& url, std::vector<std::string>* hosts); | 169 void GenerateHostsToCheck(const GURL& url, std::vector<std::string>* hosts); |
| 219 | 170 |
| 220 // Given a URL, returns all the paths we need to check. | 171 // Given a URL, returns all the paths we need to check. |
| 221 void GeneratePathsToCheck(const GURL& url, std::vector<std::string>* paths); | 172 void GeneratePathsToCheck(const GURL& url, std::vector<std::string>* paths); |
| 222 | 173 |
| 223 // Given a URL, returns all the patterns we need to check. | 174 // Given a URL, returns all the patterns we need to check. |
| 224 void GeneratePatternsToCheck(const GURL& url, std::vector<std::string>* urls); | 175 void GeneratePatternsToCheck(const GURL& url, std::vector<std::string>* urls); |
| 225 | 176 |
| 226 GURL GeneratePhishingReportUrl(const std::string& report_page, | |
| 227 const std::string& url_to_report, | |
| 228 bool is_client_side_detection); | |
| 229 | |
| 230 SBFullHash StringToSBFullHash(const std::string& hash_in); | 177 SBFullHash StringToSBFullHash(const std::string& hash_in); |
| 231 std::string SBFullHashToString(const SBFullHash& hash_out); | 178 std::string SBFullHashToString(const SBFullHash& hash_out); |
| 232 | 179 |
| 233 } // namespace safe_browsing_util | 180 } // namespace safe_browsing_util |
| 234 | 181 |
| 235 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_ | 182 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_ |
| OLD | NEW |