micro509 0.18.0 → 0.19.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.
Files changed (99) hide show
  1. package/CHANGELOG.md +88 -1
  2. package/dist/crypto/crypto.d.ts +11 -2
  3. package/dist/crypto/crypto.js +30 -17
  4. package/dist/crypto/crypto.js.map +1 -1
  5. package/dist/crypto.d.ts +2 -2
  6. package/dist/der/der.js.map +1 -1
  7. package/dist/index.d.ts +6 -5
  8. package/dist/internal/asn1/asn1.js +10 -2
  9. package/dist/internal/asn1/asn1.js.map +1 -1
  10. package/dist/internal/asn1/ber.js.map +1 -1
  11. package/dist/internal/asn1/decode-refusal.js.map +1 -1
  12. package/dist/internal/asn1/der.js.map +1 -1
  13. package/dist/internal/asn1/oids.js.map +1 -1
  14. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  15. package/dist/internal/crypto/ecdsa.js.map +1 -1
  16. package/dist/internal/crypto/hash.js.map +1 -1
  17. package/dist/internal/crypto/pbes2.js.map +1 -1
  18. package/dist/internal/crypto/prime-ec.js.map +1 -1
  19. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  20. package/dist/internal/crypto/sig-verify.d.ts +40 -0
  21. package/dist/internal/crypto/sig-verify.js +152 -65
  22. package/dist/internal/crypto/sig-verify.js.map +1 -1
  23. package/dist/internal/crypto/signing.js.map +1 -1
  24. package/dist/internal/jose/base64url.js.map +1 -1
  25. package/dist/internal/jose/json-data.js.map +1 -1
  26. package/dist/internal/jose/strict-json.js.map +1 -1
  27. package/dist/internal/shared/base64.js.map +1 -1
  28. package/dist/internal/shared/dn.js.map +1 -1
  29. package/dist/internal/shared/idna.js.map +1 -1
  30. package/dist/internal/shared/ip.js.map +1 -1
  31. package/dist/internal/shared/mailbox.js.map +1 -1
  32. package/dist/internal/shared/punycode.js.map +1 -1
  33. package/dist/internal/shared/uri-host.js.map +1 -1
  34. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  35. package/dist/internal/verify/policy-engine.js.map +1 -1
  36. package/dist/internal/verify/spki-distrust.js.map +1 -1
  37. package/dist/internal/verify/verify-path.js +222 -116
  38. package/dist/internal/verify/verify-path.js.map +1 -1
  39. package/dist/internal/x509/directory-name.js.map +1 -1
  40. package/dist/internal/x509/extension-bits.js.map +1 -1
  41. package/dist/internal/x509/extension-errors.js.map +1 -1
  42. package/dist/internal/x509/extension-registry.js.map +1 -1
  43. package/dist/internal/x509/general-name-profile.js.map +1 -1
  44. package/dist/internal/x509/general-name.js.map +1 -1
  45. package/dist/internal/x509/name-fields.js.map +1 -1
  46. package/dist/internal/x509/or-address.js.map +1 -1
  47. package/dist/jose/base64url.js.map +1 -1
  48. package/dist/jose/errors.js.map +1 -1
  49. package/dist/jose/jwe.js.map +1 -1
  50. package/dist/jose/jwks.js.map +1 -1
  51. package/dist/jose/jws.js.map +1 -1
  52. package/dist/jose/jwt.js.map +1 -1
  53. package/dist/jose/remote-jwks.js.map +1 -1
  54. package/dist/kdf/argon2-arithmetic.js.map +1 -1
  55. package/dist/kdf/argon2-core.js.map +1 -1
  56. package/dist/kdf/argon2-memory.js.map +1 -1
  57. package/dist/kdf/argon2-portable.js.map +1 -1
  58. package/dist/kdf/argon2.js.map +1 -1
  59. package/dist/keys/keys.js.map +1 -1
  60. package/dist/pem/pem.js.map +1 -1
  61. package/dist/pkcs/pfx.js.map +1 -1
  62. package/dist/pkcs/pkcs12-mac.js +1 -1
  63. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  64. package/dist/pkcs/pkcs7.d.ts +10 -0
  65. package/dist/pkcs/pkcs7.js +106 -88
  66. package/dist/pkcs/pkcs7.js.map +1 -1
  67. package/dist/result/result.js.map +1 -1
  68. package/dist/revocation/chain.d.ts +67 -13
  69. package/dist/revocation/chain.js +429 -301
  70. package/dist/revocation/chain.js.map +1 -1
  71. package/dist/revocation/crl.d.ts +65 -11
  72. package/dist/revocation/crl.js +492 -202
  73. package/dist/revocation/crl.js.map +1 -1
  74. package/dist/revocation/ocsp.d.ts +79 -24
  75. package/dist/revocation/ocsp.js +417 -231
  76. package/dist/revocation/ocsp.js.map +1 -1
  77. package/dist/revocation/revocation.d.ts +68 -13
  78. package/dist/revocation/revocation.js +194 -73
  79. package/dist/revocation/revocation.js.map +1 -1
  80. package/dist/revocation.d.ts +4 -4
  81. package/dist/ssh/ssh.js.map +1 -1
  82. package/dist/ssh/wire.js.map +1 -1
  83. package/dist/verify/identity.d.ts +2 -2
  84. package/dist/verify/identity.js +2 -2
  85. package/dist/verify/identity.js.map +1 -1
  86. package/dist/verify/verify.d.ts +84 -32
  87. package/dist/verify/verify.js +221 -171
  88. package/dist/verify/verify.js.map +1 -1
  89. package/dist/verify.d.ts +3 -2
  90. package/dist/x509/certificate.js.map +1 -1
  91. package/dist/x509/csr.js.map +1 -1
  92. package/dist/x509/extensions.js.map +1 -1
  93. package/dist/x509/fingerprint.js.map +1 -1
  94. package/dist/x509/name-text.js.map +1 -1
  95. package/dist/x509/name.js.map +1 -1
  96. package/dist/x509/parse.d.ts +6 -2
  97. package/dist/x509/parse.js +121 -121
  98. package/dist/x509/parse.js.map +1 -1
  99. package/package.json +11 -11
