erdtman / java-json-canonicalization Goto Github PK
View Code? Open in Web Editor NEWJava JSON canonicalization
License: Apache License 2.0
Java JSON canonicalization
License: Apache License 2.0
Hey,
I'd like to report an issue that we managed to finally pin down today.
I'm pasting the concrete JSON that was causing different outputs of the JsonCanonicalizer for a given string:
String jsonIn = "{\"sub\":\"alice\",\"cid\":\"1\",\"scp\":[\"openid\",\"email\"],\"irt\":false,\"rtl\":-1,\"atl\":300,\"ate\":\"S\",\"atc\":false,\"iat\":1613669294,\"clm\":[\"email_verified\",\"email\"],\"rts\":\"_bM0U_knzP20VzbVAuzmvA\",\"k\":\"[\\\"alice\\\",\\\"\\\",\\\"1\\\"]\",\"tid\":\"t2\"}";
System.out.println(new JsonCanonicalizer(jsonIn).getEncodedString());
String jsonOut = "{\"sub\":\"alice\",\"scp\":[\"openid\",\"email\"],\"clm\":[\"email\",\"email_verified\"],\"irt\":false,\"rtl\":-1,\"k\":\"[\\\"alice\\\",\\\"\\\",\\\"1\\\"]\",\"tid\":\"t2\",\"rts\":\"_bM0U_knzP20VzbVAuzmvA\",\"atc\":false,\"ate\":\"S\",\"atl\":300,\"iat\":1613669294,\"cid\":\"1\"}";
System.out.println(new JsonCanonicalizer(jsonOut).getEncodedString());
The first printout produces:
{"atc":false,"ate":"S","atl":300,"cid":"1","clm":["email_verified","email"],"iat":1613669294,"irt":false,"k":"[\"alice\",\"\",\"1\"]","rtl":-1,"rts":"_bM0U_knzP20VzbVAuzmvA","scp":["openid","email"],"sub":"alice","tid":"t2"}
The second:
{"atc":false,"ate":"S","atl":300,"cid":"1","clm":["email","email_verified"],"iat":1613669294,"irt":false,"k":"[\"alice\",\"\",\"1\"]","rtl":-1,"rts":"_bM0U_knzP20VzbVAuzmvA","scp":["openid","email"],"sub":"alice","tid":"t2"}
The difference is in the ordering of the items in the "clm" JSON array - "email" and "email_verified".
The library was used to append HMACs to items stored in DynamoDB, which returns the JSON in non-deterministic order, hence the need for canonicalisation.
Version is 1.1.
In README.md, it will be great when the (example) output is included. Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.