@blamejs/pki 0.4.14 → 0.5.0
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 +61 -0
- package/MIGRATING.md +2 -2
- package/README.md +142 -137
- package/index.js +4 -0
- package/lib/acme.js +73 -1
- package/lib/asn1-der.js +2 -0
- package/lib/attrcert-sign.js +4 -0
- package/lib/cbor-det.js +32 -16
- package/lib/cmc-build.js +880 -0
- package/lib/cmc-verify.js +657 -0
- package/lib/cmp-build.js +8 -7
- package/lib/cmp-verify.js +11 -1
- package/lib/cms-sign.js +170 -8
- package/lib/cms-verify.js +80 -14
- package/lib/crl-sign.js +22 -0
- package/lib/crmf-sign.js +5 -2
- package/lib/csr-sign.js +3 -0
- package/lib/ct.js +72 -0
- package/lib/est.js +828 -32
- package/lib/framework-error.js +13 -0
- package/lib/guard-bytes.js +37 -1
- package/lib/guard-range.js +23 -1
- package/lib/http-transport.js +9 -3
- package/lib/inspect.js +28 -5
- package/lib/jose.js +15 -0
- package/lib/lint.js +4 -0
- package/lib/merkle.js +5 -5
- package/lib/ocsp.js +139 -11
- package/lib/oid.js +69 -1
- package/lib/path-validate.js +438 -100
- package/lib/pkcs12-build.js +12 -0
- package/lib/schema-all.js +19 -1
- package/lib/schema-attrcert.js +27 -0
- package/lib/schema-c509.js +6 -0
- package/lib/schema-cmc.js +791 -0
- package/lib/schema-cmp.js +25 -0
- package/lib/schema-cms.js +17 -1
- package/lib/schema-crl.js +23 -1
- package/lib/schema-crmf.js +13 -0
- package/lib/schema-csr.js +11 -0
- package/lib/schema-csrattrs.js +6 -0
- package/lib/schema-engine.js +6 -2
- package/lib/schema-ocsp.js +41 -0
- package/lib/schema-pkcs12.js +16 -0
- package/lib/schema-pkcs8.js +8 -0
- package/lib/schema-pkix.js +6 -0
- package/lib/schema-smime.js +4 -4
- package/lib/schema-tsp.js +32 -1
- package/lib/schema-x509.js +14 -1
- package/lib/shbs.js +12 -4
- package/lib/sigstore.js +4 -0
- package/lib/smime.js +28 -7
- package/lib/tls-cert-compress.js +15 -3
- package/lib/trust.js +27 -4
- package/lib/tsp-sign.js +41 -6
- package/lib/vendor/README.md +19 -19
- package/lib/webauthn.js +895 -26
- package/lib/x509-sign.js +3 -0
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
package/lib/pkcs12-build.js
CHANGED
|
@@ -469,6 +469,10 @@ function _normalizeSpec(spec, opts) {
|
|
|
469
469
|
* - `recipientCerts` -- (public-key privacy convenience) `[certDer|PEM, ...]`; the convenience-form cert + key are placed in one recipient-enveloped safe (a plaintext keyBag). For the full form, set per-`safeContents` `recipients: [{ cert }, ...]` -- CERTIFICATE recipients only (RSA-OAEP / ECDH / X25519 / X448 / ML-KEM, dispatched off the cert key); a password or KEK recipient is not public-key privacy and is rejected -- with an optional `contentEncryptionAlgorithm` (`aes-128|192|256-cbc`, default 256; GCM/AEAD rejected). `encrypt` (password) and `recipients` (public-key) on the same safe is rejected; privacy is independent of integrity.
|
|
470
470
|
* - `pem` (boolean) -- return a PEM `PKCS12` string instead of DER.
|
|
471
471
|
* @example
|
|
472
|
+
* var pair = await pki.key.generate("Ed25519");
|
|
473
|
+
* var signerKeyPkcs8 = await pki.key.export(pair.privateKey);
|
|
474
|
+
* var signerCertDer = await pki.x509.sign({ subject: "Signer", subjectPublicKey: await pki.key.export(pair.publicKey),
|
|
475
|
+
* notBefore: new Date("2026-01-01T00:00:00Z"), notAfter: new Date("2036-01-01T00:00:00Z") }, { key: signerKeyPkcs8 });
|
|
472
476
|
* var p12 = await pki.pkcs12.build({ safeContents: [{ bags: [
|
|
473
477
|
* { type: 'cert', cert: signerCertDer },
|
|
474
478
|
* { type: 'shroudedKey', key: signerKeyPkcs8, encrypt: { password: 'changeit' } } ] }] },
|
|
@@ -526,6 +530,10 @@ async function build(spec, opts) {
|
|
|
526
530
|
* or public-key-integrity store, or an unsupported MAC algorithm (never a falsy verdict standing in for an error).
|
|
527
531
|
*
|
|
528
532
|
* @example
|
|
533
|
+
* var pair = await pki.key.generate("Ed25519");
|
|
534
|
+
* var signerKeyPkcs8 = await pki.key.export(pair.privateKey);
|
|
535
|
+
* var signerCertDer = await pki.x509.sign({ subject: "Signer", subjectPublicKey: await pki.key.export(pair.publicKey),
|
|
536
|
+
* notBefore: new Date("2026-01-01T00:00:00Z"), notAfter: new Date("2036-01-01T00:00:00Z") }, { key: signerKeyPkcs8 });
|
|
529
537
|
* var p12 = await pki.pkcs12.build({ key: signerKeyPkcs8, cert: signerCertDer }, { password: 'changeit' });
|
|
530
538
|
* var ok = await pki.pkcs12.verifyMac(p12, 'changeit');
|
|
531
539
|
*/
|
|
@@ -614,6 +622,10 @@ function _capWork(iterations, salt, opts, keyLength, hardCap) {
|
|
|
614
622
|
* - `keys` (string) -- `der` (default) or `crypto` (also `pki.key.import` each private key to a CryptoKey).
|
|
615
623
|
* - `importAlgorithm` -- forwarded to `pki.key.import` for the ambiguous RSA / EC arms when `keys: crypto`.
|
|
616
624
|
* @example
|
|
625
|
+
* var pair = await pki.key.generate("Ed25519");
|
|
626
|
+
* var signerKeyPkcs8 = await pki.key.export(pair.privateKey);
|
|
627
|
+
* var signerCertDer = await pki.x509.sign({ subject: "Signer", subjectPublicKey: await pki.key.export(pair.publicKey),
|
|
628
|
+
* notBefore: new Date("2026-01-01T00:00:00Z"), notAfter: new Date("2036-01-01T00:00:00Z") }, { key: signerKeyPkcs8 });
|
|
617
629
|
* var p12 = await pki.pkcs12.build({ key: signerKeyPkcs8, cert: signerCertDer }, { password: 'changeit' });
|
|
618
630
|
* var store = await pki.pkcs12.open(p12, 'changeit');
|
|
619
631
|
* var keyDer = store.keys[0].pkcs8, certDer = store.certs[0].cert;
|
package/lib/schema-all.js
CHANGED
|
@@ -50,6 +50,15 @@ var attrcert = require("./schema-attrcert");
|
|
|
50
50
|
// SEQUENCE) so it is deliberately absent from FORMATS / the detect-and-route
|
|
51
51
|
// `parse`; it is reached only by explicit OID dispatch on a CMS attribute.
|
|
52
52
|
var smime = require("./schema-smime");
|
|
53
|
+
// cmc is likewise a COMPANION decoder, for the same reason arrived at from the
|
|
54
|
+
// other direction: a CMC message's outer DER root IS a CMS ContentInfo, which
|
|
55
|
+
// `cms.matches` already claims below. A `cmc` FORMATS row would either shadow CMS
|
|
56
|
+
// or be shadowed by it, and there is no structurally disjoint root to detect --
|
|
57
|
+
// the discriminator is the encapsulated content type, one layer in. So it is
|
|
58
|
+
// reached by explicit call, or by dispatching on
|
|
59
|
+
// `pki.schema.cms.parse(der).encapContentInfo.eContentType`, and exports no
|
|
60
|
+
// `matches` for nobody to call.
|
|
61
|
+
var cmc = require("./schema-cmc");
|
|
53
62
|
var frameworkError = require("./framework-error");
|
|
54
63
|
|
|
55
64
|
var SchemaError = frameworkError.SchemaError;
|
|
@@ -276,6 +285,10 @@ function all() { return FORMATS.map(function (f) { return f.name; }); }
|
|
|
276
285
|
* errors of the matched format propagate unchanged.
|
|
277
286
|
*
|
|
278
287
|
* @example
|
|
288
|
+
* var pair = await pki.key.generate("Ed25519");
|
|
289
|
+
* var der = await pki.x509.sign({ subject: "example.com", subjectPublicKey: await pki.key.export(pair.publicKey),
|
|
290
|
+
* notBefore: new Date("2026-01-01T00:00:00Z"), notAfter: new Date("2036-01-01T00:00:00Z") },
|
|
291
|
+
* { key: await pki.key.export(pair.privateKey) });
|
|
279
292
|
* var parsed = pki.schema.parse(der); // cert -> the pki.schema.x509 shape
|
|
280
293
|
*/
|
|
281
294
|
function parse(input) {
|
|
@@ -294,7 +307,7 @@ function parse(input) {
|
|
|
294
307
|
* @primitive pki.schema.detectFormat
|
|
295
308
|
* @signature pki.schema.detectFormat(input) -> string | null
|
|
296
309
|
* @since 0.3.8
|
|
297
|
-
* @status
|
|
310
|
+
* @status stable
|
|
298
311
|
* @spec RFC 5280
|
|
299
312
|
* @related pki.schema.parse, pki.schema.all
|
|
300
313
|
*
|
|
@@ -307,6 +320,10 @@ function parse(input) {
|
|
|
307
320
|
* same coercion / decode error `parse` throws.
|
|
308
321
|
*
|
|
309
322
|
* @example
|
|
323
|
+
* var pair = await pki.key.generate("Ed25519");
|
|
324
|
+
* var der = await pki.x509.sign({ subject: "example.com", subjectPublicKey: await pki.key.export(pair.publicKey),
|
|
325
|
+
* notBefore: new Date("2026-01-01T00:00:00Z"), notAfter: new Date("2036-01-01T00:00:00Z") },
|
|
326
|
+
* { key: await pki.key.export(pair.privateKey) });
|
|
310
327
|
* pki.schema.detectFormat(der); // "x509" | "crl" | "csr" | "cms" | ... | null
|
|
311
328
|
*/
|
|
312
329
|
function detectFormat(input) {
|
|
@@ -339,6 +356,7 @@ module.exports = {
|
|
|
339
356
|
csrattrs: { parse: csrattrs.parse },
|
|
340
357
|
attrcert: { parse: attrcert.parse, pemDecode: attrcert.pemDecode, pemEncode: attrcert.pemEncode },
|
|
341
358
|
smime: { parseSigningCertificate: smime.parseSigningCertificate, parseSigningCertificateV2: smime.parseSigningCertificateV2, parseSmimeCapabilities: smime.parseSmimeCapabilities, decodeAttribute: smime.decodeAttribute },
|
|
359
|
+
cmc: { parse: cmc.parse, parsePkiData: cmc.parsePkiData, parsePkiResponse: cmc.parsePkiResponse },
|
|
342
360
|
all: all,
|
|
343
361
|
parse: parse,
|
|
344
362
|
detectFormat: detectFormat,
|
package/lib/schema-attrcert.js
CHANGED
|
@@ -340,6 +340,15 @@ var ATTRIBUTE_CERTIFICATE = pkix.signedEnvelope(NS, ACINFO, {
|
|
|
340
340
|
* and `Asn1Error` when the underlying DER is malformed.
|
|
341
341
|
*
|
|
342
342
|
* @example
|
|
343
|
+
* var pair = await pki.key.generate("Ed25519");
|
|
344
|
+
* var key = await pki.key.export(pair.privateKey);
|
|
345
|
+
* var aaCert = await pki.x509.sign({ subject: "Attribute Authority", subjectPublicKey: await pki.key.export(pair.publicKey),
|
|
346
|
+
* notBefore: new Date("2026-01-01T00:00:00Z"), notAfter: new Date("2036-01-01T00:00:00Z") }, { key: key });
|
|
347
|
+
* var der = await pki.attrcert.sign(
|
|
348
|
+
* { holder: { entityName: { directoryName: "CN=Alice" } },
|
|
349
|
+
* notBeforeTime: new Date("2026-01-01T00:00:00Z"), notAfterTime: new Date("2027-01-01T00:00:00Z"),
|
|
350
|
+
* attributes: { role: { roleName: { uniformResourceIdentifier: "urn:role:admin" } } } },
|
|
351
|
+
* { cert: aaCert, key: key });
|
|
343
352
|
* var ac = pki.schema.attrcert.parse(der);
|
|
344
353
|
* ac.attributes[0].name; // "role"
|
|
345
354
|
* ac.validity.notAfterTime;// Date
|
|
@@ -383,6 +392,15 @@ function parseV1(input) {
|
|
|
383
392
|
* `PemError` on a missing / mismatched envelope or a non-base64 body.
|
|
384
393
|
*
|
|
385
394
|
* @example
|
|
395
|
+
* var pair = await pki.key.generate("Ed25519");
|
|
396
|
+
* var key = await pki.key.export(pair.privateKey);
|
|
397
|
+
* var aaCert = await pki.x509.sign({ subject: "Attribute Authority", subjectPublicKey: await pki.key.export(pair.publicKey),
|
|
398
|
+
* notBefore: new Date("2026-01-01T00:00:00Z"), notAfter: new Date("2036-01-01T00:00:00Z") }, { key: key });
|
|
399
|
+
* var pemText = await pki.attrcert.sign(
|
|
400
|
+
* { holder: { entityName: { directoryName: "CN=Alice" } },
|
|
401
|
+
* notBeforeTime: new Date("2026-01-01T00:00:00Z"), notAfterTime: new Date("2027-01-01T00:00:00Z"),
|
|
402
|
+
* attributes: { role: { roleName: { uniformResourceIdentifier: "urn:role:admin" } } } },
|
|
403
|
+
* { cert: aaCert, key: key }, { pem: true });
|
|
386
404
|
* var der = pki.schema.attrcert.pemDecode(pemText);
|
|
387
405
|
*/
|
|
388
406
|
function pemDecode(text, label) { return pkix.pemDecode(text, label === null ? null : (label || "ATTRIBUTE CERTIFICATE"), PemError); }
|
|
@@ -399,6 +417,15 @@ function pemDecode(text, label) { return pkix.pemDecode(text, label === null ? n
|
|
|
399
417
|
* same default `pemDecode` reads). Throws `PemError` on a malformed label.
|
|
400
418
|
*
|
|
401
419
|
* @example
|
|
420
|
+
* var pair = await pki.key.generate("Ed25519");
|
|
421
|
+
* var key = await pki.key.export(pair.privateKey);
|
|
422
|
+
* var aaCert = await pki.x509.sign({ subject: "Attribute Authority", subjectPublicKey: await pki.key.export(pair.publicKey),
|
|
423
|
+
* notBefore: new Date("2026-01-01T00:00:00Z"), notAfter: new Date("2036-01-01T00:00:00Z") }, { key: key });
|
|
424
|
+
* var der = await pki.attrcert.sign(
|
|
425
|
+
* { holder: { entityName: { directoryName: "CN=Alice" } },
|
|
426
|
+
* notBeforeTime: new Date("2026-01-01T00:00:00Z"), notAfterTime: new Date("2027-01-01T00:00:00Z"),
|
|
427
|
+
* attributes: { role: { roleName: { uniformResourceIdentifier: "urn:role:admin" } } } },
|
|
428
|
+
* { cert: aaCert, key: key });
|
|
402
429
|
* var pem = pki.schema.attrcert.pemEncode(der);
|
|
403
430
|
*/
|
|
404
431
|
function pemEncode(der, label) { return pkix.pemEncode(der, label || "ATTRIBUTE CERTIFICATE", PemError); }
|
package/lib/schema-c509.js
CHANGED
|
@@ -2327,6 +2327,12 @@ function _encodeC509Array(r) {
|
|
|
2327
2327
|
* only for the DER -> type-3 path; ignored when re-emitting a parse result.
|
|
2328
2328
|
*
|
|
2329
2329
|
* @example
|
|
2330
|
+
* // the type-3 (natively signed) encoding covers ECDSA-signed X.509 v3 certificates
|
|
2331
|
+
* var pair = await pki.key.generate({ name: "ECDSA", namedCurve: "P-256" });
|
|
2332
|
+
* var signerCertDer = await pki.x509.sign({ subject: "example.com", subjectPublicKey: await pki.key.export(pair.publicKey),
|
|
2333
|
+
* notBefore: new Date("2026-01-01T00:00:00Z"), notAfter: new Date("2036-01-01T00:00:00Z"),
|
|
2334
|
+
* extensions: { keyUsage: ["digitalSignature"] } },
|
|
2335
|
+
* { key: await pki.key.export(pair.privateKey) });
|
|
2330
2336
|
* var cbor = pki.schema.c509.encode(signerCertDer); // a DER cert -> a compact type-3 C509
|
|
2331
2337
|
* pki.schema.c509.parse(cbor).certificateType; // 3
|
|
2332
2338
|
*/
|