Skip to content

Commit 2e857a7

Browse files
feat: Add recommendation for detecting base64-encoded messages (#154)
Co-authored-by: Matt Bullock <[email protected]>
1 parent 4cdeaa6 commit 2e857a7

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.

client-apis/decrypt.md

+30
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77

88
0.1.0-preview
99

10+
### Changelog
11+
12+
- 0.2.0
13+
14+
- [Detect Base64-encoded Messages](../changes/2020-07-13_detect-base64-encoded-messages/change.md)
15+
16+
- 0.1.0-preview
17+
18+
- Initial record
19+
1020
## Implementations
1121

1222
- [C](https://github.com/aws/aws-encryption-sdk-c/blob/master/source/session_decrypt.c)
@@ -52,6 +62,26 @@ Each key in the encrypted data key list is an encrypted version of the single pl
5262
The encryption context is the additional authenticated data that was used during encryption.
5363
The algorithm suite ID refers to the algorithm suite used to encrypt the message and is required to decrypt the encrypted message.
5464

65+
#### Encrypted Message Format
66+
67+
The message format is a binary format, but it is a common mistake for users to attempt decryption on the Base64 encoding of this data instead.
68+
Because the first two bytes of the message format have a very limited set of possible values
69+
(currently they are in fact fixed),
70+
the first two bytes of the Base64 encoding of a valid message are also simple to recognize.
71+
72+
To make diagnosing this mistake easier, implementations SHOULD detect the first two bytes of the Base64 encoding of any supported message [versions](../data-format/message-header.md#version-1)
73+
and [types](../data-format/message-header.md#type)
74+
and fail with a more specific error message.
75+
In particular, the hex values to detect for the current set of versions and types are:
76+
77+
| Version and type (hex) | Base64 encoding (ascii) | Base64 encoding (hex) |
78+
| ---------------------- | ----------------------- | --------------------- |
79+
| 01 80 | A Y ... | 41 59 ... |
80+
81+
Note that the bytes that follow the initial two in the Base64 encoding
82+
partially depend on subsequent bytes in the binary message format
83+
and hence are not as predictable.
84+
5585
### Cryptographic Materials Manager
5686

5787
A CMM that implements the [CMM interface](../framework/cmm-interface.md).

0 commit comments

Comments
 (0)