micro509 0.7.2 → 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/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/x509/parse.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ErrorResult, Micro509Error } from "../result/result.js";
|
|
2
|
+
import { ImportKeyResult, PublicKeyImportInput } from "../keys/keys.js";
|
|
2
3
|
import { NameFieldKey } from "./name.js";
|
|
3
4
|
import { AuthorityInformationAccess, BasicConstraints, CertificatePolicies, DistributionPointReason, ExtendedKeyUsage, GeneralName, GeneralSubtree, InhibitAnyPolicy, KeyUsage, NameConstraints, ParsedBitFlags, ParsedNameConstraintForm, PolicyConstraints, PolicyMappings, SubjectAltName } from "./extensions.js";
|
|
4
5
|
|
|
@@ -7,6 +8,7 @@ import { AuthorityInformationAccess, BasicConstraints, CertificatePolicies, Dist
|
|
|
7
8
|
type ParseCertificateErrorCode = "malformed";
|
|
8
9
|
/** Structured failure payload for certificate parsing. */
|
|
9
10
|
interface ParseCertificateFailure extends Micro509Error<ParseCertificateErrorCode> {
|
|
11
|
+
/** Always `false` for failures. */
|
|
10
12
|
readonly ok: false;
|
|
11
13
|
}
|
|
12
14
|
/** Success-or-failure result from {@linkcode parseCertificateDer} / {@linkcode parseCertificatePem}. */
|
|
@@ -18,6 +20,7 @@ type ParseCertificateResult<TMap extends ExtensionDecoderMap = Record<never, nev
|
|
|
18
20
|
type ParseCertificateSigningRequestErrorCode = "malformed";
|
|
19
21
|
/** Structured failure payload for CSR parsing. */
|
|
20
22
|
interface ParseCertificateSigningRequestFailure extends Micro509Error<ParseCertificateSigningRequestErrorCode> {
|
|
23
|
+
/** Always `false` for failures. */
|
|
21
24
|
readonly ok: false;
|
|
22
25
|
}
|
|
23
26
|
/**
|
|
@@ -306,6 +309,18 @@ interface ParsedCertificateSigningRequest<TMap extends ExtensionDecoderMap = Rec
|
|
|
306
309
|
readonly decodedExtensionMap?: DecodedExtensionMap<TMap>;
|
|
307
310
|
}
|
|
308
311
|
/**
|
|
312
|
+
* Throwing core for {@linkcode parseCertificateDer}.
|
|
313
|
+
*
|
|
314
|
+
* Decodes a DER-encoded X.509 certificate into a {@linkcode ParsedCertificate},
|
|
315
|
+
* throwing on malformed input. All built-in extensions (basicConstraints,
|
|
316
|
+
* keyUsage, subjectAltNames, etc.) are decoded automatically.\
|
|
317
|
+
* Pass {@linkcode ParseOptions} to also decode custom extensions.
|
|
318
|
+
*
|
|
319
|
+
* @param der Raw DER bytes of an X.509 certificate.
|
|
320
|
+
* @param options Custom extension decoders to apply during parsing.
|
|
321
|
+
*/
|
|
322
|
+
declare function parseCertificateDerOrThrow<TMap extends ExtensionDecoderMap = Record<never, never>>(der: Uint8Array, options?: ParseOptions<TMap>): ParsedCertificate<TMap>;
|
|
323
|
+
/**
|
|
309
324
|
* Decode a DER-encoded X.509 certificate into a {@linkcode ParsedCertificate}.
|
|
310
325
|
*
|
|
311
326
|
* @example
|
|
@@ -328,6 +343,25 @@ declare function parseCertificateDer<TMap extends ExtensionDecoderMap = Record<n
|
|
|
328
343
|
* Expects a single `-----BEGIN CERTIFICATE-----` block. For bundles
|
|
329
344
|
* containing multiple certificates, use {@linkcode parseCertificateChainPem}.
|
|
330
345
|
*
|
|
346
|
+
* @example
|
|
347
|
+
* Throws on malformed input. For a typed failure instead, use the
|
|
348
|
+
* Result-returning {@linkcode parseCertificatePem}.
|
|
349
|
+
*
|
|
350
|
+
* ```ts
|
|
351
|
+
* const certificate = parseCertificatePemOrThrow(pemString); // throws if malformed
|
|
352
|
+
* console.log(certificate.issuer.values.organization); // "Let's Encrypt"
|
|
353
|
+
* ```
|
|
354
|
+
*
|
|
355
|
+
* @param pem PEM string with a CERTIFICATE block.
|
|
356
|
+
* @param options Custom extension decoders to apply during parsing.
|
|
357
|
+
*/
|
|
358
|
+
declare function parseCertificatePemOrThrow<TMap extends ExtensionDecoderMap = Record<never, never>>(pem: string, options?: ParseOptions<TMap>): ParsedCertificate<TMap>;
|
|
359
|
+
/**
|
|
360
|
+
* Decode a PEM-encoded X.509 certificate into a {@linkcode ParsedCertificate}.
|
|
361
|
+
*
|
|
362
|
+
* Expects a single `-----BEGIN CERTIFICATE-----` block. For bundles
|
|
363
|
+
* containing multiple certificates, use {@linkcode parseCertificateChainPem}.
|
|
364
|
+
*
|
|
331
365
|
* @param pem PEM string with a CERTIFICATE block.
|
|
332
366
|
* @param options Custom extension decoders to apply during parsing.
|
|
333
367
|
*/
|
|
@@ -347,6 +381,13 @@ declare function parseCertificateChainPem<TMap extends ExtensionDecoderMap = Rec
|
|
|
347
381
|
* @param der Raw DER bytes of a PKCS#10 certificate signing request.
|
|
348
382
|
* @param options Custom extension decoders to apply during parsing.
|
|
349
383
|
*/
|
|
384
|
+
declare function parseCertificateSigningRequestDerOrThrow<TMap extends ExtensionDecoderMap = Record<never, never>>(der: Uint8Array, options?: ParseOptions<TMap>): ParsedCertificateSigningRequest<TMap>;
|
|
385
|
+
/**
|
|
386
|
+
* Decode a DER-encoded PKCS#10 CSR into a {@linkcode ParsedCertificateSigningRequest}.
|
|
387
|
+
*
|
|
388
|
+
* @param der Raw DER bytes of a PKCS#10 certificate signing request.
|
|
389
|
+
* @param options Custom extension decoders to apply during parsing.
|
|
390
|
+
*/
|
|
350
391
|
declare function parseCertificateSigningRequestDer<TMap extends ExtensionDecoderMap = Record<never, never>>(der: Uint8Array, options?: ParseOptions<TMap>): ParseCertificateSigningRequestResult<TMap>;
|
|
351
392
|
/**
|
|
352
393
|
* Decode a PEM-encoded PKCS#10 CSR into a {@linkcode ParsedCertificateSigningRequest}.
|
|
@@ -354,8 +395,50 @@ declare function parseCertificateSigningRequestDer<TMap extends ExtensionDecoder
|
|
|
354
395
|
* @param pem PEM string with a CERTIFICATE REQUEST block.
|
|
355
396
|
* @param options Custom extension decoders to apply during parsing.
|
|
356
397
|
*/
|
|
398
|
+
declare function parseCertificateSigningRequestPemOrThrow<TMap extends ExtensionDecoderMap = Record<never, never>>(pem: string, options?: ParseOptions<TMap>): ParsedCertificateSigningRequest<TMap>;
|
|
399
|
+
/**
|
|
400
|
+
* Decode a PEM-encoded PKCS#10 CSR into a {@linkcode ParsedCertificateSigningRequest}.
|
|
401
|
+
*
|
|
402
|
+
* @param pem PEM string with a CERTIFICATE REQUEST block.
|
|
403
|
+
* @param options Custom extension decoders to apply during parsing.
|
|
404
|
+
*/
|
|
357
405
|
declare function parseCertificateSigningRequestPem<TMap extends ExtensionDecoderMap = Record<never, never>>(pem: string, options?: ParseOptions<TMap>): ParseCertificateSigningRequestResult<TMap>;
|
|
358
406
|
/**
|
|
407
|
+
* Import the subject public key of a parsed certificate or CSR as a WebCrypto `CryptoKey`.
|
|
408
|
+
*
|
|
409
|
+
* The key algorithm — and, for EC keys, the curve — is inferred from the
|
|
410
|
+
* SubjectPublicKeyInfo's own AlgorithmIdentifier (the same resolution
|
|
411
|
+
* {@linkcode importSpkiDerOrThrow} applies when no algorithm is given), so
|
|
412
|
+
* callers never map {@linkcode ParsedCertificate.publicKeyAlgorithmOid} /
|
|
413
|
+
* {@linkcode ParsedCertificate.publicKeyParametersOid} by hand.\
|
|
414
|
+
* RSA keys import with the default `pkcs1-v1_5`/`SHA-256` parameters (a plain
|
|
415
|
+
* `rsaEncryption` SPKI encodes neither padding scheme nor hash); pass
|
|
416
|
+
* `algorithm` to choose other RSA parameters or to assert an expected
|
|
417
|
+
* algorithm.
|
|
418
|
+
*
|
|
419
|
+
* @param parsed Parsed certificate or CSR whose subject public key to import.
|
|
420
|
+
* @param algorithm Optional expected algorithm; must match the key contents when given.
|
|
421
|
+
* @returns Extractable `CryptoKey` with `verify` usage.
|
|
422
|
+
*
|
|
423
|
+
* @throws {Error} If the SubjectPublicKeyInfo is malformed, encodes an
|
|
424
|
+
* unsupported algorithm, or doesn't match `algorithm`
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```ts
|
|
428
|
+
* const parsed = parseCertificatePemOrThrow(pem);
|
|
429
|
+
* const publicKey = await getSubjectPublicKeyOrThrow(parsed);
|
|
430
|
+
* ```
|
|
431
|
+
*
|
|
432
|
+
* @see {@linkcode getSubjectPublicKey} for the non-throwing variant
|
|
433
|
+
*/
|
|
434
|
+
declare function getSubjectPublicKeyOrThrow<TMap extends ExtensionDecoderMap = Record<never, never>>(parsed: ParsedCertificate<TMap> | ParsedCertificateSigningRequest<TMap>, algorithm?: PublicKeyImportInput): Promise<CryptoKey>;
|
|
435
|
+
/**
|
|
436
|
+
* Import the subject public key of a parsed certificate or CSR as a WebCrypto `CryptoKey`.
|
|
437
|
+
*
|
|
438
|
+
* @see `getSubjectPublicKeyOrThrow` for the throwing variant
|
|
439
|
+
*/
|
|
440
|
+
declare function getSubjectPublicKey<TMap extends ExtensionDecoderMap = Record<never, never>>(parsed: ParsedCertificate<TMap> | ParsedCertificateSigningRequest<TMap>, algorithm?: PublicKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
441
|
+
/**
|
|
359
442
|
* Find a raw extension by OID within a parsed extension list.
|
|
360
443
|
*
|
|
361
444
|
* @param extensions Extension list from a {@linkcode ParsedCertificate} or CSR.
|
|
@@ -386,5 +469,4 @@ declare function decodeExtensions(extensions: readonly ParsedExtension[], decode
|
|
|
386
469
|
*/
|
|
387
470
|
declare function decodeExtensionMap<TMap extends ExtensionDecoderMap>(extensions: readonly ParsedExtension[], decoderMap: TMap): DecodedExtensionMap<TMap>;
|
|
388
471
|
//#endregion
|
|
389
|
-
export { DecodedExtensionMap, DecodedExtensionValue, ExtensionDecoder, ExtensionDecoderMap, ParseCertificateErrorCode, ParseCertificateFailure, ParseCertificateResult, ParseCertificateSigningRequestErrorCode, ParseCertificateSigningRequestFailure, ParseCertificateSigningRequestResult, ParseOptions, type ParsedBitFlags, ParsedCertificate, ParsedCertificateSigningRequest, ParsedDistributionPoint, ParsedDistributionPointName, ParsedExtension, ParsedIssuingDistributionPoint, ParsedName, ParsedNameAttribute, ParsedRelativeDistinguishedName, decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, findExtension, parseCertificateChainPem, parseCertificateDer, parseCertificatePem, parseCertificateSigningRequestDer, parseCertificateSigningRequestPem };
|
|
390
|
-
//# sourceMappingURL=parse.d.ts.map
|
|
472
|
+
export { DecodedExtensionMap, DecodedExtensionValue, ExtensionDecoder, ExtensionDecoderMap, ParseCertificateErrorCode, ParseCertificateFailure, ParseCertificateResult, ParseCertificateSigningRequestErrorCode, ParseCertificateSigningRequestFailure, ParseCertificateSigningRequestResult, ParseOptions, type ParsedBitFlags, ParsedCertificate, ParsedCertificateSigningRequest, ParsedDistributionPoint, ParsedDistributionPointName, ParsedExtension, ParsedIssuingDistributionPoint, ParsedName, ParsedNameAttribute, ParsedRelativeDistinguishedName, decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, findExtension, getSubjectPublicKey, getSubjectPublicKeyOrThrow, parseCertificateChainPem, parseCertificateDer, parseCertificateDerOrThrow, parseCertificatePem, parseCertificatePemOrThrow, parseCertificateSigningRequestDer, parseCertificateSigningRequestDerOrThrow, parseCertificateSigningRequestPem, parseCertificateSigningRequestPemOrThrow };
|