@@ -1,4 +1,5 @@
1
- import { DecodeFailureCode, DecodeRefusalCode, ErrorResult, Micro509Error } from "../result/result.js";
1
+ import { SignatureVerifiers } from "../internal/crypto/sig-verify.js";
2
+ import { DecodeFailureCode, ErrorResult, Micro509Error } from "../result/result.js";
2
3
  import { DistributionPoint, DistributionPointReason, GeneralName, IssuingDistributionPoint } from "../x509/extensions.js";
3
4
  import { NameInput } from "../x509/name.js";
4
5
  import { ParsedCertificate, ParsedDistributionPoint, ParsedIssuingDistributionPoint, ParsedName } from "../x509/parse.js";
@@ -43,6 +44,21 @@ export type ParsedRevocationReason = RevocationReason | UnrecognizedRevocationRe
43
44
  * - `'reject'`: the evidence cannot settle the certificate's status.
44
45
  */
45
46
  export type UnrecognizedReasonCodePolicy = "revoked" | "reject";
47
+ /**
48
+ * Treatment of delta CRLs that the attempt limits leave unread when a delta
49
+ * CRL already read supersedes them by both `thisUpdate` and CRL number. RFC
50
+ * 5280 §5.2.4 has a relying party use the most recent delta CRL, and §3.3 and
51
+ * §5.3.1 keep a lasting revocation listed in every later CRL, so reading the
52
+ * older ones is a check on the issuer's consistency.
53
+ *
54
+ * - `'indeterminate'`: any unread candidate leaves the status
55
+ * `delta_crl_retry_limit_exceeded`, unless a revocation no delta CRL can
56
+ * remove already settled it (default).
57
+ * - `'ignore'`: an unread candidate does not count when the delta CRL that
58
+ * settled the status as good supersedes it, or, without a good status, when
59
+ * it is not current and a delta CRL read supersedes it.
60
+ */
61
+ export type SupersededDeltaCrlPolicy = "indeterminate" | "ignore";
46
62
  /**
47
63
  * Input for {@linkcode createCertificateRevocationList}.
48
64
  */
