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

JSON canonicalization uses multiple libraries. #339

Open
vembacher opened this issue Mar 20, 2024 · 2 comments
Open

JSON canonicalization uses multiple libraries. #339

vembacher opened this issue Mar 20, 2024 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@vembacher
Copy link
Contributor

Description

Different parts of code use different libraries for JSON canonicalization.

Examples:

sigstore-rs/src/sign.rs

Lines 327 to 332 in d5ba303

let canonicalized_body = {
let mut body = json_syntax::to_value(self.log_entry.body)
.expect("failed to parse constructed Body!");
body.canonicalize();
Some(base64.encode(body.compact_print().to_string()))
};

let mut buf = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(&mut buf, CanonicalFormatter::new());
bundle.payload.serialize(&mut ser).map_err(|e| {
SigstoreError::UnexpectedError(format!(
"Cannot create canonical JSON representation of bundle: {e:?}"
))
})?;

@vembacher vembacher added the enhancement New feature or request label Mar 20, 2024
@tnytown
Copy link
Contributor

tnytown commented Apr 8, 2024

I was responsible for pulling in the second canonicalizer (json_syntax).

For context: the Rekor OpenAPI spec mentions that RFC 8785 style canonicalization should be used for SET verification. The cosign code uses OLPC style canonicalization. Investigating further, it seems that the major differences between these two canonicalization schemes are in floating-point numbers (OLPC doesn't allow them) and strings (RFC 8785 escapes control characters).

Suggestion: Can we standardize on json_syntax (or another RFC 8785 canonicalizer) across the codebase? We should never see these differences, but I figure that we are better safe than sorry :)

xref #285 (comment)

@flavio
Copy link
Member

flavio commented Apr 9, 2024

I don't think it would be worth to drop the olpc-cjson dependency since it's a a transitive dependency of oci-distribution and tough.

json-syntax is a first level one. I don't think we can use olpc-cjson to validate Rekor's data. Maybe we could make this crate optional and require it only when the rekor feature is enabled

@flavio flavio added the good first issue Good for newcomers label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants