micro509 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/README.md +2 -0
  2. package/dist/index.d.ts +5 -5
  3. package/dist/index.js +15 -1
  4. package/dist/internal/asn1/asn1.js +280 -2
  5. package/dist/internal/asn1/der.js +378 -2
  6. package/dist/internal/asn1/oids.js +103 -2
  7. package/dist/internal/crypto/algorithm-names.js +58 -2
  8. package/dist/internal/crypto/ecdsa.js +68 -2
  9. package/dist/internal/crypto/hash.js +286 -2
  10. package/dist/internal/crypto/pbes2.js +213 -2
  11. package/dist/internal/crypto/rsa-pss.js +184 -2
  12. package/dist/internal/crypto/sig-verify.js +192 -2
  13. package/dist/internal/crypto/signing.d.ts +1 -2
  14. package/dist/internal/crypto/signing.js +123 -2
  15. package/dist/internal/crypto/webcrypto.js +14 -2
  16. package/dist/internal/shared/base64.js +16 -2
  17. package/dist/internal/shared/dn.js +84 -2
  18. package/dist/internal/shared/ip.js +164 -2
  19. package/dist/internal/verify/name-constraints-engine.js +450 -2
  20. package/dist/internal/verify/policy-engine.js +382 -2
  21. package/dist/internal/verify/verify-path.js +298 -2
  22. package/dist/internal/x509/extension-bits.js +132 -2
  23. package/dist/internal/x509/extension-registry.js +229 -2
  24. package/dist/internal/x509/name-fields.js +93 -2
  25. package/dist/keys/keys.d.ts +231 -7
  26. package/dist/keys/keys.js +1087 -5
  27. package/dist/keys.d.ts +2 -2
  28. package/dist/keys.js +2 -1
  29. package/dist/pem/pem.d.ts +2 -2
  30. package/dist/pem/pem.js +172 -6
  31. package/dist/pem.js +2 -1
  32. package/dist/pkcs/pfx.d.ts +4 -5
  33. package/dist/pkcs/pfx.js +395 -2
  34. package/dist/pkcs/pkcs12-mac.d.ts +2 -2
  35. package/dist/pkcs/pkcs12-mac.js +175 -2
  36. package/dist/pkcs/pkcs7.d.ts +1 -2
  37. package/dist/pkcs/pkcs7.js +653 -2
  38. package/dist/pkcs.d.ts +2 -2
  39. package/dist/pkcs.js +4 -1
  40. package/dist/result/result.d.ts +1 -2
  41. package/dist/result/result.js +111 -2
  42. package/dist/result.js +2 -1
  43. package/dist/revocation/chain.d.ts +4 -5
  44. package/dist/revocation/chain.js +536 -2
  45. package/dist/revocation/crl.d.ts +2 -2
  46. package/dist/revocation/crl.js +1119 -2
  47. package/dist/revocation/ocsp.d.ts +3 -2
  48. package/dist/revocation/ocsp.js +958 -2
  49. package/dist/revocation/revocation.d.ts +1 -2
  50. package/dist/revocation/revocation.js +261 -2
  51. package/dist/revocation.d.ts +2 -2
  52. package/dist/revocation.js +5 -1
  53. package/dist/verify/identity.d.ts +1 -2
  54. package/dist/verify/identity.js +270 -2
  55. package/dist/verify/name-constraints.d.ts +1 -2
  56. package/dist/verify/policy.d.ts +1 -2
  57. package/dist/verify/verify.d.ts +1 -2
  58. package/dist/verify/verify.js +764 -2
  59. package/dist/verify.js +3 -1
  60. package/dist/x509/certificate.d.ts +1 -2
  61. package/dist/x509/certificate.js +151 -2
  62. package/dist/x509/csr.d.ts +1 -2
  63. package/dist/x509/csr.js +71 -2
  64. package/dist/x509/extensions.d.ts +1 -2
  65. package/dist/x509/extensions.js +387 -2
  66. package/dist/x509/name.d.ts +1 -2
  67. package/dist/x509/name.js +173 -2
  68. package/dist/x509/parse.d.ts +84 -2
  69. package/dist/x509/parse.js +1090 -2
  70. package/dist/x509.d.ts +2 -2
  71. package/dist/x509.js +6 -1
  72. package/package.json +74 -34
  73. package/dist/internal/asn1/asn1.js.map +0 -1
  74. package/dist/internal/asn1/der.js.map +0 -1
  75. package/dist/internal/asn1/oids.js.map +0 -1
  76. package/dist/internal/crypto/algorithm-names.js.map +0 -1
  77. package/dist/internal/crypto/ecdsa.js.map +0 -1
  78. package/dist/internal/crypto/hash.js.map +0 -1
  79. package/dist/internal/crypto/pbes2.d.ts +0 -23
  80. package/dist/internal/crypto/pbes2.js.map +0 -1
  81. package/dist/internal/crypto/rsa-pss.js.map +0 -1
  82. package/dist/internal/crypto/sig-verify.js.map +0 -1
  83. package/dist/internal/crypto/signing.js.map +0 -1
  84. package/dist/internal/crypto/webcrypto.js.map +0 -1
  85. package/dist/internal/shared/base64.js.map +0 -1
  86. package/dist/internal/shared/dn.js.map +0 -1
  87. package/dist/internal/shared/ip.js.map +0 -1
  88. package/dist/internal/verify/name-constraints-engine.js.map +0 -1
  89. package/dist/internal/verify/policy-engine.js.map +0 -1
  90. package/dist/internal/verify/verify-path.js.map +0 -1
  91. package/dist/internal/x509/extension-bits.js.map +0 -1
  92. package/dist/internal/x509/extension-registry.js.map +0 -1
  93. package/dist/internal/x509/name-fields.js.map +0 -1
  94. package/dist/keys/keys.js.map +0 -1
  95. package/dist/pem/pem.js.map +0 -1
  96. package/dist/pkcs/pfx.js.map +0 -1
  97. package/dist/pkcs/pkcs12-mac.js.map +0 -1
  98. package/dist/pkcs/pkcs7.js.map +0 -1
  99. package/dist/result/result.js.map +0 -1
  100. package/dist/revocation/chain.js.map +0 -1
  101. package/dist/revocation/crl.js.map +0 -1
  102. package/dist/revocation/ocsp.js.map +0 -1
  103. package/dist/revocation/revocation.js.map +0 -1
  104. package/dist/verify/identity.js.map +0 -1
  105. package/dist/verify/verify.js.map +0 -1
  106. package/dist/x509/certificate.js.map +0 -1
  107. package/dist/x509/csr.js.map +0 -1
  108. package/dist/x509/extensions.js.map +0 -1
  109. package/dist/x509/name.js.map +0 -1
  110. package/dist/x509/parse.js.map +0 -1
