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

Side by Side Diff: components/safe_browsing_db/safe_browsing_db_util.h

Issue 1420053005: Move code in components/safe_browsing_db and chrome/browser/s_b/ under the safe_browsing namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@02_components_move
Patch Set: Remove '// namespace safe_browsing' for a small fwd decl block. Created 5 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
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // Utilities for the SafeBrowsing DB code.
6
7 #ifndef COMPONENTS_SAFE_BROWSING_DB_SAFE_BROWSING_DB_UTIL_H_
8 #define COMPONENTS_SAFE_BROWSING_DB_SAFE_BROWSING_DB_UTIL_H_
9
10 #include "base/basictypes.h"
11 #include "base/strings/string_piece.h"
12
13 class GURL;
14
15 namespace safe_browsing {
16
17 // SafeBrowsing list names.
18 extern const char kMalwareList[];
19 extern const char kPhishingList[];
20 // Binary Download list name.
21 extern const char kBinUrlList[];
22 // SafeBrowsing client-side detection whitelist list name.
23 extern const char kCsdWhiteList[];
24 // SafeBrowsing download whitelist list name.
25 extern const char kDownloadWhiteList[];
26 // SafeBrowsing extension list name.
27 extern const char kExtensionBlacklist[];
28 // SafeBrowsing csd malware IP blacklist name.
29 extern const char kIPBlacklist[];
30 // SafeBrowsing unwanted URL list.
31 extern const char kUnwantedUrlList[];
32 // SafeBrowsing off-domain inclusion whitelist list name.
33 extern const char kInclusionWhitelist[];
34 // This array must contain all Safe Browsing lists.
35 extern const char* kAllLists[9];
36
37
38 // Different types of threats that SafeBrowsing protects against.
39 enum SBThreatType {
40 // No threat at all.
41 SB_THREAT_TYPE_SAFE,
42
43 // The URL is being used for phishing.
44 SB_THREAT_TYPE_URL_PHISHING,
45
46 // The URL hosts malware.
47 SB_THREAT_TYPE_URL_MALWARE,
48
49 // The URL hosts unwanted programs.
50 SB_THREAT_TYPE_URL_UNWANTED,
51
52 // The download URL is malware.
53 SB_THREAT_TYPE_BINARY_MALWARE_URL,
54
55 // Url detected by the client-side phishing model. Note that unlike the
56 // above values, this does not correspond to a downloaded list.
57 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL,
58
59 // The Chrome extension or app (given by its ID) is malware.
60 SB_THREAT_TYPE_EXTENSION,
61
62 // Url detected by the client-side malware IP list. This IP list is part
63 // of the client side detection model.
64 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL,
65 };
66
67 enum ListType {
68 INVALID = -1,
69 MALWARE = 0,
70 PHISH = 1,
71 BINURL = 2,
72 // Obsolete BINHASH = 3,
73 CSDWHITELIST = 4,
74 // SafeBrowsing lists are stored in pairs. Keep ListType 5
75 // available for a potential second list that we would store in the
76 // csd-whitelist store file.
77 DOWNLOADWHITELIST = 6,
78 // See above comment. Leave 7 available.
79 EXTENSIONBLACKLIST = 8,
80 // See above comment. Leave 9 available.
81 // Obsolete SIDEEFFECTFREEWHITELIST = 10,
82 // See above comment. Leave 11 available.
83 IPBLACKLIST = 12,
84 // See above comment. Leave 13 available.
85 UNWANTEDURL = 14,
86 // See above comment. Leave 15 available.
87 INCLUSIONWHITELIST = 16,
88 // See above comment. Leave 17 available.
89 };
90
91 // Maps a list name to ListType.
92 ListType GetListId(const base::StringPiece& name);
93
94 // Maps a ListId to list name. Return false if fails.
95 bool GetListName(ListType list_id, std::string* list);
96
97
98 // A full hash.
99 union SBFullHash {
100 char full_hash[32];
101 SBPrefix prefix;
102 };
103
104 // Used when we get a gethash response.
105 struct SBFullHashResult {
106 SBFullHash hash;
107 ListType list_id;
108 std::string metadata;
109 };
110
111 // Caches individual response from GETHASH request.
112 struct SBCachedFullHashResult {
113 SBCachedFullHashResult();
114 explicit SBCachedFullHashResult(const base::Time& in_expire_after);
115 ~SBCachedFullHashResult();
116
117 base::Time expire_after;
118 std::vector<SBFullHashResult> full_hashes;
119 };
120
121 inline bool SBFullHashEqual(const SBFullHash& a, const SBFullHash& b) {
122 return !memcmp(a.full_hash, b.full_hash, sizeof(a.full_hash));
123 }
124
125 inline bool SBFullHashLess(const SBFullHash& a, const SBFullHash& b) {
126 return memcmp(a.full_hash, b.full_hash, sizeof(a.full_hash)) < 0;
127 }
128
129 // Generate full hash for the given string.
130 SBFullHash SBFullHashForString(const base::StringPiece& str);
131 SBFullHash StringToSBFullHash(const std::string& hash_in);
132 std::string SBFullHashToString(const SBFullHash& hash_out);
133
134 // Canonicalizes url as per Google Safe Browsing Specification.
135 // See section 6.1 in
136 // http://code.google.com/p/google-safe-browsing/wiki/Protocolv2Spec.
137 void CanonicalizeUrl(const GURL& url, std::string* canonicalized_hostname,
138 std::string* canonicalized_path,
139 std::string* canonicalized_query);
140
141 // Given a URL, returns all the hosts we need to check. They are returned
142 // in order of size (i.e. b.c is first, then a.b.c).
143 void GenerateHostsToCheck(const GURL& url, std::vector<std::string>* hosts);
144
145 // Given a URL, returns all the paths we need to check.
146 void GeneratePathsToCheck(const GURL& url, std::vector<std::string>* paths);
147
148 // Given a URL, returns all the patterns we need to check.
149 void GeneratePatternsToCheck(const GURL& url, std::vector<std::string>* urls);
150
151 } // namespace safe_browsing
152
153 #endif // COMPONENTS_SAFE_BROWSING_DB_SAFE_BROWSING_DB_UTIL_H_
OLDNEW
« no previous file with comments | « components/safe_browsing_db/prefix_set_unittest.cc ('k') | components/safe_browsing_db/safe_browsing_db_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698