Skip to content

Commit fae5e00

Browse files
authored
Signed-off-by: Brian DeHamer <[email protected]>
1 parent dbe2776 commit fae5e00

File tree

28 files changed

+448
-258
lines changed

28 files changed

+448
-258
lines changed

DEPENDENCIES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ graph LR;
772772
tuf-js-->make-fetch-happen;
773773
tuf-js-->tufjs-models["@tufjs/models"];
774774
tufjs-models-->minimatch;
775+
tufjs-models-->tufjs-canonical-json["@tufjs/canonical-json"];
775776
unique-filename-->unique-slug;
776777
unique-slug-->imurmurhash;
777778
validate-npm-package-license-->spdx-correct;

node_modules/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
!/@tootallnate/once
3838
!/@tufjs/
3939
/@tufjs/*
40+
!/@tufjs/canonical-json
4041
!/@tufjs/models
4142
!/abbrev
4243
!/abort-controller
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 GitHub and the TUF Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const COMMA = ',';
2+
const COLON = ':';
3+
const LEFT_SQUARE_BRACKET = '[';
4+
const RIGHT_SQUARE_BRACKET = ']';
5+
const LEFT_CURLY_BRACKET = '{';
6+
const RIGHT_CURLY_BRACKET = '}';
7+
8+
// Recursively encodes the supplied object according to the canonical JSON form
9+
// as specified at http://wiki.laptop.org/go/Canonical_JSON. It's a restricted
10+
// dialect of JSON in which keys are lexically sorted, floats are not allowed,
11+
// and only double quotes and backslashes are escaped.
12+
function canonicalize(object) {
13+
const buffer = [];
14+
if (typeof object === 'string') {
15+
buffer.push(canonicalizeString(object));
16+
} else if (typeof object === 'boolean') {
17+
buffer.push(JSON.stringify(object));
18+
} else if (Number.isInteger(object)) {
19+
buffer.push(JSON.stringify(object));
20+
} else if (object === null) {
21+
buffer.push(JSON.stringify(object));
22+
} else if (Array.isArray(object)) {
23+
buffer.push(LEFT_SQUARE_BRACKET);
24+
let first = true;
25+
object.forEach((element) => {
26+
if (!first) {
27+
buffer.push(COMMA);
28+
}
29+
first = false;
30+
buffer.push(canonicalize(element));
31+
});
32+
buffer.push(RIGHT_SQUARE_BRACKET);
33+
} else if (typeof object === 'object') {
34+
buffer.push(LEFT_CURLY_BRACKET);
35+
let first = true;
36+
Object.keys(object)
37+
.sort()
38+
.forEach((property) => {
39+
if (!first) {
40+
buffer.push(COMMA);
41+
}
42+
first = false;
43+
buffer.push(canonicalizeString(property));
44+
buffer.push(COLON);
45+
buffer.push(canonicalize(object[property]));
46+
});
47+
buffer.push(RIGHT_CURLY_BRACKET);
48+
} else {
49+
throw new TypeError('cannot encode ' + object.toString());
50+
}
51+
52+
return buffer.join('');
53+
}
54+
55+
// String canonicalization consists of escaping backslash (\) and double
56+
// quote (") characters and wrapping the resulting string in double quotes.
57+
function canonicalizeString(string) {
58+
const escapedString = string.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
59+
return '"' + escapedString + '"';
60+
}
61+
62+
module.exports = {
63+
canonicalize,
64+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "@tufjs/canonical-json",
3+
"version": "1.0.0",
4+
"description": "OLPC JSON canonicalization",
5+
"main": "lib/index.js",
6+
"typings": "lib/index.d.ts",
7+
"license": "MIT",
8+
"keywords": [
9+
"json",
10+
"canonical",
11+
"canonicalize",
12+
"canonicalization",
13+
"crypto",
14+
"signature",
15+
"olpc"
16+
],
17+
"author": "[email protected]",
18+
"repository": {
19+
"type": "git",
20+
"url": "git+https://github.com/theupdateframework/tuf-js.git"
21+
},
22+
"homepage": "https://github.com/theupdateframework/tuf-js/packages/canonical-json#readme",
23+
"bugs": {
24+
"url": "https://github.com/theupdateframework/tuf-js/issues"
25+
},
26+
"files": [
27+
"lib/"
28+
],
29+
"scripts": {
30+
"test": "jest"
31+
},
32+
"devDependencies": {
33+
"@types/node": "^18.14.1",
34+
"typescript": "^4.9.5"
35+
},
36+
"engines": {
37+
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
38+
}
39+
}

node_modules/@tufjs/models/dist/metadata.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
44
};
55
Object.defineProperty(exports, "__esModule", { value: true });
66
exports.Metadata = void 0;
7+
const canonical_json_1 = require("@tufjs/canonical-json");
78
const util_1 = __importDefault(require("util"));
89
const base_1 = require("./base");
910
const error_1 = require("./error");
@@ -13,7 +14,6 @@ const snapshot_1 = require("./snapshot");
1314
const targets_1 = require("./targets");
1415
const timestamp_1 = require("./timestamp");
1516
const utils_1 = require("./utils");
16-
const json_1 = require("./utils/json");
1717
/***
1818
* A container for signed TUF metadata.
1919
*
@@ -45,7 +45,7 @@ class Metadata {
4545
this.unrecognizedFields = unrecognizedFields || {};
4646
}
4747
sign(signer, append = true) {
48-
const bytes = (0, json_1.canonicalize)(this.signed.toJSON());
48+
const bytes = Buffer.from((0, canonical_json_1.canonicalize)(this.signed.toJSON()));
4949
const signature = signer(bytes);
5050
if (!append) {
5151
this.signatures = {};

node_modules/@tufjs/models/dist/utils/json.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

node_modules/@tufjs/models/dist/utils/verify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
44
};
55
Object.defineProperty(exports, "__esModule", { value: true });
66
exports.verifySignature = void 0;
7+
const canonical_json_1 = require("@tufjs/canonical-json");
78
const crypto_1 = __importDefault(require("crypto"));
8-
const json_1 = require("./json");
99
const verifySignature = (metaDataSignedData, key, signature) => {
10-
const canonicalData = (0, json_1.canonicalize)(metaDataSignedData) || '';
10+
const canonicalData = Buffer.from((0, canonical_json_1.canonicalize)(metaDataSignedData));
1111
return crypto_1.default.verify(undefined, canonicalData, key, Buffer.from(signature, 'hex'));
1212
};
1313
exports.verifySignature = verifySignature;

node_modules/@tufjs/models/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tufjs/models",
3-
"version": "1.0.1",
3+
"version": "1.0.3",
44
"description": "TUF metadata models",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -29,11 +29,12 @@
2929
"homepage": "https://github.com/theupdateframework/tuf-js/tree/main/packages/models#readme",
3030
"devDependencies": {
3131
"@types/minimatch": "^5.1.2",
32-
"@types/node": "^18.15.3",
33-
"typescript": "^4.9.5"
32+
"@types/node": "^18.15.11",
33+
"typescript": "^5.0.4"
3434
},
3535
"dependencies": {
36-
"minimatch": "^7.4.2"
36+
"minimatch": "^7.4.6",
37+
"@tufjs/canonical-json": "1.0.0"
3738
},
3839
"engines": {
3940
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"

node_modules/sigstore/dist/ca/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
33
exports.CAClient = void 0;
4-
const client_1 = require("../client");
54
const error_1 = require("../error");
5+
const external_1 = require("../external");
66
const format_1 = require("./format");
77
class CAClient {
88
constructor(options) {
9-
this.fulcio = new client_1.Fulcio({ baseURL: options.fulcioBaseURL });
9+
this.fulcio = new external_1.Fulcio({ baseURL: options.fulcioBaseURL });
1010
}
1111
async createSigningCertificate(identityToken, publicKey, challenge) {
1212
const request = (0, format_1.toCertificateRequest)(identityToken, publicKey, challenge);

0 commit comments

Comments
 (0)