micro509 0.13.0 → 0.15.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 (165) hide show
  1. package/CHANGELOG.md +2064 -0
  2. package/README.md +111 -183
  3. package/dist/crypto/crypto.d.ts +104 -0
  4. package/dist/crypto/crypto.js +105 -0
  5. package/dist/crypto/crypto.js.map +1 -0
  6. package/dist/crypto.d.ts +4 -0
  7. package/dist/crypto.js +1 -0
  8. package/dist/der/der.d.ts +41 -33
  9. package/dist/der/der.js +26 -24
  10. package/dist/der/der.js.map +1 -1
  11. package/dist/index.d.ts +18 -14
  12. package/dist/index.js +19 -17
  13. package/dist/internal/asn1/asn1.d.ts +3 -6
  14. package/dist/internal/asn1/asn1.js +355 -44
  15. package/dist/internal/asn1/asn1.js.map +1 -1
  16. package/dist/internal/asn1/ber.js +146 -0
  17. package/dist/internal/asn1/ber.js.map +1 -0
  18. package/dist/internal/asn1/decode-refusal.js +29 -0
  19. package/dist/internal/asn1/decode-refusal.js.map +1 -0
  20. package/dist/internal/asn1/der.d.ts +42 -43
  21. package/dist/internal/asn1/der.js +148 -56
  22. package/dist/internal/asn1/der.js.map +1 -1
  23. package/dist/internal/asn1/oids.js +90 -54
  24. package/dist/internal/asn1/oids.js.map +1 -1
  25. package/dist/internal/asn1/oids2.js +1 -2
  26. package/dist/internal/asn1/oids2.js.map +1 -1
  27. package/dist/internal/crypto/algorithm-names.js +5 -2
  28. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  29. package/dist/internal/crypto/ecdsa.js +13 -8
  30. package/dist/internal/crypto/ecdsa.js.map +1 -1
  31. package/dist/internal/crypto/hash.js +1 -2
  32. package/dist/internal/crypto/hash.js.map +1 -1
  33. package/dist/internal/crypto/pbes2.d.ts +51 -0
  34. package/dist/internal/crypto/pbes2.js +86 -34
  35. package/dist/internal/crypto/pbes2.js.map +1 -1
  36. package/dist/internal/crypto/rsa-pss.js +48 -44
  37. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  38. package/dist/internal/crypto/sig-verify.d.ts +28 -0
  39. package/dist/internal/crypto/sig-verify.js +111 -62
  40. package/dist/internal/crypto/sig-verify.js.map +1 -1
  41. package/dist/internal/crypto/signing.d.ts +1 -4
  42. package/dist/internal/crypto/signing.js +28 -29
  43. package/dist/internal/crypto/signing.js.map +1 -1
  44. package/dist/internal/crypto/webcrypto.js +1 -2
  45. package/dist/internal/crypto/webcrypto.js.map +1 -1
  46. package/dist/internal/shared/base64.js +8 -3
  47. package/dist/internal/shared/base64.js.map +1 -1
  48. package/dist/internal/shared/dn.d.ts +13 -0
  49. package/dist/internal/shared/dn.js +101 -48
  50. package/dist/internal/shared/dn.js.map +1 -1
  51. package/dist/internal/shared/idna-tables.js +7217 -0
  52. package/dist/internal/shared/idna-tables.js.map +1 -0
  53. package/dist/internal/shared/idna.js +296 -0
  54. package/dist/internal/shared/idna.js.map +1 -0
  55. package/dist/internal/shared/ip.d.ts +66 -0
  56. package/dist/internal/shared/ip.js +19 -3
  57. package/dist/internal/shared/ip.js.map +1 -1
  58. package/dist/internal/shared/mailbox.js +26 -0
  59. package/dist/internal/shared/mailbox.js.map +1 -0
  60. package/dist/internal/shared/punycode.js +101 -0
  61. package/dist/internal/shared/punycode.js.map +1 -0
  62. package/dist/internal/shared/rfc3454-tables.js +1 -2
  63. package/dist/internal/shared/rfc3454-tables.js.map +1 -1
  64. package/dist/internal/shared/rfc4518-tables.js +119 -0
  65. package/dist/internal/shared/rfc4518-tables.js.map +1 -0
  66. package/dist/internal/shared/uri-host.js +102 -0
  67. package/dist/internal/shared/uri-host.js.map +1 -0
  68. package/dist/internal/verify/name-constraints-engine.js +246 -131
  69. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  70. package/dist/internal/verify/policy-engine.js +6 -21
  71. package/dist/internal/verify/policy-engine.js.map +1 -1
  72. package/dist/internal/verify/verify-path.d.ts +4 -0
  73. package/dist/internal/verify/verify-path.js +264 -128
  74. package/dist/internal/verify/verify-path.js.map +1 -1
  75. package/dist/internal/x509/directory-name.js +23 -0
  76. package/dist/internal/x509/directory-name.js.map +1 -0
  77. package/dist/internal/x509/extension-bits.js +15 -13
  78. package/dist/internal/x509/extension-bits.js.map +1 -1
  79. package/dist/internal/x509/extension-errors.d.ts +3 -0
  80. package/dist/internal/x509/extension-errors.js +19 -0
  81. package/dist/internal/x509/extension-errors.js.map +1 -0
  82. package/dist/internal/x509/extension-registry.js +157 -81
  83. package/dist/internal/x509/extension-registry.js.map +1 -1
  84. package/dist/internal/x509/general-name-profile.js +129 -0
  85. package/dist/internal/x509/general-name-profile.js.map +1 -0
  86. package/dist/internal/x509/general-name-tags.js +27 -0
  87. package/dist/internal/x509/general-name-tags.js.map +1 -0
  88. package/dist/internal/x509/general-name.js +183 -0
  89. package/dist/internal/x509/general-name.js.map +1 -0
  90. package/dist/internal/x509/name-fields.js +21 -12
  91. package/dist/internal/x509/name-fields.js.map +1 -1
  92. package/dist/internal/x509/or-address.js +217 -0
  93. package/dist/internal/x509/or-address.js.map +1 -0
  94. package/dist/keys/keys.d.ts +124 -95
  95. package/dist/keys/keys.js +362 -214
  96. package/dist/keys/keys.js.map +1 -1
  97. package/dist/keys.d.ts +3 -2
  98. package/dist/keys.js +3 -2
  99. package/dist/pem/pem.d.ts +17 -19
  100. package/dist/pem/pem.js +122 -41
  101. package/dist/pem/pem.js.map +1 -1
  102. package/dist/pem.js +1 -2
  103. package/dist/pkcs/pfx.d.ts +57 -32
  104. package/dist/pkcs/pfx.js +209 -173
  105. package/dist/pkcs/pfx.js.map +1 -1
  106. package/dist/pkcs/pkcs12-mac.d.ts +104 -27
  107. package/dist/pkcs/pkcs12-mac.js +266 -79
  108. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  109. package/dist/pkcs/pkcs7.d.ts +123 -53
  110. package/dist/pkcs/pkcs7.js +314 -238
  111. package/dist/pkcs/pkcs7.js.map +1 -1
  112. package/dist/pkcs.d.ts +5 -4
  113. package/dist/result/result.d.ts +43 -28
  114. package/dist/result/result.js +27 -14
  115. package/dist/result/result.js.map +1 -1
  116. package/dist/result.d.ts +2 -2
  117. package/dist/result.js +1 -2
  118. package/dist/revocation/chain.d.ts +101 -23
  119. package/dist/revocation/chain.js +456 -206
  120. package/dist/revocation/chain.js.map +1 -1
  121. package/dist/revocation/crl.d.ts +140 -65
  122. package/dist/revocation/crl.js +691 -391
  123. package/dist/revocation/crl.js.map +1 -1
  124. package/dist/revocation/ocsp.d.ts +145 -69
  125. package/dist/revocation/ocsp.js +347 -297
  126. package/dist/revocation/ocsp.js.map +1 -1
  127. package/dist/revocation/revocation.d.ts +48 -36
  128. package/dist/revocation/revocation.js +112 -63
  129. package/dist/revocation/revocation.js.map +1 -1
  130. package/dist/revocation.d.ts +5 -5
  131. package/dist/revocation.js +5 -5
  132. package/dist/verify/identity.d.ts +18 -20
  133. package/dist/verify/identity.js +120 -90
  134. package/dist/verify/identity.js.map +1 -1
  135. package/dist/verify/name-constraints.d.ts +1 -4
  136. package/dist/verify/policy.d.ts +15 -8
  137. package/dist/verify/verify.d.ts +86 -46
  138. package/dist/verify/verify.js +309 -143
  139. package/dist/verify/verify.js.map +1 -1
  140. package/dist/verify.d.ts +3 -2
  141. package/dist/verify.js +4 -3
  142. package/dist/x509/certificate.d.ts +50 -28
  143. package/dist/x509/certificate.js +69 -36
  144. package/dist/x509/certificate.js.map +1 -1
  145. package/dist/x509/csr.d.ts +9 -8
  146. package/dist/x509/csr.js +10 -11
  147. package/dist/x509/csr.js.map +1 -1
  148. package/dist/x509/extensions.d.ts +207 -82
  149. package/dist/x509/extensions.js +561 -128
  150. package/dist/x509/extensions.js.map +1 -1
  151. package/dist/x509/fingerprint.d.ts +4 -7
  152. package/dist/x509/fingerprint.js +1 -2
  153. package/dist/x509/fingerprint.js.map +1 -1
  154. package/dist/x509/name-text.d.ts +7 -9
  155. package/dist/x509/name-text.js +20 -4
  156. package/dist/x509/name-text.js.map +1 -1
  157. package/dist/x509/name.d.ts +15 -14
  158. package/dist/x509/name.js +23 -19
  159. package/dist/x509/name.js.map +1 -1
  160. package/dist/x509/parse.d.ts +165 -64
  161. package/dist/x509/parse.js +444 -459
  162. package/dist/x509/parse.js.map +1 -1
  163. package/dist/x509.d.ts +8 -5
  164. package/dist/x509.js +10 -8
  165. package/package.json +90 -65
@@ -1,27 +1,26 @@
1
- import { Result } from "../result/result.js";
1
+ import { DecodeRefusalCode, Result } from "../result/result.js";
2
2
  import { ParsedCertificate } from "../x509/parse.js";
3
- import { CertificateRevocationListMaterial, CheckCertificateRevocationAgainstCrlErrorCode, CheckCertificateRevocationAgainstCrlFailure, CheckCertificateRevocationAgainstCrlFailureDetails, CheckCertificateRevocationAgainstCrlGoodValue, CheckCertificateRevocationAgainstCrlInput, CheckCertificateRevocationAgainstCrlResult, CheckCertificateRevocationAgainstCrlRevokedValue, CheckCertificateRevocationAgainstCrlValue, CreateCertificateRevocationListInput, CrlApplicabilityFailureReason, CrlCertificateSource, CrlSource, ParseCertificateRevocationListErrorCode, ParseCertificateRevocationListFailure, ParseCertificateRevocationListResult, ParsedCertificateRevocationList, ParsedRevokedCertificate, RevocationReason, RevokedCertificateInput, ValidateCertificateRevocationListFailure, ValidateCertificateRevocationListInput, ValidateCertificateRevocationListResult, VerifyCertificateRevocationListSignatureFailure, VerifyCertificateRevocationListSignatureResult, checkCertificateRevocationAgainstCrl, createCertificateRevocationList, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, validateCertificateRevocationList, verifyCertificateRevocationListSignature } from "./crl.js";
4
- import { CreateOcspRequestInput, CreateOcspRequestItemInput, CreateOcspResponseInput, CreateOcspSingleResponseInput, OcspCertStatus, OcspCertificateSource, OcspHashAlgorithm, OcspRequestMaterial, OcspRequestSource, OcspResponderRevocationPolicy, OcspResponseMaterial, OcspResponseStatus, ParseOcspRequestErrorCode, ParseOcspRequestFailure, ParseOcspRequestResult, ParseOcspResponseErrorCode, ParseOcspResponseFailure, ParseOcspResponseResult, ParsedOcspCertId, ParsedOcspRequest, ParsedOcspResponderId, ParsedOcspResponse, ParsedOcspSingleResponse, ValidateOcspResponseErrorCode, ValidateOcspResponseFailure, ValidateOcspResponseInput, ValidateOcspResponseResult, VerifyOcspResponseSignatureFailure, VerifyOcspResponseSignatureResult, createOcspRequest, createOcspResponse, hasOcspNoCheckExtension, parseOcspRequestDer, parseOcspRequestDerOrThrow, parseOcspRequestPem, parseOcspRequestPemOrThrow, parseOcspResponseDer, parseOcspResponseDerOrThrow, parseOcspResponsePem, parseOcspResponsePemOrThrow, validateOcspResponse, verifyOcspResponseSignature } from "./ocsp.js";
5
- //#region src/revocation/revocation.d.ts
3
+ import { CertificateRevocationListMaterial, CheckCertificateRevocationAgainstCrlErrorCode, CheckCertificateRevocationAgainstCrlFailure, CheckCertificateRevocationAgainstCrlFailureDetails, CheckCertificateRevocationAgainstCrlGoodValue, CheckCertificateRevocationAgainstCrlInput, CheckCertificateRevocationAgainstCrlResult, CheckCertificateRevocationAgainstCrlRevokedValue, CheckCertificateRevocationAgainstCrlValue, CreateCertificateRevocationListInput, CrlApplicabilityFailureReason, CrlCertificateSource, CrlEncoderErrorCode, CrlSource, ParseCertificateRevocationListErrorCode, ParseCertificateRevocationListFailure, ParseCertificateRevocationListResult, ParsedCertificateRevocationList, ParsedRevocationReason, ParsedRevokedCertificate, RevocationReason, RevokedCertificateInput, UnrecognizedReasonCodePolicy, UnrecognizedRevocationReason, ValidateCertificateRevocationListFailure, ValidateCertificateRevocationListInput, ValidateCertificateRevocationListResult, VerifyCertificateRevocationListSignatureFailure, VerifyCertificateRevocationListSignatureResult, checkCertificateRevocationAgainstCrl, createCertificateRevocationList, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, revocationReasonFromCode, validateCertificateRevocationList, verifyCertificateRevocationListSignature } from "./crl.js";
4
+ import { CreateOcspCertStatusInput, CreateOcspRequestInput, CreateOcspRequestItemInput, CreateOcspResponseInput, CreateOcspSingleResponseInput, OcspCertStatus, OcspCertificateSource, OcspEncoderErrorCode, OcspHashAlgorithm, OcspRequestMaterial, OcspRequestSource, OcspResponderRevocationPolicy, OcspResponseMaterial, OcspResponseStatus, ParseOcspRequestErrorCode, ParseOcspRequestFailure, ParseOcspRequestResult, ParseOcspResponseErrorCode, ParseOcspResponseFailure, ParseOcspResponseResult, ParsedOcspCertId, ParsedOcspCertStatus, ParsedOcspRequest, ParsedOcspResponderId, ParsedOcspResponse, ParsedOcspSingleResponse, ValidateOcspResponseErrorCode, ValidateOcspResponseFailure, ValidateOcspResponseInput, ValidateOcspResponseResult, VerifyOcspResponseSignatureFailure, VerifyOcspResponseSignatureResult, createOcspRequest, createOcspResponse, hasOcspNoCheckExtension, parseOcspRequestDer, parseOcspRequestDerOrThrow, parseOcspRequestPem, parseOcspRequestPemOrThrow, parseOcspResponseDer, parseOcspResponseDerOrThrow, parseOcspResponsePem, parseOcspResponsePemOrThrow, validateOcspResponse, verifyOcspResponseSignature } from "./ocsp.js";
6
5
  /** Unified revocation outcome across CRL and OCSP evidence. */
