micro509 0.7.1 → 0.8.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/README.md +2 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +15 -1
- package/dist/internal/asn1/asn1.js +280 -2
- package/dist/internal/asn1/der.js +378 -2
- package/dist/internal/asn1/oids.js +103 -2
- package/dist/internal/crypto/algorithm-names.js +58 -2
- package/dist/internal/crypto/ecdsa.js +68 -2
- package/dist/internal/crypto/hash.js +286 -2
- package/dist/internal/crypto/pbes2.js +213 -2
- package/dist/internal/crypto/rsa-pss.js +184 -2
- package/dist/internal/crypto/sig-verify.js +192 -2
- package/dist/internal/crypto/signing.d.ts +1 -2
- package/dist/internal/crypto/signing.js +123 -2
- package/dist/internal/crypto/webcrypto.js +14 -2
- package/dist/internal/shared/base64.js +16 -2
- package/dist/internal/shared/dn.js +84 -2
- package/dist/internal/shared/ip.js +164 -2
- package/dist/internal/verify/name-constraints-engine.js +450 -2
- package/dist/internal/verify/policy-engine.js +382 -2
- package/dist/internal/verify/verify-path.js +298 -2
- package/dist/internal/x509/extension-bits.js +132 -2
- package/dist/internal/x509/extension-registry.js +229 -2
- package/dist/internal/x509/name-fields.js +93 -2
- package/dist/keys/keys.d.ts +231 -7
- package/dist/keys/keys.js +1087 -5
- package/dist/keys.d.ts +2 -2
- package/dist/keys.js +2 -1
- package/dist/pem/pem.d.ts +2 -2
- package/dist/pem/pem.js +172 -6
- package/dist/pem.js +2 -1
- package/dist/pkcs/pfx.d.ts +4 -5
- package/dist/pkcs/pfx.js +395 -2
- package/dist/pkcs/pkcs12-mac.d.ts +2 -2
- package/dist/pkcs/pkcs12-mac.js +175 -2
- package/dist/pkcs/pkcs7.d.ts +1 -2
- package/dist/pkcs/pkcs7.js +653 -2
- package/dist/pkcs.d.ts +2 -2
- package/dist/pkcs.js +4 -1
- package/dist/result/result.d.ts +1 -2
- package/dist/result/result.js +111 -2
- package/dist/result.js +2 -1
- package/dist/revocation/chain.d.ts +4 -5
- package/dist/revocation/chain.js +536 -2
- package/dist/revocation/crl.d.ts +2 -2
- package/dist/revocation/crl.js +1119 -2
- package/dist/revocation/ocsp.d.ts +3 -2
- package/dist/revocation/ocsp.js +958 -2
- package/dist/revocation/revocation.d.ts +1 -2
- package/dist/revocation/revocation.js +261 -2
- package/dist/revocation.d.ts +2 -2
- package/dist/revocation.js +5 -1
- package/dist/verify/identity.d.ts +1 -2
- package/dist/verify/identity.js +270 -2
- package/dist/verify/name-constraints.d.ts +1 -2
- package/dist/verify/policy.d.ts +1 -2
- package/dist/verify/verify.d.ts +1 -2
- package/dist/verify/verify.js +764 -2
- package/dist/verify.js +3 -1
- package/dist/x509/certificate.d.ts +1 -2
- package/dist/x509/certificate.js +151 -2
- package/dist/x509/csr.d.ts +1 -2
- package/dist/x509/csr.js +71 -2
- package/dist/x509/extensions.d.ts +1 -2
- package/dist/x509/extensions.js +387 -2
- package/dist/x509/name.d.ts +1 -2
- package/dist/x509/name.js +173 -2
- package/dist/x509/parse.d.ts +84 -2
- package/dist/x509/parse.js +1090 -2
- package/dist/x509.d.ts +2 -2
- package/dist/x509.js +6 -1
- package/package.json +74 -34
- package/dist/internal/asn1/asn1.js.map +0 -1
- package/dist/internal/asn1/der.js.map +0 -1
- package/dist/internal/asn1/oids.js.map +0 -1
- package/dist/internal/crypto/algorithm-names.js.map +0 -1
- package/dist/internal/crypto/ecdsa.js.map +0 -1
- package/dist/internal/crypto/hash.js.map +0 -1
- package/dist/internal/crypto/pbes2.d.ts +0 -23
- package/dist/internal/crypto/pbes2.js.map +0 -1
- package/dist/internal/crypto/rsa-pss.js.map +0 -1
- package/dist/internal/crypto/sig-verify.js.map +0 -1
- package/dist/internal/crypto/signing.js.map +0 -1
- package/dist/internal/crypto/webcrypto.js.map +0 -1
- package/dist/internal/shared/base64.js.map +0 -1
- package/dist/internal/shared/dn.js.map +0 -1
- package/dist/internal/shared/ip.js.map +0 -1
- package/dist/internal/verify/name-constraints-engine.js.map +0 -1
- package/dist/internal/verify/policy-engine.js.map +0 -1
- package/dist/internal/verify/verify-path.js.map +0 -1
- package/dist/internal/x509/extension-bits.js.map +0 -1
- package/dist/internal/x509/extension-registry.js.map +0 -1
- package/dist/internal/x509/name-fields.js.map +0 -1
- package/dist/keys/keys.js.map +0 -1
- package/dist/pem/pem.js.map +0 -1
- package/dist/pkcs/pfx.js.map +0 -1
- package/dist/pkcs/pkcs12-mac.js.map +0 -1
- package/dist/pkcs/pkcs7.js.map +0 -1
- package/dist/result/result.js.map +0 -1
- package/dist/revocation/chain.js.map +0 -1
- package/dist/revocation/crl.js.map +0 -1
- package/dist/revocation/ocsp.js.map +0 -1
- package/dist/revocation/revocation.js.map +0 -1
- package/dist/verify/identity.js.map +0 -1
- package/dist/verify/verify.js.map +0 -1
- package/dist/x509/certificate.js.map +0 -1
- package/dist/x509/csr.js.map +0 -1
- package/dist/x509/extensions.js.map +0 -1
- package/dist/x509/name.js.map +0 -1
- package/dist/x509/parse.js.map +0 -1
package/dist/keys.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EcKeyAlgorithmInput, EcNamedCurve, Ed25519KeyAlgorithmInput, EncryptedPkcs8Options, ImportEcKeyInput, ImportEd25519KeyInput, ImportEncryptedKeyErrorCode, ImportEncryptedKeyFailure, ImportEncryptedKeyResult, ImportKeyErrorCode, ImportKeyFailure, ImportKeyResult, ImportRsaKeyInput, KeyAlgorithmInput, KeyPairMaterial, LegacyPemEncryptionOptions, PrivateKeyImportInput, PublicKeyImportInput, RsaHash, RsaKeyAlgorithmInput, RsaScheme, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs8Der, importEncryptedPkcs8Pem, importEncryptedSec1Pem, importPkcs1Der, importPkcs1Pem, importPkcs8Base64, importPkcs8Der, importPkcs8Pem, importPrivateJwk, importPublicJwk, importSec1Der, importSec1Pem, importSpkiBase64, importSpkiDer, importSpkiPem } from "./keys/keys.js";
|
|
2
|
-
export { type EcKeyAlgorithmInput, type EcNamedCurve, type Ed25519KeyAlgorithmInput, type EncryptedPkcs8Options, type ImportEcKeyInput, type ImportEd25519KeyInput, type ImportEncryptedKeyErrorCode, type ImportEncryptedKeyFailure, type ImportEncryptedKeyResult, type ImportKeyErrorCode, type ImportKeyFailure, type ImportKeyResult, type ImportRsaKeyInput, type KeyAlgorithmInput, type KeyPairMaterial, type LegacyPemEncryptionOptions, type PrivateKeyImportInput, type PublicKeyImportInput, type RsaHash, type RsaKeyAlgorithmInput, type RsaScheme, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs8Der, importEncryptedPkcs8Pem, importEncryptedSec1Pem, importPkcs1Der, importPkcs1Pem, importPkcs8Base64, importPkcs8Der, importPkcs8Pem, importPrivateJwk, importPublicJwk, importSec1Der, importSec1Pem, importSpkiBase64, importSpkiDer, importSpkiPem };
|
|
1
|
+
import { EcKeyAlgorithmInput, EcNamedCurve, Ed25519KeyAlgorithmInput, EncryptedPkcs8Options, ImportEcKeyInput, ImportEd25519KeyInput, ImportEncryptedKeyErrorCode, ImportEncryptedKeyFailure, ImportEncryptedKeyResult, ImportKeyErrorCode, ImportKeyFailure, ImportKeyResult, ImportRsaKeyInput, KeyAlgorithmInput, KeyPairMaterial, LegacyPemEncryptionOptions, PrivateKeyImportInput, PublicKeyImportInput, RsaHash, RsaKeyAlgorithmInput, RsaScheme, derivePublicKey, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs1PemOrThrow, importEncryptedPkcs8Der, importEncryptedPkcs8DerOrThrow, importEncryptedPkcs8Pem, importEncryptedPkcs8PemOrThrow, importEncryptedSec1Pem, importEncryptedSec1PemOrThrow, importPkcs1Der, importPkcs1DerOrThrow, importPkcs1Pem, importPkcs1PemOrThrow, importPkcs8Base64, importPkcs8Base64OrThrow, importPkcs8Der, importPkcs8DerOrThrow, importPkcs8Pem, importPkcs8PemOrThrow, importPrivateJwk, importPrivateJwkOrThrow, importPublicJwk, importPublicJwkOrThrow, importSec1Der, importSec1DerOrThrow, importSec1Pem, importSec1PemOrThrow, importSpkiBase64, importSpkiBase64OrThrow, importSpkiDer, importSpkiDerOrThrow, importSpkiPem, importSpkiPemOrThrow } from "./keys/keys.js";
|
|
2
|
+
export { type EcKeyAlgorithmInput, type EcNamedCurve, type Ed25519KeyAlgorithmInput, type EncryptedPkcs8Options, type ImportEcKeyInput, type ImportEd25519KeyInput, type ImportEncryptedKeyErrorCode, type ImportEncryptedKeyFailure, type ImportEncryptedKeyResult, type ImportKeyErrorCode, type ImportKeyFailure, type ImportKeyResult, type ImportRsaKeyInput, type KeyAlgorithmInput, type KeyPairMaterial, type LegacyPemEncryptionOptions, type PrivateKeyImportInput, type PublicKeyImportInput, type RsaHash, type RsaKeyAlgorithmInput, type RsaScheme, derivePublicKey, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs1PemOrThrow, importEncryptedPkcs8Der, importEncryptedPkcs8DerOrThrow, importEncryptedPkcs8Pem, importEncryptedPkcs8PemOrThrow, importEncryptedSec1Pem, importEncryptedSec1PemOrThrow, importPkcs1Der, importPkcs1DerOrThrow, importPkcs1Pem, importPkcs1PemOrThrow, importPkcs8Base64, importPkcs8Base64OrThrow, importPkcs8Der, importPkcs8DerOrThrow, importPkcs8Pem, importPkcs8PemOrThrow, importPrivateJwk, importPrivateJwkOrThrow, importPublicJwk, importPublicJwkOrThrow, importSec1Der, importSec1DerOrThrow, importSec1Pem, importSec1PemOrThrow, importSpkiBase64, importSpkiBase64OrThrow, importSpkiDer, importSpkiDerOrThrow, importSpkiPem, importSpkiPemOrThrow };
|
package/dist/keys.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { derivePublicKey, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs1PemOrThrow, importEncryptedPkcs8Der, importEncryptedPkcs8DerOrThrow, importEncryptedPkcs8Pem, importEncryptedPkcs8PemOrThrow, importEncryptedSec1Pem, importEncryptedSec1PemOrThrow, importPkcs1Der, importPkcs1DerOrThrow, importPkcs1Pem, importPkcs1PemOrThrow, importPkcs8Base64, importPkcs8Base64OrThrow, importPkcs8Der, importPkcs8DerOrThrow, importPkcs8Pem, importPkcs8PemOrThrow, importPrivateJwk, importPrivateJwkOrThrow, importPublicJwk, importPublicJwkOrThrow, importSec1Der, importSec1DerOrThrow, importSec1Pem, importSec1PemOrThrow, importSpkiBase64, importSpkiBase64OrThrow, importSpkiDer, importSpkiDerOrThrow, importSpkiPem, importSpkiPemOrThrow } from "./keys/keys.js";
|
|
2
|
+
export { derivePublicKey, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs1PemOrThrow, importEncryptedPkcs8Der, importEncryptedPkcs8DerOrThrow, importEncryptedPkcs8Pem, importEncryptedPkcs8PemOrThrow, importEncryptedSec1Pem, importEncryptedSec1PemOrThrow, importPkcs1Der, importPkcs1DerOrThrow, importPkcs1Pem, importPkcs1PemOrThrow, importPkcs8Base64, importPkcs8Base64OrThrow, importPkcs8Der, importPkcs8DerOrThrow, importPkcs8Pem, importPkcs8PemOrThrow, importPrivateJwk, importPrivateJwkOrThrow, importPublicJwk, importPublicJwkOrThrow, importSec1Der, importSec1DerOrThrow, importSec1Pem, importSec1PemOrThrow, importSpkiBase64, importSpkiBase64OrThrow, importSpkiDer, importSpkiDerOrThrow, importSpkiPem, importSpkiPemOrThrow };
|
package/dist/pem/pem.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ declare function pemEncode(label: string, der: Uint8Array): string;
|
|
|
37
37
|
type PemErrorCode = "malformed";
|
|
38
38
|
/** Structured failure payload for PEM decoding. */
|
|
39
39
|
interface PemFailure extends Micro509Error<PemErrorCode> {
|
|
40
|
+
/** Always `false` for failures. */
|
|
40
41
|
readonly ok: false;
|
|
41
42
|
}
|
|
42
43
|
/** Success-or-failure result from {@linkcode pemDecode}. */
|
|
@@ -103,5 +104,4 @@ declare function splitPemBlocks(input: string): SplitPemBlocksResult;
|
|
|
103
104
|
*/
|
|
104
105
|
declare function categorizePemBlocks(input: string | readonly PemBlock[]): CategorizePemBlocksResult;
|
|
105
106
|
//#endregion
|
|
106
|
-
export { CategorizePemBlocksResult, CategorizedPemBlocks, PemBlock, PemDecodeResult, PemErrorCode, PemFailure, SplitPemBlocksResult, categorizePemBlocks, categorizePemBlocksOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow };
|
|
107
|
-
//# sourceMappingURL=pem.d.ts.map
|
|
107
|
+
export { CategorizePemBlocksResult, CategorizedPemBlocks, PemBlock, PemDecodeResult, PemErrorCode, PemFailure, SplitPemBlocksResult, categorizePemBlocks, categorizePemBlocksOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow };
|
package/dist/pem/pem.js
CHANGED
|
@@ -1,6 +1,172 @@
|
|
|
1
|
-
import{base64Decode
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { base64Decode, base64Encode } from "../internal/shared/base64.js";
|
|
2
|
+
import { failureResult, rethrowIfInvariant, successResult } from "../result/result.js";
|
|
3
|
+
//#region src/pem/pem.ts
|
|
4
|
+
/**
|
|
5
|
+
* PEM helpers used across the public API.
|
|
6
|
+
*
|
|
7
|
+
* Encodes, decodes, splits, and categorizes PEM blocks as defined by
|
|
8
|
+
* RFC 7468.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Wraps DER bytes in a PEM envelope with 64-character base64 lines.
|
|
14
|
+
*
|
|
15
|
+
* @param label PEM type label (e.g. `"CERTIFICATE"`, `"PRIVATE KEY"`).
|
|
16
|
+
* @param der Raw DER-encoded content.
|
|
17
|
+
*/
|
|
18
|
+
function pemEncode(label, der) {
|
|
19
|
+
return `-----BEGIN ${label}-----\n${(base64Encode(der).match(/.{1,64}/g) ?? []).join("\n")}\n-----END ${label}-----`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Throwing core for {@linkcode pemDecode}: extracts and base64-decodes the
|
|
23
|
+
* DER content from a PEM string. Throws if the `BEGIN`/`END` markers don't
|
|
24
|
+
* match `label`.
|
|
25
|
+
*
|
|
26
|
+
* @param label Expected PEM type label.
|
|
27
|
+
* @param pem PEM-encoded text (may contain `\r`).
|
|
28
|
+
*/
|
|
29
|
+
function pemDecodeOrThrow(label, pem) {
|
|
30
|
+
const normalized = pem.replace(/\r/g, "").trim();
|
|
31
|
+
const begin = `-----BEGIN ${label}-----`;
|
|
32
|
+
const end = `-----END ${label}-----`;
|
|
33
|
+
const lines = normalized.split("\n");
|
|
34
|
+
if (lines[0] !== begin || lines[lines.length - 1] !== end || lines.length < 3) throw new Error(`Invalid PEM for ${label}`);
|
|
35
|
+
const bodyLines = normalizePemBodyLines(lines.slice(1, -1));
|
|
36
|
+
if (bodyLines === void 0) throw new Error(`Invalid PEM for ${label}`);
|
|
37
|
+
try {
|
|
38
|
+
return base64Decode(bodyLines.join(""));
|
|
39
|
+
} catch {
|
|
40
|
+
throw new Error(`Invalid PEM for ${label}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Finds all `BEGIN`/`END`-delimited PEM blocks in a string and returns
|
|
45
|
+
* them as parsed {@linkcode PemBlock} entries. Handles concatenated PEM files
|
|
46
|
+
* and ignores non-PEM text between blocks.
|
|
47
|
+
*/
|
|
48
|
+
function splitPemBlocksOrThrow(input) {
|
|
49
|
+
const normalized = input.replace(/\r/g, "");
|
|
50
|
+
const blocks = [];
|
|
51
|
+
const beginToken = "-----BEGIN ";
|
|
52
|
+
let cursor = 0;
|
|
53
|
+
let scan = 0;
|
|
54
|
+
while (scan < normalized.length) {
|
|
55
|
+
const beginIdx = normalized.indexOf(beginToken, scan);
|
|
56
|
+
if (beginIdx === -1) break;
|
|
57
|
+
const labelStart = beginIdx + 11;
|
|
58
|
+
const dashIdx = normalized.indexOf("-----", labelStart);
|
|
59
|
+
if (dashIdx === -1) break;
|
|
60
|
+
const label = normalized.slice(labelStart, dashIdx);
|
|
61
|
+
const beginLineEnd = dashIdx + 5;
|
|
62
|
+
if (label.length === 0 || label.includes("-") || label.includes("\n") || normalized[beginLineEnd] !== "\n") {
|
|
63
|
+
scan = labelStart;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const bodyStart = beginLineEnd + 1;
|
|
67
|
+
const endToken = `\n-----END ${label}-----`;
|
|
68
|
+
const endIdx = normalized.indexOf(endToken, bodyStart);
|
|
69
|
+
if (endIdx === -1) break;
|
|
70
|
+
const blockEnd = endIdx + endToken.length;
|
|
71
|
+
const pem = normalized.slice(beginIdx, blockEnd);
|
|
72
|
+
if (containsPemMarker(normalized.slice(cursor, beginIdx))) throw new Error("Malformed PEM block");
|
|
73
|
+
blocks.push({
|
|
74
|
+
label,
|
|
75
|
+
bytes: pemDecodeOrThrow(label, pem),
|
|
76
|
+
pem
|
|
77
|
+
});
|
|
78
|
+
cursor = blockEnd;
|
|
79
|
+
scan = blockEnd;
|
|
80
|
+
}
|
|
81
|
+
if (containsPemMarker(normalized.slice(cursor))) throw new Error("Malformed PEM block");
|
|
82
|
+
return blocks;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Groups PEM blocks by label into well-known PKI categories
|
|
86
|
+
* (certificates, CSRs, private keys, public keys, and everything else).
|
|
87
|
+
* Accepts either raw PEM text or pre-split {@linkcode PemBlock} entries.
|
|
88
|
+
*/
|
|
89
|
+
function categorizePemBlocksOrThrow(input) {
|
|
90
|
+
const blocks = typeof input === "string" ? splitPemBlocksOrThrow(input) : input;
|
|
91
|
+
const certificates = [];
|
|
92
|
+
const certificateRequests = [];
|
|
93
|
+
const privateKeys = [];
|
|
94
|
+
const publicKeys = [];
|
|
95
|
+
const others = [];
|
|
96
|
+
for (const block of blocks) switch (block.label) {
|
|
97
|
+
case "CERTIFICATE":
|
|
98
|
+
certificates.push(block);
|
|
99
|
+
break;
|
|
100
|
+
case "CERTIFICATE REQUEST":
|
|
101
|
+
certificateRequests.push(block);
|
|
102
|
+
break;
|
|
103
|
+
case "PRIVATE KEY":
|
|
104
|
+
case "RSA PRIVATE KEY":
|
|
105
|
+
case "EC PRIVATE KEY":
|
|
106
|
+
privateKeys.push(block);
|
|
107
|
+
break;
|
|
108
|
+
case "PUBLIC KEY":
|
|
109
|
+
publicKeys.push(block);
|
|
110
|
+
break;
|
|
111
|
+
default: others.push(block);
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
certificates,
|
|
115
|
+
certificateRequests,
|
|
116
|
+
privateKeys,
|
|
117
|
+
publicKeys,
|
|
118
|
+
others
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function normalizePemBodyLines(lines) {
|
|
122
|
+
const nonEmptyLines = lines.map((line) => line.replace(/[ \t]/g, "")).filter((line) => line !== "");
|
|
123
|
+
if (nonEmptyLines.length === 0) return [""];
|
|
124
|
+
return nonEmptyLines.every((line) => /^[A-Za-z0-9+/=]+$/.test(line)) ? nonEmptyLines : void 0;
|
|
125
|
+
}
|
|
126
|
+
function containsPemMarker(value) {
|
|
127
|
+
return value.includes("-----BEGIN ") || value.includes("-----END ");
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Extracts and base64-decodes the DER content from a PEM string.
|
|
131
|
+
*
|
|
132
|
+
* Returns a typed failure (`code: 'malformed'`) when the `BEGIN`/`END`
|
|
133
|
+
* markers don't match `label` or the body is not valid base64. For the
|
|
134
|
+
* throwing form use {@linkcode pemDecodeOrThrow}.
|
|
135
|
+
*/
|
|
136
|
+
function pemDecode(label, pem) {
|
|
137
|
+
return toPemResult(() => pemDecodeOrThrow(label, pem), "Invalid PEM");
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Finds all `BEGIN`/`END`-delimited PEM blocks in a string and returns them
|
|
141
|
+
* as parsed {@linkcode PemBlock} entries. Handles concatenated PEM files and
|
|
142
|
+
* ignores non-PEM text between blocks.
|
|
143
|
+
*
|
|
144
|
+
* Returns a typed failure (`code: 'malformed'`) on stray or truncated PEM
|
|
145
|
+
* markers. For the throwing form use {@linkcode splitPemBlocksOrThrow}.
|
|
146
|
+
*/
|
|
147
|
+
function splitPemBlocks(input) {
|
|
148
|
+
return toPemResult(() => splitPemBlocksOrThrow(input), "Malformed PEM block");
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Groups PEM blocks by label into well-known PKI categories
|
|
152
|
+
* (certificates, CSRs, private keys, public keys, and everything else).
|
|
153
|
+
* Accepts either raw PEM text or pre-split {@linkcode PemBlock} entries.
|
|
154
|
+
*
|
|
155
|
+
* Returns a typed failure (`code: 'malformed'`) when raw text contains stray
|
|
156
|
+
* or truncated PEM markers. For the throwing form use
|
|
157
|
+
* {@linkcode categorizePemBlocksOrThrow}.
|
|
158
|
+
*/
|
|
159
|
+
function categorizePemBlocks(input) {
|
|
160
|
+
return toPemResult(() => categorizePemBlocksOrThrow(input), "Malformed PEM block");
|
|
161
|
+
}
|
|
162
|
+
/** Shared Result wrapper around the throwing PEM cores. */
|
|
163
|
+
function toPemResult(operation, fallbackMessage) {
|
|
164
|
+
try {
|
|
165
|
+
return successResult(operation());
|
|
166
|
+
} catch (error) {
|
|
167
|
+
rethrowIfInvariant(error);
|
|
168
|
+
return failureResult("malformed", error instanceof Error ? error.message : fallbackMessage);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
export { categorizePemBlocks, categorizePemBlocksOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow };
|
package/dist/pem.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{categorizePemBlocks
|
|
1
|
+
import { categorizePemBlocks, categorizePemBlocksOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow } from "./pem/pem.js";
|
|
2
|
+
export { categorizePemBlocks, categorizePemBlocksOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow };
|
package/dist/pkcs/pfx.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Pbes2EncryptionOptions } from "../internal/crypto/pbes2.js";
|
|
2
1
|
import { ErrorResult, Micro509Error } from "../result/result.js";
|
|
2
|
+
import { EncryptedPkcs8Options } from "../keys/keys.js";
|
|
3
3
|
import { ParsedCertificate } from "../x509/parse.js";
|
|
4
4
|
import { ParsePkcs12MacDataErrorCode, ParsePkcs12MacDataFailure, ParsePkcs12MacDataResult, ParsedPkcs12MacData, Pkcs12MacOptions, createPkcs12MacData, parsePkcs12MacData, parsePkcs12MacDataOrThrow } from "./pkcs12-mac.js";
|
|
5
5
|
|
|
@@ -40,8 +40,8 @@ interface CreatePfxInput {
|
|
|
40
40
|
/** PKCS#12 MAC integrity settings. Omit to skip MAC generation. */
|
|
41
41
|
readonly mac?: Pkcs12MacOptions;
|
|
42
42
|
}
|
|
43
|
-
/** PBES2 encryption settings for PFX key-bag protection. Alias of {@linkcode
|
|
44
|
-
type PfxEncryptionOptions =
|
|
43
|
+
/** PBES2 encryption settings for PFX key-bag protection. Alias of {@linkcode EncryptedPkcs8Options}. */
|
|
44
|
+
type PfxEncryptionOptions = EncryptedPkcs8Options;
|
|
45
45
|
/** Options for {@linkcode parsePfxDer} and {@linkcode parsePfxPem}. */
|
|
46
46
|
interface ParsePfxOptions {
|
|
47
47
|
/** Password used to decrypt PBES2-encrypted ContentInfo entries. Also used for MAC verification when `macPassword` is omitted. */
|
|
@@ -199,5 +199,4 @@ declare function parsePfxDer(der: Uint8Array, options?: ParsePfxOptions): Promis
|
|
|
199
199
|
*/
|
|
200
200
|
declare function parsePfxPem(pem: string, options?: ParsePfxOptions): Promise<ParsePfxResult>;
|
|
201
201
|
//#endregion
|
|
202
|
-
export { CreatePfxErrorCode, CreatePfxFailure, CreatePfxInput, CreatePfxResult, ParsePfxErrorCode, ParsePfxFailure, ParsePfxOptions, ParsePfxResult, type ParsePkcs12MacDataErrorCode, type ParsePkcs12MacDataFailure, type ParsePkcs12MacDataResult, ParsedPfx, ParsedPfxAttribute, ParsedPfxBag, ParsedPfxBagAttributes, type ParsedPkcs12MacData, PfxBagAttributesInput, PfxCertificateBagInput, PfxCertificateSource, PfxEncryptionOptions, PfxMaterial, PfxPrivateKeyBagInput, PfxPrivateKeySource, type Pkcs12MacOptions, createPfx, type createPkcs12MacData, parsePfxDer, parsePfxPem, type parsePkcs12MacData, type parsePkcs12MacDataOrThrow };
|
|
203
|
-
//# sourceMappingURL=pfx.d.ts.map
|
|
202
|
+
export { CreatePfxErrorCode, CreatePfxFailure, CreatePfxInput, CreatePfxResult, ParsePfxErrorCode, ParsePfxFailure, ParsePfxOptions, ParsePfxResult, type ParsePkcs12MacDataErrorCode, type ParsePkcs12MacDataFailure, type ParsePkcs12MacDataResult, ParsedPfx, ParsedPfxAttribute, ParsedPfxBag, ParsedPfxBagAttributes, type ParsedPkcs12MacData, PfxBagAttributesInput, PfxCertificateBagInput, PfxCertificateSource, PfxEncryptionOptions, PfxMaterial, PfxPrivateKeyBagInput, PfxPrivateKeySource, type Pkcs12MacOptions, createPfx, type createPkcs12MacData, parsePfxDer, parsePfxPem, type parsePkcs12MacData, type parsePkcs12MacDataOrThrow };
|