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

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

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

Powered by Google App Engine
This is Rietveld 408576698