@@ -166,5 +166,4 @@ declare function resolveOcspResponderCandidates(input: ResolveOcspResponderCandi
166
166
  */
167
167
  declare function checkCertificateRevocation(input: CheckCertificateRevocationInput): Promise<CheckCertificateRevocationResult>;
168
168
  //#endregion
169
- 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 };
170
- //# sourceMappingURL=revocation.d.ts.map
169
+ 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 };
@@ -1,2 +1,261 @@
1
- import{parseCertificateDerOrThrow as e,parseCertificateFromSource as t}from"../x509/parse.js";import{checkCertificateRevocationAgainstCrl as n}from"./crl.js";import{validateOcspResponse as r}from"./ocsp.js";const i=[`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`];function a(e){let t;try{t=u(e)}catch{return[]}let n=[],r=new Set;for(let e of t.authorityInfoAccess??[])e.method!==`ocsp`||r.has(e.uri)||(r.add(e.uri),n.push(e.uri));return n}function o(e){let t=[],n=new Map;for(let t of e.configuredResponders??[]){let e=n.get(t.uri);(e===void 0||e.responderCertificate===void 0&&t.responderCertificate!==void 0)&&n.set(t.uri,t)}let r=new Set;for(let e of n.values())r.add(e.uri),t.push({source:`configured`,uri:e.uri,...e.responderCertificate===void 0?{}:{responderCertificate:e.responderCertificate}});for(let n of a(e.certificate))r.has(n)||(r.add(n),t.push({source:`authorityInfoAccess`,uri:n}));return t}async function s(e){let t=e.evidence??[],n=t.map(e=>e.kind);if(t.length===0)return p({status:`indeterminate`,code:`revocation_evidence_missing`,message:`No CRL or OCSP evidence provided`,details:{checkedSources:n,indeterminateEvidence:[]}});let r;try{r=u(e.certificate)}catch{return p({status:`indeterminate`,code:`revocation_status_indeterminate`,message:`Certificate input is malformed`,details:{checkedSources:n,indeterminateEvidence:[]}})}let i,a=[];for(let n of t){let t;try{t=n.kind===`crl`?await c(e,n,r):await l(e,n,r)}catch{a.push({kind:n.kind,code:`signature_invalid`,message:`${n.kind.toUpperCase()} evidence input is malformed`});continue}if(t.status===`revoked`)return p(t.result);if(t.status===`good`){i??=t.result;continue}a.push(t.detail)}return p(i===void 0?{status:`indeterminate`,code:`revocation_status_indeterminate`,message:`No revocation evidence established certificate status`,details:{checkedSources:n,indeterminateEvidence:a}}:i)}async function c(e,t,r){let i=await n({certificate:r,issuerCertificate:e.issuerCertificate,crl:t.crl,...t.deltaCrl===void 0?{}:{deltaCrl:t.deltaCrl},...e.at===void 0?{}:{at:e.at},...e.clockSkewMs===void 0?{}:{clockSkewMs:e.clockSkewMs}});return i.ok?i.value.status===`revoked`?{status:`revoked`,result:{status:`revoked`,kind:`crl`,message:`Certificate is revoked according to CRL evidence`,revokedAt:i.value.revocationDate,...i.value.reasonCode===void 0?{}:{revocationReason:i.value.reasonCode}}}:{status:`good`,result:{status:`good`,kind:`crl`,message:`Certificate is not revoked according to CRL evidence`}}:{status:`indeterminate`,detail:{kind:`crl`,code:i.code,message:i.message,...i.details?.reason===void 0?{}:{reason:i.details.reason}}}}async function l(e,t,n){let i=await r({response:t.response,issuerCertificate:e.issuerCertificate,...t.request===void 0?{}:{request:t.request},...t.responderCertificate===void 0?{}:{responderCertificate:t.responderCertificate},...e.at===void 0?{}:{at:e.at},...e.clockSkewMs===void 0?{}:{clockSkewMs:e.clockSkewMs}});if(!i.ok)return{status:`indeterminate`,detail:{kind:`ocsp`,code:i.code,message:i.message}};let a=i.value.responses?.find(e=>f(e.certId.serialNumberHex)===f(n.serialNumberHex));return a===void 0?{status:`indeterminate`,detail:{kind:`ocsp`,code:`certificate_status_missing`,message:`OCSP response does not include certificate status for the target certificate`}}:a.certStatus===`revoked`?{status:`revoked`,result:{status:`revoked`,kind:`ocsp`,message:`Certificate is revoked according to OCSP evidence`,...a.revokedAt===void 0?{}:{revokedAt:a.revokedAt},...a.revocationReasonCode===void 0?{}:{revocationReasonCode:a.revocationReasonCode}}}:a.certStatus===`good`?{status:`good`,result:{status:`good`,kind:`ocsp`,message:`Certificate is not revoked according to OCSP evidence`}}:{status:`indeterminate`,detail:{kind:`ocsp`,code:`certificate_status_unknown`,message:`OCSP responder returned certificate status unknown`}}}function u(n){return d(n)?e(new Uint8Array(n.der)):t(n)}function d(e){return typeof e!=`string`&&`subjectPublicKeyInfoDer`in e}function f(e){return e.toLowerCase()}function p(e){return{ok:!0,value:e}}export{i as REVOCATION_INDETERMINATE_REASON_CODES,s as checkCertificateRevocation,a as getCertificateOcspResponderUris,o as resolveOcspResponderCandidates};
2
- //# sourceMappingURL=revocation.js.map
1
+ import { parseCertificateDerOrThrow, parseCertificateFromSource } from "../x509/parse.js";
2
+ import { checkCertificateRevocationAgainstCrl } from "./crl.js";
3
+ import { validateOcspResponse } from "./ocsp.js";
4
+ //#region src/revocation/revocation.ts
5
+ /** Every {@linkcode RevocationIndeterminateReasonCode}, as a runtime array. */
6
+ const REVOCATION_INDETERMINATE_REASON_CODES = [
7
+ "certificate_status_missing",
8
+ "certificate_status_unknown",
9
+ "crl_sign_not_permitted",
10
+ "issuer_mismatch",
11
+ "non_applicable",
12
+ "nonce_mismatch",
13
+ "ocsp_signing_missing",
14
+ "request_mismatch",
15
+ "responder_id_mismatch",
16
+ "responder_chain_invalid",
17
+ "responder_revoked",
18
+ "responder_revocation_unknown",
19
+ "response_status_invalid",
20
+ "signature_invalid",
21
+ "stale_crl",
22
+ "stale_response"
23
+ ];
24
+ /** Extracts OCSP responder URIs from the certificate's Authority Information Access extension. */
25
+ function getCertificateOcspResponderUris(certificate) {
26
+ let parsedCertificate;
27
+ try {
28
+ parsedCertificate = normalizeCertificate(certificate);
29
+ } catch {
30
+ return [];
31
+ }
32
+ const uris = [];
33
+ const seen = /* @__PURE__ */ new Set();
34
+ for (const accessDescription of parsedCertificate.authorityInfoAccess ?? []) {
35
+ if (accessDescription.method !== "ocsp" || seen.has(accessDescription.uri)) continue;
36
+ seen.add(accessDescription.uri);
37
+ uris.push(accessDescription.uri);
38
+ }
39
+ return uris;
40
+ }
41
+ /**
42
+ * Merges configured OCSP responders with those discovered from the certificate's
43
+ * AIA extension. Configured responders take priority; duplicates are deduplicated by URI.
44
+ */
45
+ function resolveOcspResponderCandidates(input) {
46
+ const candidates = [];
47
+ const configuredByUri = /* @__PURE__ */ new Map();
48
+ for (const configuredResponder of input.configuredResponders ?? []) {
49
+ const existing = configuredByUri.get(configuredResponder.uri);
50
+ if (existing === void 0 || existing.responderCertificate === void 0 && configuredResponder.responderCertificate !== void 0) configuredByUri.set(configuredResponder.uri, configuredResponder);
51
+ }
52
+ const seen = /* @__PURE__ */ new Set();
53
+ for (const configuredResponder of configuredByUri.values()) {
54
+ seen.add(configuredResponder.uri);
55
+ candidates.push({
56
+ source: "configured",
57
+ uri: configuredResponder.uri,
58
+ ...configuredResponder.responderCertificate === void 0 ? {} : { responderCertificate: configuredResponder.responderCertificate }
59
+ });
60
+ }
61
+ for (const uri of getCertificateOcspResponderUris(input.certificate)) {
62
+ if (seen.has(uri)) continue;
63
+ seen.add(uri);
64
+ candidates.push({
65
+ source: "authorityInfoAccess",
66
+ uri
67
+ });
68
+ }
69
+ return candidates;
70
+ }
71
+ /**
72
+ * Evaluates all provided CRL and OCSP evidence to determine the certificate's
73
+ * revocation status. Returns the first `revoked` if any, else the first `good`,
74
+ * else `indeterminate` with diagnostic details about each indeterminate evidence.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * import { checkCertificateRevocation } from 'micro509';
79
+ *
80
+ * const result = await checkCertificateRevocation({
81
+ * certificate: leafPem,
82
+ * issuerCertificate: caPem,
83
+ * evidence: [{ kind: 'crl', crl: crlPem }],
84
+ * });
85
+ * if (result.ok && result.value.status === 'revoked') {
86
+ * console.log('revoked at', result.value.revokedAt);
87
+ * }
88
+ * ```
89
+ */
90
+ async function checkCertificateRevocation(input) {
91
+ const evidence = input.evidence ?? [];
92
+ const checkedSources = evidence.map((entry) => entry.kind);
93
+ if (evidence.length === 0) return revocationSuccess({
94
+ status: "indeterminate",
95
+ code: "revocation_evidence_missing",
96
+ message: "No CRL or OCSP evidence provided",
97
+ details: {
98
+ checkedSources,
99
+ indeterminateEvidence: []
100
+ }
101
+ });
102
+ let normalizedCertificate;
103
+ try {
104
+ normalizedCertificate = normalizeCertificate(input.certificate);
105
+ } catch {
106
+ return revocationSuccess({
107
+ status: "indeterminate",
108
+ code: "revocation_status_indeterminate",
109
+ message: "Certificate input is malformed",
110
+ details: {
111
+ checkedSources,
112
+ indeterminateEvidence: []
113
+ }
114
+ });
115
+ }
116
+ let goodResult;
117
+ const indeterminateEvidence = [];
118
+ for (const entry of evidence) {
119
+ let result;
120
+ try {
121
+ result = entry.kind === "crl" ? await checkCertificateRevocationWithCrl(input, entry, normalizedCertificate) : await checkCertificateRevocationWithOcsp(input, entry, normalizedCertificate);
122
+ } catch {
123
+ indeterminateEvidence.push({
124
+ kind: entry.kind,
125
+ code: "signature_invalid",
126
+ message: `${entry.kind.toUpperCase()} evidence input is malformed`
127
+ });
128
+ continue;
129
+ }
130
+ if (result.status === "revoked") return revocationSuccess(result.result);
131
+ if (result.status === "good") {
132
+ goodResult ??= result.result;
133
+ continue;
134
+ }
135
+ indeterminateEvidence.push(result.detail);
136
+ }
137
+ if (goodResult !== void 0) return revocationSuccess(goodResult);
138
+ return revocationSuccess({
139
+ status: "indeterminate",
140
+ code: "revocation_status_indeterminate",
141
+ message: "No revocation evidence established certificate status",
142
+ details: {
143
+ checkedSources,
144
+ indeterminateEvidence
145
+ }
146
+ });
147
+ }
148
+ /** Evaluates a single CRL evidence entry via {@linkcode checkCertificateRevocationAgainstCrl}. */
149
+ async function checkCertificateRevocationWithCrl(input, evidence, certificate) {
150
+ const result = await checkCertificateRevocationAgainstCrl({
151
+ certificate,
152
+ issuerCertificate: input.issuerCertificate,
153
+ crl: evidence.crl,
154
+ ...evidence.deltaCrl === void 0 ? {} : { deltaCrl: evidence.deltaCrl },
155
+ ...input.at === void 0 ? {} : { at: input.at },
156
+ ...input.clockSkewMs === void 0 ? {} : { clockSkewMs: input.clockSkewMs }
157
+ });
158
+ if (result.ok) {
159
+ if (result.value.status === "revoked") return {
160
+ status: "revoked",
161
+ result: {
162
+ status: "revoked",
163
+ kind: "crl",
164
+ message: "Certificate is revoked according to CRL evidence",
165
+ revokedAt: result.value.revocationDate,
166
+ ...result.value.reasonCode === void 0 ? {} : { revocationReason: result.value.reasonCode }
167
+ }
168
+ };
169
+ return {
170
+ status: "good",
171
+ result: {
172
+ status: "good",
173
+ kind: "crl",
174
+ message: "Certificate is not revoked according to CRL evidence"
175
+ }
176
+ };
177
+ }
178
+ return {
179
+ status: "indeterminate",
180
+ detail: {
181
+ kind: "crl",
182
+ code: result.code,
183
+ message: result.message,
184
+ ...result.details?.reason === void 0 ? {} : { reason: result.details.reason }
185
+ }
186
+ };
187
+ }
188
+ /** Evaluates a single OCSP evidence entry via {@linkcode validateOcspResponse}. */
189
+ async function checkCertificateRevocationWithOcsp(input, evidence, certificate) {
190
+ const response = await validateOcspResponse({
191
+ response: evidence.response,
192
+ issuerCertificate: input.issuerCertificate,
193
+ ...evidence.request === void 0 ? {} : { request: evidence.request },
194
+ ...evidence.responderCertificate === void 0 ? {} : { responderCertificate: evidence.responderCertificate },
195
+ ...input.at === void 0 ? {} : { at: input.at },
196
+ ...input.clockSkewMs === void 0 ? {} : { clockSkewMs: input.clockSkewMs }
197
+ });
198
+ if (!response.ok) return {
199
+ status: "indeterminate",
200
+ detail: {
201
+ kind: "ocsp",
202
+ code: response.code,
203
+ message: response.message
204
+ }
205
+ };
206
+ const matchedResponse = response.value.responses?.find((entry) => normalizeHex(entry.certId.serialNumberHex) === normalizeHex(certificate.serialNumberHex));
207
+ if (matchedResponse === void 0) return {
208
+ status: "indeterminate",
209
+ detail: {
210
+ kind: "ocsp",
211
+ code: "certificate_status_missing",
212
+ message: "OCSP response does not include certificate status for the target certificate"
213
+ }
214
+ };
215
+ if (matchedResponse.certStatus === "revoked") return {
216
+ status: "revoked",
217
+ result: {
218
+ status: "revoked",
219
+ kind: "ocsp",
220
+ message: "Certificate is revoked according to OCSP evidence",
221
+ ...matchedResponse.revokedAt === void 0 ? {} : { revokedAt: matchedResponse.revokedAt },
222
+ ...matchedResponse.revocationReasonCode === void 0 ? {} : { revocationReasonCode: matchedResponse.revocationReasonCode }
223
+ }
224
+ };
225
+ if (matchedResponse.certStatus === "good") return {
226
+ status: "good",
227
+ result: {
228
+ status: "good",
229
+ kind: "ocsp",
230
+ message: "Certificate is not revoked according to OCSP evidence"
231
+ }
232
+ };
233
+ return {
234
+ status: "indeterminate",
235
+ detail: {
236
+ kind: "ocsp",
237
+ code: "certificate_status_unknown",
238
+ message: "OCSP responder returned certificate status unknown"
239
+ }
240
+ };
241
+ }
242
+ /** Accepts PEM, DER, or already-parsed certificate and returns a parsed certificate. */
243
+ function normalizeCertificate(certificate) {
244
+ return hasParsedCertificateShape(certificate) ? parseCertificateDerOrThrow(new Uint8Array(certificate.der)) : parseCertificateFromSource(certificate);
245
+ }
246
+ function hasParsedCertificateShape(value) {
247
+ return typeof value !== "string" && "subjectPublicKeyInfoDer" in value;
248
+ }
249
+ /** Lowercases a hex string for bytewise serial-number comparison. */
250
+ function normalizeHex(value) {
251
+ return value.toLowerCase();
252
+ }
253
+ /** Wraps a value into a successful `CheckCertificateRevocationResult`. */
254
+ function revocationSuccess(value) {
255
+ return {
256
+ ok: true,
257
+ value
258
+ };
259
+ }
260
+ //#endregion
261
+ export { REVOCATION_INDETERMINATE_REASON_CODES, checkCertificateRevocation, getCertificateOcspResponderUris, resolveOcspResponderCandidates };
@@ -1,7 +1,7 @@
1
- import { IssuingDistributionPoint, IssuingDistributionPointForAttributeCerts, IssuingDistributionPointForCaCerts, IssuingDistributionPointForUserCerts } from "./x509/extensions.js";
1
+ import { IssuingDistributionPoint, IssuingDistributionPointBase, IssuingDistributionPointForAttributeCerts, IssuingDistributionPointForCaCerts, IssuingDistributionPointForUserCerts } from "./x509/extensions.js";
2
2
  import { ParsedIssuingDistributionPoint } from "./x509/parse.js";
