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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 StoresToCheck({GetChromeExtMalwareId()}), extension_ids); | 249 StoresToCheck({GetChromeExtMalwareId()}), extension_ids); |
250 | 250 |
251 return HandleCheck(std::move(check)); | 251 return HandleCheck(std::move(check)); |
252 } | 252 } |
253 | 253 |
254 bool V4LocalDatabaseManager::CheckResourceUrl(const GURL& url, Client* client) { | 254 bool V4LocalDatabaseManager::CheckResourceUrl(const GURL& url, Client* client) { |
255 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 255 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
256 | 256 |
257 StoresToCheck stores_to_check({GetChromeUrlClientIncidentId()}); | 257 StoresToCheck stores_to_check({GetChromeUrlClientIncidentId()}); |
258 | 258 |
259 if (!CanCheckUrl(url) || !AreStoresAvailableNow(stores_to_check)) { | 259 if (!CanCheckUrl(url) || !AreAllStoresAvailableNow(stores_to_check)) { |
260 // Fail open: Mark resource as safe immediately. | 260 // Fail open: Mark resource as safe immediately. |
261 // TODO(nparker): This should queue the request if the DB isn't yet | 261 // TODO(nparker): This should queue the request if the DB isn't yet |
262 // loaded, and later decide if this store is available. | 262 // loaded, and later decide if this store is available. |
263 // Currently this is the only store that requires full-hash-checks | 263 // Currently this is the only store that requires full-hash-checks |
264 // AND isn't supported on Chromium, so it's unique. | 264 // AND isn't supported on Chromium, so it's unique. |
265 return true; | 265 return true; |
266 } | 266 } |
267 | 267 |
268 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( | 268 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( |
269 client, ClientCallbackType::CHECK_RESOURCE_URL, stores_to_check, | 269 client, ClientCallbackType::CHECK_RESOURCE_URL, stores_to_check, |
270 std::vector<GURL>(1, url)); | 270 std::vector<GURL>(1, url)); |
271 | 271 |
272 return HandleCheck(std::move(check)); | 272 return HandleCheck(std::move(check)); |
273 } | 273 } |
274 | 274 |
275 bool V4LocalDatabaseManager::CheckUrlForSubresourceFilter(const GURL& url, | 275 bool V4LocalDatabaseManager::CheckUrlForSubresourceFilter(const GURL& url, |
276 Client* client) { | 276 Client* client) { |
277 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 277 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
278 | 278 |
279 StoresToCheck stores_to_check({GetUrlSubresourceFilterId()}); | 279 StoresToCheck stores_to_check( |
280 if (!AreStoresAvailableNow(stores_to_check) || !CanCheckUrl(url)) { | 280 {GetUrlSocEngId(), GetUrlSubresourceFilterId()}); |
| 281 if (!AreAnyStoresAvailableNow(stores_to_check) || !CanCheckUrl(url)) { |
281 return true; | 282 return true; |
282 } | 283 } |
283 | 284 |
284 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( | 285 std::unique_ptr<PendingCheck> check = base::MakeUnique<PendingCheck>( |
285 client, ClientCallbackType::CHECK_URL_FOR_SUBRESOURCE_FILTER, | 286 client, ClientCallbackType::CHECK_URL_FOR_SUBRESOURCE_FILTER, |
286 stores_to_check, std::vector<GURL>(1, url)); | 287 stores_to_check, std::vector<GURL>(1, url)); |
287 | 288 |
288 return HandleCheck(std::move(check)); | 289 return HandleCheck(std::move(check)); |
289 } | 290 } |
290 | 291 |
291 bool V4LocalDatabaseManager::MatchCsdWhitelistUrl(const GURL& url) { | 292 bool V4LocalDatabaseManager::MatchCsdWhitelistUrl(const GURL& url) { |
292 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 293 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
293 | 294 |
294 StoresToCheck stores_to_check({GetUrlCsdWhitelistId()}); | 295 StoresToCheck stores_to_check({GetUrlCsdWhitelistId()}); |
295 if (!AreStoresAvailableNow(stores_to_check)) { | 296 if (!AreAllStoresAvailableNow(stores_to_check)) { |
296 // Fail open: Whitelist everything. Otherwise we may run the | 297 // Fail open: Whitelist everything. Otherwise we may run the |
297 // CSD phishing/malware detector on popular domains and generate | 298 // CSD phishing/malware detector on popular domains and generate |
298 // undue load on the client and server. This has the effect of disabling | 299 // undue load on the client and server. This has the effect of disabling |
299 // CSD phishing/malware detection until the store is first synced. | 300 // CSD phishing/malware detection until the store is first synced. |
300 return true; | 301 return true; |
301 } | 302 } |
302 | 303 |
303 return HandleUrlSynchronously(url, stores_to_check); | 304 return HandleUrlSynchronously(url, stores_to_check); |
304 } | 305 } |
305 | 306 |
306 bool V4LocalDatabaseManager::MatchDownloadWhitelistString( | 307 bool V4LocalDatabaseManager::MatchDownloadWhitelistString( |
307 const std::string& str) { | 308 const std::string& str) { |
308 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 309 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
309 | 310 |
310 StoresToCheck stores_to_check({GetCertCsdDownloadWhitelistId()}); | 311 StoresToCheck stores_to_check({GetCertCsdDownloadWhitelistId()}); |
311 if (!AreStoresAvailableNow(stores_to_check)) { | 312 if (!AreAllStoresAvailableNow(stores_to_check)) { |
312 // Fail close: Whitelist nothing. This may generate download-protection | 313 // Fail close: Whitelist nothing. This may generate download-protection |
313 // pings for whitelisted binaries, but that's fine. | 314 // pings for whitelisted binaries, but that's fine. |
314 return false; | 315 return false; |
315 } | 316 } |
316 | 317 |
317 return HandleHashSynchronously(str, stores_to_check); | 318 return HandleHashSynchronously(str, stores_to_check); |
318 } | 319 } |
319 | 320 |
320 bool V4LocalDatabaseManager::MatchDownloadWhitelistUrl(const GURL& url) { | 321 bool V4LocalDatabaseManager::MatchDownloadWhitelistUrl(const GURL& url) { |
321 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 322 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
322 | 323 |
323 StoresToCheck stores_to_check({GetUrlCsdDownloadWhitelistId()}); | 324 StoresToCheck stores_to_check({GetUrlCsdDownloadWhitelistId()}); |
324 if (!AreStoresAvailableNow(stores_to_check)) { | 325 if (!AreAllStoresAvailableNow(stores_to_check)) { |
325 // Fail close: Whitelist nothing. This may generate download-protection | 326 // Fail close: Whitelist nothing. This may generate download-protection |
326 // pings for whitelisted domains, but that's fine. | 327 // pings for whitelisted domains, but that's fine. |
327 return false; | 328 return false; |
328 } | 329 } |
329 | 330 |
330 return HandleUrlSynchronously(url, stores_to_check); | 331 return HandleUrlSynchronously(url, stores_to_check); |
331 } | 332 } |
332 | 333 |
333 bool V4LocalDatabaseManager::MatchMalwareIP(const std::string& ip_address) { | 334 bool V4LocalDatabaseManager::MatchMalwareIP(const std::string& ip_address) { |
334 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 335 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
335 if (!enabled_ || !v4_database_) { | 336 if (!enabled_ || !v4_database_) { |
336 return false; | 337 return false; |
337 } | 338 } |
338 | 339 |
339 FullHash hashed_encoded_ip; | 340 FullHash hashed_encoded_ip; |
340 if (!V4ProtocolManagerUtil::IPAddressToEncodedIPV6Hash(ip_address, | 341 if (!V4ProtocolManagerUtil::IPAddressToEncodedIPV6Hash(ip_address, |
341 &hashed_encoded_ip)) { | 342 &hashed_encoded_ip)) { |
342 return false; | 343 return false; |
343 } | 344 } |
344 | 345 |
345 return HandleHashSynchronously(hashed_encoded_ip, | 346 return HandleHashSynchronously(hashed_encoded_ip, |
346 StoresToCheck({GetIpMalwareId()})); | 347 StoresToCheck({GetIpMalwareId()})); |
347 } | 348 } |
348 | 349 |
349 bool V4LocalDatabaseManager::MatchModuleWhitelistString( | 350 bool V4LocalDatabaseManager::MatchModuleWhitelistString( |
350 const std::string& str) { | 351 const std::string& str) { |
351 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 352 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
352 | 353 |
353 StoresToCheck stores_to_check({GetChromeFilenameClientIncidentId()}); | 354 StoresToCheck stores_to_check({GetChromeFilenameClientIncidentId()}); |
354 if (!AreStoresAvailableNow(stores_to_check)) { | 355 if (!AreAllStoresAvailableNow(stores_to_check)) { |
355 // Fail open: Whitelist everything. This has the effect of marking | 356 // Fail open: Whitelist everything. This has the effect of marking |
356 // all DLLs as safe until the DB is synced and loaded. | 357 // all DLLs as safe until the DB is synced and loaded. |
357 return true; | 358 return true; |
358 } | 359 } |
359 | 360 |
360 // str is the module's filename. Convert to hash. | 361 // str is the module's filename. Convert to hash. |
361 FullHash hash = crypto::SHA256HashString(str); | 362 FullHash hash = crypto::SHA256HashString(str); |
362 return HandleHashSynchronously(hash, stores_to_check); | 363 return HandleHashSynchronously(hash, stores_to_check); |
363 } | 364 } |
364 | 365 |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 extended_reporting_level_callback_); | 751 extended_reporting_level_callback_); |
751 } | 752 } |
752 | 753 |
753 void V4LocalDatabaseManager::UpdateRequestCompleted( | 754 void V4LocalDatabaseManager::UpdateRequestCompleted( |
754 std::unique_ptr<ParsedServerResponse> parsed_server_response) { | 755 std::unique_ptr<ParsedServerResponse> parsed_server_response) { |
755 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 756 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
756 v4_database_->ApplyUpdate(std::move(parsed_server_response), | 757 v4_database_->ApplyUpdate(std::move(parsed_server_response), |
757 db_updated_callback_); | 758 db_updated_callback_); |
758 } | 759 } |
759 | 760 |
760 bool V4LocalDatabaseManager::AreStoresAvailableNow( | 761 bool V4LocalDatabaseManager::AreAllStoresAvailableNow( |
761 const StoresToCheck& stores_to_check) const { | 762 const StoresToCheck& stores_to_check) const { |
762 return enabled_ && v4_database_ && | 763 return enabled_ && v4_database_ && |
763 v4_database_->AreStoresAvailable(stores_to_check); | 764 v4_database_->AreAllStoresAvailable(stores_to_check); |
| 765 } |
| 766 |
| 767 bool V4LocalDatabaseManager::AreAnyStoresAvailableNow( |
| 768 const StoresToCheck& stores_to_check) const { |
| 769 return enabled_ && v4_database_ && |
| 770 v4_database_->AreAnyStoresAvailable(stores_to_check); |
764 } | 771 } |
765 | 772 |
766 } // namespace safe_browsing | 773 } // namespace safe_browsing |
OLD | NEW |