| Index: components/safe_browsing_db/util.h
|
| diff --git a/chrome/browser/safe_browsing/safe_browsing_util.h b/components/safe_browsing_db/util.h
|
| similarity index 59%
|
| copy from chrome/browser/safe_browsing/safe_browsing_util.h
|
| copy to components/safe_browsing_db/util.h
|
| index b01f6a3d4e4607498e424d2f6cb2f3dc39b777b4..666e0815f5cf81a137705e5997a7ea243e9fc8c6 100644
|
| --- a/chrome/browser/safe_browsing/safe_browsing_util.h
|
| +++ b/components/safe_browsing_db/util.h
|
| @@ -1,68 +1,61 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
| //
|
| -// Utilities for the SafeBrowsing code.
|
| +// Utilities for the SafeBrowsing DB code.
|
|
|
| -#ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_
|
| -#define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_
|
| +#ifndef COMPONENTS_SAFE_BROWSING_DB_UTIL_H_
|
| +#define COMPONENTS_SAFE_BROWSING_DB_UTIL_H_
|
|
|
| #include <cstring>
|
| #include <string>
|
| #include <vector>
|
|
|
| #include "base/basictypes.h"
|
| -#include "base/memory/scoped_ptr.h"
|
| #include "base/strings/string_piece.h"
|
| #include "base/time/time.h"
|
| -#include "chrome/browser/safe_browsing/chunk_range.h"
|
| -#include "components/safe_browsing_db/safe_browsing_db_util.h"
|
|
|
| -namespace safe_browsing {
|
| -class ChunkData;
|
| -};
|
|
|
| class GURL;
|
|
|
| -// Container for holding a chunk URL and the list it belongs to.
|
| -struct ChunkUrl {
|
| - std::string url;
|
| - std::string list_name;
|
| +// Different types of threats that SafeBrowsing protects against.
|
| +enum SBThreatType {
|
| + // No threat at all.
|
| + SB_THREAT_TYPE_SAFE,
|
| +
|
| + // The URL is being used for phishing.
|
| + SB_THREAT_TYPE_URL_PHISHING,
|
| +
|
| + // The URL hosts malware.
|
| + SB_THREAT_TYPE_URL_MALWARE,
|
| +
|
| + // The URL hosts unwanted programs.
|
| + SB_THREAT_TYPE_URL_UNWANTED,
|
| +
|
| + // The download URL is malware.
|
| + SB_THREAT_TYPE_BINARY_MALWARE_URL,
|
| +
|
| + // Url detected by the client-side phishing model. Note that unlike the
|
| + // above values, this does not correspond to a downloaded list.
|
| + SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL,
|
| +
|
| + // The Chrome extension or app (given by its ID) is malware.
|
| + SB_THREAT_TYPE_EXTENSION,
|
| +
|
| + // Url detected by the client-side malware IP list. This IP list is part
|
| + // of the client side detection model.
|
| + SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL,
|
| };
|
|
|
| -// Data for an individual chunk sent from the server.
|
| -class SBChunkData {
|
| - public:
|
| - SBChunkData();
|
| - ~SBChunkData();
|
| -
|
| - // Create with manufactured data, for testing only.
|
| - // TODO(shess): Right now the test code calling this is in an anonymous
|
| - // namespace. Figure out how to shift this into private:.
|
| - explicit SBChunkData(safe_browsing::ChunkData* chunk_data);
|
| -
|
| - // Read serialized ChunkData, returning true if the parse suceeded.
|
| - bool ParseFrom(const unsigned char* data, size_t length);
|
| -
|
| - // Access the chunk data. |AddChunkNumberAt()| can only be called if
|
| - // |IsSub()| returns true. |Prefix*()| and |FullHash*()| can only be called
|
| - // if the corrosponding |Is*()| returned true.
|
| - int ChunkNumber() const;
|
| - bool IsAdd() const;
|
| - bool IsSub() const;
|
| - int AddChunkNumberAt(size_t i) const;
|
| - bool IsPrefix() const;
|
| - size_t PrefixCount() const;
|
| - SBPrefix PrefixAt(size_t i) const;
|
| - bool IsFullHash() const;
|
| - size_t FullHashCount() const;
|
| - SBFullHash FullHashAt(size_t i) const;
|
| -
|
| - private:
|
| - // Protocol buffer sent from server.
|
| - scoped_ptr<safe_browsing::ChunkData> chunk_data_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(SBChunkData);
|
| +
|
| +// TODO(vakh): Move all these declarations under safe_browsing namespace.
|
| +// A truncated hash's type.
|
| +typedef uint32 SBPrefix;
|
| +
|
| +// A full hash.
|
| +union SBFullHash {
|
| + char full_hash[32];
|
| + SBPrefix prefix;
|
| };
|
|
|
| // Used when we get a gethash response.
|
| @@ -83,28 +76,8 @@ struct SBCachedFullHashResult {
|
| std::vector<SBFullHashResult> full_hashes;
|
| };
|
|
|
| -// Contains information about a list in the database.
|
| -struct SBListChunkRanges {
|
| - explicit SBListChunkRanges(const std::string& n);
|
| -
|
| - std::string name; // The list name.
|
| - std::string adds; // The ranges for add chunks.
|
| - std::string subs; // The ranges for sub chunks.
|
| -};
|
| -
|
| -// Container for deleting chunks from the database.
|
| -struct SBChunkDelete {
|
| - SBChunkDelete();
|
| - ~SBChunkDelete();
|
| -
|
| - std::string list_name;
|
| - bool is_sub_del;
|
| - std::vector<ChunkRange> chunk_del;
|
| -};
|
| -
|
| -// Utility functions -----------------------------------------------------------
|
|
|
| -namespace safe_browsing_util {
|
| +namespace safe_browsing {
|
|
|
| // SafeBrowsing list names.
|
| extern const char kMalwareList[];
|
| @@ -123,10 +96,10 @@ extern const char kIPBlacklist[];
|
| extern const char kUnwantedUrlList[];
|
| // SafeBrowsing off-domain inclusion whitelist list name.
|
| extern const char kInclusionWhitelist[];
|
| -
|
| // This array must contain all Safe Browsing lists.
|
| extern const char* kAllLists[9];
|
|
|
| +
|
| enum ListType {
|
| INVALID = -1,
|
| MALWARE = 0,
|
| @@ -151,6 +124,21 @@ enum ListType {
|
| // See above comment. Leave 17 available.
|
| };
|
|
|
| +
|
| +inline bool SBFullHashEqual(const SBFullHash& a, const SBFullHash& b) {
|
| + return !memcmp(a.full_hash, b.full_hash, sizeof(a.full_hash));
|
| +}
|
| +
|
| +inline bool SBFullHashLess(const SBFullHash& a, const SBFullHash& b) {
|
| + return memcmp(a.full_hash, b.full_hash, sizeof(a.full_hash)) < 0;
|
| +}
|
| +
|
| +// Generate full hash for the given string.
|
| +SBFullHash SBFullHashForString(const base::StringPiece& str);
|
| +SBFullHash StringToSBFullHash(const std::string& hash_in);
|
| +std::string SBFullHashToString(const SBFullHash& hash_out);
|
| +
|
| +
|
| // Maps a list name to ListType.
|
| ListType GetListId(const base::StringPiece& name);
|
|
|
| @@ -174,9 +162,6 @@ void GeneratePathsToCheck(const GURL& url, std::vector<std::string>* paths);
|
| // Given a URL, returns all the patterns we need to check.
|
| void GeneratePatternsToCheck(const GURL& url, std::vector<std::string>* urls);
|
|
|
| -SBFullHash StringToSBFullHash(const std::string& hash_in);
|
| -std::string SBFullHashToString(const SBFullHash& hash_out);
|
| -
|
| -} // namespace safe_browsing_util
|
| +} // namespace safe_browsing
|
|
|
| -#endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_
|
| +#endif // COMPONENTS_SAFE_BROWSING_DB_UTIL_H_
|
|
|