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,7 +1,7 @@
1
1
  import { IssuingDistributionPoint, IssuingDistributionPointBase, IssuingDistributionPointForAttributeCerts, IssuingDistributionPointForCaCerts, IssuingDistributionPointForUserCerts } from "./x509/extensions.js";
2
- import { ParsedIssuingDistributionPoint } 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 "./revocation/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 "./revocation/ocsp.js";
2
+ import { ParsedIssuingDistributionPoint, ParsedIssuingDistributionPointBase, ParsedIssuingDistributionPointScope } from "./x509/parse.js";
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 "./revocation/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 "./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
- 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 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 };
6
+ import { CertificateRevocationStatus, CheckChainRevocationInput, CheckChainRevocationResult, CheckChainRevocationValue, OcspResponseSource, REVOCATION_INDETERMINATE_REASONS, RevocationExecutionError, RevocationIndeterminateReason, RevocationParseError, RevocationPolicy, RevocationProcessingError, RevocationSource, TrustedOcspResponder, 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 CreateOcspCertStatusInput, type CreateOcspRequestInput, type CreateOcspRequestItemInput, type CreateOcspResponseInput, type CreateOcspSingleResponseInput, type CrlApplicabilityFailureReason, type CrlCertificateSource, type CrlEncoderErrorCode, type CrlSource, type IssuingDistributionPoint, type IssuingDistributionPointBase, type IssuingDistributionPointForAttributeCerts, type IssuingDistributionPointForCaCerts, type IssuingDistributionPointForUserCerts, type OcspCertStatus, type OcspCertificateSource, type OcspEncoderErrorCode, 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 ParsedIssuingDistributionPointBase, type ParsedIssuingDistributionPointScope, type ParsedOcspCertId, type ParsedOcspCertStatus, type ParsedOcspRequest, type ParsedOcspResponderId, type ParsedOcspResponse, type ParsedOcspSingleResponse, type ParsedRevocationReason, 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 RevocationParseError, type RevocationPolicy, type RevocationProcessingError, type RevocationReason, type RevocationSource, type RevocationStatus, type RevokedCertificateInput, type TrustedOcspResponder, type UnrecognizedReasonCodePolicy, type UnrecognizedRevocationReason, 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, revocationReasonFromCode, validateCertificateRevocationList, validateOcspResponse, verifyCertificateRevocationListSignature, verifyOcspResponseSignature };
@@ -1,5 +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";
2
- import { createOcspRequest as l, createOcspResponse as u, hasOcspNoCheckExtension as d, parseOcspRequestDer as f, parseOcspRequestDerOrThrow as p, parseOcspRequestPem as m, parseOcspRequestPemOrThrow as h, parseOcspResponseDer as g, parseOcspResponseDerOrThrow as _, parseOcspResponsePem as v, parseOcspResponsePemOrThrow as y, validateOcspResponse as b, verifyOcspResponseSignature as x } from "./revocation/ocsp.js";
3
- import { REVOCATION_INDETERMINATE_REASONS as S, checkChainRevocation as C } from "./revocation/chain.js";
4
- import { REVOCATION_INDETERMINATE_REASON_CODES as w, checkCertificateRevocation as T, getCertificateOcspResponderUris as E, resolveOcspResponderCandidates as D } from "./revocation/revocation.js";
5
- export { S as REVOCATION_INDETERMINATE_REASONS, w as REVOCATION_INDETERMINATE_REASON_CODES, T as checkCertificateRevocation, e as checkCertificateRevocationAgainstCrl, C as checkChainRevocation, t as createCertificateRevocationList, l as createOcspRequest, u as createOcspResponse, E as getCertificateOcspResponderUris, d as hasOcspNoCheckExtension, n as isCertificateRevoked, r as parseCertificateRevocationListDer, i as parseCertificateRevocationListDerOrThrow, a as parseCertificateRevocationListPem, o as parseCertificateRevocationListPemOrThrow, f as parseOcspRequestDer, p as parseOcspRequestDerOrThrow, m as parseOcspRequestPem, h as parseOcspRequestPemOrThrow, g as parseOcspResponseDer, _ as parseOcspResponseDerOrThrow, v as parseOcspResponsePem, y as parseOcspResponsePemOrThrow, D as resolveOcspResponderCandidates, s as validateCertificateRevocationList, b as validateOcspResponse, c as verifyCertificateRevocationListSignature, x as verifyOcspResponseSignature };
1
+ import { checkCertificateRevocationAgainstCrl as e, createCertificateRevocationList as t, isCertificateRevoked as n, parseCertificateRevocationListDer as r, parseCertificateRevocationListDerOrThrow as i, parseCertificateRevocationListPem as a, parseCertificateRevocationListPemOrThrow as o, revocationReasonFromCode as s, validateCertificateRevocationList as c, verifyCertificateRevocationListSignature as l } from "./revocation/crl.js";
2
+ import { createOcspRequest as u, createOcspResponse as d, hasOcspNoCheckExtension as f, parseOcspRequestDer as p, parseOcspRequestDerOrThrow as m, parseOcspRequestPem as h, parseOcspRequestPemOrThrow as g, parseOcspResponseDer as _, parseOcspResponseDerOrThrow as v, parseOcspResponsePem as y, parseOcspResponsePemOrThrow as b, validateOcspResponse as x, verifyOcspResponseSignature as S } from "./revocation/ocsp.js";
3
+ import { REVOCATION_INDETERMINATE_REASONS as C, checkChainRevocation as w } from "./revocation/chain.js";
4
+ import { REVOCATION_INDETERMINATE_REASON_CODES as T, checkCertificateRevocation as E, getCertificateOcspResponderUris as D, resolveOcspResponderCandidates as O } from "./revocation/revocation.js";
5
+ export { C as REVOCATION_INDETERMINATE_REASONS, T as REVOCATION_INDETERMINATE_REASON_CODES, E as checkCertificateRevocation, e as checkCertificateRevocationAgainstCrl, w as checkChainRevocation, t as createCertificateRevocationList, u as createOcspRequest, d as createOcspResponse, D as getCertificateOcspResponderUris, f as hasOcspNoCheckExtension, n as isCertificateRevoked, r as parseCertificateRevocationListDer, i as parseCertificateRevocationListDerOrThrow, a as parseCertificateRevocationListPem, o as parseCertificateRevocationListPemOrThrow, p as parseOcspRequestDer, m as parseOcspRequestDerOrThrow, h as parseOcspRequestPem, g as parseOcspRequestPemOrThrow, _ as parseOcspResponseDer, v as parseOcspResponseDerOrThrow, y as parseOcspResponsePem, b as parseOcspResponsePemOrThrow, O as resolveOcspResponderCandidates, s as revocationReasonFromCode, c as validateCertificateRevocationList, x as validateOcspResponse, l as verifyCertificateRevocationListSignature, S as verifyOcspResponseSignature };
@@ -1,8 +1,7 @@
1
- import { ErrorResult, Micro509Error } from "../result/result.js";
1
+ import { DecodeRefusalCode, ErrorResult, Micro509Error } from "../result/result.js";
2
2
  import { ParsedCertificate } from "../x509/parse.js";
