micro509 0.11.0 → 0.13.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 +17 -3
- package/dist/der/der.d.ts +127 -0
- package/dist/der/der.js +171 -0
- package/dist/der/der.js.map +1 -0
- package/dist/der.d.ts +4 -0
- package/dist/der.js +4 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/internal/asn1/asn1.d.ts +20 -0
- package/dist/internal/asn1/asn1.js +60 -28
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/der.d.ts +171 -0
- package/dist/internal/asn1/der.js +101 -36
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js +22 -0
- package/dist/internal/asn1/oids2.js +9 -2
- package/dist/internal/asn1/oids2.js.map +1 -1
- package/dist/internal/shared/dn.js +143 -13
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/rfc3454-tables.js +1782 -0
- package/dist/internal/shared/rfc3454-tables.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +47 -15
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/internal/verify/policy-engine.js +86 -95
- package/dist/internal/verify/policy-engine.js.map +1 -1
- package/dist/internal/verify/verify-path.js +18 -14
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/extension-bits.js +1 -1
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/name-fields.js +19 -4
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/revocation/chain.js +110 -55
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.js +2 -2
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.js +2 -2
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/verify/verify.d.ts +14 -1
- package/dist/verify/verify.js +39 -32
- package/dist/verify/verify.js.map +1 -1
- package/dist/x509/extensions.d.ts +1 -1
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.d.ts +3 -0
- package/dist/x509/fingerprint.js +3 -0
- package/dist/x509/fingerprint.js.map +1 -1
- package/dist/x509/name-text.d.ts +50 -0
- package/dist/x509/name-text.js +111 -0
- package/dist/x509/name-text.js.map +1 -0
- package/dist/x509/parse.d.ts +3 -0
- package/dist/x509/parse.js +10 -1
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +2 -1
- package/dist/x509.js +2 -1
- package/package.json +46 -25
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions.js","names":["_exhaustive"],"sources":["../../src/x509/extensions.ts"],"sourcesContent":["/**\n * Typed certificate and CSR extension model plus ASN.1 encoder helpers.\n *\n * Defines input types for every supported X.509v3 extension (RFC 5280) and\n * the DER encoders consumed by certificate and CSR builder flows.\n *\n * @module\n */\n\nimport { hexToBytes } from '#micro509/internal/asn1/asn1';\nimport {\n\tbool,\n\tconcatBytes,\n\tDEFAULT_MAX_DER_DEPTH,\n\texplicitContext,\n\tia5String,\n\timplicitConstructedContext,\n\timplicitPrimitiveContext,\n\tintegerFromNumber,\n\tobjectIdentifier,\n\toctetString,\n\treadElement,\n\treadRootElement,\n\treadSequenceChildren,\n\tsequence,\n\ttlv,\n\tutf8String,\n} from '#micro509/internal/asn1/der';\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport { sha1 } from '#micro509/internal/crypto/hash';\nimport { parseIpAddressToBytes } from '#micro509/internal/shared/ip';\nimport {\n\tencodeDistributionPointReasonFlagsContent,\n\tencodeKeyUsageExtension,\n} from '#micro509/internal/x509/extension-bits';\nimport type {\n\tExtensionDefinition,\n\tExtensionRegistryContext,\n} from '#micro509/internal/x509/extension-registry';\nimport {\n\tAUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION,\n\tAUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\tBASIC_CONSTRAINTS_EXTENSION_DEFINITION,\n\tCERTIFICATE_POLICIES_EXTENSION_DEFINITION,\n\tCRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION,\n\tEXTENDED_KEY_USAGE_EXTENSION_DEFINITION,\n\tgetExtensionDefinition,\n\tINHIBIT_ANY_POLICY_EXTENSION_DEFINITION,\n\tKEY_USAGE_EXTENSION_DEFINITION,\n\tNAME_CONSTRAINTS_EXTENSION_DEFINITION,\n\tPOLICY_CONSTRAINTS_EXTENSION_DEFINITION,\n\tPOLICY_MAPPINGS_EXTENSION_DEFINITION,\n\tSUBJECT_ALT_NAME_EXTENSION_DEFINITION,\n\tSUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n} from '#micro509/internal/x509/extension-registry';\nimport type { RelativeDistinguishedNameInput } from '#micro509/x509/name';\nimport { encodeRelativeDistinguishedName } from '#micro509/x509/name';\n\nexport type {\n\tNameAttribute,\n\tNameFieldKey,\n\tRelativeDistinguishedNameInput,\n} from '#micro509/x509/name';\n\n/**\n * A decoded BIT STRING flag set.\n *\n * `flags` contains the recognized flag values with any non-zero padding bits\n * masked out. `nonZeroPadding` is `true` when the original BIT STRING encoding\n * had non-zero bits in positions that DER (X.690 §11.2.2) requires to be zero.\n * Verification layers can use this signal to reject non-conformant encodings.\n */\nexport interface ParsedBitFlags<T extends string> {\n\t/** Decoded flag values, padding bits masked. */\n\treadonly flags: readonly T[];\n\t/** `true` when the original encoding had non-zero padding bits (DER violation). */\n\treadonly nonZeroPadding: boolean;\n}\n\n/**\n * RFC 5280 §4.2.1.3 Key Usage bit flag.\n *\n * Each value corresponds to one bit in the KeyUsage BIT STRING.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.3 RFC 5280 §4.2.1.3}\n */\nexport type KeyUsage =\n\t| 'digitalSignature'\n\t| 'nonRepudiation'\n\t| 'keyEncipherment'\n\t| 'dataEncipherment'\n\t| 'keyAgreement'\n\t| 'keyCertSign'\n\t| 'cRLSign'\n\t| 'encipherOnly'\n\t| 'decipherOnly';\n\n/**\n * RFC 5280 §4.2.1.6 Subject Alternative Name / GeneralName.\n *\n * Discriminated union keyed on `type`.\n *\n * The `'unknown'` variant preserves unrecognized {@linkcode GeneralName} tags for round-trip fidelity.\n */\nexport type SubjectAltName =\n\t| {\n\t\t\t/** DNS hostname (dNSName [2]). */\n\t\t\treadonly type: 'dns';\n\t\t\t/** Fully-qualified domain name, e.g. `\"example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** IP address (iPAddress [7]). */\n\t\t\treadonly type: 'ip';\n\t\t\t/** Dotted-decimal IPv4 or colon-hex IPv6 string. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** Email address (rfc822Name [1]). */\n\t\t\treadonly type: 'email';\n\t\t\t/** RFC 822 mailbox, e.g. `\"admin@example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** URI (uniformResourceIdentifier [6]). */\n\t\t\treadonly type: 'uri';\n\t\t\t/** Absolute URI string. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** SRV-ID otherName (id-on-dnsSRV). */\n\t\t\treadonly type: 'srv';\n\t\t\t/** SRV service name, e.g. `\"_imaps.example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** X.500 directory name (directoryName [4]). */\n\t\t\treadonly type: 'directoryName';\n\t\t\t/** Hex-encoded DER of the Name SEQUENCE. */\n\t\t\treadonly derHex: string;\n\t }\n\t| {\n\t\t\t/** Unrecognized {@linkcode GeneralName} tag, preserved as raw bytes. */\n\t\t\treadonly type: 'unknown';\n\t\t\t/** ASN.1 context tag number. */\n\t\t\treadonly tag: number;\n\t\t\t/** Raw content bytes of the element. */\n\t\t\treadonly value: Uint8Array;\n\t };\n\n/** Alias for {@linkcode SubjectAltName} — used where RFC 5280 says \"GeneralName\". */\nexport type GeneralName = SubjectAltName;\n\n/**\n * Revocation reason flags for CRL Distribution Points and Issuing Distribution Points\n * (RFC 5280 §4.2.1.13, §5.2.5).\n */\nexport type DistributionPointReason =\n\t| 'keyCompromise'\n\t| 'cACompromise'\n\t| 'affiliationChanged'\n\t| 'superseded'\n\t| 'cessationOfOperation'\n\t| 'certificateHold'\n\t| 'privilegeWithdrawn'\n\t| 'aACompromise';\n\n/**\n * Name component of a CRL Distribution Point (RFC 5280 §4.2.1.13).\n *\n * Supply exactly one of `fullName` or `relativeName`.\n */\nexport interface DistributionPointName {\n\t/** Absolute {@linkcode GeneralName}(s) identifying the distribution point (usually a URI). */\n\treadonly fullName?: readonly GeneralName[];\n\t/** Name relative to the issuer's DN; mutually exclusive with `fullName`. */\n\treadonly relativeName?: RelativeDistinguishedNameInput;\n}\n\n/**\n * Input for a single CRL Distribution Point (RFC 5280 §4.2.1.13).\n *\n * At least one of `distributionPoint` or `crlIssuer` must be provided.\n * The union enforces this constraint at the type level.\n */\nexport type DistributionPoint =\n\t| {\n\t\t\t/** Where to fetch the CRL (fullName or relativeName). */\n\t\t\treadonly distributionPoint: DistributionPointName;\n\t\t\t/** Revocation reason subset. Absent means all reasons. */\n\t\t\treadonly reasons?: readonly DistributionPointReason[];\n\t\t\t/** Entity that signed the CRL, when different from the cert issuer. */\n\t\t\treadonly crlIssuer?: readonly GeneralName[];\n\t }\n\t| {\n\t\t\t/** Where to fetch the CRL. Optional when `crlIssuer` is present. */\n\t\t\treadonly distributionPoint?: DistributionPointName;\n\t\t\t/** Revocation reason subset. Absent means all reasons. */\n\t\t\treadonly reasons?: readonly DistributionPointReason[];\n\t\t\t/** Entity that signed the CRL. Required when `distributionPoint` is absent. */\n\t\t\treadonly crlIssuer: readonly GeneralName[];\n\t };\n\n/** Base shape for Issuing Distribution Point (RFC 5280 §5.2.5) — no scope restriction. */\nexport interface IssuingDistributionPointBase {\n\t/** Where to fetch this CRL. */\n\treadonly distributionPoint?: DistributionPointName;\n\t/** Limits the CRL to these revocation reasons. Absent means all reasons. */\n\treadonly onlySomeReasons?: readonly DistributionPointReason[];\n\t/** When true, the CRL may contain entries from other CAs. Default false. */\n\treadonly indirectCrl?: boolean;\n\t/** Must be absent or false in this variant (no user-cert-only restriction). */\n\treadonly onlyContainsUserCerts?: false;\n\t/** Must be absent or false in this variant (no CA-cert-only restriction). */\n\treadonly onlyContainsCACerts?: false;\n\t/** When true, the CRL only covers attribute certificates. Default false. */\n\treadonly onlyContainsAttributeCerts?: boolean;\n}\n\n/** IDP scoped to end-entity (user) certificates only. Mutually exclusive with CA / attribute scopes. */\nexport interface IssuingDistributionPointForUserCerts\n\textends Omit<IssuingDistributionPointBase, 'onlyContainsUserCerts'> {\n\t/** This variant only covers end-entity certificates. */\n\treadonly onlyContainsUserCerts: true;\n\t/** Must be absent or false when the CRL is not CA-only. */\n\treadonly onlyContainsCACerts?: false;\n\t/** Must be absent or false when the CRL is not attribute-cert-only. */\n\treadonly onlyContainsAttributeCerts?: false;\n}\n\n/** IDP scoped to CA certificates only. Mutually exclusive with user / attribute scopes. */\nexport interface IssuingDistributionPointForCaCerts\n\textends Omit<IssuingDistributionPointBase, 'onlyContainsCACerts'> {\n\t/** Must be absent or false when the CRL is not user-cert-only. */\n\treadonly onlyContainsUserCerts?: false;\n\t/** This variant only covers CA certificates. */\n\treadonly onlyContainsCACerts: true;\n\t/** Must be absent or false when the CRL is not attribute-cert-only. */\n\treadonly onlyContainsAttributeCerts?: false;\n}\n\n/** IDP scoped to attribute certificates only. Mutually exclusive with user / CA scopes. */\nexport interface IssuingDistributionPointForAttributeCerts\n\textends Omit<IssuingDistributionPointBase, 'onlyContainsAttributeCerts'> {\n\t/** Must be absent or false when the CRL is not user-cert-only. */\n\treadonly onlyContainsUserCerts?: false;\n\t/** Must be absent or false when the CRL is not CA-only. */\n\treadonly onlyContainsCACerts?: false;\n\t/** This variant only covers attribute certificates. */\n\treadonly onlyContainsAttributeCerts: true;\n}\n\n/**\n * Input for the Issuing Distribution Point CRL extension (RFC 5280 §5.2.5).\n *\n * The union enforces that at most one of the `onlyContains*` flags is true.\n */\nexport type IssuingDistributionPoint =\n\t| IssuingDistributionPointBase\n\t| IssuingDistributionPointForUserCerts\n\t| IssuingDistributionPointForCaCerts\n\t| IssuingDistributionPointForAttributeCerts;\n\n/**\n * RFC 5280 §4.2.1.9 Basic Constraints.\n *\n * A certificate with `ca: true` may issue other certificates; `pathLength`\n * limits how many additional CAs may appear below it in the chain.\n */\nexport type BasicConstraints =\n\t| {\n\t\t\t/** End-entity certificate: not a CA. */\n\t\t\treadonly ca: false;\n\t\t\t/** Never present on end-entity certificates. */\n\t\t\treadonly pathLength?: undefined;\n\t }\n\t| {\n\t\t\t/** CA certificate: may issue other certificates. */\n\t\t\treadonly ca: true;\n\t\t\t/** Maximum number of intermediate CA certificates allowed below this CA. */\n\t\t\treadonly pathLength?: number;\n\t };\n\n/** A single certificate policy: an OID plus optional qualifiers. */\nexport interface PolicyInformation {\n\t/** Dotted-decimal OID of the policy (e.g. `\"2.23.140.1.2.1\"` for DV). */\n\treadonly policyIdentifier: string;\n\t/** Optional CPS URIs or user notices attached to this policy. */\n\treadonly policyQualifiers?: readonly PolicyQualifierInfo[];\n}\n\n/** RFC 5280 §4.2.1.4 — array of policy OIDs with optional qualifiers. */\nexport type CertificatePolicies = readonly {\n\t/** Dotted-decimal OID of the policy (e.g. `\"2.23.140.1.2.1\"` for DV). */\n\treadonly policyIdentifier: string;\n\t/** Optional CPS URIs or user notices attached to this policy. */\n\treadonly policyQualifiers?: readonly (\n\t\t| {\n\t\t\t\treadonly type: 'cps';\n\t\t\t\treadonly uri: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'userNotice';\n\t\t\t\treadonly noticeRef?: {\n\t\t\t\t\treadonly organization: string;\n\t\t\t\t\treadonly noticeNumbers: readonly number[];\n\t\t\t\t};\n\t\t\t\treadonly explicitText?: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'oid';\n\t\t\t\treadonly oid: string;\n\t\t\t\treadonly qualifierDer: Uint8Array;\n\t\t }\n\t)[];\n}[];\n\n/** CPS (Certification Practice Statement) URI policy qualifier. */\nexport interface CpsPolicyQualifierInfo {\n\t/** Discriminant for the `'cps'` qualifier variant. */\n\treadonly type: 'cps';\n\t/** URL of the Certification Practice Statement document. */\n\treadonly uri: string;\n}\n\n/** Reference to a numbered notice within an organization's practice statement. */\nexport interface PolicyNoticeReference {\n\t/** Organization name that published the notice. */\n\treadonly organization: string;\n\t/** One-based notice numbers within that organization's documentation. */\n\treadonly noticeNumbers: readonly number[];\n}\n\n/** UserNotice policy qualifier — human-readable notice text and/or a notice reference. */\nexport interface UserNoticePolicyQualifierInfo {\n\t/** Discriminant for the `'userNotice'` qualifier variant. */\n\treadonly type: 'userNotice';\n\t/** Pointer to a numbered notice in an organization's practice statement. */\n\treadonly noticeRef?: PolicyNoticeReference;\n\t/** Free-form text to display to relying parties. */\n\treadonly explicitText?: string;\n}\n\n/** Opaque policy qualifier identified by a custom OID, carried as raw DER. */\nexport interface CustomPolicyQualifierInfo {\n\t/** Discriminant for the custom-OID qualifier variant. */\n\treadonly type: 'oid';\n\t/** Dotted-decimal OID of the qualifier. */\n\treadonly oid: string;\n\t/** DER-encoded qualifier payload. */\n\treadonly qualifierDer: Uint8Array;\n}\n\n/** Discriminated union of all supported policy qualifier types. */\nexport type PolicyQualifierInfo =\n\t| CpsPolicyQualifierInfo\n\t| UserNoticePolicyQualifierInfo\n\t| CustomPolicyQualifierInfo;\n\n/** Maps a policy OID in the issuer's domain to an equivalent OID in the subject's domain. */\nexport interface PolicyMapping {\n\t/** Policy OID as defined by the issuing CA. Must not be anyPolicy. */\n\treadonly issuerDomainPolicy: string;\n\t/** Equivalent policy OID in the subject CA's domain. Must not be anyPolicy. */\n\treadonly subjectDomainPolicy: string;\n}\n\n/** RFC 5280 §4.2.1.5 — array of issuer-to-subject policy OID pairs. */\nexport type PolicyMappings = readonly {\n\t/** Policy OID as defined by the issuing CA. Must not be anyPolicy. */\n\treadonly issuerDomainPolicy: string;\n\t/** Equivalent policy OID in the subject CA's domain. Must not be anyPolicy. */\n\treadonly subjectDomainPolicy: string;\n}[];\n\n/**\n * RFC 5280 §4.2.1.11 Policy Constraints.\n *\n * At least one field must be present. Values are certificate-count\n * thresholds measured from the current certificate toward the end entity.\n */\nexport interface PolicyConstraints {\n\t/** After this many certificates, an acceptable policy must be in the path. */\n\treadonly requireExplicitPolicy?: number;\n\t/** After this many certificates, policy mapping is no longer allowed. */\n\treadonly inhibitPolicyMapping?: number;\n}\n\n/**\n * RFC 5280 §4.2.1.14 Inhibit anyPolicy.\n *\n * After `skipCerts` additional certificates in the path, the special\n * anyPolicy OID is no longer considered a match.\n */\nexport interface InhibitAnyPolicy {\n\t/** Number of additional certificates before anyPolicy stops being valid. */\n\treadonly skipCerts: number;\n}\n\n/**\n * Input for `createCertificate`, `createSelfSignedCertificate`,\n * and `createCertificateSigningRequest`.\n *\n * Every field is optional. Omitted extensions are not encoded. Built-in\n * extensions (SKI, AKI, basicConstraints defaults) are handled automatically\n * by the builder.\n */\nexport interface CertificateExtensionsInput {\n\t/** Subject Alternative Names (dns, ip, email, uri, srv, directoryName). */\n\treadonly subjectAltNames?: readonly SubjectAltName[];\n\t/** Key Usage flags (digitalSignature, keyCertSign, etc.). */\n\treadonly keyUsage?: readonly KeyUsage[];\n\t/** Basic Constraints (CA flag + optional pathLength). Defaults to `{ ca: false }` for certs. */\n\treadonly basicConstraints?: BasicConstraints;\n\t/** Extended Key Usage purposes (serverAuth, clientAuth, etc.). */\n\treadonly extendedKeyUsage?: readonly ExtendedKeyUsage[];\n\t/** Name Constraints — permitted and/or excluded subtrees. */\n\treadonly nameConstraints?: NameConstraints;\n\t/** Certificate Policies with optional qualifiers. */\n\treadonly certificatePolicies?: CertificatePolicies;\n\t/** Policy Mappings between issuer and subject policy domains. */\n\treadonly policyMappings?: PolicyMappings;\n\t/** Policy Constraints (requireExplicitPolicy / inhibitPolicyMapping thresholds). */\n\treadonly policyConstraints?: PolicyConstraints;\n\t/** Inhibit anyPolicy skip-certs threshold. */\n\treadonly inhibitAnyPolicy?: InhibitAnyPolicy;\n\t/** Authority Information Access — OCSP responder and CA issuer URIs. */\n\treadonly authorityInfoAccess?: readonly AuthorityInformationAccess[];\n\t/** CRL Distribution Points — where to check revocation status. */\n\treadonly crlDistributionPoints?: readonly DistributionPoint[];\n\t/** Arbitrary extensions not covered by the built-in fields. */\n\treadonly customExtensions?: readonly CustomExtension[];\n}\n\n/** An extension not covered by the typed fields in {@linkcode CertificateExtensionsInput}. */\nexport interface CustomExtension {\n\t/** Dotted-decimal OID of the extension. */\n\treadonly oid: string;\n\t/** Pre-encoded DER content for the extnValue OCTET STRING. */\n\treadonly value: Uint8Array;\n\t/** Whether the extension is critical. Default `false`. */\n\treadonly critical?: boolean;\n}\n\n// Name constraints (RFC 5280 §4.2.1.10)\n\n/**\n * A name form used as a constraint base in namEConstraints.\n * Distinct from {@linkcode SubjectAltName} because IP constraints carry\n * address + mask bytes (8 for IPv4, 32 for IPv6) rather than bare addresses.\n */\nexport type NameConstraintForm =\n\t| {\n\t\t\t/** DNS domain constraint (dNSName [2]). */\n\t\t\treadonly type: 'dns';\n\t\t\t/** Domain suffix, e.g. `\".example.com\"` or `\"example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** Email constraint (rfc822Name [1]). */\n\t\t\treadonly type: 'email';\n\t\t\t/** Email domain or full address pattern. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** URI constraint (uniformResourceIdentifier [6]). */\n\t\t\treadonly type: 'uri';\n\t\t\t/** Host or domain component of a URI. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** IP range constraint (iPAddress [7]). */\n\t\t\treadonly type: 'ip';\n\t\t\t/** Network address bytes (4 for IPv4, 16 for IPv6). */\n\t\t\treadonly addressBytes: Uint8Array;\n\t\t\t/** Subnet mask bytes (same length as addressBytes). */\n\t\t\treadonly maskBytes: Uint8Array;\n\t }\n\t| {\n\t\t\t/** Directory name constraint (directoryName [4]). */\n\t\t\treadonly type: 'directoryName';\n\t\t\t/** Hex-encoded DER of the Name SEQUENCE. */\n\t\t\treadonly derHex: string;\n\t };\n\n/**\n * Name constraint forms parsed from DER but not supported for encoding or\n * validation. Preserved for diagnostic round-tripping.\n */\nexport type UnsupportedNameConstraintForm =\n\t| {\n\t\t\t/** otherName [0] — raw bytes. */\n\t\t\treadonly type: 'otherName';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** x400Address [3] — raw bytes. */\n\t\t\treadonly type: 'x400Address';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** ediPartyName [5] — raw bytes. */\n\t\t\treadonly type: 'ediPartyName';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** registeredID [8] — decoded OID string. */\n\t\t\treadonly type: 'registeredID';\n\t\t\treadonly value: string;\n\t };\n\n/** Union of supported and unsupported name constraint forms as produced by parsing. */\nexport type ParsedNameConstraintForm =\n\t| {\n\t\t\treadonly type: 'dns';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'email';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'uri';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'ip';\n\t\t\treadonly addressBytes: Uint8Array;\n\t\t\treadonly maskBytes: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'directoryName';\n\t\t\treadonly derHex: string;\n\t }\n\t| {\n\t\t\treadonly type: 'otherName';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'x400Address';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'ediPartyName';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'registeredID';\n\t\t\treadonly value: string;\n\t };\n\n/** A single subtree entry in a Name Constraints permitted/excluded list. */\nexport interface GeneralSubtree<\n\tTForm extends ParsedNameConstraintForm =\n\t\t| {\n\t\t\t\treadonly type: 'dns';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'email';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'uri';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'ip';\n\t\t\t\treadonly addressBytes: Uint8Array;\n\t\t\t\treadonly maskBytes: Uint8Array;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'directoryName';\n\t\t\t\treadonly derHex: string;\n\t\t },\n> {\n\t/** The name form that defines this constraint boundary. */\n\treadonly base: TForm;\n}\n\n/**\n * RFC 5280 §4.2.1.10 Name Constraints.\n *\n * A CA certificate may restrict the namespace of all subject names in\n * subsequent certificates in the path.\n */\nexport interface NameConstraints<\n\tTForm extends ParsedNameConstraintForm =\n\t\t| {\n\t\t\t\treadonly type: 'dns';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'email';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'uri';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'ip';\n\t\t\t\treadonly addressBytes: Uint8Array;\n\t\t\t\treadonly maskBytes: Uint8Array;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'directoryName';\n\t\t\t\treadonly derHex: string;\n\t\t },\n> {\n\t/** Names that MUST fall within these subtrees to be valid. */\n\treadonly permittedSubtrees?: readonly GeneralSubtree<TForm>[];\n\t/** Names that MUST NOT fall within these subtrees. Takes precedence over permitted. */\n\treadonly excludedSubtrees?: readonly GeneralSubtree<TForm>[];\n}\n\n/** Well-known AIA access methods: OCSP responder or CA issuer certificate. */\nexport type KnownAuthorityInfoAccessMethod = 'ocsp' | 'caIssuers';\n\n/** AIA access method identified by a custom OID not in the well-known set. */\nexport interface CustomAuthorityInfoAccessMethod {\n\t/** Discriminant for the custom-OID access method variant. */\n\treadonly type: 'oid';\n\t/** Dotted-decimal OID of the access method. */\n\treadonly value: string;\n}\n\n/** AIA access method — either a well-known string or a custom OID. */\nexport type AuthorityInfoAccessMethod =\n\t| KnownAuthorityInfoAccessMethod\n\t| CustomAuthorityInfoAccessMethod;\n\n/** A single entry in the Authority Information Access extension (RFC 5280 §4.2.2.1). */\nexport interface AuthorityInformationAccess {\n\t/** Access method (`'ocsp'`, `'caIssuers'`, or custom OID). */\n\treadonly method:\n\t\t| 'ocsp'\n\t\t| 'caIssuers'\n\t\t| {\n\t\t\t\treadonly type: 'oid';\n\t\t\t\treadonly value: string;\n\t\t };\n\t/** URI where the resource can be fetched. */\n\treadonly uri: string;\n}\n\n/** Well-known Extended Key Usage purpose strings (RFC 5280 §4.2.1.12). */\nexport type KnownExtendedKeyUsage =\n\t| 'serverAuth'\n\t| 'clientAuth'\n\t| 'codeSigning'\n\t| 'emailProtection'\n\t| 'timeStamping'\n\t| 'ocspSigning';\n\n/** Extended Key Usage purpose identified by a custom OID. */\nexport interface CustomExtendedKeyUsage {\n\t/** Discriminant for the custom-OID EKU variant. */\n\treadonly type: 'oid';\n\t/** Dotted-decimal OID of the usage purpose. */\n\treadonly value: string;\n}\n\n/** Extended Key Usage — either a well-known purpose string or a custom OID. */\nexport type ExtendedKeyUsage =\n\t| 'serverAuth'\n\t| 'clientAuth'\n\t| 'codeSigning'\n\t| 'emailProtection'\n\t| 'timeStamping'\n\t| 'ocspSigning'\n\t| {\n\t\t\treadonly type: 'oid';\n\t\t\treadonly value: string;\n\t };\n\n/** Map from well-known EKU names to their dotted-decimal OIDs. */\nconst EXTENDED_KEY_USAGE_OIDS: Record<KnownExtendedKeyUsage, string> = {\n\tserverAuth: OIDS.serverAuth,\n\tclientAuth: OIDS.clientAuth,\n\tcodeSigning: OIDS.codeSigning,\n\temailProtection: OIDS.emailProtection,\n\ttimeStamping: OIDS.timeStamping,\n\tocspSigning: OIDS.ocspSigning,\n};\n\n/** Map from well-known AIA method names to their dotted-decimal OIDs. */\nconst AUTHORITY_INFO_ACCESS_METHOD_OIDS: Record<KnownAuthorityInfoAccessMethod, string> = {\n\tocsp: OIDS.ocspAccessMethod,\n\tcaIssuers: OIDS.caIssuersAccessMethod,\n};\n\n/**\n * Build the v3 extensions block for a certificate.\n *\n * Automatically adds SKI, AKI (when issuer key is available), and\n * basicConstraints (defaults to `{ ca: false }`). Additional extensions\n * come from the caller's {@linkcode CertificateExtensionsInput}.\n *\n * @param subjectPublicKeyInfo DER-encoded SPKI of the subject.\n * @param issuerPublicKeyInfo DER-encoded SPKI of the issuer, or `undefined` for self-signed.\n * @param input Optional extension configuration.\n * @param subjectIsEmpty Whether the certificate subject DN is empty. When `true`, the\n * subjectAltName extension is marked critical per RFC 5280 §4.2.1.6.\n * @returns Array of DER-encoded Extension SEQUENCEs.\n */\nexport function buildCertificateExtensions(\n\tsubjectPublicKeyInfo: Uint8Array,\n\tissuerPublicKeyInfo: Uint8Array | undefined,\n\tinput: CertificateExtensionsInput | undefined,\n\tsubjectIsEmpty = false,\n): Uint8Array[] {\n\tconst extensions: Uint8Array[] = [];\n\tconst seen = new Set<string>();\n\tconst basicConstraints = input?.basicConstraints ?? { ca: false };\n\tpushKnownExtension(extensions, seen, BASIC_CONSTRAINTS_EXTENSION_DEFINITION, basicConstraints);\n\tpushKnownExtension(\n\t\textensions,\n\t\tseen,\n\t\tSUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\t\tbuildSubjectKeyIdentifier(subjectPublicKeyInfo),\n\t);\n\tif (issuerPublicKeyInfo !== undefined) {\n\t\tpushKnownExtension(\n\t\t\textensions,\n\t\t\tseen,\n\t\t\tAUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\t\t\tbuildSubjectKeyIdentifier(issuerPublicKeyInfo),\n\t\t);\n\t}\n\tappendConfiguredExtensions(extensions, seen, input, 'certificate', {\n\t\tincludeBasicConstraints: false,\n\t\tsubjectIsEmpty,\n\t});\n\treturn extensions;\n}\n\n/**\n * Build the extensions for a CSR's extensionRequest attribute.\n *\n * Unlike {@linkcode buildCertificateExtensions}, SKI/AKI are not auto-generated.\n *\n * @param input Optional extension configuration.\n * @returns Array of DER-encoded Extension SEQUENCEs.\n */\nexport function buildRequestedExtensions(\n\tinput: CertificateExtensionsInput | undefined,\n): Uint8Array[] {\n\tconst extensions: Uint8Array[] = [];\n\tconst seen = new Set<string>();\n\tappendConfiguredExtensions(extensions, seen, input, 'csr', { includeBasicConstraints: true });\n\treturn extensions;\n}\n\n/** Encode and push each configured extension from the input, enforcing no duplicates. */\nfunction appendConfiguredExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput | undefined,\n\tcontext: ExtensionRegistryContext,\n\toptions: {\n\t\treadonly includeBasicConstraints: boolean;\n\t\t/** When true, SAN is marked critical per RFC 5280 §4.2.1.6. */\n\t\treadonly subjectIsEmpty?: boolean;\n\t},\n): void {\n\tif (input === undefined) {\n\t\treturn;\n\t}\n\tappendConstraintExtensions(encoded, seen, input, options.includeBasicConstraints);\n\tappendIdentityExtensions(encoded, seen, input, options.subjectIsEmpty === true);\n\tappendPolicyExtensions(encoded, seen, input);\n\tappendAccessExtensions(encoded, seen, input);\n\tappendCustomExtensions(encoded, seen, input, context);\n}\n\nfunction appendConstraintExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n\tincludeBasicConstraints: boolean,\n): void {\n\tif (includeBasicConstraints && input.basicConstraints !== undefined) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tBASIC_CONSTRAINTS_EXTENSION_DEFINITION,\n\t\t\tinput.basicConstraints,\n\t\t);\n\t}\n\tif (input.keyUsage !== undefined && input.keyUsage.length > 0) {\n\t\tpushKnownExtension(encoded, seen, KEY_USAGE_EXTENSION_DEFINITION, input.keyUsage);\n\t}\n\tif (input.nameConstraints !== undefined) {\n\t\tpushKnownExtension(encoded, seen, NAME_CONSTRAINTS_EXTENSION_DEFINITION, input.nameConstraints);\n\t}\n}\n\nfunction appendIdentityExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n\tsubjectIsEmpty: boolean,\n): void {\n\tif (input.subjectAltNames !== undefined && input.subjectAltNames.length > 0) {\n\t\t// RFC 5280 §4.2.1.6: SAN MUST be critical when subject DN is empty.\n\t\tconst sanCritical = subjectIsEmpty ? true : undefined;\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tSUBJECT_ALT_NAME_EXTENSION_DEFINITION,\n\t\t\tinput.subjectAltNames,\n\t\t\tsanCritical,\n\t\t);\n\t}\n\tif (input.extendedKeyUsage !== undefined && input.extendedKeyUsage.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tEXTENDED_KEY_USAGE_EXTENSION_DEFINITION,\n\t\t\tinput.extendedKeyUsage,\n\t\t);\n\t}\n}\n\n/** Appends configured certificate-policy extensions while enforcing unique OIDs. */\nfunction appendPolicyExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n): void {\n\tif (input.certificatePolicies !== undefined && input.certificatePolicies.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tCERTIFICATE_POLICIES_EXTENSION_DEFINITION,\n\t\t\tinput.certificatePolicies,\n\t\t);\n\t}\n\tif (input.policyMappings !== undefined && input.policyMappings.length > 0) {\n\t\tpushKnownExtension(encoded, seen, POLICY_MAPPINGS_EXTENSION_DEFINITION, input.policyMappings);\n\t}\n\tif (input.policyConstraints !== undefined) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tPOLICY_CONSTRAINTS_EXTENSION_DEFINITION,\n\t\t\tinput.policyConstraints,\n\t\t);\n\t}\n\tif (input.inhibitAnyPolicy !== undefined) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tINHIBIT_ANY_POLICY_EXTENSION_DEFINITION,\n\t\t\tinput.inhibitAnyPolicy,\n\t\t);\n\t}\n}\n\nfunction appendAccessExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n): void {\n\tif (input.authorityInfoAccess !== undefined && input.authorityInfoAccess.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tAUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION,\n\t\t\tinput.authorityInfoAccess,\n\t\t);\n\t}\n\tif (input.crlDistributionPoints !== undefined && input.crlDistributionPoints.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tCRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION,\n\t\t\tinput.crlDistributionPoints,\n\t\t);\n\t}\n}\n\nfunction appendCustomExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n\tcontext: ExtensionRegistryContext,\n): void {\n\tif (input.customExtensions !== undefined) {\n\t\tfor (const extension of input.customExtensions) {\n\t\t\tconst knownDefinition = getExtensionDefinition(extension.oid);\n\t\t\tif (knownDefinition !== undefined && !knownDefinition.contexts.includes(context)) {\n\t\t\t\tthrow new Error(`Extension ${extension.oid} is not supported in ${context} context`);\n\t\t\t}\n\t\t\tpushExtension(\n\t\t\t\tencoded,\n\t\t\t\tseen,\n\t\t\t\textension.oid,\n\t\t\t\tnew Uint8Array(extension.value),\n\t\t\t\textension.critical ?? false,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/** Encode a known extension via its registry definition and push it. */\nfunction pushKnownExtension<TParsed, TInput>(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tdefinition: ExtensionDefinition<TParsed, TInput>,\n\tvalue: TInput,\n\tcritical = definition.defaultCritical,\n): void {\n\tpushExtension(encoded, seen, definition.oid, definition.encode(value), critical);\n}\n\n/**\n * Encode a single X.509 Extension SEQUENCE (OID + optional critical BOOLEAN + OCTET STRING).\n *\n * @param oid Dotted-decimal extension OID.\n * @param extnValue DER-encoded extension payload.\n * @param critical Whether to mark the extension as critical. Default `false`.\n */\nexport function encodeExtension(oid: string, extnValue: Uint8Array, critical = false): Uint8Array {\n\tconst fields = [objectIdentifier(oid)];\n\tif (critical) {\n\t\tfields.push(bool(true));\n\t}\n\tfields.push(octetString(extnValue));\n\treturn sequence(fields);\n}\n\n/**\n * DER-encode a {@linkcode BasicConstraints} value.\n *\n * @param input CA flag and optional pathLength.\n * @returns DER SEQUENCE suitable for wrapping in an Extension OCTET STRING.\n */\nexport function encodeBasicConstraints(input: BasicConstraints): Uint8Array {\n\tconst fields: Uint8Array[] = [];\n\tif (input.ca) {\n\t\tfields.push(bool(true));\n\t}\n\tif (input.pathLength !== undefined) {\n\t\tif (!input.ca) {\n\t\t\tthrow new Error('pathLength requires ca=true');\n\t\t}\n\t\tfields.push(integerFromNumber(input.pathLength));\n\t}\n\treturn sequence(fields);\n}\n\n/**\n * DER-encode a Key Usage BIT STRING from an array of {@linkcode KeyUsage} flags.\n *\n * @param usages Flags to set in the bit string.\n */\nexport function encodeKeyUsage(usages: readonly KeyUsage[]): Uint8Array {\n\treturn encodeKeyUsageExtension(usages);\n}\n\n/**\n * DER-encode a single {@linkcode SubjectAltName} GeneralName element.\n *\n * @param value The SAN entry to encode.\n */\nexport function encodeSubjectAltName(value: SubjectAltName): Uint8Array {\n\tswitch (value.type) {\n\t\tcase 'dns':\n\t\t\treturn implicitPrimitiveContext(2, new TextEncoder().encode(value.value));\n\t\tcase 'email':\n\t\t\treturn implicitPrimitiveContext(1, new TextEncoder().encode(value.value));\n\t\tcase 'uri':\n\t\t\treturn implicitPrimitiveContext(6, new TextEncoder().encode(value.value));\n\t\tcase 'srv':\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tsequence([objectIdentifier(OIDS.idOnDnsSrv), explicitContext(0, ia5String(value.value))]),\n\t\t\t);\n\t\tcase 'ip':\n\t\t\treturn implicitPrimitiveContext(7, encodeIpAddress(value.value));\n\t\tcase 'directoryName':\n\t\t\treturn implicitConstructedContext(4, extractDirectoryNameContent(value.derHex));\n\t\tcase 'unknown':\n\t\t\treturn tlv(value.tag, value.value);\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = value;\n\t\t\tthrow new Error(`Unhandled SubjectAltName type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/**\n * DER-encode an Extended Key Usage SEQUENCE OF OIDs.\n *\n * @param usages EKU purposes to encode.\n */\nexport function encodeExtendedKeyUsage(usages: readonly ExtendedKeyUsage[]): Uint8Array {\n\treturn sequence(usages.map((usage) => objectIdentifier(getExtendedKeyUsageOid(usage))));\n}\n\n/**\n * DER-encode an Authority Information Access SEQUENCE.\n *\n * @param entries AIA entries (OCSP, caIssuers, or custom) to encode.\n */\nexport function encodeAuthorityInfoAccess(\n\tentries: readonly AuthorityInformationAccess[],\n): Uint8Array {\n\treturn sequence(\n\t\tentries.map((entry) =>\n\t\t\tsequence([\n\t\t\t\tobjectIdentifier(getAuthorityInfoAccessMethodOid(entry.method)),\n\t\t\t\timplicitPrimitiveContext(6, new TextEncoder().encode(entry.uri)),\n\t\t\t]),\n\t\t),\n\t);\n}\n\n/**\n * DER-encode a CRL Distribution Points SEQUENCE.\n *\n * @param points Distribution points to encode.\n */\nexport function encodeCrlDistributionPoints(points: readonly DistributionPoint[]): Uint8Array {\n\treturn sequence(points.map((point) => sequence(encodeDistributionPoint(point))));\n}\n\n/**\n * DER-encode a Name Constraints extension value.\n *\n * @param constraints Permitted and/or excluded subtrees.\n */\nexport function encodeNameConstraints(constraints: NameConstraints): Uint8Array {\n\tconst parts: Uint8Array[] = [];\n\tif (constraints.permittedSubtrees !== undefined && constraints.permittedSubtrees.length > 0) {\n\t\tparts.push(\n\t\t\timplicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes(constraints.permittedSubtrees.map(encodeGeneralSubtree)),\n\t\t\t),\n\t\t);\n\t}\n\tif (constraints.excludedSubtrees !== undefined && constraints.excludedSubtrees.length > 0) {\n\t\tparts.push(\n\t\t\timplicitConstructedContext(\n\t\t\t\t1,\n\t\t\t\tconcatBytes(constraints.excludedSubtrees.map(encodeGeneralSubtree)),\n\t\t\t),\n\t\t);\n\t}\n\treturn sequence(parts);\n}\n\n/**\n * DER-encode a Certificate Policies extension value.\n *\n * @param policies Non-empty array of policy information entries.\n */\nexport function encodeCertificatePolicies(policies: CertificatePolicies): Uint8Array {\n\tif (policies.length === 0) {\n\t\tthrow new Error('certificatePolicies must not be empty');\n\t}\n\treturn sequence(policies.map(encodePolicyInformation));\n}\n\n/**\n * DER-encode a Policy Mappings extension value.\n *\n * @param mappings Non-empty array of issuer-to-subject policy pairs. Neither OID may be anyPolicy.\n */\nexport function encodePolicyMappings(mappings: PolicyMappings): Uint8Array {\n\tif (mappings.length === 0) {\n\t\tthrow new Error('policyMappings must not be empty');\n\t}\n\treturn sequence(\n\t\tmappings.map((mapping) => {\n\t\t\tvalidatePolicyOid(mapping.issuerDomainPolicy);\n\t\t\tvalidatePolicyOid(mapping.subjectDomainPolicy);\n\t\t\tif (\n\t\t\t\tmapping.issuerDomainPolicy === OIDS.anyPolicy ||\n\t\t\t\tmapping.subjectDomainPolicy === OIDS.anyPolicy\n\t\t\t) {\n\t\t\t\tthrow new Error('policyMappings must not use anyPolicy');\n\t\t\t}\n\t\t\treturn sequence([\n\t\t\t\tobjectIdentifier(mapping.issuerDomainPolicy),\n\t\t\t\tobjectIdentifier(mapping.subjectDomainPolicy),\n\t\t\t]);\n\t\t}),\n\t);\n}\n\n/**\n * DER-encode a Policy Constraints extension value.\n *\n * @param constraints At least one of `requireExplicitPolicy` or `inhibitPolicyMapping` must be set.\n */\nexport function encodePolicyConstraints(constraints: PolicyConstraints): Uint8Array {\n\tconst fields: Uint8Array[] = [];\n\tif (constraints.requireExplicitPolicy !== undefined) {\n\t\tfields.push(\n\t\t\timplicitPrimitiveContext(0, encodeIntegerContent(constraints.requireExplicitPolicy)),\n\t\t);\n\t}\n\tif (constraints.inhibitPolicyMapping !== undefined) {\n\t\tfields.push(\n\t\t\timplicitPrimitiveContext(1, encodeIntegerContent(constraints.inhibitPolicyMapping)),\n\t\t);\n\t}\n\tif (fields.length === 0) {\n\t\tthrow new Error('policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping');\n\t}\n\treturn sequence(fields);\n}\n\n/**\n * DER-encode an Inhibit anyPolicy extension value (single INTEGER).\n *\n * @param input The skipCerts threshold.\n */\nexport function encodeInhibitAnyPolicy(input: InhibitAnyPolicy): Uint8Array {\n\treturn integerFromNumber(input.skipCerts);\n}\n\n/** DER-encode a single PolicyInformation SEQUENCE. */\nfunction encodePolicyInformation(policy: PolicyInformation): Uint8Array {\n\tvalidatePolicyOid(policy.policyIdentifier);\n\tconst fields = [objectIdentifier(policy.policyIdentifier)];\n\tif (policy.policyQualifiers !== undefined && policy.policyQualifiers.length > 0) {\n\t\tfields.push(sequence(policy.policyQualifiers.map(encodePolicyQualifierInfo)));\n\t}\n\treturn sequence(fields);\n}\n\n/** DER-encode a single PolicyQualifierInfo SEQUENCE. */\nfunction encodePolicyQualifierInfo(qualifier: PolicyQualifierInfo): Uint8Array {\n\tswitch (qualifier.type) {\n\t\tcase 'cps':\n\t\t\treturn sequence([objectIdentifier(OIDS.cpsPolicyQualifier), ia5String(qualifier.uri)]);\n\t\tcase 'userNotice':\n\t\t\treturn sequence([\n\t\t\t\tobjectIdentifier(OIDS.userNoticePolicyQualifier),\n\t\t\t\tencodeUserNoticePolicyQualifierInfo(qualifier),\n\t\t\t]);\n\t\tcase 'oid':\n\t\t\tvalidateOid(qualifier.oid);\n\t\t\treturn sequence([objectIdentifier(qualifier.oid), new Uint8Array(qualifier.qualifierDer)]);\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = qualifier;\n\t\t\tthrow new Error(`Unhandled PolicyQualifierInfo type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/** DER-encode a UserNotice qualifier SEQUENCE. */\nfunction encodeUserNoticePolicyQualifierInfo(qualifier: UserNoticePolicyQualifierInfo): Uint8Array {\n\tconst fields: Uint8Array[] = [];\n\tif (qualifier.noticeRef !== undefined) {\n\t\tfields.push(encodePolicyNoticeReference(qualifier.noticeRef));\n\t}\n\tif (qualifier.explicitText !== undefined) {\n\t\tfields.push(utf8String(qualifier.explicitText));\n\t}\n\treturn sequence(fields);\n}\n\n/** DER-encode a NoticeReference SEQUENCE. */\nfunction encodePolicyNoticeReference(reference: PolicyNoticeReference): Uint8Array {\n\treturn sequence([\n\t\tutf8String(reference.organization),\n\t\tsequence(reference.noticeNumbers.map((noticeNumber) => integerFromNumber(noticeNumber))),\n\t]);\n}\n\n/** Encode an INTEGER and return only the content bytes (no TLV wrapper). */\nfunction encodeIntegerContent(value: number): Uint8Array {\n\treturn readElement(integerFromNumber(value)).value;\n}\n\n/** DER-encode a GeneralSubtree SEQUENCE (base name only; min/max omitted per RFC 5280). */\nfunction encodeGeneralSubtree(subtree: GeneralSubtree): Uint8Array {\n\treturn sequence([encodeNameConstraintForm(subtree.base)]);\n}\n\n/** DER-encode the fields of a single DistributionPoint. */\nfunction encodeDistributionPoint(point: DistributionPoint): Uint8Array[] {\n\tif (point.crlIssuer !== undefined && point.crlIssuer.length === 0) {\n\t\tthrow new Error('DistributionPoint crlIssuer must not be empty');\n\t}\n\tif (point.distributionPoint === undefined && point.crlIssuer === undefined) {\n\t\tthrow new Error('DistributionPoint must contain distributionPoint or crlIssuer');\n\t}\n\tconst fields: Uint8Array[] = [];\n\tif (point.distributionPoint !== undefined) {\n\t\tfields.push(\n\t\t\timplicitConstructedContext(0, encodeDistributionPointName(point.distributionPoint)),\n\t\t);\n\t}\n\tif (point.reasons !== undefined && point.reasons.length > 0) {\n\t\tfields.push(\n\t\t\timplicitPrimitiveContext(1, encodeDistributionPointReasonFlagsContent(point.reasons)),\n\t\t);\n\t}\n\tif (point.crlIssuer !== undefined && point.crlIssuer.length > 0) {\n\t\tfields.push(\n\t\t\timplicitConstructedContext(2, concatBytes(point.crlIssuer.map(encodeSubjectAltName))),\n\t\t);\n\t}\n\treturn fields;\n}\n\n/** DER-encode a DistributionPointName (fullName or relativeName). */\nfunction encodeDistributionPointName(name: DistributionPointName): Uint8Array {\n\tif (name.fullName !== undefined && name.relativeName !== undefined) {\n\t\tthrow new Error('DistributionPointName cannot contain both fullName and relativeName');\n\t}\n\tif (name.fullName !== undefined) {\n\t\tif (name.fullName.length === 0) {\n\t\t\tthrow new Error('DistributionPointName fullName must not be empty');\n\t\t}\n\t\treturn implicitConstructedContext(0, concatBytes(name.fullName.map(encodeSubjectAltName)));\n\t}\n\tif (name.relativeName !== undefined) {\n\t\tconst relativeName = encodeRelativeDistinguishedName(name.relativeName);\n\t\tconst relativeNameElement = readElement(relativeName);\n\t\treturn implicitConstructedContext(\n\t\t\t1,\n\t\t\trelativeName.slice(relativeNameElement.start, relativeNameElement.end),\n\t\t);\n\t}\n\tthrow new Error('DistributionPointName must contain fullName or relativeName');\n}\n\n/** DER-encode a NameConstraintForm as an implicit-tagged {@linkcode GeneralName}. */\nfunction encodeNameConstraintForm(form: NameConstraintForm): Uint8Array {\n\tswitch (form.type) {\n\t\tcase 'dns':\n\t\t\treturn implicitPrimitiveContext(2, new TextEncoder().encode(form.value));\n\t\tcase 'email':\n\t\t\treturn implicitPrimitiveContext(1, new TextEncoder().encode(form.value));\n\t\tcase 'uri':\n\t\t\treturn implicitPrimitiveContext(6, new TextEncoder().encode(form.value));\n\t\tcase 'ip':\n\t\t\treturn implicitPrimitiveContext(7, concatBytes([form.addressBytes, form.maskBytes]));\n\t\tcase 'directoryName':\n\t\t\treturn implicitConstructedContext(4, extractDirectoryNameContent(form.derHex));\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = form;\n\t\t\tthrow new Error(`Unhandled NameConstraintForm type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/** Extract the content bytes from a hex-encoded DER SEQUENCE (strips the outer TLV). */\nfunction extractDirectoryNameContent(derHex: string): Uint8Array {\n\tconst element = readRootElement(hexToBytes(derHex), { maxDepth: DEFAULT_MAX_DER_DEPTH });\n\tif (element.tag !== 0x30) {\n\t\tthrow new Error('directoryName derHex must encode a DER SEQUENCE');\n\t}\n\treturn new Uint8Array(element.value);\n}\n\n/**\n * Resolve an {@linkcode ExtendedKeyUsage} to its dotted-decimal OID.\n *\n * @param usage Well-known string or custom OID object.\n */\nexport function getExtendedKeyUsageOid(usage: ExtendedKeyUsage): string {\n\tif (typeof usage === 'string') {\n\t\treturn EXTENDED_KEY_USAGE_OIDS[usage];\n\t}\n\tvalidateOid(usage.value);\n\treturn usage.value;\n}\n\n/**\n * Map a dotted-decimal OID to an {@linkcode ExtendedKeyUsage} value.\n *\n * Returns a well-known string for recognized OIDs, or `{ type: 'oid', value }` otherwise.\n */\nexport function parseExtendedKeyUsageOid(oid: string): ExtendedKeyUsage {\n\tswitch (oid) {\n\t\tcase OIDS.serverAuth:\n\t\t\treturn 'serverAuth';\n\t\tcase OIDS.clientAuth:\n\t\t\treturn 'clientAuth';\n\t\tcase OIDS.codeSigning:\n\t\t\treturn 'codeSigning';\n\t\tcase OIDS.emailProtection:\n\t\t\treturn 'emailProtection';\n\t\tcase OIDS.timeStamping:\n\t\t\treturn 'timeStamping';\n\t\tcase OIDS.ocspSigning:\n\t\t\treturn 'ocspSigning';\n\t}\n\treturn { type: 'oid', value: oid };\n}\n\n/**\n * Resolve an {@linkcode AuthorityInfoAccessMethod} to its dotted-decimal OID.\n *\n * @param method Well-known string or custom OID object.\n */\nexport function getAuthorityInfoAccessMethodOid(method: AuthorityInfoAccessMethod): string {\n\tif (typeof method === 'string') {\n\t\treturn AUTHORITY_INFO_ACCESS_METHOD_OIDS[method];\n\t}\n\tvalidateOid(method.value);\n\treturn method.value;\n}\n\n/**\n * Map a dotted-decimal OID to an {@linkcode AuthorityInfoAccessMethod} value.\n *\n * Returns `'ocsp'` or `'caIssuers'` for recognized OIDs, or `{ type: 'oid', value }` otherwise.\n */\nexport function parseAuthorityInfoAccessMethodOid(oid: string): AuthorityInfoAccessMethod {\n\tswitch (oid) {\n\t\tcase OIDS.ocspAccessMethod:\n\t\t\treturn 'ocsp';\n\t\tcase OIDS.caIssuersAccessMethod:\n\t\t\treturn 'caIssuers';\n\t}\n\treturn { type: 'oid', value: oid };\n}\n\n/** Parse a dotted-decimal/colon-hex IP string to raw address bytes. */\nfunction encodeIpAddress(input: string): Uint8Array {\n\treturn parseIpAddressToBytes(input);\n}\n\n/** @internal Compute the SKI as SHA-1 of the subjectPublicKey BIT STRING content. */\nexport function buildSubjectKeyIdentifier(subjectPublicKeyInfo: Uint8Array): Uint8Array {\n\tconst topLevel = readSequenceChildren(subjectPublicKeyInfo);\n\tconst subjectPublicKey = topLevel[1];\n\tif (subjectPublicKey === undefined || subjectPublicKey.tag !== 0x03) {\n\t\tthrow new Error('SPKI missing subject public key bit string');\n\t}\n\tconst publicKeyBytes = subjectPublicKey.value.slice(1);\n\treturn sha1(publicKeyBytes);\n}\n\n/** Throw if the string is not a valid dotted-decimal OID. */\nfunction validateOid(oid: string): void {\n\tif (!/^\\d+(?:\\.\\d+)+$/.test(oid)) {\n\t\tthrow new Error(`Invalid OID: ${oid}`);\n\t}\n}\n\n/** Validate that a policy OID is syntactically valid. */\nfunction validatePolicyOid(oid: string): void {\n\tvalidateOid(oid);\n}\n\n/** Encode and push an extension, rejecting duplicate OIDs. */\nfunction pushExtension(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\toid: string,\n\tvalue: Uint8Array,\n\tcritical = false,\n): void {\n\tvalidateOid(oid);\n\tif (seen.has(oid)) {\n\t\tthrow new Error(`Duplicate extension OID: ${oid}`);\n\t}\n\tseen.add(oid);\n\tencoded.push(encodeExtension(oid, value, critical));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqqBA,MAAM,IAAiE;CACtE,YAAY,E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AAK,IAAI,CAAG,GACZ,EAAQ,KAAK,gBAAgB,GAAK,GAAO,CAAQ,CAAC;AACnD"}
|
|
1
|
+
{"version":3,"file":"extensions.js","names":["_exhaustive"],"sources":["../../src/x509/extensions.ts"],"sourcesContent":["/**\n * Typed certificate and CSR extension model plus ASN.1 encoder helpers.\n *\n * Defines input types for every supported X.509v3 extension (RFC 5280) and\n * the DER encoders consumed by certificate and CSR builder flows.\n *\n * @module\n */\n\nimport { hexToBytes } from '#micro509/internal/asn1/asn1';\nimport {\n\tbool,\n\tconcatBytes,\n\tDEFAULT_MAX_DER_DEPTH,\n\texplicitContext,\n\tia5String,\n\timplicitConstructedContext,\n\timplicitPrimitiveContext,\n\tintegerFromNumber,\n\tobjectIdentifier,\n\toctetString,\n\treadElement,\n\treadRootElement,\n\treadSequenceChildren,\n\tsequence,\n\ttlv,\n\tutf8String,\n} from '#micro509/internal/asn1/der';\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport { sha1 } from '#micro509/internal/crypto/hash';\nimport { parseIpAddressToBytes } from '#micro509/internal/shared/ip';\nimport {\n\tencodeDistributionPointReasonFlagsContent,\n\tencodeKeyUsageExtension,\n} from '#micro509/internal/x509/extension-bits';\nimport type {\n\tExtensionDefinition,\n\tExtensionRegistryContext,\n} from '#micro509/internal/x509/extension-registry';\nimport {\n\tAUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION,\n\tAUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\tBASIC_CONSTRAINTS_EXTENSION_DEFINITION,\n\tCERTIFICATE_POLICIES_EXTENSION_DEFINITION,\n\tCRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION,\n\tEXTENDED_KEY_USAGE_EXTENSION_DEFINITION,\n\tgetExtensionDefinition,\n\tINHIBIT_ANY_POLICY_EXTENSION_DEFINITION,\n\tKEY_USAGE_EXTENSION_DEFINITION,\n\tNAME_CONSTRAINTS_EXTENSION_DEFINITION,\n\tPOLICY_CONSTRAINTS_EXTENSION_DEFINITION,\n\tPOLICY_MAPPINGS_EXTENSION_DEFINITION,\n\tSUBJECT_ALT_NAME_EXTENSION_DEFINITION,\n\tSUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n} from '#micro509/internal/x509/extension-registry';\nimport type { RelativeDistinguishedNameInput } from '#micro509/x509/name';\nimport { encodeRelativeDistinguishedName } from '#micro509/x509/name';\n\nexport type {\n\tNameAttribute,\n\tNameFieldKey,\n\tRelativeDistinguishedNameInput,\n} from '#micro509/x509/name';\n\n/**\n * A decoded BIT STRING flag set.\n *\n * `flags` contains the recognized flag values with any non-zero padding bits\n * masked out. `nonZeroPadding` is `true` when the original BIT STRING encoding\n * had non-zero bits in positions that DER ({@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690 §11.2.1}) requires to be zero.\n * Verification layers can use this signal to reject non-conformant encodings.\n */\nexport interface ParsedBitFlags<T extends string> {\n\t/** Decoded flag values, padding bits masked. */\n\treadonly flags: readonly T[];\n\t/** `true` when the original encoding had non-zero padding bits (DER violation). */\n\treadonly nonZeroPadding: boolean;\n}\n\n/**\n * RFC 5280 §4.2.1.3 Key Usage bit flag.\n *\n * Each value corresponds to one bit in the KeyUsage BIT STRING.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.3 RFC 5280 §4.2.1.3}\n */\nexport type KeyUsage =\n\t| 'digitalSignature'\n\t| 'nonRepudiation'\n\t| 'keyEncipherment'\n\t| 'dataEncipherment'\n\t| 'keyAgreement'\n\t| 'keyCertSign'\n\t| 'cRLSign'\n\t| 'encipherOnly'\n\t| 'decipherOnly';\n\n/**\n * RFC 5280 §4.2.1.6 Subject Alternative Name / GeneralName.\n *\n * Discriminated union keyed on `type`.\n *\n * The `'unknown'` variant preserves unrecognized {@linkcode GeneralName} tags for round-trip fidelity.\n */\nexport type SubjectAltName =\n\t| {\n\t\t\t/** DNS hostname (dNSName [2]). */\n\t\t\treadonly type: 'dns';\n\t\t\t/** Fully-qualified domain name, e.g. `\"example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** IP address (iPAddress [7]). */\n\t\t\treadonly type: 'ip';\n\t\t\t/** Dotted-decimal IPv4 or colon-hex IPv6 string. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** Email address (rfc822Name [1]). */\n\t\t\treadonly type: 'email';\n\t\t\t/** RFC 822 mailbox, e.g. `\"admin@example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** URI (uniformResourceIdentifier [6]). */\n\t\t\treadonly type: 'uri';\n\t\t\t/** Absolute URI string. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** SRV-ID otherName (id-on-dnsSRV). */\n\t\t\treadonly type: 'srv';\n\t\t\t/** SRV service name, e.g. `\"_imaps.example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** X.500 directory name (directoryName [4]). */\n\t\t\treadonly type: 'directoryName';\n\t\t\t/** Hex-encoded DER of the Name SEQUENCE. */\n\t\t\treadonly derHex: string;\n\t }\n\t| {\n\t\t\t/** Unrecognized {@linkcode GeneralName} tag, preserved as raw bytes. */\n\t\t\treadonly type: 'unknown';\n\t\t\t/** ASN.1 context tag number. */\n\t\t\treadonly tag: number;\n\t\t\t/** Raw content bytes of the element. */\n\t\t\treadonly value: Uint8Array;\n\t };\n\n/** Alias for {@linkcode SubjectAltName} — used where RFC 5280 says \"GeneralName\". */\nexport type GeneralName = SubjectAltName;\n\n/**\n * Revocation reason flags for CRL Distribution Points and Issuing Distribution Points\n * (RFC 5280 §4.2.1.13, §5.2.5).\n */\nexport type DistributionPointReason =\n\t| 'keyCompromise'\n\t| 'cACompromise'\n\t| 'affiliationChanged'\n\t| 'superseded'\n\t| 'cessationOfOperation'\n\t| 'certificateHold'\n\t| 'privilegeWithdrawn'\n\t| 'aACompromise';\n\n/**\n * Name component of a CRL Distribution Point (RFC 5280 §4.2.1.13).\n *\n * Supply exactly one of `fullName` or `relativeName`.\n */\nexport interface DistributionPointName {\n\t/** Absolute {@linkcode GeneralName}(s) identifying the distribution point (usually a URI). */\n\treadonly fullName?: readonly GeneralName[];\n\t/** Name relative to the issuer's DN; mutually exclusive with `fullName`. */\n\treadonly relativeName?: RelativeDistinguishedNameInput;\n}\n\n/**\n * Input for a single CRL Distribution Point (RFC 5280 §4.2.1.13).\n *\n * At least one of `distributionPoint` or `crlIssuer` must be provided.\n * The union enforces this constraint at the type level.\n */\nexport type DistributionPoint =\n\t| {\n\t\t\t/** Where to fetch the CRL (fullName or relativeName). */\n\t\t\treadonly distributionPoint: DistributionPointName;\n\t\t\t/** Revocation reason subset. Absent means all reasons. */\n\t\t\treadonly reasons?: readonly DistributionPointReason[];\n\t\t\t/** Entity that signed the CRL, when different from the cert issuer. */\n\t\t\treadonly crlIssuer?: readonly GeneralName[];\n\t }\n\t| {\n\t\t\t/** Where to fetch the CRL. Optional when `crlIssuer` is present. */\n\t\t\treadonly distributionPoint?: DistributionPointName;\n\t\t\t/** Revocation reason subset. Absent means all reasons. */\n\t\t\treadonly reasons?: readonly DistributionPointReason[];\n\t\t\t/** Entity that signed the CRL. Required when `distributionPoint` is absent. */\n\t\t\treadonly crlIssuer: readonly GeneralName[];\n\t };\n\n/** Base shape for Issuing Distribution Point (RFC 5280 §5.2.5) — no scope restriction. */\nexport interface IssuingDistributionPointBase {\n\t/** Where to fetch this CRL. */\n\treadonly distributionPoint?: DistributionPointName;\n\t/** Limits the CRL to these revocation reasons. Absent means all reasons. */\n\treadonly onlySomeReasons?: readonly DistributionPointReason[];\n\t/** When true, the CRL may contain entries from other CAs. Default false. */\n\treadonly indirectCrl?: boolean;\n\t/** Must be absent or false in this variant (no user-cert-only restriction). */\n\treadonly onlyContainsUserCerts?: false;\n\t/** Must be absent or false in this variant (no CA-cert-only restriction). */\n\treadonly onlyContainsCACerts?: false;\n\t/** When true, the CRL only covers attribute certificates. Default false. */\n\treadonly onlyContainsAttributeCerts?: boolean;\n}\n\n/** IDP scoped to end-entity (user) certificates only. Mutually exclusive with CA / attribute scopes. */\nexport interface IssuingDistributionPointForUserCerts\n\textends Omit<IssuingDistributionPointBase, 'onlyContainsUserCerts'> {\n\t/** This variant only covers end-entity certificates. */\n\treadonly onlyContainsUserCerts: true;\n\t/** Must be absent or false when the CRL is not CA-only. */\n\treadonly onlyContainsCACerts?: false;\n\t/** Must be absent or false when the CRL is not attribute-cert-only. */\n\treadonly onlyContainsAttributeCerts?: false;\n}\n\n/** IDP scoped to CA certificates only. Mutually exclusive with user / attribute scopes. */\nexport interface IssuingDistributionPointForCaCerts\n\textends Omit<IssuingDistributionPointBase, 'onlyContainsCACerts'> {\n\t/** Must be absent or false when the CRL is not user-cert-only. */\n\treadonly onlyContainsUserCerts?: false;\n\t/** This variant only covers CA certificates. */\n\treadonly onlyContainsCACerts: true;\n\t/** Must be absent or false when the CRL is not attribute-cert-only. */\n\treadonly onlyContainsAttributeCerts?: false;\n}\n\n/** IDP scoped to attribute certificates only. Mutually exclusive with user / CA scopes. */\nexport interface IssuingDistributionPointForAttributeCerts\n\textends Omit<IssuingDistributionPointBase, 'onlyContainsAttributeCerts'> {\n\t/** Must be absent or false when the CRL is not user-cert-only. */\n\treadonly onlyContainsUserCerts?: false;\n\t/** Must be absent or false when the CRL is not CA-only. */\n\treadonly onlyContainsCACerts?: false;\n\t/** This variant only covers attribute certificates. */\n\treadonly onlyContainsAttributeCerts: true;\n}\n\n/**\n * Input for the Issuing Distribution Point CRL extension (RFC 5280 §5.2.5).\n *\n * The union enforces that at most one of the `onlyContains*` flags is true.\n */\nexport type IssuingDistributionPoint =\n\t| IssuingDistributionPointBase\n\t| IssuingDistributionPointForUserCerts\n\t| IssuingDistributionPointForCaCerts\n\t| IssuingDistributionPointForAttributeCerts;\n\n/**\n * RFC 5280 §4.2.1.9 Basic Constraints.\n *\n * A certificate with `ca: true` may issue other certificates; `pathLength`\n * limits how many additional CAs may appear below it in the chain.\n */\nexport type BasicConstraints =\n\t| {\n\t\t\t/** End-entity certificate: not a CA. */\n\t\t\treadonly ca: false;\n\t\t\t/** Never present on end-entity certificates. */\n\t\t\treadonly pathLength?: undefined;\n\t }\n\t| {\n\t\t\t/** CA certificate: may issue other certificates. */\n\t\t\treadonly ca: true;\n\t\t\t/** Maximum number of intermediate CA certificates allowed below this CA. */\n\t\t\treadonly pathLength?: number;\n\t };\n\n/** A single certificate policy: an OID plus optional qualifiers. */\nexport interface PolicyInformation {\n\t/** Dotted-decimal OID of the policy (e.g. `\"2.23.140.1.2.1\"` for DV). */\n\treadonly policyIdentifier: string;\n\t/** Optional CPS URIs or user notices attached to this policy. */\n\treadonly policyQualifiers?: readonly PolicyQualifierInfo[];\n}\n\n/** RFC 5280 §4.2.1.4 — array of policy OIDs with optional qualifiers. */\nexport type CertificatePolicies = readonly {\n\t/** Dotted-decimal OID of the policy (e.g. `\"2.23.140.1.2.1\"` for DV). */\n\treadonly policyIdentifier: string;\n\t/** Optional CPS URIs or user notices attached to this policy. */\n\treadonly policyQualifiers?: readonly (\n\t\t| {\n\t\t\t\treadonly type: 'cps';\n\t\t\t\treadonly uri: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'userNotice';\n\t\t\t\treadonly noticeRef?: {\n\t\t\t\t\treadonly organization: string;\n\t\t\t\t\treadonly noticeNumbers: readonly number[];\n\t\t\t\t};\n\t\t\t\treadonly explicitText?: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'oid';\n\t\t\t\treadonly oid: string;\n\t\t\t\treadonly qualifierDer: Uint8Array;\n\t\t }\n\t)[];\n}[];\n\n/** CPS (Certification Practice Statement) URI policy qualifier. */\nexport interface CpsPolicyQualifierInfo {\n\t/** Discriminant for the `'cps'` qualifier variant. */\n\treadonly type: 'cps';\n\t/** URL of the Certification Practice Statement document. */\n\treadonly uri: string;\n}\n\n/** Reference to a numbered notice within an organization's practice statement. */\nexport interface PolicyNoticeReference {\n\t/** Organization name that published the notice. */\n\treadonly organization: string;\n\t/** One-based notice numbers within that organization's documentation. */\n\treadonly noticeNumbers: readonly number[];\n}\n\n/** UserNotice policy qualifier — human-readable notice text and/or a notice reference. */\nexport interface UserNoticePolicyQualifierInfo {\n\t/** Discriminant for the `'userNotice'` qualifier variant. */\n\treadonly type: 'userNotice';\n\t/** Pointer to a numbered notice in an organization's practice statement. */\n\treadonly noticeRef?: PolicyNoticeReference;\n\t/** Free-form text to display to relying parties. */\n\treadonly explicitText?: string;\n}\n\n/** Opaque policy qualifier identified by a custom OID, carried as raw DER. */\nexport interface CustomPolicyQualifierInfo {\n\t/** Discriminant for the custom-OID qualifier variant. */\n\treadonly type: 'oid';\n\t/** Dotted-decimal OID of the qualifier. */\n\treadonly oid: string;\n\t/** DER-encoded qualifier payload. */\n\treadonly qualifierDer: Uint8Array;\n}\n\n/** Discriminated union of all supported policy qualifier types. */\nexport type PolicyQualifierInfo =\n\t| CpsPolicyQualifierInfo\n\t| UserNoticePolicyQualifierInfo\n\t| CustomPolicyQualifierInfo;\n\n/** Maps a policy OID in the issuer's domain to an equivalent OID in the subject's domain. */\nexport interface PolicyMapping {\n\t/** Policy OID as defined by the issuing CA. Must not be anyPolicy. */\n\treadonly issuerDomainPolicy: string;\n\t/** Equivalent policy OID in the subject CA's domain. Must not be anyPolicy. */\n\treadonly subjectDomainPolicy: string;\n}\n\n/** RFC 5280 §4.2.1.5 — array of issuer-to-subject policy OID pairs. */\nexport type PolicyMappings = readonly {\n\t/** Policy OID as defined by the issuing CA. Must not be anyPolicy. */\n\treadonly issuerDomainPolicy: string;\n\t/** Equivalent policy OID in the subject CA's domain. Must not be anyPolicy. */\n\treadonly subjectDomainPolicy: string;\n}[];\n\n/**\n * RFC 5280 §4.2.1.11 Policy Constraints.\n *\n * At least one field must be present. Values are certificate-count\n * thresholds measured from the current certificate toward the end entity.\n */\nexport interface PolicyConstraints {\n\t/** After this many certificates, an acceptable policy must be in the path. */\n\treadonly requireExplicitPolicy?: number;\n\t/** After this many certificates, policy mapping is no longer allowed. */\n\treadonly inhibitPolicyMapping?: number;\n}\n\n/**\n * RFC 5280 §4.2.1.14 Inhibit anyPolicy.\n *\n * After `skipCerts` additional certificates in the path, the special\n * anyPolicy OID is no longer considered a match.\n */\nexport interface InhibitAnyPolicy {\n\t/** Number of additional certificates before anyPolicy stops being valid. */\n\treadonly skipCerts: number;\n}\n\n/**\n * Input for `createCertificate`, `createSelfSignedCertificate`,\n * and `createCertificateSigningRequest`.\n *\n * Every field is optional. Omitted extensions are not encoded. Built-in\n * extensions (SKI, AKI, basicConstraints defaults) are handled automatically\n * by the builder.\n */\nexport interface CertificateExtensionsInput {\n\t/** Subject Alternative Names (dns, ip, email, uri, srv, directoryName). */\n\treadonly subjectAltNames?: readonly SubjectAltName[];\n\t/** Key Usage flags (digitalSignature, keyCertSign, etc.). */\n\treadonly keyUsage?: readonly KeyUsage[];\n\t/** Basic Constraints (CA flag + optional pathLength). Defaults to `{ ca: false }` for certs. */\n\treadonly basicConstraints?: BasicConstraints;\n\t/** Extended Key Usage purposes (serverAuth, clientAuth, etc.). */\n\treadonly extendedKeyUsage?: readonly ExtendedKeyUsage[];\n\t/** Name Constraints — permitted and/or excluded subtrees. */\n\treadonly nameConstraints?: NameConstraints;\n\t/** Certificate Policies with optional qualifiers. */\n\treadonly certificatePolicies?: CertificatePolicies;\n\t/** Policy Mappings between issuer and subject policy domains. */\n\treadonly policyMappings?: PolicyMappings;\n\t/** Policy Constraints (requireExplicitPolicy / inhibitPolicyMapping thresholds). */\n\treadonly policyConstraints?: PolicyConstraints;\n\t/** Inhibit anyPolicy skip-certs threshold. */\n\treadonly inhibitAnyPolicy?: InhibitAnyPolicy;\n\t/** Authority Information Access — OCSP responder and CA issuer URIs. */\n\treadonly authorityInfoAccess?: readonly AuthorityInformationAccess[];\n\t/** CRL Distribution Points — where to check revocation status. */\n\treadonly crlDistributionPoints?: readonly DistributionPoint[];\n\t/** Arbitrary extensions not covered by the built-in fields. */\n\treadonly customExtensions?: readonly CustomExtension[];\n}\n\n/** An extension not covered by the typed fields in {@linkcode CertificateExtensionsInput}. */\nexport interface CustomExtension {\n\t/** Dotted-decimal OID of the extension. */\n\treadonly oid: string;\n\t/** Pre-encoded DER content for the extnValue OCTET STRING. */\n\treadonly value: Uint8Array;\n\t/** Whether the extension is critical. Default `false`. */\n\treadonly critical?: boolean;\n}\n\n// Name constraints (RFC 5280 §4.2.1.10)\n\n/**\n * A name form used as a constraint base in namEConstraints.\n * Distinct from {@linkcode SubjectAltName} because IP constraints carry\n * address + mask bytes (8 for IPv4, 32 for IPv6) rather than bare addresses.\n */\nexport type NameConstraintForm =\n\t| {\n\t\t\t/** DNS domain constraint (dNSName [2]). */\n\t\t\treadonly type: 'dns';\n\t\t\t/** Domain suffix, e.g. `\".example.com\"` or `\"example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** Email constraint (rfc822Name [1]). */\n\t\t\treadonly type: 'email';\n\t\t\t/** Email domain or full address pattern. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** URI constraint (uniformResourceIdentifier [6]). */\n\t\t\treadonly type: 'uri';\n\t\t\t/** Host or domain component of a URI. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** IP range constraint (iPAddress [7]). */\n\t\t\treadonly type: 'ip';\n\t\t\t/** Network address bytes (4 for IPv4, 16 for IPv6). */\n\t\t\treadonly addressBytes: Uint8Array;\n\t\t\t/** Subnet mask bytes (same length as addressBytes). */\n\t\t\treadonly maskBytes: Uint8Array;\n\t }\n\t| {\n\t\t\t/** Directory name constraint (directoryName [4]). */\n\t\t\treadonly type: 'directoryName';\n\t\t\t/** Hex-encoded DER of the Name SEQUENCE. */\n\t\t\treadonly derHex: string;\n\t };\n\n/**\n * Name constraint forms parsed from DER but not supported for encoding or\n * validation. Preserved for diagnostic round-tripping.\n */\nexport type UnsupportedNameConstraintForm =\n\t| {\n\t\t\t/** otherName [0] — raw bytes. */\n\t\t\treadonly type: 'otherName';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** x400Address [3] — raw bytes. */\n\t\t\treadonly type: 'x400Address';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** ediPartyName [5] — raw bytes. */\n\t\t\treadonly type: 'ediPartyName';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** registeredID [8] — decoded OID string. */\n\t\t\treadonly type: 'registeredID';\n\t\t\treadonly value: string;\n\t };\n\n/** Union of supported and unsupported name constraint forms as produced by parsing. */\nexport type ParsedNameConstraintForm =\n\t| {\n\t\t\treadonly type: 'dns';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'email';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'uri';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'ip';\n\t\t\treadonly addressBytes: Uint8Array;\n\t\t\treadonly maskBytes: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'directoryName';\n\t\t\treadonly derHex: string;\n\t }\n\t| {\n\t\t\treadonly type: 'otherName';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'x400Address';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'ediPartyName';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'registeredID';\n\t\t\treadonly value: string;\n\t };\n\n/** A single subtree entry in a Name Constraints permitted/excluded list. */\nexport interface GeneralSubtree<\n\tTForm extends ParsedNameConstraintForm =\n\t\t| {\n\t\t\t\treadonly type: 'dns';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'email';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'uri';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'ip';\n\t\t\t\treadonly addressBytes: Uint8Array;\n\t\t\t\treadonly maskBytes: Uint8Array;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'directoryName';\n\t\t\t\treadonly derHex: string;\n\t\t },\n> {\n\t/** The name form that defines this constraint boundary. */\n\treadonly base: TForm;\n}\n\n/**\n * RFC 5280 §4.2.1.10 Name Constraints.\n *\n * A CA certificate may restrict the namespace of all subject names in\n * subsequent certificates in the path.\n */\nexport interface NameConstraints<\n\tTForm extends ParsedNameConstraintForm =\n\t\t| {\n\t\t\t\treadonly type: 'dns';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'email';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'uri';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'ip';\n\t\t\t\treadonly addressBytes: Uint8Array;\n\t\t\t\treadonly maskBytes: Uint8Array;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'directoryName';\n\t\t\t\treadonly derHex: string;\n\t\t },\n> {\n\t/** Names that MUST fall within these subtrees to be valid. */\n\treadonly permittedSubtrees?: readonly GeneralSubtree<TForm>[];\n\t/** Names that MUST NOT fall within these subtrees. Takes precedence over permitted. */\n\treadonly excludedSubtrees?: readonly GeneralSubtree<TForm>[];\n}\n\n/** Well-known AIA access methods: OCSP responder or CA issuer certificate. */\nexport type KnownAuthorityInfoAccessMethod = 'ocsp' | 'caIssuers';\n\n/** AIA access method identified by a custom OID not in the well-known set. */\nexport interface CustomAuthorityInfoAccessMethod {\n\t/** Discriminant for the custom-OID access method variant. */\n\treadonly type: 'oid';\n\t/** Dotted-decimal OID of the access method. */\n\treadonly value: string;\n}\n\n/** AIA access method — either a well-known string or a custom OID. */\nexport type AuthorityInfoAccessMethod =\n\t| KnownAuthorityInfoAccessMethod\n\t| CustomAuthorityInfoAccessMethod;\n\n/** A single entry in the Authority Information Access extension (RFC 5280 §4.2.2.1). */\nexport interface AuthorityInformationAccess {\n\t/** Access method (`'ocsp'`, `'caIssuers'`, or custom OID). */\n\treadonly method:\n\t\t| 'ocsp'\n\t\t| 'caIssuers'\n\t\t| {\n\t\t\t\treadonly type: 'oid';\n\t\t\t\treadonly value: string;\n\t\t };\n\t/** URI where the resource can be fetched. */\n\treadonly uri: string;\n}\n\n/** Well-known Extended Key Usage purpose strings (RFC 5280 §4.2.1.12). */\nexport type KnownExtendedKeyUsage =\n\t| 'serverAuth'\n\t| 'clientAuth'\n\t| 'codeSigning'\n\t| 'emailProtection'\n\t| 'timeStamping'\n\t| 'ocspSigning';\n\n/** Extended Key Usage purpose identified by a custom OID. */\nexport interface CustomExtendedKeyUsage {\n\t/** Discriminant for the custom-OID EKU variant. */\n\treadonly type: 'oid';\n\t/** Dotted-decimal OID of the usage purpose. */\n\treadonly value: string;\n}\n\n/** Extended Key Usage — either a well-known purpose string or a custom OID. */\nexport type ExtendedKeyUsage =\n\t| 'serverAuth'\n\t| 'clientAuth'\n\t| 'codeSigning'\n\t| 'emailProtection'\n\t| 'timeStamping'\n\t| 'ocspSigning'\n\t| {\n\t\t\treadonly type: 'oid';\n\t\t\treadonly value: string;\n\t };\n\n/** Map from well-known EKU names to their dotted-decimal OIDs. */\nconst EXTENDED_KEY_USAGE_OIDS: Record<KnownExtendedKeyUsage, string> = {\n\tserverAuth: OIDS.serverAuth,\n\tclientAuth: OIDS.clientAuth,\n\tcodeSigning: OIDS.codeSigning,\n\temailProtection: OIDS.emailProtection,\n\ttimeStamping: OIDS.timeStamping,\n\tocspSigning: OIDS.ocspSigning,\n};\n\n/** Map from well-known AIA method names to their dotted-decimal OIDs. */\nconst AUTHORITY_INFO_ACCESS_METHOD_OIDS: Record<KnownAuthorityInfoAccessMethod, string> = {\n\tocsp: OIDS.ocspAccessMethod,\n\tcaIssuers: OIDS.caIssuersAccessMethod,\n};\n\n/**\n * Build the v3 extensions block for a certificate.\n *\n * Automatically adds SKI, AKI (when issuer key is available), and\n * basicConstraints (defaults to `{ ca: false }`). Additional extensions\n * come from the caller's {@linkcode CertificateExtensionsInput}.\n *\n * @param subjectPublicKeyInfo DER-encoded SPKI of the subject.\n * @param issuerPublicKeyInfo DER-encoded SPKI of the issuer, or `undefined` for self-signed.\n * @param input Optional extension configuration.\n * @param subjectIsEmpty Whether the certificate subject DN is empty. When `true`, the\n * subjectAltName extension is marked critical per RFC 5280 §4.2.1.6.\n * @returns Array of DER-encoded Extension SEQUENCEs.\n */\nexport function buildCertificateExtensions(\n\tsubjectPublicKeyInfo: Uint8Array,\n\tissuerPublicKeyInfo: Uint8Array | undefined,\n\tinput: CertificateExtensionsInput | undefined,\n\tsubjectIsEmpty = false,\n): Uint8Array[] {\n\tconst extensions: Uint8Array[] = [];\n\tconst seen = new Set<string>();\n\tconst basicConstraints = input?.basicConstraints ?? { ca: false };\n\tpushKnownExtension(extensions, seen, BASIC_CONSTRAINTS_EXTENSION_DEFINITION, basicConstraints);\n\tpushKnownExtension(\n\t\textensions,\n\t\tseen,\n\t\tSUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\t\tbuildSubjectKeyIdentifier(subjectPublicKeyInfo),\n\t);\n\tif (issuerPublicKeyInfo !== undefined) {\n\t\tpushKnownExtension(\n\t\t\textensions,\n\t\t\tseen,\n\t\t\tAUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\t\t\tbuildSubjectKeyIdentifier(issuerPublicKeyInfo),\n\t\t);\n\t}\n\tappendConfiguredExtensions(extensions, seen, input, 'certificate', {\n\t\tincludeBasicConstraints: false,\n\t\tsubjectIsEmpty,\n\t});\n\treturn extensions;\n}\n\n/**\n * Build the extensions for a CSR's extensionRequest attribute.\n *\n * Unlike {@linkcode buildCertificateExtensions}, SKI/AKI are not auto-generated.\n *\n * @param input Optional extension configuration.\n * @returns Array of DER-encoded Extension SEQUENCEs.\n */\nexport function buildRequestedExtensions(\n\tinput: CertificateExtensionsInput | undefined,\n): Uint8Array[] {\n\tconst extensions: Uint8Array[] = [];\n\tconst seen = new Set<string>();\n\tappendConfiguredExtensions(extensions, seen, input, 'csr', { includeBasicConstraints: true });\n\treturn extensions;\n}\n\n/** Encode and push each configured extension from the input, enforcing no duplicates. */\nfunction appendConfiguredExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput | undefined,\n\tcontext: ExtensionRegistryContext,\n\toptions: {\n\t\treadonly includeBasicConstraints: boolean;\n\t\t/** When true, SAN is marked critical per RFC 5280 §4.2.1.6. */\n\t\treadonly subjectIsEmpty?: boolean;\n\t},\n): void {\n\tif (input === undefined) {\n\t\treturn;\n\t}\n\tappendConstraintExtensions(encoded, seen, input, options.includeBasicConstraints);\n\tappendIdentityExtensions(encoded, seen, input, options.subjectIsEmpty === true);\n\tappendPolicyExtensions(encoded, seen, input);\n\tappendAccessExtensions(encoded, seen, input);\n\tappendCustomExtensions(encoded, seen, input, context);\n}\n\nfunction appendConstraintExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n\tincludeBasicConstraints: boolean,\n): void {\n\tif (includeBasicConstraints && input.basicConstraints !== undefined) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tBASIC_CONSTRAINTS_EXTENSION_DEFINITION,\n\t\t\tinput.basicConstraints,\n\t\t);\n\t}\n\tif (input.keyUsage !== undefined && input.keyUsage.length > 0) {\n\t\tpushKnownExtension(encoded, seen, KEY_USAGE_EXTENSION_DEFINITION, input.keyUsage);\n\t}\n\tif (input.nameConstraints !== undefined) {\n\t\tpushKnownExtension(encoded, seen, NAME_CONSTRAINTS_EXTENSION_DEFINITION, input.nameConstraints);\n\t}\n}\n\nfunction appendIdentityExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n\tsubjectIsEmpty: boolean,\n): void {\n\tif (input.subjectAltNames !== undefined && input.subjectAltNames.length > 0) {\n\t\t// RFC 5280 §4.2.1.6: SAN MUST be critical when subject DN is empty.\n\t\tconst sanCritical = subjectIsEmpty ? true : undefined;\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tSUBJECT_ALT_NAME_EXTENSION_DEFINITION,\n\t\t\tinput.subjectAltNames,\n\t\t\tsanCritical,\n\t\t);\n\t}\n\tif (input.extendedKeyUsage !== undefined && input.extendedKeyUsage.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tEXTENDED_KEY_USAGE_EXTENSION_DEFINITION,\n\t\t\tinput.extendedKeyUsage,\n\t\t);\n\t}\n}\n\n/** Appends configured certificate-policy extensions while enforcing unique OIDs. */\nfunction appendPolicyExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n): void {\n\tif (input.certificatePolicies !== undefined && input.certificatePolicies.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tCERTIFICATE_POLICIES_EXTENSION_DEFINITION,\n\t\t\tinput.certificatePolicies,\n\t\t);\n\t}\n\tif (input.policyMappings !== undefined && input.policyMappings.length > 0) {\n\t\tpushKnownExtension(encoded, seen, POLICY_MAPPINGS_EXTENSION_DEFINITION, input.policyMappings);\n\t}\n\tif (input.policyConstraints !== undefined) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tPOLICY_CONSTRAINTS_EXTENSION_DEFINITION,\n\t\t\tinput.policyConstraints,\n\t\t);\n\t}\n\tif (input.inhibitAnyPolicy !== undefined) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tINHIBIT_ANY_POLICY_EXTENSION_DEFINITION,\n\t\t\tinput.inhibitAnyPolicy,\n\t\t);\n\t}\n}\n\nfunction appendAccessExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n): void {\n\tif (input.authorityInfoAccess !== undefined && input.authorityInfoAccess.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tAUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION,\n\t\t\tinput.authorityInfoAccess,\n\t\t);\n\t}\n\tif (input.crlDistributionPoints !== undefined && input.crlDistributionPoints.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tCRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION,\n\t\t\tinput.crlDistributionPoints,\n\t\t);\n\t}\n}\n\nfunction appendCustomExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n\tcontext: ExtensionRegistryContext,\n): void {\n\tif (input.customExtensions !== undefined) {\n\t\tfor (const extension of input.customExtensions) {\n\t\t\tconst knownDefinition = getExtensionDefinition(extension.oid);\n\t\t\tif (knownDefinition !== undefined && !knownDefinition.contexts.includes(context)) {\n\t\t\t\tthrow new Error(`Extension ${extension.oid} is not supported in ${context} context`);\n\t\t\t}\n\t\t\tpushExtension(\n\t\t\t\tencoded,\n\t\t\t\tseen,\n\t\t\t\textension.oid,\n\t\t\t\tnew Uint8Array(extension.value),\n\t\t\t\textension.critical ?? false,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/** Encode a known extension via its registry definition and push it. */\nfunction pushKnownExtension<TParsed, TInput>(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tdefinition: ExtensionDefinition<TParsed, TInput>,\n\tvalue: TInput,\n\tcritical = definition.defaultCritical,\n): void {\n\tpushExtension(encoded, seen, definition.oid, definition.encode(value), critical);\n}\n\n/**\n * Encode a single X.509 Extension SEQUENCE (OID + optional critical BOOLEAN + OCTET STRING).\n *\n * @param oid Dotted-decimal extension OID.\n * @param extnValue DER-encoded extension payload.\n * @param critical Whether to mark the extension as critical. Default `false`.\n */\nexport function encodeExtension(oid: string, extnValue: Uint8Array, critical = false): Uint8Array {\n\tconst fields = [objectIdentifier(oid)];\n\tif (critical) {\n\t\tfields.push(bool(true));\n\t}\n\tfields.push(octetString(extnValue));\n\treturn sequence(fields);\n}\n\n/**\n * DER-encode a {@linkcode BasicConstraints} value.\n *\n * @param input CA flag and optional pathLength.\n * @returns DER SEQUENCE suitable for wrapping in an Extension OCTET STRING.\n */\nexport function encodeBasicConstraints(input: BasicConstraints): Uint8Array {\n\tconst fields: Uint8Array[] = [];\n\tif (input.ca) {\n\t\tfields.push(bool(true));\n\t}\n\tif (input.pathLength !== undefined) {\n\t\tif (!input.ca) {\n\t\t\tthrow new Error('pathLength requires ca=true');\n\t\t}\n\t\tfields.push(integerFromNumber(input.pathLength));\n\t}\n\treturn sequence(fields);\n}\n\n/**\n * DER-encode a Key Usage BIT STRING from an array of {@linkcode KeyUsage} flags.\n *\n * @param usages Flags to set in the bit string.\n */\nexport function encodeKeyUsage(usages: readonly KeyUsage[]): Uint8Array {\n\treturn encodeKeyUsageExtension(usages);\n}\n\n/**\n * DER-encode a single {@linkcode SubjectAltName} GeneralName element.\n *\n * @param value The SAN entry to encode.\n */\nexport function encodeSubjectAltName(value: SubjectAltName): Uint8Array {\n\tswitch (value.type) {\n\t\tcase 'dns':\n\t\t\treturn implicitPrimitiveContext(2, new TextEncoder().encode(value.value));\n\t\tcase 'email':\n\t\t\treturn implicitPrimitiveContext(1, new TextEncoder().encode(value.value));\n\t\tcase 'uri':\n\t\t\treturn implicitPrimitiveContext(6, new TextEncoder().encode(value.value));\n\t\tcase 'srv':\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tsequence([objectIdentifier(OIDS.idOnDnsSrv), explicitContext(0, ia5String(value.value))]),\n\t\t\t);\n\t\tcase 'ip':\n\t\t\treturn implicitPrimitiveContext(7, encodeIpAddress(value.value));\n\t\tcase 'directoryName':\n\t\t\treturn implicitConstructedContext(4, extractDirectoryNameContent(value.derHex));\n\t\tcase 'unknown':\n\t\t\treturn tlv(value.tag, value.value);\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = value;\n\t\t\tthrow new Error(`Unhandled SubjectAltName type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/**\n * DER-encode an Extended Key Usage SEQUENCE OF OIDs.\n *\n * @param usages EKU purposes to encode.\n */\nexport function encodeExtendedKeyUsage(usages: readonly ExtendedKeyUsage[]): Uint8Array {\n\treturn sequence(usages.map((usage) => objectIdentifier(getExtendedKeyUsageOid(usage))));\n}\n\n/**\n * DER-encode an Authority Information Access SEQUENCE.\n *\n * @param entries AIA entries (OCSP, caIssuers, or custom) to encode.\n */\nexport function encodeAuthorityInfoAccess(\n\tentries: readonly AuthorityInformationAccess[],\n): Uint8Array {\n\treturn sequence(\n\t\tentries.map((entry) =>\n\t\t\tsequence([\n\t\t\t\tobjectIdentifier(getAuthorityInfoAccessMethodOid(entry.method)),\n\t\t\t\timplicitPrimitiveContext(6, new TextEncoder().encode(entry.uri)),\n\t\t\t]),\n\t\t),\n\t);\n}\n\n/**\n * DER-encode a CRL Distribution Points SEQUENCE.\n *\n * @param points Distribution points to encode.\n */\nexport function encodeCrlDistributionPoints(points: readonly DistributionPoint[]): Uint8Array {\n\treturn sequence(points.map((point) => sequence(encodeDistributionPoint(point))));\n}\n\n/**\n * DER-encode a Name Constraints extension value.\n *\n * @param constraints Permitted and/or excluded subtrees.\n */\nexport function encodeNameConstraints(constraints: NameConstraints): Uint8Array {\n\tconst parts: Uint8Array[] = [];\n\tif (constraints.permittedSubtrees !== undefined && constraints.permittedSubtrees.length > 0) {\n\t\tparts.push(\n\t\t\timplicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes(constraints.permittedSubtrees.map(encodeGeneralSubtree)),\n\t\t\t),\n\t\t);\n\t}\n\tif (constraints.excludedSubtrees !== undefined && constraints.excludedSubtrees.length > 0) {\n\t\tparts.push(\n\t\t\timplicitConstructedContext(\n\t\t\t\t1,\n\t\t\t\tconcatBytes(constraints.excludedSubtrees.map(encodeGeneralSubtree)),\n\t\t\t),\n\t\t);\n\t}\n\treturn sequence(parts);\n}\n\n/**\n * DER-encode a Certificate Policies extension value.\n *\n * @param policies Non-empty array of policy information entries.\n */\nexport function encodeCertificatePolicies(policies: CertificatePolicies): Uint8Array {\n\tif (policies.length === 0) {\n\t\tthrow new Error('certificatePolicies must not be empty');\n\t}\n\treturn sequence(policies.map(encodePolicyInformation));\n}\n\n/**\n * DER-encode a Policy Mappings extension value.\n *\n * @param mappings Non-empty array of issuer-to-subject policy pairs. Neither OID may be anyPolicy.\n */\nexport function encodePolicyMappings(mappings: PolicyMappings): Uint8Array {\n\tif (mappings.length === 0) {\n\t\tthrow new Error('policyMappings must not be empty');\n\t}\n\treturn sequence(\n\t\tmappings.map((mapping) => {\n\t\t\tvalidatePolicyOid(mapping.issuerDomainPolicy);\n\t\t\tvalidatePolicyOid(mapping.subjectDomainPolicy);\n\t\t\tif (\n\t\t\t\tmapping.issuerDomainPolicy === OIDS.anyPolicy ||\n\t\t\t\tmapping.subjectDomainPolicy === OIDS.anyPolicy\n\t\t\t) {\n\t\t\t\tthrow new Error('policyMappings must not use anyPolicy');\n\t\t\t}\n\t\t\treturn sequence([\n\t\t\t\tobjectIdentifier(mapping.issuerDomainPolicy),\n\t\t\t\tobjectIdentifier(mapping.subjectDomainPolicy),\n\t\t\t]);\n\t\t}),\n\t);\n}\n\n/**\n * DER-encode a Policy Constraints extension value.\n *\n * @param constraints At least one of `requireExplicitPolicy` or `inhibitPolicyMapping` must be set.\n */\nexport function encodePolicyConstraints(constraints: PolicyConstraints): Uint8Array {\n\tconst fields: Uint8Array[] = [];\n\tif (constraints.requireExplicitPolicy !== undefined) {\n\t\tfields.push(\n\t\t\timplicitPrimitiveContext(0, encodeIntegerContent(constraints.requireExplicitPolicy)),\n\t\t);\n\t}\n\tif (constraints.inhibitPolicyMapping !== undefined) {\n\t\tfields.push(\n\t\t\timplicitPrimitiveContext(1, encodeIntegerContent(constraints.inhibitPolicyMapping)),\n\t\t);\n\t}\n\tif (fields.length === 0) {\n\t\tthrow new Error('policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping');\n\t}\n\treturn sequence(fields);\n}\n\n/**\n * DER-encode an Inhibit anyPolicy extension value (single INTEGER).\n *\n * @param input The skipCerts threshold.\n */\nexport function encodeInhibitAnyPolicy(input: InhibitAnyPolicy): Uint8Array {\n\treturn integerFromNumber(input.skipCerts);\n}\n\n/** DER-encode a single PolicyInformation SEQUENCE. */\nfunction encodePolicyInformation(policy: PolicyInformation): Uint8Array {\n\tvalidatePolicyOid(policy.policyIdentifier);\n\tconst fields = [objectIdentifier(policy.policyIdentifier)];\n\tif (policy.policyQualifiers !== undefined && policy.policyQualifiers.length > 0) {\n\t\tfields.push(sequence(policy.policyQualifiers.map(encodePolicyQualifierInfo)));\n\t}\n\treturn sequence(fields);\n}\n\n/** DER-encode a single PolicyQualifierInfo SEQUENCE. */\nfunction encodePolicyQualifierInfo(qualifier: PolicyQualifierInfo): Uint8Array {\n\tswitch (qualifier.type) {\n\t\tcase 'cps':\n\t\t\treturn sequence([objectIdentifier(OIDS.cpsPolicyQualifier), ia5String(qualifier.uri)]);\n\t\tcase 'userNotice':\n\t\t\treturn sequence([\n\t\t\t\tobjectIdentifier(OIDS.userNoticePolicyQualifier),\n\t\t\t\tencodeUserNoticePolicyQualifierInfo(qualifier),\n\t\t\t]);\n\t\tcase 'oid':\n\t\t\tvalidateOid(qualifier.oid);\n\t\t\treturn sequence([objectIdentifier(qualifier.oid), new Uint8Array(qualifier.qualifierDer)]);\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = qualifier;\n\t\t\tthrow new Error(`Unhandled PolicyQualifierInfo type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/** DER-encode a UserNotice qualifier SEQUENCE. */\nfunction encodeUserNoticePolicyQualifierInfo(qualifier: UserNoticePolicyQualifierInfo): Uint8Array {\n\tconst fields: Uint8Array[] = [];\n\tif (qualifier.noticeRef !== undefined) {\n\t\tfields.push(encodePolicyNoticeReference(qualifier.noticeRef));\n\t}\n\tif (qualifier.explicitText !== undefined) {\n\t\tfields.push(utf8String(qualifier.explicitText));\n\t}\n\treturn sequence(fields);\n}\n\n/** DER-encode a NoticeReference SEQUENCE. */\nfunction encodePolicyNoticeReference(reference: PolicyNoticeReference): Uint8Array {\n\treturn sequence([\n\t\tutf8String(reference.organization),\n\t\tsequence(reference.noticeNumbers.map((noticeNumber) => integerFromNumber(noticeNumber))),\n\t]);\n}\n\n/** Encode an INTEGER and return only the content bytes (no TLV wrapper). */\nfunction encodeIntegerContent(value: number): Uint8Array {\n\treturn readElement(integerFromNumber(value)).value;\n}\n\n/** DER-encode a GeneralSubtree SEQUENCE (base name only; min/max omitted per RFC 5280). */\nfunction encodeGeneralSubtree(subtree: GeneralSubtree): Uint8Array {\n\treturn sequence([encodeNameConstraintForm(subtree.base)]);\n}\n\n/** DER-encode the fields of a single DistributionPoint. */\nfunction encodeDistributionPoint(point: DistributionPoint): Uint8Array[] {\n\tif (point.crlIssuer !== undefined && point.crlIssuer.length === 0) {\n\t\tthrow new Error('DistributionPoint crlIssuer must not be empty');\n\t}\n\tif (point.distributionPoint === undefined && point.crlIssuer === undefined) {\n\t\tthrow new Error('DistributionPoint must contain distributionPoint or crlIssuer');\n\t}\n\tconst fields: Uint8Array[] = [];\n\tif (point.distributionPoint !== undefined) {\n\t\tfields.push(\n\t\t\timplicitConstructedContext(0, encodeDistributionPointName(point.distributionPoint)),\n\t\t);\n\t}\n\tif (point.reasons !== undefined && point.reasons.length > 0) {\n\t\tfields.push(\n\t\t\timplicitPrimitiveContext(1, encodeDistributionPointReasonFlagsContent(point.reasons)),\n\t\t);\n\t}\n\tif (point.crlIssuer !== undefined && point.crlIssuer.length > 0) {\n\t\tfields.push(\n\t\t\timplicitConstructedContext(2, concatBytes(point.crlIssuer.map(encodeSubjectAltName))),\n\t\t);\n\t}\n\treturn fields;\n}\n\n/** DER-encode a DistributionPointName (fullName or relativeName). */\nfunction encodeDistributionPointName(name: DistributionPointName): Uint8Array {\n\tif (name.fullName !== undefined && name.relativeName !== undefined) {\n\t\tthrow new Error('DistributionPointName cannot contain both fullName and relativeName');\n\t}\n\tif (name.fullName !== undefined) {\n\t\tif (name.fullName.length === 0) {\n\t\t\tthrow new Error('DistributionPointName fullName must not be empty');\n\t\t}\n\t\treturn implicitConstructedContext(0, concatBytes(name.fullName.map(encodeSubjectAltName)));\n\t}\n\tif (name.relativeName !== undefined) {\n\t\tconst relativeName = encodeRelativeDistinguishedName(name.relativeName);\n\t\tconst relativeNameElement = readElement(relativeName);\n\t\treturn implicitConstructedContext(\n\t\t\t1,\n\t\t\trelativeName.slice(relativeNameElement.start, relativeNameElement.end),\n\t\t);\n\t}\n\tthrow new Error('DistributionPointName must contain fullName or relativeName');\n}\n\n/** DER-encode a NameConstraintForm as an implicit-tagged {@linkcode GeneralName}. */\nfunction encodeNameConstraintForm(form: NameConstraintForm): Uint8Array {\n\tswitch (form.type) {\n\t\tcase 'dns':\n\t\t\treturn implicitPrimitiveContext(2, new TextEncoder().encode(form.value));\n\t\tcase 'email':\n\t\t\treturn implicitPrimitiveContext(1, new TextEncoder().encode(form.value));\n\t\tcase 'uri':\n\t\t\treturn implicitPrimitiveContext(6, new TextEncoder().encode(form.value));\n\t\tcase 'ip':\n\t\t\treturn implicitPrimitiveContext(7, concatBytes([form.addressBytes, form.maskBytes]));\n\t\tcase 'directoryName':\n\t\t\treturn implicitConstructedContext(4, extractDirectoryNameContent(form.derHex));\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = form;\n\t\t\tthrow new Error(`Unhandled NameConstraintForm type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/** Extract the content bytes from a hex-encoded DER SEQUENCE (strips the outer TLV). */\nfunction extractDirectoryNameContent(derHex: string): Uint8Array {\n\tconst element = readRootElement(hexToBytes(derHex), { maxDepth: DEFAULT_MAX_DER_DEPTH });\n\tif (element.tag !== 0x30) {\n\t\tthrow new Error('directoryName derHex must encode a DER SEQUENCE');\n\t}\n\treturn new Uint8Array(element.value);\n}\n\n/**\n * Resolve an {@linkcode ExtendedKeyUsage} to its dotted-decimal OID.\n *\n * @param usage Well-known string or custom OID object.\n */\nexport function getExtendedKeyUsageOid(usage: ExtendedKeyUsage): string {\n\tif (typeof usage === 'string') {\n\t\treturn EXTENDED_KEY_USAGE_OIDS[usage];\n\t}\n\tvalidateOid(usage.value);\n\treturn usage.value;\n}\n\n/**\n * Map a dotted-decimal OID to an {@linkcode ExtendedKeyUsage} value.\n *\n * Returns a well-known string for recognized OIDs, or `{ type: 'oid', value }` otherwise.\n */\nexport function parseExtendedKeyUsageOid(oid: string): ExtendedKeyUsage {\n\tswitch (oid) {\n\t\tcase OIDS.serverAuth:\n\t\t\treturn 'serverAuth';\n\t\tcase OIDS.clientAuth:\n\t\t\treturn 'clientAuth';\n\t\tcase OIDS.codeSigning:\n\t\t\treturn 'codeSigning';\n\t\tcase OIDS.emailProtection:\n\t\t\treturn 'emailProtection';\n\t\tcase OIDS.timeStamping:\n\t\t\treturn 'timeStamping';\n\t\tcase OIDS.ocspSigning:\n\t\t\treturn 'ocspSigning';\n\t}\n\treturn { type: 'oid', value: oid };\n}\n\n/**\n * Resolve an {@linkcode AuthorityInfoAccessMethod} to its dotted-decimal OID.\n *\n * @param method Well-known string or custom OID object.\n */\nexport function getAuthorityInfoAccessMethodOid(method: AuthorityInfoAccessMethod): string {\n\tif (typeof method === 'string') {\n\t\treturn AUTHORITY_INFO_ACCESS_METHOD_OIDS[method];\n\t}\n\tvalidateOid(method.value);\n\treturn method.value;\n}\n\n/**\n * Map a dotted-decimal OID to an {@linkcode AuthorityInfoAccessMethod} value.\n *\n * Returns `'ocsp'` or `'caIssuers'` for recognized OIDs, or `{ type: 'oid', value }` otherwise.\n */\nexport function parseAuthorityInfoAccessMethodOid(oid: string): AuthorityInfoAccessMethod {\n\tswitch (oid) {\n\t\tcase OIDS.ocspAccessMethod:\n\t\t\treturn 'ocsp';\n\t\tcase OIDS.caIssuersAccessMethod:\n\t\t\treturn 'caIssuers';\n\t}\n\treturn { type: 'oid', value: oid };\n}\n\n/** Parse a dotted-decimal/colon-hex IP string to raw address bytes. */\nfunction encodeIpAddress(input: string): Uint8Array {\n\treturn parseIpAddressToBytes(input);\n}\n\n/** @internal Compute the SKI as SHA-1 of the subjectPublicKey BIT STRING content. */\nexport function buildSubjectKeyIdentifier(subjectPublicKeyInfo: Uint8Array): Uint8Array {\n\tconst topLevel = readSequenceChildren(subjectPublicKeyInfo);\n\tconst subjectPublicKey = topLevel[1];\n\tif (subjectPublicKey === undefined || subjectPublicKey.tag !== 0x03) {\n\t\tthrow new Error('SPKI missing subject public key bit string');\n\t}\n\tconst publicKeyBytes = subjectPublicKey.value.slice(1);\n\treturn sha1(publicKeyBytes);\n}\n\n/** Throw if the string is not a valid dotted-decimal OID. */\nfunction validateOid(oid: string): void {\n\tif (!/^\\d+(?:\\.\\d+)+$/.test(oid)) {\n\t\tthrow new Error(`Invalid OID: ${oid}`);\n\t}\n}\n\n/** Validate that a policy OID is syntactically valid. */\nfunction validatePolicyOid(oid: string): void {\n\tvalidateOid(oid);\n}\n\n/** Encode and push an extension, rejecting duplicate OIDs. */\nfunction pushExtension(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\toid: string,\n\tvalue: Uint8Array,\n\tcritical = false,\n): void {\n\tvalidateOid(oid);\n\tif (seen.has(oid)) {\n\t\tthrow new Error(`Duplicate extension OID: ${oid}`);\n\t}\n\tseen.add(oid);\n\tencoded.push(encodeExtension(oid, value, critical));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqqBA,MAAM,IAAiE;CACtE,YAAY,EAAK;CACjB,YAAY,EAAK;CACjB,aAAa,EAAK;CAClB,iBAAiB,EAAK;CACtB,cAAc,EAAK;CACnB,aAAa,EAAK;AACnB,GAGM,IAAoF;CACzF,MAAM,EAAK;CACX,WAAW,EAAK;AACjB;;;;;;;;;;;;;;;AAgBA,SAAgB,2BACf,GACA,GACA,GACA,IAAiB,IACF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OAAO;EACR,KAAK,EAAK,aACT,OAAO;EACR,KAAK,EAAK,iBACT,OAAO;EACR,KAAK,EAAK,cACT,OAAO;EACR,KAAK,EAAK,aACT,OAAO;CACT;CACA,OAAO;EAAE,MAAM;EAAO,OAAO;CAAI;AAClC;;;;;;AAOA,SAAgB,gCAAgC,GAA2C;CAK1F,OAJI,OAAO,KAAW,WACd,EAAkC,MAE1C,YAAY,EAAO,KAAK,GACjB,EAAO;AACf;;;;;;AAOA,SAAgB,kCAAkC,GAAwC;CACzF,QAAQ,GAAR;EACC,KAAK,EAAK,kBACT,OAAO;EACR,KAAK,EAAK,uBACT,OAAO;CACT;CACA,OAAO;EAAE,MAAM;EAAO,OAAO;CAAI;AAClC;;AAGA,SAAS,gBAAgB,GAA2B;CACnD,OAAO,EAAsB,CAAK;AACnC;;AAGA,SAAgB,0BAA0B,GAA8C;CAEvF,IAAM,IADW,EAAqB,CACN,CAAC,CAAC;CAClC,IAAI,MAAqB,KAAA,KAAa,EAAiB,QAAQ,GAC9D,MAAU,MAAM,4CAA4C;CAG7D,OAAO,EADgB,EAAiB,MAAM,MAAM,CAC3B,CAAC;AAC3B;;AAGA,SAAS,YAAY,GAAmB;CACvC,IAAI,CAAC,kBAAkB,KAAK,CAAG,GAC9B,MAAU,MAAM,gBAAgB,GAAK;AAEvC;;AAGA,SAAS,kBAAkB,GAAmB;CAC7C,YAAY,CAAG;AAChB;;AAGA,SAAS,cACR,GACA,GACA,GACA,GACA,IAAW,IACJ;CAEP,IADA,YAAY,CAAG,GACX,EAAK,IAAI,CAAG,GACf,MAAU,MAAM,4BAA4B,GAAK;CAGlD,AADA,EAAK,IAAI,CAAG,GACZ,EAAQ,KAAK,gBAAgB,GAAK,GAAO,CAAQ,CAAC;AACnD"}
|
|
@@ -32,6 +32,9 @@ interface CertificateFingerprint {
|
|
|
32
32
|
* a well-formed certificate. Malformed input throws, matching the other DER/PEM
|
|
33
33
|
* boundaries in the library.
|
|
34
34
|
*
|
|
35
|
+
* **Asynchronous:** hashing uses WebCrypto's `crypto.subtle.digest`. Await the
|
|
36
|
+
* returned promise before reading `bytes`, `hex`, or `colonHex`.
|
|
37
|
+
*
|
|
35
38
|
* @example
|
|
36
39
|
* ```ts
|
|
37
40
|
* const fingerprint = await certificateFingerprint(pemString);
|
package/dist/x509/fingerprint.js
CHANGED
|
@@ -20,6 +20,9 @@ import { parseCertificateFromSource as r } from "./parse.js";
|
|
|
20
20
|
* a well-formed certificate. Malformed input throws, matching the other DER/PEM
|
|
21
21
|
* boundaries in the library.
|
|
22
22
|
*
|
|
23
|
+
* **Asynchronous:** hashing uses WebCrypto's `crypto.subtle.digest`. Await the
|
|
24
|
+
* returned promise before reading `bytes`, `hex`, or `colonHex`.
|
|
25
|
+
*
|
|
23
26
|
* @example
|
|
24
27
|
* ```ts
|
|
25
28
|
* const fingerprint = await certificateFingerprint(pemString);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fingerprint.js","names":[],"sources":["../../src/x509/fingerprint.ts"],"sourcesContent":["/**\n * Certificate fingerprints: a cryptographic hash over the DER encoding.\n *\n * This is the identifier that `openssl x509 -fingerprint` and every TLS UI show.\n * The helper accepts the same PEM / DER / parsed-certificate source union as\n * the verification APIs and returns the digest in the forms callers actually\n * paste around: raw bytes, lowercase hex, and uppercase colon-separated hex.\n *\n * @module\n */\n\nimport { toArrayBuffer, toHex } from '#micro509/internal/asn1/asn1';\nimport { getCrypto } from '#micro509/internal/crypto/webcrypto';\nimport type { ParsedCertificate } from '#micro509/x509/parse';\nimport { parseCertificateFromSource } from '#micro509/x509/parse';\n\n/**\n * A PEM string, raw DER bytes, or an already-parsed certificate.\n *\n * Mirrors the source union accepted by the verification, revocation, and\n * PKCS APIs so a fingerprint can be taken from whatever a caller already holds.\n */\nexport type CertificateFingerprintSource = string | Uint8Array | ParsedCertificate;\n\n/**\n * Digest algorithms supported by {@linkcode certificateFingerprint}.\n *\n * SHA-1 is intentionally included: legacy ecosystems (PGP-adjacent tooling,\n * older certificate pinning) still identify certificates by their SHA-1\n * fingerprint. Prefer SHA-256 for anything new.\n */\nexport type CertificateFingerprintAlgorithm = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';\n\n/** The three rendered forms of a certificate fingerprint. */\nexport interface CertificateFingerprint {\n\t/** Raw digest bytes. */\n\treadonly bytes: Uint8Array;\n\t/** Lowercase hex, no separators (e.g. `\"a1b2c3…\"`). */\n\treadonly hex: string;\n\t/** Uppercase hex, colon-separated (e.g. `\"A1:B2:C3:…\"`, `openssl x509 -fingerprint` style). */\n\treadonly colonHex: string;\n}\n\n/**\n * Compute a certificate fingerprint — a hash over the DER encoding.\n *\n * The certificate is parsed (validating the input and, for PEM, decoding it to\n * DER) before hashing, so the digest is always taken over the canonical DER of\n * a well-formed certificate. Malformed input throws, matching the other DER/PEM\n * boundaries in the library.\n *\n * @example\n * ```ts\n * const fingerprint = await certificateFingerprint(pemString);\n * console.log(fingerprint.colonHex); // \"AB:CD:…\" — matches `openssl x509 -fingerprint -sha256`\n * ```\n *\n * @example\n * ```ts\n * // Reuse an already-parsed certificate and request SHA-1.\n * const parsed = parseCertificatePemOrThrow(pemString);\n * const legacy = await certificateFingerprint(parsed, 'SHA-1');\n * console.log(legacy.hex);\n * ```\n *\n * @param certificate PEM string, DER bytes, or a {@linkcode ParsedCertificate}.\n * @param algorithm Digest algorithm to use. Defaults to `'SHA-256'`.\n */\nexport async function certificateFingerprint(\n\tcertificate: CertificateFingerprintSource,\n\talgorithm: CertificateFingerprintAlgorithm = 'SHA-256',\n): Promise<CertificateFingerprint> {\n\tconst { der } = parseCertificateFromSource(certificate);\n\tconst digest = await getCrypto().subtle.digest(algorithm, toArrayBuffer(der));\n\tconst bytes = new Uint8Array(digest);\n\treturn {\n\t\tbytes,\n\t\thex: toHex(bytes),\n\t\tcolonHex: toColonHex(bytes),\n\t};\n}\n\n/** Renders bytes as uppercase, colon-separated hex (openssl fingerprint style). */\nfunction toColonHex(bytes: Uint8Array): string {\n\treturn Array.from(bytes, (value) => value.toString(16).padStart(2, '0').toUpperCase()).join(':');\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"fingerprint.js","names":[],"sources":["../../src/x509/fingerprint.ts"],"sourcesContent":["/**\n * Certificate fingerprints: a cryptographic hash over the DER encoding.\n *\n * This is the identifier that `openssl x509 -fingerprint` and every TLS UI show.\n * The helper accepts the same PEM / DER / parsed-certificate source union as\n * the verification APIs and returns the digest in the forms callers actually\n * paste around: raw bytes, lowercase hex, and uppercase colon-separated hex.\n *\n * @module\n */\n\nimport { toArrayBuffer, toHex } from '#micro509/internal/asn1/asn1';\nimport { getCrypto } from '#micro509/internal/crypto/webcrypto';\nimport type { ParsedCertificate } from '#micro509/x509/parse';\nimport { parseCertificateFromSource } from '#micro509/x509/parse';\n\n/**\n * A PEM string, raw DER bytes, or an already-parsed certificate.\n *\n * Mirrors the source union accepted by the verification, revocation, and\n * PKCS APIs so a fingerprint can be taken from whatever a caller already holds.\n */\nexport type CertificateFingerprintSource = string | Uint8Array | ParsedCertificate;\n\n/**\n * Digest algorithms supported by {@linkcode certificateFingerprint}.\n *\n * SHA-1 is intentionally included: legacy ecosystems (PGP-adjacent tooling,\n * older certificate pinning) still identify certificates by their SHA-1\n * fingerprint. Prefer SHA-256 for anything new.\n */\nexport type CertificateFingerprintAlgorithm = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';\n\n/** The three rendered forms of a certificate fingerprint. */\nexport interface CertificateFingerprint {\n\t/** Raw digest bytes. */\n\treadonly bytes: Uint8Array;\n\t/** Lowercase hex, no separators (e.g. `\"a1b2c3…\"`). */\n\treadonly hex: string;\n\t/** Uppercase hex, colon-separated (e.g. `\"A1:B2:C3:…\"`, `openssl x509 -fingerprint` style). */\n\treadonly colonHex: string;\n}\n\n/**\n * Compute a certificate fingerprint — a hash over the DER encoding.\n *\n * The certificate is parsed (validating the input and, for PEM, decoding it to\n * DER) before hashing, so the digest is always taken over the canonical DER of\n * a well-formed certificate. Malformed input throws, matching the other DER/PEM\n * boundaries in the library.\n *\n * **Asynchronous:** hashing uses WebCrypto's `crypto.subtle.digest`. Await the\n * returned promise before reading `bytes`, `hex`, or `colonHex`.\n *\n * @example\n * ```ts\n * const fingerprint = await certificateFingerprint(pemString);\n * console.log(fingerprint.colonHex); // \"AB:CD:…\" — matches `openssl x509 -fingerprint -sha256`\n * ```\n *\n * @example\n * ```ts\n * // Reuse an already-parsed certificate and request SHA-1.\n * const parsed = parseCertificatePemOrThrow(pemString);\n * const legacy = await certificateFingerprint(parsed, 'SHA-1');\n * console.log(legacy.hex);\n * ```\n *\n * @param certificate PEM string, DER bytes, or a {@linkcode ParsedCertificate}.\n * @param algorithm Digest algorithm to use. Defaults to `'SHA-256'`.\n */\nexport async function certificateFingerprint(\n\tcertificate: CertificateFingerprintSource,\n\talgorithm: CertificateFingerprintAlgorithm = 'SHA-256',\n): Promise<CertificateFingerprint> {\n\tconst { der } = parseCertificateFromSource(certificate);\n\tconst digest = await getCrypto().subtle.digest(algorithm, toArrayBuffer(der));\n\tconst bytes = new Uint8Array(digest);\n\treturn {\n\t\tbytes,\n\t\thex: toHex(bytes),\n\t\tcolonHex: toColonHex(bytes),\n\t};\n}\n\n/** Renders bytes as uppercase, colon-separated hex (openssl fingerprint style). */\nfunction toColonHex(bytes: Uint8Array): string {\n\treturn Array.from(bytes, (value) => value.toString(16).padStart(2, '0').toUpperCase()).join(':');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,eAAsB,uBACrB,GACA,IAA6C,WACX;CAClC,IAAM,EAAE,WAAQ,EAA2B,CAAW,GAChD,IAAS,MAAM,EAAU,CAAC,CAAC,OAAO,OAAO,GAAW,EAAc,CAAG,CAAC,GACtE,IAAQ,IAAI,WAAW,CAAM;CACnC,OAAO;EACN;EACA,KAAK,EAAM,CAAK;EAChB,UAAU,WAAW,CAAK;CAC3B;AACD;;AAGA,SAAS,WAAW,GAA2B;CAC9C,OAAO,MAAM,KAAK,IAAQ,MAAU,EAAM,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,GAAG;AAChG"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { SubjectAltName } from "./extensions.js";
|
|
2
|
+
import { ParsedName, ParsedRelativeDistinguishedName } from "./parse.js";
|
|
3
|
+
//#region src/x509/name-text.d.ts
|
|
4
|
+
/** Options for {@linkcode subjectAltNameToString}. */
|
|
5
|
+
interface SubjectAltNameTextOptions {
|
|
6
|
+
/** Prepend `{@linkcode subjectAltNameLabel}:` to the value, as `openssl x509 -text` does. Defaults to `false`. */
|
|
7
|
+
readonly prefix?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Renders one {@linkcode SubjectAltName} as text.
|
|
11
|
+
*
|
|
12
|
+
* | variant | rendering |
|
|
13
|
+
* | --- | --- |
|
|
14
|
+
* | `dns`, `ip`, `email`, `uri`, `srv` | the value itself |
|
|
15
|
+
* | `directoryName` | {@linkcode distinguishedNameToString} of the embedded name, or the DER hex if it does not decode |
|
|
16
|
+
* | `unknown` | lowercase hex of the raw content bytes |
|
|
17
|
+
*
|
|
18
|
+
* @example Render every SAN of a parsed certificate
|
|
19
|
+
* ```ts
|
|
20
|
+
* const names = (parsed.subjectAltNames ?? []).map((name) => subjectAltNameToString(name));
|
|
21
|
+
* // ['example.com', '192.0.2.1', 'CN=Example CA,C=US']
|
|
22
|
+
*
|
|
23
|
+
* subjectAltNameToString({ type: 'dns', value: 'example.com' }, { prefix: true }); // 'DNS:example.com'
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare function subjectAltNameToString(name: SubjectAltName, options?: SubjectAltNameTextOptions): string;
|
|
27
|
+
/**
|
|
28
|
+
* The `openssl x509 -text` label for a {@linkcode SubjectAltName} variant —
|
|
29
|
+
* `DNS`, `IP Address`, `email`, `URI`, `SRV`, `DirName`, or `[tag <n>]` for an unrecognized tag.
|
|
30
|
+
*/
|
|
31
|
+
declare function subjectAltNameLabel(name: SubjectAltName): string;
|
|
32
|
+
/**
|
|
33
|
+
* Renders a {@linkcode ParsedName} as an RFC 4514 distinguished name string, e.g. `CN=Example CA,O=Acme,C=US`.
|
|
34
|
+
*
|
|
35
|
+
* RDNs are emitted in reverse encoding order and multi-valued RDNs are joined with `+`,
|
|
36
|
+
* both per RFC 4514 [§2](https://datatracker.ietf.org/doc/html/rfc4514#section-2).
|
|
37
|
+
* Attribute types outside the RFC 4514 [§3](https://datatracker.ietf.org/doc/html/rfc4514#section-3)
|
|
38
|
+
* keyword table use the short names `openssl` prints, falling back to the dotted OID.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* distinguishedNameToString(parsed.subject); // 'CN=example.com,O=Acme\\, Inc.,C=US'
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare function distinguishedNameToString(name: ParsedName): string;
|
|
46
|
+
/** Renders one {@linkcode ParsedRelativeDistinguishedName}, joining a multi-valued RDN's attributes with `+`. */
|
|
47
|
+
declare function relativeDistinguishedNameToString(rdn: ParsedRelativeDistinguishedName): string;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { SubjectAltNameTextOptions, distinguishedNameToString, relativeDistinguishedNameToString, subjectAltNameLabel, subjectAltNameToString };
|
|
50
|
+
//# sourceMappingURL=name-text.d.ts.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { hexToBytes as e, toHex as t } from "../internal/asn1/asn1.js";
|
|
2
|
+
import { DN_ATTRIBUTE_KEYWORDS as n } from "../internal/x509/name-fields.js";
|
|
3
|
+
import { parseDistinguishedNameDer as r } from "./parse.js";
|
|
4
|
+
//#region src/x509/name-text.ts
|
|
5
|
+
/**
|
|
6
|
+
* Human-readable text for parsed names.
|
|
7
|
+
*
|
|
8
|
+
* Renders a {@linkcode ParsedName} or {@linkcode SubjectAltName} as a display string,
|
|
9
|
+
* covering every variant of the union without the caller narrowing it by hand.
|
|
10
|
+
*
|
|
11
|
+
* @module micro509/x509/name-text
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Renders one {@linkcode SubjectAltName} as text.
|
|
15
|
+
*
|
|
16
|
+
* | variant | rendering |
|
|
17
|
+
* | --- | --- |
|
|
18
|
+
* | `dns`, `ip`, `email`, `uri`, `srv` | the value itself |
|
|
19
|
+
* | `directoryName` | {@linkcode distinguishedNameToString} of the embedded name, or the DER hex if it does not decode |
|
|
20
|
+
* | `unknown` | lowercase hex of the raw content bytes |
|
|
21
|
+
*
|
|
22
|
+
* @example Render every SAN of a parsed certificate
|
|
23
|
+
* ```ts
|
|
24
|
+
* const names = (parsed.subjectAltNames ?? []).map((name) => subjectAltNameToString(name));
|
|
25
|
+
* // ['example.com', '192.0.2.1', 'CN=Example CA,C=US']
|
|
26
|
+
*
|
|
27
|
+
* subjectAltNameToString({ type: 'dns', value: 'example.com' }, { prefix: true }); // 'DNS:example.com'
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function subjectAltNameToString(e, t) {
|
|
31
|
+
let n = subjectAltNameText(e);
|
|
32
|
+
return t?.prefix === !0 ? `${subjectAltNameLabel(e)}:${n}` : n;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The `openssl x509 -text` label for a {@linkcode SubjectAltName} variant —
|
|
36
|
+
* `DNS`, `IP Address`, `email`, `URI`, `SRV`, `DirName`, or `[tag <n>]` for an unrecognized tag.
|
|
37
|
+
*/
|
|
38
|
+
function subjectAltNameLabel(e) {
|
|
39
|
+
switch (e.type) {
|
|
40
|
+
case "dns": return "DNS";
|
|
41
|
+
case "ip": return "IP Address";
|
|
42
|
+
case "email": return "email";
|
|
43
|
+
case "uri": return "URI";
|
|
44
|
+
case "srv": return "SRV";
|
|
45
|
+
case "directoryName": return "DirName";
|
|
46
|
+
case "unknown": return `[tag ${String(e.tag)}]`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Renders a {@linkcode ParsedName} as an RFC 4514 distinguished name string, e.g. `CN=Example CA,O=Acme,C=US`.
|
|
51
|
+
*
|
|
52
|
+
* RDNs are emitted in reverse encoding order and multi-valued RDNs are joined with `+`,
|
|
53
|
+
* both per RFC 4514 [§2](https://datatracker.ietf.org/doc/html/rfc4514#section-2).
|
|
54
|
+
* Attribute types outside the RFC 4514 [§3](https://datatracker.ietf.org/doc/html/rfc4514#section-3)
|
|
55
|
+
* keyword table use the short names `openssl` prints, falling back to the dotted OID.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* distinguishedNameToString(parsed.subject); // 'CN=example.com,O=Acme\\, Inc.,C=US'
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
function distinguishedNameToString(e) {
|
|
63
|
+
return [...e.rdns].reverse().map((e) => relativeDistinguishedNameToString(e)).join(",");
|
|
64
|
+
}
|
|
65
|
+
/** Renders one {@linkcode ParsedRelativeDistinguishedName}, joining a multi-valued RDN's attributes with `+`. */
|
|
66
|
+
function relativeDistinguishedNameToString(e) {
|
|
67
|
+
return e.attributes.map((e) => attributeToString(e)).join("+");
|
|
68
|
+
}
|
|
69
|
+
/** Characters RFC 4514 [§2.4](https://datatracker.ietf.org/doc/html/rfc4514#section-2.4) escapes wherever they appear. */
|
|
70
|
+
const i = /* @__PURE__ */ new Set([
|
|
71
|
+
"\"",
|
|
72
|
+
"+",
|
|
73
|
+
",",
|
|
74
|
+
";",
|
|
75
|
+
"<",
|
|
76
|
+
">",
|
|
77
|
+
"\\"
|
|
78
|
+
]);
|
|
79
|
+
function attributeToString(e) {
|
|
80
|
+
return `${n[e.oid] ?? e.oid}=${escapeAttributeValue(e.value)}`;
|
|
81
|
+
}
|
|
82
|
+
function escapeAttributeValue(e) {
|
|
83
|
+
let t = [...e];
|
|
84
|
+
return t.map((e, n) => {
|
|
85
|
+
if (i.has(e)) return `\\${e}`;
|
|
86
|
+
let r = e.codePointAt(0) ?? 0;
|
|
87
|
+
return r < 32 || r === 127 ? `\\${r.toString(16).padStart(2, "0")}` : e === " " && (n === 0 || n === t.length - 1) ? "\\ " : e === "#" && n === 0 ? "\\#" : e;
|
|
88
|
+
}).join("");
|
|
89
|
+
}
|
|
90
|
+
function subjectAltNameText(e) {
|
|
91
|
+
switch (e.type) {
|
|
92
|
+
case "dns":
|
|
93
|
+
case "ip":
|
|
94
|
+
case "email":
|
|
95
|
+
case "uri":
|
|
96
|
+
case "srv": return e.value;
|
|
97
|
+
case "directoryName": return directoryNameText(e.derHex);
|
|
98
|
+
case "unknown": return t(e.value);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function directoryNameText(t) {
|
|
102
|
+
try {
|
|
103
|
+
return distinguishedNameToString(r(e(t)));
|
|
104
|
+
} catch {
|
|
105
|
+
return t;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
export { distinguishedNameToString, relativeDistinguishedNameToString, subjectAltNameLabel, subjectAltNameToString };
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=name-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name-text.js","names":[],"sources":["../../src/x509/name-text.ts"],"sourcesContent":["/**\n * Human-readable text for parsed names.\n *\n * Renders a {@linkcode ParsedName} or {@linkcode SubjectAltName} as a display string,\n * covering every variant of the union without the caller narrowing it by hand.\n *\n * @module micro509/x509/name-text\n */\n\nimport { hexToBytes, toHex } from '#micro509/internal/asn1/asn1';\nimport { DN_ATTRIBUTE_KEYWORDS } from '#micro509/internal/x509/name-fields';\nimport type { SubjectAltName } from '#micro509/x509/extensions';\nimport type {\n\tParsedName,\n\tParsedNameAttribute,\n\tParsedRelativeDistinguishedName,\n} from '#micro509/x509/parse';\nimport { parseDistinguishedNameDer } from '#micro509/x509/parse';\n\n/** Options for {@linkcode subjectAltNameToString}. */\nexport interface SubjectAltNameTextOptions {\n\t/** Prepend `{@linkcode subjectAltNameLabel}:` to the value, as `openssl x509 -text` does. Defaults to `false`. */\n\treadonly prefix?: boolean;\n}\n\n/**\n * Renders one {@linkcode SubjectAltName} as text.\n *\n * | variant | rendering |\n * | --- | --- |\n * | `dns`, `ip`, `email`, `uri`, `srv` | the value itself |\n * | `directoryName` | {@linkcode distinguishedNameToString} of the embedded name, or the DER hex if it does not decode |\n * | `unknown` | lowercase hex of the raw content bytes |\n *\n * @example Render every SAN of a parsed certificate\n * ```ts\n * const names = (parsed.subjectAltNames ?? []).map((name) => subjectAltNameToString(name));\n * // ['example.com', '192.0.2.1', 'CN=Example CA,C=US']\n *\n * subjectAltNameToString({ type: 'dns', value: 'example.com' }, { prefix: true }); // 'DNS:example.com'\n * ```\n */\nexport function subjectAltNameToString(\n\tname: SubjectAltName,\n\toptions?: SubjectAltNameTextOptions,\n): string {\n\tconst text = subjectAltNameText(name);\n\treturn options?.prefix === true ? `${subjectAltNameLabel(name)}:${text}` : text;\n}\n\n/**\n * The `openssl x509 -text` label for a {@linkcode SubjectAltName} variant —\n * `DNS`, `IP Address`, `email`, `URI`, `SRV`, `DirName`, or `[tag <n>]` for an unrecognized tag.\n */\nexport function subjectAltNameLabel(name: SubjectAltName): string {\n\tswitch (name.type) {\n\t\tcase 'dns':\n\t\t\treturn 'DNS';\n\t\tcase 'ip':\n\t\t\treturn 'IP Address';\n\t\tcase 'email':\n\t\t\treturn 'email';\n\t\tcase 'uri':\n\t\t\treturn 'URI';\n\t\tcase 'srv':\n\t\t\treturn 'SRV';\n\t\tcase 'directoryName':\n\t\t\treturn 'DirName';\n\t\tcase 'unknown':\n\t\t\treturn `[tag ${String(name.tag)}]`;\n\t}\n}\n\n/**\n * Renders a {@linkcode ParsedName} as an RFC 4514 distinguished name string, e.g. `CN=Example CA,O=Acme,C=US`.\n *\n * RDNs are emitted in reverse encoding order and multi-valued RDNs are joined with `+`,\n * both per RFC 4514 [§2](https://datatracker.ietf.org/doc/html/rfc4514#section-2).\n * Attribute types outside the RFC 4514 [§3](https://datatracker.ietf.org/doc/html/rfc4514#section-3)\n * keyword table use the short names `openssl` prints, falling back to the dotted OID.\n *\n * @example\n * ```ts\n * distinguishedNameToString(parsed.subject); // 'CN=example.com,O=Acme\\\\, Inc.,C=US'\n * ```\n */\nexport function distinguishedNameToString(name: ParsedName): string {\n\treturn [...name.rdns]\n\t\t.reverse()\n\t\t.map((rdn) => relativeDistinguishedNameToString(rdn))\n\t\t.join(',');\n}\n\n/** Renders one {@linkcode ParsedRelativeDistinguishedName}, joining a multi-valued RDN's attributes with `+`. */\nexport function relativeDistinguishedNameToString(rdn: ParsedRelativeDistinguishedName): string {\n\treturn rdn.attributes.map((attribute) => attributeToString(attribute)).join('+');\n}\n\n/** Characters RFC 4514 [§2.4](https://datatracker.ietf.org/doc/html/rfc4514#section-2.4) escapes wherever they appear. */\nconst ESCAPED_CHARACTERS = new Set(['\"', '+', ',', ';', '<', '>', '\\\\']);\n\nfunction attributeToString(attribute: ParsedNameAttribute): string {\n\tconst keyword = DN_ATTRIBUTE_KEYWORDS[attribute.oid] ?? attribute.oid;\n\treturn `${keyword}=${escapeAttributeValue(attribute.value)}`;\n}\n\nfunction escapeAttributeValue(value: string): string {\n\tconst characters = [...value];\n\treturn characters\n\t\t.map((character, index) => {\n\t\t\tif (ESCAPED_CHARACTERS.has(character)) {\n\t\t\t\treturn `\\\\${character}`;\n\t\t\t}\n\t\t\tconst code = character.codePointAt(0) ?? 0;\n\t\t\tif (code < 0x20 || code === 0x7f) {\n\t\t\t\treturn `\\\\${code.toString(16).padStart(2, '0')}`;\n\t\t\t}\n\t\t\tif (character === ' ' && (index === 0 || index === characters.length - 1)) {\n\t\t\t\treturn '\\\\ ';\n\t\t\t}\n\t\t\treturn character === '#' && index === 0 ? '\\\\#' : character;\n\t\t})\n\t\t.join('');\n}\n\nfunction subjectAltNameText(name: SubjectAltName): string {\n\tswitch (name.type) {\n\t\tcase 'dns':\n\t\tcase 'ip':\n\t\tcase 'email':\n\t\tcase 'uri':\n\t\tcase 'srv':\n\t\t\treturn name.value;\n\t\tcase 'directoryName':\n\t\t\treturn directoryNameText(name.derHex);\n\t\tcase 'unknown':\n\t\t\treturn toHex(name.value);\n\t}\n}\n\nfunction directoryNameText(derHex: string): string {\n\ttry {\n\t\treturn distinguishedNameToString(parseDistinguishedNameDer(hexToBytes(derHex)));\n\t} catch {\n\t\treturn derHex;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,uBACf,GACA,GACS;CACT,IAAM,IAAO,mBAAmB,CAAI;CACpC,OAAO,GAAS,WAAW,KAAO,GAAG,oBAAoB,CAAI,EAAE,GAAG,MAAS;AAC5E;;;;;AAMA,SAAgB,oBAAoB,GAA8B;CACjE,QAAQ,EAAK,MAAb;EACC,KAAK,OACJ,OAAO;EACR,KAAK,MACJ,OAAO;EACR,KAAK,SACJ,OAAO;EACR,KAAK,OACJ,OAAO;EACR,KAAK,OACJ,OAAO;EACR,KAAK,iBACJ,OAAO;EACR,KAAK,WACJ,OAAO,QAAQ,OAAO,EAAK,GAAG,EAAE;CAClC;AACD;;;;;;;;;;;;;;AAeA,SAAgB,0BAA0B,GAA0B;CACnE,OAAO,CAAC,GAAG,EAAK,IAAI,CAAC,CACnB,QAAQ,CAAC,CACT,KAAK,MAAQ,kCAAkC,CAAG,CAAC,CAAC,CACpD,KAAK,GAAG;AACX;;AAGA,SAAgB,kCAAkC,GAA8C;CAC/F,OAAO,EAAI,WAAW,KAAK,MAAc,kBAAkB,CAAS,CAAC,CAAC,CAAC,KAAK,GAAG;AAChF;;AAGA,MAAM,oBAAqB,IAAI,IAAI;CAAC;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AAAI,CAAC;AAEvE,SAAS,kBAAkB,GAAwC;CAElE,OAAO,GADS,EAAsB,EAAU,QAAQ,EAAU,IAChD,GAAG,qBAAqB,EAAU,KAAK;AAC1D;AAEA,SAAS,qBAAqB,GAAuB;CACpD,IAAM,IAAa,CAAC,GAAG,CAAK;CAC5B,OAAO,EACL,KAAK,GAAW,MAAU;EAC1B,IAAI,EAAmB,IAAI,CAAS,GACnC,OAAO,KAAK;EAEb,IAAM,IAAO,EAAU,YAAY,CAAC,KAAK;EAOzC,OANI,IAAO,MAAQ,MAAS,MACpB,KAAK,EAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,MAE1C,MAAc,QAAQ,MAAU,KAAK,MAAU,EAAW,SAAS,KAC/D,QAED,MAAc,OAAO,MAAU,IAAI,QAAQ;CACnD,CAAC,CAAC,CACD,KAAK,EAAE;AACV;AAEA,SAAS,mBAAmB,GAA8B;CACzD,QAAQ,EAAK,MAAb;EACC,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,OACJ,OAAO,EAAK;EACb,KAAK,iBACJ,OAAO,kBAAkB,EAAK,MAAM;EACrC,KAAK,WACJ,OAAO,EAAM,EAAK,KAAK;CACzB;AACD;AAEA,SAAS,kBAAkB,GAAwB;CAClD,IAAI;EACH,OAAO,0BAA0B,EAA0B,EAAW,CAAM,CAAC,CAAC;CAC/E,QAAQ;EACP,OAAO;CACR;AACD"}
|
package/dist/x509/parse.d.ts
CHANGED
|
@@ -361,6 +361,9 @@ declare function parseCertificatePemOrThrow<TMap extends ExtensionDecoderMap = R
|
|
|
361
361
|
* Expects a single `-----BEGIN CERTIFICATE-----` block. For bundles
|
|
362
362
|
* containing multiple certificates, use {@linkcode parseCertificateChainPem}.
|
|
363
363
|
*
|
|
364
|
+
* **Synchronous:** returns a {@linkcode ParseCertificateResult} directly. Do
|
|
365
|
+
* not `await` this function.
|
|
366
|
+
*
|
|
364
367
|
* @param pem PEM string with a CERTIFICATE block.
|
|
365
368
|
* @param options Custom extension decoders to apply during parsing.
|
|
366
369
|
*/
|
package/dist/x509/parse.js
CHANGED
|
@@ -195,6 +195,9 @@ function parseCertificatePemOrThrow(e, t) {
|
|
|
195
195
|
* Expects a single `-----BEGIN CERTIFICATE-----` block. For bundles
|
|
196
196
|
* containing multiple certificates, use {@linkcode parseCertificateChainPem}.
|
|
197
197
|
*
|
|
198
|
+
* **Synchronous:** returns a {@linkcode ParseCertificateResult} directly. Do
|
|
199
|
+
* not `await` this function.
|
|
200
|
+
*
|
|
198
201
|
* @param pem PEM string with a CERTIFICATE block.
|
|
199
202
|
* @param options Custom extension decoders to apply during parsing.
|
|
200
203
|
*/
|
|
@@ -829,6 +832,12 @@ function parseInhibitAnyPolicy(e) {
|
|
|
829
832
|
function parseSubjectAltNames(e) {
|
|
830
833
|
return i(e, f(n(e, { maxDepth: 64 }), "subjectAltName sequence")).map((t) => parseGeneralName(e, t));
|
|
831
834
|
}
|
|
835
|
+
/** @internal Decode a bare DER-encoded X.501 Name, as carried in a `directoryName` GeneralName. */
|
|
836
|
+
function parseDistinguishedNameDer(e) {
|
|
837
|
+
let t = f(n(e, { maxDepth: 64 }), "distinguished name sequence");
|
|
838
|
+
if (t.tag !== 48) throw Error("distinguished name must use SEQUENCE");
|
|
839
|
+
return parseName(e, t);
|
|
840
|
+
}
|
|
832
841
|
/** @internal Decode the Authority Information Access extension value. */
|
|
833
842
|
function parseAuthorityInfoAccess(e) {
|
|
834
843
|
let t = f(n(e, { maxDepth: 64 }), "authorityInfoAccess sequence");
|
|
@@ -1170,6 +1179,6 @@ function validateImplicitBitStringContent(e, t) {
|
|
|
1170
1179
|
if (i & (1 << n) - 1) throw Error(`${t} BIT STRING must not set padding bits`);
|
|
1171
1180
|
}
|
|
1172
1181
|
//#endregion
|
|
1173
|
-
export { certificateMatchesPrivateKey, decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, findExtension, getSubjectPublicKey, getSubjectPublicKeyOrThrow, matchCertificatePrivateKey, parseAuthorityInfoAccess, parseAuthorityKeyIdentifier, parseBasicConstraints, parseCertificateChainPem, parseCertificateDer, parseCertificateDerOrThrow, parseCertificateFromSource, parseCertificatePem, parseCertificatePemOrThrow, parseCertificatePolicies, parseCertificateSigningRequestDer, parseCertificateSigningRequestDerOrThrow, parseCertificateSigningRequestPem, parseCertificateSigningRequestPemOrThrow, parseCertificatesFromSource, parseCrlDistributionPoints, parseExtendedKeyUsage, parseInhibitAnyPolicy, parseKeyUsage, parseNameConstraints, parsePolicyConstraints, parsePolicyMappings, parseSubjectAltNames };
|
|
1182
|
+
export { certificateMatchesPrivateKey, decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, findExtension, getSubjectPublicKey, getSubjectPublicKeyOrThrow, matchCertificatePrivateKey, parseAuthorityInfoAccess, parseAuthorityKeyIdentifier, parseBasicConstraints, parseCertificateChainPem, parseCertificateDer, parseCertificateDerOrThrow, parseCertificateFromSource, parseCertificatePem, parseCertificatePemOrThrow, parseCertificatePolicies, parseCertificateSigningRequestDer, parseCertificateSigningRequestDerOrThrow, parseCertificateSigningRequestPem, parseCertificateSigningRequestPemOrThrow, parseCertificatesFromSource, parseCrlDistributionPoints, parseDistinguishedNameDer, parseExtendedKeyUsage, parseInhibitAnyPolicy, parseKeyUsage, parseNameConstraints, parsePolicyConstraints, parsePolicyMappings, parseSubjectAltNames };
|
|
1174
1183
|
|
|
1175
1184
|
//# sourceMappingURL=parse.js.map
|