Skip to content

Add validating reader - #133

Open
mikeminutillo wants to merge 4 commits into
remove-total-throughputfrom
validating-reader
Open

Add validating reader#133
mikeminutillo wants to merge 4 commits into
remove-total-throughputfrom
validating-reader

Conversation

@mikeminutillo

Copy link
Copy Markdown
Member

While trying to remove TotalThroughput we discovered a point of friction with the way signatures are being validated.

The way this was happening is as follows:

  1. Deserialize the json into an in-memory object (SignedReport). This object had two fields, Signature and ReportData.
  2. Reserialize the ReportData and use that to calculate the expected signature
  3. Compare the expected signature against the Signature

This means that any change to the ReportData that would affect the way it is serialized, would break the signature validation logic. This includes removing fields, renaming fields (even if we could handle the way old reports were deserialized), or adding fields that have a default value.

To resolve this we added a class that validates the signature while it reads the report data. It does this by:

  1. Parsing the raw json into a JsonDocument
  2. Gets the UTF8 bytes from the report data element
  3. Gets the Signature
  4. Calculates the expected signature from the result of step 2 (guaranteed to be what was in the original json)
  5. Deserializes the report data element into an in-memory representation

This means we can validate the signature, even without having the in-memory representation if we need to.

The downside to doing it this way is that we have to validate the signature when we load the raw json into memory. We cannot load a SignedReport into memory and then validate it's signature separately. As we only do this in our internal tools, and we always validate the signature shortly after loading it, that trade-off seems acceptable.

var reportId = Convert.ToHexString(SHA1.HashData(reportBytes));
var validationResult = new ReportValidationResult
{
ReportId = reportId

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just in case, to make it explicit and safeguard against a constructor being reintroduced

Suggested change
ReportId = reportId
ReportId = reportId,
IsValid = false

Assert.That(data.EnvironmentInformation.EnvironmentData["MonitoringEnabled"], Is.EqualTo("True"));

Assert.That(report.Signature, Is.EqualTo("IEbO4i0Jn54iHUzlwotHf9aw/fZIHY+dztY9cMRkWjVVo6AiYtihWR0mip793gRrWHOxHVobCpa4l5svRk16mBR+YAOrs3KNRVTzrl4+wL21e1u9zFuPNrHLtFeul+taJxV8ciA7zEgD7LMle9CcR/Vfm8BZ9mmD5W/DjsCYLCdVXfN4iRMlz+eW50mOHty21yJ0pOiYBooaN2EJexVY4Q+5FMyAkm0wucEPFyaQB6+SfcS37fEm807B7sXhtUPiW+einqDOX6uYF+MuXxUn1u9LxlEWKV9kPqXJnulxmoReHXHigP45pj/8m9jUzrQdagINl1uIOBkq5SMDccRfTA=="));
//Assert.That(report.Signature, Is.EqualTo("IEbO4i0Jn54iHUzlwotHf9aw/fZIHY+dztY9cMRkWjVVo6AiYtihWR0mip793gRrWHOxHVobCpa4l5svRk16mBR+YAOrs3KNRVTzrl4+wL21e1u9zFuPNrHLtFeul+taJxV8ciA7zEgD7LMle9CcR/Vfm8BZ9mmD5W/DjsCYLCdVXfN4iRMlz+eW50mOHty21yJ0pOiYBooaN2EJexVY4Q+5FMyAkm0wucEPFyaQB6+SfcS37fEm807B7sXhtUPiW+einqDOX6uYF+MuXxUn1u9LxlEWKV9kPqXJnulxmoReHXHigP45pj/8m9jUzrQdagINl1uIOBkq5SMDccRfTA=="));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants