Live data from Hacker News

How (not) to sign a JSON object (2019)

latacora.com

41–45 of 45 posts

Re: How (not) to sign a JSON object (2019)

#41

Earlier quoted context omitted.

This is why, in one of my projects, I first stringified the JSON using built in JSON.stringify(your_json) function, then signed that string and sent the string, its signature, and public key to server. Server verifies the signature using the string and if passes, then uses JSON.parse(your_string) to get the original json.

The problem is the following two lines produce different outputs, despite having content that means the same thing: console.log(JSON.stringify({ x: 5, y: 6 })); console.log(JSON.stringify({ y: 6, x: 5 }));

I think the relevance of order is allowed to be up to each software's implementation:

https://datatracker.ietf.org/doc/html/rfc8259

Says:

> JSON parsing libraries have been observed to differ as to whether or not they make the ordering of object members visible to calling software. Implementations whose behavior does not depend on member ordering will be interoperable in the sense that they will not be affected by these differences.

So, different signature makes sense. But it should not be an issue as long as both software are calculating/validating the signature on the string and not json.

Re: How (not) to sign a JSON object (2019)

#43
post #38
post #30

What does JSON object signing provide that TLS doesn't? Does this imply that the application doesn't trust the transport/presentation layers?

Caching or other forms or retransmission of the data. Not all signed content is meant to be confidential. Or two-party confidential. Think about tokens. You have a refresh token that’s private between you and the destination, but you hand out session tokens to your users so they can talk to the destination directly. Or via another server that doesn’t have a cache coherency with the source.

Thanks, that makes sense.

Re: How (not) to sign a JSON object (2019)

#44
post #30

What does JSON object signing provide that TLS doesn't? Does this imply that the application doesn't trust the transport/presentation layers?

Our program has to sign XML documents so that the recipient can be certain a specific user signed it, as they're considered legally binding.

The documents are transmitted via a relaying party, as we don't have support for the protocol the recipient requires.

Similar cases could pop up in JSON-land, I imagine.

Re: How (not) to sign a JSON object (2019)

#45

Earlier quoted context omitted.

The problem is the following two lines produce different outputs, despite having content that means the same thing: console.log(JSON.stringify({ x: 5, y: 6 })); console.log(JSON.stringify({ y: 6, x: 5 }));

Usually, this is not a problem for signing.

Depends on your use case. We have this problem currently where I work.
Post reply on HN