@@ -113,8 +129,10 @@ export interface ParsedCertificateRevocationList {
113
129
  readonly version: number;
114
130
  /** DER-encoded TBSCertList — the signed payload for signature verification. */
115
131
  readonly tbsCertListDer: Uint8Array;
116
- /** Raw signature bytes from the CRL outer wrapper. */
132
+ /** Signature bytes: the `signatureValue` BIT STRING content after its unused-bit count. */
117
133
  readonly signatureValue: Uint8Array;
134
+ /** Unused bits in the final octet of {@linkcode signatureValue}, 0 through 7. */
135
+ readonly signatureValueUnusedBits: number;
118
136
  /** CRL issuer distinguished name. */
119
137
  readonly issuer: ParsedName;
120
138
  /** Issue date of this CRL. */
@@ -153,7 +171,7 @@ export type CrlCertificateSource = string | Uint8Array | ParsedCertificate;
153
171
  * `limit_exceeded` report a CRL or issuer certificate micro509 cannot decode
154
172
  * (see {@linkcode ParseCertificateRevocationListErrorCode}).
155
173
  */
156
- export interface VerifyCertificateRevocationListSignatureFailure extends Micro509Error<"signature_invalid" | DecodeRefusalCode> {
174
+ export interface VerifyCertificateRevocationListSignatureFailure extends Micro509Error<"signature_invalid" | DecodeFailureCode> {
157
175
  /** Always `false` for failures. */
158
176
  readonly ok: false;
159
177
  }
@@ -166,7 +184,19 @@ export type VerifyCertificateRevocationListSignatureResult = {
166
184
  readonly ok: true;
167
185
  /** Parsed CRL with a verified signature. */
168
186
  readonly value: ParsedCertificateRevocationList;
169
- } | ErrorResult<"signature_invalid" | DecodeRefusalCode, Record<never, never>, VerifyCertificateRevocationListSignatureFailure>;
187
+ } | ErrorResult<"signature_invalid" | DecodeFailureCode, Record<never, never>, VerifyCertificateRevocationListSignatureFailure>;
188
+ /** Options for {@linkcode verifyCertificateRevocationListSignature}. */
189
+ export interface VerifyCertificateRevocationListSignatureOptions {
190
+ /**
191
+ * Caller verifiers for signature algorithms micro509 does not verify through
192
+ * WebCrypto, keyed by dotted-decimal signature algorithm OID. One runs only
193
+ * where the CRL signature would otherwise use unsupported algorithm
194
+ * parameters, with the parameters in the issuer certificate. A key that
195
+ * micro509 verifies natively, a key that is no OID, or a value that is no
196
+ * function throws `RangeError`.
197
+ */
198
+ readonly signatureVerifiers?: SignatureVerifiers;
199
+ }
170
200
  /**
171
201
  * Input for {@linkcode validateCertificateRevocationList}.
172
202
  */
@@ -179,7 +209,8 @@ export interface ValidateCertificateRevocationListInput {
179
209
  readonly at?: Date;
180
210
  /**
181
211
  * Tolerance in milliseconds for clock skew when checking `thisUpdate` and
182
- * `nextUpdate`. It also widens `maxAgeMs` by the same amount.
212
+ * `nextUpdate`. It also widens `maxAgeMs` by the same amount. Throws
213
+ * `RangeError` when negative or not finite.
183
214
  */
184
215
  readonly clockSkewMs?: number;
185
216
  /**
@@ -187,9 +218,20 @@ export interface ValidateCertificateRevocationListInput {
187
218
  * this fails with `stale_crl` even when `nextUpdate` is absent or later.
188
219
  * Unbounded by default, in which case a CRL without `nextUpdate` fails with
189
220
  * `stale_crl`. RFC 5280 §3.3 leaves the required recency of revocation data
190
- * to local policy.
221
+ * to local policy. {@linkcode checkCertificateRevocationAgainstCrl} still
222
+ * reports a revocation such a CRL lists with a reason other than
223
+ * certificateHold, for a certificate that has not expired (RFC 5280 §5.3.1).
191
224
  */
192
225
  readonly maxAgeMs?: number;
226
+ /**
227
+ * Caller verifiers for signature algorithms micro509 does not verify through
228
+ * WebCrypto, keyed by dotted-decimal signature algorithm OID. One runs only
229
+ * where the CRL signature would otherwise use unsupported algorithm
230
+ * parameters, with the parameters in the issuer certificate. A key that
231
+ * micro509 verifies natively, a key that is no OID, or a value that is no
232
+ * function throws `RangeError`.
233
+ */
234
+ readonly signatureVerifiers?: SignatureVerifiers;
193
235
  }
194
236
  /**
195
237
  * Failure detail for {@linkcode validateCertificateRevocationList}.
@@ -197,7 +239,7 @@ export interface ValidateCertificateRevocationListInput {
197
239
  * Possible codes: `signature_invalid`, `issuer_mismatch`, `stale_crl`, `crl_sign_not_permitted`,
198
240
  * and `unsupported` or `limit_exceeded` for a CRL or issuer certificate micro509 cannot decode.
199
241
  */
200
- export interface ValidateCertificateRevocationListFailure extends Micro509Error<"signature_invalid" | "issuer_mismatch" | "stale_crl" | "crl_sign_not_permitted" | DecodeRefusalCode> {
242
+ export interface ValidateCertificateRevocationListFailure extends Micro509Error<"signature_invalid" | "issuer_mismatch" | "stale_crl" | "crl_sign_not_permitted" | DecodeFailureCode> {
201
243
  /** Always `false` for failures. */
202
244
  readonly ok: false;
203
245
  }
@@ -210,7 +252,7 @@ export type ValidateCertificateRevocationListResult = {
210
252
  readonly ok: true;
211
253
  /** Validated and parsed CRL. */
212
254
  readonly value: ParsedCertificateRevocationList;
213
- } | ErrorResult<"signature_invalid" | "issuer_mismatch" | "stale_crl" | "crl_sign_not_permitted" | DecodeRefusalCode, Record<never, never>, ValidateCertificateRevocationListFailure>;
255
+ } | ErrorResult<"signature_invalid" | "issuer_mismatch" | "stale_crl" | "crl_sign_not_permitted" | DecodeFailureCode, Record<never, never>, ValidateCertificateRevocationListFailure>;
214
256
  /**
215
257
  * Input for {@linkcode checkCertificateRevocationAgainstCrl}.
216
258
  */
@@ -231,7 +273,10 @@ export interface CheckCertificateRevocationAgainstCrlInput {
231
273
  readonly deltaCrl?: CrlSource;
232
274
  /** Evaluation time. Defaults to `new Date()`. */
233
275
  readonly at?: Date;
234
- /** Clock-skew tolerance in milliseconds for freshness checks. It also widens `maxAgeMs`. */
276
+ /**
277
+ * Clock-skew tolerance in milliseconds for freshness checks. It also widens
278
+ * `maxAgeMs`. Throws `RangeError` when negative or not finite.
279
+ */
235
280
  readonly clockSkewMs?: number;
236
281
  /** Maximum age of each CRL's `thisUpdate` in milliseconds. See {@linkcode ValidateCertificateRevocationListInput.maxAgeMs}. */
237
282
  readonly maxAgeMs?: number;
@@ -240,9 +285,18 @@ export interface CheckCertificateRevocationAgainstCrlInput {
240
285
  * fails the check with `reason_code_unrecognized`. Defaults to `'revoked'`.
241
286
  */
242
287
  readonly unrecognizedReasonCode?: UnrecognizedReasonCodePolicy;
288
+ /**
289
+ * Caller verifiers for signature algorithms micro509 does not verify through
290
+ * WebCrypto, keyed by dotted-decimal signature algorithm OID. One runs only
291
+ * where the CRL signature would otherwise use unsupported algorithm
292
+ * parameters, with the parameters in the issuer certificate. A key that
293
+ * micro509 verifies natively, a key that is no OID, or a value that is no
294
+ * function throws `RangeError`.
295
+ */
296
+ readonly signatureVerifiers?: SignatureVerifiers;
243
297
  }
244
298
  /** Error codes that {@linkcode checkCertificateRevocationAgainstCrl} may return. */
245
- export type CheckCertificateRevocationAgainstCrlErrorCode = "signature_invalid" | "issuer_mismatch" | "stale_crl" | "crl_sign_not_permitted" | "non_applicable" | "reason_code_unrecognized" | DecodeRefusalCode;
299
+ export type CheckCertificateRevocationAgainstCrlErrorCode = "signature_invalid" | "issuer_mismatch" | "stale_crl" | "crl_sign_not_permitted" | "non_applicable" | "reason_code_unrecognized" | DecodeFailureCode;
246
300
  /** Structured reason why a CRL was deemed non-applicable to a given certificate. */
247
301
  export type CrlApplicabilityFailureReason = "certificate_scope_mismatch" | "delta_crl_incompatible" | "unsupported_delta_crl" | "distribution_point_mismatch" | "unsupported_indirect_crl" | "issuer_mismatch" | "reasons_mismatch";
248
302
  /** Structured details attached to a {@linkcode CheckCertificateRevocationAgainstCrlFailure}. */
@@ -371,7 +425,7 @@ export declare function parseCertificateRevocationListPem(pem: string): ParseCer
371
425
  * Does **not** check issuer name match, key-usage, or freshness — use
372
426
  * {@linkcode validateCertificateRevocationList} for full validation.
373
427
  */
374
- export declare function verifyCertificateRevocationListSignature(crl: string | Uint8Array, issuerCertificate: string | Uint8Array): Promise<VerifyCertificateRevocationListSignatureResult>;
428
+ export declare function verifyCertificateRevocationListSignature(crl: string | Uint8Array, issuerCertificate: string | Uint8Array, options?: VerifyCertificateRevocationListSignatureOptions): Promise<VerifyCertificateRevocationListSignatureResult>;
375
429
  /**
376
430
  * Full CRL validation: issuer name match, authority key identifier match,
377
431
  * a v3 issuer certificate's key usage must be present and assert cRLSign