Subject: [Json] I-D: draft-rundgren-json-canonicalization-scheme-00

From: Anders Rundgren <[email-masked]>
Date: Fri, 16 Mar 2018 06:46:20 +0100

No, this I-D has not yet been submitted to the IETF but it is available anyway :-)

    Abstract

        Cryptographic operations like hashing and signing depend on that the
        target data does not change during serialization, transport, or
        parsing.  By applying the rules defined by JCS (JSON Canonicalization
        Scheme), data provided in the JSON [RFC8259] format can be exchanged
        "as is", while still being subject to secure cryptographic
        operations.  JCS achieves this by exploiting the strict operation of
        the JSON serialization method defined in ECMAScript beginning with
        version 6 [ES6].

        The intended audiences of this document are JSON tool vendors, as
        well as designers of JSON based cryptographic solutions.

Current draft:
https://cyberphone.github.io/doc/security/draft-rundgren-json-canonicalization-scheme.html

Workspace:
https://github.com/cyberphone/json-canonicalization

I would be VERY happy to get some feedback on this!
If you have any interest in co-authoring, I'm open to suggestions.

Thanx,
Anders

// ES6 based JSON canonicalizer
'use strict';
var canonicalize = function(object) {

     var buffer = '';
     serialize(object);
     return buffer;

     function serialize(object) {
         if (object !== null && typeof object === 'object') {
             if (Array.isArray(object)) {
                 buffer += '[';
                 let next = false;
// Array - Maintain element order
                 object.forEach((element) => {
                     if (next) {
                         buffer += ',';
                     }
                     next = true;
// Recursive call
                     serialize(element);
                 });
                 buffer += ']';
             } else {
                 buffer += '{';
                 let next = false;
// Object - Sort properties before serializing
Object.keys(object).sort().forEach((property) => {
                     if (next) {
                         buffer += ',';
                     }
                     next = true;
// Properties are just strings - Use ES6
                     buffer += JSON.stringify(property);
                     buffer += ':';
// Recursive call
                     serialize(object[property]);
                 });
                 buffer += '}';
             }
         } else {
// Primitive data type - Use ES6
             buffer += JSON.stringify(object);
         }
     }
};

---

From: Anders Rundgren <[email-masked]>
Date: Sat, 17 Mar 2018 19:58:18 +0100

https://cyberphone.github.io/doc/security/browser-json-canonicalization.html