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

Unified Diff: chrome/browser/safe_browsing/protocol_manager.cc

Issue 1543153002: Add a GetFullHashWithApis method to Protocol Manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/protocol_manager.cc
diff --git a/chrome/browser/safe_browsing/protocol_manager.cc b/chrome/browser/safe_browsing/protocol_manager.cc
index beeaf023ee19a5b08345824ac76ce397daab74bc..189d4c0aedf48dab0fe53dfd9736ea9d6482dd52 100644
--- a/chrome/browser/safe_browsing/protocol_manager.cc
+++ b/chrome/browser/safe_browsing/protocol_manager.cc
@@ -6,6 +6,7 @@
#include <utility>
+#include "base/base64.h"
#include "base/environment.h"
#include "base/logging.h"
#include "base/macros.h"
@@ -92,6 +93,9 @@ static const size_t kSbMaxBackOff = 8;
const char kUmaHashResponseMetricName[] = "SB2.GetHashResponseOrErrorCode";
+// The V4 URL prefix where browser fetches hashes from the V4 server.
+const char kSbV4UrlPrefix[] = "https://safebrowsing.googleapis.com/v4";
+
// The default SBProtocolManagerFactory.
class SBProtocolManagerFactoryImpl : public SBProtocolManagerFactory {
public:
@@ -196,6 +200,10 @@ SafeBrowsingProtocolManager::~SafeBrowsingProtocolManager() {
STLDeleteContainerPairFirstPointers(hash_requests_.begin(),
hash_requests_.end());
hash_requests_.clear();
+
+ STLDeleteContainerPairFirstPointers(v4_hash_requests_.begin(),
+ v4_hash_requests_.end());
+ v4_hash_requests_.clear();
}
// We can only have one update or chunk request outstanding, but there may be
@@ -231,6 +239,58 @@ void SafeBrowsingProtocolManager::GetFullHash(
fetcher->Start();
}
+std::string SafeBrowsingProtocolManager::GetV4HashRequest(
+ const std::vector<SBPrefix>& prefixes,
+ ThreatType threat_type) {
+ // Build the request. Client info and client states are not added to the
+ // request protocol buffer. Client info is passed as params in the url.
+ FindFullHashesRequest req;
+ ThreatInfo* info = req.mutable_threat_info();
+ info->add_threat_types(threat_type);
+ info->add_platform_types(CHROME_PLATFORM);
+ info->add_threat_entry_types(URL_EXPRESSION);
+ for (const SBPrefix& prefix : prefixes) {
+ std::string hash(reinterpret_cast<const char*>(&prefix), sizeof(SBPrefix));
+ info->add_threat_entries()->set_hash(hash);
+ }
+
+ // Serialize and Base64 encode.
+ std::string req_data, req_base64;
+ req.SerializeToString(&req_data);
+ base::Base64Encode(req_data, &req_base64);
+
+ return req_base64;
+}
+
+void SafeBrowsingProtocolManager::GetV4FullHashes(
+ const std::vector<SBPrefix>& prefixes,
+ ThreatType threat_type,
+ FullHashCallback callback) {
+ DCHECK(CalledOnValidThread());
+ // TODO(kcarattini): Implement backoff behavior.
+
+ std::string req_base64 = GetV4HashRequest(prefixes, threat_type);
+ GURL gethash_url = GetV4HashUrl(req_base64);
+
+ net::URLFetcher* fetcher =
+ net::URLFetcher::Create(url_fetcher_id_++, gethash_url,
+ net::URLFetcher::GET, this)
+ .release();
+ // TODO(kcarattini): Implement a new response processor.
+ v4_hash_requests_[fetcher] = FullHashDetails(callback,
+ false /* is_download */);
+
+ fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
+ fetcher->SetRequestContext(request_context_getter_.get());
+ fetcher->Start();
+}
+
+void SafeBrowsingProtocolManager::GetFullHashesWithApis(
+ const std::vector<SBPrefix>& prefixes,
+ FullHashCallback callback) {
+ GetV4FullHashes(prefixes, API_ABUSE, callback);
+}
+
void SafeBrowsingProtocolManager::GetNextUpdate() {
DCHECK(CalledOnValidThread());
if (request_.get() || request_type_ != NO_REQUEST)
@@ -761,6 +821,15 @@ GURL SafeBrowsingProtocolManager::GetHashUrl(bool is_extended_reporting) const {
return GURL(url);
}
+// The API hash call uses the pver4 Safe Browsing server.
+GURL SafeBrowsingProtocolManager::GetV4HashUrl(
+ const std::string& request_base64) const {
+ std::string url = SafeBrowsingProtocolManagerHelper::ComposePver4Url(
+ kSbV4UrlPrefix, "encodedFullHashes",
+ request_base64, client_name_, version_);
+ return GURL(url);
+}
+
GURL SafeBrowsingProtocolManager::NextChunkUrl(const std::string& url) const {
DCHECK(CalledOnValidThread());
std::string next_url;
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.h ('k') | chrome/browser/safe_browsing/protocol_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698