micro509 0.17.1 → 0.18.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 +78 -6
- package/dist/crypto/crypto.d.ts +2 -3
- package/dist/crypto.d.ts +6 -0
- package/dist/der/der.d.ts +14 -4
- package/dist/der/der.js +19 -19
- package/dist/der.d.ts +26 -2
- package/dist/der.js +4 -4
- package/dist/index.d.ts +82 -15
- package/dist/index.js +19 -19
- package/dist/internal/asn1/asn1.d.ts +1 -2
- package/dist/internal/asn1/der.d.ts +1 -2
- package/dist/internal/asn1/oids.js +71 -353
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/asn1/oids.json.js +357 -0
- package/dist/internal/asn1/oids.json.js.map +1 -0
- package/dist/internal/crypto/algorithm-names.js +1 -1
- package/dist/internal/crypto/pbes2.d.ts +1 -2
- package/dist/internal/crypto/pbes2.js +70 -70
- package/dist/internal/crypto/prime-ec.js +37 -0
- package/dist/internal/crypto/prime-ec.js.map +1 -0
- package/dist/internal/crypto/rsa-pss.js +50 -50
- package/dist/internal/crypto/sig-verify.d.ts +1 -2
- package/dist/internal/crypto/sig-verify.js +60 -60
- package/dist/internal/crypto/signing.d.ts +1 -2
- package/dist/internal/crypto/signing.js +26 -26
- package/dist/internal/jose/json-data.js +108 -0
- package/dist/internal/jose/json-data.js.map +1 -0
- package/dist/internal/jose/strict-json.d.ts +1 -2
- package/dist/internal/shared/dn.d.ts +1 -2
- package/dist/internal/shared/dn.js +1 -1
- package/dist/internal/shared/ip.d.ts +1 -2
- package/dist/internal/verify/name-constraints-engine.js +64 -64
- package/dist/internal/verify/policy-engine.js +1 -1
- package/dist/internal/verify/verify-path.d.ts +1 -2
- package/dist/internal/verify/verify-path.js +19 -19
- package/dist/internal/x509/directory-name.js +10 -10
- package/dist/internal/x509/extension-errors.d.ts +1 -2
- package/dist/internal/x509/extension-registry.js +18 -18
- package/dist/internal/x509/general-name-profile.js +9 -9
- package/dist/internal/x509/general-name.js +32 -32
- package/dist/internal/x509/name-fields.js +1 -1
- package/dist/jose/base64url.d.ts +4 -0
- package/dist/jose/base64url.js +14 -0
- package/dist/jose/base64url.js.map +1 -0
- package/dist/jose/errors.d.ts +9 -3
- package/dist/jose/errors.js.map +1 -1
- package/dist/jose/jwe.d.ts +64 -0
- package/dist/jose/jwe.js +188 -0
- package/dist/jose/jwe.js.map +1 -0
- package/dist/jose/jwks.d.ts +38 -10
- package/dist/jose/jwks.js +156 -96
- package/dist/jose/jwks.js.map +1 -1
- package/dist/jose/jws.d.ts +8 -6
- package/dist/jose/jws.js +216 -170
- package/dist/jose/jws.js.map +1 -1
- package/dist/jose/jwt.d.ts +8 -2
- package/dist/jose/jwt.js +98 -98
- package/dist/jose/remote-jwks.d.ts +1 -2
- package/dist/jose/remote-jwks.js +106 -108
- package/dist/jose/remote-jwks.js.map +1 -1
- package/dist/jose.d.ts +15 -4
- package/dist/jose.js +7 -5
- package/dist/kdf/argon2.d.ts +7 -2
- package/dist/kdf.d.ts +6 -0
- package/dist/keys/keys.d.ts +31 -6
- package/dist/keys/keys.js +315 -233
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +11 -2
- package/dist/keys.js +2 -2
- package/dist/pem/pem.d.ts +1 -2
- package/dist/pem/pem.js +40 -25
- package/dist/pem/pem.js.map +1 -1
- package/dist/pem.d.ts +6 -0
- package/dist/pkcs/pfx.d.ts +2 -3
- package/dist/pkcs/pfx.js +142 -142
- package/dist/pkcs/pkcs12-mac.d.ts +1 -2
- package/dist/pkcs/pkcs12-mac.js +122 -122
- package/dist/pkcs/pkcs7.d.ts +14 -3
- package/dist/pkcs/pkcs7.js +268 -248
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +10 -1
- package/dist/pkcs.js +4 -4
- package/dist/result/result.d.ts +1 -2
- package/dist/result.d.ts +6 -0
- package/dist/revocation/chain.d.ts +2 -3
- package/dist/revocation/chain.js +52 -52
- package/dist/revocation/crl.d.ts +2 -3
- package/dist/revocation/crl.js +319 -319
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +2 -3
- package/dist/revocation/ocsp.js +395 -395
- package/dist/revocation/revocation.d.ts +2 -3
- package/dist/revocation/revocation.js +22 -22
- package/dist/revocation.d.ts +12 -3
- package/dist/revocation.js +4 -4
- package/dist/ssh/ssh.d.ts +2 -3
- package/dist/ssh/ssh.js +165 -170
- package/dist/ssh/ssh.js.map +1 -1
- package/dist/ssh/wire.d.ts +1 -2
- package/dist/ssh/wire.js +10 -10
- package/dist/ssh.d.ts +8 -0
- package/dist/verify/identity.d.ts +1 -2
- package/dist/verify/identity.js +31 -31
- package/dist/verify/name-constraints.d.ts +9 -2
- package/dist/verify/policy.d.ts +9 -2
- package/dist/verify/verify.d.ts +3 -4
- package/dist/verify/verify.js +121 -121
- package/dist/verify.d.ts +9 -0
- package/dist/x509/certificate.d.ts +4 -5
- package/dist/x509/certificate.js +40 -40
- package/dist/x509/csr.d.ts +3 -4
- package/dist/x509/csr.js +15 -15
- package/dist/x509/extensions.d.ts +1 -2
- package/dist/x509/extensions.js +165 -165
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.d.ts +1 -2
- package/dist/x509/name-text.d.ts +1 -2
- package/dist/x509/name.d.ts +1 -2
- package/dist/x509/name.js +15 -15
- package/dist/x509/parse.d.ts +3 -4
- package/dist/x509/parse.js +423 -423
- package/dist/x509.d.ts +17 -4
- package/dist/x509.js +8 -8
- package/package.json +22 -23
- package/dist/internal/asn1/oids2.js +0 -75
- package/dist/internal/asn1/oids2.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-data.js","names":["refusalMarker","value","size","budget","i","c","next","operation","length","descriptor","name","prototype","array","depth","names","result","items","record","limits","error"],"sources":["../../../src/internal/jose/json-data.ts"],"sourcesContent":["/** Bounded, descriptor-based snapshots of an already parsed JSON data model. @module */\n\nimport type { JsonValue } from '#micro509/internal/jose/strict-json';\n\ninterface Budget {\n\tbytes: number;\n\tnodes: number;\n\treadonly maxBytes: number;\n\treadonly maxNodes: number;\n\treadonly maxDepth: number;\n\treadonly active: Set<object>;\n}\n\ninterface Refusal {\n\treadonly marker: typeof refusalMarker;\n\treadonly code: 'invalid_json' | 'limit_exceeded';\n}\nconst refusalMarker: unique symbol = Symbol('JSON data refusal');\n\nfunction refuse(code: Refusal['code']): never {\n\tthrow { marker: refusalMarker, code } satisfies Refusal;\n}\nfunction isRefusal(value: unknown): value is Refusal {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\t'marker' in value &&\n\t\tvalue.marker === refusalMarker\n\t);\n}\nfunction bytes(budget: Budget, size: number): void {\n\tbudget.bytes += size;\n\tif (budget.bytes > budget.maxBytes) refuse('limit_exceeded');\n}\nfunction node(budget: Budget): void {\n\tif (++budget.nodes > budget.maxNodes) refuse('limit_exceeded');\n}\n/** Counts the UTF-8 bytes of the shortest JSON string spelling without allocating it. */\nfunction string(budget: Budget, value: string): string {\n\tif (value.length > budget.maxBytes - budget.bytes) refuse('limit_exceeded');\n\tbytes(budget, 2);\n\tfor (let i = 0; i < value.length; i++) {\n\t\tconst c = value.charCodeAt(i);\n\t\tif (c >= 0xd800 && c <= 0xdbff) {\n\t\t\tconst next = value.charCodeAt(++i);\n\t\t\tif (!(next >= 0xdc00 && next <= 0xdfff)) refuse('invalid_json');\n\t\t\tbytes(budget, 4);\n\t\t} else bytes(budget, characterBytes(c));\n\t}\n\treturn value;\n}\nfunction characterBytes(c: number): number {\n\tif (c >= 0xdc00 && c <= 0xdfff) refuse('invalid_json');\n\tif (c === 0x22 || c === 0x5c) return 2;\n\tif (c < 0x20) return [8, 9, 10, 12, 13].includes(c) ? 2 : 6;\n\treturn c < 0x80 ? 1 : c < 0x800 ? 2 : 3;\n}\n/** Reflection can execute proxy traps or encounter a revoked proxy; that is an input refusal. */\nfunction inspect<T>(operation: () => T): T {\n\ttry {\n\t\treturn operation();\n\t} catch {\n\t\treturn refuse('invalid_json');\n\t}\n}\nfunction arrayLength(value: object, budget: Budget): number {\n\tconst descriptor = inspect(() => Object.getOwnPropertyDescriptor(value, 'length'));\n\tconst length: unknown = descriptor?.value;\n\tif (typeof length !== 'number' || !Number.isSafeInteger(length) || length < 0)\n\t\trefuse('invalid_json');\n\tif (length > budget.maxNodes - budget.nodes) refuse('limit_exceeded');\n\treturn length;\n}\nfunction dataMember(value: object, name: string): unknown {\n\tconst descriptor = inspect(() => Object.getOwnPropertyDescriptor(value, name));\n\tif (descriptor === undefined || !('value' in descriptor) || !descriptor.enumerable)\n\t\trefuse('invalid_json');\n\treturn descriptor.value;\n}\nfunction checkPrototype(value: object, array: boolean): void {\n\tconst prototype = inspect(() => Object.getPrototypeOf(value));\n\tif (array ? prototype !== Array.prototype : prototype !== null && prototype !== Object.prototype)\n\t\trefuse('invalid_json');\n}\nfunction copy(value: unknown, budget: Budget, depth: number): JsonValue {\n\tnode(budget);\n\tif (value === null || typeof value === 'boolean') {\n\t\tbytes(budget, value === null ? 4 : value ? 4 : 5);\n\t\treturn value;\n\t}\n\tif (typeof value === 'string') return string(budget, value);\n\tif (typeof value === 'number') {\n\t\tif (!Number.isFinite(value)) refuse('invalid_json');\n\t\tbytes(budget, String(value).length);\n\t\treturn value;\n\t}\n\tif (typeof value !== 'object') refuse('invalid_json');\n\tif (depth >= budget.maxDepth) refuse('limit_exceeded');\n\tif (budget.active.has(value)) refuse('invalid_json');\n\tconst array = inspect(() => Array.isArray(value));\n\tcheckPrototype(value, array);\n\tbudget.active.add(value);\n\t// Refuse oversized arrays BEFORE allocating the list of all their indices.\n\tif (array) arrayLength(value, budget);\n\tconst names = inspect(() => Reflect.ownKeys(value));\n\tif (names.length > budget.maxNodes - budget.nodes + (array ? 1 : 0)) refuse('limit_exceeded');\n\tbytes(budget, 2);\n\tconst result = array\n\t\t? copyArray(value, names, budget, depth)\n\t\t: copyObject(value, names, budget, depth);\n\tbudget.active.delete(value);\n\treturn result;\n}\n\nfunction copyArray(\n\tvalue: object,\n\tnames: readonly PropertyKey[],\n\tbudget: Budget,\n\tdepth: number,\n): JsonValue {\n\tconst length = arrayLength(value, budget);\n\tif (names.length !== length + 1) refuse('invalid_json');\n\tconst items: JsonValue[] = [];\n\tfor (let i = 0; i < length; i++) {\n\t\tif (i > 0) bytes(budget, 1);\n\t\titems.push(copy(dataMember(value, String(i)), budget, depth + 1));\n\t}\n\treturn Object.freeze(items);\n}\nfunction copyObject(\n\tvalue: object,\n\tnames: readonly PropertyKey[],\n\tbudget: Budget,\n\tdepth: number,\n): JsonValue {\n\tconst record: Record<string, JsonValue> = {};\n\tfor (const [i, name] of names.entries()) {\n\t\tif (typeof name !== 'string') refuse('invalid_json');\n\t\tnode(budget);\n\t\tstring(budget, name);\n\t\tbytes(budget, i > 0 ? 2 : 1);\n\t\tObject.defineProperty(record, name, {\n\t\t\tvalue: copy(dataMember(value, name), budget, depth + 1),\n\t\t\tenumerable: true,\n\t\t});\n\t}\n\treturn Object.freeze(record);\n}\n\n/** Copies plain JSON data without invoking getters, coercion or `toJSON`. */\nexport function snapshotJsonData(\n\tvalue: unknown,\n\tlimits: { readonly maxBytes: number; readonly maxDepth: number; readonly maxNodes: number },\n):\n\t| { readonly ok: true; readonly value: JsonValue }\n\t| { readonly ok: false; readonly code: Refusal['code'] } {\n\ttry {\n\t\treturn {\n\t\t\tok: true,\n\t\t\tvalue: copy(value, { ...limits, bytes: 0, nodes: 0, active: new Set() }, 0),\n\t\t};\n\t} catch (error) {\n\t\tif (isRefusal(error)) return { ok: false, code: error.code };\n\t\tthrow error;\n\t}\n}\n"],"mappings":";AAiBA,MAAMA,IAA+B,OAAO,mBAAmB;AAE/D,SAAS,OAAO,GAA8B;CAC7C,MAAM;EAAE,QAAQA;EAAe;CAAK;AACrC;AACA,SAAS,UAAU,GAAkC;CACpD,OACC,OAAOC,KAAU,cACjBA,KACA,YAAYA,KACZA,EAAM,WAAWD;AAEnB;A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guishedNames(left: ParsedName, right: Parse
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function canonicalDnKey(name: ParsedName): string;
|
|
11
11
|
/** True when `subject` equals or is subordinate to `constraint` (RDN prefix match). */
|
|
12
|
-
export declare function isWithinDirectoryNameSubtree(subject: ParsedName, constraint: ParsedName): boolean;
|
|
13
|
-
//# sourceMappingURL=dn.d.ts.map
|
|
12
|
+
export declare function isWithinDirectoryNameSubtree(subject: ParsedName, constraint: ParsedName): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OIDS as e } from "../asn1/
|
|
1
|
+
import { OIDS as e } from "../asn1/oids.js";
|
|
2
2
|
import { A1_UNASSIGNED_RANGES as t, B2_CASE_FOLD as n, NFKC_3_2_CORRECTIONS as r } from "./rfc3454-tables.js";
|
|
3
3
|
import { COMBINING_MARK_RANGES as i } from "./rfc4518-tables.js";
|
|
4
4
|
// src/internal/shared/dn.ts
|
|
@@ -62,5 +62,4 @@ export declare function decodeIpAddress(bytes: Uint8Array): string;
|
|
|
62
62
|
* @param value IPv4 or IPv6 address string used to choose mask length.
|
|
63
63
|
* @returns An all-ones mask for the same address family.
|
|
64
64
|
*/
|
|
65
|
-
export declare function allOnesMaskForIpAddress(value: string): Uint8Array;
|
|
66
|
-
//# sourceMappingURL=ip.d.ts.map
|
|
65
|
+
export declare function allOnesMaskForIpAddress(value: string): Uint8Array;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { DECODE_REFUSAL_CODES as e } from "../../result/result.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { OIDS as u } from "../asn1/
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
2
|
+
import { childrenOf as t, decodeObjectIdentifier as n, decodeString as r, hexToBytes as i, requireElement as a, toHex as o } from "../asn1/asn1.js";
|
|
3
|
+
import { decodeRefusalOf as s, rethrowDecodeRefusal as c } from "../asn1/decode-refusal.js";
|
|
4
|
+
import { readRootElement as l } from "../asn1/der.js";
|
|
5
|
+
import { OIDS as u } from "../asn1/oids.js";
|
|
6
|
+
import { compareDistinguishedNames as d, directoryNameSubtreeMatch as f } from "../shared/dn.js";
|
|
7
|
+
import { domainToAscii as p } from "../shared/idna.js";
|
|
8
|
+
import { allOnesMaskForIpAddress as m, decodeIpAddress as h, parseIpAddressToBytes as g } from "../shared/ip.js";
|
|
9
|
+
import { isMailboxDomain as _, presentedSmtpUtf8MailboxDomain as v } from "../shared/mailbox.js";
|
|
10
|
+
import { uriAuthorityHost as y } from "../shared/uri-host.js";
|
|
11
|
+
import { parsePresentedSrvName as b, parseSrvNameRestriction as x, parseUriNameConstraint as S } from "../x509/general-name-profile.js";
|
|
12
|
+
import { nameFieldKeyFromOid as C } from "../x509/name-fields.js";
|
|
13
13
|
// src/internal/verify/name-constraints-engine.ts
|
|
14
14
|
/**
|
|
15
15
|
* Internal name-constraints evaluation engine.
|
|
@@ -40,7 +40,7 @@ function nameConstraintDetails(e) {
|
|
|
40
40
|
}
|
|
41
41
|
/** A certificate is self-issued when subject and issuer DNs are semantically equal (RFC 5280 §7.1). */
|
|
42
42
|
function isSelfIssued(e) {
|
|
43
|
-
return
|
|
43
|
+
return d(e.subject, e.issuer);
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* Initializes validation state from caller-supplied initial constraints.
|
|
@@ -129,18 +129,18 @@ function isSupportedNameConstraintForm(e) {
|
|
|
129
129
|
* Checks a certificate's subject DN and SANs against accumulated
|
|
130
130
|
* name constraints. Returns a failure if any name violates constraints.
|
|
131
131
|
*/
|
|
132
|
-
function checkCertificateNames(n, r
|
|
132
|
+
function checkCertificateNames(t, n, r) {
|
|
133
133
|
try {
|
|
134
|
-
let e = checkCertificateSubjectName(n, r
|
|
134
|
+
let e = checkCertificateSubjectName(t, n, r);
|
|
135
135
|
if (!e.ok) return e;
|
|
136
|
-
let
|
|
137
|
-
return
|
|
138
|
-
} catch (
|
|
139
|
-
let
|
|
140
|
-
if (
|
|
141
|
-
return nameConstraintFailure(
|
|
142
|
-
subjectCommonName:
|
|
143
|
-
actual:
|
|
136
|
+
let i = checkCertificateSubjectAltNames(t, n, r);
|
|
137
|
+
return i.ok ? checkCertificateSubjectEmailFallback(t, n, r) : i;
|
|
138
|
+
} catch (n) {
|
|
139
|
+
let i = s(n, e);
|
|
140
|
+
if (i === void 0) throw n;
|
|
141
|
+
return nameConstraintFailure(i.code, i.message, r, nameConstraintDetails({
|
|
142
|
+
subjectCommonName: t.subject.values.commonName,
|
|
143
|
+
actual: i.message
|
|
144
144
|
}));
|
|
145
145
|
}
|
|
146
146
|
}
|
|
@@ -171,7 +171,7 @@ function checkCertificateSubjectAltName(e, t, n, r) {
|
|
|
171
171
|
actual: a.actual
|
|
172
172
|
}));
|
|
173
173
|
let o = a.value;
|
|
174
|
-
return o?.type === "srv" && accumulatedHasConstraintsOfType("srv", t) &&
|
|
174
|
+
return o?.type === "srv" && accumulatedHasConstraintsOfType("srv", t) && b(asciiLowercase(o.value)) === void 0 ? nameConstraintFailure("name_constraints_violated", `SAN srv:${o.value} is not _Service.Name and cannot be evaluated against SRVName constraints`, r, nameConstraintDetails({
|
|
175
175
|
subjectCommonName: e.subject.values.commonName,
|
|
176
176
|
actual: `srv:${o.value}`
|
|
177
177
|
})) : o?.type === "uri" && accumulatedHasConstraintsOfType("uri", t) && uriConstraintHost(o.value) === void 0 ? nameConstraintFailure("name_constraints_violated", `SAN uri:${o.value} has no FQDN authority host and cannot be evaluated against URI name constraints`, r, nameConstraintDetails({
|
|
@@ -198,7 +198,7 @@ function checkSmtpUtf8Mailbox(e, t, n, r) {
|
|
|
198
198
|
}
|
|
199
199
|
/** RFC 9598 §5: a presented SmtpUTF8Mailbox whose domain the email constraints permit. */
|
|
200
200
|
function isSmtpUtf8MailboxDomainPermitted(e, t) {
|
|
201
|
-
let n =
|
|
201
|
+
let n = v(e);
|
|
202
202
|
return n !== void 0 && isMailboxDomainPermitted(n, t);
|
|
203
203
|
}
|
|
204
204
|
function isMailboxDomainPermitted(e, t) {
|
|
@@ -220,21 +220,21 @@ function isWellFormedConstraint(e) {
|
|
|
220
220
|
return t.length === 0 || isComparableDomain(t.startsWith(".") ? t.slice(1) : t);
|
|
221
221
|
}
|
|
222
222
|
case "email": return constraintMailboxDomain(e.value) !== void 0;
|
|
223
|
-
case "srv": return
|
|
223
|
+
case "srv": return x(asciiLowercase(e.value)) !== void 0;
|
|
224
224
|
case "directoryName": return parseDirectoryNameDerHex(e.derHex) !== void 0;
|
|
225
|
-
case "uri": return
|
|
225
|
+
case "uri": return S(e.value) !== void 0;
|
|
226
226
|
case "ip": return !0;
|
|
227
227
|
default: throw Error(`Unhandled NameConstraintForm type: ${String(e)}`);
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
/** Labels of 1 to 63 letters, digits, hyphens or underscores, with each `xn--` label an A-label. */
|
|
231
231
|
function isComparableDomain(e) {
|
|
232
|
-
return e.length <= 253 && e.split(".").every((e) => /^[a-z0-9_-]{1,63}$/.test(e)) &&
|
|
232
|
+
return e.length <= 253 && e.split(".").every((e) => /^[a-z0-9_-]{1,63}$/.test(e)) && p(e, "lookup").ok;
|
|
233
233
|
}
|
|
234
234
|
/** RFC 9598 §6: the lowercased domain of an rfc822Name constraint, keeping a leading ".". */
|
|
235
235
|
function constraintMailboxDomain(e) {
|
|
236
236
|
let t = asciiLowercase(e.slice(e.lastIndexOf("@") + 1)), n = t.startsWith(".") ? t.slice(1) : t;
|
|
237
|
-
return
|
|
237
|
+
return _(n, "lookup") ? t : void 0;
|
|
238
238
|
}
|
|
239
239
|
function matchesMailboxDomainConstraint(e, t) {
|
|
240
240
|
let n = constraintMailboxDomain(t);
|
|
@@ -347,8 +347,8 @@ function sanToConstraintCheckable(e) {
|
|
|
347
347
|
ok: !0,
|
|
348
348
|
value: {
|
|
349
349
|
type: "ip",
|
|
350
|
-
addressBytes:
|
|
351
|
-
maskBytes:
|
|
350
|
+
addressBytes: g(e.value),
|
|
351
|
+
maskBytes: m(e.value)
|
|
352
352
|
}
|
|
353
353
|
};
|
|
354
354
|
} catch {
|
|
@@ -405,7 +405,7 @@ function nameMatchesConstraint(e, t) {
|
|
|
405
405
|
* that domain or any subdomain added to the left.
|
|
406
406
|
*/
|
|
407
407
|
function matchesSrvConstraint(e, t) {
|
|
408
|
-
let n =
|
|
408
|
+
let n = b(asciiLowercase(e)), r = x(asciiLowercase(t));
|
|
409
409
|
return n !== void 0 && r !== void 0 && (r.service.length === 0 || n.service === r.service) && (r.name.length === 0 || n.name === r.name || n.name.endsWith(`.${r.name}`));
|
|
410
410
|
}
|
|
411
411
|
/**
|
|
@@ -444,7 +444,7 @@ function matchesEmailConstraint(e, t) {
|
|
|
444
444
|
* its subdomains only.
|
|
445
445
|
*/
|
|
446
446
|
function matchesUriConstraint(e, t) {
|
|
447
|
-
let n = uriConstraintHost(e), r =
|
|
447
|
+
let n = uriConstraintHost(e), r = S(t);
|
|
448
448
|
if (n === void 0 || r === void 0) return !1;
|
|
449
449
|
switch (r.type) {
|
|
450
450
|
case "any": return !0;
|
|
@@ -459,7 +459,7 @@ function matchesUriConstraint(e, t) {
|
|
|
459
459
|
* reg-name that is not a domain name, or a single-label host.
|
|
460
460
|
*/
|
|
461
461
|
function uriConstraintHost(e) {
|
|
462
|
-
let t =
|
|
462
|
+
let t = y(e, "presented");
|
|
463
463
|
return t.type === "dns" && t.name.includes(".") ? t.name : void 0;
|
|
464
464
|
}
|
|
465
465
|
/**
|
|
@@ -481,28 +481,28 @@ function matchesIpConstraint(e, t, n) {
|
|
|
481
481
|
*/
|
|
482
482
|
function matchesDnConstraint(e, t) {
|
|
483
483
|
let n = parseDirectoryNameDerHex(e), r = parseDirectoryNameDerHex(t);
|
|
484
|
-
return n === void 0 || r === void 0 ? "mismatch" :
|
|
484
|
+
return n === void 0 || r === void 0 ? "mismatch" : f(n, r);
|
|
485
485
|
}
|
|
486
486
|
/** Re-parses a hex-encoded DER Name for RDN-by-RDN comparison. Returns `undefined` on malformed input. */
|
|
487
|
-
function parseDirectoryNameDerHex(
|
|
488
|
-
if (/^(?:[0-9a-fA-F]{2})+$/.test(
|
|
489
|
-
let e =
|
|
490
|
-
if (
|
|
491
|
-
let a = [],
|
|
492
|
-
for (let
|
|
493
|
-
let
|
|
494
|
-
if (
|
|
495
|
-
a.push(
|
|
496
|
-
for (let e of
|
|
487
|
+
function parseDirectoryNameDerHex(n) {
|
|
488
|
+
if (/^(?:[0-9a-fA-F]{2})+$/.test(n)) try {
|
|
489
|
+
let e = i(n), r = unwrapDirectoryNameElement(e, l(e, { maxDepth: 64 }));
|
|
490
|
+
if (r.tag !== 48) return;
|
|
491
|
+
let a = [], s = [], c = {};
|
|
492
|
+
for (let n of t(e, r)) {
|
|
493
|
+
let t = parseDirectoryNameRdn(e, n);
|
|
494
|
+
if (t === void 0) return;
|
|
495
|
+
a.push(t);
|
|
496
|
+
for (let e of t.attributes) s.push(e), e.key !== void 0 && c[e.key] === void 0 && (c[e.key] = e.value);
|
|
497
497
|
}
|
|
498
498
|
return {
|
|
499
|
-
derHex:
|
|
499
|
+
derHex: o(e),
|
|
500
500
|
rdns: a,
|
|
501
|
-
attributes:
|
|
501
|
+
attributes: s,
|
|
502
502
|
values: c
|
|
503
503
|
};
|
|
504
504
|
} catch (t) {
|
|
505
|
-
|
|
505
|
+
c(t, e);
|
|
506
506
|
return;
|
|
507
507
|
}
|
|
508
508
|
}
|
|
@@ -512,29 +512,29 @@ function parseDirectoryNameDerHex(t) {
|
|
|
512
512
|
* Some encoders produce `[4] { SEQ { SEQ { SET... } } }` instead of `[4] { SEQ { SET... } }`.
|
|
513
513
|
* A single SEQUENCE child indicates the extra wrapper (valid Names have SET children).
|
|
514
514
|
*/
|
|
515
|
-
function unwrapDirectoryNameElement(e,
|
|
516
|
-
if (
|
|
517
|
-
let
|
|
518
|
-
return
|
|
515
|
+
function unwrapDirectoryNameElement(e, n) {
|
|
516
|
+
if (n.tag !== 48) return n;
|
|
517
|
+
let r = t(e, n), i = r[0];
|
|
518
|
+
return r.length === 1 && i?.tag === 48 ? i : n;
|
|
519
519
|
}
|
|
520
520
|
/** Parses one SET element (a single RDN) from the DER Name SEQUENCE. */
|
|
521
|
-
function parseDirectoryNameRdn(
|
|
522
|
-
if (
|
|
523
|
-
let
|
|
524
|
-
if (
|
|
521
|
+
function parseDirectoryNameRdn(i, s) {
|
|
522
|
+
if (s.tag !== 49) return;
|
|
523
|
+
let l = t(i, s);
|
|
524
|
+
if (l.length === 0) return;
|
|
525
525
|
let u = [], d = {};
|
|
526
|
-
for (let
|
|
527
|
-
if (
|
|
528
|
-
let s = i
|
|
526
|
+
for (let o of l) {
|
|
527
|
+
if (o.tag !== 48) return;
|
|
528
|
+
let s = t(i, o), l = s[0], f = s[1];
|
|
529
529
|
if (l === void 0 || f === void 0 || s.length !== 2 || l.tag !== 6) return;
|
|
530
|
-
let p = a(
|
|
530
|
+
let p = n(a(l, "directoryName OID").value), m;
|
|
531
531
|
try {
|
|
532
|
-
m =
|
|
532
|
+
m = r(f.tag, a(f, "directoryName value").value);
|
|
533
533
|
} catch (t) {
|
|
534
|
-
|
|
534
|
+
c(t, e);
|
|
535
535
|
return;
|
|
536
536
|
}
|
|
537
|
-
let h =
|
|
537
|
+
let h = C(p), g = h === void 0 ? {
|
|
538
538
|
oid: p,
|
|
539
539
|
valueTag: f.tag,
|
|
540
540
|
value: m
|
|
@@ -547,7 +547,7 @@ function parseDirectoryNameRdn(t, r) {
|
|
|
547
547
|
u.push(g), h !== void 0 && d[h] === void 0 && (d[h] = m);
|
|
548
548
|
}
|
|
549
549
|
if (u.length !== 0) return {
|
|
550
|
-
derHex:
|
|
550
|
+
derHex: o(i.slice(s.start - s.headerLength, s.end)),
|
|
551
551
|
attributes: u,
|
|
552
552
|
values: d
|
|
553
553
|
};
|
|
@@ -558,7 +558,7 @@ function formatConstraintForm(e) {
|
|
|
558
558
|
case "dns": return `dns:${e.value}`;
|
|
559
559
|
case "email": return `email:${e.value}`;
|
|
560
560
|
case "uri": return `uri:${e.value}`;
|
|
561
|
-
case "ip": return `ip:${
|
|
561
|
+
case "ip": return `ip:${h(e.addressBytes)}`;
|
|
562
562
|
case "directoryName": return `dn:${e.derHex.slice(0, 20)}${e.derHex.length > 20 ? "..." : ""}`;
|
|
563
563
|
case "srv": return `srv:${e.value}`;
|
|
564
564
|
default: throw Error(`Unhandled NameConstraintForm type: ${String(e)}`);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { ParsedCertificate } from "../../x509/parse.js";
|
|
2
2
|
/** Returns `true` if the certificate's subject and issuer DNs are semantically equal (RFC 5280 §7.1). */
|
|
3
|
-
export declare function isSelfIssued(certificate: ParsedCertificate): boolean;
|
|
4
|
-
//# sourceMappingURL=verify-path.d.ts.map
|
|
3
|
+
export declare function isSelfIssued(certificate: ParsedCertificate): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { toHex as e } from "../asn1/asn1.js";
|
|
2
|
+
import { DECODE_LIMIT_CODES as t, decodeRefusalOf as n } from "../asn1/decode-refusal.js";
|
|
3
3
|
import { verifySignedDataDetailed as r } from "../crypto/sig-verify.js";
|
|
4
4
|
import { canonicalDnKey as i, compareDistinguishedNames as a } from "../shared/dn.js";
|
|
5
5
|
import { parseCertificatesFromSource as o } from "../../x509/parse.js";
|
|
@@ -54,13 +54,13 @@ function verifyCertificateSignature(e, t) {
|
|
|
54
54
|
return signatureCheck(() => r(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signatureValue, e.tbsCertificateDer));
|
|
55
55
|
}
|
|
56
56
|
/** Runs `verify` as a path check, reporting a runtime failure as `signature_invalid` and a decoding limit as `limit_exceeded`. */
|
|
57
|
-
async function signatureCheck(
|
|
57
|
+
async function signatureCheck(e) {
|
|
58
58
|
let r;
|
|
59
59
|
try {
|
|
60
|
-
r = await
|
|
61
|
-
} catch (
|
|
62
|
-
let r =
|
|
63
|
-
if (r === void 0) throw
|
|
60
|
+
r = await e();
|
|
61
|
+
} catch (e) {
|
|
62
|
+
let r = n(e, t);
|
|
63
|
+
if (r === void 0) throw e;
|
|
64
64
|
return {
|
|
65
65
|
ok: !1,
|
|
66
66
|
code: r.code,
|
|
@@ -127,15 +127,15 @@ function rebaseDiagnostic(e, t, n) {
|
|
|
127
127
|
* step. Returns the first fully anchored path or the deepest partial path
|
|
128
128
|
* with the best failure encountered.
|
|
129
129
|
*/
|
|
130
|
-
async function buildChainInternal(
|
|
131
|
-
let p, m = [...
|
|
130
|
+
async function buildChainInternal(t, n, r, a, o, l, u = c, d = s, f = () => Promise.resolve(void 0)) {
|
|
131
|
+
let p, m = [...n, ...r], h = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), _ = new Set(r.map((e) => fingerprint(e))), v = /* @__PURE__ */ new Map();
|
|
132
132
|
for (let e of a) {
|
|
133
133
|
let t = i(e.subject), n = v.get(t);
|
|
134
134
|
n === void 0 ? v.set(t, [e]) : n.push(e);
|
|
135
135
|
}
|
|
136
136
|
let y = { current: {
|
|
137
137
|
kind: "none",
|
|
138
|
-
path: [
|
|
138
|
+
path: [t]
|
|
139
139
|
} }, b = /* @__PURE__ */ new Map(), x = [], S = /* @__PURE__ */ new Map(), C = {
|
|
140
140
|
remaining: d,
|
|
141
141
|
exhausted: !1
|
|
@@ -144,7 +144,7 @@ async function buildChainInternal(e, t, r, a, o, l, u = c, d = s, f = () => Prom
|
|
|
144
144
|
let n = i(e.subject), r = h.get(n);
|
|
145
145
|
r === void 0 ? h.set(n, [e]) : r.push(e), g.set(fingerprint(e), t);
|
|
146
146
|
});
|
|
147
|
-
let T = m.length + 1, E = fingerprint(
|
|
147
|
+
let T = m.length + 1, E = fingerprint(t), D = await search(t, [t], /* @__PURE__ */ new Set([E]), 0);
|
|
148
148
|
if (D !== void 0) {
|
|
149
149
|
let e = D[D.length - 1];
|
|
150
150
|
return {
|
|
@@ -267,12 +267,12 @@ async function buildChainInternal(e, t, r, a, o, l, u = c, d = s, f = () => Prom
|
|
|
267
267
|
function chargeBudget() {
|
|
268
268
|
return C.remaining === 0 ? (C.exhausted = !0, !1) : (--C.remaining, !0);
|
|
269
269
|
}
|
|
270
|
-
function verifySignatureOnce(
|
|
271
|
-
return verifyOnce(`c:${fingerprint(
|
|
270
|
+
function verifySignatureOnce(t, n) {
|
|
271
|
+
return verifyOnce(`c:${fingerprint(t)}:${e(n.subjectPublicKeyInfoDer)}`, () => u.certificate(t, n));
|
|
272
272
|
}
|
|
273
|
-
function verifyAnchorOnce(
|
|
274
|
-
let r = `${
|
|
275
|
-
return verifyOnce(`a:${fingerprint(
|
|
273
|
+
function verifyAnchorOnce(t, n) {
|
|
274
|
+
let r = `${n.publicKeyAlgorithmOid}:${n.publicKeyParametersOid ?? ""}:${e(n.subjectPublicKeyInfoDer)}`;
|
|
275
|
+
return verifyOnce(`a:${fingerprint(t)}:${r}`, () => u.trustAnchor(t, n));
|
|
276
276
|
}
|
|
277
277
|
/** One signature check per distinct certificate-and-key pair for the whole search. */
|
|
278
278
|
function verifyOnce(e, t) {
|
|
@@ -431,9 +431,9 @@ function isNonNegativeInteger(e) {
|
|
|
431
431
|
/** Cache for computed fingerprints to avoid repeated toHex() calls. */
|
|
432
432
|
const u = /* @__PURE__ */ new WeakMap();
|
|
433
433
|
/** Returns a hex fingerprint of the certificate's raw DER, used for cycle detection and dedup. */
|
|
434
|
-
function fingerprint(
|
|
435
|
-
let
|
|
436
|
-
return
|
|
434
|
+
function fingerprint(t) {
|
|
435
|
+
let n = u.get(t);
|
|
436
|
+
return n === void 0 && (n = e(t.der), u.set(t, n)), n;
|
|
437
437
|
}
|
|
438
438
|
export { s as DEFAULT_MAX_PATH_BUILDING_CHECKS, assertPathBuildingChecks, authorityKeyIdentifierMismatch, buildChainInternal, countCaCertificatesBelowParsed, isSelfIssued, isWithinValidity, loadCertificates, loadSingleCertificate, rebaseDiagnostic, verifyCertificateSignature, verifyTrustAnchorSignature };
|
|
439
439
|
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { childrenOf as e, decodeObjectIdentifier as t, requireElement as n } from "../asn1/asn1.js";
|
|
2
|
+
import { readRootElement as r } from "../asn1/der.js";
|
|
3
3
|
// src/internal/x509/directory-name.ts
|
|
4
4
|
/** Read and validate the explicit X.501 Name carried by directoryName [4]. */
|
|
5
5
|
function readDirectoryNameTlv(i) {
|
|
6
|
-
let a = new Uint8Array(i.value), o = r(
|
|
6
|
+
let a = new Uint8Array(i.value), o = n(r(a, { maxDepth: 64 }), "directoryName Name");
|
|
7
7
|
if (o.tag !== 48) throw Error("directoryName must wrap a Name SEQUENCE");
|
|
8
|
-
for (let
|
|
9
|
-
if (
|
|
10
|
-
let r =
|
|
8
|
+
for (let n of e(a, o)) {
|
|
9
|
+
if (n.tag !== 49) throw Error("directoryName RDN must use SET");
|
|
10
|
+
let r = e(a, n);
|
|
11
11
|
if (r.length === 0) throw Error("directoryName RDN must not be empty");
|
|
12
|
-
for (let
|
|
13
|
-
if (
|
|
14
|
-
let r =
|
|
12
|
+
for (let n of r) {
|
|
13
|
+
if (n.tag !== 48) throw Error("directoryName attribute must use SEQUENCE");
|
|
14
|
+
let r = e(a, n), i = r[0];
|
|
15
15
|
if (r.length !== 2 || i === void 0 || i.tag !== 6) throw Error("directoryName attribute must contain an OID and value");
|
|
16
|
-
|
|
16
|
+
t(i.value);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
return a;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
/** Machine-readable reason an extension encoder rejected its construction input. */
|
|
2
|
-
export type ExtensionEncoderErrorCode = "authority_info_access_empty" | "authority_info_access_ocsp_not_uri" | "certificate_policies_empty" | "crl_distribution_points_empty" | "directory_name_not_sequence" | "display_text_control_character" | "display_text_ia5_string" | "display_text_lone_surrogate" | "display_text_not_nfc" | "display_text_out_of_range" | "distribution_point_crl_issuer_empty" | "distribution_point_crl_issuer_not_directory_name" | "distribution_point_empty" | "distribution_point_full_name_empty" | "distribution_point_relative_name_multiple_crl_issuers" | "domain_trailing_dot" | "duplicate_extension_oid" | "duplicate_policy_oid" | "edwards_key_usage_forbids_agreement_bit" | "edwards_key_usage_forbids_key_cert_sign" | "edwards_key_usage_requires_key_cert_sign" | "edwards_key_usage_requires_signing_bit" | "email_name_constraint_names_mailbox" | "empty_general_name_value" | "empty_subject_requires_subject_alt_name" | "extended_key_usage_empty" | "extension_must_be_critical" | "extension_must_be_non_critical" | "extension_not_supported_in_context" | "invalid_bmp_string" | "invalid_general_name_content" | "invalid_general_name_tag" | "invalid_ia5_string" | "invalid_idn" | "invalid_ip_name_constraint" | "invalid_krb5_principal_name" | "invalid_other_name_value" | "invalid_oid" | "invalid_smtp_utf8_mailbox" | "invalid_srv_name" | "invalid_srv_name_constraint" | "invalid_uri_name_constraint" | "invalid_visible_string" | "key_usage_empty" | "limit_exceeded" | "malformed_known_extension_value" | "montgomery_key_usage_forbids_both_cipher_bits" | "montgomery_key_usage_forbids_signature_bit" | "montgomery_key_usage_requires_key_agreement" | "name_constraints_empty" | "no_rev_avail_conflict" | "other_name_type_id_has_variant" | "path_length_requires_ca" | "path_length_requires_key_cert_sign" | "policy_constraints_empty" | "policy_mappings_any_policy" | "policy_mappings_empty" | "reserved_policy_qualifier_oid" | "smtp_utf8_mailbox_ascii_local_part";
|
|
3
|
-
//# sourceMappingURL=extension-errors.d.ts.map
|
|
2
|
+
export type ExtensionEncoderErrorCode = "authority_info_access_empty" | "authority_info_access_ocsp_not_uri" | "certificate_policies_empty" | "crl_distribution_points_empty" | "directory_name_not_sequence" | "display_text_control_character" | "display_text_ia5_string" | "display_text_lone_surrogate" | "display_text_not_nfc" | "display_text_out_of_range" | "distribution_point_crl_issuer_empty" | "distribution_point_crl_issuer_not_directory_name" | "distribution_point_empty" | "distribution_point_full_name_empty" | "distribution_point_relative_name_multiple_crl_issuers" | "domain_trailing_dot" | "duplicate_extension_oid" | "duplicate_policy_oid" | "edwards_key_usage_forbids_agreement_bit" | "edwards_key_usage_forbids_key_cert_sign" | "edwards_key_usage_requires_key_cert_sign" | "edwards_key_usage_requires_signing_bit" | "email_name_constraint_names_mailbox" | "empty_general_name_value" | "empty_subject_requires_subject_alt_name" | "extended_key_usage_empty" | "extension_must_be_critical" | "extension_must_be_non_critical" | "extension_not_supported_in_context" | "invalid_bmp_string" | "invalid_general_name_content" | "invalid_general_name_tag" | "invalid_ia5_string" | "invalid_idn" | "invalid_ip_name_constraint" | "invalid_krb5_principal_name" | "invalid_other_name_value" | "invalid_oid" | "invalid_smtp_utf8_mailbox" | "invalid_srv_name" | "invalid_srv_name_constraint" | "invalid_uri_name_constraint" | "invalid_visible_string" | "key_usage_empty" | "limit_exceeded" | "malformed_known_extension_value" | "montgomery_key_usage_forbids_both_cipher_bits" | "montgomery_key_usage_forbids_signature_bit" | "montgomery_key_usage_requires_key_agreement" | "name_constraints_empty" | "no_rev_avail_conflict" | "other_name_type_id_has_variant" | "path_length_requires_ca" | "path_length_requires_key_cert_sign" | "policy_constraints_empty" | "policy_mappings_any_policy" | "policy_mappings_empty" | "reserved_policy_qualifier_oid" | "smtp_utf8_mailbox_ascii_local_part";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { OIDS as s } from "../asn1/
|
|
1
|
+
import { hexToBytes as e, toHex as t } from "../asn1/asn1.js";
|
|
2
|
+
import { implicitPrimitiveContext as n, nullValue as r, octetString as i, readRootElement as a, sequence as o } from "../asn1/der.js";
|
|
3
|
+
import { OIDS as s } from "../asn1/oids.js";
|
|
4
4
|
import { assertAuthorityInfoAccessProfile as c, assertCrlDistributionPointsProfile as l, assertExtensionCriticality as u, assertNameConstraintsProfile as d, assertStoredSubjectAltName as f, encodeAuthorityInfoAccess as p, encodeBasicConstraints as m, encodeCertificatePolicies as h, encodeCrlDistributionPoints as g, encodeExtendedKeyUsage as _, encodeInhibitAnyPolicy as v, encodeKeyUsage as y, encodeNameConstraints as b, encodePolicyConstraints as x, encodePolicyMappings as S, encodeSubjectAltName as C } from "../../x509/extensions.js";
|
|
5
5
|
import { parseAuthorityInfoAccess as w, parseAuthorityKeyIdentifier as T, parseBasicConstraints as E, parseCertificatePolicies as D, parseCrlDistributionPoints as O, parseExtendedKeyUsage as k, parseInhibitAnyPolicy as A, parseKeyUsage as j, parseNameConstraints as M, parsePolicyConstraints as N, parsePolicyMappings as P, parseSubjectAltNames as F } from "../../x509/parse.js";
|
|
6
6
|
// src/internal/x509/extension-registry.ts
|
|
@@ -61,7 +61,7 @@ const I = /* @__PURE__ */ new Map(), L = defineExtensionDefinition({
|
|
|
61
61
|
contexts: ["certificate", "csr"],
|
|
62
62
|
defaultCritical: !1,
|
|
63
63
|
decode: (e) => F(e),
|
|
64
|
-
encode: (e) =>
|
|
64
|
+
encode: (e) => o(e.map(C)),
|
|
65
65
|
assertProfile: (e) => {
|
|
66
66
|
for (let t of e) f(t);
|
|
67
67
|
},
|
|
@@ -73,7 +73,7 @@ const I = /* @__PURE__ */ new Map(), L = defineExtensionDefinition({
|
|
|
73
73
|
contexts: ["certificate"],
|
|
74
74
|
defaultCritical: !1,
|
|
75
75
|
decode: (e) => F(e, "issuerAltName"),
|
|
76
|
-
encode: (e) =>
|
|
76
|
+
encode: (e) => o(e.map(C)),
|
|
77
77
|
assertProfile: (e) => {
|
|
78
78
|
for (let t of e) f(t);
|
|
79
79
|
},
|
|
@@ -169,7 +169,7 @@ const I = /* @__PURE__ */ new Map(), L = defineExtensionDefinition({
|
|
|
169
169
|
contexts: ["certificate", "csr"],
|
|
170
170
|
defaultCritical: !1,
|
|
171
171
|
decode: (e) => decodeNoRevAvail(e),
|
|
172
|
-
encode: () =>
|
|
172
|
+
encode: () => r(),
|
|
173
173
|
assertProfile: (e, t) => {
|
|
174
174
|
u("noRevAvail", !1, t);
|
|
175
175
|
},
|
|
@@ -182,9 +182,9 @@ const I = /* @__PURE__ */ new Map(), L = defineExtensionDefinition({
|
|
|
182
182
|
defaultCritical: !1,
|
|
183
183
|
autoGenerated: !0,
|
|
184
184
|
decode: (e) => decodeSubjectKeyIdentifier(e),
|
|
185
|
-
encode: (e) =>
|
|
186
|
-
assertProfile: (
|
|
187
|
-
|
|
185
|
+
encode: (e) => i(normalizeKeyIdentifier(e)),
|
|
186
|
+
assertProfile: (t, n) => {
|
|
187
|
+
e(t), u("subjectKeyIdentifier", !1, n);
|
|
188
188
|
},
|
|
189
189
|
applyParsed: (e, t) => {
|
|
190
190
|
e.subjectKeyIdentifier = t;
|
|
@@ -195,9 +195,9 @@ const I = /* @__PURE__ */ new Map(), L = defineExtensionDefinition({
|
|
|
195
195
|
defaultCritical: !1,
|
|
196
196
|
autoGenerated: !0,
|
|
197
197
|
decode: (e) => T(e),
|
|
198
|
-
encode: (
|
|
199
|
-
assertProfile: (
|
|
200
|
-
|
|
198
|
+
encode: (e) => o([n(0, normalizeKeyIdentifier(e))]),
|
|
199
|
+
assertProfile: (t, n) => {
|
|
200
|
+
t !== void 0 && e(t), u("authorityKeyIdentifier", !1, n);
|
|
201
201
|
},
|
|
202
202
|
applyParsed: (e, t) => {
|
|
203
203
|
t !== void 0 && (e.authorityKeyIdentifier = t);
|
|
@@ -254,20 +254,20 @@ function defineExtensionDefinition(e) {
|
|
|
254
254
|
};
|
|
255
255
|
}
|
|
256
256
|
/** Accept hex string or Uint8Array and return raw bytes. */
|
|
257
|
-
function normalizeKeyIdentifier(
|
|
258
|
-
return typeof
|
|
257
|
+
function normalizeKeyIdentifier(t) {
|
|
258
|
+
return typeof t == "string" ? e(t) : t;
|
|
259
259
|
}
|
|
260
260
|
/** Decode a noRevAvail extension value, which RFC 9608 §2 defines as NULL. */
|
|
261
261
|
function decodeNoRevAvail(e) {
|
|
262
|
-
let t =
|
|
262
|
+
let t = a(e, { maxDepth: 64 });
|
|
263
263
|
if (t.tag !== 5 || t.value.length !== 0) throw Error("noRevAvail must be NULL");
|
|
264
264
|
return !0;
|
|
265
265
|
}
|
|
266
266
|
/** Decode an SKI extension value DER to a hex string. */
|
|
267
267
|
function decodeSubjectKeyIdentifier(e) {
|
|
268
|
-
let
|
|
269
|
-
if (
|
|
270
|
-
return
|
|
268
|
+
let n = a(e, { maxDepth: 64 });
|
|
269
|
+
if (n.tag !== 4) throw Error("SubjectKeyIdentifier must be an OCTET STRING");
|
|
270
|
+
return t(n.value);
|
|
271
271
|
}
|
|
272
272
|
export { q as AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION, Z as AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION, L as BASIC_CONSTRAINTS_EXTENSION_DEFINITION, U as CERTIFICATE_POLICIES_EXTENSION_DEFINITION, Q as CERT_CSR_EXTENSION_DEFINITIONS, J as CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION, z as EXTENDED_KEY_USAGE_EXTENSION_DEFINITION, K as INHIBIT_ANY_POLICY_EXTENSION_DEFINITION, V as ISSUER_ALT_NAME_EXTENSION_DEFINITION, R as KEY_USAGE_EXTENSION_DEFINITION, H as NAME_CONSTRAINTS_EXTENSION_DEFINITION, Y as NO_REV_AVAIL_EXTENSION_DEFINITION, G as POLICY_CONSTRAINTS_EXTENSION_DEFINITION, W as POLICY_MAPPINGS_EXTENSION_DEFINITION, B as SUBJECT_ALT_NAME_EXTENSION_DEFINITION, X as SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION, decodeAndApplyKnownExtension, getExtensionDefinition };
|
|
273
273
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { checkStrictDer as e, childrenOf as t, decodeString as n } from "../asn1/asn1.js";
|
|
2
|
+
import { readRootElement as r } from "../asn1/der.js";
|
|
3
3
|
import { domainToAscii as i, presentedDomainToAscii as a } from "../shared/idna.js";
|
|
4
4
|
import { isIpv4Address as o } from "../shared/uri-host.js";
|
|
5
5
|
import { checkOrAddressFields as s } from "./or-address.js";
|
|
@@ -91,7 +91,7 @@ function checkDirectoryString(e) {
|
|
|
91
91
|
if (e.tag === 20) return d;
|
|
92
92
|
if (!f.has(e.tag) || e.value.length === 0) return u;
|
|
93
93
|
try {
|
|
94
|
-
return
|
|
94
|
+
return n(e.tag, e.value), l;
|
|
95
95
|
} catch {
|
|
96
96
|
return u;
|
|
97
97
|
}
|
|
@@ -102,8 +102,8 @@ function checkDirectoryString(e) {
|
|
|
102
102
|
* explicit around its CHOICE.
|
|
103
103
|
*/
|
|
104
104
|
function checkEdiPartyName(e) {
|
|
105
|
-
return checkStructuredGeneralName(e, (e,
|
|
106
|
-
let r = n
|
|
105
|
+
return checkStructuredGeneralName(e, (e, n) => e.at(-1)?.tag !== 161 || !(e.length === 1 || e.length === 2 && e[0]?.tag === 160) ? u : firstFailure(e.map((e) => {
|
|
106
|
+
let r = t(n, e), i = r[0];
|
|
107
107
|
return r.length === 1 && i !== void 0 ? checkDirectoryString(i) : u;
|
|
108
108
|
})));
|
|
109
109
|
}
|
|
@@ -111,12 +111,12 @@ function checkEdiPartyName(e) {
|
|
|
111
111
|
function checkOrAddress(e) {
|
|
112
112
|
return checkStructuredGeneralName(e, s);
|
|
113
113
|
}
|
|
114
|
-
function checkStructuredGeneralName(
|
|
115
|
-
let a =
|
|
114
|
+
function checkStructuredGeneralName(n, i) {
|
|
115
|
+
let a = e(n);
|
|
116
116
|
if (a === "malformed") return u;
|
|
117
117
|
try {
|
|
118
|
-
let
|
|
119
|
-
return
|
|
118
|
+
let e = i(t(n, r(n)), n);
|
|
119
|
+
return e.ok && a === "unsupported" ? d : e;
|
|
120
120
|
} catch {
|
|
121
121
|
return u;
|
|
122
122
|
}
|