3
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 "./revocation/crl.js";
4
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 "./revocation/ocsp.js";
5
5
  import { CheckCertificateRevocationErrorCode, CheckCertificateRevocationFailureDetails, CheckCertificateRevocationInput, CheckCertificateRevocationResult, CheckCertificateRevocationValue, ConfiguredOcspResponder, ConfiguredOcspResponderCertificate, OcspResponderCandidate, OcspResponderSource, REVOCATION_INDETERMINATE_REASON_CODES, ResolveOcspResponderCandidatesInput, RevocationCertificateSource, RevocationCheckGoodValue, RevocationCheckIndeterminateValue, RevocationCheckRevokedValue, RevocationCrlEvidenceInput, RevocationEvidenceInput, RevocationEvidenceKind, RevocationIndeterminateEvidence, RevocationIndeterminateReasonCode, RevocationOcspEvidenceInput, RevocationStatus, checkCertificateRevocation, getCertificateOcspResponderUris, resolveOcspResponderCandidates } from "./revocation/revocation.js";
6
6
  import { CertificateRevocationStatus, CheckChainRevocationInput, CheckChainRevocationResult, CheckChainRevocationValue, OcspResponseSource, REVOCATION_INDETERMINATE_REASONS, RevocationExecutionError, RevocationIndeterminateReason, RevocationPolicy, RevocationSource, checkChainRevocation } from "./revocation/chain.js";
