@blamejs/pki 0.6.14 → 0.6.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -1
- package/lib/acme.js +59 -815
- package/lib/asn1-der.js +7 -245
- package/lib/attrcert-sign.js +12 -260
- package/lib/attrcert-verify.js +1 -7
- package/lib/byte-reader.js +0 -8
- package/lib/byte-writer.js +0 -11
- package/lib/cbor-det.js +0 -54
- package/lib/cmc-build.js +15 -357
- package/lib/cmc-verify.js +6 -239
- package/lib/cmp-build.js +41 -317
- package/lib/cmp-session.js +73 -760
- package/lib/cmp-verify.js +32 -488
- package/lib/cms-compress.js +3 -32
- package/lib/cms-decrypt.js +29 -294
- package/lib/cms-encrypt.js +14 -234
- package/lib/cms-sign.js +29 -324
- package/lib/cms-verify.js +9 -500
- package/lib/composite-kem.js +2 -102
- package/lib/composite-sig.js +1 -77
- package/lib/constants.js +0 -249
- package/lib/crl-sign.js +9 -237
- package/lib/crl-verify.js +1 -10
- package/lib/crmf-sign.js +19 -198
- package/lib/crmf-verify.js +1 -12
- package/lib/csr-sign.js +3 -34
- package/lib/csr-verify.js +1 -12
- package/lib/ct.js +28 -253
- package/lib/edwards-point.js +10 -44
- package/lib/est.js +28 -764
- package/lib/framework-error.js +4 -182
- package/lib/guard-all.js +1 -58
- package/lib/guard-async.js +1 -36
- package/lib/guard-bytes.js +6 -650
- package/lib/guard-compress.js +5 -102
- package/lib/guard-crypto.js +1 -40
- package/lib/guard-der.js +2 -93
- package/lib/guard-encoding.js +2 -60
- package/lib/guard-header.js +1 -36
- package/lib/guard-identifier.js +7 -531
- package/lib/guard-intrinsic.js +1 -150
- package/lib/guard-json.js +10 -73
- package/lib/guard-limits.js +1 -77
- package/lib/guard-list.js +1 -49
- package/lib/guard-name.js +3 -209
- package/lib/guard-parsed.js +7 -335
- package/lib/guard-range.js +1 -71
- package/lib/guard-secret.js +1 -102
- package/lib/guard-text.js +1 -64
- package/lib/guard-time.js +1 -97
- package/lib/hpke.js +3 -105
- package/lib/http-digest.js +14 -142
- package/lib/http-retry-after.js +1 -47
- package/lib/http-transport.js +21 -131
- package/lib/inspect.js +30 -284
- package/lib/ip-utils.js +6 -47
- package/lib/jose.js +7 -142
- package/lib/key.js +2 -67
- package/lib/lint.js +9 -194
- package/lib/merkle.js +1 -27
- package/lib/mime.js +9 -82
- package/lib/ocsp-request-verify.js +1 -14
- package/lib/ocsp-verify.js +1 -82
- package/lib/ocsp.js +11 -169
- package/lib/oid.js +5 -337
- package/lib/path-validate.js +103 -1492
- package/lib/pbes2.js +2 -89
- package/lib/pkcs12-build.js +31 -379
- package/lib/pki-build.js +64 -290
- package/lib/rc2.js +2 -18
- package/lib/rfc3339.js +4 -27
- package/lib/scep.js +8 -252
- package/lib/schema-all.js +0 -122
- package/lib/schema-attrcert.js +4 -146
- package/lib/schema-c509.js +153 -802
- package/lib/schema-cmc.js +5 -220
- package/lib/schema-cmp.js +2 -223
- package/lib/schema-cms.js +13 -427
- package/lib/schema-crl.js +5 -68
- package/lib/schema-crmf.js +6 -167
- package/lib/schema-csr.js +1 -54
- package/lib/schema-csrattrs.js +2 -87
- package/lib/schema-engine.js +0 -152
- package/lib/schema-ocsp.js +0 -117
- package/lib/schema-pkcs12.js +2 -93
- package/lib/schema-pkcs8.js +3 -35
- package/lib/schema-pkix.js +24 -655
- package/lib/schema-smime.js +0 -54
- package/lib/schema-tsp.js +3 -99
- package/lib/schema-x509.js +4 -63
- package/lib/shbs.js +11 -95
- package/lib/sign-scheme.js +2 -97
- package/lib/sigstore.js +9 -169
- package/lib/sleep.js +2 -8
- package/lib/smime.js +15 -408
- package/lib/tls-cert-compress.js +0 -62
- package/lib/trust.js +19 -185
- package/lib/tsp-sign.js +16 -270
- package/lib/validator-all.js +1 -30
- package/lib/validator-attcert.js +2 -46
- package/lib/validator-cose.js +2 -153
- package/lib/validator-keydesc.js +1 -37
- package/lib/validator-sig.js +1 -46
- package/lib/validator-tls.js +1 -88
- package/lib/validator-tpm.js +19 -122
- package/lib/verify-seam.js +1 -24
- package/lib/webauthn-mds.js +3 -400
- package/lib/webauthn.js +12 -833
- package/lib/webcrypto.js +5 -485
- package/lib/x509-sign.js +4 -108
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
package/lib/rc2.js
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// Copyright (c) blamejs contributors
|
|
3
3
|
"use strict";
|
|
4
|
-
//
|
|
5
|
-
// @internal -- no operator-facing namespace. RC2 is exposed only through the legacy-PBE bag decryption of
|
|
6
|
-
// pki.pkcs12.open (RFC 7292 App. C), never as a general cipher; RC2 is a broken 64-bit block cipher (RC2-40
|
|
7
|
-
// is export-crippled) kept solely to READ old `openssl pkcs12 -legacy` / NSS stores.
|
|
8
|
-
//
|
|
9
|
-
// rc2 -- a from-scratch RFC 2268 RC2-CBC. OpenSSL 3.x moved RC2 to the legacy provider (not loaded by Node),
|
|
10
|
-
// so node:crypto cannot decrypt these bags; this in-tree primitive fills that single gap (Hard rule #1: own
|
|
11
|
-
// code, no npm hop, so MANIFEST stays empty; it is a lib primitive alongside webcrypto.js, outside lib/vendor/). The
|
|
12
|
-
// RFC 2268 sec. 5 known-answer vectors pin the cipher; the `openssl -legacy` store is the end-to-end KAT.
|
|
4
|
+
// @internal
|
|
13
5
|
|
|
14
|
-
// RFC 2268 sec. 2: PITABLE, a fixed 256-byte permutation of the digits of pi used by the key schedule.
|
|
15
6
|
var PITABLE = [
|
|
16
7
|
0xd9, 0x78, 0xf9, 0xc4, 0x19, 0xdd, 0xb5, 0xed, 0x28, 0xe9, 0xfd, 0x79, 0x4a, 0xa0, 0xd8, 0x9d,
|
|
17
8
|
0xc6, 0x7e, 0x37, 0x83, 0x2b, 0x76, 0x53, 0x8e, 0x62, 0x4c, 0x64, 0x88, 0x44, 0x8b, 0xfb, 0xa2,
|
|
@@ -31,13 +22,12 @@ var PITABLE = [
|
|
|
31
22
|
0xc5, 0xf3, 0xdb, 0x47, 0xe5, 0xa5, 0x9c, 0x77, 0x0a, 0xa6, 0x20, 0x68, 0xfe, 0x7f, 0xc1, 0xad,
|
|
32
23
|
];
|
|
33
24
|
|
|
34
|
-
// RFC 2268 sec. 2: expand `key` (1..128 bytes) to the 64 16-bit words K[0..63], reducing to `effectiveBits`.
|
|
35
25
|
function _expandKey(key, effectiveBits) {
|
|
36
26
|
var T = key.length, L = new Array(128);
|
|
37
27
|
for (var i = 0; i < T; i++) L[i] = key[i];
|
|
38
28
|
for (i = T; i < 128; i++) L[i] = PITABLE[(L[i - 1] + L[i - T]) & 0xff];
|
|
39
29
|
var T8 = (effectiveBits + 7) >>> 3;
|
|
40
|
-
var TM = 0xff >>> ((8 - (effectiveBits & 7)) & 7);
|
|
30
|
+
var TM = 0xff >>> ((8 - (effectiveBits & 7)) & 7);
|
|
41
31
|
L[128 - T8] = PITABLE[L[128 - T8] & TM];
|
|
42
32
|
for (i = 127 - T8; i >= 0; i--) L[i] = PITABLE[L[i + 1] ^ L[i + T8]];
|
|
43
33
|
var K = new Array(64);
|
|
@@ -49,7 +39,6 @@ function _rotl16(x, n) { return ((x << n) | (x >>> (16 - n))) & 0xffff; }
|
|
|
49
39
|
function _rotr16(x, n) { return ((x >>> n) | (x << (16 - n))) & 0xffff; }
|
|
50
40
|
var SHIFT = [1, 2, 3, 5];
|
|
51
41
|
|
|
52
|
-
// RFC 2268 sec. 3: encrypt one 8-byte block (little-endian 16-bit words) in place-ish, returning 8 bytes.
|
|
53
42
|
function _encBlock(K, b, off) {
|
|
54
43
|
var R = [b[off] | (b[off + 1] << 8), b[off + 2] | (b[off + 3] << 8), b[off + 4] | (b[off + 5] << 8), b[off + 6] | (b[off + 7] << 8)];
|
|
55
44
|
var j = 0, i;
|
|
@@ -69,7 +58,6 @@ function _encBlock(K, b, off) {
|
|
|
69
58
|
return R;
|
|
70
59
|
}
|
|
71
60
|
|
|
72
|
-
// RFC 2268 sec. 3 inverse: decrypt one 8-byte block.
|
|
73
61
|
function _decBlock(K, b, off) {
|
|
74
62
|
var R = [b[off] | (b[off + 1] << 8), b[off + 2] | (b[off + 3] << 8), b[off + 4] | (b[off + 5] << 8), b[off + 6] | (b[off + 7] << 8)];
|
|
75
63
|
var j = 63, i;
|
|
@@ -93,12 +81,9 @@ function _wordsToBytes(R) {
|
|
|
93
81
|
return Buffer.from([R[0] & 0xff, (R[0] >>> 8) & 0xff, R[1] & 0xff, (R[1] >>> 8) & 0xff, R[2] & 0xff, (R[2] >>> 8) & 0xff, R[3] & 0xff, (R[3] >>> 8) & 0xff]);
|
|
94
82
|
}
|
|
95
83
|
|
|
96
|
-
// ECB block encrypt/decrypt (used by the KAT; CBC wraps them).
|
|
97
84
|
function encryptBlock(key, effectiveBits, block) { return _wordsToBytes(_encBlock(_expandKey(key, effectiveBits), block, 0)); }
|
|
98
85
|
function decryptBlock(key, effectiveBits, block) { return _wordsToBytes(_decBlock(_expandKey(key, effectiveBits), block, 0)); }
|
|
99
86
|
|
|
100
|
-
// RC2-CBC decrypt with PKCS#7 unpadding. `E`/`code` are the caller's typed-error factory + code; a structural
|
|
101
|
-
// fault (bad length, invalid pad) throws E(code) so the caller can collapse it to its uniform decrypt verdict.
|
|
102
87
|
function cbcDecrypt(key, effectiveBits, iv, ct, E, code) {
|
|
103
88
|
if (ct.length === 0 || ct.length % 8 !== 0) throw E(code, "RC2-CBC ciphertext length must be a non-zero multiple of 8");
|
|
104
89
|
var K = _expandKey(key, effectiveBits), out = Buffer.alloc(ct.length), prev = iv;
|
|
@@ -113,7 +98,6 @@ function cbcDecrypt(key, effectiveBits, iv, ct, E, code) {
|
|
|
113
98
|
return out.subarray(0, out.length - pad);
|
|
114
99
|
}
|
|
115
100
|
|
|
116
|
-
// RC2-CBC encrypt with PKCS#7 padding (for the round-trip KAT; pkcs12.open only decrypts).
|
|
117
101
|
function cbcEncrypt(key, effectiveBits, iv, pt) {
|
|
118
102
|
var padLen = 8 - (pt.length % 8), padded = Buffer.concat([pt, Buffer.alloc(padLen, padLen)]);
|
|
119
103
|
var K = _expandKey(key, effectiveBits), out = Buffer.alloc(padded.length), prev = iv;
|
package/lib/rfc3339.js
CHANGED
|
@@ -13,9 +13,6 @@
|
|
|
13
13
|
* domain fault code.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
// Exactly `count` ASCII digits at `start`, as an integer, or null on any non-digit or short read.
|
|
17
|
-
// The grammar is decided character by character (no regex, whose match protocol re-dispatches through
|
|
18
|
-
// a replaceable `exec`); `\d` in the original is ASCII [0-9] only, matched here as 48..57.
|
|
19
16
|
function _digitsAt(v, start, count) {
|
|
20
17
|
if (start + count > v.length) return null;
|
|
21
18
|
var val = 0;
|
|
@@ -27,10 +24,6 @@ function _digitsAt(v, start, count) {
|
|
|
27
24
|
return val;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
// RFC 3339 date-time scanned into its components, or null on any grammar violation:
|
|
31
|
-
// YYYY "-" MM "-" DD [Tt] HH ":" MM ":" SS, an optional "." + one-or-more fraction digits, then a
|
|
32
|
-
// zone -- [Zz] or ([+-]) OFFHH ":" OFFMM -- with nothing after. Calendar validity is checked by the
|
|
33
|
-
// caller. `offset` carries the numeric-offset hours/minutes when present, else null.
|
|
34
27
|
function _scanDateTime(v) {
|
|
35
28
|
var n = v.length, p = 0;
|
|
36
29
|
var year = _digitsAt(v, p, 4); if (year === null) return null; p += 4;
|
|
@@ -44,7 +37,7 @@ function _scanDateTime(v) {
|
|
|
44
37
|
var min = _digitsAt(v, p, 2); if (min === null) return null; p += 2;
|
|
45
38
|
if (v.charAt(p) !== ":") return null; p += 1;
|
|
46
39
|
var sec = _digitsAt(v, p, 2); if (sec === null) return null; p += 2;
|
|
47
|
-
if (v.charAt(p) === ".") {
|
|
40
|
+
if (v.charAt(p) === ".") {
|
|
48
41
|
p += 1;
|
|
49
42
|
var fracStart = p;
|
|
50
43
|
while (p < n) { var fc = v.charCodeAt(p); if (fc < 48 || fc > 57) break; p += 1; }
|
|
@@ -60,40 +53,30 @@ function _scanDateTime(v) {
|
|
|
60
53
|
var offMin = _digitsAt(v, p, 2); if (offMin === null) return null; p += 2;
|
|
61
54
|
offset = { hour: offHour, min: offMin };
|
|
62
55
|
} else {
|
|
63
|
-
return null;
|
|
56
|
+
return null;
|
|
64
57
|
}
|
|
65
|
-
if (p !== n) return null;
|
|
58
|
+
if (p !== n) return null;
|
|
66
59
|
return { year: year, month: month, day: day, hour: hour, min: min, sec: sec, offset: offset };
|
|
67
60
|
}
|
|
68
61
|
|
|
69
|
-
// isValid(v) -> boolean: v is a syntactically well-formed AND calendar-valid RFC 3339 date-time string.
|
|
70
62
|
function isValid(v) {
|
|
71
63
|
if (typeof v !== "string") return false;
|
|
72
64
|
var t = _scanDateTime(v);
|
|
73
65
|
if (!t) return false;
|
|
74
66
|
if (t.month < 1 || t.month > 12) return false;
|
|
75
|
-
// Reject a :60 leap second (Node's Date.parse returns NaN for it, so a comparison on such a value
|
|
76
|
-
// would silently pass) and any hour/minute/second out of range.
|
|
77
67
|
if (t.hour > 23 || t.min > 59 || t.sec > 59) return false;
|
|
78
68
|
var leap = (t.year % 4 === 0 && t.year % 100 !== 0) || t.year % 400 === 0;
|
|
79
69
|
var daysInMonth = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
80
70
|
if (t.day < 1 || t.day > daysInMonth[t.month - 1]) return false;
|
|
81
|
-
if (t.offset) { if (t.offset.hour > 23 || t.offset.min > 59) return false; }
|
|
71
|
+
if (t.offset) { if (t.offset.hour > 23 || t.offset.min > 59) return false; }
|
|
82
72
|
return true;
|
|
83
73
|
}
|
|
84
74
|
|
|
85
|
-
// parse(v, E, code, label) -> Date: a calendar-valid RFC 3339 date-time as a comparable Date; otherwise
|
|
86
|
-
// throws E(code, message) (the caller's (code, message) factory). isValid guarantees `new Date(v)` is a
|
|
87
|
-
// real instant (never NaN), so a returned Date is always safe to compare.
|
|
88
75
|
function parse(v, E, code, label) {
|
|
89
76
|
if (!isValid(v)) throw E(code, (label || "the value") + " is not a valid RFC 3339 date-time");
|
|
90
77
|
return new Date(v);
|
|
91
78
|
}
|
|
92
79
|
|
|
93
|
-
// RFC 3339 sec. 5.6 `full-date`: a calendar date with no time component. A distinct production from
|
|
94
|
-
// the date-time above, and deliberately a separate pair of functions instead of a flag: a consumer
|
|
95
|
-
// that expects one and is handed the other has a malformed value, not a permissible variant.
|
|
96
|
-
// RFC 3339 full-date scanned into its components (YYYY "-" MM "-" DD, nothing after), or null.
|
|
97
80
|
function _scanFullDate(v) {
|
|
98
81
|
var p = 0;
|
|
99
82
|
var year = _digitsAt(v, p, 4); if (year === null) return null; p += 4;
|
|
@@ -105,9 +88,6 @@ function _scanFullDate(v) {
|
|
|
105
88
|
return { year: year, month: month, day: day };
|
|
106
89
|
}
|
|
107
90
|
|
|
108
|
-
// isValidDate(v) -> boolean: v is a syntactically well-formed AND calendar-valid RFC 3339 full-date.
|
|
109
|
-
// Calendar validity matters as much as shape: "2021-02-30" parses as a Date in JS by rolling over
|
|
110
|
-
// into March, so a shape-only check would silently accept a day that does not exist.
|
|
111
91
|
function isValidDate(v) {
|
|
112
92
|
if (typeof v !== "string") return false;
|
|
113
93
|
var t = _scanFullDate(v);
|
|
@@ -118,9 +98,6 @@ function isValidDate(v) {
|
|
|
118
98
|
return t.day >= 1 && t.day <= daysInMonth[t.month - 1];
|
|
119
99
|
}
|
|
120
100
|
|
|
121
|
-
// parseDate(v, E, code, label) -> Date at UTC midnight. Anchored explicitly at UTC ("T00:00:00Z")
|
|
122
|
-
// instead of left to `new Date("YYYY-MM-DD")`, so the instant does not shift with the host time
|
|
123
|
-
// zone. A freshness or rollback comparison must not depend on where it runs.
|
|
124
101
|
function parseDate(v, E, code, label) {
|
|
125
102
|
if (!isValidDate(v)) throw E(code, (label || "the value") + " is not a valid RFC 3339 full-date (YYYY-MM-DD)");
|
|
126
103
|
return new Date(v + "T00:00:00Z");
|