|
| 1 | +[//]: # "Copyright Amazon.com Inc. or its affiliates. All Rights Reserved." |
| 2 | +[//]: # "SPDX-License-Identifier: CC-BY-SA-4.0" |
| 3 | + |
| 4 | +# Detect Base64-encoded Messages |
| 5 | + |
| 6 | +## Affected Features |
| 7 | + |
| 8 | +This serves as a reference of all features that this change affects. |
| 9 | + |
| 10 | +| Feature | |
| 11 | +| --------------------------------------- | |
| 12 | +| [Decrypt](../../client-apis/decrypt.md) | |
| 13 | + |
| 14 | +## Affected Specifications |
| 15 | + |
| 16 | +This serves as a reference of all specification documents that this change affects. |
| 17 | + |
| 18 | +| Specification | |
| 19 | +| --------------------------------------- | |
| 20 | +| [Decrypt](../../client-apis/decrypt.md) | |
| 21 | + |
| 22 | +## Affected Implementations |
| 23 | + |
| 24 | +This serves as a reference for all implementations that this change affects. |
| 25 | + |
| 26 | +| Language | Repository | |
| 27 | +| ---------- | ------------------------------------------------------------------------------------- | |
| 28 | +| C | [aws-encryption-sdk-c](https://github.com/aws/aws-encryption-sdk-c) | |
| 29 | +| Java | [aws-encryption-sdk-java](https://github.com/aws/aws-encryption-sdk-java) | |
| 30 | +| Javascript | [aws-encryption-sdk-javascript](https://github.com/aws/aws-encryption-sdk-javascript) | |
| 31 | +| Python | [aws-encryption-sdk-python](https://github.com/aws/aws-encryption-sdk-python) | |
| 32 | + |
| 33 | +## Definitions |
| 34 | + |
| 35 | +### Conventions used in this document |
| 36 | + |
| 37 | +The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" |
| 38 | +in this document are to be interpreted as described in [RFC 2119](https://tools.ietf.org/html/rfc2119). |
| 39 | + |
| 40 | +## Summary |
| 41 | + |
| 42 | +When a decryption attempt is made on the Base64-encoding of a valid message, |
| 43 | +implementations SHOULD detect this and provide a more specific error message. |
| 44 | + |
| 45 | +## Motivation |
| 46 | + |
| 47 | +The message format is a binary format |
| 48 | +but users commonly attempt to decrypt the Base64 encoding of this data. |
| 49 | +Because the first two bytes of the message format have a very limited set of possible values |
| 50 | +(currently they are in fact fixed), |
| 51 | +the first two bytes of the Base64 encoding of a valid message are also simple to recognize. |
| 52 | + |
| 53 | +## Drawbacks |
| 54 | + |
| 55 | +If the version value ever advances beyond the hex value `40`, |
| 56 | +it will not be possible to catch this error for all supported versions |
| 57 | +since `41` would then conflict with the Base64-encoded value for `1`. |
| 58 | +This is acceptable given it is a best-effort guard, |
| 59 | +and also extremely unlikely |
| 60 | +given how rarely we intended to change the version. |
| 61 | + |
| 62 | +## Security Implications |
| 63 | + |
| 64 | +This change SHOULD NOT have any security implications. |
| 65 | + |
| 66 | +## Operational Implications |
| 67 | + |
| 68 | +This change should have positive operational impact |
| 69 | +because it removes ambiguity on a common failure mode, |
| 70 | +reducing potential for customer confusion |
| 71 | +and increasing the likelihood that customers can |
| 72 | +diagnose this root cause without needing to contact us. |
| 73 | + |
| 74 | +## Guide-level Explanation |
| 75 | + |
| 76 | +When a decryption attempt is made on the Base64-encoding of a valid message, |
| 77 | +implementations SHOULD detect this and provide a more specific error message on a best-effort basis. |
| 78 | + |
| 79 | +## Reference-level Explanation |
| 80 | + |
| 81 | +Implementations SHOULD detect the first two bytes of the Base64 encoding of any supported message [versions](../data-format/message-header.md#version-1) |
| 82 | +and [types](../data-format/message-header.md#type) |
| 83 | +and fail with a more specific error message. |
| 84 | +In particular, the hex values to detect for the current set of versions and types are: |
| 85 | + |
| 86 | +| Version and type (hex) | Base64 encoding (ascii) | Base64 encoding (hex) | |
| 87 | +| ---------------------- | ----------------------- | --------------------- | |
| 88 | +| 01 80 | A Y ... | 41 59 ... | |
| 89 | + |
| 90 | +Note that the bytes that follow the initial two in the Base64 encoding |
| 91 | +partially depend on subsequent bytes in the binary message format |
| 92 | +and hence are not as predictable. |
0 commit comments