Chromium Code Reviews| 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 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | 5 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base64url.h" | 9 #include "base/base64url.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 base::Time positive_expiry; | 534 base::Time positive_expiry; |
| 535 if (match.has_cache_duration()) { | 535 if (match.has_cache_duration()) { |
| 536 // Seconds resolution is good enough so we ignore the nanos field. | 536 // Seconds resolution is good enough so we ignore the nanos field. |
| 537 positive_expiry = clock_->Now() + TimeDelta::FromSeconds( | 537 positive_expiry = clock_->Now() + TimeDelta::FromSeconds( |
| 538 match.cache_duration().seconds()); | 538 match.cache_duration().seconds()); |
| 539 } else { | 539 } else { |
| 540 positive_expiry = clock_->Now() - base::TimeDelta::FromSeconds(1); | 540 positive_expiry = clock_->Now() - base::TimeDelta::FromSeconds(1); |
| 541 } | 541 } |
| 542 FullHashInfo full_hash_info(match.threat().hash(), list_id, | 542 FullHashInfo full_hash_info(match.threat().hash(), list_id, |
| 543 positive_expiry); | 543 positive_expiry); |
| 544 if (!ParseMetadata(match, &full_hash_info.metadata)) { | 544 ParseMetadata(match, &full_hash_info.metadata); |
| 545 return false; | |
| 546 } | |
| 547 | |
| 548 full_hash_infos->push_back(full_hash_info); | 545 full_hash_infos->push_back(full_hash_info); |
|
Nathan Parker
2016/10/27 22:06:49
Do we want to add this full_hash_info if the metad
vakh (use Gerrit instead)
2016/10/27 22:40:04
Yes, we still want to. See the scenario in: http:/
| |
| 549 } | 546 } |
| 550 return true; | 547 return true; |
| 551 } | 548 } |
| 552 | 549 |
| 553 bool V4GetHashProtocolManager::ParseMetadata(const ThreatMatch& match, | 550 // static |
| 551 void V4GetHashProtocolManager::ParseMetadata(const ThreatMatch& match, | |
| 554 ThreatMetadata* metadata) { | 552 ThreatMetadata* metadata) { |
| 555 // Different threat types will handle the metadata differently. | 553 // Different threat types will handle the metadata differently. |
| 556 if (match.threat_type() == API_ABUSE) { | 554 if (match.threat_type() == API_ABUSE) { |
| 557 if (!match.has_platform_type() || | 555 if (!match.has_platform_type() || |
| 558 match.platform_type() != CHROME_PLATFORM) { | 556 match.platform_type() != CHROME_PLATFORM) { |
| 559 RecordParseGetHashResult(UNEXPECTED_PLATFORM_TYPE_ERROR); | 557 RecordParseGetHashResult(UNEXPECTED_PLATFORM_TYPE_ERROR); |
| 560 return false; | 558 return; |
| 561 } | 559 } |
| 562 | 560 |
| 563 if (!match.has_threat_entry_metadata()) { | 561 if (!match.has_threat_entry_metadata()) { |
| 564 RecordParseGetHashResult(NO_METADATA_ERROR); | 562 RecordParseGetHashResult(NO_METADATA_ERROR); |
| 565 return false; | 563 return; |
| 566 } | 564 } |
| 567 // For API Abuse, store a list of the returned permissions. | 565 // For API Abuse, store a list of the returned permissions. |
| 568 for (const ThreatEntryMetadata::MetadataEntry& m : | 566 for (const ThreatEntryMetadata::MetadataEntry& m : |
| 569 match.threat_entry_metadata().entries()) { | 567 match.threat_entry_metadata().entries()) { |
| 570 if (m.key() != kPermission) { | 568 if (m.key() != kPermission) { |
| 571 RecordParseGetHashResult(UNEXPECTED_METADATA_VALUE_ERROR); | 569 RecordParseGetHashResult(UNEXPECTED_METADATA_VALUE_ERROR); |
| 572 return false; | 570 return; |
| 573 } | 571 } |
| 574 metadata->api_permissions.insert(m.value()); | 572 metadata->api_permissions.insert(m.value()); |
| 575 } | 573 } |
| 576 } else if (match.threat_type() == MALWARE_THREAT || | 574 } else if (match.threat_type() == MALWARE_THREAT || |
| 577 match.threat_type() == POTENTIALLY_HARMFUL_APPLICATION) { | 575 match.threat_type() == POTENTIALLY_HARMFUL_APPLICATION) { |
| 578 for (const ThreatEntryMetadata::MetadataEntry& m : | 576 for (const ThreatEntryMetadata::MetadataEntry& m : |
| 579 match.threat_entry_metadata().entries()) { | 577 match.threat_entry_metadata().entries()) { |
| 580 // TODO: Need to confirm the below key/value pairs with CSD backend. | 578 // TODO: Need to confirm the below key/value pairs with CSD backend. |
|
Nathan Parker
2016/10/27 22:06:49
Is this TODO still valid?
vakh (use Gerrit instead)
2016/10/27 22:40:05
Yes, I'll check with the CSD folks.
| |
| 581 if (m.key() == kPhaPatternType || m.key() == kMalwarePatternType) { | 579 if (m.key() == kPhaPatternType || m.key() == kMalwarePatternType) { |
| 582 if (m.value() == kLanding) { | 580 if (m.value() == kLanding) { |
| 583 metadata->threat_pattern_type = ThreatPatternType::MALWARE_LANDING; | 581 metadata->threat_pattern_type = ThreatPatternType::MALWARE_LANDING; |
| 584 break; | 582 break; |
| 585 } else if (m.value() == kDistribution) { | 583 } else if (m.value() == kDistribution) { |
| 586 metadata->threat_pattern_type = | 584 metadata->threat_pattern_type = |
| 587 ThreatPatternType::MALWARE_DISTRIBUTION; | 585 ThreatPatternType::MALWARE_DISTRIBUTION; |
| 588 break; | 586 break; |
| 589 } else { | 587 } else { |
| 590 RecordParseGetHashResult(UNEXPECTED_METADATA_VALUE_ERROR); | 588 RecordParseGetHashResult(UNEXPECTED_METADATA_VALUE_ERROR); |
| 591 return false; | 589 return; |
| 592 } | 590 } |
| 593 } | 591 } |
| 594 } | 592 } |
| 595 } else if (match.threat_type() == SOCIAL_ENGINEERING_PUBLIC) { | 593 } else if (match.threat_type() == SOCIAL_ENGINEERING_PUBLIC) { |
| 596 for (const ThreatEntryMetadata::MetadataEntry& m : | 594 for (const ThreatEntryMetadata::MetadataEntry& m : |
| 597 match.threat_entry_metadata().entries()) { | 595 match.threat_entry_metadata().entries()) { |
| 598 if (m.key() == kSePatternType) { | 596 if (m.key() == kSePatternType) { |
| 599 if (m.value() == kSocialEngineeringAds) { | 597 if (m.value() == kSocialEngineeringAds) { |
| 600 metadata->threat_pattern_type = | 598 metadata->threat_pattern_type = |
| 601 ThreatPatternType::SOCIAL_ENGINEERING_ADS; | 599 ThreatPatternType::SOCIAL_ENGINEERING_ADS; |
| 602 break; | 600 break; |
| 603 } else if (m.value() == kSocialEngineeringLanding) { | 601 } else if (m.value() == kSocialEngineeringLanding) { |
| 604 metadata->threat_pattern_type = | 602 metadata->threat_pattern_type = |
| 605 ThreatPatternType::SOCIAL_ENGINEERING_LANDING; | 603 ThreatPatternType::SOCIAL_ENGINEERING_LANDING; |
| 606 break; | 604 break; |
| 607 } else if (m.value() == kPhishing) { | 605 } else if (m.value() == kPhishing) { |
| 608 metadata->threat_pattern_type = ThreatPatternType::PHISHING; | 606 metadata->threat_pattern_type = ThreatPatternType::PHISHING; |
| 609 break; | 607 break; |
| 610 } else { | 608 } else { |
| 611 RecordParseGetHashResult(UNEXPECTED_METADATA_VALUE_ERROR); | 609 RecordParseGetHashResult(UNEXPECTED_METADATA_VALUE_ERROR); |
| 612 return false; | 610 return; |
| 613 } | 611 } |
| 614 } | 612 } |
| 615 } | 613 } |
| 616 } else { | 614 } else if (match.has_threat_entry_metadata() && |
| 615 match.threat_entry_metadata().entries_size() > 1) { | |
| 617 RecordParseGetHashResult(UNEXPECTED_THREAT_TYPE_ERROR); | 616 RecordParseGetHashResult(UNEXPECTED_THREAT_TYPE_ERROR); |
| 618 return false; | |
| 619 } | 617 } |
| 620 | |
| 621 return true; | |
| 622 } | 618 } |
| 623 | 619 |
| 624 void V4GetHashProtocolManager::ResetGetHashErrors() { | 620 void V4GetHashProtocolManager::ResetGetHashErrors() { |
| 625 gethash_error_count_ = 0; | 621 gethash_error_count_ = 0; |
| 626 gethash_back_off_mult_ = 1; | 622 gethash_back_off_mult_ = 1; |
| 627 } | 623 } |
| 628 | 624 |
| 629 void V4GetHashProtocolManager::SetClockForTests( | 625 void V4GetHashProtocolManager::SetClockForTests( |
| 630 std::unique_ptr<base::Clock> clock) { | 626 std::unique_ptr<base::Clock> clock) { |
| 631 clock_ = std::move(clock); | 627 clock_ = std::move(clock); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 std::ostream& operator<<(std::ostream& os, const FullHashInfo& fhi) { | 739 std::ostream& operator<<(std::ostream& os, const FullHashInfo& fhi) { |
| 744 os << "{full_hash: " << fhi.full_hash << "; list_id: " << fhi.list_id | 740 os << "{full_hash: " << fhi.full_hash << "; list_id: " << fhi.list_id |
| 745 << "; positive_expiry: " << fhi.positive_expiry | 741 << "; positive_expiry: " << fhi.positive_expiry |
| 746 << "; metadata.api_permissions.size(): " | 742 << "; metadata.api_permissions.size(): " |
| 747 << fhi.metadata.api_permissions.size() << "}"; | 743 << fhi.metadata.api_permissions.size() << "}"; |
| 748 return os; | 744 return os; |
| 749 } | 745 } |
| 750 #endif | 746 #endif |
| 751 | 747 |
| 752 } // namespace safe_browsing | 748 } // namespace safe_browsing |
| OLD | NEW |