Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Review of src/SDK/DefaultCMM.dfy #218

Merged
merged 6 commits into from
Mar 10, 2020
Merged

refactor: Review of src/SDK/DefaultCMM.dfy #218

merged 6 commits into from
Mar 10, 2020

Conversation

MatthewBennington
Copy link

Issue #, if available: resolves #41

Description of changes: Changes mostly to specification of the DefaultCMM. Added tests.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lavaleri
Copy link
Contributor

lavaleri commented Mar 2, 2020

AWS CodeBuild CI Report

  • CodeBuild project: DafnyESDK
  • Commit ID: 6208d65
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

lavaleri
lavaleri previously approved these changes Mar 3, 2020
Copy link
Contributor

@lavaleri lavaleri left a comment

Choose a reason for hiding this comment

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

One minor nitpick and one small suggestion for a change that can be done as part of this PR if you think it's appropriate. Otherwise LGTM!

kr := k;
Repr := {this, kr} + k.Repr;
keyring := k;
Repr := {this, keyring} + k.Repr;
}

method GetEncryptionMaterials(materialsRequest: Materials.EncryptionMaterialsRequest)
returns (res: Result<Materials.ValidEncryptionMaterials>)
requires Valid()
requires ValidAAD(materialsRequest.encryptionContext)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think with #79 in, we should also be able to just remove this line.
As part of this we can also just remove these preconditions from the CMM interface, which should accomplish #210.
Arguably this could also be done in a different PR.

Copy link
Author

Choose a reason for hiding this comment

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

I think with #79 in, we should also be able to just remove this line.

Just to be clear: we still need to be sure we pass our keyring a valid encryption context here, so you suggest a runtime check?

Copy link
Contributor

Choose a reason for hiding this comment

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

The spec doesn't actually specify that the EC passed in MUST be serializable, which is why #210 suggests removing that condition from the CMM interface (which would require removing it here too). After the work done in #203, we should already be doing the runtime checks in deafult CMM needed to ensure that the output EC is serializable. As such, this line currently isn't doing anythign useful in DefaultCMM, and should be removed either in this PR or in a different PR which removes these conditions from the CMM interface.

expect shouldBeFail.Failure?, "GetEncryptionMaterials returned Success with bad input";
}

method MakeKeyring() returns (res: Result<RawRSAKeyringDef.RawRSAKeyring>)
Copy link
Contributor

Choose a reason for hiding this comment

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

Because none of the above tests depend on the particular confiuration of the keyring, let's move this into TestUtils, where it can be possibly reused by other tests which similarly needs keyrings, but don't actually care about the keyring configuration.

acioc
acioc previously approved these changes Mar 3, 2020
Copy link

@acioc acioc left a comment

Choose a reason for hiding this comment

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

Looks good! Agreed it would be nice to see MakeKeyring in TestUtils instead.

- Remove ValidAAD precondition on DefaultCMM.GetEncryptionMaterials
- Add runtime check of encryptionContext validity to
DefaultCMM.GetEncryptionMaterials
- Move MakeKeyring from DefaultCMMTests to TestUtils
@MatthewBennington MatthewBennington dismissed stale reviews from acioc and lavaleri via 00d87fc March 5, 2020 23:56
@lavaleri
Copy link
Contributor

lavaleri commented Mar 6, 2020

AWS CodeBuild CI Report

  • CodeBuild project: DafnyESDK
  • Commit ID: 00d87fc
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Comment on lines 94 to 96
if UINT16_LIMIT <= |enc_ctx| {
return Failure("encryption context has too many entries");
} else if UINT16_LIMIT <= len {
Copy link
Contributor

Choose a reason for hiding this comment

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

These two cases should already be covered by ComputeValidAAD. We should remove ComputeKVPairsLength in order to avoid two computations on the EC, and just check ComputeValidAAD instead.

Copy link
Author

Choose a reason for hiding this comment

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

In this case, relying only on ComputeValidAAD() would mean we give less helpful error messages to the customer. I think Ideally we could break out ComputeValidAAD is a what in which we can identify how an encryption context violated it's bounds. Until then, I think the performance tradeoff is worth having better error messages.

If that sounds okay to you, I'll cut an issue and reference it in the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

The Default CMM shouldn't be aware of the different ways that the EC may be un-serializable, it just needs to concern itself with whether the EC it produces is serializable or not. But you are correct that this means less helpful messages to the user unless the thing computing the "AAD Validity" is able to surface the different failure cases, which we don't do here because ComputeValidAAD just returns a bool. Perhaps what we want here is a "ValidateECSerializability" method which errors if the EC can't be serialized into AAD. This might make sense because currently everywhere we use "ComputeValidAAD" we just return an error if it's false, and I can't think of a case where we would want to do anything other than error if we're working with a bad EC.

My preference would be to keep DefaultCMM as simple as possible, as least aware of the serializing logic as possible, and cut an issue to address surfacing better error messaging in this case. Regardless, I won't block on this.

lavaleri
lavaleri previously approved these changes Mar 9, 2020
@lavaleri
Copy link
Contributor

lavaleri commented Mar 9, 2020

AWS CodeBuild CI Report

  • CodeBuild project: DafnyESDK
  • Commit ID: 184f9eb
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@lavaleri
Copy link
Contributor

AWS CodeBuild CI Report

  • CodeBuild project: DafnyESDK
  • Commit ID: 4504fb2
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@MatthewBennington MatthewBennington merged commit 1c9effd into aws:develop Mar 10, 2020
josecorella pushed a commit to josecorella/aws-encryption-sdk-dafny that referenced this pull request Oct 11, 2023
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.

Review DefaultCMM
3 participants