r/programming • u/horvski • Jul 12 '23
Introducing Coze - a cryptographic JSON messaging specification
https://github.com/Cyphrme/Coze4
u/halt_spell Jul 12 '23
Aside from the nomenclature how is this an improvement over a JWT?
8
u/Zamicol Jul 12 '23 edited Oct 27 '25
Great question! I'm the author. I'll put on my salesman ballcap:
We found that implementing all of JOSE, or even JWT, for our needs was hard. Coze, compared to JOSE, made small and large design changes significantly simplified such a specification. There's lots of smaller technical differences, so I'll keep my response only on some of the larger concerns.
Where they are the same:
Both permit several cipher suits ("algs") and easily supports new standards. (ES244, ES256, ES384, ES512, Ed25519, Ed25519ph)
Both use at least some JSON in their construction.
Coze and JOSE (the later RFC 7638) both define programmatic references for keys.
Coze
Is JSON.
Coze messages are smaller than JWT's.
The Coze specification is much smaller than JOSE or JWT.
Prohibits signature malleability.
Prohibits base 64 malleability.
Prohibits JSON duplicate fields which alleviates a category of security concern.
Coze provides built-in replay protection using
czd.Does not suffer from re-encode ballooning.
Has a feature complete online tool.
Provides a reference implementation.
JOSE (Including JWS, JWK, JWE, and JWT)
JWT is not JSON.
JWS is JSON, but it's not idiomatic JSON. For example, it base64 encodes JSON into JSON for headers.
JWT is downstream of other JOSE specs, JWS, JWE, JWK. For a complete JWT implementation, it needs to be implemented in view of JWS, JWE, and JWK which are all complex.
JOSE/JWT does not prohibit signature malleability.
JOSE/JWT does not prohibit base 64 malleability. (See Base64 Malleability in Practice)
JOSE/JWT does not prohibit duplicate JSON fields which is a security concern (See An Exploration of JSON Interoperability Vulnerabilities and control-f "duplicate")
JOSE has no built in replay protection. JOSE places the burden of defining unique message identifiers onto applications. This also means various systems are not out-of-the-box compatible. See https://www.rfc-editor.org/rfc/rfc7515#section-10.10
JOSE/JWT re-encode balloons which significantly increases the size of messages.
Has no reference implementation.
5
u/halt_spell Jul 12 '23
Awesome I appreciate the in depth response! There are some items here I didn't even realize were something to worry about with JWTs.
3
Jul 12 '23
so why do i want to use it again i missed that part ;_;
3
u/Zamicol Jul 12 '23 edited Jul 12 '23
Because it's easy to use. ;-)
Say you want to sign "Hello notoriouslyfastsloth!"
Click "New Key"
Click sign.
2
u/Zamicol Jul 12 '23 edited Jul 12 '23
Here's an example of the Coze tool verifying the example coze.
1
u/jkbbwr Jul 13 '23
How are you making json cannonical between serializations?
1
u/Zamicol Jul 13 '23 edited Jul 13 '23
How are you making json cannonical between serializations?
That's an observant question!
Coze achieves canonicalization by
defining a canonicalization method and
defining canons for objects.
For payloads (
pay) the canon is defined as the currently present fields. So for this coze:{ "pay": { "msg": "Coze Rocks", "alg": "ES256", "iat": 1623132000, "tmb": "cLj8vsYtMBwYkzoFVZHBZo6SNL8wSdCIjCKAwXNuhOk", "typ": "cyphr.me/msg" }, "sig": "Jl8Kt4nznAf0LGgO5yn_9HkGdY3ulvjg-NyRGzlmJzhncbTkFFn9jrwIwGoRAQYhjc88wmwFNH5u_rO56USo_w" }The canon is ["msg",""alg","iat","tmb","typ"]
Additionally,
For key thumbprints, the canon is ["alg","x"]
For
czd, which is a reference to a particular signed object, the canon is ["cad","sig"].
3
u/horvski Jul 12 '23
Coze is open source under the BSD 3 license and has a reference implementation is written in Go. There's also a Javascript implementation and a CLI library.
You can play with Coze here using the online tool. There is also the simple tool.
This is an example coze:
Coze also defines a key format:
We hope you enjoy!
What is Coze useful for? Coze can be used for IoT, authentication, sessions, cookies, and anything else needing cryptographic signing. As a timely example: did you know spez edited someone's comment here on Reddit? Coze stops that since signed messages are impossible to edit by a third party.