Skip to content

feat: Add recommendation for detecting base64-encoded messages #154

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

Merged

Conversation

robin-aws
Copy link
Contributor

Fixes #42

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@robin-aws
Copy link
Contributor Author

Realized I still need a change doc and version change etc. for this, coming soon.

@robin-aws robin-aws changed the title feat: Add recommendation for detecting base64-encoded messages [DRAFT] feat: Add recommendation for detecting base64-encoded messages Jul 13, 2020
@robin-aws robin-aws changed the title [DRAFT] feat: Add recommendation for detecting base64-encoded messages feat: Add recommendation for detecting base64-encoded messages Jul 13, 2020

## Summary

When a decryption attempt is made on the Base64-encoding of a valid message,
Copy link
Contributor

Choose a reason for hiding this comment

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

a decryption attempt is made on the Base64-encoding of a valid message

Does this mean a user is trying to decrypt a Base64-string, the utf-8 encoding of a Base64-string, or both/either?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The UTF-8 encoding of the string - decrypt accepts a message as a byte sequence after all.

FWIW, a Base64 string only uses ASCII characters so nearly all encodings will use the same byte values.

Copy link
Contributor

Choose a reason for hiding this comment

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

decrypt accepts a message as a byte sequence after all

The spec must acknowledge dynamically typed languages though, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely! But it MUST interpret whatever input it is given as a sequence of bytes somehow. If it's idiomatic to accept a string because it quacks like a byte sequence, the operation has to be clear about how it will interpret it as bytes: whether it will use a particular hard-coded encoding like UTF-8, or rely on an encoding attached to the string value, etc.

In a particular language implementation, I would expect the documentation to cover this if it's not obvious by context.


| Specification |
| --------------------------------------- |
| [Decrypt](../../client-apis/decrypt.md) |
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the SHA be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was following the example here, which only includes the SHA in "Affected Features" but not in "Affected Specifications": https://raw.githubusercontent.com/awslabs/aws-encryption-sdk-specification/master/changes/2020-05-13_remove-keyring-trace/change.md

@mattsb42-aws Do you think we need to use permalinks in both places? Whatever we decide should be written down in #137.

Copy link
Member

Choose a reason for hiding this comment

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

The pattern that I've been following is to use permalinks when referencing features that are being removed or referencing specific lines in files. I think that a standard relative link is appropriate here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As per my comment on #137, switching the existing permalink back to relative.

seebees
seebees previously approved these changes Jul 14, 2020
seebees
seebees previously approved these changes Jul 15, 2020
Copy link
Contributor

@seebees seebees left a comment

Choose a reason for hiding this comment

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

LGTM

acioc
acioc previously approved these changes Jul 16, 2020
seebees
seebees previously approved these changes Jul 16, 2020
Copy link
Contributor

@seebees seebees left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@MatthewBennington MatthewBennington left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@mattsb42-aws mattsb42-aws left a comment

Choose a reason for hiding this comment

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

x_x apparently I forgot to post these comments whenever I wrote them..


| Specification |
| --------------------------------------- |
| [Decrypt](../../client-apis/decrypt.md) |
Copy link
Member

Choose a reason for hiding this comment

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

The pattern that I've been following is to use permalinks when referencing features that are being removed or referencing specific lines in files. I think that a standard relative link is appropriate here.

Comment on lines 54 to 58
This feature technically means the version value
cannot be incremented beyond the hex value `40`,
since `41` would then conflict with the Base64-encoded value for `1`.
This does not seem worth worrying about
given how rarely we intended to change the version, however.
Copy link
Member

Choose a reason for hiding this comment

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

I would consider this a reference-level detail. Implementations SHOULD detect base64-encodings of all supported version and type prefixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To rephrase, it's not that the version cannot advance to 41, it's just that if it does this "SHOULD" becomes impossible to do for all versions, but that doesn't mean it shouldn't be done when possible. I'll improve this.

Comment on lines +77 to +88
Implementations SHOULD detect the first two bytes of the Base64 encoding of any supported message [versions](../data-format/message-header.md#version-1)
and [types](../data-format/message-header.md#type)
and fail with a more specific error message.
In particular, the hex values to detect for the current set of versions and types are:

| Version and type (hex) | Base64 encoding (ascii) | Base64 encoding (hex) |
| ---------------------- | ----------------------- | --------------------- |
| 01 80 | A Y ... | 41 59 ... |

Note that the bytes that follow the initial two in the Base64 encoding
partially depend on subsequent bytes in the binary message format
and hence are not as predictable.
Copy link
Member

Choose a reason for hiding this comment

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

Rather than stating a set of static values here, we should state how to find those values and provide an example of what they might be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to at least keep the table so that each implementation doesn't have to go through that process themselves.

@robin-aws robin-aws dismissed stale reviews from MatthewBennington, seebees, and acioc via 73e6a36 July 17, 2020 19:08
I can’t believe none of us caught this already :)
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.

Verification of version and type on deserialization base64 encoding error
5 participants