| OLD | NEW |
| 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> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // NOTE(vakh): When adding a store here, add the corresponding store-specific | 32 // NOTE(vakh): When adding a store here, add the corresponding store-specific |
| 33 // histograms also. | 33 // histograms also. |
| 34 // NOTE(vakh): Delete file "AnyIpMalware.store". It has been renamed to | 34 // NOTE(vakh): Delete file "AnyIpMalware.store". It has been renamed to |
| 35 // "IpMalware.store". If it exists, it should be 75 bytes long. | 35 // "IpMalware.store". If it exists, it should be 75 bytes long. |
| 36 // The first argument to ListInfo specifies whether to sync hash prefixes for | 36 // The first argument to ListInfo specifies whether to sync hash prefixes for |
| 37 // that list. This can be false for two reasons: | 37 // that list. This can be false for two reasons: |
| 38 // - The server doesn't support that list yet. Once the server adds support | 38 // - The server doesn't support that list yet. Once the server adds support |
| 39 // for it, it can be changed to true. | 39 // for it, it can be changed to true. |
| 40 // - The list doesn't have hash prefixes to match. All requests lead to full | 40 // - The list doesn't have hash prefixes to match. All requests lead to full |
| 41 // hash checks. For instance: GetChromeUrlApiId() | 41 // hash checks. For instance: GetChromeUrlApiId() |
| 42 |
| 43 #if defined(GOOGLE_CHROME_BUILD) |
| 44 const bool kSyncOnlyOnChromeBuilds = true; |
| 45 #else |
| 46 const bool kSyncOnlyOnChromeBuilds = false; |
| 47 #endif |
| 48 const bool kSyncAlways = true; |
| 49 const bool kSyncNever = false; |
| 42 return ListInfos({ | 50 return ListInfos({ |
| 43 ListInfo(false, "CertCsdDownloadWhitelist.store", | 51 ListInfo(kSyncOnlyOnChromeBuilds, "CertCsdDownloadWhitelist.store", |
| 44 GetCertCsdDownloadWhitelistId(), SB_THREAT_TYPE_UNUSED), | 52 GetCertCsdDownloadWhitelistId(), SB_THREAT_TYPE_UNUSED), |
| 45 ListInfo(false, "ChromeFilenameClientIncident.store", | 53 ListInfo(kSyncOnlyOnChromeBuilds, "ChromeFilenameClientIncident.store", |
| 46 GetChromeFilenameClientIncidentId(), SB_THREAT_TYPE_UNUSED), | 54 GetChromeFilenameClientIncidentId(), SB_THREAT_TYPE_UNUSED), |
| 47 ListInfo(true, "IpMalware.store", GetIpMalwareId(), | 55 ListInfo(kSyncAlways, "IpMalware.store", GetIpMalwareId(), |
| 48 SB_THREAT_TYPE_UNUSED), | 56 SB_THREAT_TYPE_UNUSED), |
| 49 ListInfo(false, "UrlCsdDownloadWhitelist.store", | 57 ListInfo(kSyncOnlyOnChromeBuilds, "UrlCsdDownloadWhitelist.store", |
| 50 GetUrlCsdDownloadWhitelistId(), SB_THREAT_TYPE_UNUSED), | 58 GetUrlCsdDownloadWhitelistId(), SB_THREAT_TYPE_UNUSED), |
| 51 ListInfo(false, "UrlCsdWhitelist.store", GetUrlCsdWhitelistId(), | 59 ListInfo(kSyncOnlyOnChromeBuilds, "UrlCsdWhitelist.store", |
| 52 SB_THREAT_TYPE_UNUSED), | 60 GetUrlCsdWhitelistId(), SB_THREAT_TYPE_UNUSED), |
| 53 ListInfo(true, "UrlSoceng.store", GetUrlSocEngId(), | 61 ListInfo(kSyncAlways, "UrlSoceng.store", GetUrlSocEngId(), |
| 54 SB_THREAT_TYPE_URL_PHISHING), | 62 SB_THREAT_TYPE_URL_PHISHING), |
| 55 ListInfo(true, "UrlMalware.store", GetUrlMalwareId(), | 63 ListInfo(kSyncAlways, "UrlMalware.store", GetUrlMalwareId(), |
| 56 SB_THREAT_TYPE_URL_MALWARE), | 64 SB_THREAT_TYPE_URL_MALWARE), |
| 57 ListInfo(true, "UrlUws.store", GetUrlUwsId(), | 65 ListInfo(kSyncAlways, "UrlUws.store", GetUrlUwsId(), |
| 58 SB_THREAT_TYPE_URL_UNWANTED), | 66 SB_THREAT_TYPE_URL_UNWANTED), |
| 59 ListInfo(true, "UrlMalBin.store", GetUrlMalBinId(), | 67 ListInfo(kSyncAlways, "UrlMalBin.store", GetUrlMalBinId(), |
| 60 SB_THREAT_TYPE_BINARY_MALWARE_URL), | 68 SB_THREAT_TYPE_BINARY_MALWARE_URL), |
| 61 ListInfo(true, "ChromeExtMalware.store", GetChromeExtensionMalwareId(), | 69 ListInfo(kSyncAlways, "ChromeExtMalware.store", GetChromeExtMalwareId(), |
| 62 SB_THREAT_TYPE_EXTENSION), | 70 SB_THREAT_TYPE_EXTENSION), |
| 63 ListInfo(false, "ChromeUrlClientIncident.store", | 71 ListInfo(kSyncOnlyOnChromeBuilds, "ChromeUrlClientIncident.store", |
| 64 GetChromeUrlClientIncidentId(), | 72 GetChromeUrlClientIncidentId(), |
| 65 SB_THREAT_TYPE_BLACKLISTED_RESOURCE), | 73 SB_THREAT_TYPE_BLACKLISTED_RESOURCE), |
| 66 ListInfo(false, "", GetChromeUrlApiId(), SB_THREAT_TYPE_API_ABUSE), | 74 ListInfo(kSyncNever, "", GetChromeUrlApiId(), SB_THREAT_TYPE_API_ABUSE), |
| 67 }); | 75 }); |
| 68 } | 76 } |
| 69 | 77 |
| 70 // Returns the severity information about a given SafeBrowsing list. The lowest | 78 // Returns the severity information about a given SafeBrowsing list. The lowest |
| 71 // value is 0, which represents the most severe list. | 79 // value is 0, which represents the most severe list. |
| 72 ThreatSeverity GetThreatSeverity(const ListIdentifier& list_id) { | 80 ThreatSeverity GetThreatSeverity(const ListIdentifier& list_id) { |
| 73 switch (list_id.threat_type()) { | 81 switch (list_id.threat_type()) { |
| 74 case MALWARE_THREAT: | 82 case MALWARE_THREAT: |
| 75 case SOCIAL_ENGINEERING_PUBLIC: | 83 case SOCIAL_ENGINEERING_PUBLIC: |
| 76 return 0; | 84 return 0; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 const std::set<FullHash>& extension_ids, | 222 const std::set<FullHash>& extension_ids, |
| 215 Client* client) { | 223 Client* client) { |
| 216 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 224 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 217 | 225 |
| 218 if (!enabled_) { | 226 if (!enabled_) { |
| 219 return true; | 227 return true; |
| 220 } | 228 } |
| 221 | 229 |
| 222 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( | 230 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( |
| 223 client, ClientCallbackType::CHECK_EXTENSION_IDS, | 231 client, ClientCallbackType::CHECK_EXTENSION_IDS, |
| 224 StoresToCheck({GetChromeExtensionMalwareId()}), extension_ids); | 232 StoresToCheck({GetChromeExtMalwareId()}), extension_ids); |
| 225 | 233 |
| 226 return HandleCheck(std::move(check)); | 234 return HandleCheck(std::move(check)); |
| 227 } | 235 } |
| 228 | 236 |
| 229 bool V4LocalDatabaseManager::CheckResourceUrl(const GURL& url, Client* client) { | 237 bool V4LocalDatabaseManager::CheckResourceUrl(const GURL& url, Client* client) { |
| 230 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 238 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 231 | 239 |
| 232 if (!enabled_ || !CanCheckUrl(url)) { | 240 if (!enabled_ || !CanCheckUrl(url)) { |
| 233 return true; | 241 return true; |
| 234 } | 242 } |
| 235 | 243 |
| 236 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( | 244 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( |
| 237 client, ClientCallbackType::CHECK_RESOURCE_URL, | 245 client, ClientCallbackType::CHECK_RESOURCE_URL, |
| 238 StoresToCheck({GetChromeUrlClientIncidentId()}), | 246 StoresToCheck({GetChromeUrlClientIncidentId()}), |
| 239 std::vector<GURL>(1, url)); | 247 std::vector<GURL>(1, url)); |
| 240 | 248 |
| 241 return HandleCheck(std::move(check)); | 249 return HandleCheck(std::move(check)); |
| 242 } | 250 } |
| 243 | 251 |
| 244 bool V4LocalDatabaseManager::MatchCsdWhitelistUrl(const GURL& url) { | 252 bool V4LocalDatabaseManager::MatchCsdWhitelistUrl(const GURL& url) { |
| 245 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 253 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 254 |
| 255 if (!enabled_ || !v4_database_) { |
| 256 // To make sure we are conservative we return true. |
| 257 return true; |
| 258 } |
| 259 |
| 246 return HandleUrlSynchronously(url, StoresToCheck({GetUrlCsdWhitelistId()})); | 260 return HandleUrlSynchronously(url, StoresToCheck({GetUrlCsdWhitelistId()})); |
| 247 } | 261 } |
| 248 | 262 |
| 249 bool V4LocalDatabaseManager::MatchDownloadWhitelistString( | 263 bool V4LocalDatabaseManager::MatchDownloadWhitelistString( |
| 250 const std::string& str) { | 264 const std::string& str) { |
| 251 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 265 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 266 |
| 267 if (!enabled_ || !v4_database_) { |
| 268 // To make sure we are conservative we return true. |
| 269 return true; |
| 270 } |
| 271 |
| 252 return HandleHashSynchronously( | 272 return HandleHashSynchronously( |
| 253 str, StoresToCheck({GetCertCsdDownloadWhitelistId()})); | 273 str, StoresToCheck({GetCertCsdDownloadWhitelistId()})); |
| 254 } | 274 } |
| 255 | 275 |
| 256 bool V4LocalDatabaseManager::MatchDownloadWhitelistUrl(const GURL& url) { | 276 bool V4LocalDatabaseManager::MatchDownloadWhitelistUrl(const GURL& url) { |
| 257 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 277 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 278 |
| 279 if (!enabled_ || !v4_database_) { |
| 280 // To make sure we are conservative we return true. |
| 281 return true; |
| 282 } |
| 283 |
| 258 return HandleUrlSynchronously( | 284 return HandleUrlSynchronously( |
| 259 url, StoresToCheck({GetUrlCsdDownloadWhitelistId()})); | 285 url, StoresToCheck({GetUrlCsdDownloadWhitelistId()})); |
| 260 } | 286 } |
| 261 | 287 |
| 262 bool V4LocalDatabaseManager::MatchMalwareIP(const std::string& ip_address) { | 288 bool V4LocalDatabaseManager::MatchMalwareIP(const std::string& ip_address) { |
| 263 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 289 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 264 if (!enabled_) { | 290 if (!enabled_ || !v4_database_) { |
| 265 return false; | 291 return false; |
| 266 } | 292 } |
| 267 | 293 |
| 268 FullHash hashed_encoded_ip; | 294 FullHash hashed_encoded_ip; |
| 269 if (!V4ProtocolManagerUtil::IPAddressToEncodedIPV6Hash(ip_address, | 295 if (!V4ProtocolManagerUtil::IPAddressToEncodedIPV6Hash(ip_address, |
| 270 &hashed_encoded_ip)) { | 296 &hashed_encoded_ip)) { |
| 271 return false; | 297 return false; |
| 272 } | 298 } |
| 273 | 299 |
| 274 return HandleHashSynchronously(hashed_encoded_ip, | 300 return HandleHashSynchronously(hashed_encoded_ip, |
| 275 StoresToCheck({GetIpMalwareId()})); | 301 StoresToCheck({GetIpMalwareId()})); |
| 276 } | 302 } |
| 277 | 303 |
| 278 bool V4LocalDatabaseManager::MatchModuleWhitelistString( | 304 bool V4LocalDatabaseManager::MatchModuleWhitelistString( |
| 279 const std::string& str) { | 305 const std::string& str) { |
| 280 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 306 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 307 |
| 308 if (!enabled_ || !v4_database_) { |
| 309 // To make sure we are conservative we return true. |
| 310 return true; |
| 311 } |
| 312 |
| 281 return HandleHashSynchronously( | 313 return HandleHashSynchronously( |
| 282 str, StoresToCheck({GetChromeFilenameClientIncidentId()})); | 314 str, StoresToCheck({GetChromeFilenameClientIncidentId()})); |
| 283 } | 315 } |
| 284 | 316 |
| 285 ThreatSource V4LocalDatabaseManager::GetThreatSource() const { | 317 ThreatSource V4LocalDatabaseManager::GetThreatSource() const { |
| 286 return ThreatSource::LOCAL_PVER4; | 318 return ThreatSource::LOCAL_PVER4; |
| 287 } | 319 } |
| 288 | 320 |
| 289 bool V4LocalDatabaseManager::IsCsdWhitelistKillSwitchOn() { | 321 bool V4LocalDatabaseManager::IsCsdWhitelistKillSwitchOn() { |
| 290 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 322 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 full_hash_to_store_and_hash_prefixes)); | 523 full_hash_to_store_and_hash_prefixes)); |
| 492 | 524 |
| 493 return false; | 525 return false; |
| 494 } | 526 } |
| 495 | 527 |
| 496 bool V4LocalDatabaseManager::HandleHashSynchronously( | 528 bool V4LocalDatabaseManager::HandleHashSynchronously( |
| 497 const FullHash& hash, | 529 const FullHash& hash, |
| 498 const StoresToCheck& stores_to_check) { | 530 const StoresToCheck& stores_to_check) { |
| 499 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 531 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 500 | 532 |
| 501 if (!enabled_ || !v4_database_) { | |
| 502 return false; | |
| 503 } | |
| 504 | |
| 505 std::set<FullHash> hashes{hash}; | 533 std::set<FullHash> hashes{hash}; |
| 506 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( | 534 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( |
| 507 nullptr, ClientCallbackType::CHECK_OTHER, stores_to_check, hashes); | 535 nullptr, ClientCallbackType::CHECK_OTHER, stores_to_check, hashes); |
| 508 | 536 |
| 509 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; | 537 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; |
| 510 return GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes); | 538 return GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes); |
| 511 } | 539 } |
| 512 | 540 |
| 513 bool V4LocalDatabaseManager::HandleUrlSynchronously( | 541 bool V4LocalDatabaseManager::HandleUrlSynchronously( |
| 514 const GURL& url, | 542 const GURL& url, |
| 515 const StoresToCheck& stores_to_check) { | 543 const StoresToCheck& stores_to_check) { |
| 516 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 544 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 517 | 545 |
| 518 if (!enabled_ || !v4_database_) { | |
| 519 return false; | |
| 520 } | |
| 521 | |
| 522 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( | 546 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( |
| 523 nullptr, ClientCallbackType::CHECK_OTHER, stores_to_check, | 547 nullptr, ClientCallbackType::CHECK_OTHER, stores_to_check, |
| 524 std::vector<GURL>(1, url)); | 548 std::vector<GURL>(1, url)); |
| 525 | 549 |
| 526 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; | 550 FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes; |
| 527 return GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes); | 551 return GetPrefixMatches(check, &full_hash_to_store_and_hash_prefixes); |
| 528 } | 552 } |
| 529 | 553 |
| 530 void V4LocalDatabaseManager::OnFullHashResponse( | 554 void V4LocalDatabaseManager::OnFullHashResponse( |
| 531 std::unique_ptr<PendingCheck> pending_check, | 555 std::unique_ptr<PendingCheck> pending_check, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 } | 674 } |
| 651 | 675 |
| 652 void V4LocalDatabaseManager::UpdateRequestCompleted( | 676 void V4LocalDatabaseManager::UpdateRequestCompleted( |
| 653 std::unique_ptr<ParsedServerResponse> parsed_server_response) { | 677 std::unique_ptr<ParsedServerResponse> parsed_server_response) { |
| 654 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 678 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 655 v4_database_->ApplyUpdate(std::move(parsed_server_response), | 679 v4_database_->ApplyUpdate(std::move(parsed_server_response), |
| 656 db_updated_callback_); | 680 db_updated_callback_); |
| 657 } | 681 } |
| 658 | 682 |
| 659 } // namespace safe_browsing | 683 } // namespace safe_browsing |
| OLD | NEW |