3
- //#region src/verify/identity.d.ts
4
3
  /** DNS hostname reference identifier. */
5
- interface DnsServiceIdentityInput {
4
+ export interface DnsServiceIdentityInput {
6
5
  /** Discriminant for DNS hostname matching. */
7
6
  readonly type: "dns";
8
7
  /** The hostname to match (e.g. `"mail.example.com"`). Wildcard labels in the certificate are handled internally. */
@@ -10,39 +9,40 @@ interface DnsServiceIdentityInput {
10
9
  /**
11
10
  * When `true`, falls back to the subject CN if the SAN extension has no
12
11
  * dns/uri/srv entries. Suppressed when any supported SAN type is present.
12
+ * RFC 9525 §4.1 forbids identifying a service by the Common Name RDN.
13
13
  * @default false
14
14
  */
15
15
  readonly allowCommonNameFallback?: boolean;
16
16
  }
17
17
  /** IP address reference identifier. */
18
- interface IpServiceIdentityInput {
18
+ export interface IpServiceIdentityInput {
19
19
  /** Discriminant for IP address matching. */
20
20
  readonly type: "ip";
21
21
  /** IPv4 or IPv6 address string. Normalized before comparison. */
22
22
  readonly value: string;
23
23
  }
24
- /** URI-ID reference identifier (RFC 6125 §6.5). Scheme and host are matched. */
25
- interface UriServiceIdentityInput {
24
+ /** URI-ID reference identifier (RFC 9525 §§6.2-6.5). Scheme and host are matched. */
25
+ export interface UriServiceIdentityInput {
26
26
  /** Discriminant for URI-ID matching. */
27
27
  readonly type: "uri";
28
28
  /** Full URI whose scheme and reg-name will be compared. */
29
29
  readonly value: string;
30
30
  }
31
31
  /** SRV-ID reference identifier (RFC 4985). */
32
- interface SrvServiceIdentityInput {
32
+ export interface SrvServiceIdentityInput {
33
33
  /** Discriminant for SRV-ID matching. */
34
34
  readonly type: "srv";
35
35
  /** SRV name in `_service.domain` form (e.g. `"_imap.example.com"`). */
36
36
  readonly value: string;
37
37
  }
38
38
  /** Discriminated union of all supported reference identifier types. */
39
- type ServiceIdentityInput = DnsServiceIdentityInput | IpServiceIdentityInput | UriServiceIdentityInput | SrvServiceIdentityInput;
39
+ export type ServiceIdentityInput = DnsServiceIdentityInput | IpServiceIdentityInput | UriServiceIdentityInput | SrvServiceIdentityInput;
40
40
  /** The `type` discriminant values of {@linkcode ServiceIdentityInput}. */
41
- type ServiceIdentityType = ServiceIdentityInput["type"];
41
+ export type ServiceIdentityType = ServiceIdentityInput["type"];
42
42
  /** Discriminant codes for identity-matching failures. */
43
- type MatchServiceIdentityErrorCode = "subject_alt_name_mismatch" | "common_name_fallback_suppressed" | "service_identity_mismatch" | "unsupported_service_identity_type";
43
+ export type MatchServiceIdentityErrorCode = "subject_alt_name_mismatch" | "common_name_fallback_suppressed" | "service_identity_mismatch" | "unsupported_service_identity_type" | DecodeRefusalCode;
44
44
  /** Diagnostic context attached to an identity-matching failure. */
45
- interface MatchServiceIdentityFailureDetails {
45
+ export interface MatchServiceIdentityFailureDetails {
46
46
  /** CN of the certificate that was being matched, if present. */
47
47
  readonly subjectCommonName?: string;
48
48
  /** The reference identifier the caller asked to verify. */
@@ -55,23 +55,23 @@ interface MatchServiceIdentityFailureDetails {
55
55
  readonly commonNameFallbackReason?: "disabled" | "suppressed_by_presented_identifier" | "common_name_missing" | "common_name_mismatch";
56
56
  }
57
57
  /** A failed identity-matching attempt. */
58
- interface MatchServiceIdentityFailure extends Micro509Error<MatchServiceIdentityErrorCode, MatchServiceIdentityFailureDetails> {
58
+ export interface MatchServiceIdentityFailure extends Micro509Error<MatchServiceIdentityErrorCode, MatchServiceIdentityFailureDetails> {
59
59
  /** Always `false` for failures. */
60
60
  readonly ok: false;
61
61
  }
62
62
  /** A successful identity match (the certificate covers the requested name). */
63
- interface MatchServiceIdentitySuccess {
63
+ export interface MatchServiceIdentitySuccess {
64
64
  /** Always `true` for success. */
65
65
  readonly ok: true;
66
66
  /** No payload on success — the match itself is the signal. */
67
67
  readonly value: undefined;
68
68
  }
69
69
  /** Failure branch of {@linkcode MatchServiceIdentityResult} with structured error details. */
70
- type MatchServiceIdentityFailureResult = ErrorResult<MatchServiceIdentityErrorCode, MatchServiceIdentityFailureDetails, MatchServiceIdentityFailure>;
70
+ export type MatchServiceIdentityFailureResult = ErrorResult<MatchServiceIdentityErrorCode, MatchServiceIdentityFailureDetails, MatchServiceIdentityFailure>;
71
71
  /** Result of matching a reference identifier against a certificate's presented identifiers. */
72
- type MatchServiceIdentityResult = MatchServiceIdentitySuccess | MatchServiceIdentityFailureResult;
72
+ export type MatchServiceIdentityResult = MatchServiceIdentitySuccess | MatchServiceIdentityFailureResult;
73
73
  /** Input for {@linkcode matchServiceIdentity}. */
74
- interface MatchServiceIdentityInput {
74
+ export interface MatchServiceIdentityInput {
75
75
  /** The parsed leaf certificate to check. */
76
76
  readonly certificate: ParsedCertificate;
77
77
  /** The reference identifier the client wants to verify. */
@@ -92,7 +92,7 @@ interface MatchServiceIdentityInput {
92
92
  * if (!result.ok) console.error(result.error.message);
93
93
  * ```
94
94
  */
95
- declare function matchServiceIdentity(input: MatchServiceIdentityInput): MatchServiceIdentityResult;
95
+ export declare function matchServiceIdentity(input: MatchServiceIdentityInput): MatchServiceIdentityResult;
96
96
  /**
97
97
  * Compares a reference identifier against a certificate's SAN entries.
98
98
  *
@@ -116,7 +116,5 @@ declare function matchServiceIdentity(input: MatchServiceIdentityInput): MatchSe
116
116
  * });
117
117
  * ```
118
118
  */
119
- declare function matchCertificateServiceIdentity(rawCertificate: ParsedCertificate, serviceIdentity: ServiceIdentityInput): MatchServiceIdentityResult;
120
- //#endregion
121
- export { DnsServiceIdentityInput, IpServiceIdentityInput, MatchServiceIdentityErrorCode, MatchServiceIdentityFailure, MatchServiceIdentityFailureDetails, MatchServiceIdentityFailureResult, MatchServiceIdentityInput, MatchServiceIdentityResult, MatchServiceIdentitySuccess, ServiceIdentityInput, ServiceIdentityType, SrvServiceIdentityInput, UriServiceIdentityInput, matchCertificateServiceIdentity, matchServiceIdentity };
119
+ export declare function matchCertificateServiceIdentity(rawCertificate: ParsedCertificate, serviceIdentity: ServiceIdentityInput): MatchServiceIdentityResult;
122
120
  //# sourceMappingURL=identity.d.ts.map
@@ -1,9 +1,14 @@
1
- import { errorResult as e, micro509Error as t, successResult as n } from "../result/result.js";
2
- import { decodeIpAddress as r, parseIpAddressToBytes as i } from "../internal/shared/ip.js";
3
- import { parseCertificateDerOrThrow as a } from "../x509/parse.js";
4
- //#region src/verify/identity.ts
1
+ import { DECODE_REFUSAL_CODES as e, errorResult as t, micro509Error as n, successResult as r } from "../result/result.js";
2
+ import { decodeRefusalOf as i } from "../internal/asn1/decode-refusal.js";
3
+ import { presentedDomainToAscii as a, referenceDomainToAscii as o } from "../internal/shared/idna.js";
4
+ import { decodeIpAddress as s, parseIpAddressToBytes as c } from "../internal/shared/ip.js";
5
+ import { hostportHost as l, uriAuthorityHost as u } from "../internal/shared/uri-host.js";
6
+ import { parsePresentedSrvName as d } from "../internal/x509/general-name-profile.js";
7
+ import { parseCertificateDerOrThrow as f } from "../x509/parse.js";
8
+ // src/verify/identity.ts
5
9
  /**
6
- * Service-identity matching (RFC 6125 / RFC 9525).
10
+ * Service-identity matching (RFC 9525), with opt-in CN fallback from the
11
+ * obsoleted RFC 6125 §6.4.4.
7
12
  *
8
13
  * Compares a reference identifier (hostname, IP, URI, SRV name) against the
9
14
  * presented identifiers in a certificate's SAN extension, with optional
@@ -52,24 +57,25 @@ function matchServiceIdentity(e) {
52
57
  * });
53
58
  * ```
54
59
  */
55
- function matchCertificateServiceIdentity(e, t) {
56
- let n;
60
+ function matchCertificateServiceIdentity(t, n) {
61
+ let r;
57
62
  try {
58
- n = a(new Uint8Array(e.der));
59
- } catch {
60
- return failure("subject_alt_name_mismatch", "certificate input is malformed");
63
+ r = f(new Uint8Array(t.der));
64
+ } catch (t) {
65
+ let n = i(t, e);
66
+ return n === void 0 ? failure("subject_alt_name_mismatch", "certificate input is malformed") : failure(n.code, n.message);
61
67
  }
62
- switch (t.type) {
63
- case "dns": return matchDnsServiceIdentity(n, t);
64
- case "ip": return matchIpServiceIdentity(n, t);
65
- case "uri": return matchScopedServiceIdentity(n, t, {
68
+ switch (n.type) {
69
+ case "dns": return matchDnsServiceIdentity(r, n);
70
+ case "ip": return matchIpServiceIdentity(r, n);
71
+ case "uri": return matchScopedServiceIdentity(r, n, {
66
72
  parse: tryParseUriServiceIdentity,
67
73
  sanType: "uri",
68
74
  missingMessage: "URI-ID not present in SAN",
69
75
  serviceMismatchMessage: "URI scheme not present in SAN",
70
76
  domainMismatchMessage: "URI host not present in SAN"
71
77
  });
72
- case "srv": return matchScopedServiceIdentity(n, t, {
78
+ case "srv": return matchScopedServiceIdentity(r, n, {
73
79
  parse: tryParseSrvServiceIdentity,
74
80
  sanType: "srv",
75
81
  missingMessage: "SRV-ID not present in SAN",
@@ -102,37 +108,38 @@ function matchIpServiceIdentity(e, t) {
102
108
  return n === void 0 ? malformedServiceIdentityFailure(e, "ip", t.value) : matchParsedIpServiceIdentity(e, n);
103
109
  }
104
110
  function matchParsedIpServiceIdentity(e, t) {
105
- let n = r(t), i = e.subjectAltNames?.filter((e) => e.type === "ip") ?? [], a = [];
106
- for (let o of i) {
107
- let i = tryParsePresentedIpAddress(o.value);
108
- if (i === void 0) return failure("subject_alt_name_mismatch", "IP address SAN is malformed", details(e.subject.values.commonName, n, `ip:${o.value}`));
109
- if (a.push(r(i)), sameIpAddressBytes(i, t)) return success();
111
+ let n = s(t), r = e.subjectAltNames?.filter((e) => e.type === "ip") ?? [], i = [];
112
+ for (let a of r) {
113
+ let r = tryParsePresentedIpAddress(a.value);
114
+ if (r === void 0) return failure("subject_alt_name_mismatch", "IP address SAN is malformed", details(e.subject.values.commonName, n, `ip:${a.value}`));
115
+ if (i.push(s(r)), sameIpAddressBytes(r, t)) return success();
110
116
  }
111
- return failure("subject_alt_name_mismatch", "IP address not present in SAN", details(e.subject.values.commonName, n, a.join(",")));
117
+ return failure("subject_alt_name_mismatch", "IP address not present in SAN", details(e.subject.values.commonName, n, i.join(",")));
112
118
  }
113
119
  function matchScopedServiceIdentity(e, t, n) {
114
120
  if (typeof t.value != "string") return malformedServiceIdentityFailure(e, t.type, t.value);
115
- let r = n.parse(t.value);
121
+ let r = n.parse(t.value, "reference");
116
122
  if (r === void 0) return malformedServiceIdentityFailure(e, t.type, t.value);
117
123
  let i = e.subjectAltNames?.filter((e) => isScopedSubjectAltName(e, n.sanType)) ?? [], a = i.flatMap((e) => {
118
- let t = n.parse(e.value);
124
+ let t = n.parse(e.value, "presented");
119
125
  return t === void 0 || t.serviceType !== r.serviceType ? [] : [t];
120
126
  });
121
- return a.some((e) => matchesDnsName(e.domainName, r.domainName)) ? success() : scopedServiceIdentityFailure(e, r, i, a, n);
127
+ return a.some((e) => matchesServiceHost(e.host, r.host)) ? success() : scopedServiceIdentityFailure(e, r, i, a, n);
122
128
  }
123
129
  function isScopedSubjectAltName(e, t) {
124
130
  return e.type === t;
125
131
  }
126
132
  function scopedServiceIdentityFailure(e, t, n, r, i) {
127
- return r.length > 0 ? failure("subject_alt_name_mismatch", i.domainMismatchMessage, details(e.subject.values.commonName, t.domainName, r.map((e) => e.domainName).join(","))) : n.length > 0 ? failure("service_identity_mismatch", i.serviceMismatchMessage, details(e.subject.values.commonName, t.serviceType, n.flatMap((e) => serviceTypeFromSanValue(e.value, i.parse)).join(","))) : failure("subject_alt_name_mismatch", i.missingMessage, details(e.subject.values.commonName, t.domainName, ""));
133
+ return r.length > 0 ? failure("subject_alt_name_mismatch", i.domainMismatchMessage, details(e.subject.values.commonName, serviceHostText(t.host), r.map((e) => serviceHostText(e.host)).join(","))) : n.length > 0 ? failure("service_identity_mismatch", i.serviceMismatchMessage, details(e.subject.values.commonName, t.serviceType, n.flatMap((e) => serviceTypeFromSanValue(e.value, i.parse)).join(","))) : failure("subject_alt_name_mismatch", i.missingMessage, details(e.subject.values.commonName, serviceHostText(t.host), ""));
128
134
  }
129
135
  function serviceTypeFromSanValue(e, t) {
130
- let n = t(e);
136
+ let n = t(e, "presented");
131
137
  return n === void 0 ? [] : [n.serviceType];
132
138
  }
133
139
  /** Compares a presented DNS identifier (possibly wildcarded) against a reference name. */
134
140
  function matchesDnsName(e, t) {
135
- let n = normalizeDnsPattern(e), r = normalizeDnsName(t);
141
+ let n = normalizeDnsPattern(e), r = tryNormalizeDnsName(t);
142
+ if (r === void 0) return !1;
136
143
  if (!n.includes("*")) return n === r;
137
144
  if (!n.startsWith("*.")) return !1;
138
145
  let i = n.slice(1);
@@ -140,32 +147,28 @@ function matchesDnsName(e, t) {
140
147
  let a = r.slice(0, r.length - i.length);
141
148
  return a.length > 0 && !a.includes(".");
142
149
  }
143
- /** Lowercases a DNS pattern, preserving the `*.` wildcard prefix if present. */
150
+ /**
151
+ * Lowercases the ASCII letters of a presented DNS identifier and nothing else:
152
+ * RFC 9549 §2.3 compares DNS names by a case-insensitive exact match, so no
153
+ * percent-decoding, IPv4 parsing or IDNA mapping applies to what the
154
+ * certificate presents.
155
+ */
144
156
  function normalizeDnsPattern(e) {
145
- return e.startsWith("*.") ? `*.${normalizeDnsName(e.slice(2))}` : normalizeDnsName(e);
157
+ return e.replace(/[A-Z]/g, (e) => e.toLowerCase());
146
158
  }
147
- /** Lowercases and IDNA-normalizes a DNS name via the URL parser. */
148
- function normalizeDnsName(e) {
149
- return tryNormalizeDnsName(e) ?? e.toLowerCase();
150
- }
151
- /** Attempts IDNA normalization via URL constructor. Returns `undefined` for invalid names. */
159
+ /**
160
+ * RFC 9525 §6.3: a reference domain name in A-labels, lowercased. Returns
161
+ * `undefined` for a name with URI delimiters or one that is not valid IDNA2008.
162
+ */
152
163
  function tryNormalizeDnsName(e) {
153
- if (e.length !== 0) {
154
- for (let t of [
155
- "/",
156
- ":",
157
- "?",
158
- "#",
159
- "@",
160
- "[",
161
- "]"
162
- ]) if (e.includes(t)) return;
163
- try {
164
- return new URL(`https://${e}`).hostname.toLowerCase();
165
- } catch {
166
- return;
167
- }
168
- }
164
+ if (!(e.length === 0 || /[/:?#@[\]]/.test(e))) return o(e);
165
+ }
166
+ /** RFC 9525 §6.3 compares domain names and §6.4 compares IP addresses by their octets. */
167
+ function matchesServiceHost(e, t) {
168
+ return e.type === "ip" ? t.type === "ip" && sameIpAddressBytes(e.bytes, t.bytes) : t.type === "dns" && matchesDnsName(e.name, t.name);
169
+ }
170
+ function serviceHostText(e) {
171
+ return e.type === "ip" ? s(e.bytes) : e.name;
169
172
  }
170
173
  /** Returns which SAN types (dns, uri, srv) the certificate presents, used for CN-fallback suppression. */
171
174
  function presentedDnsIdentifierTypes(e) {
@@ -177,57 +180,85 @@ function presentedDnsIdentifierTypes(e) {
177
180
  ]) t.some((t) => t.type === e) && n.push(e);
178
181
  return n;
179
182
  }
180
- /** Attempts to split a URI into scheme + reg-name. @returns `undefined` on failure. */
181
- function tryParseUriServiceIdentity(e) {
182
- let t = e.indexOf(":");
183
- if (t <= 0) return;
184
- let n = e.slice(0, t).toLowerCase(), r = extractUriRegName(e);
185
- if (r !== void 0) return {
186
- serviceType: n,
187
- domainName: normalizeDnsName(r)
183
+ /** RFC 9525 §6.2: a URI-ID's scheme and the host of its authority, or of a SIP URI. */
184
+ function tryParseUriServiceIdentity(e, t) {
185
+ let n = e.indexOf(":");
186
+ if (n <= 0 || !/^[A-Za-z][A-Za-z0-9+.-]*$/.test(e.slice(0, n))) return;
187
+ let r = e.slice(0, n).toLowerCase(), i = r === "sip" || r === "sips", a = uriServiceHost(i ? sipUriHost(e.slice(n + 1), t) : u(e, t), t === "presented" && !i);
188
+ return a === void 0 ? void 0 : {
189
+ serviceType: r,
190
+ host: a
188
191
  };
189
192
  }
190
- /** Extracts the reg-name host from a URI, stripping scheme, userinfo, port, and path components. */
191
- function extractUriRegName(e) {
192
- let t = e.indexOf(":");
193
- if (t <= 0) return;
194
- let n = e.slice(t + 1), r = cutAtFirstDelimiter(n.startsWith("//") ? n.slice(2) : n, [
195
- "/",
196
- "?",
197
- "#"
198
- ]), i = r.lastIndexOf("@");
199
- if (i >= 0 && (r = r.slice(i + 1)), r.startsWith("[")) return;
200
- let a = cutAtFirstDelimiter(r, [":", ";"]);
201
- if (!(a.length === 0 || a.includes("[") || a.includes("]"))) return a;
193
+ /** RFC 3261 §25.1 userinfo without its "@": a non-empty user and an optional password. */
194
+ const p = /^(?:[A-Za-z0-9\-_.!~*'()&=+$,;?/]|%[0-9A-Fa-f]{2})+(?::(?:[A-Za-z0-9\-_.!~*'()&=+$,]|%[0-9A-Fa-f]{2})*)?$/, m = /^(?:;(?:[A-Za-z0-9\-_.!~*'()[\]/:&+$]|%[0-9A-Fa-f]{2})+(?:=(?:[A-Za-z0-9\-_.!~*'()[\]/:&+$]|%[0-9A-Fa-f]{2})+)?)*$/, h = /^(?:\?(?:[A-Za-z0-9\-_.!~*'()[\]/?:+$]|%[0-9A-Fa-f]{2})+=(?:[A-Za-z0-9\-_.!~*'()[\]/?:+$]|%[0-9A-Fa-f]{2})*(?:&(?:[A-Za-z0-9\-_.!~*'()[\]/?:+$]|%[0-9A-Fa-f]{2})+=(?:[A-Za-z0-9\-_.!~*'()[\]/?:+$]|%[0-9A-Fa-f]{2})*)*)?$/, g = /^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*[a-z](?:[a-z0-9-]*[a-z0-9])?$/i;
195
+ /**
196
+ * RFC 3261 §25.1: the only "@" a SIP URI may hold ends its userinfo, and its
197
+ * hostport is a hostname or IP address with no escaped octets and a port of at
198
+ * least one digit. The uri-parameters and headers after it follow their
199
+ * grammar, with every "%" opening an escaped octet (§19.1.2), and no parameter
200
+ * name appears twice (§19.1.1). RFC 5922 §7.1 forbids accepting a presented
201
+ * SIP URI with a userpart as a SIP domain identity.
202
+ */
203
+ function sipUriHost(e, t) {
204
+ let n = e.indexOf("@"), r = e.slice(n + 1), i = r.split(/[;?]/, 1)[0] ?? "", a = r.slice(i.length), o = a.includes("?") ? a.indexOf("?") : a.length, s = a.slice(0, o);
205
+ if (n >= 0 && t === "presented" || n >= 0 && !p.test(e.slice(0, n)) || !m.test(s) || !h.test(a.slice(o)) || hasRepeatedParameter(s) || i.includes("%") || i.endsWith(":")) return { type: "invalid" };
206
+ let c = l(i, t);
207
+ return c.type === "ip" || c.type === "dns" && g.test(c.name) ? c : { type: "invalid" };
208
+ }
209
+ /** RFC 3261 §19.1.4 compares parameter names without regard to case. */
210
+ function hasRepeatedParameter(e) {
211
+ let t = e.split(";").slice(1).map((e) => (e.split("=", 1)[0] ?? "").toLowerCase());
212
+ return new Set(t).size !== t.length;
202
213
  }
203
- /** Returns the substring before the first occurrence of any delimiter character. */
204
- function cutAtFirstDelimiter(e, t) {
205
- let n = e.length;
206
- for (let r of t) {
207
- let t = e.indexOf(r);
208
- t >= 0 && t < n && (n = t);
214
+ /**
215
+ * RFC 9525 §6.3: a presented wildcard is the whole left-most label of the
216
+ * domain name. RFC 5922 §7.2 prohibits wildcards for SIP domains.
217
+ */
218
+ function uriServiceHost(e, t) {
219
+ switch (e.type) {
220
+ case "dns":
221
+ case "ip": return e;
222
+ case "regName": {
223
+ let n = t && e.value.startsWith("*.") ? a(e.value.slice(2)) : void 0;
224
+ return n === void 0 ? void 0 : {
225
+ type: "dns",
226
+ name: `*.${n}`
227
+ };
228
+ }
229
+ case "absent":
230
+ case "invalid": return;
231
+ default: throw Error(`Unhandled UriHost type: ${String(e)}`);
209
232
  }
210
- return e.slice(0, n);
211
233
  }
212
- /** Attempts to split `_service.domain` into parts. @returns `undefined` on failure. */
213
- function tryParseSrvServiceIdentity(e) {
234
+ /**
235
+ * RFC 4985 §2 `_Service.Name`. RFC 9525 §6.3 lets a presented Name open with
236
+ * a `*` label.
237
+ */
238
+ function tryParseSrvServiceIdentity(e, t) {
214
239
  if (!e.startsWith("_")) return;
215
- let t = e.indexOf(".");
216
- if (!(t <= 1 || t === e.length - 1)) return {
217
- serviceType: e.slice(1, t).toLowerCase(),
218
- domainName: normalizeDnsName(e.slice(t + 1))
240
+ let n = e.indexOf(".");
241
+ if (n <= 1 || n === e.length - 1) return;
242
+ let r = e.slice(n + 1), i = t === "presented" && r.startsWith("*."), a = tryNormalizeDnsName(i ? r.slice(2) : r), o = a === void 0 ? void 0 : d(`${e.slice(0, n).toLowerCase()}.${a}`);
243
+ return o === void 0 ? void 0 : {
244
+ serviceType: o.service.slice(1),
245
+ host: {
246
+ type: "dns",
247
+ name: i ? `*.${o.name}` : o.name
248
+ }
219
249
  };
220
250
  }
221
251
  /** Constructs a failure result with the given error code and diagnostic details. */
222
- function failure(n, r, i) {
223
- return e({
252
+ function failure(e, r, i) {
253
+ let a = {
224
254
  ok: !1,
225
- ...t(n, r, i)
226
- });
255
+ ...n(e, r, i)
256
+ };
257
+ return t(a);
227
258
  }
228
259
  /** Constructs a success result indicating the identity matched. */
229
260
  function success() {
230
- return n(void 0);
261
+ return r(void 0);
231
262
  }
232
263
  function malformedServiceIdentityFailure(e, t, n) {
233
264
  let r = typeof n == "string" ? n : "<malformed>";
@@ -235,7 +266,7 @@ function malformedServiceIdentityFailure(e, t, n) {
235
266
  }
236
267
  function tryParsePresentedIpAddress(e) {
237
268
  try {
238
- return i(e);
269
+ return c(e);
239
270
  } catch {
240
271
  return;
241
272
  }
@@ -255,7 +286,6 @@ function details(e, t, n, r) {
255
286
  ...r?.commonNameFallbackReason === void 0 ? {} : { commonNameFallbackReason: r.commonNameFallbackReason }
256
287
  };
257
288
  }
258
- //#endregion
259
289
  export { matchCertificateServiceIdentity, matchServiceIdentity };
260
290
 
261
291
  //# sourceMappingURL=identity.js.map