7
- export { type CertificateRevocationListMaterial, type CertificateRevocationStatus, type CheckCertificateRevocationAgainstCrlErrorCode, type CheckCertificateRevocationAgainstCrlFailure, type CheckCertificateRevocationAgainstCrlFailureDetails, type CheckCertificateRevocationAgainstCrlGoodValue, type CheckCertificateRevocationAgainstCrlInput, type CheckCertificateRevocationAgainstCrlResult, type CheckCertificateRevocationAgainstCrlRevokedValue, type CheckCertificateRevocationAgainstCrlValue, type CheckCertificateRevocationErrorCode, type CheckCertificateRevocationFailureDetails, type CheckCertificateRevocationInput, type CheckCertificateRevocationResult, type CheckCertificateRevocationValue, type CheckChainRevocationInput, type CheckChainRevocationResult, type CheckChainRevocationValue, type ConfiguredOcspResponder, type ConfiguredOcspResponderCertificate, type CreateCertificateRevocationListInput, type CreateOcspRequestInput, type CreateOcspRequestItemInput, type CreateOcspResponseInput, type CreateOcspSingleResponseInput, type CrlApplicabilityFailureReason, type CrlCertificateSource, type CrlSource, type IssuingDistributionPoint, type IssuingDistributionPointForAttributeCerts, type IssuingDistributionPointForCaCerts, type IssuingDistributionPointForUserCerts, type OcspCertStatus, type OcspCertificateSource, type OcspHashAlgorithm, type OcspRequestMaterial, type OcspRequestSource, type OcspResponderCandidate, type OcspResponderRevocationPolicy, type OcspResponderSource, type OcspResponseMaterial, type OcspResponseSource, type OcspResponseStatus, type ParseCertificateRevocationListErrorCode, type ParseCertificateRevocationListFailure, type ParseCertificateRevocationListResult, type ParseOcspRequestErrorCode, type ParseOcspRequestFailure, type ParseOcspRequestResult, type ParseOcspResponseErrorCode, type ParseOcspResponseFailure, type ParseOcspResponseResult, type ParsedCertificateRevocationList, type ParsedIssuingDistributionPoint, type ParsedOcspCertId, type ParsedOcspRequest, type ParsedOcspResponderId, type ParsedOcspResponse, type ParsedOcspSingleResponse, type ParsedRevokedCertificate, REVOCATION_INDETERMINATE_REASONS, REVOCATION_INDETERMINATE_REASON_CODES, type ResolveOcspResponderCandidatesInput, type RevocationCertificateSource, type RevocationCheckGoodValue, type RevocationCheckIndeterminateValue, type RevocationCheckRevokedValue, type RevocationCrlEvidenceInput, type RevocationEvidenceInput, type RevocationEvidenceKind, type RevocationExecutionError, type RevocationIndeterminateEvidence, type RevocationIndeterminateReason, type RevocationIndeterminateReasonCode, type RevocationOcspEvidenceInput, type RevocationPolicy, type RevocationReason, type RevocationSource, type 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, checkCertificateRevocationAgainstCrl, checkChainRevocation, createCertificateRevocationList, createOcspRequest, createOcspResponse, getCertificateOcspResponderUris, hasOcspNoCheckExtension, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, parseOcspRequestDer, parseOcspRequestDerOrThrow, parseOcspRequestPem, parseOcspRequestPemOrThrow, parseOcspResponseDer, parseOcspResponseDerOrThrow, parseOcspResponsePem, parseOcspResponsePemOrThrow, resolveOcspResponderCandidates, validateCertificateRevocationList, validateOcspResponse, verifyCertificateRevocationListSignature, verifyOcspResponseSignature };
7
+ export { type CertificateRevocationListMaterial, type CertificateRevocationStatus, type CheckCertificateRevocationAgainstCrlErrorCode, type CheckCertificateRevocationAgainstCrlFailure, type CheckCertificateRevocationAgainstCrlFailureDetails, type CheckCertificateRevocationAgainstCrlGoodValue, type CheckCertificateRevocationAgainstCrlInput, type CheckCertificateRevocationAgainstCrlResult, type CheckCertificateRevocationAgainstCrlRevokedValue, type CheckCertificateRevocationAgainstCrlValue, type CheckCertificateRevocationErrorCode, type CheckCertificateRevocationFailureDetails, type CheckCertificateRevocationInput, type CheckCertificateRevocationResult, type CheckCertificateRevocationValue, type CheckChainRevocationInput, type CheckChainRevocationResult, type CheckChainRevocationValue, type ConfiguredOcspResponder, type ConfiguredOcspResponderCertificate, type CreateCertificateRevocationListInput, type CreateOcspRequestInput, type CreateOcspRequestItemInput, type CreateOcspResponseInput, type CreateOcspSingleResponseInput, type CrlApplicabilityFailureReason, type CrlCertificateSource, type CrlSource, type IssuingDistributionPoint, type IssuingDistributionPointBase, type IssuingDistributionPointForAttributeCerts, type IssuingDistributionPointForCaCerts, type IssuingDistributionPointForUserCerts, type OcspCertStatus, type OcspCertificateSource, type OcspHashAlgorithm, type OcspRequestMaterial, type OcspRequestSource, type OcspResponderCandidate, type OcspResponderRevocationPolicy, type OcspResponderSource, type OcspResponseMaterial, type OcspResponseSource, type OcspResponseStatus, type ParseCertificateRevocationListErrorCode, type ParseCertificateRevocationListFailure, type ParseCertificateRevocationListResult, type ParseOcspRequestErrorCode, type ParseOcspRequestFailure, type ParseOcspRequestResult, type ParseOcspResponseErrorCode, type ParseOcspResponseFailure, type ParseOcspResponseResult, type ParsedCertificateRevocationList, type ParsedIssuingDistributionPoint, type ParsedOcspCertId, type ParsedOcspRequest, type ParsedOcspResponderId, type ParsedOcspResponse, type ParsedOcspSingleResponse, type ParsedRevokedCertificate, REVOCATION_INDETERMINATE_REASONS, REVOCATION_INDETERMINATE_REASON_CODES, type ResolveOcspResponderCandidatesInput, type RevocationCertificateSource, type RevocationCheckGoodValue, type RevocationCheckIndeterminateValue, type RevocationCheckRevokedValue, type RevocationCrlEvidenceInput, type RevocationEvidenceInput, type RevocationEvidenceKind, type RevocationExecutionError, type RevocationIndeterminateEvidence, type RevocationIndeterminateReason, type RevocationIndeterminateReasonCode, type RevocationOcspEvidenceInput, type RevocationPolicy, type RevocationReason, type RevocationSource, type 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, checkCertificateRevocationAgainstCrl, checkChainRevocation, createCertificateRevocationList, createOcspRequest, createOcspResponse, getCertificateOcspResponderUris, hasOcspNoCheckExtension, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, parseOcspRequestDer, parseOcspRequestDerOrThrow, parseOcspRequestPem, parseOcspRequestPemOrThrow, parseOcspResponseDer, parseOcspResponseDerOrThrow, parseOcspResponsePem, parseOcspResponsePemOrThrow, resolveOcspResponderCandidates, validateCertificateRevocationList, validateOcspResponse, verifyCertificateRevocationListSignature, verifyOcspResponseSignature };
@@ -1 +1,5 @@
1
- import{checkCertificateRevocationAgainstCrl as e,createCertificateRevocationList as t,isCertificateRevoked as n,parseCertificateRevocationListDer as r,parseCertificateRevocationListDerOrThrow as i,parseCertificateRevocationListPem as a,parseCertificateRevocationListPemOrThrow as o,validateCertificateRevocationList as s,verifyCertificateRevocationListSignature as c}from"./revocation/crl.js";import{REVOCATION_INDETERMINATE_REASONS as l,checkChainRevocation as u}from"./revocation/chain.js";import{createOcspRequest as d,createOcspResponse as f,hasOcspNoCheckExtension as p,parseOcspRequestDer as m,parseOcspRequestDerOrThrow as h,parseOcspRequestPem as g,parseOcspRequestPemOrThrow as _,parseOcspResponseDer as v,parseOcspResponseDerOrThrow as y,parseOcspResponsePem as b,parseOcspResponsePemOrThrow as x,validateOcspResponse as S,verifyOcspResponseSignature as C}from"./revocation/ocsp.js";import{REVOCATION_INDETERMINATE_REASON_CODES as w,checkCertificateRevocation as T,getCertificateOcspResponderUris as E,resolveOcspResponderCandidates as D}from"./revocation/revocation.js";export{l as REVOCATION_INDETERMINATE_REASONS,w as REVOCATION_INDETERMINATE_REASON_CODES,T as checkCertificateRevocation,e as checkCertificateRevocationAgainstCrl,u as checkChainRevocation,t as createCertificateRevocationList,d as createOcspRequest,f as createOcspResponse,E as getCertificateOcspResponderUris,p as hasOcspNoCheckExtension,n as isCertificateRevoked,r as parseCertificateRevocationListDer,i as parseCertificateRevocationListDerOrThrow,a as parseCertificateRevocationListPem,o as parseCertificateRevocationListPemOrThrow,m as parseOcspRequestDer,h as parseOcspRequestDerOrThrow,g as parseOcspRequestPem,_ as parseOcspRequestPemOrThrow,v as parseOcspResponseDer,y as parseOcspResponseDerOrThrow,b as parseOcspResponsePem,x as parseOcspResponsePemOrThrow,D as resolveOcspResponderCandidates,s as validateCertificateRevocationList,S as validateOcspResponse,c as verifyCertificateRevocationListSignature,C as verifyOcspResponseSignature};
1
+ import { checkCertificateRevocationAgainstCrl, createCertificateRevocationList, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, validateCertificateRevocationList, verifyCertificateRevocationListSignature } from "./revocation/crl.js";
2
+ import { REVOCATION_INDETERMINATE_REASONS, checkChainRevocation } from "./revocation/chain.js";
3
+ import { createOcspRequest, createOcspResponse, hasOcspNoCheckExtension, parseOcspRequestDer, parseOcspRequestDerOrThrow, parseOcspRequestPem, parseOcspRequestPemOrThrow, parseOcspResponseDer, parseOcspResponseDerOrThrow, parseOcspResponsePem, parseOcspResponsePemOrThrow, validateOcspResponse, verifyOcspResponseSignature } from "./revocation/ocsp.js";
4
+ import { REVOCATION_INDETERMINATE_REASON_CODES, checkCertificateRevocation, getCertificateOcspResponderUris, resolveOcspResponderCandidates } from "./revocation/revocation.js";
5
+ export { REVOCATION_INDETERMINATE_REASONS, REVOCATION_INDETERMINATE_REASON_CODES, checkCertificateRevocation, checkCertificateRevocationAgainstCrl, checkChainRevocation, createCertificateRevocationList, createOcspRequest, createOcspResponse, getCertificateOcspResponderUris, hasOcspNoCheckExtension, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, parseOcspRequestDer, parseOcspRequestDerOrThrow, parseOcspRequestPem, parseOcspRequestPemOrThrow, parseOcspResponseDer, parseOcspResponseDerOrThrow, parseOcspResponsePem, parseOcspResponsePemOrThrow, resolveOcspResponderCandidates, validateCertificateRevocationList, validateOcspResponse, verifyCertificateRevocationListSignature, verifyOcspResponseSignature };
@@ -119,5 +119,4 @@ declare function matchServiceIdentity(input: MatchServiceIdentityInput): MatchSe
119
119
  */
