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

Side by Side Diff: components/safe_browsing_db/v4_local_database_manager.cc

Issue 2495783003: Implement support for checking bad IPs aka MatchMalwareIP (Closed)
Patch Set: Add a comma after the last enum value Created 4 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // This file should not be build on Android but is currently getting built. 5 // This file should not be build on Android but is currently getting built.
6 // TODO(vakh): Fix that: http://crbug.com/621647 6 // TODO(vakh): Fix that: http://crbug.com/621647
7 7
8 #include "components/safe_browsing_db/v4_local_database_manager.h" 8 #include "components/safe_browsing_db/v4_local_database_manager.h"
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "components/safe_browsing_db/v4_feature_list.h" 17 #include "components/safe_browsing_db/v4_feature_list.h"
18 #include "components/safe_browsing_db/v4_protocol_manager_util.h"
18 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
19 20
20 using content::BrowserThread; 21 using content::BrowserThread;
21 using base::TimeTicks; 22 using base::TimeTicks;
22 23
23 namespace safe_browsing { 24 namespace safe_browsing {
24 25
25 namespace { 26 namespace {
26 27
27 const ThreatSeverity kLeastSeverity = 28 const ThreatSeverity kLeastSeverity =
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 return true; 228 return true;
228 } 229 }
229 230
230 bool V4LocalDatabaseManager::MatchDownloadWhitelistUrl(const GURL& url) { 231 bool V4LocalDatabaseManager::MatchDownloadWhitelistUrl(const GURL& url) {
231 // TODO(vakh): Implement this skeleton. 232 // TODO(vakh): Implement this skeleton.
232 DCHECK_CURRENTLY_ON(BrowserThread::IO); 233 DCHECK_CURRENTLY_ON(BrowserThread::IO);
233 return true; 234 return true;
234 } 235 }
235 236
236 bool V4LocalDatabaseManager::MatchMalwareIP(const std::string& ip_address) { 237 bool V4LocalDatabaseManager::MatchMalwareIP(const std::string& ip_address) {
237 // TODO(vakh): Implement this skeleton.
238 DCHECK_CURRENTLY_ON(BrowserThread::IO); 238 DCHECK_CURRENTLY_ON(BrowserThread::IO);
239 return false; 239 if (!enabled_) {
240 return false;
241 }
242 FullHash hashed_encoded_ip;
243 if (!V4ProtocolManagerUtil::IPAddressToEncodedIPV6Hash(ip_address,
244 &hashed_encoded_ip)) {
245 return false;
246 }
247
248 std::set<FullHash> hashed_encoded_ips{hashed_encoded_ip};
249 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>(
250 nullptr, ClientCallbackType::CHECK_MALWARE_IP,
251 StoresToCheck({GetAnyIpMalwareId()}), hashed_encoded_ips);
252
253 // HandleCheckSynchronously() tells us whether the resource is safe.
254 return !HandleCheckSynchronously(std::move(check));
240 } 255 }
241 256
242 bool V4LocalDatabaseManager::MatchModuleWhitelistString( 257 bool V4LocalDatabaseManager::MatchModuleWhitelistString(
243 const std::string& str) { 258 const std::string& str) {
244 // TODO(vakh): Implement this skeleton. 259 // TODO(vakh): Implement this skeleton.
245 DCHECK_CURRENTLY_ON(BrowserThread::IO); 260 DCHECK_CURRENTLY_ON(BrowserThread::IO);
246 return true; 261 return true;
247 } 262 }
248 263
249 ThreatSource V4LocalDatabaseManager::GetThreatSource() const { 264 ThreatSource V4LocalDatabaseManager::GetThreatSource() const {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 const std::unique_ptr<PendingCheck>& check, 377 const std::unique_ptr<PendingCheck>& check,
363 FullHashToStoreAndHashPrefixesMap* full_hash_to_store_and_hash_prefixes) { 378 FullHashToStoreAndHashPrefixesMap* full_hash_to_store_and_hash_prefixes) {
364 DCHECK_CURRENTLY_ON(BrowserThread::IO); 379 DCHECK_CURRENTLY_ON(BrowserThread::IO);
365 380
366 DCHECK(enabled_); 381 DCHECK(enabled_);
367 DCHECK(v4_database_); 382 DCHECK(v4_database_);
368 383
369 const base::TimeTicks before = TimeTicks::Now(); 384 const base::TimeTicks before = TimeTicks::Now();
370 if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL || 385 if (check->client_callback_type == ClientCallbackType::CHECK_BROWSE_URL ||
371 check->client_callback_type == ClientCallbackType::CHECK_DOWNLOAD_URLS || 386 check->client_callback_type == ClientCallbackType::CHECK_DOWNLOAD_URLS ||
372 check->client_callback_type == ClientCallbackType::CHECK_EXTENSION_IDS) { 387 check->client_callback_type == ClientCallbackType::CHECK_EXTENSION_IDS ||
388 check->client_callback_type == ClientCallbackType::CHECK_MALWARE_IP) {
373 DCHECK(!check->full_hashes.empty()); 389 DCHECK(!check->full_hashes.empty());
374 390
375 full_hash_to_store_and_hash_prefixes->clear(); 391 full_hash_to_store_and_hash_prefixes->clear();
376 for (const auto& full_hash : check->full_hashes) { 392 for (const auto& full_hash : check->full_hashes) {
377 StoreAndHashPrefixes matched_store_and_hash_prefixes; 393 StoreAndHashPrefixes matched_store_and_hash_prefixes;
378 v4_database_->GetStoresMatchingFullHash(full_hash, check->stores_to_check, 394 v4_database_->GetStoresMatchingFullHash(full_hash, check->stores_to_check,
379 &matched_store_and_hash_prefixes); 395 &matched_store_and_hash_prefixes);
380 if (!matched_store_and_hash_prefixes.empty()) { 396 if (!matched_store_and_hash_prefixes.empty()) {
381 (*full_hash_to_store_and_hash_prefixes)[full_hash] = 397 (*full_hash_to_store_and_hash_prefixes)[full_hash] =
382 matched_store_and_hash_prefixes; 398 matched_store_and_hash_prefixes;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 if (!GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes)) { 462 if (!GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes)) {
447 return true; 463 return true;
448 } 464 }
449 465
450 // Post on the IO thread to enforce async behavior. 466 // Post on the IO thread to enforce async behavior.
451 BrowserThread::PostTask( 467 BrowserThread::PostTask(
452 BrowserThread::IO, FROM_HERE, 468 BrowserThread::IO, FROM_HERE,
453 base::Bind(&V4LocalDatabaseManager::PerformFullHashCheck, this, 469 base::Bind(&V4LocalDatabaseManager::PerformFullHashCheck, this,
454 base::Passed(std::move(check)), 470 base::Passed(std::move(check)),
455 full_hash_to_store_and_hash_prefixes)); 471 full_hash_to_store_and_hash_prefixes));
472
456 return false; 473 return false;
457 } 474 }
458 475
476 bool V4LocalDatabaseManager::HandleCheckSynchronously(
477 std::unique_ptr<PendingCheck> check) {
478 if (!v4_database_) {
479 return true;
480 }
481
482 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes;
483 return !GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes);
484 }
485
459 void V4LocalDatabaseManager::OnFullHashResponse( 486 void V4LocalDatabaseManager::OnFullHashResponse(
460 std::unique_ptr<PendingCheck> pending_check, 487 std::unique_ptr<PendingCheck> pending_check,
461 const std::vector<FullHashInfo>& full_hash_infos) { 488 const std::vector<FullHashInfo>& full_hash_infos) {
462 DCHECK_CURRENTLY_ON(BrowserThread::IO); 489 DCHECK_CURRENTLY_ON(BrowserThread::IO);
463 490
464 if (!enabled_) { 491 if (!enabled_) {
465 DCHECK(pending_clients_.empty()); 492 DCHECK(pending_clients_.empty());
466 return; 493 return;
467 } 494 }
468 495
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 } 606 }
580 607
581 void V4LocalDatabaseManager::UpdateRequestCompleted( 608 void V4LocalDatabaseManager::UpdateRequestCompleted(
582 std::unique_ptr<ParsedServerResponse> parsed_server_response) { 609 std::unique_ptr<ParsedServerResponse> parsed_server_response) {
583 DCHECK_CURRENTLY_ON(BrowserThread::IO); 610 DCHECK_CURRENTLY_ON(BrowserThread::IO);
584 v4_database_->ApplyUpdate(std::move(parsed_server_response), 611 v4_database_->ApplyUpdate(std::move(parsed_server_response),
585 db_updated_callback_); 612 db_updated_callback_);
586 } 613 }
587 614
588 } // namespace safe_browsing 615 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698