7
- type RevocationStatus = "good" | "revoked" | "indeterminate";
6
+ export type RevocationStatus = "good" | "revoked" | "indeterminate";
8
7
  /** Which revocation mechanism produced the evidence. */
9
- type RevocationEvidenceKind = "crl" | "ocsp";
8
+ export type RevocationEvidenceKind = "crl" | "ocsp";
10
9
  /** PEM string, DER bytes, or already-parsed certificate. */
11
- type RevocationCertificateSource = string | Uint8Array | ParsedCertificate;
10
+ export type RevocationCertificateSource = string | Uint8Array | ParsedCertificate;
12
11
  /** Where the OCSP responder URI came from. */
13
- type OcspResponderSource = "configured" | "authorityInfoAccess";
12
+ export type OcspResponderSource = "configured" | "authorityInfoAccess";
14
13
  /** PEM or DER bytes of a pre-configured OCSP responder certificate. */
15
- type ConfiguredOcspResponderCertificate = string | Uint8Array;
14
+ export type ConfiguredOcspResponderCertificate = string | Uint8Array;
16
15
  /** A manually-configured OCSP responder endpoint. */
17
- interface ConfiguredOcspResponder {
16
+ export interface ConfiguredOcspResponder {
18
17
  /** OCSP responder URI (typically `http://...`). */
19
18
  readonly uri: string;
20
19
  /** Known responder certificate — skips embedded-certificate discovery. */
21
20
  readonly responderCertificate?: ConfiguredOcspResponderCertificate;
22
21
  }
23
22
  /** One candidate OCSP responder resolved by {@linkcode resolveOcspResponderCandidates}. */
24
- interface OcspResponderCandidate {
23
+ export interface OcspResponderCandidate {
25
24
  /** Whether this candidate came from configuration or the certificate's AIA extension. */
26
25
  readonly source: OcspResponderSource;
27
26
  /** OCSP responder URI. */
@@ -30,14 +29,14 @@ interface OcspResponderCandidate {
30
29
  readonly responderCertificate?: ConfiguredOcspResponderCertificate;
31
30
  }
32
31
  /** Input for {@linkcode resolveOcspResponderCandidates}. */
33
- interface ResolveOcspResponderCandidatesInput {
32
+ export interface ResolveOcspResponderCandidatesInput {
34
33
  /** Certificate whose AIA extension will be inspected for OCSP URIs. */
35
34
  readonly certificate: RevocationCertificateSource;
36
35
  /** Manually-configured responders — checked before AIA-derived ones. */
37
36
  readonly configuredResponders?: readonly ConfiguredOcspResponder[];
38
37
  }
39
38
  /** CRL-based revocation evidence for {@linkcode CheckCertificateRevocationInput.evidence}. */
40
- interface RevocationCrlEvidenceInput {
39
+ export interface RevocationCrlEvidenceInput {
41
40
  /** Discriminator for the CRL evidence variant. */
42
41
  readonly kind: "crl";
43
42
  /** Complete (base) CRL. */
@@ -46,7 +45,7 @@ interface RevocationCrlEvidenceInput {
46
45
  readonly deltaCrl?: CrlSource;
47
46
  }
48
47
  /** OCSP-based revocation evidence for {@linkcode CheckCertificateRevocationInput.evidence}. */
49
- interface RevocationOcspEvidenceInput {
48
+ export interface RevocationOcspEvidenceInput {
50
49
  /** Discriminator for the OCSP evidence variant. */
51
50
  readonly kind: "ocsp";
52
51
  /** OCSP response to validate. */
@@ -57,9 +56,9 @@ interface RevocationOcspEvidenceInput {
57
56
  readonly responderCertificate?: OcspCertificateSource;
58
57
  }
59
58
  /** Discriminated union of CRL and OCSP evidence inputs. */
60
- type RevocationEvidenceInput = RevocationCrlEvidenceInput | RevocationOcspEvidenceInput;
59
+ export type RevocationEvidenceInput = RevocationCrlEvidenceInput | RevocationOcspEvidenceInput;
61
60
  /** Input for {@linkcode checkCertificateRevocation}. */
62
- interface CheckCertificateRevocationInput {
61
+ export interface CheckCertificateRevocationInput {
63
62
  /** Certificate whose revocation status to determine. */
64
63
  readonly certificate: RevocationCertificateSource;
65
64
  /** Issuer of `certificate`. */
@@ -68,17 +67,31 @@ interface CheckCertificateRevocationInput {
68
67
  readonly evidence?: readonly RevocationEvidenceInput[];
69
68
  /** Evaluation time. Defaults to `new Date()`. */
70
69
  readonly at?: Date;
71
- /** Clock-skew tolerance in milliseconds. */
70
+ /** Clock-skew tolerance in milliseconds. It also widens `crlMaxAgeMs`. */
72
71
  readonly clockSkewMs?: number;
72
+ /** Maximum age of each CRL's `thisUpdate` in milliseconds. Unbounded by default. See {@linkcode ValidateCertificateRevocationListInput.maxAgeMs}. */
73
+ readonly crlMaxAgeMs?: number;
74
+ /**
75
+ * OCSP client profile for every OCSP evidence entry. See
76
+ * {@linkcode ValidateOcspResponseInput.profile}. Defaults to `'rfc6960'`.
77
+ */
78
+ readonly ocspProfile?: ValidateOcspResponseInput["profile"];
79
+ /**
80
+ * Treatment of CRL or OCSP evidence whose CRLReason is unrecognized. See
81
+ * {@linkcode UnrecognizedReasonCodePolicy}. `'reject'` turns that evidence
82
+ * into `reason_code_unrecognized`, which also keeps other evidence from
83
+ * settling the status as `good`. Defaults to `'revoked'`.
84
+ */
85
+ readonly unrecognizedReasonCode?: UnrecognizedReasonCodePolicy;
73
86
  }
74
87
  /** Error codes that {@linkcode checkCertificateRevocation} may surface inside an `indeterminate` result. */
75
- type CheckCertificateRevocationErrorCode = "revocation_evidence_missing" | "revocation_status_indeterminate";
88
+ export type CheckCertificateRevocationErrorCode = "revocation_evidence_missing" | "revocation_status_indeterminate" | DecodeRefusalCode;
76
89
  /** Every {@linkcode RevocationIndeterminateReasonCode}, as a runtime array. */
77
- declare const REVOCATION_INDETERMINATE_REASON_CODES: readonly ["certificate_status_missing", "certificate_status_unknown", "crl_sign_not_permitted", "issuer_mismatch", "non_applicable", "nonce_mismatch", "ocsp_signing_missing", "request_mismatch", "responder_id_mismatch", "responder_chain_invalid", "responder_revoked", "responder_revocation_unknown", "response_status_invalid", "signature_invalid", "stale_crl", "stale_response"];
90
+ export declare const REVOCATION_INDETERMINATE_REASON_CODES: readonly ["certificate_status_missing", "certificate_status_unknown", "crl_sign_not_permitted", "issuer_mismatch", "next_update_missing", "non_applicable", "nonce_mismatch", "ocsp_signing_missing", "reason_code_unrecognized", "reason_coverage_incomplete", "request_mismatch", "responder_id_mismatch", "responder_chain_invalid", "responder_revoked", "responder_revocation_unknown", "response_status_invalid", "signature_invalid", "stale_crl", "stale_response", "unsupported", "limit_exceeded"];
78
91
  /** Why a particular piece of evidence could not produce a definitive `good`/`revoked` answer. */
79
- type RevocationIndeterminateReasonCode = (typeof REVOCATION_INDETERMINATE_REASON_CODES)[number];
92
+ export type RevocationIndeterminateReasonCode = (typeof REVOCATION_INDETERMINATE_REASON_CODES)[number];
80
93
  /** One piece of evidence that failed to produce a definitive revocation answer. */
81
- interface RevocationIndeterminateEvidence {
94
+ export interface RevocationIndeterminateEvidence {
82
95
  /** Whether this evidence was CRL or OCSP. */
83
96
  readonly kind: RevocationEvidenceKind;
84
97
  /** Machine-readable reason code. */
@@ -89,14 +102,14 @@ interface RevocationIndeterminateEvidence {
89
102
  readonly reason?: CrlApplicabilityFailureReason;
90
103
  }
91
104
  /** Diagnostic details attached to an `indeterminate` revocation result. */
92
- interface CheckCertificateRevocationFailureDetails {
105
+ export interface CheckCertificateRevocationFailureDetails {
93
106
  /** Which evidence kinds were attempted (`'crl'`, `'ocsp'`, or both). */
94
107
  readonly checkedSources: readonly RevocationEvidenceKind[];
95
108
  /** Per-evidence explanations of why no definitive answer was reached. */
96
109
  readonly indeterminateEvidence: readonly RevocationIndeterminateEvidence[];
97
110
  }
98
111
  /** Revocation status could not be determined from the provided evidence. */
99
- interface RevocationCheckIndeterminateValue {
112
+ export interface RevocationCheckIndeterminateValue {
100
113
  /** Status is indeterminate. */
101
114
  readonly status: Extract<RevocationStatus, "indeterminate">;
102
115
  /** Why revocation status is indeterminate. */
@@ -107,7 +120,7 @@ interface RevocationCheckIndeterminateValue {
107
120
  readonly details: CheckCertificateRevocationFailureDetails;
108
121
  }
109
122
  /** Certificate is not revoked according to the checked evidence. */
110
- interface RevocationCheckGoodValue {
123
+ export interface RevocationCheckGoodValue {
111
124
  /** Certificate is not revoked. */
112
125
  readonly status: Extract<RevocationStatus, "good">;
113
126
  /** Which evidence kind confirmed the good status. */
@@ -116,7 +129,7 @@ interface RevocationCheckGoodValue {
116
129
  readonly message: string;
117
130
  }
118
131
  /** Certificate is revoked according to the checked evidence. */
119
- interface RevocationCheckRevokedValue {
132
+ export interface RevocationCheckRevokedValue {
120
133
  /** Certificate is revoked. */
121
134
  readonly status: Extract<RevocationStatus, "revoked">;
122
135
  /** Which evidence kind reported the revocation. */
@@ -125,25 +138,25 @@ interface RevocationCheckRevokedValue {
125
138
  readonly message: string;
126
139
  /** When the certificate was revoked (from CRL entry or OCSP response). */
127
140
  readonly revokedAt?: Date;
128
- /** CRL reason string (from CRL evidence). */
129
- readonly revocationReason?: RevocationReason;
130
- /** CRL reason integer code (from OCSP evidence). */
131
- readonly revocationReasonCode?: number;
141
+ /** CRL reason (from CRL evidence). */
142
+ readonly revocationReason?: ParsedRevocationReason;
143
+ /** CRL reason code (from OCSP evidence). */
144
+ readonly revocationReasonCode?: bigint;
132
145
  }
133
146
  /** Discriminated union of `good`, `revoked`, and `indeterminate` revocation outcomes. */
134
- type CheckCertificateRevocationValue = RevocationCheckGoodValue | RevocationCheckRevokedValue | RevocationCheckIndeterminateValue;
147
+ export type CheckCertificateRevocationValue = RevocationCheckGoodValue | RevocationCheckRevokedValue | RevocationCheckIndeterminateValue;
135
148
  /**
136
149
  * Result of {@linkcode checkCertificateRevocation}. Always succeeds (`ok: true`) —
137
150
  * the `value.status` discriminator carries the actual outcome.
138
151
  */
139
- type CheckCertificateRevocationResult = Result<CheckCertificateRevocationValue, never>;
152
+ export type CheckCertificateRevocationResult = Result<CheckCertificateRevocationValue, never>;
140
153
  /** Extracts OCSP responder URIs from the certificate's Authority Information Access extension. */
141
- declare function getCertificateOcspResponderUris(certificate: RevocationCertificateSource): readonly string[];
154
+ export declare function getCertificateOcspResponderUris(certificate: RevocationCertificateSource): readonly string[];
142
155
  /**
143
156
  * Merges configured OCSP responders with those discovered from the certificate's
144
157
  * AIA extension. Configured responders take priority; duplicates are deduplicated by URI.
145
158
  */
146
- declare function resolveOcspResponderCandidates(input: ResolveOcspResponderCandidatesInput): readonly OcspResponderCandidate[];
159
+ export declare function resolveOcspResponderCandidates(input: ResolveOcspResponderCandidatesInput): readonly OcspResponderCandidate[];
147
160
  /**
148
161
  * Evaluates all provided CRL and OCSP evidence to determine the certificate's
149
162
  * revocation status. Returns the first `revoked` if any, else the first `good`,
@@ -163,7 +176,6 @@ declare function resolveOcspResponderCandidates(input: ResolveOcspResponderCandi
163
176
  * }
164
177
  * ```
165
178
  */
166
- declare function checkCertificateRevocation(input: CheckCertificateRevocationInput): Promise<CheckCertificateRevocationResult>;
167
- //#endregion
168
- export { type CertificateRevocationListMaterial, type CheckCertificateRevocationAgainstCrlErrorCode, type CheckCertificateRevocationAgainstCrlFailure, type CheckCertificateRevocationAgainstCrlFailureDetails, type CheckCertificateRevocationAgainstCrlGoodValue, type CheckCertificateRevocationAgainstCrlInput, type CheckCertificateRevocationAgainstCrlResult, type CheckCertificateRevocationAgainstCrlRevokedValue, type CheckCertificateRevocationAgainstCrlValue, CheckCertificateRevocationErrorCode, CheckCertificateRevocationFailureDetails, CheckCertificateRevocationInput, CheckCertificateRevocationResult, CheckCertificateRevocationValue, ConfiguredOcspResponder, ConfiguredOcspResponderCertificate, type CreateCertificateRevocationListInput, type CreateOcspRequestInput, type CreateOcspRequestItemInput, type CreateOcspResponseInput, type CreateOcspSingleResponseInput, type CrlApplicabilityFailureReason, type CrlCertificateSource, type CrlSource, type OcspCertStatus, type OcspCertificateSource, type OcspHashAlgorithm, type OcspRequestMaterial, type OcspRequestSource, OcspResponderCandidate, type OcspResponderRevocationPolicy, OcspResponderSource, type OcspResponseMaterial, type OcspResponseStatus, type ParseCertificateRevocationListErrorCode, type ParseCertificateRevocationListFailure, type ParseCertificateRevocationListResult, type ParseOcspRequestErrorCode, type ParseOcspRequestFailure, type ParseOcspRequestResult, type ParseOcspResponseErrorCode, type ParseOcspResponseFailure, type ParseOcspResponseResult, type ParsedCertificateRevocationList, type ParsedOcspCertId, type ParsedOcspRequest, type ParsedOcspResponderId, type ParsedOcspResponse, type ParsedOcspSingleResponse, type ParsedRevokedCertificate, REVOCATION_INDETERMINATE_REASON_CODES, ResolveOcspResponderCandidatesInput, RevocationCertificateSource, RevocationCheckGoodValue, RevocationCheckIndeterminateValue, RevocationCheckRevokedValue, RevocationCrlEvidenceInput, RevocationEvidenceInput, RevocationEvidenceKind, RevocationIndeterminateEvidence, RevocationIndeterminateReasonCode, RevocationOcspEvidenceInput, type RevocationReason, RevocationStatus, type RevokedCertificateInput, type ValidateCertificateRevocationListFailure, type ValidateCertificateRevocationListInput, type ValidateCertificateRevocationListResult, type ValidateOcspResponseErrorCode, type ValidateOcspResponseFailure, type ValidateOcspResponseInput, type ValidateOcspResponseResult, type VerifyCertificateRevocationListSignatureFailure, type VerifyCertificateRevocationListSignatureResult, type VerifyOcspResponseSignatureFailure, type VerifyOcspResponseSignatureResult, checkCertificateRevocation, type checkCertificateRevocationAgainstCrl, type createCertificateRevocationList, type createOcspRequest, type createOcspResponse, getCertificateOcspResponderUris, type hasOcspNoCheckExtension, type isCertificateRevoked, type parseCertificateRevocationListDer, type parseCertificateRevocationListDerOrThrow, type parseCertificateRevocationListPem, type parseCertificateRevocationListPemOrThrow, type parseOcspRequestDer, type parseOcspRequestDerOrThrow, type parseOcspRequestPem, type parseOcspRequestPemOrThrow, type parseOcspResponseDer, type parseOcspResponseDerOrThrow, type parseOcspResponsePem, type parseOcspResponsePemOrThrow, resolveOcspResponderCandidates, type validateCertificateRevocationList, type validateOcspResponse, type verifyCertificateRevocationListSignature, type verifyOcspResponseSignature };
179
+ export declare function checkCertificateRevocation(input: CheckCertificateRevocationInput): Promise<CheckCertificateRevocationResult>;
180
+ export type { CertificateRevocationListMaterial, CheckCertificateRevocationAgainstCrlErrorCode, CheckCertificateRevocationAgainstCrlFailure, CheckCertificateRevocationAgainstCrlFailureDetails, CheckCertificateRevocationAgainstCrlGoodValue, CheckCertificateRevocationAgainstCrlInput, CheckCertificateRevocationAgainstCrlResult, CheckCertificateRevocationAgainstCrlRevokedValue, CheckCertificateRevocationAgainstCrlValue, CreateCertificateRevocationListInput, CreateOcspCertStatusInput, CreateOcspRequestInput, CreateOcspRequestItemInput, CreateOcspResponseInput, CreateOcspSingleResponseInput, CrlApplicabilityFailureReason, CrlCertificateSource, CrlEncoderErrorCode, CrlSource, OcspCertStatus, OcspCertificateSource, OcspEncoderErrorCode, OcspHashAlgorithm, OcspRequestMaterial, OcspRequestSource, OcspResponderRevocationPolicy, OcspResponseMaterial, OcspResponseStatus, ParseCertificateRevocationListErrorCode, ParseCertificateRevocationListFailure, ParseCertificateRevocationListResult, ParseOcspRequestErrorCode, ParseOcspRequestFailure, ParseOcspRequestResult, ParseOcspResponseErrorCode, ParseOcspResponseFailure, ParseOcspResponseResult, ParsedCertificateRevocationList, ParsedOcspCertId, ParsedOcspCertStatus, ParsedOcspRequest, ParsedOcspResponderId, ParsedOcspResponse, ParsedOcspSingleResponse, ParsedRevocationReason, ParsedRevokedCertificate, RevocationReason, RevokedCertificateInput, UnrecognizedReasonCodePolicy, UnrecognizedRevocationReason, ValidateCertificateRevocationListFailure, ValidateCertificateRevocationListInput, ValidateCertificateRevocationListResult, ValidateOcspResponseErrorCode, ValidateOcspResponseFailure, ValidateOcspResponseInput, ValidateOcspResponseResult, VerifyCertificateRevocationListSignatureFailure, VerifyCertificateRevocationListSignatureResult, VerifyOcspResponseSignatureFailure, VerifyOcspResponseSignatureResult, checkCertificateRevocationAgainstCrl, createCertificateRevocationList, createOcspRequest, createOcspResponse, hasOcspNoCheckExtension, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, parseOcspRequestDer, parseOcspRequestDerOrThrow, parseOcspRequestPem, parseOcspRequestPemOrThrow, parseOcspResponseDer, parseOcspResponseDerOrThrow, parseOcspResponsePem, parseOcspResponsePemOrThrow, revocationReasonFromCode, validateCertificateRevocationList, validateOcspResponse, verifyCertificateRevocationListSignature, verifyOcspResponseSignature };
169
181
  //# sourceMappingURL=revocation.d.ts.map
@@ -1,16 +1,27 @@
1
- import { parseCertificateDerOrThrow as e, parseCertificateFromSource as t } from "../x509/parse.js";
2
- import { checkCertificateRevocationAgainstCrl as n } from "./crl.js";
3
- import { validateOcspResponse as r } from "./ocsp.js";
4
- //#region src/revocation/revocation.ts
1
+ import { DECODE_REFUSAL_CODES as e, rethrowIfInvariant as t } from "../result/result.js";
2
+ import { decodeRefusalOf as n } from "../internal/asn1/decode-refusal.js";
3
+ import { parseCertificateDerOrThrow as r, parseCertificateFromSource as i } from "../x509/parse.js";
4
+ import { assertCrlMaxAge as a, checkCertificateRevocationAgainstCrl as o, coversAllDistributionPointReasons as s, revocationReasonFromCode as c } from "./crl.js";
5
+ import { validateOcspResponse as l } from "./ocsp.js";
6
+ // src/revocation/revocation.ts
7
+ /**
8
+ * Revocation orchestration: evaluates CRL and OCSP evidence to produce a
9
+ * unified `good`/`revoked`/`indeterminate` status for a certificate.
10
+ *
11
+ * @module
12
+ */
5
13
  /** Every {@linkcode RevocationIndeterminateReasonCode}, as a runtime array. */
6
- const i = [
14
+ const u = [
7
15
  "certificate_status_missing",
8
16
  "certificate_status_unknown",
9
17
  "crl_sign_not_permitted",
10
18
  "issuer_mismatch",
19
+ "next_update_missing",
11
20
  "non_applicable",
12
21
  "nonce_mismatch",
13
22
  "ocsp_signing_missing",
23
+ "reason_code_unrecognized",
24
+ "reason_coverage_incomplete",
14
25
  "request_mismatch",
15
26
  "responder_id_mismatch",
16
27
  "responder_chain_invalid",
@@ -19,7 +30,9 @@ const i = [
19
30
  "response_status_invalid",
20
31
  "signature_invalid",
21
32
  "stale_crl",
22
- "stale_response"
33
+ "stale_response",
34
+ "unsupported",
35
+ "limit_exceeded"
23
36
  ];
24
37
  /** Extracts OCSP responder URIs from the certificate's Authority Information Access extension. */
25
38
  function getCertificateOcspResponderUris(e) {
@@ -30,7 +43,11 @@ function getCertificateOcspResponderUris(e) {
30
43
  return [];
31
44
  }
32
45
  let n = [], r = /* @__PURE__ */ new Set();
33
- for (let e of t.authorityInfoAccess ?? []) e.method !== "ocsp" || r.has(e.uri) || (r.add(e.uri), n.push(e.uri));
46
+ for (let e of t.authorityInfoAccess ?? []) {
47
+ if (e.method !== "ocsp" || e.location.type !== "uri") continue;
48
+ let t = e.location.value;
49
+ r.has(t) || (r.add(t), n.push(t));
50
+ }
34
51
  return n;
35
52
  }
36
53
  /**
@@ -75,6 +92,7 @@ function resolveOcspResponderCandidates(e) {
75
92
  * ```
76
93
  */
77
94
  async function checkCertificateRevocation(e) {
95
+ a(e.crlMaxAgeMs);
78
96
  let t = e.evidence ?? [], n = t.map((e) => e.kind);
79
97
  if (t.length === 0) return revocationSuccess({
80
98
  status: "indeterminate",
@@ -88,65 +106,88 @@ async function checkCertificateRevocation(e) {
88
106
  let r;
89
107
  try {
90
108
  r = normalizeCertificate(e.certificate);
91
- } catch {
92
- return revocationSuccess({
93
- status: "indeterminate",
94
- code: "revocation_status_indeterminate",
95
- message: "Certificate input is malformed",
96
- details: {
97
- checkedSources: n,
98
- indeterminateEvidence: []
99
- }
100
- });
109
+ } catch (e) {
110
+ return undecodableCertificateResult(e, n);
101
111
  }
102
- let i, a = [];
112
+ let i, o, s = /* @__PURE__ */ new Set(), c = [];
103
113
  for (let n of t) {
104
- let t;
105
- try {
106
- t = n.kind === "crl" ? await checkCertificateRevocationWithCrl(e, n, r) : await checkCertificateRevocationWithOcsp(e, n, r);
107
- } catch {
108
- a.push({
109
- kind: n.kind,
110
- code: "signature_invalid",
111
- message: `${n.kind.toUpperCase()} evidence input is malformed`
112
- });
113
- continue;
114
- }
114
+ let t = await checkRevocationEvidenceEntry(e, n, r);
115
115
  if (t.status === "revoked") return revocationSuccess(t.result);
116
116
  if (t.status === "good") {
117
- i ??= t.result;
118
- continue;
119
- }
120
- a.push(t.detail);
117
+ if (t.coveredReasons === void 0) i ??= t.result;
118
+ else {
119
+ o ??= t.result;
120
+ for (let e of t.coveredReasons) s.add(e);
121
+ }
122
+ } else c.push(t.detail);
121
123
  }
122
- return revocationSuccess(i === void 0 ? {
124
+ return settleRevocationEvidence(i, o, s, c, n);
125
+ }
126
+ /** The result once no evidence revoked the certificate outright. */
127
+ function settleRevocationEvidence(e, t, n, r, i) {
128
+ let a = r.some((e) => e.code === "reason_code_unrecognized");
129
+ return e !== void 0 && !a ? revocationSuccess(e) : t !== void 0 && !a && s(n) ? revocationSuccess(t) : (t !== void 0 && !s(n) && r.push({
130
+ kind: "crl",
131
+ code: "reason_coverage_incomplete",
132
+ message: "CRL evidence covers only some revocation reasons"
133
+ }), revocationSuccess({
123
134
  status: "indeterminate",
124
135
  code: "revocation_status_indeterminate",
125
136
  message: "No revocation evidence established certificate status",
126
137
  details: {
127
- checkedSources: n,
128
- indeterminateEvidence: a
138
+ checkedSources: i,
139
+ indeterminateEvidence: r
140
+ }
141
+ }));
142
+ }
143
+ function undecodableCertificateResult(t, r) {
144
+ let i = n(t, e);
145
+ return revocationSuccess({
146
+ status: "indeterminate",
147
+ code: i?.code ?? "revocation_status_indeterminate",
148
+ message: i?.message ?? "Certificate input is malformed",
149
+ details: {
150
+ checkedSources: r,
151
+ indeterminateEvidence: []
129
152
  }
130
- } : i);
153
+ });
154
+ }
155
+ async function checkRevocationEvidenceEntry(r, i, a) {
156
+ try {
157
+ return i.kind === "crl" ? await checkCertificateRevocationWithCrl(r, i, a) : await checkCertificateRevocationWithOcsp(r, i, a);
158
+ } catch (r) {
159
+ t(r);
160
+ let a = n(r, e);
161
+ return {
162
+ status: "indeterminate",
163
+ detail: {
164
+ kind: i.kind,
165
+ code: a?.code ?? "signature_invalid",
166
+ message: a?.message ?? `${i.kind.toUpperCase()} evidence input is malformed`
167
+ }
168
+ };
169
+ }
131
170
  }
132
171
  /** Evaluates a single CRL evidence entry via {@linkcode checkCertificateRevocationAgainstCrl}. */
133
- async function checkCertificateRevocationWithCrl(e, t, r) {
134
- let i = await n({
135
- certificate: r,
172
+ async function checkCertificateRevocationWithCrl(e, t, n) {
173
+ let r = await o({
174
+ certificate: n,
136
175
  issuerCertificate: e.issuerCertificate,
137
176
  crl: t.crl,
138
177
  ...t.deltaCrl === void 0 ? {} : { deltaCrl: t.deltaCrl },
139
178
  ...e.at === void 0 ? {} : { at: e.at },
140
- ...e.clockSkewMs === void 0 ? {} : { clockSkewMs: e.clockSkewMs }
179
+ ...e.clockSkewMs === void 0 ? {} : { clockSkewMs: e.clockSkewMs },
180
+ ...e.crlMaxAgeMs === void 0 ? {} : { maxAgeMs: e.crlMaxAgeMs },
181
+ ...e.unrecognizedReasonCode === void 0 ? {} : { unrecognizedReasonCode: e.unrecognizedReasonCode }
141
182
  });
142
- return i.ok ? i.value.status === "revoked" ? {
183
+ return r.ok ? r.value.status === "revoked" ? {
143
184
  status: "revoked",
144
185
  result: {
145
186
  status: "revoked",
146
187
  kind: "crl",
147
188
  message: "Certificate is revoked according to CRL evidence",
148
- revokedAt: i.value.revocationDate,
149
- ...i.value.reasonCode === void 0 ? {} : { revocationReason: i.value.reasonCode }
189
+ revokedAt: r.value.revocationDate,
190
+ ...r.value.reasonCode === void 0 ? {} : { revocationReason: r.value.reasonCode }
150
191
  }
151
192
  } : {
152
193
  status: "good",
@@ -154,53 +195,62 @@ async function checkCertificateRevocationWithCrl(e, t, r) {
154
195
  status: "good",
155
196
  kind: "crl",
156
197
  message: "Certificate is not revoked according to CRL evidence"
157
- }
198
+ },
199
+ coveredReasons: r.value.coveredReasons
158
200
  } : {
159
201
  status: "indeterminate",
160
202
  detail: {
161
203
  kind: "crl",
162
- code: i.code,
163
- message: i.message,
164
- ...i.details?.reason === void 0 ? {} : { reason: i.details.reason }
204
+ code: r.code,
205
+ message: r.message,
206
+ ...r.details?.reason === void 0 ? {} : { reason: r.details.reason }
165
207
  }
166
208
  };
167
209
  }
168
210
  /** Evaluates a single OCSP evidence entry via {@linkcode validateOcspResponse}. */
169
211
  async function checkCertificateRevocationWithOcsp(e, t, n) {
170
- let i = await r({
212
+ let r = await l({
171
213
  response: t.response,
172
214
  issuerCertificate: e.issuerCertificate,
173
215
  ...t.request === void 0 ? {} : { request: t.request },
174
216
  ...t.responderCertificate === void 0 ? {} : { responderCertificate: t.responderCertificate },
175
217
  ...e.at === void 0 ? {} : { at: e.at },
176
- ...e.clockSkewMs === void 0 ? {} : { clockSkewMs: e.clockSkewMs }
218
+ ...e.clockSkewMs === void 0 ? {} : { clockSkewMs: e.clockSkewMs },
219
+ ...e.ocspProfile === void 0 ? {} : { profile: e.ocspProfile }
177
220
  });
178
- if (!i.ok) return {
221
+ if (!r.ok) return {
179
222
  status: "indeterminate",
180
223
  detail: {
181
224
  kind: "ocsp",
182
- code: i.code,
183
- message: i.message
225
+ code: r.code,
226
+ message: r.message
184
227
  }
185
228
  };
186
- let a = i.value.responses?.find((e) => normalizeHex(e.certId.serialNumberHex) === normalizeHex(n.serialNumberHex));
187
- return a === void 0 ? {
229
+ let i = r.value.responses?.find((e) => normalizeHex(e.certId.serialNumberHex) === normalizeHex(n.serialNumberHex));
230
+ return i === void 0 ? {
188
231
  status: "indeterminate",
189
232
  detail: {
190
233
  kind: "ocsp",
191
234
  code: "certificate_status_missing",
192
235
  message: "OCSP response does not include certificate status for the target certificate"
193
236
  }
194
- } : a.certStatus === "revoked" ? {
237
+ } : i.certStatus === "revoked" ? e.unrecognizedReasonCode === "reject" && typeof c(i.revocationReasonCode) == "object" ? {
238
+ status: "indeterminate",
239
+ detail: {
240
+ kind: "ocsp",
241
+ code: "reason_code_unrecognized",
242
+ message: `OCSP response carries unrecognized reason code ${String(i.revocationReasonCode)}`
243
+ }
244
+ } : {
195
245
  status: "revoked",
196
246
  result: {
197
247
  status: "revoked",
198
248
  kind: "ocsp",
199
249
  message: "Certificate is revoked according to OCSP evidence",
200
- ...a.revokedAt === void 0 ? {} : { revokedAt: a.revokedAt },
201
- ...a.revocationReasonCode === void 0 ? {} : { revocationReasonCode: a.revocationReasonCode }
250
+ ...i.revokedAt === void 0 ? {} : { revokedAt: i.revokedAt },
251
+ ...i.revocationReasonCode === void 0 ? {} : { revocationReasonCode: i.revocationReasonCode }
202
252
  }
203
- } : a.certStatus === "good" ? {
253
+ } : i.certStatus === "good" ? {
204
254
  status: "good",
205
255
  result: {
206
256
  status: "good",
@@ -217,8 +267,8 @@ async function checkCertificateRevocationWithOcsp(e, t, n) {
217
267
  };
218
268
  }
219
269
  /** Accepts PEM, DER, or already-parsed certificate and returns a parsed certificate. */
220
- function normalizeCertificate(n) {
221
- return hasParsedCertificateShape(n) ? e(new Uint8Array(n.der)) : t(n);
270
+ function normalizeCertificate(e) {
271
+ return hasParsedCertificateShape(e) ? r(new Uint8Array(e.der)) : i(e);
222
272
  }
223
273
  function hasParsedCertificateShape(e) {
224
274
  return typeof e != "string" && "subjectPublicKeyInfoDer" in e;
@@ -234,7 +284,6 @@ function revocationSuccess(e) {
234
284
  value: e
235
285
  };
236
286
  }
237
- //#endregion
238
- export { i as REVOCATION_INDETERMINATE_REASON_CODES, checkCertificateRevocation, getCertificateOcspResponderUris, resolveOcspResponderCandidates };
287
+ export { u as REVOCATION_INDETERMINATE_REASON_CODES, checkCertificateRevocation, getCertificateOcspResponderUris, resolveOcspResponderCandidates };
239
288
 
240
289
  //# sourceMappingURL=revocation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"revocation.js","names":[],"sources":["../../src/revocation/revocation.ts"],"sourcesContent":["/**\n * Revocation orchestration: evaluates CRL and OCSP evidence to produce a\n * unified `good`/`revoked`/`indeterminate` status for a certificate.\n *\n * @module\n */\n\nimport type { Result } from '#micro509/result/result';\nimport type {\n\tCrlApplicabilityFailureReason,\n\tCrlSource,\n\tRevocationReason,\n} from '#micro509/revocation/crl';\nimport { checkCertificateRevocationAgainstCrl } from '#micro509/revocation/crl';\nimport type {\n\tOcspCertificateSource,\n\tOcspRequestSource,\n\tParsedOcspResponse,\n} from '#micro509/revocation/ocsp';\nimport { validateOcspResponse } from '#micro509/revocation/ocsp';\nimport type { ParsedCertificate } from '#micro509/x509/parse';\nimport { parseCertificateDerOrThrow, parseCertificateFromSource } from '#micro509/x509/parse';\n\nexport type * from '#micro509/revocation/crl';\nexport type * from '#micro509/revocation/ocsp';\n\n/** Unified revocation outcome across CRL and OCSP evidence. */\nexport type RevocationStatus = 'good' | 'revoked' | 'indeterminate';\n\n/** Which revocation mechanism produced the evidence. */\nexport type RevocationEvidenceKind = 'crl' | 'ocsp';\n/** PEM string, DER bytes, or already-parsed certificate. */\nexport type RevocationCertificateSource = string | Uint8Array | ParsedCertificate;\n/** Where the OCSP responder URI came from. */\nexport type OcspResponderSource = 'configured' | 'authorityInfoAccess';\n/** PEM or DER bytes of a pre-configured OCSP responder certificate. */\nexport type ConfiguredOcspResponderCertificate = string | Uint8Array;\n\n/** A manually-configured OCSP responder endpoint. */\nexport interface ConfiguredOcspResponder {\n\t/** OCSP responder URI (typically `http://...`). */\n\treadonly uri: string;\n\t/** Known responder certificate — skips embedded-certificate discovery. */\n\treadonly responderCertificate?: ConfiguredOcspResponderCertificate;\n}\n\n/** One candidate OCSP responder resolved by {@linkcode resolveOcspResponderCandidates}. */\nexport interface OcspResponderCandidate {\n\t/** Whether this candidate came from configuration or the certificate's AIA extension. */\n\treadonly source: OcspResponderSource;\n\t/** OCSP responder URI. */\n\treadonly uri: string;\n\t/** Pre-known responder certificate, if available. */\n\treadonly responderCertificate?: ConfiguredOcspResponderCertificate;\n}\n\n/** Input for {@linkcode resolveOcspResponderCandidates}. */\nexport interface ResolveOcspResponderCandidatesInput {\n\t/** Certificate whose AIA extension will be inspected for OCSP URIs. */\n\treadonly certificate: RevocationCertificateSource;\n\t/** Manually-configured responders — checked before AIA-derived ones. */\n\treadonly configuredResponders?: readonly ConfiguredOcspResponder[];\n}\n\n/** CRL-based revocation evidence for {@linkcode CheckCertificateRevocationInput.evidence}. */\nexport interface RevocationCrlEvidenceInput {\n\t/** Discriminator for the CRL evidence variant. */\n\treadonly kind: 'crl';\n\t/** Complete (base) CRL. */\n\treadonly crl: CrlSource;\n\t/** Optional delta CRL for more recent revocation information. */\n\treadonly deltaCrl?: CrlSource;\n}\n\n/** OCSP-based revocation evidence for {@linkcode CheckCertificateRevocationInput.evidence}. */\nexport interface RevocationOcspEvidenceInput {\n\t/** Discriminator for the OCSP evidence variant. */\n\treadonly kind: 'ocsp';\n\t/** OCSP response to validate. */\n\treadonly response: string | Uint8Array | ParsedOcspResponse;\n\t/** Original OCSP request — enables nonce and coverage checks. */\n\treadonly request?: OcspRequestSource;\n\t/** Explicit responder certificate — overrides embedded certificate discovery. */\n\treadonly responderCertificate?: OcspCertificateSource;\n}\n\n/** Discriminated union of CRL and OCSP evidence inputs. */\nexport type RevocationEvidenceInput = RevocationCrlEvidenceInput | RevocationOcspEvidenceInput;\n\n/** Input for {@linkcode checkCertificateRevocation}. */\nexport interface CheckCertificateRevocationInput {\n\t/** Certificate whose revocation status to determine. */\n\treadonly certificate: RevocationCertificateSource;\n\t/** Issuer of `certificate`. */\n\treadonly issuerCertificate: RevocationCertificateSource;\n\t/** CRL and/or OCSP evidence to evaluate. Returns `indeterminate` if empty. */\n\treadonly evidence?: readonly RevocationEvidenceInput[];\n\t/** Evaluation time. Defaults to `new Date()`. */\n\treadonly at?: Date;\n\t/** Clock-skew tolerance in milliseconds. */\n\treadonly clockSkewMs?: number;\n}\n\n/** Error codes that {@linkcode checkCertificateRevocation} may surface inside an `indeterminate` result. */\nexport type CheckCertificateRevocationErrorCode =\n\t| 'revocation_evidence_missing'\n\t| 'revocation_status_indeterminate';\n\n/** Every {@linkcode RevocationIndeterminateReasonCode}, as a runtime array. */\nexport const REVOCATION_INDETERMINATE_REASON_CODES = [\n\t'certificate_status_missing',\n\t'certificate_status_unknown',\n\t'crl_sign_not_permitted',\n\t'issuer_mismatch',\n\t'non_applicable',\n\t'nonce_mismatch',\n\t'ocsp_signing_missing',\n\t'request_mismatch',\n\t'responder_id_mismatch',\n\t'responder_chain_invalid',\n\t'responder_revoked',\n\t'responder_revocation_unknown',\n\t'response_status_invalid',\n\t'signature_invalid',\n\t'stale_crl',\n\t'stale_response',\n] as const;\n\n/** Why a particular piece of evidence could not produce a definitive `good`/`revoked` answer. */\nexport type RevocationIndeterminateReasonCode =\n\t(typeof REVOCATION_INDETERMINATE_REASON_CODES)[number];\n\n/** One piece of evidence that failed to produce a definitive revocation answer. */\nexport interface RevocationIndeterminateEvidence {\n\t/** Whether this evidence was CRL or OCSP. */\n\treadonly kind: RevocationEvidenceKind;\n\t/** Machine-readable reason code. */\n\treadonly code: RevocationIndeterminateReasonCode;\n\t/** Human-readable explanation. */\n\treadonly message: string;\n\t/** CRL-specific applicability failure reason, when `kind` is `'crl'`. */\n\treadonly reason?: CrlApplicabilityFailureReason;\n}\n\n/** Diagnostic details attached to an `indeterminate` revocation result. */\nexport interface CheckCertificateRevocationFailureDetails {\n\t/** Which evidence kinds were attempted (`'crl'`, `'ocsp'`, or both). */\n\treadonly checkedSources: readonly RevocationEvidenceKind[];\n\t/** Per-evidence explanations of why no definitive answer was reached. */\n\treadonly indeterminateEvidence: readonly RevocationIndeterminateEvidence[];\n}\n\n/** Revocation status could not be determined from the provided evidence. */\nexport interface RevocationCheckIndeterminateValue {\n\t/** Status is indeterminate. */\n\treadonly status: Extract<RevocationStatus, 'indeterminate'>;\n\t/** Why revocation status is indeterminate. */\n\treadonly code: CheckCertificateRevocationErrorCode;\n\t/** Human-readable diagnostic message. */\n\treadonly message: string;\n\t/** What evidence was attempted and why each failed. */\n\treadonly details: CheckCertificateRevocationFailureDetails;\n}\n\n/** Certificate is not revoked according to the checked evidence. */\nexport interface RevocationCheckGoodValue {\n\t/** Certificate is not revoked. */\n\treadonly status: Extract<RevocationStatus, 'good'>;\n\t/** Which evidence kind confirmed the good status. */\n\treadonly kind: RevocationEvidenceKind;\n\t/** Human-readable diagnostic message. */\n\treadonly message: string;\n}\n\n/** Certificate is revoked according to the checked evidence. */\nexport interface RevocationCheckRevokedValue {\n\t/** Certificate is revoked. */\n\treadonly status: Extract<RevocationStatus, 'revoked'>;\n\t/** Which evidence kind reported the revocation. */\n\treadonly kind: RevocationEvidenceKind;\n\t/** Human-readable diagnostic message. */\n\treadonly message: string;\n\t/** When the certificate was revoked (from CRL entry or OCSP response). */\n\treadonly revokedAt?: Date;\n\t/** CRL reason string (from CRL evidence). */\n\treadonly revocationReason?: RevocationReason;\n\t/** CRL reason integer code (from OCSP evidence). */\n\treadonly revocationReasonCode?: number;\n}\n\n/** Discriminated union of `good`, `revoked`, and `indeterminate` revocation outcomes. */\nexport type CheckCertificateRevocationValue =\n\t| RevocationCheckGoodValue\n\t| RevocationCheckRevokedValue\n\t| RevocationCheckIndeterminateValue;\n\n/**\n * Result of {@linkcode checkCertificateRevocation}. Always succeeds (`ok: true`) —\n * the `value.status` discriminator carries the actual outcome.\n */\nexport type CheckCertificateRevocationResult = Result<CheckCertificateRevocationValue, never>;\n\n/** Internal intermediate result from evaluating a single piece of revocation evidence. */\ntype RevocationEvidenceCheck =\n\t| { readonly status: 'good'; readonly result: RevocationCheckGoodValue }\n\t| { readonly status: 'revoked'; readonly result: RevocationCheckRevokedValue }\n\t| { readonly status: 'indeterminate'; readonly detail: RevocationIndeterminateEvidence };\n\n/** Extracts OCSP responder URIs from the certificate's Authority Information Access extension. */\nexport function getCertificateOcspResponderUris(\n\tcertificate: RevocationCertificateSource,\n): readonly string[] {\n\tlet parsedCertificate: ParsedCertificate;\n\ttry {\n\t\tparsedCertificate = normalizeCertificate(certificate);\n\t} catch {\n\t\treturn [];\n\t}\n\tconst uris: string[] = [];\n\tconst seen = new Set<string>();\n\tfor (const accessDescription of parsedCertificate.authorityInfoAccess ?? []) {\n\t\tif (accessDescription.method !== 'ocsp' || seen.has(accessDescription.uri)) {\n\t\t\tcontinue;\n\t\t}\n\t\tseen.add(accessDescription.uri);\n\t\turis.push(accessDescription.uri);\n\t}\n\treturn uris;\n}\n\n/**\n * Merges configured OCSP responders with those discovered from the certificate's\n * AIA extension. Configured responders take priority; duplicates are deduplicated by URI.\n */\nexport function resolveOcspResponderCandidates(\n\tinput: ResolveOcspResponderCandidatesInput,\n): readonly OcspResponderCandidate[] {\n\tconst candidates: OcspResponderCandidate[] = [];\n\tconst configuredByUri = new Map<string, ConfiguredOcspResponder>();\n\tfor (const configuredResponder of input.configuredResponders ?? []) {\n\t\tconst existing = configuredByUri.get(configuredResponder.uri);\n\t\tif (\n\t\t\texisting === undefined ||\n\t\t\t(existing.responderCertificate === undefined &&\n\t\t\t\tconfiguredResponder.responderCertificate !== undefined)\n\t\t) {\n\t\t\tconfiguredByUri.set(configuredResponder.uri, configuredResponder);\n\t\t}\n\t}\n\tconst seen = new Set<string>();\n\tfor (const configuredResponder of configuredByUri.values()) {\n\t\tseen.add(configuredResponder.uri);\n\t\tcandidates.push({\n\t\t\tsource: 'configured',\n\t\t\turi: configuredResponder.uri,\n\t\t\t...(configuredResponder.responderCertificate === undefined\n\t\t\t\t? {}\n\t\t\t\t: { responderCertificate: configuredResponder.responderCertificate }),\n\t\t});\n\t}\n\tfor (const uri of getCertificateOcspResponderUris(input.certificate)) {\n\t\tif (seen.has(uri)) {\n\t\t\tcontinue;\n\t\t}\n\t\tseen.add(uri);\n\t\tcandidates.push({\n\t\t\tsource: 'authorityInfoAccess',\n\t\t\turi,\n\t\t});\n\t}\n\treturn candidates;\n}\n\n/**\n * Evaluates all provided CRL and OCSP evidence to determine the certificate's\n * revocation status. Returns the first `revoked` if any, else the first `good`,\n * else `indeterminate` with diagnostic details about each indeterminate evidence.\n *\n * @example\n * ```ts\n * import { checkCertificateRevocation } from 'micro509';\n *\n * const result = await checkCertificateRevocation({\n * certificate: leafPem,\n * issuerCertificate: caPem,\n * evidence: [{ kind: 'crl', crl: crlPem }],\n * });\n * if (result.ok && result.value.status === 'revoked') {\n * console.log('revoked at', result.value.revokedAt);\n * }\n * ```\n */\nexport async function checkCertificateRevocation(\n\tinput: CheckCertificateRevocationInput,\n): Promise<CheckCertificateRevocationResult> {\n\tconst evidence = input.evidence ?? [];\n\tconst checkedSources = evidence.map((entry) => entry.kind);\n\tif (evidence.length === 0) {\n\t\treturn revocationSuccess({\n\t\t\tstatus: 'indeterminate',\n\t\t\tcode: 'revocation_evidence_missing',\n\t\t\tmessage: 'No CRL or OCSP evidence provided',\n\t\t\tdetails: {\n\t\t\t\tcheckedSources,\n\t\t\t\tindeterminateEvidence: [],\n\t\t\t},\n\t\t});\n\t}\n\tlet normalizedCertificate: ParsedCertificate;\n\ttry {\n\t\tnormalizedCertificate = normalizeCertificate(input.certificate);\n\t} catch {\n\t\treturn revocationSuccess({\n\t\t\tstatus: 'indeterminate',\n\t\t\tcode: 'revocation_status_indeterminate',\n\t\t\tmessage: 'Certificate input is malformed',\n\t\t\tdetails: {\n\t\t\t\tcheckedSources,\n\t\t\t\tindeterminateEvidence: [],\n\t\t\t},\n\t\t});\n\t}\n\tlet goodResult: RevocationCheckGoodValue | undefined;\n\tconst indeterminateEvidence: RevocationIndeterminateEvidence[] = [];\n\tfor (const entry of evidence) {\n\t\tlet result: RevocationEvidenceCheck;\n\t\ttry {\n\t\t\tresult =\n\t\t\t\tentry.kind === 'crl'\n\t\t\t\t\t? await checkCertificateRevocationWithCrl(input, entry, normalizedCertificate)\n\t\t\t\t\t: await checkCertificateRevocationWithOcsp(input, entry, normalizedCertificate);\n\t\t} catch {\n\t\t\tindeterminateEvidence.push({\n\t\t\t\tkind: entry.kind,\n\t\t\t\tcode: 'signature_invalid',\n\t\t\t\tmessage: `${entry.kind.toUpperCase()} evidence input is malformed`,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tif (result.status === 'revoked') {\n\t\t\treturn revocationSuccess(result.result);\n\t\t}\n\t\tif (result.status === 'good') {\n\t\t\tgoodResult ??= result.result;\n\t\t\tcontinue;\n\t\t}\n\t\tindeterminateEvidence.push(result.detail);\n\t}\n\tif (goodResult !== undefined) {\n\t\treturn revocationSuccess(goodResult);\n\t}\n\treturn revocationSuccess({\n\t\tstatus: 'indeterminate',\n\t\tcode: 'revocation_status_indeterminate',\n\t\tmessage: 'No revocation evidence established certificate status',\n\t\tdetails: {\n\t\t\tcheckedSources,\n\t\t\tindeterminateEvidence,\n\t\t},\n\t});\n}\n\n/** Evaluates a single CRL evidence entry via {@linkcode checkCertificateRevocationAgainstCrl}. */\nasync function checkCertificateRevocationWithCrl(\n\tinput: CheckCertificateRevocationInput,\n\tevidence: RevocationCrlEvidenceInput,\n\tcertificate: ParsedCertificate,\n): Promise<RevocationEvidenceCheck> {\n\tconst result = await checkCertificateRevocationAgainstCrl({\n\t\tcertificate,\n\t\tissuerCertificate: input.issuerCertificate,\n\t\tcrl: evidence.crl,\n\t\t...(evidence.deltaCrl === undefined ? {} : { deltaCrl: evidence.deltaCrl }),\n\t\t...(input.at === undefined ? {} : { at: input.at }),\n\t\t...(input.clockSkewMs === undefined ? {} : { clockSkewMs: input.clockSkewMs }),\n\t});\n\tif (result.ok) {\n\t\tif (result.value.status === 'revoked') {\n\t\t\treturn {\n\t\t\t\tstatus: 'revoked',\n\t\t\t\tresult: {\n\t\t\t\t\tstatus: 'revoked',\n\t\t\t\t\tkind: 'crl',\n\t\t\t\t\tmessage: 'Certificate is revoked according to CRL evidence',\n\t\t\t\t\trevokedAt: result.value.revocationDate,\n\t\t\t\t\t...(result.value.reasonCode === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { revocationReason: result.value.reasonCode }),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tstatus: 'good',\n\t\t\tresult: {\n\t\t\t\tstatus: 'good',\n\t\t\t\tkind: 'crl',\n\t\t\t\tmessage: 'Certificate is not revoked according to CRL evidence',\n\t\t\t},\n\t\t};\n\t}\n\treturn {\n\t\tstatus: 'indeterminate',\n\t\tdetail: {\n\t\t\tkind: 'crl',\n\t\t\tcode: result.code,\n\t\t\tmessage: result.message,\n\t\t\t...(result.details?.reason === undefined ? {} : { reason: result.details.reason }),\n\t\t},\n\t};\n}\n\n/** Evaluates a single OCSP evidence entry via {@linkcode validateOcspResponse}. */\nasync function checkCertificateRevocationWithOcsp(\n\tinput: CheckCertificateRevocationInput,\n\tevidence: RevocationOcspEvidenceInput,\n\tcertificate: ParsedCertificate,\n): Promise<RevocationEvidenceCheck> {\n\tconst response = await validateOcspResponse({\n\t\tresponse: evidence.response,\n\t\tissuerCertificate: input.issuerCertificate,\n\t\t...(evidence.request === undefined ? {} : { request: evidence.request }),\n\t\t...(evidence.responderCertificate === undefined\n\t\t\t? {}\n\t\t\t: { responderCertificate: evidence.responderCertificate }),\n\t\t...(input.at === undefined ? {} : { at: input.at }),\n\t\t...(input.clockSkewMs === undefined ? {} : { clockSkewMs: input.clockSkewMs }),\n\t});\n\tif (!response.ok) {\n\t\treturn {\n\t\t\tstatus: 'indeterminate',\n\t\t\tdetail: {\n\t\t\t\tkind: 'ocsp',\n\t\t\t\tcode: response.code,\n\t\t\t\tmessage: response.message,\n\t\t\t},\n\t\t};\n\t}\n\tconst matchedResponse = response.value.responses?.find(\n\t\t(entry) =>\n\t\t\tnormalizeHex(entry.certId.serialNumberHex) === normalizeHex(certificate.serialNumberHex),\n\t);\n\tif (matchedResponse === undefined) {\n\t\treturn {\n\t\t\tstatus: 'indeterminate',\n\t\t\tdetail: {\n\t\t\t\tkind: 'ocsp',\n\t\t\t\tcode: 'certificate_status_missing',\n\t\t\t\tmessage: 'OCSP response does not include certificate status for the target certificate',\n\t\t\t},\n\t\t};\n\t}\n\tif (matchedResponse.certStatus === 'revoked') {\n\t\treturn {\n\t\t\tstatus: 'revoked',\n\t\t\tresult: {\n\t\t\t\tstatus: 'revoked',\n\t\t\t\tkind: 'ocsp',\n\t\t\t\tmessage: 'Certificate is revoked according to OCSP evidence',\n\t\t\t\t...(matchedResponse.revokedAt === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { revokedAt: matchedResponse.revokedAt }),\n\t\t\t\t...(matchedResponse.revocationReasonCode === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { revocationReasonCode: matchedResponse.revocationReasonCode }),\n\t\t\t},\n\t\t};\n\t}\n\tif (matchedResponse.certStatus === 'good') {\n\t\treturn {\n\t\t\tstatus: 'good',\n\t\t\tresult: {\n\t\t\t\tstatus: 'good',\n\t\t\t\tkind: 'ocsp',\n\t\t\t\tmessage: 'Certificate is not revoked according to OCSP evidence',\n\t\t\t},\n\t\t};\n\t}\n\treturn {\n\t\tstatus: 'indeterminate',\n\t\tdetail: {\n\t\t\tkind: 'ocsp',\n\t\t\tcode: 'certificate_status_unknown',\n\t\t\tmessage: 'OCSP responder returned certificate status unknown',\n\t\t},\n\t};\n}\n\n/** Accepts PEM, DER, or already-parsed certificate and returns a parsed certificate. */\nfunction normalizeCertificate(certificate: RevocationCertificateSource): ParsedCertificate {\n\treturn hasParsedCertificateShape(certificate)\n\t\t? parseCertificateDerOrThrow(new Uint8Array(certificate.der))\n\t\t: parseCertificateFromSource(certificate);\n}\n\nfunction hasParsedCertificateShape(value: RevocationCertificateSource): value is ParsedCertificate {\n\treturn typeof value !== 'string' && 'subjectPublicKeyInfoDer' in value;\n}\n\n/** Lowercases a hex string for bytewise serial-number comparison. */\nfunction normalizeHex(value: string): string {\n\treturn value.toLowerCase();\n}\n\n/** Wraps a value into a successful `CheckCertificateRevocationResult`. */\nfunction revocationSuccess(\n\tvalue: CheckCertificateRevocationValue,\n): CheckCertificateRevocationResult {\n\treturn { ok: true, value };\n}\n"],"mappings":";;;;;AA6GA,MAAa,IAAwC;CACpD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;AAmFA,SAAgB,gCACf,GACoB;CACpB,IAAI;CACJ,IAAI;EACH,IAAoB,qBAAqB,CAAW;CACrD,QAAQ;EACP,OAAO,CAAC;CACT;CACA,IAAM,IAAiB,CAAC,GAClB,oBAAO,IAAI,IAAY;CAC7B,KAAK,IAAM,KAAqB,EAAkB,uBAAuB,CAAC,GACrE,EAAkB,WAAW,UAAU,EAAK,IAAI,EAAkB,GAAG,MAGzE,EAAK,IAAI,EAAkB,GAAG,GAC9B,EAAK,KAAK,EAAkB,GAAG;CAEhC,OAAO;AACR;;;;;AAMA,SAAgB,+BACf,GACoC;CACpC,IAAM,IAAuC,CAAC,GACxC,oBAAkB,IAAI,IAAqC;CACjE,KAAK,IAAM,KAAuB,EAAM,wBAAwB,CAAC,GAAG;EACnE,IAAM,IAAW,EAAgB,IAAI,EAAoB,GAAG;EAC5D,CACC,MAAa,KAAA,KACZ,EAAS,yBAAyB,KAAA,KAClC,EAAoB,yBAAyB,KAAA,MAE9C,EAAgB,IAAI,EAAoB,KAAK,CAAmB;CAElE;CACA,IAAM,oBAAO,IAAI,IAAY;CAC7B,KAAK,IAAM,KAAuB,EAAgB,OAAO,GAExD,AADA,EAAK,IAAI,EAAoB,GAAG,GAChC,EAAW,KAAK;EACf,QAAQ;EACR,KAAK,EAAoB;EACzB,GAAI,EAAoB,yBAAyB,KAAA,IAC9C,CAAC,IACD,EAAE,sBAAsB,EAAoB,qBAAqB;CACrE,CAAC;CAEF,KAAK,IAAM,KAAO,gCAAgC,EAAM,WAAW,GAC9D,EAAK,IAAI,CAAG,MAGhB,EAAK,IAAI,CAAG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,EAAS,MAAM,WAAW,MAChD,MACA,aAAa,EAAM,OAAO,eAAe,MAAM,aAAa,EAAY,eAAe,CACzF;CAqCA,OApCI,MAAoB,KAAA,IAChB;EACN,QAAQ;EACR,QAAQ;GACP,MAAM;GACN,MAAM;GACN,SAAS;EACV;CACD,IAEG,EAAgB,eAAe,YAC3B;EACN,QAAQ;EACR,QAAQ;GACP,QAAQ;GACR,MAAM;GACN,SAAS;GACT,GAAI,EAAgB,cAAc,KAAA,IAC/B,CAAC,IACD,EAAE,WAAW,EAAgB,UAAU;GAC1C,GAAI,EAAgB,yBAAyB,KAAA,IAC1C,CAAC,IACD,EAAE,sBAAsB,EAAgB,qBAAqB;EACjE;CACD,IAEG,EAAgB,eAAe,SAC3B;EACN,QAAQ;EACR,QAAQ;GACP,QAAQ;GACR,MAAM;GACN,SAAS;EACV;CACD,IAEM;EACN,QAAQ;EACR,QAAQ;GACP,MAAM;GACN,MAAM;GACN,SAAS;EACV;CACD;AACD;;AAGA,SAAS,qBAAqB,GAA6D;CAC1F,OAAO,0BAA0B,CAAW,IACzC,EAA2B,IAAI,WAAW,EAAY,GAAG,CAAC,IAC1D,EAA2B,CAAW;AAC1C;AAEA,SAAS,0BAA0B,GAAgE;CAClG,OAAO,OAAO,KAAU,YAAY,6BAA6B;AAClE;;AAGA,SAAS,aAAa,GAAuB;CAC5C,OAAO,EAAM,YAAY;AAC1B;;AAGA,SAAS,kBACR,GACmC;CACnC,OAAO;EAAE,IAAI;EAAM;CAAM;AAC1B"}
1
+ {"version":3,"file":"revocation.js","names":["REVOCATION_INDETERMINATE_REASON_CODES","parsedCertificate","certificate","uris","seen","accessDescription","uri","candidates","configuredByUri","configuredResponder","input","existing","evidence","checkedSources","entry","normalizedCertificate","error","ocspGoodResult","crlGoodResult","crlCoveredReasons","indeterminateEvidence","result","reason","unrecognizedReason","coversAllDistributionPointReasons","refusal","decodeRefusalOf","DECODE_REFUSAL_CODES","checkCertificateRevocationAgainstCrl","response","validateOcspResponse","matchedResponse","revocationReasonFromCode","parseCertificateDerOrThrow","parseCertificateFromSource","value"],"sources":["../../src/revocation/revocation.ts"],"sourcesContent":["/**\n * Revocation orchestration: evaluates CRL and OCSP evidence to produce a\n * unified `good`/`revoked`/`indeterminate` status for a certificate.\n *\n * @module\n */\n\nimport { DECODE_REFUSAL_CODES, decodeRefusalOf } from '#micro509/internal/asn1/decode-refusal';\nimport type { DecodeRefusalCode, Result } from '#micro509/result/result';\nimport { rethrowIfInvariant } from '#micro509/result/result';\nimport type {\n\tCrlApplicabilityFailureReason,\n\tCrlSource,\n\tParsedRevocationReason,\n\tUnrecognizedReasonCodePolicy,\n} from '#micro509/revocation/crl';\nimport {\n\tassertCrlMaxAge,\n\tcheckCertificateRevocationAgainstCrl,\n\tcoversAllDistributionPointReasons,\n\trevocationReasonFromCode,\n} from '#micro509/revocation/crl';\nimport type {\n\tOcspCertificateSource,\n\tOcspRequestSource,\n\tParsedOcspResponse,\n\tValidateOcspResponseInput,\n} from '#micro509/revocation/ocsp';\nimport { validateOcspResponse } from '#micro509/revocation/ocsp';\nimport type { DistributionPointReason } from '#micro509/x509/extensions';\nimport type { ParsedCertificate } from '#micro509/x509/parse';\nimport { parseCertificateDerOrThrow, parseCertificateFromSource } from '#micro509/x509/parse';\n\nexport type * from '#micro509/revocation/crl';\nexport type * from '#micro509/revocation/ocsp';\n\n/** Unified revocation outcome across CRL and OCSP evidence. */\nexport type RevocationStatus = 'good' | 'revoked' | 'indeterminate';\n\n/** Which revocation mechanism produced the evidence. */\nexport type RevocationEvidenceKind = 'crl' | 'ocsp';\n/** PEM string, DER bytes, or already-parsed certificate. */\nexport type RevocationCertificateSource = string | Uint8Array | ParsedCertificate;\n/** Where the OCSP responder URI came from. */\nexport type OcspResponderSource = 'configured' | 'authorityInfoAccess';\n/** PEM or DER bytes of a pre-configured OCSP responder certificate. */\nexport type ConfiguredOcspResponderCertificate = string | Uint8Array;\n\n/** A manually-configured OCSP responder endpoint. */\nexport interface ConfiguredOcspResponder {\n\t/** OCSP responder URI (typically `http://...`). */\n\treadonly uri: string;\n\t/** Known responder certificate — skips embedded-certificate discovery. */\n\treadonly responderCertificate?: ConfiguredOcspResponderCertificate;\n}\n\n/** One candidate OCSP responder resolved by {@linkcode resolveOcspResponderCandidates}. */\nexport interface OcspResponderCandidate {\n\t/** Whether this candidate came from configuration or the certificate's AIA extension. */\n\treadonly source: OcspResponderSource;\n\t/** OCSP responder URI. */\n\treadonly uri: string;\n\t/** Pre-known responder certificate, if available. */\n\treadonly responderCertificate?: ConfiguredOcspResponderCertificate;\n}\n\n/** Input for {@linkcode resolveOcspResponderCandidates}. */\nexport interface ResolveOcspResponderCandidatesInput {\n\t/** Certificate whose AIA extension will be inspected for OCSP URIs. */\n\treadonly certificate: RevocationCertificateSource;\n\t/** Manually-configured responders — checked before AIA-derived ones. */\n\treadonly configuredResponders?: readonly ConfiguredOcspResponder[];\n}\n\n/** CRL-based revocation evidence for {@linkcode CheckCertificateRevocationInput.evidence}. */\nexport interface RevocationCrlEvidenceInput {\n\t/** Discriminator for the CRL evidence variant. */\n\treadonly kind: 'crl';\n\t/** Complete (base) CRL. */\n\treadonly crl: CrlSource;\n\t/** Optional delta CRL for more recent revocation information. */\n\treadonly deltaCrl?: CrlSource;\n}\n\n/** OCSP-based revocation evidence for {@linkcode CheckCertificateRevocationInput.evidence}. */\nexport interface RevocationOcspEvidenceInput {\n\t/** Discriminator for the OCSP evidence variant. */\n\treadonly kind: 'ocsp';\n\t/** OCSP response to validate. */\n\treadonly response: string | Uint8Array | ParsedOcspResponse;\n\t/** Original OCSP request — enables nonce and coverage checks. */\n\treadonly request?: OcspRequestSource;\n\t/** Explicit responder certificate — overrides embedded certificate discovery. */\n\treadonly responderCertificate?: OcspCertificateSource;\n}\n\n/** Discriminated union of CRL and OCSP evidence inputs. */\nexport type RevocationEvidenceInput = RevocationCrlEvidenceInput | RevocationOcspEvidenceInput;\n\n/** Input for {@linkcode checkCertificateRevocation}. */\nexport interface CheckCertificateRevocationInput {\n\t/** Certificate whose revocation status to determine. */\n\treadonly certificate: RevocationCertificateSource;\n\t/** Issuer of `certificate`. */\n\treadonly issuerCertificate: RevocationCertificateSource;\n\t/** CRL and/or OCSP evidence to evaluate. Returns `indeterminate` if empty. */\n\treadonly evidence?: readonly RevocationEvidenceInput[];\n\t/** Evaluation time. Defaults to `new Date()`. */\n\treadonly at?: Date;\n\t/** Clock-skew tolerance in milliseconds. It also widens `crlMaxAgeMs`. */\n\treadonly clockSkewMs?: number;\n\t/** Maximum age of each CRL's `thisUpdate` in milliseconds. Unbounded by default. See {@linkcode ValidateCertificateRevocationListInput.maxAgeMs}. */\n\treadonly crlMaxAgeMs?: number;\n\t/**\n\t * OCSP client profile for every OCSP evidence entry. See\n\t * {@linkcode ValidateOcspResponseInput.profile}. Defaults to `'rfc6960'`.\n\t */\n\treadonly ocspProfile?: ValidateOcspResponseInput['profile'];\n\t/**\n\t * Treatment of CRL or OCSP evidence whose CRLReason is unrecognized. See\n\t * {@linkcode UnrecognizedReasonCodePolicy}. `'reject'` turns that evidence\n\t * into `reason_code_unrecognized`, which also keeps other evidence from\n\t * settling the status as `good`. Defaults to `'revoked'`.\n\t */\n\treadonly unrecognizedReasonCode?: UnrecognizedReasonCodePolicy;\n}\n\n/** Error codes that {@linkcode checkCertificateRevocation} may surface inside an `indeterminate` result. */\nexport type CheckCertificateRevocationErrorCode =\n\t| 'revocation_evidence_missing'\n\t| 'revocation_status_indeterminate'\n\t| DecodeRefusalCode;\n\n/** Every {@linkcode RevocationIndeterminateReasonCode}, as a runtime array. */\nexport const REVOCATION_INDETERMINATE_REASON_CODES = [\n\t'certificate_status_missing',\n\t'certificate_status_unknown',\n\t'crl_sign_not_permitted',\n\t'issuer_mismatch',\n\t'next_update_missing',\n\t'non_applicable',\n\t'nonce_mismatch',\n\t'ocsp_signing_missing',\n\t'reason_code_unrecognized',\n\t'reason_coverage_incomplete',\n\t'request_mismatch',\n\t'responder_id_mismatch',\n\t'responder_chain_invalid',\n\t'responder_revoked',\n\t'responder_revocation_unknown',\n\t'response_status_invalid',\n\t'signature_invalid',\n\t'stale_crl',\n\t'stale_response',\n\t'unsupported',\n\t'limit_exceeded',\n] as const;\n\n/** Why a particular piece of evidence could not produce a definitive `good`/`revoked` answer. */\nexport type RevocationIndeterminateReasonCode =\n\t(typeof REVOCATION_INDETERMINATE_REASON_CODES)[number];\n\n/** One piece of evidence that failed to produce a definitive revocation answer. */\nexport interface RevocationIndeterminateEvidence {\n\t/** Whether this evidence was CRL or OCSP. */\n\treadonly kind: RevocationEvidenceKind;\n\t/** Machine-readable reason code. */\n\treadonly code: RevocationIndeterminateReasonCode;\n\t/** Human-readable explanation. */\n\treadonly message: string;\n\t/** CRL-specific applicability failure reason, when `kind` is `'crl'`. */\n\treadonly reason?: CrlApplicabilityFailureReason;\n}\n\n/** Diagnostic details attached to an `indeterminate` revocation result. */\nexport interface CheckCertificateRevocationFailureDetails {\n\t/** Which evidence kinds were attempted (`'crl'`, `'ocsp'`, or both). */\n\treadonly checkedSources: readonly RevocationEvidenceKind[];\n\t/** Per-evidence explanations of why no definitive answer was reached. */\n\treadonly indeterminateEvidence: readonly RevocationIndeterminateEvidence[];\n}\n\n/** Revocation status could not be determined from the provided evidence. */\nexport interface RevocationCheckIndeterminateValue {\n\t/** Status is indeterminate. */\n\treadonly status: Extract<RevocationStatus, 'indeterminate'>;\n\t/** Why revocation status is indeterminate. */\n\treadonly code: CheckCertificateRevocationErrorCode;\n\t/** Human-readable diagnostic message. */\n\treadonly message: string;\n\t/** What evidence was attempted and why each failed. */\n\treadonly details: CheckCertificateRevocationFailureDetails;\n}\n\n/** Certificate is not revoked according to the checked evidence. */\nexport interface RevocationCheckGoodValue {\n\t/** Certificate is not revoked. */\n\treadonly status: Extract<RevocationStatus, 'good'>;\n\t/** Which evidence kind confirmed the good status. */\n\treadonly kind: RevocationEvidenceKind;\n\t/** Human-readable diagnostic message. */\n\treadonly message: string;\n}\n\n/** Certificate is revoked according to the checked evidence. */\nexport interface RevocationCheckRevokedValue {\n\t/** Certificate is revoked. */\n\treadonly status: Extract<RevocationStatus, 'revoked'>;\n\t/** Which evidence kind reported the revocation. */\n\treadonly kind: RevocationEvidenceKind;\n\t/** Human-readable diagnostic message. */\n\treadonly message: string;\n\t/** When the certificate was revoked (from CRL entry or OCSP response). */\n\treadonly revokedAt?: Date;\n\t/** CRL reason (from CRL evidence). */\n\treadonly revocationReason?: ParsedRevocationReason;\n\t/** CRL reason code (from OCSP evidence). */\n\treadonly revocationReasonCode?: bigint;\n}\n\n/** Discriminated union of `good`, `revoked`, and `indeterminate` revocation outcomes. */\nexport type CheckCertificateRevocationValue =\n\t| RevocationCheckGoodValue\n\t| RevocationCheckRevokedValue\n\t| RevocationCheckIndeterminateValue;\n\n/**\n * Result of {@linkcode checkCertificateRevocation}. Always succeeds (`ok: true`) —\n * the `value.status` discriminator carries the actual outcome.\n */\nexport type CheckCertificateRevocationResult = Result<CheckCertificateRevocationValue, never>;\n\n/** Internal intermediate result from evaluating a single piece of revocation evidence. */\ntype RevocationEvidenceCheck =\n\t| {\n\t\t\treadonly status: 'good';\n\t\t\treadonly result: RevocationCheckGoodValue;\n\t\t\t/** RFC 5280 §6.3.3(d) reasons this CRL covered; absent for OCSP (which is definitive). */\n\t\t\treadonly coveredReasons?: readonly DistributionPointReason[];\n\t }\n\t| { readonly status: 'revoked'; readonly result: RevocationCheckRevokedValue }\n\t| { readonly status: 'indeterminate'; readonly detail: RevocationIndeterminateEvidence };\n\n/** Extracts OCSP responder URIs from the certificate's Authority Information Access extension. */\nexport function getCertificateOcspResponderUris(\n\tcertificate: RevocationCertificateSource,\n): readonly string[] {\n\tlet parsedCertificate: ParsedCertificate;\n\ttry {\n\t\tparsedCertificate = normalizeCertificate(certificate);\n\t} catch {\n\t\treturn [];\n\t}\n\tconst uris: string[] = [];\n\tconst seen = new Set<string>();\n\tfor (const accessDescription of parsedCertificate.authorityInfoAccess ?? []) {\n\t\tif (accessDescription.method !== 'ocsp' || accessDescription.location.type !== 'uri') {\n\t\t\tcontinue;\n\t\t}\n\t\tconst uri = accessDescription.location.value;\n\t\tif (seen.has(uri)) {\n\t\t\tcontinue;\n\t\t}\n\t\tseen.add(uri);\n\t\turis.push(uri);\n\t}\n\treturn uris;\n}\n\n/**\n * Merges configured OCSP responders with those discovered from the certificate's\n * AIA extension. Configured responders take priority; duplicates are deduplicated by URI.\n */\nexport function resolveOcspResponderCandidates(\n\tinput: ResolveOcspResponderCandidatesInput,\n): readonly OcspResponderCandidate[] {\n\tconst candidates: OcspResponderCandidate[] = [];\n\tconst configuredByUri = new Map<string, ConfiguredOcspResponder>();\n\tfor (const configuredResponder of input.configuredResponders ?? []) {\n\t\tconst existing = configuredByUri.get(configuredResponder.uri);\n\t\tif (\n\t\t\texisting === undefined ||\n\t\t\t(existing.responderCertificate === undefined &&\n\t\t\t\tconfiguredResponder.responderCertificate !== undefined)\n\t\t) {\n\t\t\tconfiguredByUri.set(configuredResponder.uri, configuredResponder);\n\t\t}\n\t}\n\tconst seen = new Set<string>();\n\tfor (const configuredResponder of configuredByUri.values()) {\n\t\tseen.add(configuredResponder.uri);\n\t\tcandidates.push({\n\t\t\tsource: 'configured',\n\t\t\turi: configuredResponder.uri,\n\t\t\t...(configuredResponder.responderCertificate === undefined\n\t\t\t\t? {}\n\t\t\t\t: { responderCertificate: configuredResponder.responderCertificate }),\n\t\t});\n\t}\n\tfor (const uri of getCertificateOcspResponderUris(input.certificate)) {\n\t\tif (seen.has(uri)) {\n\t\t\tcontinue;\n\t\t}\n\t\tseen.add(uri);\n\t\tcandidates.push({\n\t\t\tsource: 'authorityInfoAccess',\n\t\t\turi,\n\t\t});\n\t}\n\treturn candidates;\n}\n\n/**\n * Evaluates all provided CRL and OCSP evidence to determine the certificate's\n * revocation status. Returns the first `revoked` if any, else the first `good`,\n * else `indeterminate` with diagnostic details about each indeterminate evidence.\n *\n * @example\n * ```ts\n * import { checkCertificateRevocation } from 'micro509';\n *\n * const result = await checkCertificateRevocation({\n * certificate: leafPem,\n * issuerCertificate: caPem,\n * evidence: [{ kind: 'crl', crl: crlPem }],\n * });\n * if (result.ok && result.value.status === 'revoked') {\n * console.log('revoked at', result.value.revokedAt);\n * }\n * ```\n */\nexport async function checkCertificateRevocation(\n\tinput: CheckCertificateRevocationInput,\n): Promise<CheckCertificateRevocationResult> {\n\tassertCrlMaxAge(input.crlMaxAgeMs);\n\tconst evidence = input.evidence ?? [];\n\tconst checkedSources = evidence.map((entry) => entry.kind);\n\tif (evidence.length === 0) {\n\t\treturn revocationSuccess({\n\t\t\tstatus: 'indeterminate',\n\t\t\tcode: 'revocation_evidence_missing',\n\t\t\tmessage: 'No CRL or OCSP evidence provided',\n\t\t\tdetails: {\n\t\t\t\tcheckedSources,\n\t\t\t\tindeterminateEvidence: [],\n\t\t\t},\n\t\t});\n\t}\n\tlet normalizedCertificate: ParsedCertificate;\n\ttry {\n\t\tnormalizedCertificate = normalizeCertificate(input.certificate);\n\t} catch (error) {\n\t\treturn undecodableCertificateResult(error, checkedSources);\n\t}\n\tlet ocspGoodResult: RevocationCheckGoodValue | undefined;\n\tlet crlGoodResult: RevocationCheckGoodValue | undefined;\n\tconst crlCoveredReasons = new Set<string>();\n\tconst indeterminateEvidence: RevocationIndeterminateEvidence[] = [];\n\tfor (const entry of evidence) {\n\t\tconst result = await checkRevocationEvidenceEntry(input, entry, normalizedCertificate);\n\t\tif (result.status === 'revoked') {\n\t\t\treturn revocationSuccess(result.result);\n\t\t}\n\t\tif (result.status === 'good') {\n\t\t\tif (result.coveredReasons === undefined) {\n\t\t\t\tocspGoodResult ??= result.result;\n\t\t\t} else {\n\t\t\t\tcrlGoodResult ??= result.result;\n\t\t\t\tfor (const reason of result.coveredReasons) {\n\t\t\t\t\tcrlCoveredReasons.add(reason);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tindeterminateEvidence.push(result.detail);\n\t}\n\treturn settleRevocationEvidence(\n\t\tocspGoodResult,\n\t\tcrlGoodResult,\n\t\tcrlCoveredReasons,\n\t\tindeterminateEvidence,\n\t\tcheckedSources,\n\t);\n}\n\n/** The result once no evidence revoked the certificate outright. */\nfunction settleRevocationEvidence(\n\tocspGoodResult: RevocationCheckGoodValue | undefined,\n\tcrlGoodResult: RevocationCheckGoodValue | undefined,\n\tcrlCoveredReasons: Set<string>,\n\tindeterminateEvidence: RevocationIndeterminateEvidence[],\n\tcheckedSources: readonly RevocationEvidenceKind[],\n): CheckCertificateRevocationResult {\n\tconst unrecognizedReason = indeterminateEvidence.some(\n\t\t(entry) => entry.code === 'reason_code_unrecognized',\n\t);\n\t// An OCSP good is per-certificate and definitive. A CRL good is definitive\n\t// only once the applicable CRLs together cover every revocation reason.\n\tif (ocspGoodResult !== undefined && !unrecognizedReason) {\n\t\treturn revocationSuccess(ocspGoodResult);\n\t}\n\tif (\n\t\tcrlGoodResult !== undefined &&\n\t\t!unrecognizedReason &&\n\t\tcoversAllDistributionPointReasons(crlCoveredReasons)\n\t) {\n\t\treturn revocationSuccess(crlGoodResult);\n\t}\n\tif (crlGoodResult !== undefined && !coversAllDistributionPointReasons(crlCoveredReasons)) {\n\t\tindeterminateEvidence.push({\n\t\t\tkind: 'crl',\n\t\t\tcode: 'reason_coverage_incomplete',\n\t\t\tmessage: 'CRL evidence covers only some revocation reasons',\n\t\t});\n\t}\n\treturn revocationSuccess({\n\t\tstatus: 'indeterminate',\n\t\tcode: 'revocation_status_indeterminate',\n\t\tmessage: 'No revocation evidence established certificate status',\n\t\tdetails: {\n\t\t\tcheckedSources,\n\t\t\tindeterminateEvidence,\n\t\t},\n\t});\n}\n\nfunction undecodableCertificateResult(\n\terror: unknown,\n\tcheckedSources: readonly RevocationEvidenceKind[],\n): CheckCertificateRevocationResult {\n\tconst refusal = decodeRefusalOf(error, DECODE_REFUSAL_CODES);\n\treturn revocationSuccess({\n\t\tstatus: 'indeterminate',\n\t\tcode: refusal?.code ?? 'revocation_status_indeterminate',\n\t\tmessage: refusal?.message ?? 'Certificate input is malformed',\n\t\tdetails: {\n\t\t\tcheckedSources,\n\t\t\tindeterminateEvidence: [],\n\t\t},\n\t});\n}\n\nasync function checkRevocationEvidenceEntry(\n\tinput: CheckCertificateRevocationInput,\n\tevidence: RevocationEvidenceInput,\n\tcertificate: ParsedCertificate,\n): Promise<RevocationEvidenceCheck> {\n\ttry {\n\t\treturn evidence.kind === 'crl'\n\t\t\t? await checkCertificateRevocationWithCrl(input, evidence, certificate)\n\t\t\t: await checkCertificateRevocationWithOcsp(input, evidence, certificate);\n\t} catch (error) {\n\t\trethrowIfInvariant(error);\n\t\tconst refusal = decodeRefusalOf(error, DECODE_REFUSAL_CODES);\n\t\treturn {\n\t\t\tstatus: 'indeterminate',\n\t\t\tdetail: {\n\t\t\t\tkind: evidence.kind,\n\t\t\t\tcode: refusal?.code ?? 'signature_invalid',\n\t\t\t\tmessage: refusal?.message ?? `${evidence.kind.toUpperCase()} evidence input is malformed`,\n\t\t\t},\n\t\t};\n\t}\n}\n\n/** Evaluates a single CRL evidence entry via {@linkcode checkCertificateRevocationAgainstCrl}. */\nasync function checkCertificateRevocationWithCrl(\n\tinput: CheckCertificateRevocationInput,\n\tevidence: RevocationCrlEvidenceInput,\n\tcertificate: ParsedCertificate,\n): Promise<RevocationEvidenceCheck> {\n\tconst result = await checkCertificateRevocationAgainstCrl({\n\t\tcertificate,\n\t\tissuerCertificate: input.issuerCertificate,\n\t\tcrl: evidence.crl,\n\t\t...(evidence.deltaCrl === undefined ? {} : { deltaCrl: evidence.deltaCrl }),\n\t\t...(input.at === undefined ? {} : { at: input.at }),\n\t\t...(input.clockSkewMs === undefined ? {} : { clockSkewMs: input.clockSkewMs }),\n\t\t...(input.crlMaxAgeMs === undefined ? {} : { maxAgeMs: input.crlMaxAgeMs }),\n\t\t...(input.unrecognizedReasonCode === undefined\n\t\t\t? {}\n\t\t\t: { unrecognizedReasonCode: input.unrecognizedReasonCode }),\n\t});\n\tif (result.ok) {\n\t\tif (result.value.status === 'revoked') {\n\t\t\treturn {\n\t\t\t\tstatus: 'revoked',\n\t\t\t\tresult: {\n\t\t\t\t\tstatus: 'revoked',\n\t\t\t\t\tkind: 'crl',\n\t\t\t\t\tmessage: 'Certificate is revoked according to CRL evidence',\n\t\t\t\t\trevokedAt: result.value.revocationDate,\n\t\t\t\t\t...(result.value.reasonCode === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { revocationReason: result.value.reasonCode }),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tstatus: 'good',\n\t\t\tresult: {\n\t\t\t\tstatus: 'good',\n\t\t\t\tkind: 'crl',\n\t\t\t\tmessage: 'Certificate is not revoked according to CRL evidence',\n\t\t\t},\n\t\t\tcoveredReasons: result.value.coveredReasons,\n\t\t};\n\t}\n\treturn {\n\t\tstatus: 'indeterminate',\n\t\tdetail: {\n\t\t\tkind: 'crl',\n\t\t\tcode: result.code,\n\t\t\tmessage: result.message,\n\t\t\t...(result.details?.reason === undefined ? {} : { reason: result.details.reason }),\n\t\t},\n\t};\n}\n\n/** Evaluates a single OCSP evidence entry via {@linkcode validateOcspResponse}. */\nasync function checkCertificateRevocationWithOcsp(\n\tinput: CheckCertificateRevocationInput,\n\tevidence: RevocationOcspEvidenceInput,\n\tcertificate: ParsedCertificate,\n): Promise<RevocationEvidenceCheck> {\n\tconst response = await validateOcspResponse({\n\t\tresponse: evidence.response,\n\t\tissuerCertificate: input.issuerCertificate,\n\t\t...(evidence.request === undefined ? {} : { request: evidence.request }),\n\t\t...(evidence.responderCertificate === undefined\n\t\t\t? {}\n\t\t\t: { responderCertificate: evidence.responderCertificate }),\n\t\t...(input.at === undefined ? {} : { at: input.at }),\n\t\t...(input.clockSkewMs === undefined ? {} : { clockSkewMs: input.clockSkewMs }),\n\t\t...(input.ocspProfile === undefined ? {} : { profile: input.ocspProfile }),\n\t});\n\tif (!response.ok) {\n\t\treturn {\n\t\t\tstatus: 'indeterminate',\n\t\t\tdetail: {\n\t\t\t\tkind: 'ocsp',\n\t\t\t\tcode: response.code,\n\t\t\t\tmessage: response.message,\n\t\t\t},\n\t\t};\n\t}\n\tconst matchedResponse = response.value.responses?.find(\n\t\t(entry) =>\n\t\t\tnormalizeHex(entry.certId.serialNumberHex) === normalizeHex(certificate.serialNumberHex),\n\t);\n\tif (matchedResponse === undefined) {\n\t\treturn {\n\t\t\tstatus: 'indeterminate',\n\t\t\tdetail: {\n\t\t\t\tkind: 'ocsp',\n\t\t\t\tcode: 'certificate_status_missing',\n\t\t\t\tmessage: 'OCSP response does not include certificate status for the target certificate',\n\t\t\t},\n\t\t};\n\t}\n\tif (matchedResponse.certStatus === 'revoked') {\n\t\tif (\n\t\t\tinput.unrecognizedReasonCode === 'reject' &&\n\t\t\ttypeof revocationReasonFromCode(matchedResponse.revocationReasonCode) === 'object'\n\t\t) {\n\t\t\treturn {\n\t\t\t\tstatus: 'indeterminate',\n\t\t\t\tdetail: {\n\t\t\t\t\tkind: 'ocsp',\n\t\t\t\t\tcode: 'reason_code_unrecognized',\n\t\t\t\t\tmessage: `OCSP response carries unrecognized reason code ${String(matchedResponse.revocationReasonCode)}`,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tstatus: 'revoked',\n\t\t\tresult: {\n\t\t\t\tstatus: 'revoked',\n\t\t\t\tkind: 'ocsp',\n\t\t\t\tmessage: 'Certificate is revoked according to OCSP evidence',\n\t\t\t\t...(matchedResponse.revokedAt === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { revokedAt: matchedResponse.revokedAt }),\n\t\t\t\t...(matchedResponse.revocationReasonCode === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { revocationReasonCode: matchedResponse.revocationReasonCode }),\n\t\t\t},\n\t\t};\n\t}\n\tif (matchedResponse.certStatus === 'good') {\n\t\treturn {\n\t\t\tstatus: 'good',\n\t\t\tresult: {\n\t\t\t\tstatus: 'good',\n\t\t\t\tkind: 'ocsp',\n\t\t\t\tmessage: 'Certificate is not revoked according to OCSP evidence',\n\t\t\t},\n\t\t};\n\t}\n\treturn {\n\t\tstatus: 'indeterminate',\n\t\tdetail: {\n\t\t\tkind: 'ocsp',\n\t\t\tcode: 'certificate_status_unknown',\n\t\t\tmessage: 'OCSP responder returned certificate status unknown',\n\t\t},\n\t};\n}\n\n/** Accepts PEM, DER, or already-parsed certificate and returns a parsed certificate. */\nfunction normalizeCertificate(certificate: RevocationCertificateSource): ParsedCertificate {\n\treturn hasParsedCertificateShape(certificate)\n\t\t? parseCertificateDerOrThrow(new Uint8Array(certificate.der))\n\t\t: parseCertificateFromSource(certificate);\n}\n\nfunction hasParsedCertificateShape(value: RevocationCertificateSource): value is ParsedCertificate {\n\treturn typeof value !== 'string' && 'subjectPublicKeyInfoDer' in value;\n}\n\n/** Lowercases a hex string for bytewise serial-number comparison. */\nfunction normalizeHex(value: string): string {\n\treturn value.toLowerCase();\n}\n\n/** Wraps a value into a successful `CheckCertificateRevocationResult`. */\nfunction revocationSuccess(\n\tvalue: CheckCertificateRevocationValue,\n): CheckCertificateRevocationResult {\n\treturn { ok: true, value };\n}\n"],"mappings":";;;;;;;;;;;;;AAsIA,MAAaA,IAAwC;CACpD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;AAwFA,SAAgB,gCACf,GACoB;CACpB,IAAIC;CACJ,IAAI;EACH,IAAoB,qBAAqBC,CAAW;CACrD,QAAQ;EACP,OAAO,CAAC;CACT;CACA,IAAMC,IAAiB,CAAC,GAClBC,oBAAO,IAAI,IAAY;CAC7B,KAAK,IAAMC,KAAqBJ,EAAkB,uBAAuB,CAAC,GAAG;EAC5E,IAAII,EAAkB,WAAW,UAAUA,EAAkB,SAAS,SAAS,OAC9E;EAED,IAAMC,IAAMD,EAAkB,SAAS;EACvC,AAAID,EAAK,IAAIE,CAAG,MAGhBF,EAAK,IAAIE,CAAG,GACZH,EAAK,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