micro509 0.1.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/LICENSE +22 -0
- package/README.md +220 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +1 -0
- package/dist/internal/asn1/asn1.js +2 -0
- package/dist/internal/asn1/asn1.js.map +1 -0
- package/dist/internal/asn1/der.js +2 -0
- package/dist/internal/asn1/der.js.map +1 -0
- package/dist/internal/asn1/oids.js +2 -0
- package/dist/internal/asn1/oids.js.map +1 -0
- package/dist/internal/crypto/algorithm-names.js +2 -0
- package/dist/internal/crypto/algorithm-names.js.map +1 -0
- package/dist/internal/crypto/ecdsa.js +2 -0
- package/dist/internal/crypto/ecdsa.js.map +1 -0
- package/dist/internal/crypto/hash.js +2 -0
- package/dist/internal/crypto/hash.js.map +1 -0
- package/dist/internal/crypto/pbes2.d.ts +23 -0
- package/dist/internal/crypto/pbes2.js +2 -0
- package/dist/internal/crypto/pbes2.js.map +1 -0
- package/dist/internal/crypto/rsa-pss.js +2 -0
- package/dist/internal/crypto/rsa-pss.js.map +1 -0
- package/dist/internal/crypto/sig-verify.js +2 -0
- package/dist/internal/crypto/sig-verify.js.map +1 -0
- package/dist/internal/crypto/signing.d.ts +16 -0
- package/dist/internal/crypto/signing.js +2 -0
- package/dist/internal/crypto/signing.js.map +1 -0
- package/dist/internal/crypto/webcrypto.js +2 -0
- package/dist/internal/crypto/webcrypto.js.map +1 -0
- package/dist/internal/shared/base64.js +2 -0
- package/dist/internal/shared/base64.js.map +1 -0
- package/dist/internal/shared/dn.js +2 -0
- package/dist/internal/shared/dn.js.map +1 -0
- package/dist/internal/shared/ip.js +2 -0
- package/dist/internal/shared/ip.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +2 -0
- package/dist/internal/verify/name-constraints-engine.js.map +1 -0
- package/dist/internal/verify/policy-engine.js +2 -0
- package/dist/internal/verify/policy-engine.js.map +1 -0
- package/dist/internal/verify/verify-path.js +2 -0
- package/dist/internal/verify/verify-path.js.map +1 -0
- package/dist/internal/x509/extension-bits.d.ts +18 -0
- package/dist/internal/x509/extension-bits.js +2 -0
- package/dist/internal/x509/extension-bits.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +2 -0
- package/dist/internal/x509/extension-registry.js.map +1 -0
- package/dist/internal/x509/name-fields.js +2 -0
- package/dist/internal/x509/name-fields.js.map +1 -0
- package/dist/keys/keys.d.ts +431 -0
- package/dist/keys/keys.js +5 -0
- package/dist/keys/keys.js.map +1 -0
- package/dist/keys.d.ts +3 -0
- package/dist/keys.js +1 -0
- package/dist/pem/pem.d.ts +56 -0
- package/dist/pem/pem.js +6 -0
- package/dist/pem/pem.js.map +1 -0
- package/dist/pem.d.ts +2 -0
- package/dist/pem.js +1 -0
- package/dist/pkcs/pfx.d.ts +177 -0
- package/dist/pkcs/pfx.js +2 -0
- package/dist/pkcs/pfx.js.map +1 -0
- package/dist/pkcs/pkcs12-mac.d.ts +41 -0
- package/dist/pkcs/pkcs12-mac.js +2 -0
- package/dist/pkcs/pkcs12-mac.js.map +1 -0
- package/dist/pkcs/pkcs7.d.ts +131 -0
- package/dist/pkcs/pkcs7.js +2 -0
- package/dist/pkcs/pkcs7.js.map +1 -0
- package/dist/pkcs.d.ts +5 -0
- package/dist/pkcs.js +1 -0
- package/dist/result/result.d.ts +68 -0
- package/dist/result/result.js +2 -0
- package/dist/result/result.js.map +1 -0
- package/dist/result.d.ts +2 -0
- package/dist/result.js +1 -0
- package/dist/revocation/chain.d.ts +180 -0
- package/dist/revocation/chain.js +2 -0
- package/dist/revocation/chain.js.map +1 -0
- package/dist/revocation/crl.d.ts +316 -0
- package/dist/revocation/crl.js +2 -0
- package/dist/revocation/crl.js.map +1 -0
- package/dist/revocation/ocsp.d.ts +332 -0
- package/dist/revocation/ocsp.js +2 -0
- package/dist/revocation/ocsp.js.map +1 -0
- package/dist/revocation/revocation.d.ts +168 -0
- package/dist/revocation/revocation.js +2 -0
- package/dist/revocation/revocation.js.map +1 -0
- package/dist/revocation.d.ts +5 -0
- package/dist/revocation.js +1 -0
- package/dist/verify/identity.d.ts +129 -0
- package/dist/verify/identity.js +2 -0
- package/dist/verify/identity.js.map +1 -0
- package/dist/verify/name-constraints.d.ts +18 -0
- package/dist/verify/policy.d.ts +39 -0
- package/dist/verify/verify.d.ts +404 -0
- package/dist/verify/verify.js +2 -0
- package/dist/verify/verify.js.map +1 -0
- package/dist/verify.d.ts +5 -0
- package/dist/verify.js +1 -0
- package/dist/x509/certificate.d.ts +191 -0
- package/dist/x509/certificate.js +2 -0
- package/dist/x509/certificate.js.map +1 -0
- package/dist/x509/csr.d.ts +55 -0
- package/dist/x509/csr.js +2 -0
- package/dist/x509/csr.js.map +1 -0
- package/dist/x509/extensions.d.ts +550 -0
- package/dist/x509/extensions.js +2 -0
- package/dist/x509/extensions.js.map +1 -0
- package/dist/x509/name.d.ts +140 -0
- package/dist/x509/name.js +2 -0
- package/dist/x509/name.js.map +1 -0
- package/dist/x509/parse.d.ts +377 -0
- package/dist/x509/parse.js +2 -0
- package/dist/x509/parse.js.map +1 -0
- package/dist/x509.d.ts +8 -0
- package/dist/x509.js +1 -0
- package/package.json +153 -0
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
import { NameAttribute, NameFieldKey, RelativeDistinguishedNameInput } from "./name.js";
|
|
2
|
+
|
|
3
|
+
//#region src/x509/extensions.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* RFC 5280 §4.2.1.3 Key Usage bit flag.
|
|
6
|
+
*
|
|
7
|
+
* Each value corresponds to one bit in the KeyUsage BIT STRING.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.3 RFC 5280 §4.2.1.3}
|
|
10
|
+
*/
|
|
11
|
+
type KeyUsage = "digitalSignature" | "nonRepudiation" | "keyEncipherment" | "dataEncipherment" | "keyAgreement" | "keyCertSign" | "cRLSign" | "encipherOnly" | "decipherOnly";
|
|
12
|
+
/**
|
|
13
|
+
* RFC 5280 §4.2.1.6 Subject Alternative Name / GeneralName.
|
|
14
|
+
*
|
|
15
|
+
* Discriminated union keyed on `type`.
|
|
16
|
+
*
|
|
17
|
+
* The `'unknown'` variant preserves unrecognized {@linkcode GeneralName} tags for round-trip fidelity.
|
|
18
|
+
*/
|
|
19
|
+
type SubjectAltName = {
|
|
20
|
+
/** DNS hostname (dNSName [2]). */readonly type: "dns"; /** Fully-qualified domain name, e.g. `"example.com"`. */
|
|
21
|
+
readonly value: string;
|
|
22
|
+
} | {
|
|
23
|
+
/** IP address (iPAddress [7]). */readonly type: "ip"; /** Dotted-decimal IPv4 or colon-hex IPv6 string. */
|
|
24
|
+
readonly value: string;
|
|
25
|
+
} | {
|
|
26
|
+
/** Email address (rfc822Name [1]). */readonly type: "email"; /** RFC 822 mailbox, e.g. `"admin@example.com"`. */
|
|
27
|
+
readonly value: string;
|
|
28
|
+
} | {
|
|
29
|
+
/** URI (uniformResourceIdentifier [6]). */readonly type: "uri"; /** Absolute URI string. */
|
|
30
|
+
readonly value: string;
|
|
31
|
+
} | {
|
|
32
|
+
/** SRV-ID otherName (id-on-dnsSRV). */readonly type: "srv"; /** SRV service name, e.g. `"_imaps.example.com"`. */
|
|
33
|
+
readonly value: string;
|
|
34
|
+
} | {
|
|
35
|
+
/** X.500 directory name (directoryName [4]). */readonly type: "directoryName"; /** Hex-encoded DER of the Name SEQUENCE. */
|
|
36
|
+
readonly derHex: string;
|
|
37
|
+
} | {
|
|
38
|
+
/** Unrecognized {@linkcode GeneralName} tag, preserved as raw bytes. */readonly type: "unknown"; /** ASN.1 context tag number. */
|
|
39
|
+
readonly tag: number; /** Raw content bytes of the element. */
|
|
40
|
+
readonly value: Uint8Array;
|
|
41
|
+
};
|
|
42
|
+
/** Alias for {@linkcode SubjectAltName} — used where RFC 5280 says "GeneralName". */
|
|
43
|
+
type GeneralName = SubjectAltName;
|
|
44
|
+
/**
|
|
45
|
+
* Revocation reason flags for CRL Distribution Points and Issuing Distribution Points
|
|
46
|
+
* (RFC 5280 §4.2.1.13, §5.2.5).
|
|
47
|
+
*/
|
|
48
|
+
type DistributionPointReason = "keyCompromise" | "cACompromise" | "affiliationChanged" | "superseded" | "cessationOfOperation" | "certificateHold" | "privilegeWithdrawn" | "aACompromise";
|
|
49
|
+
/**
|
|
50
|
+
* Name component of a CRL Distribution Point (RFC 5280 §4.2.1.13).
|
|
51
|
+
*
|
|
52
|
+
* Supply exactly one of `fullName` or `relativeName`.
|
|
53
|
+
*/
|
|
54
|
+
interface DistributionPointName {
|
|
55
|
+
/** Absolute {@linkcode GeneralName}(s) identifying the distribution point (usually a URI). */
|
|
56
|
+
readonly fullName?: readonly GeneralName[];
|
|
57
|
+
/** Name relative to the issuer's DN; mutually exclusive with `fullName`. */
|
|
58
|
+
readonly relativeName?: RelativeDistinguishedNameInput;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Input for a single CRL Distribution Point (RFC 5280 §4.2.1.13).
|
|
62
|
+
*
|
|
63
|
+
* At least one of `distributionPoint` or `crlIssuer` must be provided.
|
|
64
|
+
* The union enforces this constraint at the type level.
|
|
65
|
+
*/
|
|
66
|
+
type DistributionPoint = {
|
|
67
|
+
/** Where to fetch the CRL (fullName or relativeName). */readonly distributionPoint: DistributionPointName; /** Revocation reason subset. Absent means all reasons. */
|
|
68
|
+
readonly reasons?: readonly DistributionPointReason[]; /** Entity that signed the CRL, when different from the cert issuer. */
|
|
69
|
+
readonly crlIssuer?: readonly GeneralName[];
|
|
70
|
+
} | {
|
|
71
|
+
/** Where to fetch the CRL. Optional when `crlIssuer` is present. */readonly distributionPoint?: DistributionPointName; /** Revocation reason subset. Absent means all reasons. */
|
|
72
|
+
readonly reasons?: readonly DistributionPointReason[]; /** Entity that signed the CRL. Required when `distributionPoint` is absent. */
|
|
73
|
+
readonly crlIssuer: readonly GeneralName[];
|
|
74
|
+
};
|
|
75
|
+
/** Base shape for Issuing Distribution Point (RFC 5280 §5.2.5) — no scope restriction. */
|
|
76
|
+
interface IssuingDistributionPointBase {
|
|
77
|
+
/** Where to fetch this CRL. */
|
|
78
|
+
readonly distributionPoint?: DistributionPointName;
|
|
79
|
+
/** Limits the CRL to these revocation reasons. Absent means all reasons. */
|
|
80
|
+
readonly onlySomeReasons?: readonly DistributionPointReason[];
|
|
81
|
+
/** When true, the CRL may contain entries from other CAs. Default false. */
|
|
82
|
+
readonly indirectCrl?: boolean;
|
|
83
|
+
/** Must be absent or false in this variant (no user-cert-only restriction). */
|
|
84
|
+
readonly onlyContainsUserCerts?: false;
|
|
85
|
+
/** Must be absent or false in this variant (no CA-cert-only restriction). */
|
|
86
|
+
readonly onlyContainsCACerts?: false;
|
|
87
|
+
/** When true, the CRL only covers attribute certificates. Default false. */
|
|
88
|
+
readonly onlyContainsAttributeCerts?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/** IDP scoped to end-entity (user) certificates only. Mutually exclusive with CA / attribute scopes. */
|
|
91
|
+
interface IssuingDistributionPointForUserCerts extends Omit<IssuingDistributionPointBase, "onlyContainsUserCerts"> {
|
|
92
|
+
/** This variant only covers end-entity certificates. */
|
|
93
|
+
readonly onlyContainsUserCerts: true;
|
|
94
|
+
/** Must be absent or false when the CRL is not CA-only. */
|
|
95
|
+
readonly onlyContainsCACerts?: false;
|
|
96
|
+
/** Must be absent or false when the CRL is not attribute-cert-only. */
|
|
97
|
+
readonly onlyContainsAttributeCerts?: false;
|
|
98
|
+
}
|
|
99
|
+
/** IDP scoped to CA certificates only. Mutually exclusive with user / attribute scopes. */
|
|
100
|
+
interface IssuingDistributionPointForCaCerts extends Omit<IssuingDistributionPointBase, "onlyContainsCACerts"> {
|
|
101
|
+
/** Must be absent or false when the CRL is not user-cert-only. */
|
|
102
|
+
readonly onlyContainsUserCerts?: false;
|
|
103
|
+
/** This variant only covers CA certificates. */
|
|
104
|
+
readonly onlyContainsCACerts: true;
|
|
105
|
+
/** Must be absent or false when the CRL is not attribute-cert-only. */
|
|
106
|
+
readonly onlyContainsAttributeCerts?: false;
|
|
107
|
+
}
|
|
108
|
+
/** IDP scoped to attribute certificates only. Mutually exclusive with user / CA scopes. */
|
|
109
|
+
interface IssuingDistributionPointForAttributeCerts extends Omit<IssuingDistributionPointBase, "onlyContainsAttributeCerts"> {
|
|
110
|
+
/** Must be absent or false when the CRL is not user-cert-only. */
|
|
111
|
+
readonly onlyContainsUserCerts?: false;
|
|
112
|
+
/** Must be absent or false when the CRL is not CA-only. */
|
|
113
|
+
readonly onlyContainsCACerts?: false;
|
|
114
|
+
/** This variant only covers attribute certificates. */
|
|
115
|
+
readonly onlyContainsAttributeCerts: true;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Input for the Issuing Distribution Point CRL extension (RFC 5280 §5.2.5).
|
|
119
|
+
*
|
|
120
|
+
* The union enforces that at most one of the `onlyContains*` flags is true.
|
|
121
|
+
*/
|
|
122
|
+
type IssuingDistributionPoint = IssuingDistributionPointBase | IssuingDistributionPointForUserCerts | IssuingDistributionPointForCaCerts | IssuingDistributionPointForAttributeCerts;
|
|
123
|
+
/**
|
|
124
|
+
* RFC 5280 §4.2.1.9 Basic Constraints.
|
|
125
|
+
*
|
|
126
|
+
* A certificate with `ca: true` may issue other certificates; `pathLength`
|
|
127
|
+
* limits how many additional CAs may appear below it in the chain.
|
|
128
|
+
*/
|
|
129
|
+
interface BasicConstraints {
|
|
130
|
+
/** Whether this certificate belongs to a CA. End-entity certs set this to `false`. */
|
|
131
|
+
readonly ca: boolean;
|
|
132
|
+
/** Maximum number of intermediate CA certificates allowed below this CA. Only valid when `ca` is `true`. */
|
|
133
|
+
readonly pathLength?: number;
|
|
134
|
+
}
|
|
135
|
+
/** A single certificate policy: an OID plus optional qualifiers. */
|
|
136
|
+
interface PolicyInformation {
|
|
137
|
+
/** Dotted-decimal OID of the policy (e.g. `"2.23.140.1.2.1"` for DV). */
|
|
138
|
+
readonly policyIdentifier: string;
|
|
139
|
+
/** Optional CPS URIs or user notices attached to this policy. */
|
|
140
|
+
readonly policyQualifiers?: readonly PolicyQualifierInfo[];
|
|
141
|
+
}
|
|
142
|
+
/** RFC 5280 §4.2.1.4 — array of policy OIDs with optional qualifiers. */
|
|
143
|
+
type CertificatePolicies = readonly {
|
|
144
|
+
/** Dotted-decimal OID of the policy (e.g. `"2.23.140.1.2.1"` for DV). */readonly policyIdentifier: string; /** Optional CPS URIs or user notices attached to this policy. */
|
|
145
|
+
readonly policyQualifiers?: readonly ({
|
|
146
|
+
readonly type: "cps";
|
|
147
|
+
readonly uri: string;
|
|
148
|
+
} | {
|
|
149
|
+
readonly type: "userNotice";
|
|
150
|
+
readonly noticeRef?: {
|
|
151
|
+
readonly organization: string;
|
|
152
|
+
readonly noticeNumbers: readonly number[];
|
|
153
|
+
};
|
|
154
|
+
readonly explicitText?: string;
|
|
155
|
+
} | {
|
|
156
|
+
readonly type: "oid";
|
|
157
|
+
readonly oid: string;
|
|
158
|
+
readonly qualifierDer: Uint8Array;
|
|
159
|
+
})[];
|
|
160
|
+
}[];
|
|
161
|
+
/** CPS (Certification Practice Statement) URI policy qualifier. */
|
|
162
|
+
interface CpsPolicyQualifierInfo {
|
|
163
|
+
/** Discriminant for the `'cps'` qualifier variant. */
|
|
164
|
+
readonly type: "cps";
|
|
165
|
+
/** URL of the Certification Practice Statement document. */
|
|
166
|
+
readonly uri: string;
|
|
167
|
+
}
|
|
168
|
+
/** Reference to a numbered notice within an organization's practice statement. */
|
|
169
|
+
interface PolicyNoticeReference {
|
|
170
|
+
/** Organization name that published the notice. */
|
|
171
|
+
readonly organization: string;
|
|
172
|
+
/** One-based notice numbers within that organization's documentation. */
|
|
173
|
+
readonly noticeNumbers: readonly number[];
|
|
174
|
+
}
|
|
175
|
+
/** UserNotice policy qualifier — human-readable notice text and/or a notice reference. */
|
|
176
|
+
interface UserNoticePolicyQualifierInfo {
|
|
177
|
+
/** Discriminant for the `'userNotice'` qualifier variant. */
|
|
178
|
+
readonly type: "userNotice";
|
|
179
|
+
/** Pointer to a numbered notice in an organization's practice statement. */
|
|
180
|
+
readonly noticeRef?: PolicyNoticeReference;
|
|
181
|
+
/** Free-form text to display to relying parties. */
|
|
182
|
+
readonly explicitText?: string;
|
|
183
|
+
}
|
|
184
|
+
/** Opaque policy qualifier identified by a custom OID, carried as raw DER. */
|
|
185
|
+
interface CustomPolicyQualifierInfo {
|
|
186
|
+
/** Discriminant for the custom-OID qualifier variant. */
|
|
187
|
+
readonly type: "oid";
|
|
188
|
+
/** Dotted-decimal OID of the qualifier. */
|
|
189
|
+
readonly oid: string;
|
|
190
|
+
/** DER-encoded qualifier payload. */
|
|
191
|
+
readonly qualifierDer: Uint8Array;
|
|
192
|
+
}
|
|
193
|
+
/** Discriminated union of all supported policy qualifier types. */
|
|
194
|
+
type PolicyQualifierInfo = CpsPolicyQualifierInfo | UserNoticePolicyQualifierInfo | CustomPolicyQualifierInfo;
|
|
195
|
+
/** Maps a policy OID in the issuer's domain to an equivalent OID in the subject's domain. */
|
|
196
|
+
interface PolicyMapping {
|
|
197
|
+
/** Policy OID as defined by the issuing CA. Must not be anyPolicy. */
|
|
198
|
+
readonly issuerDomainPolicy: string;
|
|
199
|
+
/** Equivalent policy OID in the subject CA's domain. Must not be anyPolicy. */
|
|
200
|
+
readonly subjectDomainPolicy: string;
|
|
201
|
+
}
|
|
202
|
+
/** RFC 5280 §4.2.1.5 — array of issuer-to-subject policy OID pairs. */
|
|
203
|
+
type PolicyMappings = readonly {
|
|
204
|
+
/** Policy OID as defined by the issuing CA. Must not be anyPolicy. */readonly issuerDomainPolicy: string; /** Equivalent policy OID in the subject CA's domain. Must not be anyPolicy. */
|
|
205
|
+
readonly subjectDomainPolicy: string;
|
|
206
|
+
}[];
|
|
207
|
+
/**
|
|
208
|
+
* RFC 5280 §4.2.1.11 Policy Constraints.
|
|
209
|
+
*
|
|
210
|
+
* At least one field must be present. Values are certificate-count
|
|
211
|
+
* thresholds measured from the current certificate toward the end entity.
|
|
212
|
+
*/
|
|
213
|
+
interface PolicyConstraints {
|
|
214
|
+
/** After this many certificates, an acceptable policy must be in the path. */
|
|
215
|
+
readonly requireExplicitPolicy?: number;
|
|
216
|
+
/** After this many certificates, policy mapping is no longer allowed. */
|
|
217
|
+
readonly inhibitPolicyMapping?: number;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* RFC 5280 §4.2.1.14 Inhibit anyPolicy.
|
|
221
|
+
*
|
|
222
|
+
* After `skipCerts` additional certificates in the path, the special
|
|
223
|
+
* anyPolicy OID is no longer considered a match.
|
|
224
|
+
*/
|
|
225
|
+
interface InhibitAnyPolicy {
|
|
226
|
+
/** Number of additional certificates before anyPolicy stops being valid. */
|
|
227
|
+
readonly skipCerts: number;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Input for `createCertificate`, `createSelfSignedCertificate`,
|
|
231
|
+
* and `createCertificateSigningRequest`.
|
|
232
|
+
*
|
|
233
|
+
* Every field is optional. Omitted extensions are not encoded. Built-in
|
|
234
|
+
* extensions (SKI, AKI, basicConstraints defaults) are handled automatically
|
|
235
|
+
* by the builder.
|
|
236
|
+
*/
|
|
237
|
+
interface CertificateExtensionsInput {
|
|
238
|
+
/** Subject Alternative Names (dns, ip, email, uri, srv, directoryName). */
|
|
239
|
+
readonly subjectAltNames?: readonly SubjectAltName[];
|
|
240
|
+
/** Key Usage flags (digitalSignature, keyCertSign, etc.). */
|
|
241
|
+
readonly keyUsage?: readonly KeyUsage[];
|
|
242
|
+
/** Basic Constraints (CA flag + optional pathLength). Defaults to `{ ca: false }` for certs. */
|
|
243
|
+
readonly basicConstraints?: BasicConstraints;
|
|
244
|
+
/** Extended Key Usage purposes (serverAuth, clientAuth, etc.). */
|
|
245
|
+
readonly extendedKeyUsage?: readonly ExtendedKeyUsage[];
|
|
246
|
+
/** Name Constraints — permitted and/or excluded subtrees. */
|
|
247
|
+
readonly nameConstraints?: NameConstraints;
|
|
248
|
+
/** Certificate Policies with optional qualifiers. */
|
|
249
|
+
readonly certificatePolicies?: CertificatePolicies;
|
|
250
|
+
/** Policy Mappings between issuer and subject policy domains. */
|
|
251
|
+
readonly policyMappings?: PolicyMappings;
|
|
252
|
+
/** Policy Constraints (requireExplicitPolicy / inhibitPolicyMapping thresholds). */
|
|
253
|
+
readonly policyConstraints?: PolicyConstraints;
|
|
254
|
+
/** Inhibit anyPolicy skip-certs threshold. */
|
|
255
|
+
readonly inhibitAnyPolicy?: InhibitAnyPolicy;
|
|
256
|
+
/** Authority Information Access — OCSP responder and CA issuer URIs. */
|
|
257
|
+
readonly authorityInfoAccess?: readonly AuthorityInformationAccess[];
|
|
258
|
+
/** CRL Distribution Points — where to check revocation status. */
|
|
259
|
+
readonly crlDistributionPoints?: readonly DistributionPoint[];
|
|
260
|
+
/** Arbitrary extensions not covered by the built-in fields. */
|
|
261
|
+
readonly customExtensions?: readonly CustomExtension[];
|
|
262
|
+
}
|
|
263
|
+
/** An extension not covered by the typed fields in {@linkcode CertificateExtensionsInput}. */
|
|
264
|
+
interface CustomExtension {
|
|
265
|
+
/** Dotted-decimal OID of the extension. */
|
|
266
|
+
readonly oid: string;
|
|
267
|
+
/** Pre-encoded DER content for the extnValue OCTET STRING. */
|
|
268
|
+
readonly value: Uint8Array;
|
|
269
|
+
/** Whether the extension is critical. Default `false`. */
|
|
270
|
+
readonly critical?: boolean;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* A name form used as a constraint base in namEConstraints.
|
|
274
|
+
* Distinct from {@linkcode SubjectAltName} because IP constraints carry
|
|
275
|
+
* address + mask bytes (8 for IPv4, 32 for IPv6) rather than bare addresses.
|
|
276
|
+
*/
|
|
277
|
+
type NameConstraintForm = {
|
|
278
|
+
/** DNS domain constraint (dNSName [2]). */readonly type: "dns"; /** Domain suffix, e.g. `".example.com"` or `"example.com"`. */
|
|
279
|
+
readonly value: string;
|
|
280
|
+
} | {
|
|
281
|
+
/** Email constraint (rfc822Name [1]). */readonly type: "email"; /** Email domain or full address pattern. */
|
|
282
|
+
readonly value: string;
|
|
283
|
+
} | {
|
|
284
|
+
/** URI constraint (uniformResourceIdentifier [6]). */readonly type: "uri"; /** Host or domain component of a URI. */
|
|
285
|
+
readonly value: string;
|
|
286
|
+
} | {
|
|
287
|
+
/** IP range constraint (iPAddress [7]). */readonly type: "ip"; /** Network address bytes (4 for IPv4, 16 for IPv6). */
|
|
288
|
+
readonly addressBytes: Uint8Array; /** Subnet mask bytes (same length as addressBytes). */
|
|
289
|
+
readonly maskBytes: Uint8Array;
|
|
290
|
+
} | {
|
|
291
|
+
/** Directory name constraint (directoryName [4]). */readonly type: "directoryName"; /** Hex-encoded DER of the Name SEQUENCE. */
|
|
292
|
+
readonly derHex: string;
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Name constraint forms parsed from DER but not supported for encoding or
|
|
296
|
+
* validation. Preserved for diagnostic round-tripping.
|
|
297
|
+
*/
|
|
298
|
+
type UnsupportedNameConstraintForm = {
|
|
299
|
+
/** otherName [0] — raw bytes. */readonly type: "otherName";
|
|
300
|
+
readonly value: Uint8Array;
|
|
301
|
+
} | {
|
|
302
|
+
/** x400Address [3] — raw bytes. */readonly type: "x400Address";
|
|
303
|
+
readonly value: Uint8Array;
|
|
304
|
+
} | {
|
|
305
|
+
/** ediPartyName [5] — raw bytes. */readonly type: "ediPartyName";
|
|
306
|
+
readonly value: Uint8Array;
|
|
307
|
+
} | {
|
|
308
|
+
/** registeredID [8] — decoded OID string. */readonly type: "registeredID";
|
|
309
|
+
readonly value: string;
|
|
310
|
+
};
|
|
311
|
+
/** Union of supported and unsupported name constraint forms as produced by parsing. */
|
|
312
|
+
type ParsedNameConstraintForm = {
|
|
313
|
+
readonly type: "dns";
|
|
314
|
+
readonly value: string;
|
|
315
|
+
} | {
|
|
316
|
+
readonly type: "email";
|
|
317
|
+
readonly value: string;
|
|
318
|
+
} | {
|
|
319
|
+
readonly type: "uri";
|
|
320
|
+
readonly value: string;
|
|
321
|
+
} | {
|
|
322
|
+
readonly type: "ip";
|
|
323
|
+
readonly addressBytes: Uint8Array;
|
|
324
|
+
readonly maskBytes: Uint8Array;
|
|
325
|
+
} | {
|
|
326
|
+
readonly type: "directoryName";
|
|
327
|
+
readonly derHex: string;
|
|
328
|
+
} | {
|
|
329
|
+
readonly type: "otherName";
|
|
330
|
+
readonly value: Uint8Array;
|
|
331
|
+
} | {
|
|
332
|
+
readonly type: "x400Address";
|
|
333
|
+
readonly value: Uint8Array;
|
|
334
|
+
} | {
|
|
335
|
+
readonly type: "ediPartyName";
|
|
336
|
+
readonly value: Uint8Array;
|
|
337
|
+
} | {
|
|
338
|
+
readonly type: "registeredID";
|
|
339
|
+
readonly value: string;
|
|
340
|
+
};
|
|
341
|
+
/** A single subtree entry in a Name Constraints permitted/excluded list. */
|
|
342
|
+
interface GeneralSubtree<TForm extends ParsedNameConstraintForm = {
|
|
343
|
+
readonly type: "dns";
|
|
344
|
+
readonly value: string;
|
|
345
|
+
} | {
|
|
346
|
+
readonly type: "email";
|
|
347
|
+
readonly value: string;
|
|
348
|
+
} | {
|
|
349
|
+
readonly type: "uri";
|
|
350
|
+
readonly value: string;
|
|
351
|
+
} | {
|
|
352
|
+
readonly type: "ip";
|
|
353
|
+
readonly addressBytes: Uint8Array;
|
|
354
|
+
readonly maskBytes: Uint8Array;
|
|
355
|
+
} | {
|
|
356
|
+
readonly type: "directoryName";
|
|
357
|
+
readonly derHex: string;
|
|
358
|
+
}> {
|
|
359
|
+
/** The name form that defines this constraint boundary. */
|
|
360
|
+
readonly base: TForm;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* RFC 5280 §4.2.1.10 Name Constraints.
|
|
364
|
+
*
|
|
365
|
+
* A CA certificate may restrict the namespace of all subject names in
|
|
366
|
+
* subsequent certificates in the path.
|
|
367
|
+
*/
|
|
368
|
+
interface NameConstraints<TForm extends ParsedNameConstraintForm = {
|
|
369
|
+
readonly type: "dns";
|
|
370
|
+
readonly value: string;
|
|
371
|
+
} | {
|
|
372
|
+
readonly type: "email";
|
|
373
|
+
readonly value: string;
|
|
374
|
+
} | {
|
|
375
|
+
readonly type: "uri";
|
|
376
|
+
readonly value: string;
|
|
377
|
+
} | {
|
|
378
|
+
readonly type: "ip";
|
|
379
|
+
readonly addressBytes: Uint8Array;
|
|
380
|
+
readonly maskBytes: Uint8Array;
|
|
381
|
+
} | {
|
|
382
|
+
readonly type: "directoryName";
|
|
383
|
+
readonly derHex: string;
|
|
384
|
+
}> {
|
|
385
|
+
/** Names that MUST fall within these subtrees to be valid. */
|
|
386
|
+
readonly permittedSubtrees?: readonly GeneralSubtree<TForm>[];
|
|
387
|
+
/** Names that MUST NOT fall within these subtrees. Takes precedence over permitted. */
|
|
388
|
+
readonly excludedSubtrees?: readonly GeneralSubtree<TForm>[];
|
|
389
|
+
}
|
|
390
|
+
/** Well-known AIA access methods: OCSP responder or CA issuer certificate. */
|
|
391
|
+
type KnownAuthorityInfoAccessMethod = "ocsp" | "caIssuers";
|
|
392
|
+
/** AIA access method identified by a custom OID not in the well-known set. */
|
|
393
|
+
interface CustomAuthorityInfoAccessMethod {
|
|
394
|
+
/** Discriminant for the custom-OID access method variant. */
|
|
395
|
+
readonly type: "oid";
|
|
396
|
+
/** Dotted-decimal OID of the access method. */
|
|
397
|
+
readonly value: string;
|
|
398
|
+
}
|
|
399
|
+
/** AIA access method — either a well-known string or a custom OID. */
|
|
400
|
+
type AuthorityInfoAccessMethod = KnownAuthorityInfoAccessMethod | CustomAuthorityInfoAccessMethod;
|
|
401
|
+
/** A single entry in the Authority Information Access extension (RFC 5280 §4.2.2.1). */
|
|
402
|
+
interface AuthorityInformationAccess {
|
|
403
|
+
/** Access method (`'ocsp'`, `'caIssuers'`, or custom OID). */
|
|
404
|
+
readonly method: "ocsp" | "caIssuers" | {
|
|
405
|
+
readonly type: "oid";
|
|
406
|
+
readonly value: string;
|
|
407
|
+
};
|
|
408
|
+
/** URI where the resource can be fetched. */
|
|
409
|
+
readonly uri: string;
|
|
410
|
+
}
|
|
411
|
+
/** Well-known Extended Key Usage purpose strings (RFC 5280 §4.2.1.12). */
|
|
412
|
+
type KnownExtendedKeyUsage = "serverAuth" | "clientAuth" | "codeSigning" | "emailProtection" | "timeStamping" | "ocspSigning";
|
|
413
|
+
/** Extended Key Usage purpose identified by a custom OID. */
|
|
414
|
+
interface CustomExtendedKeyUsage {
|
|
415
|
+
/** Discriminant for the custom-OID EKU variant. */
|
|
416
|
+
readonly type: "oid";
|
|
417
|
+
/** Dotted-decimal OID of the usage purpose. */
|
|
418
|
+
readonly value: string;
|
|
419
|
+
}
|
|
420
|
+
/** Extended Key Usage — either a well-known purpose string or a custom OID. */
|
|
421
|
+
type ExtendedKeyUsage = "serverAuth" | "clientAuth" | "codeSigning" | "emailProtection" | "timeStamping" | "ocspSigning" | {
|
|
422
|
+
readonly type: "oid";
|
|
423
|
+
readonly value: string;
|
|
424
|
+
};
|
|
425
|
+
/**
|
|
426
|
+
* Build the v3 extensions block for a certificate.
|
|
427
|
+
*
|
|
428
|
+
* Automatically adds SKI, AKI (when issuer key is available), and
|
|
429
|
+
* basicConstraints (defaults to `{ ca: false }`). Additional extensions
|
|
430
|
+
* come from the caller's {@linkcode CertificateExtensionsInput}.
|
|
431
|
+
*
|
|
432
|
+
* @param subjectPublicKeyInfo DER-encoded SPKI of the subject.
|
|
433
|
+
* @param issuerPublicKeyInfo DER-encoded SPKI of the issuer, or `undefined` for self-signed.
|
|
434
|
+
* @param input Optional extension configuration.
|
|
435
|
+
* @param subjectIsEmpty Whether the certificate subject DN is empty. When `true`, the
|
|
436
|
+
* subjectAltName extension is marked critical per RFC 5280 §4.2.1.6.
|
|
437
|
+
* @returns Array of DER-encoded Extension SEQUENCEs.
|
|
438
|
+
*/
|
|
439
|
+
declare function buildCertificateExtensions(subjectPublicKeyInfo: Uint8Array, issuerPublicKeyInfo: Uint8Array | undefined, input: CertificateExtensionsInput | undefined, subjectIsEmpty?: boolean): Uint8Array[];
|
|
440
|
+
/**
|
|
441
|
+
* Build the extensions for a CSR's extensionRequest attribute.
|
|
442
|
+
*
|
|
443
|
+
* Unlike {@linkcode buildCertificateExtensions}, SKI/AKI are not auto-generated.
|
|
444
|
+
*
|
|
445
|
+
* @param input Optional extension configuration.
|
|
446
|
+
* @returns Array of DER-encoded Extension SEQUENCEs.
|
|
447
|
+
*/
|
|
448
|
+
declare function buildRequestedExtensions(input: CertificateExtensionsInput | undefined): Uint8Array[];
|
|
449
|
+
/**
|
|
450
|
+
* Encode a single X.509 Extension SEQUENCE (OID + optional critical BOOLEAN + OCTET STRING).
|
|
451
|
+
*
|
|
452
|
+
* @param oid Dotted-decimal extension OID.
|
|
453
|
+
* @param extnValue DER-encoded extension payload.
|
|
454
|
+
* @param critical Whether to mark the extension as critical. Default `false`.
|
|
455
|
+
*/
|
|
456
|
+
declare function encodeExtension(oid: string, extnValue: Uint8Array, critical?: boolean): Uint8Array;
|
|
457
|
+
/**
|
|
458
|
+
* DER-encode a {@linkcode BasicConstraints} value.
|
|
459
|
+
*
|
|
460
|
+
* @param input CA flag and optional pathLength.
|
|
461
|
+
* @returns DER SEQUENCE suitable for wrapping in an Extension OCTET STRING.
|
|
462
|
+
*/
|
|
463
|
+
declare function encodeBasicConstraints(input: BasicConstraints): Uint8Array;
|
|
464
|
+
/**
|
|
465
|
+
* DER-encode a Key Usage BIT STRING from an array of {@linkcode KeyUsage} flags.
|
|
466
|
+
*
|
|
467
|
+
* @param usages Flags to set in the bit string.
|
|
468
|
+
*/
|
|
469
|
+
declare function encodeKeyUsage(usages: readonly KeyUsage[]): Uint8Array;
|
|
470
|
+
/**
|
|
471
|
+
* DER-encode a single {@linkcode SubjectAltName} GeneralName element.
|
|
472
|
+
*
|
|
473
|
+
* @param value The SAN entry to encode.
|
|
474
|
+
*/
|
|
475
|
+
declare function encodeSubjectAltName(value: SubjectAltName): Uint8Array;
|
|
476
|
+
/**
|
|
477
|
+
* DER-encode an Extended Key Usage SEQUENCE OF OIDs.
|
|
478
|
+
*
|
|
479
|
+
* @param usages EKU purposes to encode.
|
|
480
|
+
*/
|
|
481
|
+
declare function encodeExtendedKeyUsage(usages: readonly ExtendedKeyUsage[]): Uint8Array;
|
|
482
|
+
/**
|
|
483
|
+
* DER-encode an Authority Information Access SEQUENCE.
|
|
484
|
+
*
|
|
485
|
+
* @param entries AIA entries (OCSP, caIssuers, or custom) to encode.
|
|
486
|
+
*/
|
|
487
|
+
declare function encodeAuthorityInfoAccess(entries: readonly AuthorityInformationAccess[]): Uint8Array;
|
|
488
|
+
/**
|
|
489
|
+
* DER-encode a CRL Distribution Points SEQUENCE.
|
|
490
|
+
*
|
|
491
|
+
* @param points Distribution points to encode.
|
|
492
|
+
*/
|
|
493
|
+
declare function encodeCrlDistributionPoints(points: readonly DistributionPoint[]): Uint8Array;
|
|
494
|
+
/**
|
|
495
|
+
* DER-encode a Name Constraints extension value.
|
|
496
|
+
*
|
|
497
|
+
* @param constraints Permitted and/or excluded subtrees.
|
|
498
|
+
*/
|
|
499
|
+
declare function encodeNameConstraints(constraints: NameConstraints): Uint8Array;
|
|
500
|
+
/**
|
|
501
|
+
* DER-encode a Certificate Policies extension value.
|
|
502
|
+
*
|
|
503
|
+
* @param policies Non-empty array of policy information entries.
|
|
504
|
+
*/
|
|
505
|
+
declare function encodeCertificatePolicies(policies: CertificatePolicies): Uint8Array;
|
|
506
|
+
/**
|
|
507
|
+
* DER-encode a Policy Mappings extension value.
|
|
508
|
+
*
|
|
509
|
+
* @param mappings Non-empty array of issuer-to-subject policy pairs. Neither OID may be anyPolicy.
|
|
510
|
+
*/
|
|
511
|
+
declare function encodePolicyMappings(mappings: PolicyMappings): Uint8Array;
|
|
512
|
+
/**
|
|
513
|
+
* DER-encode a Policy Constraints extension value.
|
|
514
|
+
*
|
|
515
|
+
* @param constraints At least one of `requireExplicitPolicy` or `inhibitPolicyMapping` must be set.
|
|
516
|
+
*/
|
|
517
|
+
declare function encodePolicyConstraints(constraints: PolicyConstraints): Uint8Array;
|
|
518
|
+
/**
|
|
519
|
+
* DER-encode an Inhibit anyPolicy extension value (single INTEGER).
|
|
520
|
+
*
|
|
521
|
+
* @param input The skipCerts threshold.
|
|
522
|
+
*/
|
|
523
|
+
declare function encodeInhibitAnyPolicy(input: InhibitAnyPolicy): Uint8Array;
|
|
524
|
+
/**
|
|
525
|
+
* Resolve an {@linkcode ExtendedKeyUsage} to its dotted-decimal OID.
|
|
526
|
+
*
|
|
527
|
+
* @param usage Well-known string or custom OID object.
|
|
528
|
+
*/
|
|
529
|
+
declare function getExtendedKeyUsageOid(usage: ExtendedKeyUsage): string;
|
|
530
|
+
/**
|
|
531
|
+
* Map a dotted-decimal OID to an {@linkcode ExtendedKeyUsage} value.
|
|
532
|
+
*
|
|
533
|
+
* Returns a well-known string for recognized OIDs, or `{ type: 'oid', value }` otherwise.
|
|
534
|
+
*/
|
|
535
|
+
declare function parseExtendedKeyUsageOid(oid: string): ExtendedKeyUsage;
|
|
536
|
+
/**
|
|
537
|
+
* Resolve an {@linkcode AuthorityInfoAccessMethod} to its dotted-decimal OID.
|
|
538
|
+
*
|
|
539
|
+
* @param method Well-known string or custom OID object.
|
|
540
|
+
*/
|
|
541
|
+
declare function getAuthorityInfoAccessMethodOid(method: AuthorityInfoAccessMethod): string;
|
|
542
|
+
/**
|
|
543
|
+
* Map a dotted-decimal OID to an {@linkcode AuthorityInfoAccessMethod} value.
|
|
544
|
+
*
|
|
545
|
+
* Returns `'ocsp'` or `'caIssuers'` for recognized OIDs, or `{ type: 'oid', value }` otherwise.
|
|
546
|
+
*/
|
|
547
|
+
declare function parseAuthorityInfoAccessMethodOid(oid: string): AuthorityInfoAccessMethod;
|
|
548
|
+
//#endregion
|
|
549
|
+
export { AuthorityInfoAccessMethod, AuthorityInformationAccess, BasicConstraints, CertificateExtensionsInput, CertificatePolicies, CpsPolicyQualifierInfo, CustomAuthorityInfoAccessMethod, CustomExtendedKeyUsage, CustomExtension, CustomPolicyQualifierInfo, DistributionPoint, DistributionPointName, DistributionPointReason, ExtendedKeyUsage, GeneralName, GeneralSubtree, InhibitAnyPolicy, IssuingDistributionPoint, IssuingDistributionPointBase, IssuingDistributionPointForAttributeCerts, IssuingDistributionPointForCaCerts, IssuingDistributionPointForUserCerts, KeyUsage, KnownAuthorityInfoAccessMethod, KnownExtendedKeyUsage, NameConstraintForm, NameConstraints, ParsedNameConstraintForm, PolicyConstraints, PolicyInformation, PolicyMapping, PolicyMappings, PolicyNoticeReference, PolicyQualifierInfo, SubjectAltName, UnsupportedNameConstraintForm, UserNoticePolicyQualifierInfo, buildCertificateExtensions, buildRequestedExtensions, encodeAuthorityInfoAccess, encodeBasicConstraints, encodeCertificatePolicies, encodeCrlDistributionPoints, encodeExtendedKeyUsage, encodeExtension, encodeInhibitAnyPolicy, encodeKeyUsage, encodeNameConstraints, encodePolicyConstraints, encodePolicyMappings, encodeSubjectAltName, getAuthorityInfoAccessMethodOid, getExtendedKeyUsageOid, parseAuthorityInfoAccessMethodOid, parseExtendedKeyUsageOid };
|
|
550
|
+
//# sourceMappingURL=extensions.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{bool as e,concatBytes as t,explicitContext as n,ia5String as r,implicitConstructedContext as i,implicitPrimitiveContext as a,integerFromNumber as o,objectIdentifier as s,octetString as ee,readElement as c,readRootElement as l,readSequenceChildren as u,sequence as d,tlv as te,utf8String as f}from"../internal/asn1/der.js";import{hexToBytes as ne}from"../internal/asn1/asn1.js";import{OIDS as p}from"../internal/asn1/oids.js";import{sha1 as m}from"../internal/crypto/hash.js";import{parseIpAddressToBytes as re}from"../internal/shared/ip.js";import{encodeDistributionPointReasonFlagsContent as h,encodeKeyUsageExtension as g}from"../internal/x509/extension-bits.js";import{encodeRelativeDistinguishedName as ie}from"./name.js";import{AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION as ae,AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION as oe,BASIC_CONSTRAINTS_EXTENSION_DEFINITION as _,CERTIFICATE_POLICIES_EXTENSION_DEFINITION as se,CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION as ce,EXTENDED_KEY_USAGE_EXTENSION_DEFINITION as le,INHIBIT_ANY_POLICY_EXTENSION_DEFINITION as v,KEY_USAGE_EXTENSION_DEFINITION as y,NAME_CONSTRAINTS_EXTENSION_DEFINITION as b,POLICY_CONSTRAINTS_EXTENSION_DEFINITION as x,POLICY_MAPPINGS_EXTENSION_DEFINITION as S,SUBJECT_ALT_NAME_EXTENSION_DEFINITION as C,SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION as w,getExtensionDefinition as T}from"../internal/x509/extension-registry.js";const E={serverAuth:p.serverAuth,clientAuth:p.clientAuth,codeSigning:p.codeSigning,emailProtection:p.emailProtection,timeStamping:p.timeStamping,ocspSigning:p.ocspSigning},D={ocsp:p.ocspAccessMethod,caIssuers:p.caIssuersAccessMethod};function O(e,t,n,r=!1){let i=[],a=new Set;return j(i,a,_,n?.basicConstraints??{ca:!1}),j(i,a,w,X(e)),t!==void 0&&j(i,a,oe,X(t)),A(i,a,n,`certificate`,{includeBasicConstraints:!1,subjectIsEmpty:r}),i}function k(e){let t=[];return A(t,new Set,e,`csr`,{includeBasicConstraints:!0}),t}function A(e,t,n,r,i){if(n!==void 0){if(i.includeBasicConstraints&&n.basicConstraints!==void 0&&j(e,t,_,n.basicConstraints),n.keyUsage!==void 0&&n.keyUsage.length>0&&j(e,t,y,n.keyUsage),n.subjectAltNames!==void 0&&n.subjectAltNames.length>0){let r=i.subjectIsEmpty===!0?!0:void 0;j(e,t,C,n.subjectAltNames,r)}if(n.extendedKeyUsage!==void 0&&n.extendedKeyUsage.length>0&&j(e,t,le,n.extendedKeyUsage),n.nameConstraints!==void 0&&j(e,t,b,n.nameConstraints),n.certificatePolicies!==void 0&&n.certificatePolicies.length>0&&j(e,t,se,n.certificatePolicies),n.policyMappings!==void 0&&n.policyMappings.length>0&&j(e,t,S,n.policyMappings),n.policyConstraints!==void 0&&j(e,t,x,n.policyConstraints),n.inhibitAnyPolicy!==void 0&&j(e,t,v,n.inhibitAnyPolicy),n.authorityInfoAccess!==void 0&&n.authorityInfoAccess.length>0&&j(e,t,ae,n.authorityInfoAccess),n.crlDistributionPoints!==void 0&&n.crlDistributionPoints.length>0&&j(e,t,ce,n.crlDistributionPoints),n.customExtensions!==void 0)for(let i of n.customExtensions){let n=T(i.oid);if(n!==void 0&&!n.contexts.includes(r))throw Error(`Extension ${i.oid} is not supported in ${r} context`);$(e,t,i.oid,new Uint8Array(i.value),i.critical??!1)}}}function j(e,t,n,r,i=n.defaultCritical){$(e,t,n.oid,n.encode(r),i)}function M(t,n,r=!1){let i=[s(t)];return r&&i.push(e(!0)),i.push(ee(n)),d(i)}function N(t){let n=[];if(t.ca&&n.push(e(!0)),t.pathLength!==void 0){if(!t.ca)throw Error(`pathLength requires ca=true`);n.push(o(t.pathLength))}return d(n)}function P(e){return g(e)}function F(e){switch(e.type){case`dns`:return a(2,new TextEncoder().encode(e.value));case`email`:return a(1,new TextEncoder().encode(e.value));case`uri`:return a(6,new TextEncoder().encode(e.value));case`srv`:return i(0,d([s(p.idOnDnsSrv),n(0,r(e.value))]));case`ip`:return a(7,ve(e.value));case`directoryName`:return i(4,K(e.derHex));case`unknown`:return te(e.tag,e.value);default:throw Error(`Unhandled SubjectAltName type: ${String(e)}`)}}function I(e){return d(e.map(e=>s(q(e))))}function ue(e){return d(e.map(e=>d([s(Y(e.method)),a(6,new TextEncoder().encode(e.uri))])))}function L(e){return d(e.map(e=>d(me(e))))}function R(e){let n=[];return e.permittedSubtrees!==void 0&&e.permittedSubtrees.length>0&&n.push(i(0,t(e.permittedSubtrees.map(G)))),e.excludedSubtrees!==void 0&&e.excludedSubtrees.length>0&&n.push(i(1,t(e.excludedSubtrees.map(G)))),d(n)}function z(e){if(e.length===0)throw Error(`certificatePolicies must not be empty`);return d(e.map(U))}function B(e){if(e.length===0)throw Error(`policyMappings must not be empty`);return d(e.map(e=>{if(Q(e.issuerDomainPolicy),Q(e.subjectDomainPolicy),e.issuerDomainPolicy===p.anyPolicy||e.subjectDomainPolicy===p.anyPolicy)throw Error(`policyMappings must not use anyPolicy`);return d([s(e.issuerDomainPolicy),s(e.subjectDomainPolicy)])}))}function V(e){let t=[];if(e.requireExplicitPolicy!==void 0&&t.push(a(0,W(e.requireExplicitPolicy))),e.inhibitPolicyMapping!==void 0&&t.push(a(1,W(e.inhibitPolicyMapping))),t.length===0)throw Error(`policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping`);return d(t)}function H(e){return o(e.skipCerts)}function U(e){Q(e.policyIdentifier);let t=[s(e.policyIdentifier)];return e.policyQualifiers!==void 0&&e.policyQualifiers.length>0&&t.push(d(e.policyQualifiers.map(de))),d(t)}function de(e){switch(e.type){case`cps`:return d([s(p.cpsPolicyQualifier),r(e.uri)]);case`userNotice`:return d([s(p.userNoticePolicyQualifier),fe(e)]);case`oid`:return Z(e.oid),d([s(e.oid),new Uint8Array(e.qualifierDer)]);default:throw Error(`Unhandled PolicyQualifierInfo type: ${String(e)}`)}}function fe(e){let t=[];return e.noticeRef!==void 0&&t.push(pe(e.noticeRef)),e.explicitText!==void 0&&t.push(f(e.explicitText)),d(t)}function pe(e){return d([f(e.organization),d(e.noticeNumbers.map(e=>o(e)))])}function W(e){return c(o(e)).value}function G(e){return d([ge(e.base)])}function me(e){if(e.crlIssuer!==void 0&&e.crlIssuer.length===0)throw Error(`DistributionPoint crlIssuer must not be empty`);if(e.distributionPoint===void 0&&e.crlIssuer===void 0)throw Error(`DistributionPoint must contain distributionPoint or crlIssuer`);let n=[];return e.distributionPoint!==void 0&&n.push(i(0,he(e.distributionPoint))),e.reasons!==void 0&&e.reasons.length>0&&n.push(a(1,h(e.reasons))),e.crlIssuer!==void 0&&e.crlIssuer.length>0&&n.push(i(2,t(e.crlIssuer.map(F)))),n}function he(e){if(e.fullName!==void 0&&e.relativeName!==void 0)throw Error(`DistributionPointName cannot contain both fullName and relativeName`);if(e.fullName!==void 0){if(e.fullName.length===0)throw Error(`DistributionPointName fullName must not be empty`);return i(0,t(e.fullName.map(F)))}if(e.relativeName!==void 0){let t=ie(e.relativeName),n=c(t);return i(1,t.slice(n.start,n.end))}throw Error(`DistributionPointName must contain fullName or relativeName`)}function ge(e){switch(e.type){case`dns`:return a(2,new TextEncoder().encode(e.value));case`email`:return a(1,new TextEncoder().encode(e.value));case`uri`:return a(6,new TextEncoder().encode(e.value));case`ip`:return a(7,t([e.addressBytes,e.maskBytes]));case`directoryName`:return i(4,K(e.derHex));default:throw Error(`Unhandled NameConstraintForm type: ${String(e)}`)}}function K(e){let t=l(ne(e),{maxDepth:64});if(t.tag!==48)throw Error(`directoryName derHex must encode a DER SEQUENCE`);return new Uint8Array(t.value)}function q(e){return typeof e==`string`?E[e]:(Z(e.value),e.value)}function J(e){switch(e){case p.serverAuth:return`serverAuth`;case p.clientAuth:return`clientAuth`;case p.codeSigning:return`codeSigning`;case p.emailProtection:return`emailProtection`;case p.timeStamping:return`timeStamping`;case p.ocspSigning:return`ocspSigning`}return{type:`oid`,value:e}}function Y(e){return typeof e==`string`?D[e]:(Z(e.value),e.value)}function _e(e){switch(e){case p.ocspAccessMethod:return`ocsp`;case p.caIssuersAccessMethod:return`caIssuers`}return{type:`oid`,value:e}}function ve(e){return re(e)}function X(e){let t=u(e)[1];if(t===void 0||t.tag!==3)throw Error(`SPKI missing subject public key bit string`);return m(t.value.slice(1))}function Z(e){if(!/^\d+(?:\.\d+)+$/.test(e))throw Error(`Invalid OID: ${e}`)}function Q(e){Z(e)}function $(e,t,n,r,i=!1){if(Z(n),t.has(n))throw Error(`Duplicate extension OID: ${n}`);t.add(n),e.push(M(n,r,i))}export{O as buildCertificateExtensions,k as buildRequestedExtensions,X as buildSubjectKeyIdentifier,ue as encodeAuthorityInfoAccess,N as encodeBasicConstraints,z as encodeCertificatePolicies,L as encodeCrlDistributionPoints,I as encodeExtendedKeyUsage,M as encodeExtension,H as encodeInhibitAnyPolicy,P as encodeKeyUsage,R as encodeNameConstraints,V as encodePolicyConstraints,B as encodePolicyMappings,F as encodeSubjectAltName,Y as getAuthorityInfoAccessMethodOid,q as getExtendedKeyUsageOid,_e as parseAuthorityInfoAccessMethodOid,J as parseExtendedKeyUsageOid};
|
|
2
|
+
//# sourceMappingURL=extensions.js.map
|