120
120
  declare function matchCertificateServiceIdentity(rawCertificate: ParsedCertificate, serviceIdentity: ServiceIdentityInput): MatchServiceIdentityResult;
121
121
  //#endregion
122
- export { DnsServiceIdentityInput, IpServiceIdentityInput, MatchServiceIdentityErrorCode, MatchServiceIdentityFailure, MatchServiceIdentityFailureDetails, MatchServiceIdentityFailureResult, MatchServiceIdentityInput, MatchServiceIdentityResult, MatchServiceIdentitySuccess, ServiceIdentityInput, ServiceIdentityType, SrvServiceIdentityInput, UriServiceIdentityInput, matchCertificateServiceIdentity, matchServiceIdentity };
123
- //# sourceMappingURL=identity.d.ts.map
122
+ export { DnsServiceIdentityInput, IpServiceIdentityInput, MatchServiceIdentityErrorCode, MatchServiceIdentityFailure, MatchServiceIdentityFailureDetails, MatchServiceIdentityFailureResult, MatchServiceIdentityInput, MatchServiceIdentityResult, MatchServiceIdentitySuccess, ServiceIdentityInput, ServiceIdentityType, SrvServiceIdentityInput, UriServiceIdentityInput, matchCertificateServiceIdentity, matchServiceIdentity };
@@ -1,2 +1,270 @@
1
- import{errorResult as e,micro509Error as t,successResult as n}from"../result/result.js";import{decodeIpAddress as r,parseIpAddressToBytes as i}from"../internal/shared/ip.js";import{parseCertificateDerOrThrow as a}from"../x509/parse.js";function o(e){return s(e.certificate,e.serviceIdentity)}function s(e,t){let n;try{n=a(new Uint8Array(e.der))}catch{return _(`subject_alt_name_mismatch`,`certificate input is malformed`)}switch(t.type){case`dns`:{if(typeof t.value!=`string`)return y(n,`dns`,t.value);let e=t.value,r=n.subjectAltNames?.filter(e=>e.type===`dns`)??[];if(r.some(t=>c(t.value,e)))return v();let i=f(n);if(t.allowCommonNameFallback===!0&&i.length>0)return _(`common_name_fallback_suppressed`,`DNS name not present in SAN; CN fallback suppressed because supported SAN identifiers exist`,S(n.subject.values.commonName,e,r.map(e=>e.value).join(`,`),{presentedIdentifierTypes:i,commonNameFallbackReason:`suppressed_by_presented_identifier`}));if(r.length>0)return _(`subject_alt_name_mismatch`,`DNS name not present in SAN`,S(n.subject.values.commonName,e,r.map(e=>e.value).join(`,`)));if(t.allowCommonNameFallback===!0){let t=n.subject.values.commonName;return t===void 0||!c(t,e)?_(`subject_alt_name_mismatch`,`DNS name not present in SAN or CN`,S(t,e,t??``,{commonNameFallbackReason:t===void 0?`common_name_missing`:`common_name_mismatch`})):v()}return _(`subject_alt_name_mismatch`,`DNS name not present in SAN`,S(n.subject.values.commonName,e,``,{commonNameFallbackReason:`disabled`}))}case`ip`:{if(typeof t.value!=`string`)return y(n,`ip`,t.value);let e=b(t.value);if(e===void 0)return y(n,`ip`,t.value);let i=r(e),a=n.subjectAltNames?.filter(e=>e.type===`ip`)??[],o=[];for(let t of a){let a=b(t.value);if(a===void 0)return _(`subject_alt_name_mismatch`,`IP address SAN is malformed`,S(n.subject.values.commonName,i,`ip:${t.value}`));if(o.push(r(a)),x(a,e))return v()}return _(`subject_alt_name_mismatch`,`IP address not present in SAN`,S(n.subject.values.commonName,i,o.join(`,`)))}case`uri`:{if(typeof t.value!=`string`)return y(n,`uri`,t.value);let e=p(t.value);if(e===void 0)return y(n,`uri`,t.value);let r=n.subjectAltNames?.filter(e=>e.type===`uri`)??[],i=r.flatMap(t=>{let n=p(t.value);return n===void 0||n.serviceType!==e.serviceType?[]:[n]});return i.some(t=>c(t.domainName,e.domainName))?v():i.length>0?_(`subject_alt_name_mismatch`,`URI host not present in SAN`,S(n.subject.values.commonName,e.domainName,i.map(e=>e.domainName).join(`,`))):r.length>0?_(`service_identity_mismatch`,`URI scheme not present in SAN`,S(n.subject.values.commonName,e.serviceType,r.flatMap(e=>{let t=p(e.value);return t===void 0?[]:[t.serviceType]}).join(`,`))):_(`subject_alt_name_mismatch`,`URI-ID not present in SAN`,S(n.subject.values.commonName,e.domainName,``))}case`srv`:{if(typeof t.value!=`string`)return y(n,`srv`,t.value);let e=g(t.value);if(e===void 0)return y(n,`srv`,t.value);let r=n.subjectAltNames?.filter(e=>e.type===`srv`)??[],i=r.flatMap(t=>{let n=g(t.value);return n===void 0||n.serviceType!==e.serviceType?[]:[n]});return i.some(t=>c(t.domainName,e.domainName))?v():i.length>0?_(`subject_alt_name_mismatch`,`SRV domain not present in SAN`,S(n.subject.values.commonName,e.domainName,i.map(e=>e.domainName).join(`,`))):r.length>0?_(`service_identity_mismatch`,`SRV service not present in SAN`,S(n.subject.values.commonName,e.serviceType,r.flatMap(e=>{let t=g(e.value);return t===void 0?[]:[t.serviceType]}).join(`,`))):_(`subject_alt_name_mismatch`,`SRV-ID not present in SAN`,S(n.subject.values.commonName,e.domainName,``))}default:return _(`unsupported_service_identity_type`,`Unsupported service identity type`)}}function c(e,t){let n=l(e),r=u(t);if(!n.includes(`*`))return n===r;if(!n.startsWith(`*.`))return!1;let i=n.slice(1);if(!r.endsWith(i))return!1;let a=r.slice(0,r.length-i.length);return a.length>0&&!a.includes(`.`)}function l(e){return e.startsWith(`*.`)?`*.${u(e.slice(2))}`:u(e)}function u(e){return d(e)??e.toLowerCase()}function d(e){if(e.length!==0){for(let t of[`/`,`:`,`?`,`#`,`@`,`[`,`]`])if(e.includes(t))return;try{return new URL(`https://${e}`).hostname.toLowerCase()}catch{return}}}function f(e){let t=e.subjectAltNames??[],n=[];for(let e of[`dns`,`uri`,`srv`])t.some(t=>t.type===e)&&n.push(e);return n}function p(e){let t=e.indexOf(`:`);if(t<=0)return;let n=e.slice(0,t).toLowerCase(),r=m(e);if(r!==void 0)return{serviceType:n,domainName:u(r)}}function m(e){let t=e.indexOf(`:`);if(t<=0)return;let n=e.slice(t+1),r=h(n.startsWith(`//`)?n.slice(2):n,[`/`,`?`,`#`]),i=r.lastIndexOf(`@`);if(i>=0&&(r=r.slice(i+1)),r.startsWith(`[`))return;let a=h(r,[`:`,`;`]);if(!(a.length===0||a.includes(`[`)||a.includes(`]`)))return a}function h(e,t){let n=e.length;for(let r of t){let t=e.indexOf(r);t>=0&&t<n&&(n=t)}return e.slice(0,n)}function g(e){if(!e.startsWith(`_`))return;let t=e.indexOf(`.`);if(!(t<=1||t===e.length-1))return{serviceType:e.slice(1,t).toLowerCase(),domainName:u(e.slice(t+1))}}function _(n,r,i){return e({ok:!1,...t(n,r,i)})}function v(){return n(void 0)}function y(e,t,n){let r=typeof n==`string`?n:`<malformed>`;return _(`subject_alt_name_mismatch`,`service identity input is malformed`,S(e.subject.values.commonName,`${t}:${r}`,t))}function b(e){try{return i(e)}catch{return}}function x(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function S(e,t,n,r){return{...e===void 0?{}:{subjectCommonName:e},expected:t,actual:n,...r?.presentedIdentifierTypes===void 0?{}:{presentedIdentifierTypes:r.presentedIdentifierTypes},...r?.commonNameFallbackReason===void 0?{}:{commonNameFallbackReason:r.commonNameFallbackReason}}}export{s as matchCertificateServiceIdentity,o as matchServiceIdentity};
2
- //# sourceMappingURL=identity.js.map
1
+ import { errorResult, micro509Error, successResult } from "../result/result.js";
2
+ import { decodeIpAddress, parseIpAddressToBytes } from "../internal/shared/ip.js";
3
+ import { parseCertificateDerOrThrow } from "../x509/parse.js";
4
+ //#region src/verify/identity.ts
5
+ /**
6
+ * Service-identity matching (RFC 6125 / RFC 9525).
7
+ *
8
+ * Compares a reference identifier (hostname, IP, URI, SRV name) against the
9
+ * presented identifiers in a certificate's SAN extension, with optional
10
+ * common-name fallback for DNS names.
11
+ *
12
+ * @module
13
+ */
14
+ /**
15
+ * Checks whether a certificate covers the requested service identity.
16
+ *
17
+ * Delegates to {@linkcode matchCertificateServiceIdentity} — this overload
18
+ * accepts a single options object.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const result = matchServiceIdentity({
23
+ * certificate: parsed,
24
+ * serviceIdentity: { type: 'dns', value: 'example.com' },
25
+ * });
26
+ * if (!result.ok) console.error(result.error.message);
27
+ * ```
28
+ */
29
+ function matchServiceIdentity(input) {
30
+ return matchCertificateServiceIdentity(input.certificate, input.serviceIdentity);
31
+ }
32
+ /**
33
+ * Compares a reference identifier against a certificate's SAN entries.
34
+ *
35
+ * Supports DNS (with wildcard matching), IP, URI-ID, and SRV-ID.
36
+ * For DNS, optionally falls back to subject CN when no SAN of a supported type is present.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const result = matchCertificateServiceIdentity(parsed, {
41
+ * type: 'ip',
42
+ * value: '192.168.1.1',
43
+ * });
44
+ * ```
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const result = matchCertificateServiceIdentity(parsed, {
49
+ * type: 'dns',
50
+ * value: 'mail.example.com',
51
+ * allowCommonNameFallback: true,
52
+ * });
53
+ * ```
54
+ */
55
+ function matchCertificateServiceIdentity(rawCertificate, serviceIdentity) {
56
+ let certificate;
57
+ try {
58
+ certificate = parseCertificateDerOrThrow(new Uint8Array(rawCertificate.der));
59
+ } catch {
60
+ return failure("subject_alt_name_mismatch", "certificate input is malformed");
61
+ }
62
+ switch (serviceIdentity.type) {
63
+ case "dns": {
64
+ if (typeof serviceIdentity.value !== "string") return malformedServiceIdentityFailure(certificate, "dns", serviceIdentity.value);
65
+ const expected = serviceIdentity.value;
66
+ const sans = certificate.subjectAltNames?.filter((entry) => entry.type === "dns") ?? [];
67
+ if (sans.some((entry) => matchesDnsName(entry.value, expected))) return success();
68
+ const presentedIdentifierTypes = presentedDnsIdentifierTypes(certificate);
69
+ if (serviceIdentity.allowCommonNameFallback === true && presentedIdentifierTypes.length > 0) return failure("common_name_fallback_suppressed", "DNS name not present in SAN; CN fallback suppressed because supported SAN identifiers exist", details(certificate.subject.values.commonName, expected, sans.map((entry) => entry.value).join(","), {
70
+ presentedIdentifierTypes,
71
+ commonNameFallbackReason: "suppressed_by_presented_identifier"
72
+ }));
73
+ if (sans.length > 0) return failure("subject_alt_name_mismatch", "DNS name not present in SAN", details(certificate.subject.values.commonName, expected, sans.map((entry) => entry.value).join(",")));
74
+ if (serviceIdentity.allowCommonNameFallback === true) {
75
+ const commonName = certificate.subject.values.commonName;
76
+ if (commonName === void 0 || !matchesDnsName(commonName, expected)) return failure("subject_alt_name_mismatch", "DNS name not present in SAN or CN", details(commonName, expected, commonName ?? "", { commonNameFallbackReason: commonName === void 0 ? "common_name_missing" : "common_name_mismatch" }));
77
+ return success();
78
+ }
79
+ return failure("subject_alt_name_mismatch", "DNS name not present in SAN", details(certificate.subject.values.commonName, expected, "", { commonNameFallbackReason: "disabled" }));
80
+ }
81
+ case "ip": {
82
+ if (typeof serviceIdentity.value !== "string") return malformedServiceIdentityFailure(certificate, "ip", serviceIdentity.value);
83
+ const expectedBytes = tryParsePresentedIpAddress(serviceIdentity.value);
84
+ if (expectedBytes === void 0) return malformedServiceIdentityFailure(certificate, "ip", serviceIdentity.value);
85
+ const expected = decodeIpAddress(expectedBytes);
86
+ const sans = certificate.subjectAltNames?.filter((entry) => entry.type === "ip") ?? [];
87
+ const presentedAddresses = [];
88
+ for (const entry of sans) {
89
+ const presentedBytes = tryParsePresentedIpAddress(entry.value);
90
+ if (presentedBytes === void 0) return failure("subject_alt_name_mismatch", "IP address SAN is malformed", details(certificate.subject.values.commonName, expected, `ip:${entry.value}`));
91
+ presentedAddresses.push(decodeIpAddress(presentedBytes));
92
+ if (sameIpAddressBytes(presentedBytes, expectedBytes)) return success();
93
+ }
94
+ return failure("subject_alt_name_mismatch", "IP address not present in SAN", details(certificate.subject.values.commonName, expected, presentedAddresses.join(",")));
95
+ }
96
+ case "uri": {
97
+ if (typeof serviceIdentity.value !== "string") return malformedServiceIdentityFailure(certificate, "uri", serviceIdentity.value);
98
+ const expected = tryParseUriServiceIdentity(serviceIdentity.value);
99
+ if (expected === void 0) return malformedServiceIdentityFailure(certificate, "uri", serviceIdentity.value);
100
+ const sans = certificate.subjectAltNames?.filter((entry) => entry.type === "uri") ?? [];
101
+ const matchingService = sans.flatMap((entry) => {
102
+ const parsed = tryParseUriServiceIdentity(entry.value);
103
+ if (parsed === void 0 || parsed.serviceType !== expected.serviceType) return [];
104
+ return [parsed];
105
+ });
106
+ if (matchingService.some((entry) => matchesDnsName(entry.domainName, expected.domainName))) return success();
107
+ if (matchingService.length > 0) return failure("subject_alt_name_mismatch", "URI host not present in SAN", details(certificate.subject.values.commonName, expected.domainName, matchingService.map((entry) => entry.domainName).join(",")));
108
+ if (sans.length > 0) return failure("service_identity_mismatch", "URI scheme not present in SAN", details(certificate.subject.values.commonName, expected.serviceType, sans.flatMap((entry) => {
109
+ const parsed = tryParseUriServiceIdentity(entry.value);
110
+ return parsed === void 0 ? [] : [parsed.serviceType];
111
+ }).join(",")));
112
+ return failure("subject_alt_name_mismatch", "URI-ID not present in SAN", details(certificate.subject.values.commonName, expected.domainName, ""));
113
+ }
114
+ case "srv": {
115
+ if (typeof serviceIdentity.value !== "string") return malformedServiceIdentityFailure(certificate, "srv", serviceIdentity.value);
116
+ const expected = tryParseSrvServiceIdentity(serviceIdentity.value);
117
+ if (expected === void 0) return malformedServiceIdentityFailure(certificate, "srv", serviceIdentity.value);
118
+ const sans = certificate.subjectAltNames?.filter((entry) => entry.type === "srv") ?? [];
119
+ const matchingService = sans.flatMap((entry) => {
120
+ const parsed = tryParseSrvServiceIdentity(entry.value);
121
+ if (parsed === void 0 || parsed.serviceType !== expected.serviceType) return [];
122
+ return [parsed];
123
+ });
124
+ if (matchingService.some((entry) => matchesDnsName(entry.domainName, expected.domainName))) return success();
125
+ if (matchingService.length > 0) return failure("subject_alt_name_mismatch", "SRV domain not present in SAN", details(certificate.subject.values.commonName, expected.domainName, matchingService.map((entry) => entry.domainName).join(",")));
126
+ if (sans.length > 0) return failure("service_identity_mismatch", "SRV service not present in SAN", details(certificate.subject.values.commonName, expected.serviceType, sans.flatMap((entry) => {
127
+ const parsed = tryParseSrvServiceIdentity(entry.value);
128
+ return parsed === void 0 ? [] : [parsed.serviceType];
129
+ }).join(",")));
130
+ return failure("subject_alt_name_mismatch", "SRV-ID not present in SAN", details(certificate.subject.values.commonName, expected.domainName, ""));
131
+ }
132
+ default: return failure("unsupported_service_identity_type", "Unsupported service identity type");
133
+ }
134
+ }
135
+ /** Compares a presented DNS identifier (possibly wildcarded) against a reference name. */
136
+ function matchesDnsName(pattern, actual) {
137
+ const lowerPattern = normalizeDnsPattern(pattern);
138
+ const lowerActual = normalizeDnsName(actual);
139
+ if (!lowerPattern.includes("*")) return lowerPattern === lowerActual;
140
+ if (!lowerPattern.startsWith("*.")) return false;
141
+ const suffix = lowerPattern.slice(1);
142
+ if (!lowerActual.endsWith(suffix)) return false;
143
+ const prefix = lowerActual.slice(0, lowerActual.length - suffix.length);
144
+ return prefix.length > 0 && !prefix.includes(".");
145
+ }
146
+ /** Lowercases a DNS pattern, preserving the `*.` wildcard prefix if present. */
147
+ function normalizeDnsPattern(value) {
148
+ if (!value.startsWith("*.")) return normalizeDnsName(value);
149
+ return `*.${normalizeDnsName(value.slice(2))}`;
150
+ }
151
+ /** Lowercases and IDNA-normalizes a DNS name via the URL parser. */
152
+ function normalizeDnsName(value) {
153
+ return tryNormalizeDnsName(value) ?? value.toLowerCase();
154
+ }
155
+ /** Attempts IDNA normalization via URL constructor. Returns `undefined` for invalid names. */
156
+ function tryNormalizeDnsName(value) {
157
+ if (value.length === 0) return;
158
+ for (const forbidden of [
159
+ "/",
160
+ ":",
161
+ "?",
162
+ "#",
163
+ "@",
164
+ "[",
165
+ "]"
166
+ ]) if (value.includes(forbidden)) return;
167
+ try {
168
+ return new URL(`https://${value}`).hostname.toLowerCase();
169
+ } catch {
170
+ return;
171
+ }
172
+ }
173
+ /** Returns which SAN types (dns, uri, srv) the certificate presents, used for CN-fallback suppression. */
174
+ function presentedDnsIdentifierTypes(certificate) {
175
+ const sans = certificate.subjectAltNames ?? [];
176
+ const types = [];
177
+ for (const type of [
178
+ "dns",
179
+ "uri",
180
+ "srv"
181
+ ]) if (sans.some((entry) => entry.type === type)) types.push(type);
182
+ return types;
183
+ }
184
+ /** Attempts to split a URI into scheme + reg-name. @returns `undefined` on failure. */
185
+ function tryParseUriServiceIdentity(value) {
186
+ const schemeEnd = value.indexOf(":");
187
+ if (schemeEnd <= 0) return;
188
+ const serviceType = value.slice(0, schemeEnd).toLowerCase();
189
+ const domainName = extractUriRegName(value);
190
+ if (domainName === void 0) return;
191
+ return {
192
+ serviceType,
193
+ domainName: normalizeDnsName(domainName)
194
+ };
195
+ }
196
+ /** Extracts the reg-name host from a URI, stripping scheme, userinfo, port, and path components. */
197
+ function extractUriRegName(value) {
198
+ const schemeEnd = value.indexOf(":");
199
+ if (schemeEnd <= 0) return;
200
+ const schemeSpecific = value.slice(schemeEnd + 1);
201
+ let authority = cutAtFirstDelimiter(schemeSpecific.startsWith("//") ? schemeSpecific.slice(2) : schemeSpecific, [
202
+ "/",
203
+ "?",
204
+ "#"
205
+ ]);
206
+ const userInfoSeparator = authority.lastIndexOf("@");
207
+ if (userInfoSeparator >= 0) authority = authority.slice(userInfoSeparator + 1);
208
+ if (authority.startsWith("[")) return;
209
+ const host = cutAtFirstDelimiter(authority, [":", ";"]);
210
+ if (host.length === 0 || host.includes("[") || host.includes("]")) return;
211
+ return host;
212
+ }
213
+ /** Returns the substring before the first occurrence of any delimiter character. */
214
+ function cutAtFirstDelimiter(value, delimiters) {
215
+ let end = value.length;
216
+ for (const delimiter of delimiters) {
217
+ const index = value.indexOf(delimiter);
218
+ if (index >= 0 && index < end) end = index;
219
+ }
220
+ return value.slice(0, end);
221
+ }
222
+ /** Attempts to split `_service.domain` into parts. @returns `undefined` on failure. */
223
+ function tryParseSrvServiceIdentity(value) {
224
+ if (!value.startsWith("_")) return;
225
+ const dotIndex = value.indexOf(".");
226
+ if (dotIndex <= 1 || dotIndex === value.length - 1) return;
227
+ return {
228
+ serviceType: value.slice(1, dotIndex).toLowerCase(),
229
+ domainName: normalizeDnsName(value.slice(dotIndex + 1))
230
+ };
231
+ }
232
+ /** Constructs a failure result with the given error code and diagnostic details. */
233
+ function failure(code, message, details) {
234
+ return errorResult({
235
+ ok: false,
236
+ ...micro509Error(code, message, details)
237
+ });
238
+ }
239
+ /** Constructs a success result indicating the identity matched. */
240
+ function success() {
241
+ return successResult(void 0);
242
+ }
243
+ function malformedServiceIdentityFailure(certificate, type, value) {
244
+ const renderedValue = typeof value === "string" ? value : "<malformed>";
245
+ return failure("subject_alt_name_mismatch", "service identity input is malformed", details(certificate.subject.values.commonName, `${type}:${renderedValue}`, type));
246
+ }
247
+ function tryParsePresentedIpAddress(value) {
248
+ try {
249
+ return parseIpAddressToBytes(value);
250
+ } catch {
251
+ return;
252
+ }
253
+ }
254
+ function sameIpAddressBytes(left, right) {
255
+ if (left.length !== right.length) return false;
256
+ for (let index = 0; index < left.length; index += 1) if (left[index] !== right[index]) return false;
257
+ return true;
258
+ }
259
+ /** Assembles failure detail fields, merging optional CN-fallback and identifier-type info. */
260
+ function details(subjectCommonName, expected, actual, extra) {
261
+ return {
262
+ ...subjectCommonName === void 0 ? {} : { subjectCommonName },
263
+ expected,
264
+ actual,
265
+ ...extra?.presentedIdentifierTypes === void 0 ? {} : { presentedIdentifierTypes: extra.presentedIdentifierTypes },
266
+ ...extra?.commonNameFallbackReason === void 0 ? {} : { commonNameFallbackReason: extra.commonNameFallbackReason }
267
+ };
268
+ }
269
+ //#endregion
270
+ export { matchCertificateServiceIdentity, matchServiceIdentity };
@@ -14,5 +14,4 @@ interface InitialNameConstraintsInput {
14
14
  readonly excludedSubtrees?: readonly GeneralSubtree[];
15
15
  }
16
16
  //#endregion
17
- export { InitialNameConstraintsInput };
18
- //# sourceMappingURL=name-constraints.d.ts.map
17
+ export { InitialNameConstraintsInput };
@@ -35,5 +35,4 @@ interface PolicyValidationOutcome {
35
35
  readonly userConstrainedPolicies: readonly ConstrainedPolicy[];
36
36
  }
37
37
  //#endregion
38
- export { ConstrainedPolicy, PolicyValidationInput, PolicyValidationOutcome };
39
- //# sourceMappingURL=policy.d.ts.map
38
+ export { ConstrainedPolicy, PolicyValidationInput, PolicyValidationOutcome };