awslabs / aws-encryption-sdk-specification

AWS Encryption SDK Specification
Other
30 stars 27 forks source link

Clarify Encrypt behavior based on plaintext length input #102

Closed lavaleri closed 4 years ago

lavaleri commented 4 years ago

Related to unblocking: #71

Encryption "plaintext length" param behavior

When performing the encrypt operation on a plaintext where the plaintext length is not immediately known, users MUST be able to specify the optional parameter maxPlaintextLength. The value of this field represents the bound on the length of the plaintext to be encrypted. The ESDK MUST NOT encrypt a plaintext greater than this length, and MUST fail if it can be determined during encryption that the actual plaintext length is greater than what the user supplied on input. The actual name of this parameter MAY be different per implementation.

Similarly, the CMM's GetEncryptionMaterials should clearly define maxPlaintextLength as an input that represents the maximum size of the plaintext that will be encrypted using these materials. Having this parameter is integral for having the Caching CMM work for streaming encrypt operations. The actual name of this input MAY be different per implementation.

However, what should happen if a user inputs a plaintext with a known length (e.g. a byte array instead of a stream) as well as inputs a (possible incorrect) maxPlaintextLength?

We should avoid letting users do this as much as is reasonable for the implementation. If for a certain API the supplied plaintext's length will always be known, that API shouldn't provide maxPlaintextLength as an input. As such, we should add the following to the spec:

To make clear the behavior in the latter case, we should add the following to the spec:

Why not pass always pass the user supplied maxPlaintextLength to the CMM?

This passes less accurate information to the CMM. There is no case where a user would benefit from passing a less accurate maxPlaintextLength to the CMM. If there were such a case, then such a CMM is not correctly using the intent behind maxPlaintextLength, and it is better to restrict flexibilty here so that users have less opportunity to depends on bad behaviors from a poorly designed CMM.

Why not standardize on a name?

Most implementations already have this control with almost the same exact behavior, but with different names. It is not worth it to break customers to update the name of this control in every implementation, without actually changing the core behavior. We should define this control in the spec as maxPlaintextLength for the Encrypt API and the CMM Interface, and we can document what each implementation names this control.

What changes are needed in implementations to match this specification?

lavaleri commented 4 years ago

Resolved by #138