Skip to content

Update JSON canonicalization (backwards incompatible) #159

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

Closed
lukpueh opened this issue Oct 17, 2018 · 11 comments
Closed

Update JSON canonicalization (backwards incompatible) #159

lukpueh opened this issue Oct 17, 2018 · 11 comments

Comments

@lukpueh
Copy link
Member

lukpueh commented Oct 17, 2018

Description of issue or feature request:
Securesystemslib provides a custom json canonicalization function based on this Canonical JSON specification.

The specification seems outdated, or at least is not compatible with newer and more detailed specifications, such as the gibson042/canonicaljson-spec, for which a Go implementation exists.

The Notary Go implementation of TUF uses its own canonical JSON implementation which (IIUC) does not conform with any of above two specifications, but looks similar to the latter.

Current behavior:
securesystemslib uses an outdated JSON canonicalization specification.

Expected behavior:
I wonder if we should update securesystemlib's JSON canonicalization, or, given that there is no single accepted specification, switch to something that has wider cross-language support?

Note: I am well aware that this is a bigger request, as it would break backwards compatibility for metadata signatures used in TUF and in-toto, and would therefor require a TAP or ITE.

@lukpueh
Copy link
Member Author

lukpueh commented Oct 17, 2018

Here is a shell snippet that tests securesystemslib's encode_canonical function against the gibson042/canonicaljson-spec.

mkvirtualenv secsyslib-canonical # Optional

pip install securesystemslib
git clone [email protected]:gibson042/canonicaljson-spec.git
cd canonicaljson-spec

cat >secsyslib_canonical_json.py <<EOL
#!/usr/bin/env python
import sys, json, securesystemslib.formats

# Load JSON file passed as first argument by test.sh
with open(sys.argv[1]) as fobj:
  json_data = json.load(fobj)

json_canonical = securesystemslib.formats.encode_canonical(json_data)

# Write canonicalized json to stdout from where it is read by test.sh
sys.stdout.write(json_canonical)
EOL
chmod 755 secsyslib_canonical_json.py

PATH=$PATH:${PWD} ./test.sh secsyslib_canonical_json.py

@JustinCappos
Copy link

JustinCappos commented Oct 17, 2018 via email

@lukpueh
Copy link
Member Author

lukpueh commented Oct 18, 2018

Not sure about the exact requirements for TAP/ITE. However, the currently used canonical json format is also mandated by our specs (see in-toto: 4.1 Metaformat and TUF: 4.1 Metaformat).

lukpueh added a commit to lukpueh/in-toto-golang that referenced this issue Oct 18, 2018
The in-toto reference implementation uses a custom json
canonicalization function from securesystemslib.

Unfortunately it is not compatible with a similar go implementation
See secure-systems-lab/securesystemslib#159

In order to verify signatures created by the reference
implementation and also to create keyids, we have to use the
same canonicalization, hence this commit ports securesystemslib's
encode_canonical to go.
@lukpueh
Copy link
Member Author

lukpueh commented Nov 7, 2018

@JustinCappos I apologize for misreading the specs.

You were right, the in-toto specification does not mandate the OLPC canonicalization specification. As a matter of fact it explicitly states that implementers are not required to use JSON:

To provide descriptive examples, we will adopt "canonical JSON," as described in http://wiki.laptop.org/go/Canonical_JSON, as the data format. However, applications that desire to implement in-toto are not required to use JSON.

The TUF specification, however, leaves room for interpretation whether it is mandated or not:

All documents use a subset of the JSON object format, with floating-point numbers omitted. When calculating the digest of an object, we use the "canonical JSON" subdialect as described at http://wiki.laptop.org/go/Canonical_JSON

@JustinCappos
Copy link

JustinCappos commented Nov 7, 2018 via email

@lukpueh
Copy link
Member Author

lukpueh commented Nov 7, 2018

FWIW: @vladimir-v-diaz and @heartsucker had a lively discussion about this a year ago. The corresponding ticket -- theupdateframework/python-tuf#457 -- is still open.

@joshuagl
Copy link
Collaborator

joshuagl commented Mar 4, 2020

This might be a good topic for the next TUF community meeting.

Are TUF users/implementers happy with Canonical JSON?
If so, do we want to try and rally around a Canonical JSON specification?
If not, do we want to try and switch to something else with wider cross-language support?

@heartsucker
Copy link

See this for some of the reasons why it shouldn't use CJSON. theupdateframework/python-tuf#457

@joshuagl
Copy link
Collaborator

I sent a mail to the TUF discussion group seeking input from authors and implementers on this topic: https://groups.google.com/d/msg/theupdateframework/xuT5wDA8kh8/Mb0N1umxAAAJ

@mnm678
Copy link
Contributor

mnm678 commented Jun 12, 2020

The TUF specification no longer requires canonical json as of theupdateframework/specification#102.

@lukpueh
Copy link
Member Author

lukpueh commented Mar 16, 2023

Rather than switching to another canonicalization spec, we should encourage use of DSSE instead. Closing here.

@lukpueh lukpueh closed this as completed Mar 16, 2023
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

No branches or pull requests

5 participants