Bug 1485180 - Instrument invalid download protection hashes. r?dimi draft truncated-hash-telemetry-1485180
authorFrancois Marier <francois@mozilla.com>
Tue, 21 Aug 2018 16:44:04 -0700
changeset 480906 47408b897580f060d441b3c25cfe5c0b05674a53
parent 480905 130bb81b5f4f9c98ba138ab5593148537dd77b57
push id231
push userfmarier@mozilla.com
push dateWed, 22 Aug 2018 00:04:13 +0000
reviewersdimi
bugs1485180
milestone63.0a1
Bug 1485180 - Instrument invalid download protection hashes. r?dimi
toolkit/components/reputationservice/ApplicationReputation.cpp
toolkit/components/telemetry/Histograms.json
--- a/toolkit/components/reputationservice/ApplicationReputation.cpp
+++ b/toolkit/components/reputationservice/ApplicationReputation.cpp
@@ -1461,16 +1461,34 @@ PendingLookup::SendRemoteQueryInternal()
   if (mRequest.signature().trusted()) {
     LOG(("Got signed binary for remote application reputation check "
          "[this = %p]", this));
   } else {
     LOG(("Got unsigned binary for remote application reputation check "
          "[this = %p]", this));
   }
 
+  // Look for truncated hashes (see bug 1190020)
+  const auto originalHashLength = sha256Hash.Length();
+  if (originalHashLength == 0) {
+    AccumulateCategorical(mozilla::Telemetry::LABELS_APPLICATION_REPUTATION_HASH_LENGTH::OriginalHashEmpty);
+  } else if (originalHashLength < 32) {
+    AccumulateCategorical(mozilla::Telemetry::LABELS_APPLICATION_REPUTATION_HASH_LENGTH::OriginalHashTooShort);
+  } else if (originalHashLength > 32) {
+    AccumulateCategorical(mozilla::Telemetry::LABELS_APPLICATION_REPUTATION_HASH_LENGTH::OriginalHashTooLong);
+  } else if (!mRequest.has_digests()) {
+    AccumulateCategorical(mozilla::Telemetry::LABELS_APPLICATION_REPUTATION_HASH_LENGTH::MissingDigest);
+  } else if (!mRequest.digests().has_sha256()) {
+    AccumulateCategorical(mozilla::Telemetry::LABELS_APPLICATION_REPUTATION_HASH_LENGTH::MissingSha256);
+  } else if (mRequest.digests().sha256().size() != originalHashLength) {
+    AccumulateCategorical(mozilla::Telemetry::LABELS_APPLICATION_REPUTATION_HASH_LENGTH::InvalidSha256);
+  } else {
+    AccumulateCategorical(mozilla::Telemetry::LABELS_APPLICATION_REPUTATION_HASH_LENGTH::ValidHash);
+  }
+
   // Serialize the protocol buffer to a string. This can only fail if we are
   // out of memory, or if the protocol buffer req is missing required fields
   // (only the URL for now).
   std::string serialized;
   if (!mRequest.SerializeToString(&serialized)) {
     return NS_ERROR_UNEXPECTED;
   }
   LOG(("Serialized protocol buffer [this = %p]: (length=%zu) %s", this,
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -103,16 +103,26 @@
     "alert_emails": ["francois@mozilla.com", "safebrowsing-telemetry@mozilla.org"],
     "bug_numbers": [1480639],
     "expires_in_version": "never",
     "releaseChannelCollection": "opt-out",
     "kind": "categorical",
     "labels": ["OtherBinaryFile", "DmgFile", "RarFile", "ZipFile"],
     "description": "Whether a binary file examined by download protection is one of the common archive formats."
   },
+  "APPLICATION_REPUTATION_HASH_LENGTH": {
+    "record_in_processes": ["main", "content"],
+    "alert_emails": ["francois@mozilla.com", "safebrowsing-telemetry@mozilla.org"],
+    "bug_numbers": [1485180],
+    "expires_in_version": "69",
+    "releaseChannelCollection": "opt-out",
+    "kind": "categorical",
+    "labels": ["ValidHash", "OriginalHashEmpty", "OriginalHashTooShort", "OriginalHashTooLong", "MissingDigest", "MissingSha256", "InvalidSha256"],
+    "description": "Whether the hash included in application reputation lookups is valid or broken in some way."
+  },
   "APPLICATION_REPUTATION_SHOULD_BLOCK": {
     "record_in_processes": ["main", "content"],
     "alert_emails": ["francois@mozilla.com", "safebrowsing-telemetry@mozilla.org"],
     "expires_in_version": "never",
     "releaseChannelCollection": "opt-out",
     "kind": "boolean",
     "description": "Overall (local or remote) application reputation verdict (shouldBlock=false is OK)."
   },