|
| 1 | +[//]: # "Copyright Amazon.com Inc. or its affiliates. All Rights Reserved." |
| 2 | +[//]: # "SPDX-License-Identifier: CC-BY-SA-4.0" |
| 3 | + |
| 4 | +# Enforce Safe Handling of Max Plaintext Length in Caching Cryptographic Materials Manager |
| 5 | + |
| 6 | +## Affected Features |
| 7 | + |
| 8 | +| Feature | |
| 9 | +| ------------------------------------------------------------------------- | |
| 10 | +| [Caching Cryptographic Materials Manager](../../framework/caching-cmm.md) | |
| 11 | + |
| 12 | +## Affected Specifications |
| 13 | + |
| 14 | +| Specification | |
| 15 | +| ------------------------------------------------------------------------- | |
| 16 | +| [Caching Cryptographic Materials Manager](../../framework/caching-cmm.md) | |
| 17 | + |
| 18 | +## Affected Implementations |
| 19 | + |
| 20 | +| Language | Repository | |
| 21 | +| ---------- | ------------------------------------------------------------------------------------- | |
| 22 | +| C | [aws-encryption-sdk-c](https://github.com/aws/aws-encryption-sdk-c) | |
| 23 | +| Java | [aws-encryption-sdk-java](https://github.com/aws/aws-encryption-sdk-java) | |
| 24 | +| JavaScript | [aws-encryption-sdk-javascript](https://github.com/aws/aws-encryption-sdk-javascript) | |
| 25 | +| Python | [aws-encryption-sdk-python](https://github.com/aws/aws-encryption-sdk-python) | |
| 26 | + |
| 27 | +## Definitions |
| 28 | + |
| 29 | +### Conventions used in this document |
| 30 | + |
| 31 | +The key words |
| 32 | +"MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", |
| 33 | +"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" |
| 34 | +in this document are to be interpreted as described in |
| 35 | +[RFC 2119](https://tools.ietf.org/html/rfc2119). |
| 36 | + |
| 37 | +## Summary |
| 38 | + |
| 39 | +The Get Encryption Materials operation accepts an optional `max plaintext length` parameter, |
| 40 | +but the specification does not state how the caching CMM should behave |
| 41 | +when the caller does not provide the parameter value. |
| 42 | +This change specifies that the caching CMM should bypass the cache in this case. |
| 43 | + |
| 44 | +Also, when the caching CMM is performing a Get Encryption Materials operation |
| 45 | +for which no materials are cached, |
| 46 | +it MUST call its underlying CMM's Get Encryption Materials operation. |
| 47 | +The specification does not state what value of `max plaintext length` (if any) |
| 48 | +the caching CMM should pass to its underlying CMM. |
| 49 | +This change specifies that the caching CMM should pass its `byte limit` value |
| 50 | +as the `max plaintext length` parameter of the call to the underlying CMM. |
| 51 | + |
| 52 | +## Out of Scope |
| 53 | + |
| 54 | +- Changing the shape of any CMM APIs is out of scope. |
| 55 | + |
| 56 | +## Motivation |
| 57 | + |
| 58 | +### Fulfulling Encryption Materials Requests Without `max plaintext length` |
| 59 | + |
| 60 | +The Get Encryption Materials operation of the Cryptographic Materials Manager (CMM) |
| 61 | +accepts an Encryption Materials Request that MAY specify a `max plaintext length` field, |
| 62 | +indicating the maximum length of plaintext |
| 63 | +that the caller intends to encrypt using the returned materials. |
| 64 | +The caching Cryptographic Materials Manager (caching CMM) |
| 65 | +aims to prevent its users from using encryption materials |
| 66 | +to encrypt more bytes than its configured `byte limit`, |
| 67 | +and existing implementations do so by bypassing the cache |
| 68 | +whenever it does not know their users' `max plaintext length`. |
| 69 | +This behavior is safe but previously unspecified, |
| 70 | +and this change mandates that implementations implement it. |
| 71 | + |
| 72 | +### Setting `max plaintext length` for Underlying CMM's Get Encryption Materials |
| 73 | + |
| 74 | +The CMM interface specification implicitly allows an underlying CMM |
| 75 | +to produce encryption materials using logic |
| 76 | +that depends on the `max plaintext length` of its Encryption Materials Request. |
| 77 | +Suppose the caching CMM passes a `max plaintext length` value of `N` |
| 78 | +to its underlying CMM's Get Encryption Materials operation, |
| 79 | +and caches the materials that it receives. |
| 80 | +If a later Get Encryption Materials operation fetches those materials from the cache, |
| 81 | +but has a `max plaintext length` value that exceeds `N`, |
| 82 | +then the caching CMM returns those materials unsafely. |
| 83 | + |
| 84 | +It is therefore important that the caching CMM |
| 85 | +carefully selects the `max plaintext length` parameter to pass to its underlying CMM. |
| 86 | +This change mandates that the caching CMM passes its configured `byte limit` value |
| 87 | +as the `max plaintext length` parameter to the underlying CMM, |
| 88 | +whereas previously, the caching CMM could choose any value. |
| 89 | +With this change in place, |
| 90 | +even if the underlying CMM produces materials using plaintext-length-dependent logic, |
| 91 | +the caching CMM receives and caches materials |
| 92 | +that are safe to use for up to `byte limit` bytes of plaintext. |
| 93 | +It follows that if a later Get Encryption Materials operation's `max plaintext length` |
| 94 | +does not exceed the caching CMM's `byte limit`, |
| 95 | +then it is also safe for the caching CMM to return corresponding cached materials. |
| 96 | + |
| 97 | +## Drawbacks |
| 98 | + |
| 99 | +Bypassing the cache in the caching CMM on Get Encryption Materials operations |
| 100 | +that do not specify `max plaintext length` |
| 101 | +could be confusing to the user. |
| 102 | +Warning the user when this happens could help prevent users from running into |
| 103 | +unexpected (and potentially expensive) calls to the underlying CMM, |
| 104 | +but we leave this as an implementation choice. |
| 105 | + |
| 106 | +## Security Implications |
| 107 | + |
| 108 | +This change SHOULD NOT have any security implications. |
| 109 | + |
| 110 | +## Operational Implications |
| 111 | + |
| 112 | +This change will break any customer use case |
| 113 | +that depends on the Caching CMM passing no `max plaintext length` parameter |
| 114 | +to the underlying CMM on Get Encryption Materials calls. |
| 115 | + |
| 116 | +## Guide-level Explanation |
| 117 | + |
| 118 | +When you make a Get Encryption Materials call to the caching CMM, |
| 119 | +you may optionally specify a value for the `max plaintext length` parameter, |
| 120 | +which indicates the maximum number of bytes you will encrypt |
| 121 | +with the materials you receive from the call. |
| 122 | +If you do not specify a `max plaintext length` value, |
| 123 | +then the caching CMM will neither use cached materials |
| 124 | +nor cache materials from its underlying CMM. |
| 125 | +This helps to ensure that you do not exceed the `byte limit` |
| 126 | +that you configure on the caching CMM. |
| 127 | +So in order to maximize the benefits of caching, |
| 128 | +you should specify the `max plaintext length` value |
| 129 | +whenever you know an appropriate upper bound for bytes you will encrypt. |
| 130 | + |
| 131 | +If you customize the underlying CMM of a caching CMM, |
| 132 | +then whenever the caching CMM makes a Get Encryption Materials call |
| 133 | +to your customized underlying CMM, |
| 134 | +the Encryption Materials Request will have a `max plaintext length` value |
| 135 | +equal to the `byte limit` value configured on the caching CMM. |
| 136 | +This helps to ensure that the caching CMM can safely cache materials |
| 137 | +that it receives from the customized underlying CMM. |
| 138 | + |
| 139 | +## Reference-level Explanation |
| 140 | + |
| 141 | +When the caching CMM is performing the Get Encryption Materials operation |
| 142 | +for an Encryption Materials Request that does not specify a `max plaintext length`, |
| 143 | + |
| 144 | +- The caching CMM MUST NOT return materials from its CMC. |
| 145 | +- If the caching CMM calls its underlying CMM's Get Encryption Materials operation |
| 146 | + in order to obtain encryption materials, |
| 147 | + it MUST NOT cache the encryption materials in its CMC. |
| 148 | + |
| 149 | +When the caching CMM calls its underlying CMM's Get Encryption Materials operation |
| 150 | +in order to obtain encryption materials, |
| 151 | +it MUST use its configured `byte limit` value |
| 152 | +as the `max plaintext length` field of the Encryption Materials Request |
| 153 | +that it sends to the underlying CMM. |
0 commit comments