Skip to content
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

Canonicalised JSON format produces invalid JSON #246

Closed
toby-jn opened this issue Mar 29, 2022 · 1 comment · Fixed by #247
Closed

Canonicalised JSON format produces invalid JSON #246

toby-jn opened this issue Mar 29, 2022 · 1 comment · Fixed by #247

Comments

@toby-jn
Copy link
Contributor

toby-jn commented Mar 29, 2022

The go-tuf library appears to mis-use JSON canonicalisation when serialising metadata.

The JSON canonicalisation format (specified here: https://wiki.laptop.org/go/Canonical_JSON) does not escape of control sequences in string values, however the JSON standard (https://www.ecma-international.org/wp-content/uploads/ECMA-404_2nd_edition_december_2017.pdf) requires that all control characters (defined as U+0000 to U+001F) MUST be escaped in strings.

As a result new line characters in strings are not escaped and this produces invalid JSON and go-tuf will fail to marshal metadata containing these sequences. This is particularly problematic for RSA and ECDSA keys where the specification states they are encoded in PEM format, which will inevitably contain newline characters.

I believe the cause of the error is that go-tuf does not just use canonicalisation to calculate the message digest, and also uses it to serialise the metadata for output.

@rdimitrov
Copy link
Contributor

Related to #223

toby-jn added a commit to toby-jn/go-tuf that referenced this issue Mar 29, 2022
toby-jn added a commit to toby-jn/go-tuf that referenced this issue Apr 13, 2022
toby-jn added a commit to toby-jn/go-tuf that referenced this issue Apr 13, 2022
asraa pushed a commit that referenced this issue Apr 14, 2022
* fix JSON canonicalisation (see #246)
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 a pull request may close this issue.

2 participants