| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/safe_browsing/protocol_manager.h" | 5 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 // A match in the response had an unexpected THREAT_ENTRY_TYPE. | 84 // A match in the response had an unexpected THREAT_ENTRY_TYPE. |
| 85 UNEXPECTED_THREAT_ENTRY_TYPE_ERROR = 1, | 85 UNEXPECTED_THREAT_ENTRY_TYPE_ERROR = 1, |
| 86 | 86 |
| 87 // A match in the response had an unexpected THREAT_TYPE. | 87 // A match in the response had an unexpected THREAT_TYPE. |
| 88 UNEXPECTED_THREAT_TYPE_ERROR = 2, | 88 UNEXPECTED_THREAT_TYPE_ERROR = 2, |
| 89 | 89 |
| 90 // A match in the response had an unexpected PLATFORM_TYPE. | 90 // A match in the response had an unexpected PLATFORM_TYPE. |
| 91 UNEXPECTED_PLATFORM_TYPE_ERROR = 3, | 91 UNEXPECTED_PLATFORM_TYPE_ERROR = 3, |
| 92 | 92 |
| 93 // A match in teh response contained no metadata where metadata was | 93 // A match in the response contained no metadata where metadata was |
| 94 // expected. | 94 // expected. |
| 95 NO_METADATA_ERROR = 4, | 95 NO_METADATA_ERROR = 4, |
| 96 | 96 |
| 97 // A match in the response contained a ThreatType that was inconsistent |
| 98 // with the other matches. |
| 99 INCONSISTENT_THREAT_TYPE_ERROR = 5, |
| 100 |
| 97 // Memory space for histograms is determined by the max. ALWAYS | 101 // Memory space for histograms is determined by the max. ALWAYS |
| 98 // ADD NEW VALUES BEFORE THIS ONE. | 102 // ADD NEW VALUES BEFORE THIS ONE. |
| 99 PARSE_GET_HASH_RESULT_MAX = 5 | 103 PARSE_GET_HASH_RESULT_MAX = 6 |
| 100 }; | 104 }; |
| 101 | 105 |
| 102 // Record parsing errors of a GetHash result. | 106 // Record parsing errors of a GetHash result. |
| 103 void RecordParseGetHashResult(ParseResultType result_type) { | 107 void RecordParseGetHashResult(ParseResultType result_type) { |
| 104 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.ParseV4HashResult", result_type, | 108 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.ParseV4HashResult", result_type, |
| 105 PARSE_GET_HASH_RESULT_MAX); | 109 PARSE_GET_HASH_RESULT_MAX); |
| 106 } | 110 } |
| 107 | 111 |
| 108 } // namespace | 112 } // namespace |
| 109 | 113 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 for (const ThreatMatch& match : response.matches()) { | 372 for (const ThreatMatch& match : response.matches()) { |
| 369 // Make sure the platform and threat entry type match. | 373 // Make sure the platform and threat entry type match. |
| 370 if (!(match.has_threat_entry_type() && | 374 if (!(match.has_threat_entry_type() && |
| 371 match.threat_entry_type() == URL_EXPRESSION && | 375 match.threat_entry_type() == URL_EXPRESSION && |
| 372 match.has_threat())) { | 376 match.has_threat())) { |
| 373 RecordParseGetHashResult(UNEXPECTED_THREAT_ENTRY_TYPE_ERROR); | 377 RecordParseGetHashResult(UNEXPECTED_THREAT_ENTRY_TYPE_ERROR); |
| 374 return false; | 378 return false; |
| 375 } | 379 } |
| 376 | 380 |
| 377 if (!match.has_threat_type()) { | 381 if (!match.has_threat_type()) { |
| 378 // TODO(kcarattini): Add UMA. | 382 RecordParseGetHashResult(UNEXPECTED_THREAT_TYPE_ERROR); |
| 379 return false; | 383 return false; |
| 380 } | 384 } |
| 381 | 385 |
| 382 if (expected_threat_type == THREAT_TYPE_UNSPECIFIED) { | 386 if (expected_threat_type == THREAT_TYPE_UNSPECIFIED) { |
| 383 expected_threat_type = match.threat_type(); | 387 expected_threat_type = match.threat_type(); |
| 384 } else if (match.threat_type() != expected_threat_type) { | 388 } else if (match.threat_type() != expected_threat_type) { |
| 385 // TODO(kcarattini): Add UMA. | 389 RecordParseGetHashResult(INCONSISTENT_THREAT_TYPE_ERROR); |
| 386 return false; | 390 return false; |
| 387 } | 391 } |
| 388 | 392 |
| 389 // Fill in the full hash. | 393 // Fill in the full hash. |
| 390 SBFullHashResult result; | 394 SBFullHashResult result; |
| 391 result.hash = StringToSBFullHash(match.threat().hash()); | 395 result.hash = StringToSBFullHash(match.threat().hash()); |
| 392 | 396 |
| 393 if (match.has_cache_duration()) { | 397 if (match.has_cache_duration()) { |
| 394 // Seconds resolution is good enough so we ignore the nanos field. | 398 // Seconds resolution is good enough so we ignore the nanos field. |
| 395 result.cache_duration = base::TimeDelta::FromSeconds( | 399 result.cache_duration = base::TimeDelta::FromSeconds( |
| 396 match.cache_duration().seconds()); | 400 match.cache_duration().seconds()); |
| 397 } | 401 } |
| 398 | 402 |
| 399 // Different threat types will handle the metadata differently. | 403 // Different threat types will handle the metadata differently. |
| 400 if (match.has_threat_type() && match.threat_type() == API_ABUSE) { | 404 if (match.threat_type() == API_ABUSE) { |
| 401 if (match.has_platform_type() && | 405 if (match.has_platform_type() && |
| 402 match.platform_type() == CHROME_PLATFORM) { | 406 match.platform_type() == CHROME_PLATFORM) { |
| 403 if (match.has_threat_entry_metadata()) { | 407 if (match.has_threat_entry_metadata()) { |
| 404 // For API Abuse, store a csv of the returned permissions. | 408 // For API Abuse, store a csv of the returned permissions. |
| 405 for (const ThreatEntryMetadata::MetadataEntry& m : | 409 for (const ThreatEntryMetadata::MetadataEntry& m : |
| 406 match.threat_entry_metadata().entries()) { | 410 match.threat_entry_metadata().entries()) { |
| 407 if (m.key() == "permission") { | 411 if (m.key() == "permission") { |
| 408 result.metadata += m.value() + ","; | 412 result.metadata += m.value() + ","; |
| 409 } | 413 } |
| 410 } | 414 } |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 SafeBrowsingProtocolManager::FullHashDetails::FullHashDetails( | 1098 SafeBrowsingProtocolManager::FullHashDetails::FullHashDetails( |
| 1095 FullHashCallback callback, | 1099 FullHashCallback callback, |
| 1096 bool is_download) | 1100 bool is_download) |
| 1097 : callback(callback), is_download(is_download) {} | 1101 : callback(callback), is_download(is_download) {} |
| 1098 | 1102 |
| 1099 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() {} | 1103 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() {} |
| 1100 | 1104 |
| 1101 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() {} | 1105 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() {} |
| 1102 | 1106 |
| 1103 } // namespace safe_browsing | 1107 } // namespace safe_browsing |
| OLD | NEW |