micro509 0.19.0 → 0.19.1
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 +22 -1
- package/dist/index.d.ts +2 -2
- package/dist/internal/crypto/hash.js +64 -64
- package/dist/internal/crypto/pbes2.js +3 -3
- package/dist/internal/shared/dn.js +1 -1
- package/dist/internal/shared/idna-tables.js +3 -3
- package/dist/internal/shared/punycode.js +1 -1
- package/dist/kdf/argon2-portable.js +1 -1
- package/dist/kdf/argon2.js +2 -2
- package/dist/keys/keys.d.ts +7 -2
- package/dist/keys/keys.js +10 -6
- package/dist/keys/keys.js.map +1 -1
- package/dist/pem/pem.d.ts +20 -7
- package/dist/pem/pem.js +24 -20
- package/dist/pem/pem.js.map +1 -1
- package/dist/pem.d.ts +2 -2
- package/dist/pkcs/pkcs12-mac.js +2 -2
- package/dist/revocation/crl.js +46 -46
- package/dist/revocation/crl.js.map +1 -1
- package/dist/verify/verify.js +0 -4
- package/dist/verify/verify.js.map +1 -1
- package/dist/x509/extensions.js +1 -1
- package/dist/x509/name-text.js +1 -1
- package/dist/x509/name-text.js.map +1 -1
- package/package.json +7 -7
package/dist/pem/pem.d.ts
CHANGED
|
@@ -33,6 +33,16 @@ export interface CategorizedPemBlocks {
|
|
|
33
33
|
export declare function pemEncode(label: string, der: Uint8Array): string;
|
|
34
34
|
/** Machine-readable failure reason for the PEM decoders. */
|
|
35
35
|
export type PemErrorCode = "malformed";
|
|
36
|
+
/** Controls how much of the input a PEM decoder consumes. */
|
|
37
|
+
export interface PemDecodeOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Require the entire input to be one PEM block of the requested label.
|
|
40
|
+
* The BEGIN and END lines must be exact, and the body must contain only
|
|
41
|
+
* nonempty base64 lines. Each line break may be LF or CRLF, with at most
|
|
42
|
+
* one optional line break after END. Defaults to false.
|
|
43
|
+
*/
|
|
44
|
+
readonly wholeInput?: boolean;
|
|
45
|
+
}
|
|
36
46
|
/** Structured failure payload for PEM decoding. */
|
|
37
47
|
export interface PemFailure extends Micro509Error<PemErrorCode> {
|
|
38
48
|
/** Always `false` for failures. */
|
|
@@ -55,13 +65,15 @@ export type CategorizePemBlocksResult = {
|
|
|
55
65
|
} | ErrorResult<PemErrorCode, Record<never, never>, PemFailure>;
|
|
56
66
|
/**
|
|
57
67
|
* Throwing core for {@linkcode pemDecode}: extracts and base64-decodes the
|
|
58
|
-
* DER content from a PEM string.
|
|
59
|
-
* Throws if the
|
|
68
|
+
* DER content from a PEM string. By default, text ahead of the `BEGIN` line
|
|
69
|
+
* is ignored. Throws if the input fails the selected policy or the
|
|
70
|
+
* `BEGIN`/`END` markers don't match `label`.
|
|
60
71
|
*
|
|
61
72
|
* @param label Expected PEM type label.
|
|
62
73
|
* @param pem PEM-encoded text (may contain `\r`).
|
|
74
|
+
* @param options Set `wholeInput` to require one block with exact boundaries.
|
|
63
75
|
*/
|
|
64
|
-
export declare function pemDecodeOrThrow(label: string, pem: string): Uint8Array;
|
|
76
|
+
export declare function pemDecodeOrThrow(label: string, pem: string, options?: PemDecodeOptions): Uint8Array;
|
|
65
77
|
/**
|
|
66
78
|
* Finds all `BEGIN`/`END`-delimited PEM blocks in a string and returns
|
|
67
79
|
* them as parsed {@linkcode PemBlock} entries. Handles concatenated PEM files
|
|
@@ -76,13 +88,14 @@ export declare function splitPemBlocksOrThrow(input: string): readonly PemBlock[
|
|
|
76
88
|
export declare function categorizePemBlocksOrThrow(input: string | readonly PemBlock[]): CategorizedPemBlocks;
|
|
77
89
|
/**
|
|
78
90
|
* Extracts and base64-decodes the DER content from a PEM string.
|
|
79
|
-
* Text ahead of the `BEGIN` line is ignored.
|
|
91
|
+
* Text ahead of the `BEGIN` line is ignored by default. Set
|
|
92
|
+
* {@linkcode PemDecodeOptions.wholeInput} to require one complete block.
|
|
80
93
|
*
|
|
81
94
|
* Returns a typed failure (`code: 'malformed'`) when the `BEGIN`/`END`
|
|
82
|
-
* markers don't match `label
|
|
83
|
-
* throwing form use {@linkcode pemDecodeOrThrow}.
|
|
95
|
+
* markers don't match `label`, the input fails the selected policy, or the
|
|
96
|
+
* body is not valid base64. For the throwing form use {@linkcode pemDecodeOrThrow}.
|
|
84
97
|
*/
|
|
85
|
-
export declare function pemDecode(label: string, pem: string): PemDecodeResult;
|
|
98
|
+
export declare function pemDecode(label: string, pem: string, options?: PemDecodeOptions): PemDecodeResult;
|
|
86
99
|
/**
|
|
87
100
|
* Finds all `BEGIN`/`END`-delimited PEM blocks in a string and returns them
|
|
88
101
|
* as parsed {@linkcode PemBlock} entries. Handles concatenated PEM files and
|
package/dist/pem/pem.js
CHANGED
|
@@ -22,25 +22,29 @@ function pemEncode(e, n) {
|
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Throwing core for {@linkcode pemDecode}: extracts and base64-decodes the
|
|
25
|
-
* DER content from a PEM string.
|
|
26
|
-
* Throws if the
|
|
25
|
+
* DER content from a PEM string. By default, text ahead of the `BEGIN` line
|
|
26
|
+
* is ignored. Throws if the input fails the selected policy or the
|
|
27
|
+
* `BEGIN`/`END` markers don't match `label`.
|
|
27
28
|
*
|
|
28
29
|
* @param label Expected PEM type label.
|
|
29
30
|
* @param pem PEM-encoded text (may contain `\r`).
|
|
31
|
+
* @param options Set `wholeInput` to require one block with exact boundaries.
|
|
30
32
|
*/
|
|
31
|
-
function pemDecodeOrThrow(t, n) {
|
|
32
|
-
let i = trimPemDocument(n.replace(/\r\n?/g, "\n")).split("\n")
|
|
33
|
-
|
|
33
|
+
function pemDecodeOrThrow(t, n, i) {
|
|
34
|
+
let o = i?.wholeInput === !0, s = (o ? n.replace(/\r\n/g, "\n") : trimPemDocument(n.replace(/\r\n?/g, "\n"))).split("\n");
|
|
35
|
+
o && s.at(-1) === "" && s.pop();
|
|
36
|
+
let c = o ? 0 : findPreEncapsulationBoundary(s);
|
|
37
|
+
(c === void 0 || parsePemBoundaryLine(s[c] ?? "", "BEGIN", o) !== t || parsePemBoundaryLine(s.at(-1) ?? "", "END", o) !== t || s.length - c < 3) && a("malformed", `Invalid PEM for ${t}`, {
|
|
34
38
|
stage: "pem",
|
|
35
39
|
reason: "invalid_armor"
|
|
36
40
|
});
|
|
37
|
-
let
|
|
38
|
-
|
|
41
|
+
let l = s.slice(c + 1, -1), u = o ? l : normalizePemBodyLines(l);
|
|
42
|
+
u.every((e) => /^[A-Za-z0-9+/=]+$/.test(e)) || a("malformed", `Invalid PEM for ${t}`, {
|
|
39
43
|
stage: "base64",
|
|
40
44
|
reason: "invalid_base64"
|
|
41
45
|
});
|
|
42
46
|
try {
|
|
43
|
-
return e(
|
|
47
|
+
return e(u.join(""));
|
|
44
48
|
} catch (e) {
|
|
45
49
|
r(e), a("malformed", `Invalid PEM for ${t}`, {
|
|
46
50
|
stage: "base64",
|
|
@@ -119,14 +123,13 @@ function categorizePemBlocksOrThrow(e) {
|
|
|
119
123
|
};
|
|
120
124
|
}
|
|
121
125
|
function normalizePemBodyLines(e) {
|
|
122
|
-
|
|
123
|
-
return t.length === 0 ? [""] : t.every((e) => /^[A-Za-z0-9+/=]+$/.test(e)) ? t : void 0;
|
|
126
|
+
return e.map((e) => e.replace(/[ \t]/g, "")).filter((e) => e !== "");
|
|
124
127
|
}
|
|
125
|
-
function parsePemBoundaryLine(e, t) {
|
|
126
|
-
let
|
|
127
|
-
if (!
|
|
128
|
-
let
|
|
129
|
-
return isPemLabel(
|
|
128
|
+
function parsePemBoundaryLine(e, t, n = !1) {
|
|
129
|
+
let r = `-----${t} `, i = n ? e : trimLwsp(e);
|
|
130
|
+
if (!i.startsWith(r) || !i.endsWith("-----")) return;
|
|
131
|
+
let a = i.slice(r.length, -5);
|
|
132
|
+
return isPemLabel(a) ? a : void 0;
|
|
130
133
|
}
|
|
131
134
|
/** RFC 7468 §2: data before the encapsulation boundaries is permitted. */
|
|
132
135
|
function findPreEncapsulationBoundary(e) {
|
|
@@ -204,14 +207,15 @@ function isPemLabel(e) {
|
|
|
204
207
|
}
|
|
205
208
|
/**
|
|
206
209
|
* Extracts and base64-decodes the DER content from a PEM string.
|
|
207
|
-
* Text ahead of the `BEGIN` line is ignored.
|
|
210
|
+
* Text ahead of the `BEGIN` line is ignored by default. Set
|
|
211
|
+
* {@linkcode PemDecodeOptions.wholeInput} to require one complete block.
|
|
208
212
|
*
|
|
209
213
|
* Returns a typed failure (`code: 'malformed'`) when the `BEGIN`/`END`
|
|
210
|
-
* markers don't match `label
|
|
211
|
-
* throwing form use {@linkcode pemDecodeOrThrow}.
|
|
214
|
+
* markers don't match `label`, the input fails the selected policy, or the
|
|
215
|
+
* body is not valid base64. For the throwing form use {@linkcode pemDecodeOrThrow}.
|
|
212
216
|
*/
|
|
213
|
-
function pemDecode(e, t) {
|
|
214
|
-
return toPemResult(() => pemDecodeOrThrow(e, t), "Invalid PEM");
|
|
217
|
+
function pemDecode(e, t, n) {
|
|
218
|
+
return toPemResult(() => pemDecodeOrThrow(e, t, n), "Invalid PEM");
|
|
215
219
|
}
|
|
216
220
|
/**
|
|
217
221
|
* Finds all `BEGIN`/`END`-delimited PEM blocks in a string and returns them
|
package/dist/pem/pem.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pem.js","names":["base64Decode","base64Encode","failureResult","rethrowIfInvariant","successResult","throwMicro509Error","PEM_LABEL_PATTERN","label","der","pem","lines","begin","bodyLines","error","input","block","normalized","blocks","openBlock","lineStart","newline","lineEnd","nextLineStart","line","beginLine","beginLabel","endLabel","end","certificates","certificateRequests","privateKeys","publicKeys","others","nonEmptyLines","kind","prefix","withoutSurroundingWsp","index","RFC822_FIELD_NAME","character","value","headers","foldedName","delimiter","headerName","operation","fallbackMessage"],"sources":["../../src/pem/pem.ts"],"sourcesContent":["/**\n * PEM helpers used across the public API.\n *\n * Encodes, decodes, splits, and categorizes PEM blocks as defined by\n * RFC 7468.\n *\n * @module\n */\n\nimport { base64Decode, base64Encode } from '#micro509/internal/shared/base64';\nimport type { ErrorResult, Micro509Error } from '#micro509/result/result';\nimport {\n\tfailureResult,\n\trethrowIfInvariant,\n\tsuccessResult,\n\tthrowMicro509Error,\n} from '#micro509/result/result';\n\n/** A single decoded PEM block with its label, decoded DER bytes, and original PEM text. */\nexport interface PemBlock {\n\t/** RFC 7468 label between the `BEGIN` / `END` markers (e.g. `\"CERTIFICATE\"`). */\n\treadonly label: string;\n\t/** Decoded DER content of this block. */\n\treadonly bytes: Uint8Array;\n\t/** The original PEM text including `BEGIN`/`END` lines. */\n\treadonly pem: string;\n}\n\n/**\n * PEM blocks grouped by their label into well-known PKI categories.\n * Blocks that don't match any known label land in {@linkcode others}.\n */\nexport interface CategorizedPemBlocks {\n\t/** Blocks with label `CERTIFICATE`. */\n\treadonly certificates: readonly PemBlock[];\n\t/** Blocks with label `CERTIFICATE REQUEST`. */\n\treadonly certificateRequests: readonly PemBlock[];\n\t/** Blocks with label `PRIVATE KEY`, `RSA PRIVATE KEY`, or `EC PRIVATE KEY`. */\n\treadonly privateKeys: readonly PemBlock[];\n\t/** Blocks with label `PUBLIC KEY`. */\n\treadonly publicKeys: readonly PemBlock[];\n\t/** Blocks whose label doesn't match any of the above categories. */\n\treadonly others: readonly PemBlock[];\n}\n\n// RFC 7468 §3 label ABNF: labelchar = %x21-2C / %x2E-7E, joined by an optional\n// single \"-\" or SP; an empty label is legal.\nconst PEM_LABEL_PATTERN = /^(?:[!-,.-~](?:[- ]?[!-,.-~])*)?$/;\n\n/**\n * Wraps DER bytes in a PEM envelope with 64-character base64 lines.\n *\n * @param label PEM type label (e.g. `\"CERTIFICATE\"`, `\"PRIVATE KEY\"`).\n * @param der Raw DER-encoded content.\n */\nexport function pemEncode(label: string, der: Uint8Array): string {\n\tif (!isPemLabel(label)) {\n\t\tthrow new Error('Invalid PEM label');\n\t}\n\tconst body = base64Encode(der);\n\tconst lines = body.match(/.{1,64}/g) ?? [];\n\treturn `-----BEGIN ${label}-----\\n${lines.join('\\n')}\\n-----END ${label}-----\\n`;\n}\n\n/** Machine-readable failure reason for the PEM decoders. */\nexport type PemErrorCode = 'malformed';\n\n/** Structured failure payload for PEM decoding. */\nexport interface PemFailure extends Micro509Error<PemErrorCode> {\n\t/** Always `false` for failures. */\n\treadonly ok: false;\n}\n\n/** Success-or-failure result from {@linkcode pemDecode}. */\nexport type PemDecodeResult =\n\t| { readonly ok: true; readonly value: Uint8Array }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure>;\n\n/** Success-or-failure result from {@linkcode splitPemBlocks}. */\nexport type SplitPemBlocksResult =\n\t| { readonly ok: true; readonly value: readonly PemBlock[] }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure>;\n\n/** Success-or-failure result from {@linkcode categorizePemBlocks}. */\nexport type CategorizePemBlocksResult =\n\t| { readonly ok: true; readonly value: CategorizedPemBlocks }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure>;\n\n/**\n * Throwing core for {@linkcode pemDecode}: extracts and base64-decodes the\n * DER content from a PEM string. Text ahead of the `BEGIN` line is ignored.\n * Throws if the `BEGIN`/`END` markers don't match `label`.\n *\n * @param label Expected PEM type label.\n * @param pem PEM-encoded text (may contain `\\r`).\n */\nexport function pemDecodeOrThrow(label: string, pem: string): Uint8Array {\n\tconst normalized = trimPemDocument(pem.replace(/\\r\\n?/g, '\\n'));\n\tconst lines = normalized.split('\\n');\n\tconst begin = findPreEncapsulationBoundary(lines);\n\tif (\n\t\tbegin === undefined ||\n\t\tparsePemBoundaryLine(lines[begin] ?? '', 'BEGIN') !== label ||\n\t\tparsePemBoundaryLine(lines[lines.length - 1] ?? '', 'END') !== label ||\n\t\tlines.length - begin < 3\n\t) {\n\t\tthrowMicro509Error('malformed', `Invalid PEM for ${label}`, {\n\t\t\tstage: 'pem',\n\t\t\treason: 'invalid_armor',\n\t\t} as const);\n\t}\n\tconst bodyLines = normalizePemBodyLines(lines.slice(begin + 1, -1));\n\tif (bodyLines === undefined) {\n\t\tthrowMicro509Error('malformed', `Invalid PEM for ${label}`, {\n\t\t\tstage: 'base64',\n\t\t\treason: 'invalid_base64',\n\t\t} as const);\n\t}\n\ttry {\n\t\treturn base64Decode(bodyLines.join(''));\n\t} catch (error) {\n\t\trethrowIfInvariant(error);\n\t\tthrowMicro509Error('malformed', `Invalid PEM for ${label}`, {\n\t\t\tstage: 'base64',\n\t\t\treason: 'invalid_base64',\n\t\t} as const);\n\t}\n}\n\n/**\n * Finds all `BEGIN`/`END`-delimited PEM blocks in a string and returns\n * them as parsed {@linkcode PemBlock} entries. Handles concatenated PEM files\n * and ignores non-PEM text between blocks.\n */\nexport function splitPemBlocksOrThrow(input: string): readonly PemBlock[] {\n\treturn splitPemTextBlocksOrThrow(input).map((block) => ({\n\t\t...block,\n\t\tbytes: pemDecodeOrThrow(block.label, block.pem),\n\t}));\n}\n\n/** @internal A bounded-by-input PEM block before decoding its body. */\nexport interface PemTextBlock {\n\treadonly label: string;\n\treadonly pem: string;\n}\n\n/** @internal Shares the ordinary boundary scanner, retaining legacy encrypted bodies verbatim. */\nexport function splitPemTextBlocksOrThrow(input: string): readonly PemTextBlock[] {\n\tconst normalized = input.replace(/^\\uFEFF/, '').replace(/\\r\\n?/g, '\\n');\n\tconst blocks: PemTextBlock[] = [];\n\tlet openBlock: { readonly label: string; readonly start: number } | undefined;\n\tlet lineStart = 0;\n\twhile (lineStart < normalized.length) {\n\t\tconst newline = normalized.indexOf('\\n', lineStart);\n\t\tconst lineEnd = newline === -1 ? normalized.length : newline;\n\t\tconst nextLineStart = newline === -1 ? normalized.length : newline + 1;\n\t\tconst line = normalized.slice(lineStart, lineEnd);\n\t\tconst beginLine = line.replace(/^[ \\t]+/, '');\n\t\tconst beginLabel = parsePemBoundaryLine(line, 'BEGIN');\n\t\tconst endLabel = parsePemBoundaryLine(line, 'END');\n\n\t\tif (beginLabel !== undefined) {\n\t\t\tif (openBlock !== undefined) {\n\t\t\t\tthrow new Error('Malformed PEM block');\n\t\t\t}\n\t\t\topenBlock = { label: beginLabel, start: lineStart + line.length - beginLine.length };\n\t\t} else if (endLabel !== undefined) {\n\t\t\tblocks.push(closePemBlock(normalized, openBlock, endLabel, nextLineStart));\n\t\t\topenBlock = undefined;\n\t\t} else if (looksLikePemBoundary(line)) {\n\t\t\tthrow new Error('Malformed PEM block');\n\t\t}\n\n\t\tif (newline === -1) {\n\t\t\tbreak;\n\t\t}\n\t\tlineStart = nextLineStart;\n\t}\n\tif (openBlock !== undefined) {\n\t\tthrow new Error('Malformed PEM block');\n\t}\n\treturn blocks;\n}\n\nfunction closePemBlock(\n\tinput: string,\n\topenBlock: { readonly label: string; readonly start: number } | undefined,\n\tendLabel: string,\n\tend: number,\n): PemTextBlock {\n\tif (openBlock === undefined || openBlock.label !== endLabel) {\n\t\tthrow new Error('Malformed PEM block');\n\t}\n\tconst pem = input.slice(openBlock.start, end);\n\treturn {\n\t\tlabel: openBlock.label,\n\t\tpem,\n\t};\n}\n\n/**\n * Groups PEM blocks by label into well-known PKI categories\n * (certificates, CSRs, private keys, public keys, and everything else).\n * Accepts either raw PEM text or pre-split {@linkcode PemBlock} entries.\n */\nexport function categorizePemBlocksOrThrow(\n\tinput: string | readonly PemBlock[],\n): CategorizedPemBlocks {\n\tconst blocks = typeof input === 'string' ? splitPemBlocksOrThrow(input) : input;\n\tconst certificates: PemBlock[] = [];\n\tconst certificateRequests: PemBlock[] = [];\n\tconst privateKeys: PemBlock[] = [];\n\tconst publicKeys: PemBlock[] = [];\n\tconst others: PemBlock[] = [];\n\n\tfor (const block of blocks) {\n\t\tswitch (block.label) {\n\t\t\tcase 'CERTIFICATE':\n\t\t\t\tcertificates.push(block);\n\t\t\t\tbreak;\n\t\t\tcase 'CERTIFICATE REQUEST':\n\t\t\t\tcertificateRequests.push(block);\n\t\t\t\tbreak;\n\t\t\tcase 'PRIVATE KEY':\n\t\t\tcase 'RSA PRIVATE KEY':\n\t\t\tcase 'EC PRIVATE KEY':\n\t\t\t\tprivateKeys.push(block);\n\t\t\t\tbreak;\n\t\t\tcase 'PUBLIC KEY':\n\t\t\t\tpublicKeys.push(block);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tothers.push(block);\n\t\t}\n\t}\n\n\treturn { certificates, certificateRequests, privateKeys, publicKeys, others };\n}\n\nfunction normalizePemBodyLines(lines: readonly string[]): readonly string[] | undefined {\n\tconst normalizedLines = lines.map((line) => line.replace(/[ \\t]/g, ''));\n\tconst nonEmptyLines = normalizedLines.filter((line) => line !== '');\n\tif (nonEmptyLines.length === 0) {\n\t\treturn [''];\n\t}\n\treturn nonEmptyLines.every((line) => /^[A-Za-z0-9+/=]+$/.test(line)) ? nonEmptyLines : undefined;\n}\n\nfunction parsePemBoundaryLine(line: string, kind: 'BEGIN' | 'END'): string | undefined {\n\tconst prefix = `-----${kind} `;\n\tconst withoutSurroundingWsp = trimLwsp(line);\n\tif (!withoutSurroundingWsp.startsWith(prefix) || !withoutSurroundingWsp.endsWith('-----')) {\n\t\treturn undefined;\n\t}\n\tconst label = withoutSurroundingWsp.slice(prefix.length, -5);\n\treturn isPemLabel(label) ? label : undefined;\n}\n\n/** RFC 7468 §2: data before the encapsulation boundaries is permitted. */\nfunction findPreEncapsulationBoundary(lines: readonly string[]): number | undefined {\n\tfor (const [index, line] of lines.entries()) {\n\t\tif (parsePemBoundaryLine(line, 'BEGIN') !== undefined) {\n\t\t\treturn index;\n\t\t}\n\t\tif (looksLikePemBoundary(line)) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction looksLikePemBoundary(line: string): boolean {\n\treturn /^[ \\t]*-{5,}(?:BEGIN|END)/.test(line);\n}\n\n/** RFC 822 §3.2: `field-name = 1*<any CHAR, excluding CTLs, SPACE, and \":\">`. */\nconst RFC822_FIELD_NAME = /^[\\x21-\\x39\\x3b-\\x7e]+$/;\n\n/** RFC 822 §3.3: `LWSP-char = SPACE / HTAB`. */\nfunction isLwspChar(character: string): boolean {\n\treturn character === ' ' || character === '\\t';\n}\n\n/**\n * Strips the whitespace surrounding a PEM document: `LWSP-char`s and the line\n * terminators that separate the boundary lines from the body.\n *\n * `String.prototype.trim` would also strip VT, FF, NBSP, and every Unicode\n * `Zs`, making those characters acceptable at a document edge while\n * {@linkcode parsePemBoundaryLine} rejects them everywhere else.\n */\nfunction trimPemDocument(value: string): string {\n\treturn value.replace(/^[ \\t\\n]+|[ \\t\\n]+$/g, '');\n}\n\n/**\n * @internal Strips surrounding RFC 822 §3.3 `LWSP-char`s.\n *\n * `String.prototype.trim` would also strip VT, FF, NBSP, and every Unicode `Zs`,\n * none of which the grammar admits.\n */\nexport function trimLwsp(value: string): string {\n\treturn value.replace(/^[ \\t]+|[ \\t]+$/g, '');\n}\n\n/** A PEM block carrying RFC 1421 §4.6 encapsulated headers ahead of its body. */\nexport interface TraditionalPemBlock {\n\t/** PEM type label between the `BEGIN` / `END` markers. */\n\treadonly label: string;\n\t/** Encapsulated headers (e.g. `Proc-Type`, `DEK-Info`), unfolded. */\n\treadonly headers: ReadonlyMap<string, string>;\n\t/** Base64-encoded payload after the headers. */\n\treadonly base64Body: string;\n}\n\n/**\n * @internal Parses a PEM block with RFC 1421 §4.6 encapsulated headers.\n *\n * RFC 7468 §2 forbids headers, so this path exists only for the legacy\n * OpenSSL-style encrypted PKCS#1 and SEC1 blocks that predate it.\n */\nexport function parseTraditionalPemOrThrow(pem: string): TraditionalPemBlock {\n\tconst normalized = trimPemDocument(pem.replace(/\\r\\n?/g, '\\n'));\n\tconst lines = normalized.split('\\n');\n\tconst label = parsePemBoundaryLine(lines[0] ?? '', 'BEGIN');\n\tif (label === undefined || lines.length < 2) {\n\t\tthrow new Error('Invalid PEM block');\n\t}\n\tif (parsePemBoundaryLine(lines[lines.length - 1] ?? '', 'END') !== label) {\n\t\tthrow new Error('PEM boundaries do not match');\n\t}\n\tconst headers = new Map<string, string>();\n\tlet index = 1;\n\tlet foldedName: string | undefined;\n\twhile (index < lines.length - 1) {\n\t\tconst line = lines[index];\n\t\tif (line === undefined) {\n\t\t\tbreak;\n\t\t}\n\t\tif (line.length === 0) {\n\t\t\tindex += 1;\n\t\t\tbreak;\n\t\t}\n\t\tif (foldedName !== undefined && isLwspChar(line.charAt(0))) {\n\t\t\theaders.set(foldedName, `${headers.get(foldedName) ?? ''}${line}`);\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tconst delimiter = line.indexOf(':');\n\t\tif (delimiter === -1) {\n\t\t\tbreak;\n\t\t}\n\t\tconst headerName = line.slice(0, delimiter);\n\t\tif (!RFC822_FIELD_NAME.test(headerName)) {\n\t\t\tthrow new Error(`Invalid PEM header name: ${headerName}`);\n\t\t}\n\t\tif (headers.has(headerName)) {\n\t\t\tthrow new Error(`Duplicate PEM header: ${headerName}`);\n\t\t}\n\t\theaders.set(headerName, line.slice(delimiter + 1).replace(/^[ \\t]+/, ''));\n\t\tfoldedName = headerName;\n\t\tindex += 1;\n\t}\n\treturn { label, headers, base64Body: lines.slice(index, lines.length - 1).join('') };\n}\n\nfunction isPemLabel(label: string): boolean {\n\treturn PEM_LABEL_PATTERN.exec(label)?.[0] === label;\n}\n\n/**\n * Extracts and base64-decodes the DER content from a PEM string.\n * Text ahead of the `BEGIN` line is ignored.\n *\n * Returns a typed failure (`code: 'malformed'`) when the `BEGIN`/`END`\n * markers don't match `label` or the body is not valid base64. For the\n * throwing form use {@linkcode pemDecodeOrThrow}.\n */\nexport function pemDecode(label: string, pem: string): PemDecodeResult {\n\treturn toPemResult(() => pemDecodeOrThrow(label, pem), 'Invalid PEM');\n}\n\n/**\n * Finds all `BEGIN`/`END`-delimited PEM blocks in a string and returns them\n * as parsed {@linkcode PemBlock} entries. Handles concatenated PEM files and\n * ignores non-PEM text between blocks.\n *\n * Returns a typed failure (`code: 'malformed'`) on stray or truncated PEM\n * markers. For the throwing form use {@linkcode splitPemBlocksOrThrow}.\n */\nexport function splitPemBlocks(input: string): SplitPemBlocksResult {\n\treturn toPemResult(() => splitPemBlocksOrThrow(input), 'Malformed PEM block');\n}\n\n/**\n * Groups PEM blocks by label into well-known PKI categories\n * (certificates, CSRs, private keys, public keys, and everything else).\n * Accepts either raw PEM text or pre-split {@linkcode PemBlock} entries.\n *\n * Returns a typed failure (`code: 'malformed'`) when raw text contains stray\n * or truncated PEM markers. For the throwing form use\n * {@linkcode categorizePemBlocksOrThrow}.\n */\nexport function categorizePemBlocks(\n\tinput: string | readonly PemBlock[],\n): CategorizePemBlocksResult {\n\treturn toPemResult(() => categorizePemBlocksOrThrow(input), 'Malformed PEM block');\n}\n\n/** Shared Result wrapper around the throwing PEM cores. */\nfunction toPemResult<TValue>(\n\toperation: () => TValue,\n\tfallbackMessage: string,\n):\n\t| { readonly ok: true; readonly value: TValue }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure> {\n\ttry {\n\t\treturn successResult(operation());\n\t} catch (error) {\n\t\trethrowIfInvariant(error);\n\t\treturn failureResult('malformed', error instanceof Error ? error.message : fallbackMessage);\n\t}\n}\n"],"mappings":";;;;;;;;;;;AA+CA,MAAMM,IAAoB;;;;;;;AAQ1B,SAAgB,UAAUC,GAAeC,GAAyB;CACjE,IAAI,CAAC,WAAWD,CAAK,GACpB,MAAU,MAAM,mBAAmB;CAIpC,OAAO,cAAcA,EAAM,UAFdN,EAAaO,CACT,CAAC,CAAC,MAAM,UAAU,KAAK,CAAC,EAAA,CACC,KAAK,IAAI,EAAE,aAAaD,EAAM;AACzE;;;;;;;;;AAkCA,SAAgB,iBAAiBA,GAAeE,GAAyB;CAExE,IAAMC,IADa,gBAAgBD,EAAI,QAAQ,UAAU,IAAI,CACtC,CAAC,CAAC,MAAM,IAAI,GAC7BE,IAAQ,6BAA6BD,CAAK;CAChD,CACCC,MAAU,KAAA,KACV,qBAAqBD,EAAMC,MAAU,IAAI,OAAO,MAAMJ,KACtD,qBAAqBG,EAAMA,EAAM,SAAS,MAAM,IAAI,KAAK,MAAMH,KAC/DG,EAAM,SAASC,IAAQ,MAEvBN,EAAmB,aAAa,mBAAmBE,KAAS;EAC3D,OAAO;EACP,QAAQ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1C,EAAcyC,EAAU,CAAC;CACjC,SAAShC,GAAO;EAEf,OADAV,EAAmBU,CAAK,GACjBX,EAAc,aAAaW,aAAiB,QAAQA,EAAM,UAAUiC,CAAe;CAC3F;AACD"}
|
|
1
|
+
{"version":3,"file":"pem.js","names":["base64Decode","base64Encode","failureResult","rethrowIfInvariant","successResult","throwMicro509Error","PEM_LABEL_PATTERN","label","der","pem","options","wholeInput","lines","begin","bodyLines","base64Lines","line","error","input","block","normalized","blocks","openBlock","lineStart","newline","lineEnd","nextLineStart","beginLine","beginLabel","endLabel","end","certificates","certificateRequests","privateKeys","publicKeys","others","kind","prefix","boundary","index","RFC822_FIELD_NAME","character","value","headers","foldedName","delimiter","headerName","operation","fallbackMessage"],"sources":["../../src/pem/pem.ts"],"sourcesContent":["/**\n * PEM helpers used across the public API.\n *\n * Encodes, decodes, splits, and categorizes PEM blocks as defined by\n * RFC 7468.\n *\n * @module\n */\n\nimport { base64Decode, base64Encode } from '#micro509/internal/shared/base64';\nimport type { ErrorResult, Micro509Error } from '#micro509/result/result';\nimport {\n\tfailureResult,\n\trethrowIfInvariant,\n\tsuccessResult,\n\tthrowMicro509Error,\n} from '#micro509/result/result';\n\n/** A single decoded PEM block with its label, decoded DER bytes, and original PEM text. */\nexport interface PemBlock {\n\t/** RFC 7468 label between the `BEGIN` / `END` markers (e.g. `\"CERTIFICATE\"`). */\n\treadonly label: string;\n\t/** Decoded DER content of this block. */\n\treadonly bytes: Uint8Array;\n\t/** The original PEM text including `BEGIN`/`END` lines. */\n\treadonly pem: string;\n}\n\n/**\n * PEM blocks grouped by their label into well-known PKI categories.\n * Blocks that don't match any known label land in {@linkcode others}.\n */\nexport interface CategorizedPemBlocks {\n\t/** Blocks with label `CERTIFICATE`. */\n\treadonly certificates: readonly PemBlock[];\n\t/** Blocks with label `CERTIFICATE REQUEST`. */\n\treadonly certificateRequests: readonly PemBlock[];\n\t/** Blocks with label `PRIVATE KEY`, `RSA PRIVATE KEY`, or `EC PRIVATE KEY`. */\n\treadonly privateKeys: readonly PemBlock[];\n\t/** Blocks with label `PUBLIC KEY`. */\n\treadonly publicKeys: readonly PemBlock[];\n\t/** Blocks whose label doesn't match any of the above categories. */\n\treadonly others: readonly PemBlock[];\n}\n\n// RFC 7468 §3 label ABNF: labelchar = %x21-2C / %x2E-7E, joined by an optional\n// single \"-\" or SP; an empty label is legal.\nconst PEM_LABEL_PATTERN = /^(?:[!-,.-~](?:[- ]?[!-,.-~])*)?$/;\n\n/**\n * Wraps DER bytes in a PEM envelope with 64-character base64 lines.\n *\n * @param label PEM type label (e.g. `\"CERTIFICATE\"`, `\"PRIVATE KEY\"`).\n * @param der Raw DER-encoded content.\n */\nexport function pemEncode(label: string, der: Uint8Array): string {\n\tif (!isPemLabel(label)) {\n\t\tthrow new Error('Invalid PEM label');\n\t}\n\tconst body = base64Encode(der);\n\tconst lines = body.match(/.{1,64}/g) ?? [];\n\treturn `-----BEGIN ${label}-----\\n${lines.join('\\n')}\\n-----END ${label}-----\\n`;\n}\n\n/** Machine-readable failure reason for the PEM decoders. */\nexport type PemErrorCode = 'malformed';\n\n/** Controls how much of the input a PEM decoder consumes. */\nexport interface PemDecodeOptions {\n\t/**\n\t * Require the entire input to be one PEM block of the requested label.\n\t * The BEGIN and END lines must be exact, and the body must contain only\n\t * nonempty base64 lines. Each line break may be LF or CRLF, with at most\n\t * one optional line break after END. Defaults to false.\n\t */\n\treadonly wholeInput?: boolean;\n}\n\n/** Structured failure payload for PEM decoding. */\nexport interface PemFailure extends Micro509Error<PemErrorCode> {\n\t/** Always `false` for failures. */\n\treadonly ok: false;\n}\n\n/** Success-or-failure result from {@linkcode pemDecode}. */\nexport type PemDecodeResult =\n\t| { readonly ok: true; readonly value: Uint8Array }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure>;\n\n/** Success-or-failure result from {@linkcode splitPemBlocks}. */\nexport type SplitPemBlocksResult =\n\t| { readonly ok: true; readonly value: readonly PemBlock[] }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure>;\n\n/** Success-or-failure result from {@linkcode categorizePemBlocks}. */\nexport type CategorizePemBlocksResult =\n\t| { readonly ok: true; readonly value: CategorizedPemBlocks }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure>;\n\n/**\n * Throwing core for {@linkcode pemDecode}: extracts and base64-decodes the\n * DER content from a PEM string. By default, text ahead of the `BEGIN` line\n * is ignored. Throws if the input fails the selected policy or the\n * `BEGIN`/`END` markers don't match `label`.\n *\n * @param label Expected PEM type label.\n * @param pem PEM-encoded text (may contain `\\r`).\n * @param options Set `wholeInput` to require one block with exact boundaries.\n */\nexport function pemDecodeOrThrow(\n\tlabel: string,\n\tpem: string,\n\toptions?: PemDecodeOptions,\n): Uint8Array {\n\tconst wholeInput = options?.wholeInput === true;\n\tconst normalized = wholeInput\n\t\t? pem.replace(/\\r\\n/g, '\\n')\n\t\t: trimPemDocument(pem.replace(/\\r\\n?/g, '\\n'));\n\tconst lines = normalized.split('\\n');\n\tif (wholeInput && lines.at(-1) === '') lines.pop();\n\tconst begin = wholeInput ? 0 : findPreEncapsulationBoundary(lines);\n\tif (\n\t\tbegin === undefined ||\n\t\tparsePemBoundaryLine(lines[begin] ?? '', 'BEGIN', wholeInput) !== label ||\n\t\tparsePemBoundaryLine(lines.at(-1) ?? '', 'END', wholeInput) !== label ||\n\t\tlines.length - begin < 3\n\t) {\n\t\tthrowMicro509Error('malformed', `Invalid PEM for ${label}`, {\n\t\t\tstage: 'pem',\n\t\t\treason: 'invalid_armor',\n\t\t} as const);\n\t}\n\tconst bodyLines = lines.slice(begin + 1, -1);\n\tconst base64Lines = wholeInput ? bodyLines : normalizePemBodyLines(bodyLines);\n\tif (!base64Lines.every((line) => /^[A-Za-z0-9+/=]+$/.test(line))) {\n\t\tthrowMicro509Error('malformed', `Invalid PEM for ${label}`, {\n\t\t\tstage: 'base64',\n\t\t\treason: 'invalid_base64',\n\t\t} as const);\n\t}\n\ttry {\n\t\treturn base64Decode(base64Lines.join(''));\n\t} catch (error) {\n\t\trethrowIfInvariant(error);\n\t\tthrowMicro509Error('malformed', `Invalid PEM for ${label}`, {\n\t\t\tstage: 'base64',\n\t\t\treason: 'invalid_base64',\n\t\t} as const);\n\t}\n}\n\n/**\n * Finds all `BEGIN`/`END`-delimited PEM blocks in a string and returns\n * them as parsed {@linkcode PemBlock} entries. Handles concatenated PEM files\n * and ignores non-PEM text between blocks.\n */\nexport function splitPemBlocksOrThrow(input: string): readonly PemBlock[] {\n\treturn splitPemTextBlocksOrThrow(input).map((block) => ({\n\t\t...block,\n\t\tbytes: pemDecodeOrThrow(block.label, block.pem),\n\t}));\n}\n\n/** @internal A bounded-by-input PEM block before decoding its body. */\nexport interface PemTextBlock {\n\treadonly label: string;\n\treadonly pem: string;\n}\n\n/** @internal Shares the ordinary boundary scanner, retaining legacy encrypted bodies verbatim. */\nexport function splitPemTextBlocksOrThrow(input: string): readonly PemTextBlock[] {\n\tconst normalized = input.replace(/^\\uFEFF/, '').replace(/\\r\\n?/g, '\\n');\n\tconst blocks: PemTextBlock[] = [];\n\tlet openBlock: { readonly label: string; readonly start: number } | undefined;\n\tlet lineStart = 0;\n\twhile (lineStart < normalized.length) {\n\t\tconst newline = normalized.indexOf('\\n', lineStart);\n\t\tconst lineEnd = newline === -1 ? normalized.length : newline;\n\t\tconst nextLineStart = newline === -1 ? normalized.length : newline + 1;\n\t\tconst line = normalized.slice(lineStart, lineEnd);\n\t\tconst beginLine = line.replace(/^[ \\t]+/, '');\n\t\tconst beginLabel = parsePemBoundaryLine(line, 'BEGIN');\n\t\tconst endLabel = parsePemBoundaryLine(line, 'END');\n\n\t\tif (beginLabel !== undefined) {\n\t\t\tif (openBlock !== undefined) {\n\t\t\t\tthrow new Error('Malformed PEM block');\n\t\t\t}\n\t\t\topenBlock = { label: beginLabel, start: lineStart + line.length - beginLine.length };\n\t\t} else if (endLabel !== undefined) {\n\t\t\tblocks.push(closePemBlock(normalized, openBlock, endLabel, nextLineStart));\n\t\t\topenBlock = undefined;\n\t\t} else if (looksLikePemBoundary(line)) {\n\t\t\tthrow new Error('Malformed PEM block');\n\t\t}\n\n\t\tif (newline === -1) {\n\t\t\tbreak;\n\t\t}\n\t\tlineStart = nextLineStart;\n\t}\n\tif (openBlock !== undefined) {\n\t\tthrow new Error('Malformed PEM block');\n\t}\n\treturn blocks;\n}\n\nfunction closePemBlock(\n\tinput: string,\n\topenBlock: { readonly label: string; readonly start: number } | undefined,\n\tendLabel: string,\n\tend: number,\n): PemTextBlock {\n\tif (openBlock === undefined || openBlock.label !== endLabel) {\n\t\tthrow new Error('Malformed PEM block');\n\t}\n\tconst pem = input.slice(openBlock.start, end);\n\treturn {\n\t\tlabel: openBlock.label,\n\t\tpem,\n\t};\n}\n\n/**\n * Groups PEM blocks by label into well-known PKI categories\n * (certificates, CSRs, private keys, public keys, and everything else).\n * Accepts either raw PEM text or pre-split {@linkcode PemBlock} entries.\n */\nexport function categorizePemBlocksOrThrow(\n\tinput: string | readonly PemBlock[],\n): CategorizedPemBlocks {\n\tconst blocks = typeof input === 'string' ? splitPemBlocksOrThrow(input) : input;\n\tconst certificates: PemBlock[] = [];\n\tconst certificateRequests: PemBlock[] = [];\n\tconst privateKeys: PemBlock[] = [];\n\tconst publicKeys: PemBlock[] = [];\n\tconst others: PemBlock[] = [];\n\n\tfor (const block of blocks) {\n\t\tswitch (block.label) {\n\t\t\tcase 'CERTIFICATE':\n\t\t\t\tcertificates.push(block);\n\t\t\t\tbreak;\n\t\t\tcase 'CERTIFICATE REQUEST':\n\t\t\t\tcertificateRequests.push(block);\n\t\t\t\tbreak;\n\t\t\tcase 'PRIVATE KEY':\n\t\t\tcase 'RSA PRIVATE KEY':\n\t\t\tcase 'EC PRIVATE KEY':\n\t\t\t\tprivateKeys.push(block);\n\t\t\t\tbreak;\n\t\t\tcase 'PUBLIC KEY':\n\t\t\t\tpublicKeys.push(block);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tothers.push(block);\n\t\t}\n\t}\n\n\treturn { certificates, certificateRequests, privateKeys, publicKeys, others };\n}\n\nfunction normalizePemBodyLines(lines: readonly string[]): readonly string[] {\n\treturn lines.map((line) => line.replace(/[ \\t]/g, '')).filter((line) => line !== '');\n}\n\nfunction parsePemBoundaryLine(\n\tline: string,\n\tkind: 'BEGIN' | 'END',\n\twholeInput = false,\n): string | undefined {\n\tconst prefix = `-----${kind} `;\n\tconst boundary = wholeInput ? line : trimLwsp(line);\n\tif (!boundary.startsWith(prefix) || !boundary.endsWith('-----')) {\n\t\treturn undefined;\n\t}\n\tconst label = boundary.slice(prefix.length, -5);\n\treturn isPemLabel(label) ? label : undefined;\n}\n\n/** RFC 7468 §2: data before the encapsulation boundaries is permitted. */\nfunction findPreEncapsulationBoundary(lines: readonly string[]): number | undefined {\n\tfor (const [index, line] of lines.entries()) {\n\t\tif (parsePemBoundaryLine(line, 'BEGIN') !== undefined) {\n\t\t\treturn index;\n\t\t}\n\t\tif (looksLikePemBoundary(line)) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction looksLikePemBoundary(line: string): boolean {\n\treturn /^[ \\t]*-{5,}(?:BEGIN|END)/.test(line);\n}\n\n/** RFC 822 §3.2: `field-name = 1*<any CHAR, excluding CTLs, SPACE, and \":\">`. */\nconst RFC822_FIELD_NAME = /^[\\x21-\\x39\\x3b-\\x7e]+$/;\n\n/** RFC 822 §3.3: `LWSP-char = SPACE / HTAB`. */\nfunction isLwspChar(character: string): boolean {\n\treturn character === ' ' || character === '\\t';\n}\n\n/**\n * Strips the whitespace surrounding a PEM document: `LWSP-char`s and the line\n * terminators that separate the boundary lines from the body.\n *\n * `String.prototype.trim` would also strip VT, FF, NBSP, and every Unicode\n * `Zs`, making those characters acceptable at a document edge while\n * {@linkcode parsePemBoundaryLine} rejects them everywhere else.\n */\nfunction trimPemDocument(value: string): string {\n\treturn value.replace(/^[ \\t\\n]+|[ \\t\\n]+$/g, '');\n}\n\n/**\n * @internal Strips surrounding RFC 822 §3.3 `LWSP-char`s.\n *\n * `String.prototype.trim` would also strip VT, FF, NBSP, and every Unicode `Zs`,\n * none of which the grammar admits.\n */\nexport function trimLwsp(value: string): string {\n\treturn value.replace(/^[ \\t]+|[ \\t]+$/g, '');\n}\n\n/** A PEM block carrying RFC 1421 §4.6 encapsulated headers ahead of its body. */\nexport interface TraditionalPemBlock {\n\t/** PEM type label between the `BEGIN` / `END` markers. */\n\treadonly label: string;\n\t/** Encapsulated headers (e.g. `Proc-Type`, `DEK-Info`), unfolded. */\n\treadonly headers: ReadonlyMap<string, string>;\n\t/** Base64-encoded payload after the headers. */\n\treadonly base64Body: string;\n}\n\n/**\n * @internal Parses a PEM block with RFC 1421 §4.6 encapsulated headers.\n *\n * RFC 7468 §2 forbids headers, so this path exists only for the legacy\n * OpenSSL-style encrypted PKCS#1 and SEC1 blocks that predate it.\n */\nexport function parseTraditionalPemOrThrow(pem: string): TraditionalPemBlock {\n\tconst normalized = trimPemDocument(pem.replace(/\\r\\n?/g, '\\n'));\n\tconst lines = normalized.split('\\n');\n\tconst label = parsePemBoundaryLine(lines[0] ?? '', 'BEGIN');\n\tif (label === undefined || lines.length < 2) {\n\t\tthrow new Error('Invalid PEM block');\n\t}\n\tif (parsePemBoundaryLine(lines[lines.length - 1] ?? '', 'END') !== label) {\n\t\tthrow new Error('PEM boundaries do not match');\n\t}\n\tconst headers = new Map<string, string>();\n\tlet index = 1;\n\tlet foldedName: string | undefined;\n\twhile (index < lines.length - 1) {\n\t\tconst line = lines[index];\n\t\tif (line === undefined) {\n\t\t\tbreak;\n\t\t}\n\t\tif (line.length === 0) {\n\t\t\tindex += 1;\n\t\t\tbreak;\n\t\t}\n\t\tif (foldedName !== undefined && isLwspChar(line.charAt(0))) {\n\t\t\theaders.set(foldedName, `${headers.get(foldedName) ?? ''}${line}`);\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tconst delimiter = line.indexOf(':');\n\t\tif (delimiter === -1) {\n\t\t\tbreak;\n\t\t}\n\t\tconst headerName = line.slice(0, delimiter);\n\t\tif (!RFC822_FIELD_NAME.test(headerName)) {\n\t\t\tthrow new Error(`Invalid PEM header name: ${headerName}`);\n\t\t}\n\t\tif (headers.has(headerName)) {\n\t\t\tthrow new Error(`Duplicate PEM header: ${headerName}`);\n\t\t}\n\t\theaders.set(headerName, line.slice(delimiter + 1).replace(/^[ \\t]+/, ''));\n\t\tfoldedName = headerName;\n\t\tindex += 1;\n\t}\n\treturn { label, headers, base64Body: lines.slice(index, lines.length - 1).join('') };\n}\n\nfunction isPemLabel(label: string): boolean {\n\treturn PEM_LABEL_PATTERN.exec(label)?.[0] === label;\n}\n\n/**\n * Extracts and base64-decodes the DER content from a PEM string.\n * Text ahead of the `BEGIN` line is ignored by default. Set\n * {@linkcode PemDecodeOptions.wholeInput} to require one complete block.\n *\n * Returns a typed failure (`code: 'malformed'`) when the `BEGIN`/`END`\n * markers don't match `label`, the input fails the selected policy, or the\n * body is not valid base64. For the throwing form use {@linkcode pemDecodeOrThrow}.\n */\nexport function pemDecode(label: string, pem: string, options?: PemDecodeOptions): PemDecodeResult {\n\treturn toPemResult(() => pemDecodeOrThrow(label, pem, options), 'Invalid PEM');\n}\n\n/**\n * Finds all `BEGIN`/`END`-delimited PEM blocks in a string and returns them\n * as parsed {@linkcode PemBlock} entries. Handles concatenated PEM files and\n * ignores non-PEM text between blocks.\n *\n * Returns a typed failure (`code: 'malformed'`) on stray or truncated PEM\n * markers. For the throwing form use {@linkcode splitPemBlocksOrThrow}.\n */\nexport function splitPemBlocks(input: string): SplitPemBlocksResult {\n\treturn toPemResult(() => splitPemBlocksOrThrow(input), 'Malformed PEM block');\n}\n\n/**\n * Groups PEM blocks by label into well-known PKI categories\n * (certificates, CSRs, private keys, public keys, and everything else).\n * Accepts either raw PEM text or pre-split {@linkcode PemBlock} entries.\n *\n * Returns a typed failure (`code: 'malformed'`) when raw text contains stray\n * or truncated PEM markers. For the throwing form use\n * {@linkcode categorizePemBlocksOrThrow}.\n */\nexport function categorizePemBlocks(\n\tinput: string | readonly PemBlock[],\n): CategorizePemBlocksResult {\n\treturn toPemResult(() => categorizePemBlocksOrThrow(input), 'Malformed PEM block');\n}\n\n/** Shared Result wrapper around the throwing PEM cores. */\nfunction toPemResult<TValue>(\n\toperation: () => TValue,\n\tfallbackMessage: string,\n):\n\t| { readonly ok: true; readonly value: TValue }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure> {\n\ttry {\n\t\treturn successResult(operation());\n\t} catch (error) {\n\t\trethrowIfInvariant(error);\n\t\treturn failureResult('malformed', error instanceof Error ? error.message : fallbackMessage);\n\t}\n}\n"],"mappings":";;;;;;;;;;;AA+CA,MAAMM,IAAoB;;;;;;;AAQ1B,SAAgB,UAAUC,GAAeC,GAAyB;CACjE,IAAI,CAAC,WAAWD,CAAK,GACpB,MAAU,MAAM,mBAAmB;CAIpC,OAAO,cAAcA,EAAM,UAFdN,EAAaO,CACT,CAAC,CAAC,MAAM,UAAU,KAAK,CAAC,EAAA,CACC,KAAK,IAAI,EAAE,aAAaD,EAAM;AACzE;;;;;;;;;;;AA+CA,SAAgB,iBACfA,GACAE,GACAC,GACa;CACb,IAAMC,IAAaD,GAAS,eAAe,IAIrCE,KAHaD,IAChBF,EAAI,QAAQ,SAAS,IAAI,IACzB,gBAAgBA,EAAI,QAAQ,UAAU,IAAI,CAAC,EAAA,CACrB,MAAM,IAAI;CAC/BE,KAAcC,EAAM,GAAG,EAAE,MAAM,MAAIA,EAAM,IAAI;CACjD,IAAMC,IAAQF,IAAa,IAAI,6BAA6BC,CAAK;CACjE,CACCC,MAAU,KAAA,KACV,qBAAqBD,EAAMC,MAAU,IAAI,SAASF,CAAU,MAAMJ,KAClE,qBAAqBK,EAAM,GAAG,EAAE,KAAK,IAAI,OAAOD,CAAU,MAAMJ,KAChEK,EAAM,SAASC,IAAQ,MAEvBR,EAAmB,aAAa,mBAAmBE,KAAS;EAC3D,OAAO;EACP,QAAQ;CACT,CAA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AC;CACjC,SAAS9B,GAAO;EAEf,OADAd,EAAmBc,CAAK,GACjBf,EAAc,aAAae,aAAiB,QAAQA,EAAM,UAAU+B,CAAe;CAC3F;AACD"}
|
package/dist/pem.d.ts
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module micro509/pem
|
|
6
6
|
*/
|
|
7
|
-
import { CategorizePemBlocksResult, CategorizedPemBlocks, PemBlock, PemDecodeResult, PemErrorCode, PemFailure, SplitPemBlocksResult, categorizePemBlocks, categorizePemBlocksOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow } from "./pem/pem.js";
|
|
8
|
-
export { type CategorizePemBlocksResult, type CategorizedPemBlocks, type PemBlock, type PemDecodeResult, type PemErrorCode, type PemFailure, type SplitPemBlocksResult, categorizePemBlocks, categorizePemBlocksOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow };
|
|
7
|
+
import { CategorizePemBlocksResult, CategorizedPemBlocks, PemBlock, PemDecodeOptions, PemDecodeResult, PemErrorCode, PemFailure, SplitPemBlocksResult, categorizePemBlocks, categorizePemBlocksOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow } from "./pem/pem.js";
|
|
8
|
+
export { type CategorizePemBlocksResult, type CategorizedPemBlocks, type PemBlock, type PemDecodeOptions, type PemDecodeResult, type PemErrorCode, type PemFailure, type SplitPemBlocksResult, categorizePemBlocks, categorizePemBlocksOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow };
|
package/dist/pkcs/pkcs12-mac.js
CHANGED
|
@@ -52,7 +52,7 @@ async function createPkcs12MacData(e, t) {
|
|
|
52
52
|
}
|
|
53
53
|
async function createPbmac1MacData(e, t) {
|
|
54
54
|
let n = t.iterations ?? 1e5;
|
|
55
|
-
(!Number.isInteger(n) || n < 1 || n >
|
|
55
|
+
(!Number.isInteger(n) || n < 1 || n > 0xffffffff) && throwPkcs12MacError("invalid_iterations", `PBMAC1 iterations must be an integer from 1 to ${_}, got ${n}`);
|
|
56
56
|
let i = t.salt ?? S().getRandomValues(/* @__PURE__ */ new Uint8Array(16)), a = {
|
|
57
57
|
salt: i,
|
|
58
58
|
iterations: n,
|
|
@@ -211,7 +211,7 @@ function parsePbkdf2Parameters(t) {
|
|
|
211
211
|
if (o === void 0) throw Error("PBKDF2-params in PBMAC1 must include keyLength");
|
|
212
212
|
c === void 0 && throwMacDataError("unsupported_mac_algorithm", "PBKDF2 prf is absent and defaults to HMAC-SHA-1, which PBMAC1 verification does not accept");
|
|
213
213
|
let l = parseHmacAlgorithm(readAlgorithmIdentifier(n, c, "PBKDF2 prf"), "PBKDF2 prf"), u = e(i.value, "PBKDF2 iterationCount");
|
|
214
|
-
if (u.type === "unsafe" || u.value >
|
|
214
|
+
if (u.type === "unsafe" || u.value > 0xffffffff) throw Error(`PBKDF2 iterationCount must be at most ${_}`);
|
|
215
215
|
if (u.value === 0) throw Error("PBKDF2 iterationCount must be at least 1");
|
|
216
216
|
return {
|
|
217
217
|
salt: new Uint8Array(r.value),
|
package/dist/revocation/crl.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { childrenOf as e, decodeBoolean as t, decodeIntegerMagnitude as n, decodeIntegerNumber as r, decodeNonNegativeIntegerBigInt as i, decodeObjectIdentifier as a, decodeString as o, hexToBytes as s, parseTime as c, requireElement as l, signatureBits as u, toHex as d } from "../internal/asn1/asn1.js";
|
|
2
2
|
import { decodeFailureResult as f, decodeRefusalOf as p, rethrowDecodeRefusal as m } from "../internal/asn1/decode-refusal.js";
|
|
3
|
-
import { bitString as h, concatBytes as g, explicitContext as _, generalizedTime as v, implicitConstructedContext as y, implicitPrimitiveContext as b, integer as x, integerFromNumber as
|
|
4
|
-
import { OIDS as
|
|
5
|
-
import { describeSignatureAlgorithm as
|
|
6
|
-
import { NO_CALLER_VERIFICATION as
|
|
3
|
+
import { bitString as h, concatBytes as g, explicitContext as _, generalizedTime as v, implicitConstructedContext as y, implicitPrimitiveContext as b, integer as x, integerFromNumber as S, optionalBytesEqual as ee, readElement as C, readRootElement as w, readSequenceChildren as T, sequence as E, time as D, tlv as O } from "../internal/asn1/der.js";
|
|
4
|
+
import { OIDS as k } from "../internal/asn1/oids.js";
|
|
5
|
+
import { describeSignatureAlgorithm as te } from "../internal/crypto/algorithm-names.js";
|
|
6
|
+
import { NO_CALLER_VERIFICATION as ne, callerVerification as A, verifySignedDataDetailed as j } from "../internal/crypto/sig-verify.js";
|
|
7
7
|
import { encodeAlgorithmIdentifier as M, getSignatureAlgorithm as N, signBytes as P } from "../internal/crypto/signing.js";
|
|
8
8
|
import { base64Encode as F } from "../internal/shared/base64.js";
|
|
9
9
|
import { compareDistinguishedNames as I, compareRelativeDistinguishedNames as L } from "../internal/shared/dn.js";
|
|
@@ -83,15 +83,15 @@ async function createCertificateRevocationList(e) {
|
|
|
83
83
|
assertCrlDate(a, "thisUpdate"), assertCrlDate(o, "nextUpdate");
|
|
84
84
|
for (let t of e.revokedCertificates ?? []) assertCrlDate(t.revocationDate, "revocationDate"), assertCrlDate(t.invalidityDate, "invalidityDate");
|
|
85
85
|
Math.floor(o.getTime() / 1e3) <= Math.floor(a.getTime() / 1e3) && throwCrlEncoderError("next_update_not_after_this_update", "nextUpdate must be at least one second later than thisUpdate");
|
|
86
|
-
let s = buildCrlExtensions(t, n, r, e.issuingDistributionPoint, e.freshestCrlDistributionPoints), c = e.revokedCertificates ?? [], l = c.length === 0 ? [] : [
|
|
87
|
-
|
|
86
|
+
let s = buildCrlExtensions(t, n, r, e.issuingDistributionPoint, e.freshestCrlDistributionPoints), c = e.revokedCertificates ?? [], l = c.length === 0 ? [] : [E(c.map((e) => createRevokedCertificate(e, a)))], u = E([
|
|
87
|
+
S(1),
|
|
88
88
|
M(i),
|
|
89
89
|
ce(e.issuer),
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
D(a),
|
|
91
|
+
D(o),
|
|
92
92
|
...l,
|
|
93
|
-
_(0,
|
|
94
|
-
]), d = await P(e.signerPrivateKey, i, u), f =
|
|
93
|
+
_(0, E(s))
|
|
94
|
+
]), d = await P(e.signerPrivateKey, i, u), f = E([
|
|
95
95
|
u,
|
|
96
96
|
M(i),
|
|
97
97
|
h(d)
|
|
@@ -109,7 +109,7 @@ async function createCertificateRevocationList(e) {
|
|
|
109
109
|
* {@linkcode validateCertificateRevocationList} for that.
|
|
110
110
|
*/
|
|
111
111
|
function parseCertificateRevocationListDerOrThrow(e) {
|
|
112
|
-
let t =
|
|
112
|
+
let t = T(e, { maxDepth: 64 });
|
|
113
113
|
if (t.length !== 3) throw Error("Malformed CRL");
|
|
114
114
|
let n = l(t[0], "TBSCertList"), r = l(t[1], "signatureAlgorithm"), i = l(t[2], "signatureValue"), a = parseSignedCrlFields(e.slice(n.start - n.headerLength, n.end)), o = parseAlgorithmIdentifier(e, r);
|
|
115
115
|
return assertMatchingCrlSignatureAlgorithms(a.signature, o), {
|
|
@@ -121,7 +121,7 @@ function parseCertificateRevocationListDerOrThrow(e) {
|
|
|
121
121
|
thisUpdate: a.thisUpdate,
|
|
122
122
|
...a.nextUpdate === void 0 ? {} : { nextUpdate: a.nextUpdate },
|
|
123
123
|
signatureAlgorithmOid: o.oid,
|
|
124
|
-
signatureAlgorithmName:
|
|
124
|
+
signatureAlgorithmName: te(o.oid, o.parametersDer),
|
|
125
125
|
...o.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: o.parametersDer },
|
|
126
126
|
...a.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: a.authorityKeyIdentifier },
|
|
127
127
|
...a.crlNumber === void 0 ? {} : { crlNumber: a.crlNumber },
|
|
@@ -232,7 +232,7 @@ async function validateCrlBy(e, t, n) {
|
|
|
232
232
|
*
|
|
233
233
|
* @internal
|
|
234
234
|
*/
|
|
235
|
-
async function authenticateCrl(e, t, n =
|
|
235
|
+
async function authenticateCrl(e, t, n = ne) {
|
|
236
236
|
let r;
|
|
237
237
|
try {
|
|
238
238
|
r = normalizeCrl(e);
|
|
@@ -917,12 +917,12 @@ function matchesIdpNameAgainstCrlIssuer(e, t, n) {
|
|
|
917
917
|
/** Constructs a full DN by appending an RDN to an existing Name, returning hex-encoded DER. */
|
|
918
918
|
function resolveRelativeNameToDnHex(e, t) {
|
|
919
919
|
let n = e.rdns.map((e) => s(e.derHex)), r = rebuildRelativeNameAsSet(s(t.derHex));
|
|
920
|
-
return n.push(r), d(
|
|
920
|
+
return n.push(r), d(E(n));
|
|
921
921
|
}
|
|
922
922
|
/** Converts an implicit-tagged [1] relativeName to a proper SET-tagged RDN. */
|
|
923
923
|
function rebuildRelativeNameAsSet(e) {
|
|
924
|
-
let t =
|
|
925
|
-
return
|
|
924
|
+
let t = w(e, { maxDepth: 64 });
|
|
925
|
+
return O(49, t.value);
|
|
926
926
|
}
|
|
927
927
|
/** Deep-compares two issuing distribution point extensions for delta-CRL compatibility. */
|
|
928
928
|
function sameIssuingDistributionPoint(e, t) {
|
|
@@ -1067,22 +1067,22 @@ function bytesEqual(e, t) {
|
|
|
1067
1067
|
}
|
|
1068
1068
|
/** Assembles the CRL-level v2 extensions (AKI, CRLNumber, deltaCRLIndicator, IDP, freshestCRL). */
|
|
1069
1069
|
function buildCrlExtensions(e, t, n, r, i) {
|
|
1070
|
-
let a = [Y(
|
|
1071
|
-
return n !== void 0 && a.push(Y(
|
|
1070
|
+
let a = [Y(k.authorityKeyIdentifier, E([b(0, se(e))])), Y(k.cRLNumber, t)];
|
|
1071
|
+
return n !== void 0 && a.push(Y(k.deltaCRLIndicator, n, !0)), r !== void 0 && a.push(Y(k.issuingDistributionPoint, encodeIssuingDistributionPoint(r), !0)), i !== void 0 && i.length > 0 && a.push(Y(k.freshestCRL, ae(i))), a;
|
|
1072
1072
|
}
|
|
1073
1073
|
/** DER-encodes a single revokedCertificate SEQUENCE (serial, date, optional extensions). */
|
|
1074
1074
|
function createRevokedCertificate(e, t) {
|
|
1075
1075
|
let n = buildRevokedCertificateExtensions(e);
|
|
1076
|
-
return
|
|
1076
|
+
return E([
|
|
1077
1077
|
x(e.serialNumber),
|
|
1078
|
-
|
|
1079
|
-
...n.length === 0 ? [] : [
|
|
1078
|
+
D(e.revocationDate ?? t),
|
|
1079
|
+
...n.length === 0 ? [] : [E(n)]
|
|
1080
1080
|
]);
|
|
1081
1081
|
}
|
|
1082
1082
|
/** Encodes CRL entry extensions (reasonCode, invalidityDate). */
|
|
1083
1083
|
function buildRevokedCertificateExtensions(e) {
|
|
1084
1084
|
let t = [];
|
|
1085
|
-
return e.reasonCode !== void 0 && t.push(Y(
|
|
1085
|
+
return e.reasonCode !== void 0 && t.push(Y(k.cRLReason, O(10, Uint8Array.of(de[e.reasonCode])))), e.invalidityDate !== void 0 && t.push(Y(k.invalidityDate, v(e.invalidityDate))), t;
|
|
1086
1086
|
}
|
|
1087
1087
|
/** Decodes per-entry CRL extensions (reasonCode, invalidityDate, certificateIssuer). */
|
|
1088
1088
|
function parseRevokedCertificateExtensions(t, n) {
|
|
@@ -1107,25 +1107,25 @@ function parseRevokedCertificateExtension(n, r, i, o) {
|
|
|
1107
1107
|
applyRevokedCertificateExtensionValue(c, d.value, u, o);
|
|
1108
1108
|
}
|
|
1109
1109
|
function isSupportedRevokedCertificateExtensionOid(e) {
|
|
1110
|
-
return e ===
|
|
1110
|
+
return e === k.cRLReason || e === k.invalidityDate || e === k.certificateIssuer;
|
|
1111
1111
|
}
|
|
1112
1112
|
function applyRevokedCertificateExtensionValue(e, t, n, r) {
|
|
1113
|
-
if (e ===
|
|
1114
|
-
let e =
|
|
1113
|
+
if (e === k.cRLReason) {
|
|
1114
|
+
let e = w(t, { maxDepth: 64 });
|
|
1115
1115
|
if (e.tag !== 10) throw Error("cRLReason must use ENUMERATED");
|
|
1116
1116
|
let a = parsedRevocationReason(i(e.value, "cRLReason"));
|
|
1117
1117
|
if (n && typeof a != "string") throw Error(`Critical cRLReason holds unrecognized reason code ${String(a.code)}`);
|
|
1118
1118
|
r.reasonCode = a;
|
|
1119
1119
|
}
|
|
1120
|
-
if (e ===
|
|
1121
|
-
let e =
|
|
1120
|
+
if (e === k.invalidityDate && (r.invalidityDate = c(w(t, { maxDepth: 64 }))), e === k.certificateIssuer) {
|
|
1121
|
+
let e = w(t, { maxDepth: 64 });
|
|
1122
1122
|
if (e.tag !== 48) throw Error("certificateIssuer must use SEQUENCE");
|
|
1123
1123
|
r.certificateIssuer = z(t, e);
|
|
1124
1124
|
}
|
|
1125
1125
|
}
|
|
1126
1126
|
/** Decodes the IssuingDistributionPoint extension from its OCTET STRING content. */
|
|
1127
1127
|
function parseIssuingDistributionPoint(t) {
|
|
1128
|
-
let n =
|
|
1128
|
+
let n = w(t, { maxDepth: 64 }), r = {};
|
|
1129
1129
|
for (let i of e(t, n)) parseIssuingDistributionPointField(t, i, r);
|
|
1130
1130
|
return {
|
|
1131
1131
|
...r.distributionPoint === void 0 ? {} : { distributionPoint: r.distributionPoint },
|
|
@@ -1211,7 +1211,7 @@ function parseUniqueIssuingDistributionPointBoolean(e, n, r) {
|
|
|
1211
1211
|
}
|
|
1212
1212
|
/** Decodes a SEQUENCE OF DistributionPoint from DER. */
|
|
1213
1213
|
function parseDistributionPoints(t) {
|
|
1214
|
-
let n =
|
|
1214
|
+
let n = w(t, { maxDepth: 64 });
|
|
1215
1215
|
if (n.tag !== 48) throw Error("DistributionPoints must use SEQUENCE");
|
|
1216
1216
|
let r = e(t, n);
|
|
1217
1217
|
if (r.length === 0) throw Error("DistributionPoints must not be empty");
|
|
@@ -1313,7 +1313,7 @@ function encodeCrlNumber(e, t) {
|
|
|
1313
1313
|
}
|
|
1314
1314
|
/** RFC 5280 §5.2.3: a received CRLNumber of any length, since verifiers MUST handle up to 20 octets. */
|
|
1315
1315
|
function decodeCrlNumber(e) {
|
|
1316
|
-
let t =
|
|
1316
|
+
let t = w(e, { maxDepth: 64 });
|
|
1317
1317
|
if (t.tag !== 2) throw Error("CRLNumber must be an INTEGER");
|
|
1318
1318
|
return n(t.value, "CRLNumber"), BigInt(`0x${d(t.value)}`);
|
|
1319
1319
|
}
|
|
@@ -1328,7 +1328,7 @@ function encodeIssuingDistributionPoint(e) {
|
|
|
1328
1328
|
e.onlyContainsAttributeCerts === !0
|
|
1329
1329
|
].filter(Boolean).length > 1) throw Error("IssuingDistributionPoint can assert at most one of user, CA, or attribute cert scope");
|
|
1330
1330
|
let t = [];
|
|
1331
|
-
return e.distributionPoint !== void 0 && t.push(y(0, encodeDistributionPointName(e.distributionPoint))), e.onlyContainsUserCerts && t.push(b(1, Uint8Array.of(255))), e.onlyContainsCACerts && t.push(b(2, Uint8Array.of(255))), e.onlySomeReasons !== void 0 && e.onlySomeReasons.length > 0 && t.push(b(3, re(e.onlySomeReasons))), e.indirectCrl && t.push(b(4, Uint8Array.of(255))), e.onlyContainsAttributeCerts && t.push(b(5, Uint8Array.of(255))),
|
|
1331
|
+
return e.distributionPoint !== void 0 && t.push(y(0, encodeDistributionPointName(e.distributionPoint))), e.onlyContainsUserCerts && t.push(b(1, Uint8Array.of(255))), e.onlyContainsCACerts && t.push(b(2, Uint8Array.of(255))), e.onlySomeReasons !== void 0 && e.onlySomeReasons.length > 0 && t.push(b(3, re(e.onlySomeReasons))), e.indirectCrl && t.push(b(4, Uint8Array.of(255))), e.onlyContainsAttributeCerts && t.push(b(5, Uint8Array.of(255))), E(t);
|
|
1332
1332
|
}
|
|
1333
1333
|
/** DER-encodes a DistributionPointName (fullName or relativeName). */
|
|
1334
1334
|
function encodeDistributionPointName(e) {
|
|
@@ -1336,7 +1336,7 @@ function encodeDistributionPointName(e) {
|
|
|
1336
1336
|
switch (e.type) {
|
|
1337
1337
|
case "fullName": return e.fullName.length === 0 && throwCrlEncoderError("distribution_point_full_name_empty", "DistributionPointName fullName must not be empty"), y(0, concatGeneralNames(e.fullName));
|
|
1338
1338
|
case "relativeName": {
|
|
1339
|
-
let t = le(e.relativeName), n =
|
|
1339
|
+
let t = le(e.relativeName), n = C(t);
|
|
1340
1340
|
return y(1, t.slice(n.start, n.end));
|
|
1341
1341
|
}
|
|
1342
1342
|
default: throw Error(`Unhandled DistributionPointName type: ${String(e)}`);
|
|
@@ -1383,7 +1383,7 @@ function parseIssuer(t, n) {
|
|
|
1383
1383
|
*/
|
|
1384
1384
|
function parseDerHexName(e) {
|
|
1385
1385
|
try {
|
|
1386
|
-
let t = s(e), n = unwrapNameElement(t,
|
|
1386
|
+
let t = s(e), n = unwrapNameElement(t, w(t, { maxDepth: 64 }));
|
|
1387
1387
|
return n.tag === 48 ? parseIssuer(t, n) : void 0;
|
|
1388
1388
|
} catch (e) {
|
|
1389
1389
|
m(e, W);
|
|
@@ -1408,7 +1408,7 @@ function directoryNameDerHexMatchesParsedName(e, t) {
|
|
|
1408
1408
|
}
|
|
1409
1409
|
/** Extracts the keyIdentifier field from an AuthorityKeyIdentifier extension value. */
|
|
1410
1410
|
function parseAuthorityKeyIdentifier(t) {
|
|
1411
|
-
let n =
|
|
1411
|
+
let n = w(t, {
|
|
1412
1412
|
maxDepth: 64,
|
|
1413
1413
|
allowOpaqueConstructedTags: [161, 162]
|
|
1414
1414
|
});
|
|
@@ -1458,7 +1458,7 @@ function validateImplicitSerialNumberEncoding(e, t) {
|
|
|
1458
1458
|
}
|
|
1459
1459
|
/** RFC 5280 §5.1.1.2: signatureAlgorithm MUST equal the tbsCertList signature field. */
|
|
1460
1460
|
function assertMatchingCrlSignatureAlgorithms(e, t) {
|
|
1461
|
-
if (e.oid !== t.oid || !
|
|
1461
|
+
if (e.oid !== t.oid || !ee(e.parametersDer, t.parametersDer)) throw Error("CRL signatureAlgorithm must match TBSCertList signature");
|
|
1462
1462
|
}
|
|
1463
1463
|
/** Extracts the algorithm OID from an AlgorithmIdentifier SEQUENCE. */
|
|
1464
1464
|
function parseAlgorithmIdentifier(t, n) {
|
|
@@ -1519,22 +1519,22 @@ function normalizeCrl(e) {
|
|
|
1519
1519
|
throw Error("certificate revocation list input is malformed");
|
|
1520
1520
|
}
|
|
1521
1521
|
function parseSignedCrlFields(t) {
|
|
1522
|
-
let n =
|
|
1522
|
+
let n = w(t, { maxDepth: 64 }), r = e(t, n), i = parseCrlVersionField(r), a = i.version, o = l(r[i.nextIndex], "signature"), s = i.nextIndex + 1, u = l(r[s], "issuer"), d = l(r[s + 1], "thisUpdate"), f = s + 2, p = r[f], m = p !== void 0 && (p.tag === 23 || p.tag === 24) ? c(p) : void 0;
|
|
1523
1523
|
m !== void 0 && (f += 1);
|
|
1524
1524
|
let h = r[f], g = h?.tag === 48 ? parseRevokedCertificates(t, h, a) : [];
|
|
1525
1525
|
h?.tag === 48 && (f += 1);
|
|
1526
|
-
let _ =
|
|
1526
|
+
let _ = parseCrlExtensionFields(t, r[f], a);
|
|
1527
1527
|
return {
|
|
1528
1528
|
version: a,
|
|
1529
1529
|
signature: parseAlgorithmIdentifier(t, o),
|
|
1530
1530
|
issuer: parseIssuer(t, u),
|
|
1531
1531
|
thisUpdate: c(d),
|
|
1532
1532
|
...m === void 0 ? {} : { nextUpdate: m },
|
|
1533
|
-
...
|
|
1534
|
-
...
|
|
1535
|
-
...
|
|
1536
|
-
...
|
|
1537
|
-
...
|
|
1533
|
+
..._.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: _.authorityKeyIdentifier },
|
|
1534
|
+
..._.crlNumber === void 0 ? {} : { crlNumber: _.crlNumber },
|
|
1535
|
+
..._.baseCrlNumber === void 0 ? {} : { baseCrlNumber: _.baseCrlNumber },
|
|
1536
|
+
..._.issuingDistributionPoint === void 0 ? {} : { issuingDistributionPoint: _.issuingDistributionPoint },
|
|
1537
|
+
..._.freshestCrlDistributionPoints === void 0 ? {} : { freshestCrlDistributionPoints: _.freshestCrlDistributionPoints },
|
|
1538
1538
|
revokedCertificates: g
|
|
1539
1539
|
};
|
|
1540
1540
|
}
|
|
@@ -1556,7 +1556,7 @@ function parseRevokedCertificates(t, n, r) {
|
|
|
1556
1556
|
return e(t, n).map((e) => parseRevokedCertificateEntry(t, e, r));
|
|
1557
1557
|
}
|
|
1558
1558
|
function parseRevokedCertificateEntry(e, t, n) {
|
|
1559
|
-
let r = e.slice(t.start - t.headerLength, t.end), i =
|
|
1559
|
+
let r = e.slice(t.start - t.headerLength, t.end), i = T(r), a = l(i[0], "revoked serialNumber");
|
|
1560
1560
|
if (a.tag !== 2) throw Error("revoked serialNumber must use INTEGER");
|
|
1561
1561
|
let o = i[2];
|
|
1562
1562
|
if (o !== void 0 && n !== 2) throw Error("revoked certificate extensions require CRL version 2");
|
|
@@ -1588,14 +1588,14 @@ function parseCrlExtensionField(n, r, i, o) {
|
|
|
1588
1588
|
applyParsedCrlExtensionField(c, d.value, o);
|
|
1589
1589
|
}
|
|
1590
1590
|
function isSupportedCrlExtensionOid(e) {
|
|
1591
|
-
return e ===
|
|
1591
|
+
return e === k.authorityKeyIdentifier || e === k.cRLNumber || e === k.deltaCRLIndicator || e === k.issuingDistributionPoint || e === k.freshestCRL;
|
|
1592
1592
|
}
|
|
1593
1593
|
function applyParsedCrlExtensionField(e, t, n) {
|
|
1594
|
-
if (e ===
|
|
1594
|
+
if (e === k.authorityKeyIdentifier) {
|
|
1595
1595
|
let e = parseAuthorityKeyIdentifier(t);
|
|
1596
1596
|
e !== void 0 && (n.authorityKeyIdentifier = e);
|
|
1597
1597
|
}
|
|
1598
|
-
e ===
|
|
1598
|
+
e === k.cRLNumber && (n.crlNumber = decodeCrlNumber(t)), e === k.deltaCRLIndicator && (n.baseCrlNumber = decodeCrlNumber(t)), e === k.issuingDistributionPoint && (n.issuingDistributionPoint = parseIssuingDistributionPoint(t)), e === k.freshestCRL && (n.freshestCrlDistributionPoints = parseDistributionPoints(t));
|
|
1599
1599
|
}
|
|
1600
1600
|
/** Accepts PEM, DER, or already-parsed certificate and returns a parsed certificate. */
|
|
1601
1601
|
function normalizeCrlCertificate(e) {
|