micro509 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/internal/asn1/oids.js +1 -1
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/verify/name-constraints-engine.js +1 -1
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/revocation/chain.d.ts +22 -1
- package/dist/revocation/chain.js +1 -1
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +44 -6
- package/dist/revocation/ocsp.js +1 -1
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +3 -3
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +2 -2
- package/dist/revocation.js +1 -1
- package/dist/verify/identity.d.ts +2 -2
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/verify.d.ts +2 -0
- package/dist/verify/verify.js +1 -1
- package/dist/verify/verify.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -177,12 +177,12 @@ It intentionally excludes niche, blockchain-specific, or key-agreement-only prim
|
|
|
177
177
|
|
|
178
178
|
## Standards status
|
|
179
179
|
|
|
180
|
-
| Area | Status
|
|
181
|
-
| -------------------------- |
|
|
182
|
-
| RFC 5280 path validation |
|
|
183
|
-
| RFC 6960 OCSP |
|
|
184
|
-
| RFC 6125 service identity |
|
|
185
|
-
| RFC 9618 policy validation |
|
|
180
|
+
| Area | Status |
|
|
181
|
+
| -------------------------- | -------- |
|
|
182
|
+
| RFC 5280 path validation | complete |
|
|
183
|
+
| RFC 6960 OCSP | complete |
|
|
184
|
+
| RFC 6125 service identity | complete |
|
|
185
|
+
| RFC 9618 policy validation | complete |
|
|
186
186
|
|
|
187
187
|
See [`docs/PKIX-SCOPE.md`](./docs/PKIX-SCOPE.md) for the detailed scope boundary
|
|
188
188
|
and the [API reference](https://micro509.kjanat.dev/api/) for the public module surface.
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { DecodedExtensionMap, DecodedExtensionValue, ExtensionDecoder, Extension
|
|
|
9
9
|
import { CreatePfxErrorCode, CreatePfxFailure, CreatePfxInput, CreatePfxResult, ParsePfxErrorCode, ParsePfxFailure, ParsePfxOptions, ParsePfxResult, ParsedPfx, ParsedPfxAttribute, ParsedPfxBag, ParsedPfxBagAttributes, PfxBagAttributesInput, PfxCertificateBagInput, PfxCertificateSource, PfxEncryptionOptions, PfxMaterial, PfxPrivateKeyBagInput, PfxPrivateKeySource, createPfx, parsePfxDer, parsePfxPem } from "./pkcs/pfx.js";
|
|
10
10
|
import { CreatePkcs7CertBagDerResult, CreatePkcs7CertBagErrorCode, CreatePkcs7CertBagFailure, CreatePkcs7CertBagResult, CreatePkcs7SignedDataDerResult, CreatePkcs7SignedDataErrorCode, CreatePkcs7SignedDataFailure, CreatePkcs7SignedDataInput, CreatePkcs7SignedDataResult, ParsePkcs7CertBagResult, ParsePkcs7ErrorCode, ParsePkcs7Failure, ParsePkcs7SignedDataResult, ParsedPkcs7SignedData, ParsedPkcs7SignerInfo, Pkcs7CertBag, Pkcs7CertificateSource, Pkcs7SignedDataMaterial, Pkcs7Signer, VerifyPkcs7SignedDataFailure, VerifyPkcs7SignedDataResult, createPkcs7CertBagDer, createPkcs7CertBagPem, createPkcs7SignedDataDer, createPkcs7SignedDataPem, parsePkcs7CertBagDer, parsePkcs7CertBagPem, parsePkcs7SignedDataDer, parsePkcs7SignedDataPem, verifyPkcs7SignedData } from "./pkcs/pkcs7.js";
|
|
11
11
|
import { CertificateRevocationListMaterial, CheckCertificateRevocationAgainstCrlInput, CheckCertificateRevocationAgainstCrlResult, CreateCertificateRevocationListInput, CrlCertificateSource, CrlSource, ParsedCertificateRevocationList, ParsedRevokedCertificate, RevocationReason, RevokedCertificateInput, ValidateCertificateRevocationListFailure, ValidateCertificateRevocationListInput, ValidateCertificateRevocationListResult, VerifyCertificateRevocationListFailure, VerifyCertificateRevocationListResult, checkCertificateRevocationAgainstCrl, createCertificateRevocationList, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListPem, validateCertificateRevocationList, verifyCertificateRevocationList } from "./revocation/crl.js";
|
|
12
|
-
import { CreateOcspRequestInput, CreateOcspRequestItemInput, CreateOcspResponseInput, CreateOcspSingleResponseInput, OcspCertStatus, OcspCertificateSource, OcspRequestMaterial, OcspRequestSource, OcspResponseMaterial, ParsedOcspCertId, ParsedOcspRequest, ParsedOcspResponderId, ParsedOcspResponse, ParsedOcspSingleResponse, ValidateOcspResponseFailure, ValidateOcspResponseInput, ValidateOcspResponseResult, VerifyOcspResponseFailure, VerifyOcspResponseResult, createOcspRequest, createOcspResponse, parseOcspRequestDer, parseOcspRequestPem, parseOcspResponseDer, parseOcspResponsePem, validateOcspResponse, verifyOcspResponse } from "./revocation/ocsp.js";
|
|
12
|
+
import { CreateOcspRequestInput, CreateOcspRequestItemInput, CreateOcspResponseInput, CreateOcspSingleResponseInput, OcspCertStatus, OcspCertificateSource, OcspRequestMaterial, OcspRequestSource, OcspResponseMaterial, ParsedOcspCertId, ParsedOcspRequest, ParsedOcspResponderId, ParsedOcspResponse, ParsedOcspSingleResponse, ValidateOcspResponseFailure, ValidateOcspResponseInput, ValidateOcspResponseResult, VerifyOcspResponseFailure, VerifyOcspResponseResult, createOcspRequest, createOcspResponse, hasOcspNoCheckExtension, parseOcspRequestDer, parseOcspRequestPem, parseOcspResponseDer, parseOcspResponsePem, validateOcspResponse, verifyOcspResponse } from "./revocation/ocsp.js";
|
|
13
13
|
import { CheckCertificateRevocationInput, CheckCertificateRevocationResult, ConfiguredOcspResponder, OcspResponderCandidate, OcspResponderSource, ResolveOcspResponderCandidatesInput, RevocationCertificateSource, RevocationCrlEvidenceInput, RevocationEvidenceInput, RevocationEvidenceKind, RevocationOcspEvidenceInput, RevocationStatus, checkCertificateRevocation, getCertificateOcspResponderUris, resolveOcspResponderCandidates } from "./revocation/revocation.js";
|
|
14
14
|
import { CertificateRevocationStatus, CheckChainRevocationInput, CheckChainRevocationResult, CheckChainRevocationValue, RevocationExecutionError, RevocationIndeterminateReason, RevocationPolicy, RevocationSource, checkChainRevocation } from "./revocation/chain.js";
|
|
15
15
|
import { DnsServiceIdentityInput, IpServiceIdentityInput, MatchServiceIdentityErrorCode, MatchServiceIdentityFailure, MatchServiceIdentityInput, MatchServiceIdentityResult, MatchServiceIdentitySuccess, ServiceIdentityInput, ServiceIdentityType, SrvServiceIdentityInput, UriServiceIdentityInput, VerifyServiceIdentityInput, matchCertificateServiceIdentity, matchServiceIdentity } from "./verify/identity.js";
|
|
@@ -18,4 +18,4 @@ import { PolicyValidationInput } from "./verify/policy.js";
|
|
|
18
18
|
import { BuildCandidatePathInput, BuildCandidatePathResult, CandidatePath, CertificateSource, ChainRevocationInput, CsrSource, EkuCheckFailure, EkuCheckPurpose, EkuCheckResult, TrustAnchor, VERIFY_ERROR_CODES, ValidateCandidatePathInput, ValidateCandidatePathResult, ValidateCandidatePathSuccess, ValidateForCaInput, ValidateForCodeSigningInput, ValidateForTlsClientInput, ValidateForTlsServerInput, VerifiedCertificateChain, VerifyCertificateChainInput, VerifyChainFailure, VerifyChainResult, VerifyErrorCode, VerifyFailureDetails, VerifyPurpose, VerifyRequestFailure, VerifyRequestResult, buildCandidatePath, checkExtendedKeyUsage, trustAnchorFromCertificate, validateCandidatePath, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, verifyCertificateChain, verifyCertificateSigningRequest } from "./verify/verify.js";
|
|
19
19
|
import { CertificateMaterial, CreateCertificateInput, CreateSelfSignedCertificateInput, SelfSignedCertificateResult, ValidityInput, createCertificate, createSelfSignedCertificate } from "./x509/certificate.js";
|
|
20
20
|
import { CreateCsrInput, CsrMaterial, createCertificateSigningRequest } from "./x509/csr.js";
|
|
21
|
-
export { type AuthorityInformationAccess, type BasicConstraints, type BuildCandidatePathInput, type BuildCandidatePathResult, type CandidatePath, type CategorizedPemBlocks, type CertificateExtensionsInput, type CertificateMaterial, type CertificatePolicies, type CertificateRevocationListMaterial, type CertificateRevocationStatus, type CertificateSource, type ChainRevocationInput, type CheckCertificateRevocationAgainstCrlInput, type CheckCertificateRevocationAgainstCrlResult, type CheckCertificateRevocationInput, type CheckCertificateRevocationResult, type CheckChainRevocationInput, type CheckChainRevocationResult, type CheckChainRevocationValue, type ConfiguredOcspResponder, type CreateCertificateInput, type CreateCertificateRevocationListInput, type CreateCsrInput, type CreateOcspRequestInput, type CreateOcspRequestItemInput, type CreateOcspResponseInput, type CreateOcspSingleResponseInput, type CreatePfxErrorCode, type CreatePfxFailure, type CreatePfxInput, type CreatePfxResult, type CreatePkcs7CertBagDerResult, type CreatePkcs7CertBagErrorCode, type CreatePkcs7CertBagFailure, type CreatePkcs7CertBagResult, type CreatePkcs7SignedDataDerResult, type CreatePkcs7SignedDataErrorCode, type CreatePkcs7SignedDataFailure, type CreatePkcs7SignedDataInput, type CreatePkcs7SignedDataResult, type CreateSelfSignedCertificateInput, type CrlCertificateSource, type CrlSource, type CsrMaterial, type CsrSource, type DecodedExtensionMap, type DecodedExtensionValue, type DistributionPoint, type DistributionPointName, type DnsServiceIdentityInput, type EcKeyAlgorithmInput, type EcNamedCurve, type Ed25519KeyAlgorithmInput, type EkuCheckFailure, type EkuCheckPurpose, type EkuCheckResult, type EncryptedPkcs8Options, type ErrorResult, type ExtendedKeyUsage, type ExtensionDecoder, type ExtensionDecoderMap, type GeneralName, type GeneralSubtree, type ImportEcPublicKeyInput, type ImportEd25519PublicKeyInput, type ImportEncryptedKeyErrorCode, type ImportEncryptedKeyFailure, type ImportEncryptedKeyResult, type ImportKeyErrorCode, type ImportKeyFailure, type ImportKeyResult, type ImportRsaPublicKeyInput, type IndexedErrorResult, type IndexedMicro509Error, type InhibitAnyPolicy, type InitialNameConstraintsInput, type IpServiceIdentityInput, type IssuingDistributionPoint, type KeyAlgorithmInput, type KeyPairMaterial, type KeyUsage, type LegacyPemEncryptionOptions, type MatchServiceIdentityErrorCode, type MatchServiceIdentityFailure, type MatchServiceIdentityInput, type MatchServiceIdentityResult, type MatchServiceIdentitySuccess, type Micro509Error, type NameAttribute, type NameConstraintForm, type NameConstraints, type NameFieldKey, type NameInput, type NameObject, type OcspCertStatus, type OcspCertificateSource, type OcspRequestMaterial, type OcspRequestSource, type OcspResponderCandidate, type OcspResponderSource, type OcspResponseMaterial, type ParseCertificateErrorCode, type ParseCertificateFailure, type ParseCertificateResult, type ParseCertificateSigningRequestErrorCode, type ParseCertificateSigningRequestFailure, type ParseCertificateSigningRequestResult, type ParseOptions, type ParsePfxErrorCode, type ParsePfxFailure, type ParsePfxOptions, type ParsePfxResult, type ParsePkcs7CertBagResult, type ParsePkcs7ErrorCode, type ParsePkcs7Failure, type ParsePkcs7SignedDataResult, type ParsedBitFlags, type ParsedCertificate, type ParsedCertificateRevocationList, type ParsedCertificateSigningRequest, type ParsedDistributionPoint, type ParsedDistributionPointName, type ParsedExtension, type ParsedIssuingDistributionPoint, type ParsedName, type ParsedNameAttribute, type ParsedNameConstraintForm, type ParsedOcspCertId, type ParsedOcspRequest, type ParsedOcspResponderId, type ParsedOcspResponse, type ParsedOcspSingleResponse, type ParsedPfx, type ParsedPfxAttribute, type ParsedPfxBag, type ParsedPfxBagAttributes, type ParsedPkcs7SignedData, type ParsedPkcs7SignerInfo, type ParsedRelativeDistinguishedName, type ParsedRevokedCertificate, type Pbes2EncryptionOptions, type Pbes2EncryptionScheme, type Pbes2Prf, type PemBlock, type PfxBagAttributesInput, type PfxCertificateBagInput, type PfxCertificateSource, type PfxEncryptionOptions, type PfxMaterial, type PfxPrivateKeyBagInput, type PfxPrivateKeySource, type Pkcs7CertBag, type Pkcs7CertificateSource, type Pkcs7SignedDataMaterial, type Pkcs7Signer, type PolicyConstraints, type PolicyInformation, type PolicyMapping, type PolicyMappings, type PolicyQualifierInfo, type PolicyValidationInput, type PrivateKeyImportInput, type PublicKeyImportInput, type RelativeDistinguishedNameInput, type ResolveOcspResponderCandidatesInput, type Result, type ResultError, type RevocationCertificateSource, type RevocationCrlEvidenceInput, type RevocationEvidenceInput, type RevocationEvidenceKind, type RevocationExecutionError, type RevocationIndeterminateReason, type RevocationOcspEvidenceInput, type RevocationPolicy, type RevocationReason, type RevocationSource, type RevocationStatus, type RevokedCertificateInput, type RsaHash, type RsaKeyAlgorithmInput, type RsaScheme, type SelfSignedCertificateResult, type ServiceIdentityInput, type ServiceIdentityType, type SrvServiceIdentityInput, type SubjectAltName, type TrustAnchor, type UriServiceIdentityInput, VERIFY_ERROR_CODES, type ValidateCandidatePathInput, type ValidateCandidatePathResult, type ValidateCandidatePathSuccess, type ValidateCertificateRevocationListFailure, type ValidateCertificateRevocationListInput, type ValidateCertificateRevocationListResult, type ValidateForCaInput, type ValidateForCodeSigningInput, type ValidateForTlsClientInput, type ValidateForTlsServerInput, type ValidateOcspResponseFailure, type ValidateOcspResponseInput, type ValidateOcspResponseResult, type ValidityInput, type VerifiedCertificateChain, type VerifyCertificateChainInput, type VerifyCertificateRevocationListFailure, type VerifyCertificateRevocationListResult, type VerifyChainFailure, type VerifyChainResult, type VerifyErrorCode, type VerifyFailureDetails, type VerifyOcspResponseFailure, type VerifyOcspResponseResult, type VerifyPkcs7SignedDataFailure, type VerifyPkcs7SignedDataResult, type VerifyPurpose, type VerifyRequestFailure, type VerifyRequestResult, type VerifyServiceIdentityInput, buildCandidatePath, categorizePemBlocks, checkCertificateRevocation, checkCertificateRevocationAgainstCrl, checkChainRevocation, checkExtendedKeyUsage, createCertificate, createCertificateRevocationList, createCertificateSigningRequest, createOcspRequest, createOcspResponse, createPfx, createPkcs7CertBagDer, createPkcs7CertBagPem, createPkcs7SignedDataDer, createPkcs7SignedDataPem, createSelfSignedCertificate, decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, findExtension, generateKeyPair, getCertificateOcspResponderUris, importEncryptedPkcs1Pem, importEncryptedPkcs8Der, importEncryptedPkcs8Pem, importEncryptedSec1Pem, importPkcs1Der, importPkcs1Pem, importPkcs8Base64, importPkcs8Der, importPkcs8Pem, importPrivateJwk, importPublicJwk, importSec1Der, importSec1Pem, importSpkiBase64, importSpkiDer, importSpkiPem, isCertificateRevoked, isResultError, matchCertificateServiceIdentity, matchServiceIdentity, parseCertificateChainPem, parseCertificateDer, parseCertificatePem, parseCertificateRevocationListDer, parseCertificateRevocationListPem, parseCertificateSigningRequestDer, parseCertificateSigningRequestPem, parseOcspRequestDer, parseOcspRequestPem, parseOcspResponseDer, parseOcspResponsePem, parsePfxDer, parsePfxPem, parsePkcs7CertBagDer, parsePkcs7CertBagPem, parsePkcs7SignedDataDer, parsePkcs7SignedDataPem, pemDecode, pemEncode, resolveOcspResponderCandidates, splitPemBlocks, trustAnchorFromCertificate, unwrap, unwrapOr, validateCandidatePath, validateCertificateRevocationList, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, validateOcspResponse, verifyCertificateChain, verifyCertificateRevocationList, verifyCertificateSigningRequest, verifyOcspResponse, verifyPkcs7SignedData };
|
|
21
|
+
export { type AuthorityInformationAccess, type BasicConstraints, type BuildCandidatePathInput, type BuildCandidatePathResult, type CandidatePath, type CategorizedPemBlocks, type CertificateExtensionsInput, type CertificateMaterial, type CertificatePolicies, type CertificateRevocationListMaterial, type CertificateRevocationStatus, type CertificateSource, type ChainRevocationInput, type CheckCertificateRevocationAgainstCrlInput, type CheckCertificateRevocationAgainstCrlResult, type CheckCertificateRevocationInput, type CheckCertificateRevocationResult, type CheckChainRevocationInput, type CheckChainRevocationResult, type CheckChainRevocationValue, type ConfiguredOcspResponder, type CreateCertificateInput, type CreateCertificateRevocationListInput, type CreateCsrInput, type CreateOcspRequestInput, type CreateOcspRequestItemInput, type CreateOcspResponseInput, type CreateOcspSingleResponseInput, type CreatePfxErrorCode, type CreatePfxFailure, type CreatePfxInput, type CreatePfxResult, type CreatePkcs7CertBagDerResult, type CreatePkcs7CertBagErrorCode, type CreatePkcs7CertBagFailure, type CreatePkcs7CertBagResult, type CreatePkcs7SignedDataDerResult, type CreatePkcs7SignedDataErrorCode, type CreatePkcs7SignedDataFailure, type CreatePkcs7SignedDataInput, type CreatePkcs7SignedDataResult, type CreateSelfSignedCertificateInput, type CrlCertificateSource, type CrlSource, type CsrMaterial, type CsrSource, type DecodedExtensionMap, type DecodedExtensionValue, type DistributionPoint, type DistributionPointName, type DnsServiceIdentityInput, type EcKeyAlgorithmInput, type EcNamedCurve, type Ed25519KeyAlgorithmInput, type EkuCheckFailure, type EkuCheckPurpose, type EkuCheckResult, type EncryptedPkcs8Options, type ErrorResult, type ExtendedKeyUsage, type ExtensionDecoder, type ExtensionDecoderMap, type GeneralName, type GeneralSubtree, type ImportEcPublicKeyInput, type ImportEd25519PublicKeyInput, type ImportEncryptedKeyErrorCode, type ImportEncryptedKeyFailure, type ImportEncryptedKeyResult, type ImportKeyErrorCode, type ImportKeyFailure, type ImportKeyResult, type ImportRsaPublicKeyInput, type IndexedErrorResult, type IndexedMicro509Error, type InhibitAnyPolicy, type InitialNameConstraintsInput, type IpServiceIdentityInput, type IssuingDistributionPoint, type KeyAlgorithmInput, type KeyPairMaterial, type KeyUsage, type LegacyPemEncryptionOptions, type MatchServiceIdentityErrorCode, type MatchServiceIdentityFailure, type MatchServiceIdentityInput, type MatchServiceIdentityResult, type MatchServiceIdentitySuccess, type Micro509Error, type NameAttribute, type NameConstraintForm, type NameConstraints, type NameFieldKey, type NameInput, type NameObject, type OcspCertStatus, type OcspCertificateSource, type OcspRequestMaterial, type OcspRequestSource, type OcspResponderCandidate, type OcspResponderSource, type OcspResponseMaterial, type ParseCertificateErrorCode, type ParseCertificateFailure, type ParseCertificateResult, type ParseCertificateSigningRequestErrorCode, type ParseCertificateSigningRequestFailure, type ParseCertificateSigningRequestResult, type ParseOptions, type ParsePfxErrorCode, type ParsePfxFailure, type ParsePfxOptions, type ParsePfxResult, type ParsePkcs7CertBagResult, type ParsePkcs7ErrorCode, type ParsePkcs7Failure, type ParsePkcs7SignedDataResult, type ParsedBitFlags, type ParsedCertificate, type ParsedCertificateRevocationList, type ParsedCertificateSigningRequest, type ParsedDistributionPoint, type ParsedDistributionPointName, type ParsedExtension, type ParsedIssuingDistributionPoint, type ParsedName, type ParsedNameAttribute, type ParsedNameConstraintForm, type ParsedOcspCertId, type ParsedOcspRequest, type ParsedOcspResponderId, type ParsedOcspResponse, type ParsedOcspSingleResponse, type ParsedPfx, type ParsedPfxAttribute, type ParsedPfxBag, type ParsedPfxBagAttributes, type ParsedPkcs7SignedData, type ParsedPkcs7SignerInfo, type ParsedRelativeDistinguishedName, type ParsedRevokedCertificate, type Pbes2EncryptionOptions, type Pbes2EncryptionScheme, type Pbes2Prf, type PemBlock, type PfxBagAttributesInput, type PfxCertificateBagInput, type PfxCertificateSource, type PfxEncryptionOptions, type PfxMaterial, type PfxPrivateKeyBagInput, type PfxPrivateKeySource, type Pkcs7CertBag, type Pkcs7CertificateSource, type Pkcs7SignedDataMaterial, type Pkcs7Signer, type PolicyConstraints, type PolicyInformation, type PolicyMapping, type PolicyMappings, type PolicyQualifierInfo, type PolicyValidationInput, type PrivateKeyImportInput, type PublicKeyImportInput, type RelativeDistinguishedNameInput, type ResolveOcspResponderCandidatesInput, type Result, type ResultError, type RevocationCertificateSource, type RevocationCrlEvidenceInput, type RevocationEvidenceInput, type RevocationEvidenceKind, type RevocationExecutionError, type RevocationIndeterminateReason, type RevocationOcspEvidenceInput, type RevocationPolicy, type RevocationReason, type RevocationSource, type RevocationStatus, type RevokedCertificateInput, type RsaHash, type RsaKeyAlgorithmInput, type RsaScheme, type SelfSignedCertificateResult, type ServiceIdentityInput, type ServiceIdentityType, type SrvServiceIdentityInput, type SubjectAltName, type TrustAnchor, type UriServiceIdentityInput, VERIFY_ERROR_CODES, type ValidateCandidatePathInput, type ValidateCandidatePathResult, type ValidateCandidatePathSuccess, type ValidateCertificateRevocationListFailure, type ValidateCertificateRevocationListInput, type ValidateCertificateRevocationListResult, type ValidateForCaInput, type ValidateForCodeSigningInput, type ValidateForTlsClientInput, type ValidateForTlsServerInput, type ValidateOcspResponseFailure, type ValidateOcspResponseInput, type ValidateOcspResponseResult, type ValidityInput, type VerifiedCertificateChain, type VerifyCertificateChainInput, type VerifyCertificateRevocationListFailure, type VerifyCertificateRevocationListResult, type VerifyChainFailure, type VerifyChainResult, type VerifyErrorCode, type VerifyFailureDetails, type VerifyOcspResponseFailure, type VerifyOcspResponseResult, type VerifyPkcs7SignedDataFailure, type VerifyPkcs7SignedDataResult, type VerifyPurpose, type VerifyRequestFailure, type VerifyRequestResult, type VerifyServiceIdentityInput, buildCandidatePath, categorizePemBlocks, checkCertificateRevocation, checkCertificateRevocationAgainstCrl, checkChainRevocation, checkExtendedKeyUsage, createCertificate, createCertificateRevocationList, createCertificateSigningRequest, createOcspRequest, createOcspResponse, createPfx, createPkcs7CertBagDer, createPkcs7CertBagPem, createPkcs7SignedDataDer, createPkcs7SignedDataPem, createSelfSignedCertificate, decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, findExtension, generateKeyPair, getCertificateOcspResponderUris, hasOcspNoCheckExtension, importEncryptedPkcs1Pem, importEncryptedPkcs8Der, importEncryptedPkcs8Pem, importEncryptedSec1Pem, importPkcs1Der, importPkcs1Pem, importPkcs8Base64, importPkcs8Der, importPkcs8Pem, importPrivateJwk, importPublicJwk, importSec1Der, importSec1Pem, importSpkiBase64, importSpkiDer, importSpkiPem, isCertificateRevoked, isResultError, matchCertificateServiceIdentity, matchServiceIdentity, parseCertificateChainPem, parseCertificateDer, parseCertificatePem, parseCertificateRevocationListDer, parseCertificateRevocationListPem, parseCertificateSigningRequestDer, parseCertificateSigningRequestPem, parseOcspRequestDer, parseOcspRequestPem, parseOcspResponseDer, parseOcspResponsePem, parsePfxDer, parsePfxPem, parsePkcs7CertBagDer, parsePkcs7CertBagPem, parsePkcs7SignedDataDer, parsePkcs7SignedDataPem, pemDecode, pemEncode, resolveOcspResponderCandidates, splitPemBlocks, trustAnchorFromCertificate, unwrap, unwrapOr, validateCandidatePath, validateCertificateRevocationList, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, validateOcspResponse, verifyCertificateChain, verifyCertificateRevocationList, verifyCertificateSigningRequest, verifyOcspResponse, verifyPkcs7SignedData };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{categorizePemBlocks as e,pemDecode as t,pemEncode as n,splitPemBlocks as r}from"./pem/pem.js";import{isResultError as i,unwrap as a,unwrapOr as o}from"./result/result.js";import{exportBinaryBase64 as s,exportEncryptedPkcs1Pem as c,exportEncryptedPkcs8Der as l,exportEncryptedPkcs8Pem as u,exportEncryptedSec1Pem as d,exportPkcs1Der as f,exportPkcs1Pem as p,exportPkcs8Der as m,exportPkcs8Pem as h,exportPrivateJwk as g,exportPublicJwk as _,exportSec1Der as v,exportSec1Pem as y,exportSpkiDer as b,exportSpkiPem as x,generateKeyPair as S,importEncryptedPkcs1Pem as C,importEncryptedPkcs8Der as w,importEncryptedPkcs8Pem as T,importEncryptedSec1Pem as E,importPkcs1Der as D,importPkcs1Pem as O,importPkcs8Base64 as k,importPkcs8Der as A,importPkcs8Pem as j,importPrivateJwk as M,importPublicJwk as N,importSec1Der as P,importSec1Pem as F,importSpkiBase64 as I,importSpkiDer as L,importSpkiPem as R}from"./keys/keys.js";import{decodeExtension as z,decodeExtensionMap as B,decodeExtensions as V,defineExtensionDecoder as H,defineExtensionDecoderMap as U,findExtension as W,parseCertificateChainPem as G,parseCertificateDer as K,parseCertificatePem as q,parseCertificateSigningRequestDer as J,parseCertificateSigningRequestPem as Y}from"./x509/parse.js";import{createPfx as X,parsePfxDer as Z,parsePfxPem as Q}from"./pkcs/pfx.js";import{createPkcs7CertBagDer as $,createPkcs7CertBagPem as ee,createPkcs7SignedDataDer as te,createPkcs7SignedDataPem as ne,parsePkcs7CertBagDer as re,parsePkcs7CertBagPem as ie,parsePkcs7SignedDataDer as ae,parsePkcs7SignedDataPem as oe,verifyPkcs7SignedData as se}from"./pkcs/pkcs7.js";import{checkCertificateRevocationAgainstCrl as ce,createCertificateRevocationList as le,isCertificateRevoked as ue,parseCertificateRevocationListDer as de,parseCertificateRevocationListPem as fe,validateCertificateRevocationList as pe,verifyCertificateRevocationList as me}from"./revocation/crl.js";import{checkChainRevocation as he}from"./revocation/chain.js";import{matchCertificateServiceIdentity as ge,matchServiceIdentity as _e}from"./verify/identity.js";import{VERIFY_ERROR_CODES as ve,buildCandidatePath as ye,checkExtendedKeyUsage as be,trustAnchorFromCertificate as xe,validateCandidatePath as Se,validateForCa as Ce,validateForCodeSigning as we,validateForTlsClient as Te,validateForTlsServer as Ee,verifyCertificateChain as De,verifyCertificateSigningRequest as Oe}from"./verify/verify.js";import{createOcspRequest as ke,createOcspResponse as Ae,
|
|
1
|
+
import{categorizePemBlocks as e,pemDecode as t,pemEncode as n,splitPemBlocks as r}from"./pem/pem.js";import{isResultError as i,unwrap as a,unwrapOr as o}from"./result/result.js";import{exportBinaryBase64 as s,exportEncryptedPkcs1Pem as c,exportEncryptedPkcs8Der as l,exportEncryptedPkcs8Pem as u,exportEncryptedSec1Pem as d,exportPkcs1Der as f,exportPkcs1Pem as p,exportPkcs8Der as m,exportPkcs8Pem as h,exportPrivateJwk as g,exportPublicJwk as _,exportSec1Der as v,exportSec1Pem as y,exportSpkiDer as b,exportSpkiPem as x,generateKeyPair as S,importEncryptedPkcs1Pem as C,importEncryptedPkcs8Der as w,importEncryptedPkcs8Pem as T,importEncryptedSec1Pem as E,importPkcs1Der as D,importPkcs1Pem as O,importPkcs8Base64 as k,importPkcs8Der as A,importPkcs8Pem as j,importPrivateJwk as M,importPublicJwk as N,importSec1Der as P,importSec1Pem as F,importSpkiBase64 as I,importSpkiDer as L,importSpkiPem as R}from"./keys/keys.js";import{decodeExtension as z,decodeExtensionMap as B,decodeExtensions as V,defineExtensionDecoder as H,defineExtensionDecoderMap as U,findExtension as W,parseCertificateChainPem as G,parseCertificateDer as K,parseCertificatePem as q,parseCertificateSigningRequestDer as J,parseCertificateSigningRequestPem as Y}from"./x509/parse.js";import{createPfx as X,parsePfxDer as Z,parsePfxPem as Q}from"./pkcs/pfx.js";import{createPkcs7CertBagDer as $,createPkcs7CertBagPem as ee,createPkcs7SignedDataDer as te,createPkcs7SignedDataPem as ne,parsePkcs7CertBagDer as re,parsePkcs7CertBagPem as ie,parsePkcs7SignedDataDer as ae,parsePkcs7SignedDataPem as oe,verifyPkcs7SignedData as se}from"./pkcs/pkcs7.js";import{checkCertificateRevocationAgainstCrl as ce,createCertificateRevocationList as le,isCertificateRevoked as ue,parseCertificateRevocationListDer as de,parseCertificateRevocationListPem as fe,validateCertificateRevocationList as pe,verifyCertificateRevocationList as me}from"./revocation/crl.js";import{checkChainRevocation as he}from"./revocation/chain.js";import{matchCertificateServiceIdentity as ge,matchServiceIdentity as _e}from"./verify/identity.js";import{VERIFY_ERROR_CODES as ve,buildCandidatePath as ye,checkExtendedKeyUsage as be,trustAnchorFromCertificate as xe,validateCandidatePath as Se,validateForCa as Ce,validateForCodeSigning as we,validateForTlsClient as Te,validateForTlsServer as Ee,verifyCertificateChain as De,verifyCertificateSigningRequest as Oe}from"./verify/verify.js";import{createOcspRequest as ke,createOcspResponse as Ae,hasOcspNoCheckExtension as je,parseOcspRequestDer as Me,parseOcspRequestPem as Ne,parseOcspResponseDer as Pe,parseOcspResponsePem as Fe,validateOcspResponse as Ie,verifyOcspResponse as Le}from"./revocation/ocsp.js";import{checkCertificateRevocation as Re,getCertificateOcspResponderUris as ze,resolveOcspResponderCandidates as Be}from"./revocation/revocation.js";import{createCertificate as Ve,createSelfSignedCertificate as He}from"./x509/certificate.js";import{createCertificateSigningRequest as Ue}from"./x509/csr.js";export{ve as VERIFY_ERROR_CODES,ye as buildCandidatePath,e as categorizePemBlocks,Re as checkCertificateRevocation,ce as checkCertificateRevocationAgainstCrl,he as checkChainRevocation,be as checkExtendedKeyUsage,Ve as createCertificate,le as createCertificateRevocationList,Ue as createCertificateSigningRequest,ke as createOcspRequest,Ae as createOcspResponse,X as createPfx,$ as createPkcs7CertBagDer,ee as createPkcs7CertBagPem,te as createPkcs7SignedDataDer,ne as createPkcs7SignedDataPem,He as createSelfSignedCertificate,z as decodeExtension,B as decodeExtensionMap,V as decodeExtensions,H as defineExtensionDecoder,U as defineExtensionDecoderMap,s as exportBinaryBase64,c as exportEncryptedPkcs1Pem,l as exportEncryptedPkcs8Der,u as exportEncryptedPkcs8Pem,d as exportEncryptedSec1Pem,f as exportPkcs1Der,p as exportPkcs1Pem,m as exportPkcs8Der,h as exportPkcs8Pem,g as exportPrivateJwk,_ as exportPublicJwk,v as exportSec1Der,y as exportSec1Pem,b as exportSpkiDer,x as exportSpkiPem,W as findExtension,S as generateKeyPair,ze as getCertificateOcspResponderUris,je as hasOcspNoCheckExtension,C as importEncryptedPkcs1Pem,w as importEncryptedPkcs8Der,T as importEncryptedPkcs8Pem,E as importEncryptedSec1Pem,D as importPkcs1Der,O as importPkcs1Pem,k as importPkcs8Base64,A as importPkcs8Der,j as importPkcs8Pem,M as importPrivateJwk,N as importPublicJwk,P as importSec1Der,F as importSec1Pem,I as importSpkiBase64,L as importSpkiDer,R as importSpkiPem,ue as isCertificateRevoked,i as isResultError,ge as matchCertificateServiceIdentity,_e as matchServiceIdentity,G as parseCertificateChainPem,K as parseCertificateDer,q as parseCertificatePem,de as parseCertificateRevocationListDer,fe as parseCertificateRevocationListPem,J as parseCertificateSigningRequestDer,Y as parseCertificateSigningRequestPem,Me as parseOcspRequestDer,Ne as parseOcspRequestPem,Pe as parseOcspResponseDer,Fe as parseOcspResponsePem,Z as parsePfxDer,Q as parsePfxPem,re as parsePkcs7CertBagDer,ie as parsePkcs7CertBagPem,ae as parsePkcs7SignedDataDer,oe as parsePkcs7SignedDataPem,t as pemDecode,n as pemEncode,Be as resolveOcspResponderCandidates,r as splitPemBlocks,xe as trustAnchorFromCertificate,a as unwrap,o as unwrapOr,Se as validateCandidatePath,pe as validateCertificateRevocationList,Ce as validateForCa,we as validateForCodeSigning,Te as validateForTlsClient,Ee as validateForTlsServer,Ie as validateOcspResponse,De as verifyCertificateChain,me as verifyCertificateRevocationList,Oe as verifyCertificateSigningRequest,Le as verifyOcspResponse,se as verifyPkcs7SignedData};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={commonName:`2.5.4.3`,surname:`2.5.4.4`,serialNumber:`2.5.4.5`,countryName:`2.5.4.6`,localityName:`2.5.4.7`,stateOrProvinceName:`2.5.4.8`,streetAddress:`2.5.4.9`,organizationName:`2.5.4.10`,organizationalUnitName:`2.5.4.11`,title:`2.5.4.12`,givenName:`2.5.4.42`,emailAddress:`1.2.840.113549.1.9.1`,cmsContentType:`1.2.840.113549.1.9.3`,cmsMessageDigest:`1.2.840.113549.1.9.4`,extensionRequest:`1.2.840.113549.1.9.14`,pkcs7Data:`1.2.840.113549.1.7.1`,pkcs7SignedData:`1.2.840.113549.1.7.2`,pkcs7EncryptedData:`1.2.840.113549.1.7.6`,pkcs12KeyBag:`1.2.840.113549.1.12.10.1.1`,pkcs12CertBag:`1.2.840.113549.1.12.10.1.3`,x509CertificateBagType:`1.2.840.113549.1.9.22.1`,friendlyName:`1.2.840.113549.1.9.20`,localKeyId:`1.2.840.113549.1.9.21`,pbes2:`1.2.840.113549.1.5.13`,pbkdf2:`1.2.840.113549.1.5.12`,mgf1:`1.2.840.113549.1.1.8`,hmacWithSHA1:`1.2.840.113549.2.7`,hmacWithSHA256:`1.2.840.113549.2.9`,aes128Cbc:`2.16.840.1.101.3.4.1.2`,aes192Cbc:`2.16.840.1.101.3.4.1.22`,aes256Cbc:`2.16.840.1.101.3.4.1.42`,rsaEncryption:`1.2.840.113549.1.1.1`,sha1WithRSAEncryption:`1.2.840.113549.1.1.5`,rsassaPss:`1.2.840.113549.1.1.10`,sha256WithRSAEncryption:`1.2.840.113549.1.1.11`,sha384WithRSAEncryption:`1.2.840.113549.1.1.12`,sha512WithRSAEncryption:`1.2.840.113549.1.1.13`,ecPublicKey:`1.2.840.10045.2.1`,ecdsaWithSHA1:`1.2.840.10045.4.1`,ecdsaWithSHA224:`1.2.840.10045.4.3.1`,ecdsaWithSHA256:`1.2.840.10045.4.3.2`,ecdsaWithSHA384:`1.2.840.10045.4.3.3`,ecdsaWithSHA512:`1.2.840.10045.4.3.4`,prime256v1:`1.2.840.10045.3.1.7`,secp384r1:`1.3.132.0.34`,secp521r1:`1.3.132.0.35`,ed25519:`1.3.101.112`,subjectKeyIdentifier:`2.5.29.14`,keyUsage:`2.5.29.15`,subjectAltName:`2.5.29.17`,nameConstraints:`2.5.29.30`,certificatePolicies:`2.5.29.32`,policyMappings:`2.5.29.33`,cRLNumber:`2.5.29.20`,cRLReason:`2.5.29.21`,invalidityDate:`2.5.29.24`,certificateIssuer:`2.5.29.29`,issuingDistributionPoint:`2.5.29.28`,deltaCRLIndicator:`2.5.29.27`,basicConstraints:`2.5.29.19`,policyConstraints:`2.5.29.36`,cRLDistributionPoints:`2.5.29.31`,freshestCRL:`2.5.29.46`,inhibitAnyPolicy:`2.5.29.54`,extendedKeyUsage:`2.5.29.37`,authorityKeyIdentifier:`2.5.29.35`,anyPolicy:`2.5.29.32.0`,authorityInfoAccess:`1.3.6.1.5.5.7.1.1`,idOnDnsSrv:`1.3.6.1.5.5.7.8.7`,cpsPolicyQualifier:`1.3.6.1.5.5.7.2.1`,userNoticePolicyQualifier:`1.3.6.1.5.5.7.2.2`,ocspAccessMethod:`1.3.6.1.5.5.7.48.1`,caIssuersAccessMethod:`1.3.6.1.5.5.7.48.2`,ocspBasicResponse:`1.3.6.1.5.5.7.48.1.1`,ocspNonce:`1.3.6.1.5.5.7.48.1.2`,sha1:`1.3.14.3.2.26`,sha256:`2.16.840.1.101.3.4.2.1`,sha384:`2.16.840.1.101.3.4.2.2`,sha512:`2.16.840.1.101.3.4.2.3`,serverAuth:`1.3.6.1.5.5.7.3.1`,clientAuth:`1.3.6.1.5.5.7.3.2`,codeSigning:`1.3.6.1.5.5.7.3.3`,emailProtection:`1.3.6.1.5.5.7.3.4`,timeStamping:`1.3.6.1.5.5.7.3.8`,ocspSigning:`1.3.6.1.5.5.7.3.9`};export{e as OIDS};
|
|
1
|
+
const e={commonName:`2.5.4.3`,surname:`2.5.4.4`,serialNumber:`2.5.4.5`,countryName:`2.5.4.6`,localityName:`2.5.4.7`,stateOrProvinceName:`2.5.4.8`,streetAddress:`2.5.4.9`,organizationName:`2.5.4.10`,organizationalUnitName:`2.5.4.11`,title:`2.5.4.12`,givenName:`2.5.4.42`,emailAddress:`1.2.840.113549.1.9.1`,cmsContentType:`1.2.840.113549.1.9.3`,cmsMessageDigest:`1.2.840.113549.1.9.4`,extensionRequest:`1.2.840.113549.1.9.14`,pkcs7Data:`1.2.840.113549.1.7.1`,pkcs7SignedData:`1.2.840.113549.1.7.2`,pkcs7EncryptedData:`1.2.840.113549.1.7.6`,pkcs12KeyBag:`1.2.840.113549.1.12.10.1.1`,pkcs12CertBag:`1.2.840.113549.1.12.10.1.3`,x509CertificateBagType:`1.2.840.113549.1.9.22.1`,friendlyName:`1.2.840.113549.1.9.20`,localKeyId:`1.2.840.113549.1.9.21`,pbes2:`1.2.840.113549.1.5.13`,pbkdf2:`1.2.840.113549.1.5.12`,mgf1:`1.2.840.113549.1.1.8`,hmacWithSHA1:`1.2.840.113549.2.7`,hmacWithSHA256:`1.2.840.113549.2.9`,aes128Cbc:`2.16.840.1.101.3.4.1.2`,aes192Cbc:`2.16.840.1.101.3.4.1.22`,aes256Cbc:`2.16.840.1.101.3.4.1.42`,rsaEncryption:`1.2.840.113549.1.1.1`,sha1WithRSAEncryption:`1.2.840.113549.1.1.5`,rsassaPss:`1.2.840.113549.1.1.10`,sha256WithRSAEncryption:`1.2.840.113549.1.1.11`,sha384WithRSAEncryption:`1.2.840.113549.1.1.12`,sha512WithRSAEncryption:`1.2.840.113549.1.1.13`,ecPublicKey:`1.2.840.10045.2.1`,ecdsaWithSHA1:`1.2.840.10045.4.1`,ecdsaWithSHA224:`1.2.840.10045.4.3.1`,ecdsaWithSHA256:`1.2.840.10045.4.3.2`,ecdsaWithSHA384:`1.2.840.10045.4.3.3`,ecdsaWithSHA512:`1.2.840.10045.4.3.4`,prime256v1:`1.2.840.10045.3.1.7`,secp384r1:`1.3.132.0.34`,secp521r1:`1.3.132.0.35`,ed25519:`1.3.101.112`,subjectKeyIdentifier:`2.5.29.14`,keyUsage:`2.5.29.15`,subjectAltName:`2.5.29.17`,nameConstraints:`2.5.29.30`,certificatePolicies:`2.5.29.32`,policyMappings:`2.5.29.33`,cRLNumber:`2.5.29.20`,cRLReason:`2.5.29.21`,invalidityDate:`2.5.29.24`,certificateIssuer:`2.5.29.29`,issuingDistributionPoint:`2.5.29.28`,deltaCRLIndicator:`2.5.29.27`,basicConstraints:`2.5.29.19`,policyConstraints:`2.5.29.36`,cRLDistributionPoints:`2.5.29.31`,freshestCRL:`2.5.29.46`,inhibitAnyPolicy:`2.5.29.54`,extendedKeyUsage:`2.5.29.37`,authorityKeyIdentifier:`2.5.29.35`,anyPolicy:`2.5.29.32.0`,authorityInfoAccess:`1.3.6.1.5.5.7.1.1`,idOnDnsSrv:`1.3.6.1.5.5.7.8.7`,cpsPolicyQualifier:`1.3.6.1.5.5.7.2.1`,userNoticePolicyQualifier:`1.3.6.1.5.5.7.2.2`,ocspAccessMethod:`1.3.6.1.5.5.7.48.1`,caIssuersAccessMethod:`1.3.6.1.5.5.7.48.2`,ocspBasicResponse:`1.3.6.1.5.5.7.48.1.1`,ocspNonce:`1.3.6.1.5.5.7.48.1.2`,ocspNoCheck:`1.3.6.1.5.5.7.48.1.5`,sha1:`1.3.14.3.2.26`,sha256:`2.16.840.1.101.3.4.2.1`,sha384:`2.16.840.1.101.3.4.2.2`,sha512:`2.16.840.1.101.3.4.2.3`,serverAuth:`1.3.6.1.5.5.7.3.1`,clientAuth:`1.3.6.1.5.5.7.3.2`,codeSigning:`1.3.6.1.5.5.7.3.3`,emailProtection:`1.3.6.1.5.5.7.3.4`,timeStamping:`1.3.6.1.5.5.7.3.8`,ocspSigning:`1.3.6.1.5.5.7.3.9`};export{e as OIDS};
|
|
2
2
|
//# sourceMappingURL=oids.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oids.js","names":[],"sources":["../../../src/internal/asn1/oids.ts"],"sourcesContent":["/**\n * Centralized ASN.1 object identifier registry referenced by create, parse,\n * verify, and container modules.\n *\n * All OIDs are dotted-decimal string constants keyed by their common short name.\n *\n * @module\n */\n\n/**\n * Dotted-decimal OID constants for X.500 attributes, PKCS algorithms,\n * X.509v3 extensions, EKU purposes, hash algorithms, and PKIX access methods.\n */\nconst OIDS = {\n\tcommonName: '2.5.4.3',\n\tsurname: '2.5.4.4',\n\tserialNumber: '2.5.4.5',\n\tcountryName: '2.5.4.6',\n\tlocalityName: '2.5.4.7',\n\tstateOrProvinceName: '2.5.4.8',\n\tstreetAddress: '2.5.4.9',\n\torganizationName: '2.5.4.10',\n\torganizationalUnitName: '2.5.4.11',\n\ttitle: '2.5.4.12',\n\tgivenName: '2.5.4.42',\n\temailAddress: '1.2.840.113549.1.9.1',\n\tcmsContentType: '1.2.840.113549.1.9.3',\n\tcmsMessageDigest: '1.2.840.113549.1.9.4',\n\textensionRequest: '1.2.840.113549.1.9.14',\n\tpkcs7Data: '1.2.840.113549.1.7.1',\n\tpkcs7SignedData: '1.2.840.113549.1.7.2',\n\tpkcs7EncryptedData: '1.2.840.113549.1.7.6',\n\tpkcs12KeyBag: '1.2.840.113549.1.12.10.1.1',\n\tpkcs12CertBag: '1.2.840.113549.1.12.10.1.3',\n\tx509CertificateBagType: '1.2.840.113549.1.9.22.1',\n\tfriendlyName: '1.2.840.113549.1.9.20',\n\tlocalKeyId: '1.2.840.113549.1.9.21',\n\tpbes2: '1.2.840.113549.1.5.13',\n\tpbkdf2: '1.2.840.113549.1.5.12',\n\tmgf1: '1.2.840.113549.1.1.8',\n\thmacWithSHA1: '1.2.840.113549.2.7',\n\thmacWithSHA256: '1.2.840.113549.2.9',\n\taes128Cbc: '2.16.840.1.101.3.4.1.2',\n\taes192Cbc: '2.16.840.1.101.3.4.1.22',\n\taes256Cbc: '2.16.840.1.101.3.4.1.42',\n\trsaEncryption: '1.2.840.113549.1.1.1',\n\tsha1WithRSAEncryption: '1.2.840.113549.1.1.5',\n\trsassaPss: '1.2.840.113549.1.1.10',\n\tsha256WithRSAEncryption: '1.2.840.113549.1.1.11',\n\tsha384WithRSAEncryption: '1.2.840.113549.1.1.12',\n\tsha512WithRSAEncryption: '1.2.840.113549.1.1.13',\n\tecPublicKey: '1.2.840.10045.2.1',\n\tecdsaWithSHA1: '1.2.840.10045.4.1',\n\tecdsaWithSHA224: '1.2.840.10045.4.3.1',\n\tecdsaWithSHA256: '1.2.840.10045.4.3.2',\n\tecdsaWithSHA384: '1.2.840.10045.4.3.3',\n\tecdsaWithSHA512: '1.2.840.10045.4.3.4',\n\tprime256v1: '1.2.840.10045.3.1.7',\n\tsecp384r1: '1.3.132.0.34',\n\tsecp521r1: '1.3.132.0.35',\n\ted25519: '1.3.101.112',\n\tsubjectKeyIdentifier: '2.5.29.14',\n\tkeyUsage: '2.5.29.15',\n\tsubjectAltName: '2.5.29.17',\n\tnameConstraints: '2.5.29.30',\n\tcertificatePolicies: '2.5.29.32',\n\tpolicyMappings: '2.5.29.33',\n\tcRLNumber: '2.5.29.20',\n\tcRLReason: '2.5.29.21',\n\tinvalidityDate: '2.5.29.24',\n\tcertificateIssuer: '2.5.29.29',\n\tissuingDistributionPoint: '2.5.29.28',\n\tdeltaCRLIndicator: '2.5.29.27',\n\tbasicConstraints: '2.5.29.19',\n\tpolicyConstraints: '2.5.29.36',\n\tcRLDistributionPoints: '2.5.29.31',\n\tfreshestCRL: '2.5.29.46',\n\tinhibitAnyPolicy: '2.5.29.54',\n\textendedKeyUsage: '2.5.29.37',\n\tauthorityKeyIdentifier: '2.5.29.35',\n\tanyPolicy: '2.5.29.32.0',\n\tauthorityInfoAccess: '1.3.6.1.5.5.7.1.1',\n\tidOnDnsSrv: '1.3.6.1.5.5.7.8.7',\n\tcpsPolicyQualifier: '1.3.6.1.5.5.7.2.1',\n\tuserNoticePolicyQualifier: '1.3.6.1.5.5.7.2.2',\n\tocspAccessMethod: '1.3.6.1.5.5.7.48.1',\n\tcaIssuersAccessMethod: '1.3.6.1.5.5.7.48.2',\n\tocspBasicResponse: '1.3.6.1.5.5.7.48.1.1',\n\tocspNonce: '1.3.6.1.5.5.7.48.1.2',\n\tsha1: '1.3.14.3.2.26',\n\tsha256: '2.16.840.1.101.3.4.2.1',\n\tsha384: '2.16.840.1.101.3.4.2.2',\n\tsha512: '2.16.840.1.101.3.4.2.3',\n\tserverAuth: '1.3.6.1.5.5.7.3.1',\n\tclientAuth: '1.3.6.1.5.5.7.3.2',\n\tcodeSigning: '1.3.6.1.5.5.7.3.3',\n\temailProtection: '1.3.6.1.5.5.7.3.4',\n\ttimeStamping: '1.3.6.1.5.5.7.3.8',\n\tocspSigning: '1.3.6.1.5.5.7.3.9',\n} as const;\n\nexport { OIDS };\n"],"mappings":"AAaA,MAAM,EAAO,CACZ,WAAY,UACZ,QAAS,UACT,aAAc,UACd,YAAa,UACb,aAAc,UACd,oBAAqB,UACrB,cAAe,UACf,iBAAkB,WAClB,uBAAwB,WACxB,MAAO,WACP,UAAW,WACX,aAAc,uBACd,eAAgB,uBAChB,iBAAkB,uBAClB,iBAAkB,wBAClB,UAAW,uBACX,gBAAiB,uBACjB,mBAAoB,uBACpB,aAAc,6BACd,cAAe,6BACf,uBAAwB,0BACxB,aAAc,wBACd,WAAY,wBACZ,MAAO,wBACP,OAAQ,wBACR,KAAM,uBACN,aAAc,qBACd,eAAgB,qBAChB,UAAW,yBACX,UAAW,0BACX,UAAW,0BACX,cAAe,uBACf,sBAAuB,uBACvB,UAAW,wBACX,wBAAyB,wBACzB,wBAAyB,wBACzB,wBAAyB,wBACzB,YAAa,oBACb,cAAe,oBACf,gBAAiB,sBACjB,gBAAiB,sBACjB,gBAAiB,sBACjB,gBAAiB,sBACjB,WAAY,sBACZ,UAAW,eACX,UAAW,eACX,QAAS,cACT,qBAAsB,YACtB,SAAU,YACV,eAAgB,YAChB,gBAAiB,YACjB,oBAAqB,YACrB,eAAgB,YAChB,UAAW,YACX,UAAW,YACX,eAAgB,YAChB,kBAAmB,YACnB,yBAA0B,YAC1B,kBAAmB,YACnB,iBAAkB,YAClB,kBAAmB,YACnB,sBAAuB,YACvB,YAAa,YACb,iBAAkB,YAClB,iBAAkB,YAClB,uBAAwB,YACxB,UAAW,cACX,oBAAqB,oBACrB,WAAY,oBACZ,mBAAoB,oBACpB,0BAA2B,oBAC3B,iBAAkB,qBAClB,sBAAuB,qBACvB,kBAAmB,uBACnB,UAAW,uBACX,KAAM,gBACN,OAAQ,yBACR,OAAQ,yBACR,OAAQ,yBACR,WAAY,oBACZ,WAAY,oBACZ,YAAa,oBACb,gBAAiB,oBACjB,aAAc,oBACd,YAAa,mBACd"}
|
|
1
|
+
{"version":3,"file":"oids.js","names":[],"sources":["../../../src/internal/asn1/oids.ts"],"sourcesContent":["/**\n * Centralized ASN.1 object identifier registry referenced by create, parse,\n * verify, and container modules.\n *\n * All OIDs are dotted-decimal string constants keyed by their common short name.\n *\n * @module\n */\n\n/**\n * Dotted-decimal OID constants for X.500 attributes, PKCS algorithms,\n * X.509v3 extensions, EKU purposes, hash algorithms, and PKIX access methods.\n */\nconst OIDS = {\n\tcommonName: '2.5.4.3',\n\tsurname: '2.5.4.4',\n\tserialNumber: '2.5.4.5',\n\tcountryName: '2.5.4.6',\n\tlocalityName: '2.5.4.7',\n\tstateOrProvinceName: '2.5.4.8',\n\tstreetAddress: '2.5.4.9',\n\torganizationName: '2.5.4.10',\n\torganizationalUnitName: '2.5.4.11',\n\ttitle: '2.5.4.12',\n\tgivenName: '2.5.4.42',\n\temailAddress: '1.2.840.113549.1.9.1',\n\tcmsContentType: '1.2.840.113549.1.9.3',\n\tcmsMessageDigest: '1.2.840.113549.1.9.4',\n\textensionRequest: '1.2.840.113549.1.9.14',\n\tpkcs7Data: '1.2.840.113549.1.7.1',\n\tpkcs7SignedData: '1.2.840.113549.1.7.2',\n\tpkcs7EncryptedData: '1.2.840.113549.1.7.6',\n\tpkcs12KeyBag: '1.2.840.113549.1.12.10.1.1',\n\tpkcs12CertBag: '1.2.840.113549.1.12.10.1.3',\n\tx509CertificateBagType: '1.2.840.113549.1.9.22.1',\n\tfriendlyName: '1.2.840.113549.1.9.20',\n\tlocalKeyId: '1.2.840.113549.1.9.21',\n\tpbes2: '1.2.840.113549.1.5.13',\n\tpbkdf2: '1.2.840.113549.1.5.12',\n\tmgf1: '1.2.840.113549.1.1.8',\n\thmacWithSHA1: '1.2.840.113549.2.7',\n\thmacWithSHA256: '1.2.840.113549.2.9',\n\taes128Cbc: '2.16.840.1.101.3.4.1.2',\n\taes192Cbc: '2.16.840.1.101.3.4.1.22',\n\taes256Cbc: '2.16.840.1.101.3.4.1.42',\n\trsaEncryption: '1.2.840.113549.1.1.1',\n\tsha1WithRSAEncryption: '1.2.840.113549.1.1.5',\n\trsassaPss: '1.2.840.113549.1.1.10',\n\tsha256WithRSAEncryption: '1.2.840.113549.1.1.11',\n\tsha384WithRSAEncryption: '1.2.840.113549.1.1.12',\n\tsha512WithRSAEncryption: '1.2.840.113549.1.1.13',\n\tecPublicKey: '1.2.840.10045.2.1',\n\tecdsaWithSHA1: '1.2.840.10045.4.1',\n\tecdsaWithSHA224: '1.2.840.10045.4.3.1',\n\tecdsaWithSHA256: '1.2.840.10045.4.3.2',\n\tecdsaWithSHA384: '1.2.840.10045.4.3.3',\n\tecdsaWithSHA512: '1.2.840.10045.4.3.4',\n\tprime256v1: '1.2.840.10045.3.1.7',\n\tsecp384r1: '1.3.132.0.34',\n\tsecp521r1: '1.3.132.0.35',\n\ted25519: '1.3.101.112',\n\tsubjectKeyIdentifier: '2.5.29.14',\n\tkeyUsage: '2.5.29.15',\n\tsubjectAltName: '2.5.29.17',\n\tnameConstraints: '2.5.29.30',\n\tcertificatePolicies: '2.5.29.32',\n\tpolicyMappings: '2.5.29.33',\n\tcRLNumber: '2.5.29.20',\n\tcRLReason: '2.5.29.21',\n\tinvalidityDate: '2.5.29.24',\n\tcertificateIssuer: '2.5.29.29',\n\tissuingDistributionPoint: '2.5.29.28',\n\tdeltaCRLIndicator: '2.5.29.27',\n\tbasicConstraints: '2.5.29.19',\n\tpolicyConstraints: '2.5.29.36',\n\tcRLDistributionPoints: '2.5.29.31',\n\tfreshestCRL: '2.5.29.46',\n\tinhibitAnyPolicy: '2.5.29.54',\n\textendedKeyUsage: '2.5.29.37',\n\tauthorityKeyIdentifier: '2.5.29.35',\n\tanyPolicy: '2.5.29.32.0',\n\tauthorityInfoAccess: '1.3.6.1.5.5.7.1.1',\n\tidOnDnsSrv: '1.3.6.1.5.5.7.8.7',\n\tcpsPolicyQualifier: '1.3.6.1.5.5.7.2.1',\n\tuserNoticePolicyQualifier: '1.3.6.1.5.5.7.2.2',\n\tocspAccessMethod: '1.3.6.1.5.5.7.48.1',\n\tcaIssuersAccessMethod: '1.3.6.1.5.5.7.48.2',\n\tocspBasicResponse: '1.3.6.1.5.5.7.48.1.1',\n\tocspNonce: '1.3.6.1.5.5.7.48.1.2',\n\tocspNoCheck: '1.3.6.1.5.5.7.48.1.5',\n\tsha1: '1.3.14.3.2.26',\n\tsha256: '2.16.840.1.101.3.4.2.1',\n\tsha384: '2.16.840.1.101.3.4.2.2',\n\tsha512: '2.16.840.1.101.3.4.2.3',\n\tserverAuth: '1.3.6.1.5.5.7.3.1',\n\tclientAuth: '1.3.6.1.5.5.7.3.2',\n\tcodeSigning: '1.3.6.1.5.5.7.3.3',\n\temailProtection: '1.3.6.1.5.5.7.3.4',\n\ttimeStamping: '1.3.6.1.5.5.7.3.8',\n\tocspSigning: '1.3.6.1.5.5.7.3.9',\n} as const;\n\nexport { OIDS };\n"],"mappings":"AAaA,MAAM,EAAO,CACZ,WAAY,UACZ,QAAS,UACT,aAAc,UACd,YAAa,UACb,aAAc,UACd,oBAAqB,UACrB,cAAe,UACf,iBAAkB,WAClB,uBAAwB,WACxB,MAAO,WACP,UAAW,WACX,aAAc,uBACd,eAAgB,uBAChB,iBAAkB,uBAClB,iBAAkB,wBAClB,UAAW,uBACX,gBAAiB,uBACjB,mBAAoB,uBACpB,aAAc,6BACd,cAAe,6BACf,uBAAwB,0BACxB,aAAc,wBACd,WAAY,wBACZ,MAAO,wBACP,OAAQ,wBACR,KAAM,uBACN,aAAc,qBACd,eAAgB,qBAChB,UAAW,yBACX,UAAW,0BACX,UAAW,0BACX,cAAe,uBACf,sBAAuB,uBACvB,UAAW,wBACX,wBAAyB,wBACzB,wBAAyB,wBACzB,wBAAyB,wBACzB,YAAa,oBACb,cAAe,oBACf,gBAAiB,sBACjB,gBAAiB,sBACjB,gBAAiB,sBACjB,gBAAiB,sBACjB,WAAY,sBACZ,UAAW,eACX,UAAW,eACX,QAAS,cACT,qBAAsB,YACtB,SAAU,YACV,eAAgB,YAChB,gBAAiB,YACjB,oBAAqB,YACrB,eAAgB,YAChB,UAAW,YACX,UAAW,YACX,eAAgB,YAChB,kBAAmB,YACnB,yBAA0B,YAC1B,kBAAmB,YACnB,iBAAkB,YAClB,kBAAmB,YACnB,sBAAuB,YACvB,YAAa,YACb,iBAAkB,YAClB,iBAAkB,YAClB,uBAAwB,YACxB,UAAW,cACX,oBAAqB,oBACrB,WAAY,oBACZ,mBAAoB,oBACpB,0BAA2B,oBAC3B,iBAAkB,qBAClB,sBAAuB,qBACvB,kBAAmB,uBACnB,UAAW,uBACX,YAAa,uBACb,KAAM,gBACN,OAAQ,yBACR,OAAQ,yBACR,OAAQ,yBACR,WAAY,oBACZ,WAAY,oBACZ,YAAa,oBACb,gBAAiB,oBACjB,aAAc,oBACd,YAAa,mBACd"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{readRootElement as e}from"../asn1/der.js";import{childrenOf as t,decodeObjectIdentifier as n,decodeString as r,hexToBytes as i,requireElement as a,toHex as o}from"../asn1/asn1.js";import{OIDS as s}from"../asn1/oids.js";import{allOnesMaskForIpAddress as c,decodeIpAddress as l,parseIpAddressToBytes as u}from"../shared/ip.js";import{nameFieldKeyFromOid as d}from"../x509/name-fields.js";import{compareDistinguishedNames as f,isWithinDirectoryNameSubtree as p}from"../shared/dn.js";function m(e,t,n,r){return{ok:!1,code:e,message:t,index:n,...r===void 0?{}:{details:r}}}function h(e){let t={...e.subjectCommonName===void 0?{}:{subjectCommonName:e.subjectCommonName},...e.actual===void 0?{}:{actual:e.actual}};return Object.keys(t).length===0?void 0:t}function g(e){return f(e.subject,e.issuer)}function _(e){return{initialPermittedSubtrees:e.permittedSubtrees?.map(e=>e.base)??[],initialExcludedSubtrees:e.excludedSubtrees?.map(e=>e.base)??[]}}function v(e,t){let n=
|
|
1
|
+
import{readRootElement as e}from"../asn1/der.js";import{childrenOf as t,decodeObjectIdentifier as n,decodeString as r,hexToBytes as i,requireElement as a,toHex as o}from"../asn1/asn1.js";import{OIDS as s}from"../asn1/oids.js";import{allOnesMaskForIpAddress as c,decodeIpAddress as l,parseIpAddressToBytes as u}from"../shared/ip.js";import{nameFieldKeyFromOid as d}from"../x509/name-fields.js";import{compareDistinguishedNames as f,isWithinDirectoryNameSubtree as p}from"../shared/dn.js";function m(e,t,n,r){return{ok:!1,code:e,message:t,index:n,...r===void 0?{}:{details:r}}}function h(e){let t={...e.subjectCommonName===void 0?{}:{subjectCommonName:e.subjectCommonName},...e.actual===void 0?{}:{actual:e.actual}};return Object.keys(t).length===0?void 0:t}function g(e){return f(e.subject,e.issuer)}function _(e){return{initialPermittedSubtrees:e.permittedSubtrees?.map(e=>e.base)??[],initialExcludedSubtrees:e.excludedSubtrees?.map(e=>e.base)??[]}}function v(e,t){let n=b(t),r=e[e.length-1];r?.nameConstraints!==void 0&&(n=x(n,r.nameConstraints,y(r)));for(let t=e.length-2;t>=0;--t){let r=e[t];if(r===void 0)throw Error(`Certificate chain contains undefined at index ${String(t)}`);if(!g(r)||t===0){let e=w(r,n,t);if(!e.ok)return e}r.nameConstraints!==void 0&&(n=x(n,r.nameConstraints,y(r)))}return{ok:!0}}function y(e){return e.extensions.some(e=>e.oid===s.nameConstraints&&e.critical)}function b(e){return{permittedLevels:e.initialPermittedSubtrees.length>0?[e.initialPermittedSubtrees]:[],excluded:e.initialExcludedSubtrees,unsupportedCriticalForms:new Set}}function x(e,t,n){let r=t.permittedSubtrees!==void 0&&t.permittedSubtrees.length>0?[...e.permittedLevels,t.permittedSubtrees.flatMap(e=>C(e.base)?[e.base]:[])]:e.permittedLevels,i=t.excludedSubtrees!==void 0&&t.excludedSubtrees.length>0?[...e.excluded,...t.excludedSubtrees.flatMap(e=>C(e.base)?[e.base]:[])]:e.excluded,a=n?S(t):[];return{permittedLevels:r,excluded:i,unsupportedCriticalForms:a.length>0?new Set([...e.unsupportedCriticalForms,...a]):e.unsupportedCriticalForms}}function S(e){let t=new Set;for(let n of e.permittedSubtrees??[])C(n.base)||t.add(n.base.type);for(let n of e.excludedSubtrees??[])C(n.base)||t.add(n.base.type);return[...t]}function C(e){switch(e.type){case`dns`:case`email`:case`uri`:case`ip`:case`directoryName`:return!0;case`otherName`:case`x400Address`:case`ediPartyName`:case`registeredID`:return!1;default:throw Error(`Unhandled NameConstraintForm type: ${String(e)}`)}}function w(e,t,n){if(e.subject.derHex!==`3000`&&!O({type:`directoryName`,derHex:e.subject.derHex},t))return m(`name_constraints_violated`,`subject distinguished name violates name constraints`,n,h({subjectCommonName:e.subject.values.commonName}));if(e.subjectAltNames!==void 0)for(let r of e.subjectAltNames){let i=E(r);if(i!==void 0&&t.unsupportedCriticalForms.has(i))return m(`unsupported_name_constraints`,`critical name constraints impose ${i} constraints that cannot be processed, and the certificate contains a ${i} subject alternative name`,n,h({subjectCommonName:e.subject.values.commonName,actual:i}));let a=D(r);if(!a.ok)return m(`name_constraints_violated`,`SAN ${a.actual} is malformed and cannot be checked against name constraints`,n,h({subjectCommonName:e.subject.values.commonName,actual:a.actual}));let o=a.value;if(o!==void 0&&!O(o,t))return m(`name_constraints_violated`,`SAN ${z(o)} violates name constraints`,n,h({subjectCommonName:e.subject.values.commonName,actual:z(o)}))}return T(t)&&!(e.subjectAltNames?.some(e=>e.type===`email`)??!1)&&e.subject.values.emailAddress!==void 0&&!O({type:`email`,value:e.subject.values.emailAddress},t)?m(`name_constraints_violated`,`subject emailAddress ${e.subject.values.emailAddress} violates name constraints`,n,h({subjectCommonName:e.subject.values.commonName,actual:e.subject.values.emailAddress})):{ok:!0}}function T(e){for(let t of e.permittedLevels)if(t.some(e=>e.type===`email`))return!0;return e.excluded.some(e=>e.type===`email`)}function E(e){if(e.type===`srv`)return`otherName`;if(e.type===`unknown`)switch(e.tag){case 160:return`otherName`;case 163:return`x400Address`;case 165:return`ediPartyName`;case 136:return`registeredID`;default:return}}function D(e){switch(e.type){case`dns`:return{ok:!0,value:{type:`dns`,value:e.value}};case`email`:return{ok:!0,value:{type:`email`,value:e.value}};case`uri`:return{ok:!0,value:{type:`uri`,value:e.value}};case`srv`:return{ok:!0,value:void 0};case`ip`:try{return{ok:!0,value:{type:`ip`,addressBytes:u(e.value),maskBytes:c(e.value)}}}catch{return{ok:!1,actual:`ip:${e.value}`}}case`directoryName`:return{ok:!0,value:{type:`directoryName`,derHex:e.derHex}};case`unknown`:return{ok:!0,value:void 0};default:throw Error(`Unhandled SubjectAltName type: ${String(e)}`)}}function O(e,t){for(let n of t.excluded)if(k(e,n))return!1;for(let n of t.permittedLevels){let t=n.filter(t=>t.type===e.type);if(t.length!==0&&!t.some(t=>k(e,t)))return!1}return!0}function k(e,t){return e.type===`dns`&&t.type===`dns`?A(e.value,t.value):e.type===`email`&&t.type===`email`?j(e.value,t.value):e.type===`uri`&&t.type===`uri`?M(e.value,t.value):e.type===`ip`&&t.type===`ip`?P(e.addressBytes,t.addressBytes,t.maskBytes):e.type===`directoryName`&&t.type===`directoryName`?F(e.derHex,t.derHex):!1}function A(e,t){let n=e.toLowerCase(),r=t.toLowerCase();return r.length===0?!0:r.startsWith(`.`)?n.endsWith(r):n===r||n.endsWith(`.${r}`)}function j(e,t){let n=e.toLowerCase(),r=t.toLowerCase();if(r.includes(`@`))return n===r;let i=n.indexOf(`@`);if(i<0)return!1;let a=n.slice(i+1);return r.startsWith(`.`)?a.endsWith(r):a===r}function M(e,t){let n=N(e);if(n===void 0)return!1;let r=n.toLowerCase(),i=t.toLowerCase();return i.length===0?!0:i.startsWith(`.`)?r.endsWith(i):r===i}function N(e){try{return new URL(e).hostname}catch{return}}function P(e,t,n){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r+=1){let i=e[r]??0,a=t[r]??0,o=n[r]??0;if((i&o)!==(a&o))return!1}return!0}function F(e,t){let n=I(e),r=I(t);return n===void 0||r===void 0?!1:p(n,r)}function I(n){if(/^(?:[0-9a-fA-F]{2})+$/.test(n))try{let r=i(n),a=L(r,e(r,{maxDepth:64}));if(a.tag!==48)return;let s=[],c=[],l={};for(let e of t(r,a)){let t=R(r,e);if(t===void 0)return;s.push(t);for(let e of t.attributes)c.push(e),e.key!==void 0&&l[e.key]===void 0&&(l[e.key]=e.value)}return{derHex:o(r),rdns:s,attributes:c,values:l}}catch{return}}function L(e,n){if(n.tag!==48)return n;let r=t(e,n),i=r[0];return r.length===1&&i?.tag===48?i:n}function R(e,i){if(i.tag!==49)return;let s=t(e,i);if(s.length===0)return;let c=[],l={};for(let i of s){if(i.tag!==48)return;let o=t(e,i),s=o[0],u=o[1];if(s===void 0||u===void 0||o.length!==2||s.tag!==6)return;let f=n(a(s,`directoryName OID`).value),p;try{p=r(u.tag,a(u,`directoryName value`).value)}catch{return}let m=d(f),h=m===void 0?{oid:f,valueTag:u.tag,value:p}:{oid:f,key:m,valueTag:u.tag,value:p};c.push(h),m!==void 0&&l[m]===void 0&&(l[m]=p)}if(c.length!==0)return{derHex:o(e.slice(i.start-i.headerLength,i.end)),attributes:c,values:l}}function z(e){switch(e.type){case`dns`:return`dns:${e.value}`;case`email`:return`email:${e.value}`;case`uri`:return`uri:${e.value}`;case`ip`:return`ip:${l(e.addressBytes)}`;case`directoryName`:return`dn:${e.derHex.slice(0,20)}${e.derHex.length>20?`...`:``}`;default:throw Error(`Unhandled NameConstraintForm type: ${String(e)}`)}}export{_ as createNameConstraintValidationState,v as evaluateNameConstraints};
|
|
2
2
|
//# sourceMappingURL=name-constraints-engine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"name-constraints-engine.js","names":["exhaustive"],"sources":["../../../src/internal/verify/name-constraints-engine.ts"],"sourcesContent":["/**\n * Internal name-constraints evaluation engine.\n *\n * Accumulates and evaluates the shipped RFC 5280 §4.2.1.10 / §6.1\n * name-constraint subset during certificate path validation.\n *\n * @module\n */\n\nimport {\n\tchildrenOf,\n\tdecodeObjectIdentifier,\n\tdecodeString,\n\thexToBytes,\n\trequireElement,\n\ttoHex,\n} from '#micro509/internal/asn1/asn1.ts';\nimport {\n\tDEFAULT_MAX_DER_DEPTH,\n\ttype DerElement,\n\treadRootElement,\n} from '#micro509/internal/asn1/der.ts';\nimport { OIDS } from '#micro509/internal/asn1/oids.ts';\nimport {\n\tcompareDistinguishedNames,\n\tisWithinDirectoryNameSubtree,\n} from '#micro509/internal/shared/dn.ts';\nimport {\n\tallOnesMaskForIpAddress,\n\tdecodeIpAddress,\n\tparseIpAddressToBytes,\n} from '#micro509/internal/shared/ip.ts';\nimport type { Micro509Error } from '#micro509/result/result.ts';\nimport type { InitialNameConstraintsInput } from '#micro509/verify/name-constraints.ts';\nimport type {\n\tNameConstraintForm,\n\tNameConstraints,\n\tParsedNameConstraintForm,\n\tSubjectAltName,\n} from '#micro509/x509/extensions.ts';\nimport { nameFieldKeyFromOid } from '#micro509/x509/name.ts';\nimport type {\n\tParsedCertificate,\n\tParsedName,\n\tParsedNameAttribute,\n\tParsedRelativeDistinguishedName,\n} from '#micro509/x509/parse.ts';\n\n/**\n * Opaque state seeded from {@linkcode InitialNameConstraintsInput} and consumed\n * by {@linkcode evaluateNameConstraints}.\n */\nexport interface NameConstraintValidationState {\n\t/** Caller-supplied permitted subtree bases (pre-chain). */\n\treadonly initialPermittedSubtrees: readonly NameConstraintForm[];\n\t/** Caller-supplied excluded subtree bases (pre-chain). */\n\treadonly initialExcludedSubtrees: readonly NameConstraintForm[];\n}\n\n/** Discriminant codes for name-constraint validation failures. */\nexport type NameConstraintValidationFailureCode =\n\t| 'name_constraints_violated'\n\t| 'unsupported_name_constraints';\n\n/** Diagnostic context attached to a name-constraint validation failure. */\nexport interface NameConstraintValidationFailureDetails {\n\t/** CN of the certificate whose name violated constraints, if available. */\n\treadonly subjectCommonName?: string;\n\t/** The name or constraint-type string that caused the violation. */\n\treadonly actual?: string;\n}\n\n/** A name-constraint check that failed, with the offending certificate's chain index. */\nexport interface NameConstraintValidationFailure\n\textends Micro509Error<\n\t\tNameConstraintValidationFailureCode,\n\t\tNameConstraintValidationFailureDetails\n\t> {\n\t/** Always `false` for failures. */\n\treadonly ok: false;\n\t/** Zero-based index into the chain of the certificate that violated constraints. */\n\treadonly index: number;\n}\n\n/** Success or failure outcome of name-constraint evaluation across a chain. */\nexport type NameConstraintValidationResult =\n\t| {\n\t\t\t/** All names in the chain satisfy accumulated constraints. */\n\t\t\treadonly ok: true;\n\t }\n\t| NameConstraintValidationFailure;\n\n/** Builder input for assembling optional failure detail fields. */\ninterface NameConstraintValidationFailureDetailsInput {\n\treadonly subjectCommonName?: string | undefined;\n\treadonly actual?: string | undefined;\n}\n\ntype SubjectAltNameCheckableResult =\n\t| {\n\t\t\treadonly ok: true;\n\t\t\treadonly value: NameConstraintForm | undefined;\n\t }\n\t| {\n\t\t\treadonly ok: false;\n\t\t\treadonly actual: string;\n\t };\n\n/** Constructs a {@linkcode NameConstraintValidationFailure} with optional details. */\nfunction nameConstraintFailure(\n\tcode: NameConstraintValidationFailureCode,\n\tmessage: string,\n\tindex: number,\n\tdetails?: NameConstraintValidationFailureDetails,\n): NameConstraintValidationFailure {\n\treturn {\n\t\tok: false,\n\t\tcode,\n\t\tmessage,\n\t\tindex,\n\t\t...(details === undefined ? {} : { details }),\n\t};\n}\n\n/** Strips undefined fields and returns `undefined` when all fields are empty. */\nfunction nameConstraintDetails(\n\tinput: NameConstraintValidationFailureDetailsInput,\n): NameConstraintValidationFailureDetails | undefined {\n\tconst details: NameConstraintValidationFailureDetails = {\n\t\t...(input.subjectCommonName === undefined\n\t\t\t? {}\n\t\t\t: { subjectCommonName: input.subjectCommonName }),\n\t\t...(input.actual === undefined ? {} : { actual: input.actual }),\n\t};\n\treturn Object.keys(details).length === 0 ? undefined : details;\n}\n\n/** A certificate is self-issued when subject and issuer DNs are semantically equal (RFC 5280 §7.1). */\nfunction isSelfIssued(certificate: ParsedCertificate): boolean {\n\treturn compareDistinguishedNames(certificate.subject, certificate.issuer);\n}\n\n/**\n * Initializes validation state from caller-supplied initial constraints.\n *\n * Call once before {@linkcode evaluateNameConstraints}.\n */\nexport function createNameConstraintValidationState(\n\tinput: InitialNameConstraintsInput,\n): NameConstraintValidationState {\n\treturn {\n\t\tinitialPermittedSubtrees: input.permittedSubtrees?.map((subtree) => subtree.base) ?? [],\n\t\tinitialExcludedSubtrees: input.excludedSubtrees?.map((subtree) => subtree.base) ?? [],\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Private: name constraint validation (RFC 5280 §4.2.1.10 / §6.1)\n// ---------------------------------------------------------------------------\n\n/** Empty SEQUENCE DER hex — represents an empty subject DN. */\nconst EMPTY_SEQUENCE_HEX = '3000';\n\n/**\n * Accumulated name constraint state during root-to-leaf traversal.\n * - `permittedLevels`: each entry is one CA's permittedSubtrees. A name\n * must match at least one entry in *every* level (intersection semantics).\n * - `excluded`: flat list; a name must NOT match *any* entry.\n */\ninterface AccumulatedNameConstraints {\n\t/** One entry per CA that asserted permittedSubtrees; intersection semantics. */\n\treadonly permittedLevels: readonly (readonly NameConstraintForm[])[];\n\t/** Flat union of all excludedSubtrees seen so far. */\n\treadonly excluded: readonly NameConstraintForm[];\n}\n\n/**\n * Walks the chain root-to-leaf, accumulating nameConstraints from CA\n * certificates and checking each non-self-issued certificate's names\n * against the accumulated constraints.\n *\n * RFC 5280 §6.1.3(b)–(c) for intermediates, §6.1.5(g) for the leaf.\n */\n\nexport function evaluateNameConstraints(\n\tchain: readonly ParsedCertificate[],\n\tstate: NameConstraintValidationState,\n): NameConstraintValidationResult {\n\tlet accumulated = seedInitialNameConstraints(state);\n\n\t// Seed constraints from the root (trust anchor). The root's own\n\t// names are not checked, but its nameConstraints apply to all\n\t// certificates below it in the chain.\n\tconst root = chain[chain.length - 1];\n\tif (root?.nameConstraints !== undefined) {\n\t\tconst unsupportedRoot = failOnUnsupportedNameConstraints(root, chain.length - 1);\n\t\tif (!unsupportedRoot.ok) {\n\t\t\treturn unsupportedRoot;\n\t\t}\n\t\taccumulated = accumulateConstraints(accumulated, root.nameConstraints);\n\t}\n\n\t// Walk from just below root toward leaf.\n\tfor (let index = chain.length - 2; index >= 0; index -= 1) {\n\t\tconst current = chain[index];\n\t\tif (current === undefined) {\n\t\t\tthrow new Error(`Certificate chain contains undefined at index ${String(index)}`);\n\t\t}\n\n\t\t// (b) If not self-issued, check names against accumulated constraints.\n\t\t// RFC 5280 §4.2.1.10: self-issued certificates are exempt UNLESS\n\t\t// they are the final certificate (leaf) in the path.\n\t\tif (!isSelfIssued(current) || index === 0) {\n\t\t\tconst nameCheckResult = checkCertificateNames(current, accumulated, index);\n\t\t\tif (!nameCheckResult.ok) {\n\t\t\t\treturn nameCheckResult;\n\t\t\t}\n\t\t}\n\n\t\t// (c) If this cert has nameConstraints, accumulate them.\n\t\tif (current.nameConstraints !== undefined) {\n\t\t\tconst unsupportedCurrent = failOnUnsupportedNameConstraints(current, index);\n\t\t\tif (!unsupportedCurrent.ok) {\n\t\t\t\treturn unsupportedCurrent;\n\t\t\t}\n\t\t\taccumulated = accumulateConstraints(accumulated, current.nameConstraints);\n\t\t}\n\t}\n\n\treturn { ok: true };\n}\n\n/** Converts initial state into the starting accumulated-constraints snapshot. */\nfunction seedInitialNameConstraints(\n\tstate: NameConstraintValidationState,\n): AccumulatedNameConstraints {\n\treturn {\n\t\tpermittedLevels:\n\t\t\tstate.initialPermittedSubtrees.length > 0 ? [state.initialPermittedSubtrees] : [],\n\t\texcluded: state.initialExcludedSubtrees,\n\t};\n}\n\n/** Merges one certificate's nameConstraints extension into the running totals. */\nfunction accumulateConstraints(\n\tcurrent: AccumulatedNameConstraints,\n\tconstraints: NameConstraints<ParsedNameConstraintForm>,\n): AccumulatedNameConstraints {\n\tconst permittedLevels =\n\t\tconstraints.permittedSubtrees !== undefined && constraints.permittedSubtrees.length > 0\n\t\t\t? [\n\t\t\t\t\t...current.permittedLevels,\n\t\t\t\t\tconstraints.permittedSubtrees.flatMap((subtree) =>\n\t\t\t\t\t\tisSupportedNameConstraintForm(subtree.base) ? [subtree.base] : [],\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t: current.permittedLevels;\n\tconst excluded =\n\t\tconstraints.excludedSubtrees !== undefined && constraints.excludedSubtrees.length > 0\n\t\t\t? [\n\t\t\t\t\t...current.excluded,\n\t\t\t\t\t...constraints.excludedSubtrees.flatMap((subtree) =>\n\t\t\t\t\t\tisSupportedNameConstraintForm(subtree.base) ? [subtree.base] : [],\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t: current.excluded;\n\treturn { permittedLevels, excluded };\n}\n\n/** Rejects the chain if a critical nameConstraints extension uses unsupported name forms. */\nfunction failOnUnsupportedNameConstraints(\n\tcertificate: ParsedCertificate,\n\tindex: number,\n): NameConstraintValidationResult {\n\tif (certificate.nameConstraints === undefined) {\n\t\treturn { ok: true };\n\t}\n\tconst hasCriticalNameConstraintsExtension = certificate.extensions.some(\n\t\t(entry) => entry.oid === OIDS.nameConstraints && entry.critical,\n\t);\n\tif (!hasCriticalNameConstraintsExtension) {\n\t\treturn { ok: true };\n\t}\n\tconst unsupportedTypes = listUnsupportedNameConstraintTypes(certificate.nameConstraints);\n\tif (unsupportedTypes.length === 0) {\n\t\treturn { ok: true };\n\t}\n\treturn nameConstraintFailure(\n\t\t'unsupported_name_constraints',\n\t\t'certificate contains unsupported critical name constraints',\n\t\tindex,\n\t\tnameConstraintDetails({\n\t\t\tsubjectCommonName: certificate.subject.values.commonName,\n\t\t\tactual: unsupportedTypes.join(', '),\n\t\t}),\n\t);\n}\n\n/** Collects the distinct unsupported GeneralName type strings from a nameConstraints extension. */\nfunction listUnsupportedNameConstraintTypes(\n\tconstraints: NameConstraints<ParsedNameConstraintForm>,\n): readonly string[] {\n\tconst unsupportedTypes = new Set<string>();\n\tfor (const subtree of constraints.permittedSubtrees ?? []) {\n\t\tif (!isSupportedNameConstraintForm(subtree.base)) {\n\t\t\tunsupportedTypes.add(subtree.base.type);\n\t\t}\n\t}\n\tfor (const subtree of constraints.excludedSubtrees ?? []) {\n\t\tif (!isSupportedNameConstraintForm(subtree.base)) {\n\t\t\tunsupportedTypes.add(subtree.base.type);\n\t\t}\n\t}\n\treturn [...unsupportedTypes];\n}\n\n/** True for name forms this engine can evaluate: dns, email, uri, ip, directoryName. */\nfunction isSupportedNameConstraintForm(form: ParsedNameConstraintForm): form is NameConstraintForm {\n\tswitch (form.type) {\n\t\tcase 'dns':\n\t\tcase 'email':\n\t\tcase 'uri':\n\t\tcase 'ip':\n\t\tcase 'directoryName':\n\t\t\treturn true;\n\t\tcase 'otherName':\n\t\tcase 'x400Address':\n\t\tcase 'ediPartyName':\n\t\tcase 'registeredID':\n\t\t\treturn false;\n\t\tdefault: {\n\t\t\tconst exhaustive: never = form;\n\t\t\tthrow new Error(`Unhandled NameConstraintForm type: ${String(exhaustive)}`);\n\t\t}\n\t}\n}\n\n/**\n * Checks a certificate's subject DN and SANs against accumulated\n * name constraints. Returns a failure if any name violates constraints.\n */\nfunction checkCertificateNames(\n\tcertificate: ParsedCertificate,\n\taccumulated: AccumulatedNameConstraints,\n\tindex: number,\n): NameConstraintValidationResult {\n\t// Check subject DN as directoryName (if non-empty).\n\tif (certificate.subject.derHex !== EMPTY_SEQUENCE_HEX) {\n\t\tconst dnResult = isNamePermitted(\n\t\t\t{ type: 'directoryName', derHex: certificate.subject.derHex },\n\t\t\taccumulated,\n\t\t);\n\t\tif (!dnResult) {\n\t\t\treturn nameConstraintFailure(\n\t\t\t\t'name_constraints_violated',\n\t\t\t\t'subject distinguished name violates name constraints',\n\t\t\t\tindex,\n\t\t\t\tnameConstraintDetails({\n\t\t\t\t\tsubjectCommonName: certificate.subject.values.commonName,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check each SAN.\n\tif (certificate.subjectAltNames !== undefined) {\n\t\tfor (const san of certificate.subjectAltNames) {\n\t\t\tconst checkableResult = sanToConstraintCheckable(san);\n\t\t\tif (!checkableResult.ok) {\n\t\t\t\treturn nameConstraintFailure(\n\t\t\t\t\t'name_constraints_violated',\n\t\t\t\t\t`SAN ${checkableResult.actual} is malformed and cannot be checked against name constraints`,\n\t\t\t\t\tindex,\n\t\t\t\t\tnameConstraintDetails({\n\t\t\t\t\t\tsubjectCommonName: certificate.subject.values.commonName,\n\t\t\t\t\t\tactual: checkableResult.actual,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst checkable = checkableResult.value;\n\t\t\tif (checkable === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!isNamePermitted(checkable, accumulated)) {\n\t\t\t\treturn nameConstraintFailure(\n\t\t\t\t\t'name_constraints_violated',\n\t\t\t\t\t`SAN ${formatConstraintForm(checkable)} violates name constraints`,\n\t\t\t\t\tindex,\n\t\t\t\t\tnameConstraintDetails({\n\t\t\t\t\t\tsubjectCommonName: certificate.subject.values.commonName,\n\t\t\t\t\t\tactual: formatConstraintForm(checkable),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// RFC 5280 §4.2.1.10: When constraints are imposed on the rfc822Name\n\t// name form, but the certificate does not include a SAN email, the\n\t// constraint MUST be applied to the emailAddress attribute in the\n\t// subject DN.\n\tconst hasEmailConstraints = accumulatedHasEmailConstraints(accumulated);\n\tif (hasEmailConstraints) {\n\t\tconst hasSanEmail = certificate.subjectAltNames?.some((san) => san.type === 'email') ?? false;\n\t\tif (!hasSanEmail && certificate.subject.values.emailAddress !== undefined) {\n\t\t\tconst emailForm: NameConstraintForm = {\n\t\t\t\ttype: 'email',\n\t\t\t\tvalue: certificate.subject.values.emailAddress,\n\t\t\t};\n\t\t\tif (!isNamePermitted(emailForm, accumulated)) {\n\t\t\t\treturn nameConstraintFailure(\n\t\t\t\t\t'name_constraints_violated',\n\t\t\t\t\t`subject emailAddress ${certificate.subject.values.emailAddress} violates name constraints`,\n\t\t\t\t\tindex,\n\t\t\t\t\tnameConstraintDetails({\n\t\t\t\t\t\tsubjectCommonName: certificate.subject.values.commonName,\n\t\t\t\t\t\tactual: certificate.subject.values.emailAddress,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { ok: true };\n}\n\n/** True when any level of accumulated constraints addresses the email name form. */\nfunction accumulatedHasEmailConstraints(accumulated: AccumulatedNameConstraints): boolean {\n\tfor (const level of accumulated.permittedLevels) {\n\t\tif (level.some((c) => c.type === 'email')) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn accumulated.excluded.some((c) => c.type === 'email');\n}\n\n/**\n * Converts a SubjectAltName to a NameConstraintForm for checking.\n * Returns `undefined` for name forms that don't participate in\n * constraint checking (unknown tags).\n */\nfunction sanToConstraintCheckable(san: SubjectAltName): SubjectAltNameCheckableResult {\n\tswitch (san.type) {\n\t\tcase 'dns':\n\t\t\treturn { ok: true, value: { type: 'dns', value: san.value } };\n\t\tcase 'email':\n\t\t\treturn { ok: true, value: { type: 'email', value: san.value } };\n\t\tcase 'uri':\n\t\t\treturn { ok: true, value: { type: 'uri', value: san.value } };\n\t\tcase 'srv':\n\t\t\treturn { ok: true, value: undefined };\n\t\tcase 'ip':\n\t\t\ttry {\n\t\t\t\treturn {\n\t\t\t\t\tok: true,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\ttype: 'ip',\n\t\t\t\t\t\taddressBytes: parseIpAddressToBytes(san.value),\n\t\t\t\t\t\tmaskBytes: allOnesMaskForIpAddress(san.value),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\tactual: `ip:${san.value}`,\n\t\t\t\t};\n\t\t\t}\n\t\tcase 'directoryName':\n\t\t\treturn { ok: true, value: { type: 'directoryName', derHex: san.derHex } };\n\t\tcase 'unknown':\n\t\t\treturn { ok: true, value: undefined };\n\t\tdefault: {\n\t\t\tconst exhaustive: never = san;\n\t\t\tthrow new Error(`Unhandled SubjectAltName type: ${String(exhaustive)}`);\n\t\t}\n\t}\n}\n\n/**\n * Checks whether a name is permitted by the accumulated constraints.\n * A name is permitted if:\n * 1. It does NOT match any excluded constraint, AND\n * 2. For every permitted level that contains constraints of the same\n * name form, it matches at least one.\n */\nfunction isNamePermitted(\n\tname: NameConstraintForm,\n\taccumulated: AccumulatedNameConstraints,\n): boolean {\n\t// Check excluded — if any match, reject.\n\tfor (const constraint of accumulated.excluded) {\n\t\tif (nameMatchesConstraint(name, constraint)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\t// Check permitted — for each level with relevant constraints,\n\t// the name must match at least one.\n\tfor (const level of accumulated.permittedLevels) {\n\t\tconst relevant = level.filter((constraint) => constraint.type === name.type);\n\t\tif (relevant.length === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (!relevant.some((constraint) => nameMatchesConstraint(name, constraint))) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/** Dispatches to the type-specific matching function for the name form. */\nfunction nameMatchesConstraint(name: NameConstraintForm, constraint: NameConstraintForm): boolean {\n\tif (name.type === 'dns' && constraint.type === 'dns') {\n\t\treturn matchesDnsConstraint(name.value, constraint.value);\n\t}\n\tif (name.type === 'email' && constraint.type === 'email') {\n\t\treturn matchesEmailConstraint(name.value, constraint.value);\n\t}\n\tif (name.type === 'uri' && constraint.type === 'uri') {\n\t\treturn matchesUriConstraint(name.value, constraint.value);\n\t}\n\tif (name.type === 'ip' && constraint.type === 'ip') {\n\t\treturn matchesIpConstraint(name.addressBytes, constraint.addressBytes, constraint.maskBytes);\n\t}\n\tif (name.type === 'directoryName' && constraint.type === 'directoryName') {\n\t\treturn matchesDnConstraint(name.derHex, constraint.derHex);\n\t}\n\treturn false;\n}\n\n/**\n * RFC 5280 §4.2.1.10: DNS name constraint matching.\n * Constraint \"example.com\" matches \"example.com\" and any subdomain.\n * Constraint \".example.com\" matches only subdomains, not \"example.com\" itself.\n */\nfunction matchesDnsConstraint(name: string, constraint: string): boolean {\n\tconst lowerName = name.toLowerCase();\n\tconst lowerConstraint = constraint.toLowerCase();\n\tif (lowerConstraint.length === 0) {\n\t\treturn true;\n\t}\n\tif (lowerConstraint.startsWith('.')) {\n\t\treturn lowerName.endsWith(lowerConstraint);\n\t}\n\treturn lowerName === lowerConstraint || lowerName.endsWith(`.${lowerConstraint}`);\n}\n\n/**\n * RFC 5280 §4.2.1.10: Email constraint matching.\n * - \"user@example.com\" matches only that exact address.\n * - \"example.com\" matches any address @example.com.\n * - \".example.com\" matches any address @subdomain.example.com.\n */\nfunction matchesEmailConstraint(name: string, constraint: string): boolean {\n\tconst lowerName = name.toLowerCase();\n\tconst lowerConstraint = constraint.toLowerCase();\n\tif (lowerConstraint.includes('@')) {\n\t\treturn lowerName === lowerConstraint;\n\t}\n\tconst atIndex = lowerName.indexOf('@');\n\tif (atIndex < 0) {\n\t\treturn false;\n\t}\n\tconst host = lowerName.slice(atIndex + 1);\n\tif (lowerConstraint.startsWith('.')) {\n\t\treturn host.endsWith(lowerConstraint);\n\t}\n\treturn host === lowerConstraint;\n}\n\n/**\n * RFC 5280 §4.2.1.10: URI constraint matching.\n * Applied to the host part of the URI.\n * - Constraint \".example.com\" matches subdomains only.\n * - Constraint \"example.com\" matches ONLY that exact host (no subdomain\n * expansion, unlike DNS constraints).\n */\nfunction matchesUriConstraint(uri: string, constraint: string): boolean {\n\tconst host = extractUriHost(uri);\n\tif (host === undefined) {\n\t\treturn false;\n\t}\n\tconst lowerHost = host.toLowerCase();\n\tconst lowerConstraint = constraint.toLowerCase();\n\tif (lowerConstraint.length === 0) {\n\t\treturn true;\n\t}\n\tif (lowerConstraint.startsWith('.')) {\n\t\treturn lowerHost.endsWith(lowerConstraint);\n\t}\n\t// Non-period constraint: exact host match only (RFC 5280 §4.2.1.10).\n\treturn lowerHost === lowerConstraint;\n}\n\n/** Extracts the host (reg-name) portion of a URI, stripping scheme, userinfo, port, and path. */\nfunction extractUriHost(uri: string): string | undefined {\n\ttry {\n\t\tconst url = new URL(uri);\n\t\treturn url.hostname;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * RFC 5280 §4.2.1.10: IP constraint matching.\n * (nameiP & mask) == (constraintiP & mask)\n */\nfunction matchesIpConstraint(\n\tnameBytes: Uint8Array,\n\tconstraintAddr: Uint8Array,\n\tconstraintMask: Uint8Array,\n): boolean {\n\tif (nameBytes.length !== constraintAddr.length) {\n\t\treturn false;\n\t}\n\tfor (let i = 0; i < nameBytes.length; i += 1) {\n\t\tconst nameByte = nameBytes[i] ?? 0;\n\t\tconst addrByte = constraintAddr[i] ?? 0;\n\t\tconst maskByte = constraintMask[i] ?? 0;\n\t\tif ((nameByte & maskByte) !== (addrByte & maskByte)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/**\n * RFC 5280 §4.2.1.10: DirectoryName constraint matching.\n * The subject DN must equal or be subordinate to the constraint DN,\n * using RFC 5280 section 7.1 name comparison semantics.\n */\nfunction matchesDnConstraint(subjectDerHex: string, constraintDerHex: string): boolean {\n\tconst subjectName = parseDirectoryNameDerHex(subjectDerHex);\n\tconst constraintName = parseDirectoryNameDerHex(constraintDerHex);\n\tif (subjectName === undefined || constraintName === undefined) {\n\t\treturn false;\n\t}\n\treturn isWithinDirectoryNameSubtree(subjectName, constraintName);\n}\n\n/** Re-parses a hex-encoded DER Name for RDN-by-RDN comparison. Returns `undefined` on malformed input. */\nfunction parseDirectoryNameDerHex(derHex: string): ParsedName | undefined {\n\tif (!/^(?:[0-9a-fA-F]{2})+$/.test(derHex)) {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\tconst bytes = hexToBytes(derHex);\n\t\tconst root = readRootElement(bytes, { maxDepth: DEFAULT_MAX_DER_DEPTH });\n\t\tconst element = unwrapDirectoryNameElement(bytes, root);\n\t\tif (element.tag !== 0x30) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst rdns: ParsedRelativeDistinguishedName[] = [];\n\t\tconst attributes: ParsedNameAttribute[] = [];\n\t\tconst values: ParsedName['values'] = {};\n\t\tfor (const setElement of childrenOf(bytes, element)) {\n\t\t\tconst rdn = parseDirectoryNameRdn(bytes, setElement);\n\t\t\tif (rdn === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\trdns.push(rdn);\n\t\t\tfor (const attribute of rdn.attributes) {\n\t\t\t\tattributes.push(attribute);\n\t\t\t\tif (attribute.key !== undefined && values[attribute.key] === undefined) {\n\t\t\t\t\tvalues[attribute.key] = attribute.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tderHex: toHex(bytes),\n\t\t\trdns,\n\t\t\tattributes,\n\t\t\tvalues,\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Unwraps doubly-nested directoryName SEQUENCE encoding.\n *\n * Some encoders produce `[4] { SEQ { SEQ { SET... } } }` instead of `[4] { SEQ { SET... } }`.\n * A single SEQUENCE child indicates the extra wrapper (valid Names have SET children).\n */\nfunction unwrapDirectoryNameElement(source: Uint8Array, element: DerElement): DerElement {\n\tif (element.tag !== 0x30) {\n\t\treturn element;\n\t}\n\tconst children = childrenOf(source, element);\n\tconst child = children[0];\n\tif (children.length === 1 && child?.tag === 0x30) {\n\t\treturn child;\n\t}\n\treturn element;\n}\n\n/** Parses one SET element (a single RDN) from the DER Name SEQUENCE. */\nfunction parseDirectoryNameRdn(\n\tsource: Uint8Array,\n\tsetElement: DerElement,\n): ParsedRelativeDistinguishedName | undefined {\n\tif (setElement.tag !== 0x31) {\n\t\treturn undefined;\n\t}\n\tconst children = childrenOf(source, setElement);\n\tif (children.length === 0) {\n\t\treturn undefined;\n\t}\n\tconst attributes: ParsedNameAttribute[] = [];\n\tconst values: ParsedName['values'] = {};\n\tfor (const attributeSequence of children) {\n\t\tif (attributeSequence.tag !== 0x30) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst parts = childrenOf(source, attributeSequence);\n\t\tconst oidElement = parts[0];\n\t\tconst valueElement = parts[1];\n\t\tif (oidElement === undefined || valueElement === undefined || parts.length !== 2) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (oidElement.tag !== 0x06) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst oid = decodeObjectIdentifier(requireElement(oidElement, 'directoryName OID').value);\n\t\tlet fieldValue: string;\n\t\ttry {\n\t\t\tfieldValue = decodeString(\n\t\t\t\tvalueElement.tag,\n\t\t\t\trequireElement(valueElement, 'directoryName value').value,\n\t\t\t);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst fieldKey = nameFieldKeyFromOid(oid);\n\t\tconst attribute: ParsedNameAttribute =\n\t\t\tfieldKey !== undefined\n\t\t\t\t? { oid, key: fieldKey, valueTag: valueElement.tag, value: fieldValue }\n\t\t\t\t: { oid, valueTag: valueElement.tag, value: fieldValue };\n\t\tattributes.push(attribute);\n\t\tif (fieldKey !== undefined && values[fieldKey] === undefined) {\n\t\t\tvalues[fieldKey] = fieldValue;\n\t\t}\n\t}\n\tif (attributes.length === 0) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tderHex: toHex(source.slice(setElement.start - setElement.headerLength, setElement.end)),\n\t\tattributes,\n\t\tvalues,\n\t};\n}\n\n/** Human-readable label for a constraint form, used in error messages. */\nfunction formatConstraintForm(form: NameConstraintForm): string {\n\tswitch (form.type) {\n\t\tcase 'dns':\n\t\t\treturn `dns:${form.value}`;\n\t\tcase 'email':\n\t\t\treturn `email:${form.value}`;\n\t\tcase 'uri':\n\t\t\treturn `uri:${form.value}`;\n\t\tcase 'ip':\n\t\t\treturn `ip:${decodeIpAddress(form.addressBytes)}`;\n\t\tcase 'directoryName':\n\t\t\treturn `dn:${form.derHex.slice(0, 20)}${form.derHex.length > 20 ? '...' : ''}`;\n\t\tdefault: {\n\t\t\tconst exhaustive = form;\n\t\t\tthrow new Error(`Unhandled NameConstraintForm type: ${String(exhaustive)}`);\n\t\t}\n\t}\n}\n"],"mappings":"ueA6GA,SAAS,EACR,EACA,EACA,EACA,EACkC,CAClC,MAAO,CACN,GAAI,GACJ,OACA,UACA,QACA,GAAI,IAAY,IAAA,GAAY,CAAC,EAAI,CAAE,SAAQ,CAC5C,CACD,CAGA,SAAS,EACR,EACqD,CACrD,IAAM,EAAkD,CACvD,GAAI,EAAM,oBAAsB,IAAA,GAC7B,CAAC,EACD,CAAE,kBAAmB,EAAM,iBAAkB,EAChD,GAAI,EAAM,SAAW,IAAA,GAAY,CAAC,EAAI,CAAE,OAAQ,EAAM,MAAO,CAC9D,EACA,OAAO,OA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/D,OAAQ,EAAK,KAAb,CACC,IAAK,MACJ,MAAO,OAAO,EAAK,QACpB,IAAK,QACJ,MAAO,SAAS,EAAK,QACtB,IAAK,MACJ,MAAO,OAAO,EAAK,QACpB,IAAK,KACJ,MAAO,MAAM,EAAgB,EAAK,YAAY,IAC/C,IAAK,gBACJ,MAAO,MAAM,EAAK,OAAO,MAAM,EAAG,EAAE,IAAI,EAAK,OAAO,OAAS,GAAK,MAAQ,KAC3E,QAEC,MAAU,MAAM,sCAAsC,OAAOA,CAAU,GAAG,CAE5E,CACD"}
|
|
1
|
+
{"version":3,"file":"name-constraints-engine.js","names":["exhaustive"],"sources":["../../../src/internal/verify/name-constraints-engine.ts"],"sourcesContent":["/**\n * Internal name-constraints evaluation engine.\n *\n * Accumulates and evaluates the shipped RFC 5280 §4.2.1.10 / §6.1\n * name-constraint subset during certificate path validation.\n *\n * @module\n */\n\nimport {\n\tchildrenOf,\n\tdecodeObjectIdentifier,\n\tdecodeString,\n\thexToBytes,\n\trequireElement,\n\ttoHex,\n} from '#micro509/internal/asn1/asn1.ts';\nimport {\n\tDEFAULT_MAX_DER_DEPTH,\n\ttype DerElement,\n\treadRootElement,\n} from '#micro509/internal/asn1/der.ts';\nimport { OIDS } from '#micro509/internal/asn1/oids.ts';\nimport {\n\tcompareDistinguishedNames,\n\tisWithinDirectoryNameSubtree,\n} from '#micro509/internal/shared/dn.ts';\nimport {\n\tallOnesMaskForIpAddress,\n\tdecodeIpAddress,\n\tparseIpAddressToBytes,\n} from '#micro509/internal/shared/ip.ts';\nimport type { Micro509Error } from '#micro509/result/result.ts';\nimport type { InitialNameConstraintsInput } from '#micro509/verify/name-constraints.ts';\nimport type {\n\tNameConstraintForm,\n\tNameConstraints,\n\tParsedNameConstraintForm,\n\tSubjectAltName,\n\tUnsupportedNameConstraintForm,\n} from '#micro509/x509/extensions.ts';\nimport { nameFieldKeyFromOid } from '#micro509/x509/name.ts';\nimport type {\n\tParsedCertificate,\n\tParsedName,\n\tParsedNameAttribute,\n\tParsedRelativeDistinguishedName,\n} from '#micro509/x509/parse.ts';\n\n/**\n * Opaque state seeded from {@linkcode InitialNameConstraintsInput} and consumed\n * by {@linkcode evaluateNameConstraints}.\n */\nexport interface NameConstraintValidationState {\n\t/** Caller-supplied permitted subtree bases (pre-chain). */\n\treadonly initialPermittedSubtrees: readonly NameConstraintForm[];\n\t/** Caller-supplied excluded subtree bases (pre-chain). */\n\treadonly initialExcludedSubtrees: readonly NameConstraintForm[];\n}\n\n/** Discriminant codes for name-constraint validation failures. */\nexport type NameConstraintValidationFailureCode =\n\t| 'name_constraints_violated'\n\t| 'unsupported_name_constraints';\n\n/** Diagnostic context attached to a name-constraint validation failure. */\nexport interface NameConstraintValidationFailureDetails {\n\t/** CN of the certificate whose name violated constraints, if available. */\n\treadonly subjectCommonName?: string;\n\t/** The name or constraint-type string that caused the violation. */\n\treadonly actual?: string;\n}\n\n/** A name-constraint check that failed, with the offending certificate's chain index. */\nexport interface NameConstraintValidationFailure\n\textends Micro509Error<\n\t\tNameConstraintValidationFailureCode,\n\t\tNameConstraintValidationFailureDetails\n\t> {\n\t/** Always `false` for failures. */\n\treadonly ok: false;\n\t/** Zero-based index into the chain of the certificate that violated constraints. */\n\treadonly index: number;\n}\n\n/** Success or failure outcome of name-constraint evaluation across a chain. */\nexport type NameConstraintValidationResult =\n\t| {\n\t\t\t/** All names in the chain satisfy accumulated constraints. */\n\t\t\treadonly ok: true;\n\t }\n\t| NameConstraintValidationFailure;\n\n/** Builder input for assembling optional failure detail fields. */\ninterface NameConstraintValidationFailureDetailsInput {\n\treadonly subjectCommonName?: string | undefined;\n\treadonly actual?: string | undefined;\n}\n\ntype SubjectAltNameCheckableResult =\n\t| {\n\t\t\treadonly ok: true;\n\t\t\treadonly value: NameConstraintForm | undefined;\n\t }\n\t| {\n\t\t\treadonly ok: false;\n\t\t\treadonly actual: string;\n\t };\n\n/** Constructs a {@linkcode NameConstraintValidationFailure} with optional details. */\nfunction nameConstraintFailure(\n\tcode: NameConstraintValidationFailureCode,\n\tmessage: string,\n\tindex: number,\n\tdetails?: NameConstraintValidationFailureDetails,\n): NameConstraintValidationFailure {\n\treturn {\n\t\tok: false,\n\t\tcode,\n\t\tmessage,\n\t\tindex,\n\t\t...(details === undefined ? {} : { details }),\n\t};\n}\n\n/** Strips undefined fields and returns `undefined` when all fields are empty. */\nfunction nameConstraintDetails(\n\tinput: NameConstraintValidationFailureDetailsInput,\n): NameConstraintValidationFailureDetails | undefined {\n\tconst details: NameConstraintValidationFailureDetails = {\n\t\t...(input.subjectCommonName === undefined\n\t\t\t? {}\n\t\t\t: { subjectCommonName: input.subjectCommonName }),\n\t\t...(input.actual === undefined ? {} : { actual: input.actual }),\n\t};\n\treturn Object.keys(details).length === 0 ? undefined : details;\n}\n\n/** A certificate is self-issued when subject and issuer DNs are semantically equal (RFC 5280 §7.1). */\nfunction isSelfIssued(certificate: ParsedCertificate): boolean {\n\treturn compareDistinguishedNames(certificate.subject, certificate.issuer);\n}\n\n/**\n * Initializes validation state from caller-supplied initial constraints.\n *\n * Call once before {@linkcode evaluateNameConstraints}.\n */\nexport function createNameConstraintValidationState(\n\tinput: InitialNameConstraintsInput,\n): NameConstraintValidationState {\n\treturn {\n\t\tinitialPermittedSubtrees: input.permittedSubtrees?.map((subtree) => subtree.base) ?? [],\n\t\tinitialExcludedSubtrees: input.excludedSubtrees?.map((subtree) => subtree.base) ?? [],\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Private: name constraint validation (RFC 5280 §4.2.1.10 / §6.1)\n// ---------------------------------------------------------------------------\n\n/** Empty SEQUENCE DER hex — represents an empty subject DN. */\nconst EMPTY_SEQUENCE_HEX = '3000';\n\n/**\n * Accumulated name constraint state during root-to-leaf traversal.\n * - `permittedLevels`: each entry is one CA's permittedSubtrees. A name\n * must match at least one entry in *every* level (intersection semantics).\n * - `excluded`: flat list; a name must NOT match *any* entry.\n */\ninterface AccumulatedNameConstraints {\n\t/** One entry per CA that asserted permittedSubtrees; intersection semantics. */\n\treadonly permittedLevels: readonly (readonly NameConstraintForm[])[];\n\t/** Flat union of all excludedSubtrees seen so far. */\n\treadonly excluded: readonly NameConstraintForm[];\n\t/**\n\t * Name forms this engine cannot evaluate that were imposed by a\n\t * **critical** nameConstraints extension above. RFC 5280 §4.2.1.10:\n\t * a subsequent certificate carrying a name of such a form MUST be\n\t * rejected; certificates without one stay acceptable.\n\t */\n\treadonly unsupportedCriticalForms: ReadonlySet<UnsupportedNameConstraintForm['type']>;\n}\n\n/**\n * Walks the chain root-to-leaf, accumulating nameConstraints from CA\n * certificates and checking each non-self-issued certificate's names\n * against the accumulated constraints.\n *\n * RFC 5280 §6.1.3(b)–(c) for intermediates, §6.1.5(g) for the leaf.\n */\n\nexport function evaluateNameConstraints(\n\tchain: readonly ParsedCertificate[],\n\tstate: NameConstraintValidationState,\n): NameConstraintValidationResult {\n\tlet accumulated = seedInitialNameConstraints(state);\n\n\t// Seed constraints from the root (trust anchor). The root's own\n\t// names are not checked, but its nameConstraints apply to all\n\t// certificates below it in the chain.\n\tconst root = chain[chain.length - 1];\n\tif (root?.nameConstraints !== undefined) {\n\t\taccumulated = accumulateConstraints(\n\t\t\taccumulated,\n\t\t\troot.nameConstraints,\n\t\t\thasCriticalNameConstraintsExtension(root),\n\t\t);\n\t}\n\n\t// Walk from just below root toward leaf.\n\tfor (let index = chain.length - 2; index >= 0; index -= 1) {\n\t\tconst current = chain[index];\n\t\tif (current === undefined) {\n\t\t\tthrow new Error(`Certificate chain contains undefined at index ${String(index)}`);\n\t\t}\n\n\t\t// (b) If not self-issued, check names against accumulated constraints.\n\t\t// RFC 5280 §4.2.1.10: self-issued certificates are exempt UNLESS\n\t\t// they are the final certificate (leaf) in the path.\n\t\tif (!isSelfIssued(current) || index === 0) {\n\t\t\tconst nameCheckResult = checkCertificateNames(current, accumulated, index);\n\t\t\tif (!nameCheckResult.ok) {\n\t\t\t\treturn nameCheckResult;\n\t\t\t}\n\t\t}\n\n\t\t// (c) If this cert has nameConstraints, accumulate them.\n\t\tif (current.nameConstraints !== undefined) {\n\t\t\taccumulated = accumulateConstraints(\n\t\t\t\taccumulated,\n\t\t\t\tcurrent.nameConstraints,\n\t\t\t\thasCriticalNameConstraintsExtension(current),\n\t\t\t);\n\t\t}\n\t}\n\n\treturn { ok: true };\n}\n\n/** True when the certificate carries a critical nameConstraints extension. */\nfunction hasCriticalNameConstraintsExtension(certificate: ParsedCertificate): boolean {\n\treturn certificate.extensions.some(\n\t\t(entry) => entry.oid === OIDS.nameConstraints && entry.critical,\n\t);\n}\n\n/** Converts initial state into the starting accumulated-constraints snapshot. */\nfunction seedInitialNameConstraints(\n\tstate: NameConstraintValidationState,\n): AccumulatedNameConstraints {\n\treturn {\n\t\tpermittedLevels:\n\t\t\tstate.initialPermittedSubtrees.length > 0 ? [state.initialPermittedSubtrees] : [],\n\t\texcluded: state.initialExcludedSubtrees,\n\t\tunsupportedCriticalForms: new Set(),\n\t};\n}\n\n/**\n * Merges one certificate's nameConstraints extension into the running totals.\n *\n * Unsupported constraint forms from a critical extension are recorded so\n * subsequent certificates carrying a name of that form fail closed\n * (RFC 5280 §4.2.1.10). Unsupported forms in a non-critical extension are\n * dropped — the RFC's rejection requirement is scoped to critical\n * extensions (conforming CAs MUST mark nameConstraints critical anyway).\n */\nfunction accumulateConstraints(\n\tcurrent: AccumulatedNameConstraints,\n\tconstraints: NameConstraints<ParsedNameConstraintForm>,\n\tcritical: boolean,\n): AccumulatedNameConstraints {\n\tconst permittedLevels =\n\t\tconstraints.permittedSubtrees !== undefined && constraints.permittedSubtrees.length > 0\n\t\t\t? [\n\t\t\t\t\t...current.permittedLevels,\n\t\t\t\t\tconstraints.permittedSubtrees.flatMap((subtree) =>\n\t\t\t\t\t\tisSupportedNameConstraintForm(subtree.base) ? [subtree.base] : [],\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t: current.permittedLevels;\n\tconst excluded =\n\t\tconstraints.excludedSubtrees !== undefined && constraints.excludedSubtrees.length > 0\n\t\t\t? [\n\t\t\t\t\t...current.excluded,\n\t\t\t\t\t...constraints.excludedSubtrees.flatMap((subtree) =>\n\t\t\t\t\t\tisSupportedNameConstraintForm(subtree.base) ? [subtree.base] : [],\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t: current.excluded;\n\tconst newUnsupported = critical ? listUnsupportedNameConstraintTypes(constraints) : [];\n\tconst unsupportedCriticalForms =\n\t\tnewUnsupported.length > 0\n\t\t\t? new Set([...current.unsupportedCriticalForms, ...newUnsupported])\n\t\t\t: current.unsupportedCriticalForms;\n\treturn { permittedLevels, excluded, unsupportedCriticalForms };\n}\n\n/** Collects the distinct unsupported GeneralName form types from a nameConstraints extension. */\nfunction listUnsupportedNameConstraintTypes(\n\tconstraints: NameConstraints<ParsedNameConstraintForm>,\n): readonly UnsupportedNameConstraintForm['type'][] {\n\tconst unsupportedTypes = new Set<UnsupportedNameConstraintForm['type']>();\n\tfor (const subtree of constraints.permittedSubtrees ?? []) {\n\t\tif (!isSupportedNameConstraintForm(subtree.base)) {\n\t\t\tunsupportedTypes.add(subtree.base.type);\n\t\t}\n\t}\n\tfor (const subtree of constraints.excludedSubtrees ?? []) {\n\t\tif (!isSupportedNameConstraintForm(subtree.base)) {\n\t\t\tunsupportedTypes.add(subtree.base.type);\n\t\t}\n\t}\n\treturn [...unsupportedTypes];\n}\n\n/** True for name forms this engine can evaluate: dns, email, uri, ip, directoryName. */\nfunction isSupportedNameConstraintForm(form: ParsedNameConstraintForm): form is NameConstraintForm {\n\tswitch (form.type) {\n\t\tcase 'dns':\n\t\tcase 'email':\n\t\tcase 'uri':\n\t\tcase 'ip':\n\t\tcase 'directoryName':\n\t\t\treturn true;\n\t\tcase 'otherName':\n\t\tcase 'x400Address':\n\t\tcase 'ediPartyName':\n\t\tcase 'registeredID':\n\t\t\treturn false;\n\t\tdefault: {\n\t\t\tconst exhaustive: never = form;\n\t\t\tthrow new Error(`Unhandled NameConstraintForm type: ${String(exhaustive)}`);\n\t\t}\n\t}\n}\n\n/**\n * Checks a certificate's subject DN and SANs against accumulated\n * name constraints. Returns a failure if any name violates constraints.\n */\nfunction checkCertificateNames(\n\tcertificate: ParsedCertificate,\n\taccumulated: AccumulatedNameConstraints,\n\tindex: number,\n): NameConstraintValidationResult {\n\t// Check subject DN as directoryName (if non-empty).\n\tif (certificate.subject.derHex !== EMPTY_SEQUENCE_HEX) {\n\t\tconst dnResult = isNamePermitted(\n\t\t\t{ type: 'directoryName', derHex: certificate.subject.derHex },\n\t\t\taccumulated,\n\t\t);\n\t\tif (!dnResult) {\n\t\t\treturn nameConstraintFailure(\n\t\t\t\t'name_constraints_violated',\n\t\t\t\t'subject distinguished name violates name constraints',\n\t\t\t\tindex,\n\t\t\t\tnameConstraintDetails({\n\t\t\t\t\tsubjectCommonName: certificate.subject.values.commonName,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t}\n\n\t// Check each SAN.\n\tif (certificate.subjectAltNames !== undefined) {\n\t\tfor (const san of certificate.subjectAltNames) {\n\t\t\t// RFC 5280 §4.2.1.10: a critical nameConstraints extension imposing\n\t\t\t// constraints on a name form this engine cannot process forces\n\t\t\t// rejection of any subsequent certificate carrying that form.\n\t\t\tconst unsupportedForm = sanUnsupportedFormType(san);\n\t\t\tif (\n\t\t\t\tunsupportedForm !== undefined &&\n\t\t\t\taccumulated.unsupportedCriticalForms.has(unsupportedForm)\n\t\t\t) {\n\t\t\t\treturn nameConstraintFailure(\n\t\t\t\t\t'unsupported_name_constraints',\n\t\t\t\t\t`critical name constraints impose ${unsupportedForm} constraints that cannot be processed, and the certificate contains a ${unsupportedForm} subject alternative name`,\n\t\t\t\t\tindex,\n\t\t\t\t\tnameConstraintDetails({\n\t\t\t\t\t\tsubjectCommonName: certificate.subject.values.commonName,\n\t\t\t\t\t\tactual: unsupportedForm,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst checkableResult = sanToConstraintCheckable(san);\n\t\t\tif (!checkableResult.ok) {\n\t\t\t\treturn nameConstraintFailure(\n\t\t\t\t\t'name_constraints_violated',\n\t\t\t\t\t`SAN ${checkableResult.actual} is malformed and cannot be checked against name constraints`,\n\t\t\t\t\tindex,\n\t\t\t\t\tnameConstraintDetails({\n\t\t\t\t\t\tsubjectCommonName: certificate.subject.values.commonName,\n\t\t\t\t\t\tactual: checkableResult.actual,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst checkable = checkableResult.value;\n\t\t\tif (checkable === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!isNamePermitted(checkable, accumulated)) {\n\t\t\t\treturn nameConstraintFailure(\n\t\t\t\t\t'name_constraints_violated',\n\t\t\t\t\t`SAN ${formatConstraintForm(checkable)} violates name constraints`,\n\t\t\t\t\tindex,\n\t\t\t\t\tnameConstraintDetails({\n\t\t\t\t\t\tsubjectCommonName: certificate.subject.values.commonName,\n\t\t\t\t\t\tactual: formatConstraintForm(checkable),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// RFC 5280 §4.2.1.10: When constraints are imposed on the rfc822Name\n\t// name form, but the certificate does not include a SAN email, the\n\t// constraint MUST be applied to the emailAddress attribute in the\n\t// subject DN.\n\tconst hasEmailConstraints = accumulatedHasEmailConstraints(accumulated);\n\tif (hasEmailConstraints) {\n\t\tconst hasSanEmail = certificate.subjectAltNames?.some((san) => san.type === 'email') ?? false;\n\t\tif (!hasSanEmail && certificate.subject.values.emailAddress !== undefined) {\n\t\t\tconst emailForm: NameConstraintForm = {\n\t\t\t\ttype: 'email',\n\t\t\t\tvalue: certificate.subject.values.emailAddress,\n\t\t\t};\n\t\t\tif (!isNamePermitted(emailForm, accumulated)) {\n\t\t\t\treturn nameConstraintFailure(\n\t\t\t\t\t'name_constraints_violated',\n\t\t\t\t\t`subject emailAddress ${certificate.subject.values.emailAddress} violates name constraints`,\n\t\t\t\t\tindex,\n\t\t\t\t\tnameConstraintDetails({\n\t\t\t\t\t\tsubjectCommonName: certificate.subject.values.commonName,\n\t\t\t\t\t\tactual: certificate.subject.values.emailAddress,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { ok: true };\n}\n\n/** True when any level of accumulated constraints addresses the email name form. */\nfunction accumulatedHasEmailConstraints(accumulated: AccumulatedNameConstraints): boolean {\n\tfor (const level of accumulated.permittedLevels) {\n\t\tif (level.some((c) => c.type === 'email')) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn accumulated.excluded.some((c) => c.type === 'email');\n}\n\n/**\n * Maps a SAN to the unsupported constraint form it instantiates, if any.\n *\n * SRV-ID SANs are otherName [0] instances. Unknown SANs carry the full DER\n * tag byte: 0xa0 otherName [0], 0xa3 x400Address [3], 0xa5 ediPartyName [5],\n * 0x88 registeredID [8].\n */\nfunction sanUnsupportedFormType(\n\tsan: SubjectAltName,\n): UnsupportedNameConstraintForm['type'] | undefined {\n\tif (san.type === 'srv') {\n\t\treturn 'otherName';\n\t}\n\tif (san.type !== 'unknown') {\n\t\treturn undefined;\n\t}\n\tswitch (san.tag) {\n\t\tcase 0xa0:\n\t\t\treturn 'otherName';\n\t\tcase 0xa3:\n\t\t\treturn 'x400Address';\n\t\tcase 0xa5:\n\t\t\treturn 'ediPartyName';\n\t\tcase 0x88:\n\t\t\treturn 'registeredID';\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\n/**\n * Converts a SubjectAltName to a NameConstraintForm for checking.\n * Returns `undefined` for name forms that don't participate in\n * constraint checking (unknown tags).\n */\nfunction sanToConstraintCheckable(san: SubjectAltName): SubjectAltNameCheckableResult {\n\tswitch (san.type) {\n\t\tcase 'dns':\n\t\t\treturn { ok: true, value: { type: 'dns', value: san.value } };\n\t\tcase 'email':\n\t\t\treturn { ok: true, value: { type: 'email', value: san.value } };\n\t\tcase 'uri':\n\t\t\treturn { ok: true, value: { type: 'uri', value: san.value } };\n\t\tcase 'srv':\n\t\t\treturn { ok: true, value: undefined };\n\t\tcase 'ip':\n\t\t\ttry {\n\t\t\t\treturn {\n\t\t\t\t\tok: true,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\ttype: 'ip',\n\t\t\t\t\t\taddressBytes: parseIpAddressToBytes(san.value),\n\t\t\t\t\t\tmaskBytes: allOnesMaskForIpAddress(san.value),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\tactual: `ip:${san.value}`,\n\t\t\t\t};\n\t\t\t}\n\t\tcase 'directoryName':\n\t\t\treturn { ok: true, value: { type: 'directoryName', derHex: san.derHex } };\n\t\tcase 'unknown':\n\t\t\treturn { ok: true, value: undefined };\n\t\tdefault: {\n\t\t\tconst exhaustive: never = san;\n\t\t\tthrow new Error(`Unhandled SubjectAltName type: ${String(exhaustive)}`);\n\t\t}\n\t}\n}\n\n/**\n * Checks whether a name is permitted by the accumulated constraints.\n * A name is permitted if:\n * 1. It does NOT match any excluded constraint, AND\n * 2. For every permitted level that contains constraints of the same\n * name form, it matches at least one.\n */\nfunction isNamePermitted(\n\tname: NameConstraintForm,\n\taccumulated: AccumulatedNameConstraints,\n): boolean {\n\t// Check excluded — if any match, reject.\n\tfor (const constraint of accumulated.excluded) {\n\t\tif (nameMatchesConstraint(name, constraint)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\t// Check permitted — for each level with relevant constraints,\n\t// the name must match at least one.\n\tfor (const level of accumulated.permittedLevels) {\n\t\tconst relevant = level.filter((constraint) => constraint.type === name.type);\n\t\tif (relevant.length === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (!relevant.some((constraint) => nameMatchesConstraint(name, constraint))) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/** Dispatches to the type-specific matching function for the name form. */\nfunction nameMatchesConstraint(name: NameConstraintForm, constraint: NameConstraintForm): boolean {\n\tif (name.type === 'dns' && constraint.type === 'dns') {\n\t\treturn matchesDnsConstraint(name.value, constraint.value);\n\t}\n\tif (name.type === 'email' && constraint.type === 'email') {\n\t\treturn matchesEmailConstraint(name.value, constraint.value);\n\t}\n\tif (name.type === 'uri' && constraint.type === 'uri') {\n\t\treturn matchesUriConstraint(name.value, constraint.value);\n\t}\n\tif (name.type === 'ip' && constraint.type === 'ip') {\n\t\treturn matchesIpConstraint(name.addressBytes, constraint.addressBytes, constraint.maskBytes);\n\t}\n\tif (name.type === 'directoryName' && constraint.type === 'directoryName') {\n\t\treturn matchesDnConstraint(name.derHex, constraint.derHex);\n\t}\n\treturn false;\n}\n\n/**\n * RFC 5280 §4.2.1.10: DNS name constraint matching.\n * Constraint \"example.com\" matches \"example.com\" and any subdomain.\n * Constraint \".example.com\" matches only subdomains, not \"example.com\" itself.\n */\nfunction matchesDnsConstraint(name: string, constraint: string): boolean {\n\tconst lowerName = name.toLowerCase();\n\tconst lowerConstraint = constraint.toLowerCase();\n\tif (lowerConstraint.length === 0) {\n\t\treturn true;\n\t}\n\tif (lowerConstraint.startsWith('.')) {\n\t\treturn lowerName.endsWith(lowerConstraint);\n\t}\n\treturn lowerName === lowerConstraint || lowerName.endsWith(`.${lowerConstraint}`);\n}\n\n/**\n * RFC 5280 §4.2.1.10: Email constraint matching.\n * - \"user@example.com\" matches only that exact address.\n * - \"example.com\" matches any address @example.com.\n * - \".example.com\" matches any address @subdomain.example.com.\n */\nfunction matchesEmailConstraint(name: string, constraint: string): boolean {\n\tconst lowerName = name.toLowerCase();\n\tconst lowerConstraint = constraint.toLowerCase();\n\tif (lowerConstraint.includes('@')) {\n\t\treturn lowerName === lowerConstraint;\n\t}\n\tconst atIndex = lowerName.indexOf('@');\n\tif (atIndex < 0) {\n\t\treturn false;\n\t}\n\tconst host = lowerName.slice(atIndex + 1);\n\tif (lowerConstraint.startsWith('.')) {\n\t\treturn host.endsWith(lowerConstraint);\n\t}\n\treturn host === lowerConstraint;\n}\n\n/**\n * RFC 5280 §4.2.1.10: URI constraint matching.\n * Applied to the host part of the URI.\n * - Constraint \".example.com\" matches subdomains only.\n * - Constraint \"example.com\" matches ONLY that exact host (no subdomain\n * expansion, unlike DNS constraints).\n */\nfunction matchesUriConstraint(uri: string, constraint: string): boolean {\n\tconst host = extractUriHost(uri);\n\tif (host === undefined) {\n\t\treturn false;\n\t}\n\tconst lowerHost = host.toLowerCase();\n\tconst lowerConstraint = constraint.toLowerCase();\n\tif (lowerConstraint.length === 0) {\n\t\treturn true;\n\t}\n\tif (lowerConstraint.startsWith('.')) {\n\t\treturn lowerHost.endsWith(lowerConstraint);\n\t}\n\t// Non-period constraint: exact host match only (RFC 5280 §4.2.1.10).\n\treturn lowerHost === lowerConstraint;\n}\n\n/** Extracts the host (reg-name) portion of a URI, stripping scheme, userinfo, port, and path. */\nfunction extractUriHost(uri: string): string | undefined {\n\ttry {\n\t\tconst url = new URL(uri);\n\t\treturn url.hostname;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * RFC 5280 §4.2.1.10: IP constraint matching.\n * (nameiP & mask) == (constraintiP & mask)\n */\nfunction matchesIpConstraint(\n\tnameBytes: Uint8Array,\n\tconstraintAddr: Uint8Array,\n\tconstraintMask: Uint8Array,\n): boolean {\n\tif (nameBytes.length !== constraintAddr.length) {\n\t\treturn false;\n\t}\n\tfor (let i = 0; i < nameBytes.length; i += 1) {\n\t\tconst nameByte = nameBytes[i] ?? 0;\n\t\tconst addrByte = constraintAddr[i] ?? 0;\n\t\tconst maskByte = constraintMask[i] ?? 0;\n\t\tif ((nameByte & maskByte) !== (addrByte & maskByte)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/**\n * RFC 5280 §4.2.1.10: DirectoryName constraint matching.\n * The subject DN must equal or be subordinate to the constraint DN,\n * using RFC 5280 section 7.1 name comparison semantics.\n */\nfunction matchesDnConstraint(subjectDerHex: string, constraintDerHex: string): boolean {\n\tconst subjectName = parseDirectoryNameDerHex(subjectDerHex);\n\tconst constraintName = parseDirectoryNameDerHex(constraintDerHex);\n\tif (subjectName === undefined || constraintName === undefined) {\n\t\treturn false;\n\t}\n\treturn isWithinDirectoryNameSubtree(subjectName, constraintName);\n}\n\n/** Re-parses a hex-encoded DER Name for RDN-by-RDN comparison. Returns `undefined` on malformed input. */\nfunction parseDirectoryNameDerHex(derHex: string): ParsedName | undefined {\n\tif (!/^(?:[0-9a-fA-F]{2})+$/.test(derHex)) {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\tconst bytes = hexToBytes(derHex);\n\t\tconst root = readRootElement(bytes, { maxDepth: DEFAULT_MAX_DER_DEPTH });\n\t\tconst element = unwrapDirectoryNameElement(bytes, root);\n\t\tif (element.tag !== 0x30) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst rdns: ParsedRelativeDistinguishedName[] = [];\n\t\tconst attributes: ParsedNameAttribute[] = [];\n\t\tconst values: ParsedName['values'] = {};\n\t\tfor (const setElement of childrenOf(bytes, element)) {\n\t\t\tconst rdn = parseDirectoryNameRdn(bytes, setElement);\n\t\t\tif (rdn === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\trdns.push(rdn);\n\t\t\tfor (const attribute of rdn.attributes) {\n\t\t\t\tattributes.push(attribute);\n\t\t\t\tif (attribute.key !== undefined && values[attribute.key] === undefined) {\n\t\t\t\t\tvalues[attribute.key] = attribute.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tderHex: toHex(bytes),\n\t\t\trdns,\n\t\t\tattributes,\n\t\t\tvalues,\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Unwraps doubly-nested directoryName SEQUENCE encoding.\n *\n * Some encoders produce `[4] { SEQ { SEQ { SET... } } }` instead of `[4] { SEQ { SET... } }`.\n * A single SEQUENCE child indicates the extra wrapper (valid Names have SET children).\n */\nfunction unwrapDirectoryNameElement(source: Uint8Array, element: DerElement): DerElement {\n\tif (element.tag !== 0x30) {\n\t\treturn element;\n\t}\n\tconst children = childrenOf(source, element);\n\tconst child = children[0];\n\tif (children.length === 1 && child?.tag === 0x30) {\n\t\treturn child;\n\t}\n\treturn element;\n}\n\n/** Parses one SET element (a single RDN) from the DER Name SEQUENCE. */\nfunction parseDirectoryNameRdn(\n\tsource: Uint8Array,\n\tsetElement: DerElement,\n): ParsedRelativeDistinguishedName | undefined {\n\tif (setElement.tag !== 0x31) {\n\t\treturn undefined;\n\t}\n\tconst children = childrenOf(source, setElement);\n\tif (children.length === 0) {\n\t\treturn undefined;\n\t}\n\tconst attributes: ParsedNameAttribute[] = [];\n\tconst values: ParsedName['values'] = {};\n\tfor (const attributeSequence of children) {\n\t\tif (attributeSequence.tag !== 0x30) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst parts = childrenOf(source, attributeSequence);\n\t\tconst oidElement = parts[0];\n\t\tconst valueElement = parts[1];\n\t\tif (oidElement === undefined || valueElement === undefined || parts.length !== 2) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (oidElement.tag !== 0x06) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst oid = decodeObjectIdentifier(requireElement(oidElement, 'directoryName OID').value);\n\t\tlet fieldValue: string;\n\t\ttry {\n\t\t\tfieldValue = decodeString(\n\t\t\t\tvalueElement.tag,\n\t\t\t\trequireElement(valueElement, 'directoryName value').value,\n\t\t\t);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst fieldKey = nameFieldKeyFromOid(oid);\n\t\tconst attribute: ParsedNameAttribute =\n\t\t\tfieldKey !== undefined\n\t\t\t\t? { oid, key: fieldKey, valueTag: valueElement.tag, value: fieldValue }\n\t\t\t\t: { oid, valueTag: valueElement.tag, value: fieldValue };\n\t\tattributes.push(attribute);\n\t\tif (fieldKey !== undefined && values[fieldKey] === undefined) {\n\t\t\tvalues[fieldKey] = fieldValue;\n\t\t}\n\t}\n\tif (attributes.length === 0) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tderHex: toHex(source.slice(setElement.start - setElement.headerLength, setElement.end)),\n\t\tattributes,\n\t\tvalues,\n\t};\n}\n\n/** Human-readable label for a constraint form, used in error messages. */\nfunction formatConstraintForm(form: NameConstraintForm): string {\n\tswitch (form.type) {\n\t\tcase 'dns':\n\t\t\treturn `dns:${form.value}`;\n\t\tcase 'email':\n\t\t\treturn `email:${form.value}`;\n\t\tcase 'uri':\n\t\t\treturn `uri:${form.value}`;\n\t\tcase 'ip':\n\t\t\treturn `ip:${decodeIpAddress(form.addressBytes)}`;\n\t\tcase 'directoryName':\n\t\t\treturn `dn:${form.derHex.slice(0, 20)}${form.derHex.length > 20 ? '...' : ''}`;\n\t\tdefault: {\n\t\t\tconst exhaustive = form;\n\t\t\tthrow new Error(`Unhandled NameConstraintForm type: ${String(exhaustive)}`);\n\t\t}\n\t}\n}\n"],"mappings":"ueA8GA,SAAS,EACR,EACA,EACA,EACA,EACkC,CAClC,MAAO,CACN,GAAI,GACJ,OACA,UACA,QACA,GAAI,IAAY,IAAA,GAAY,CAAC,EAAI,CAAE,SAAQ,CAC5C,CACD,CAGA,SAAS,EACR,EACqD,CACrD,IAAM,EAAkD,CACvD,GAAI,EAAM,oBAAsB,IAAA,GAC7B,CAAC,EACD,CAAE,kBAAmB,EAAM,iBAAkB,EAChD,GAAI,EAAM,SAAW,IAAA,GAAY,CAAC,EAAI,CAAE,OAAQ,EAAM,MAAO,CAC9D,EACA,OAAO,OAAO,KAAK,CAAO,CAAC,CAAC,SAAW,EAAI,IAAA,GAAY,CACxD,CAGA,SAAS,EAAa,EAAyC,CAC9D,OAAO,EAA0B,EAAY,QAAS,EAAY,MAAM,CACzE,CAOA,SAAgB,EACf,EACgC,CAChC,MAAO,CACN,yBAA0B,EAAM,mBAAmB,IAAK,GAAY,EAAQ,IAAI,GAAK,CAAC,EACtF,wBAAyB,EAAM,kBAAkB,IAAK,GAAY,EAAQ,IAAI,GAAK,CAAC,CACrF,CACD,CAqCA,SAAgB,EACf,EACA,EACiC,CACjC,IAAI,EAAc,EAA2B,CAAK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C/C,IAAK,gBACJ,MAAO,MAAM,EAAK,OAAO,MAAM,EAAG,EAAE,IAAI,EAAK,OAAO,OAAS,GAAK,MAAQ,KAC3E,QAEC,MAAU,MAAM,sCAAsC,OAAOA,CAAU,GAAG,CAE5E,CACD"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ParsedCertificate } from "../x509/parse.js";
|
|
2
2
|
import { CrlSource, RevocationReason } from "./crl.js";
|
|
3
|
+
import { OcspResponderRevocationPolicy } from "./ocsp.js";
|
|
3
4
|
|
|
4
5
|
//#region src/revocation/chain.d.ts
|
|
5
6
|
/**
|
|
@@ -38,11 +39,19 @@ interface RevocationPolicy {
|
|
|
38
39
|
* Preference only decides which source's `good` verdict is reported when
|
|
39
40
|
* both yield one.
|
|
40
41
|
*
|
|
41
|
-
* - `'best-available'`:
|
|
42
|
+
* - `'best-available'`: the source with the fresher evidence — the later
|
|
43
|
+
* `thisUpdate` on the validated OCSP entry or CRL — is reported; ties
|
|
44
|
+
* favor OCSP (default)
|
|
42
45
|
* - `'ocsp'`: prefer OCSP over CRL
|
|
43
46
|
* - `'crl'`: prefer CRL over OCSP
|
|
44
47
|
*/
|
|
45
48
|
readonly prefer?: "ocsp" | "crl" | "best-available";
|
|
49
|
+
/**
|
|
50
|
+
* Revocation policy for delegated OCSP responder certificates
|
|
51
|
+
* (RFC 6960 §4.2.2.2.1). Supplied CRLs double as responder revocation
|
|
52
|
+
* evidence. Defaults to `'honor-nocheck'`.
|
|
53
|
+
*/
|
|
54
|
+
readonly ocspResponderRevocation?: OcspResponderRevocationPolicy;
|
|
46
55
|
}
|
|
47
56
|
/** Input for {@linkcode checkChainRevocation}. */
|
|
48
57
|
interface CheckChainRevocationInput {
|
|
@@ -54,6 +63,12 @@ interface CheckChainRevocationInput {
|
|
|
54
63
|
readonly ocspResponses?: readonly OcspResponseSource[];
|
|
55
64
|
/** Extra certs for indirect CRL issuers / delegated OCSP responders. */
|
|
56
65
|
readonly extraCertificates?: readonly CertificateSource[];
|
|
66
|
+
/**
|
|
67
|
+
* Explicitly trusted OCSP responder certificates (RFC 6960 §4.2.2.2
|
|
68
|
+
* criterion 1). A response signed by one of these is accepted without
|
|
69
|
+
* delegated-responder issuance, EKU, and revocation checks.
|
|
70
|
+
*/
|
|
71
|
+
readonly trustedOcspResponders?: readonly CertificateSource[];
|
|
57
72
|
/** Evaluation time. Defaults to `new Date()`. */
|
|
58
73
|
readonly at?: Date;
|
|
59
74
|
/** Revocation policy. */
|
|
@@ -86,6 +101,12 @@ interface RevocationSource {
|
|
|
86
101
|
readonly signerCertificate?: ParsedCertificate;
|
|
87
102
|
/** Identifier for debugging (e.g., CRL issuer DN or OCSP responder URL). */
|
|
88
103
|
readonly evidenceIdentifier?: string;
|
|
104
|
+
/**
|
|
105
|
+
* `thisUpdate` of the evidence backing the verdict — the OCSP single
|
|
106
|
+
* response entry or the freshest contributing CRL (an applied delta CRL
|
|
107
|
+
* supersedes its base). This is the timestamp `'best-available'` compares.
|
|
108
|
+
*/
|
|
109
|
+
readonly thisUpdate?: Date;
|
|
89
110
|
}
|
|
90
111
|
/**
|
|
91
112
|
* Revocation evaluation result for a single certificate.
|
package/dist/revocation/chain.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{parseCertificateFromSource as e}from"../x509/parse.js";import{checkCertificateRevocationAgainstCrl as t,parseCertificateRevocationListDer as n,parseCertificateRevocationListPem as r,revocationReasonFromCode as i}from"./crl.js";import{parseOcspResponseDer as a,parseOcspResponsePem as o,validateOcspResponse as s}from"./ocsp.js";function c(e){return typeof e==`object`&&`issuer`in e?e:typeof e==`string`?r(e):n(e)}function l(t){try{return e(t)}catch{return}}function u(e,t){if(e.der.length!==t.der.length)return!1;for(let n=0;n<e.der.length;n++)if(e.der[n]!==t.der[n])return!1;return!0}function d(e,t,n){let r=[];for(let e of t){let t=l(e);t!==void 0&&r.push(t)}let i=[...r,...n];if(e.authorityKeyIdentifier!==void 0){for(let t of i)if(t.subjectKeyIdentifier!==void 0&&f(e.authorityKeyIdentifier)===f(t.subjectKeyIdentifier))return t}for(let t of i)if(e.issuer.derHex===t.subject.derHex)return t}function f(e){return e.toLowerCase()}function p(e){return`${e.issuer.derHex}:${e.serialNumberHex}`}async function m(e,t){let n=p(e),r=t.cache.get(n);if(r===`visiting`)return`resolved-indeterminate`;if(r!==void 0)return r;t.cache.set(n,`visiting`);let i=t.chain[t.chain.length-1];if(i!==void 0&&u(e,i)||t.chain.some(t=>u(t,e)))return t.cache.set(n,`resolved-valid`),`resolved-valid`;let a=h(e,t);if(a===void 0)return t.cache.set(n,`resolved-indeterminate`),`resolved-indeterminate`;let o=await g(e,a,t);return t.cache.set(n,o),o}function h(e,t){let n=[];for(let e of t.extraCertificates){let t=l(e);t!==void 0&&n.push(t)}let r=[...t.chain,...n];for(let t of r)if(e.authorityKeyIdentifier!==void 0&&t.subjectKeyIdentifier!==void 0&&f(e.authorityKeyIdentifier)===f(t.subjectKeyIdentifier)||e.issuer.derHex===t.subject.derHex)return t}async function g(e,n,r){let i=r.chain.some(e=>u(e,n));for(let i of r.crls){let a;try{a=c(i)}catch{continue}let o=await t({certificate:e,issuerCertificate:n,crl:a,at:r.at});if(o.ok){if(o.value.status===`revoked`)return`resolved-revoked`;if(o.value.status===`good`&&await m(n,r)===`resolved-valid`)return`resolved-valid`}}return i?`resolved-valid`:`resolved-indeterminate`}function _(e,t,n,r,i){return n===`revoked`&&
|
|
1
|
+
import{parseCertificateFromSource as e}from"../x509/parse.js";import{checkCertificateRevocationAgainstCrl as t,parseCertificateRevocationListDer as n,parseCertificateRevocationListPem as r,revocationReasonFromCode as i}from"./crl.js";import{parseOcspResponseDer as a,parseOcspResponsePem as o,validateOcspResponse as s}from"./ocsp.js";function c(e){return typeof e==`object`&&`issuer`in e?e:typeof e==`string`?r(e):n(e)}function l(t){try{return e(t)}catch{return}}function u(e,t){if(e.der.length!==t.der.length)return!1;for(let n=0;n<e.der.length;n++)if(e.der[n]!==t.der[n])return!1;return!0}function d(e,t,n){let r=[];for(let e of t){let t=l(e);t!==void 0&&r.push(t)}let i=[...r,...n];if(e.authorityKeyIdentifier!==void 0){for(let t of i)if(t.subjectKeyIdentifier!==void 0&&f(e.authorityKeyIdentifier)===f(t.subjectKeyIdentifier))return t}for(let t of i)if(e.issuer.derHex===t.subject.derHex)return t}function f(e){return e.toLowerCase()}function p(e){return`${e.issuer.derHex}:${e.serialNumberHex}`}async function m(e,t){let n=p(e),r=t.cache.get(n);if(r===`visiting`)return`resolved-indeterminate`;if(r!==void 0)return r;t.cache.set(n,`visiting`);let i=t.chain[t.chain.length-1];if(i!==void 0&&u(e,i)||t.chain.some(t=>u(t,e)))return t.cache.set(n,`resolved-valid`),`resolved-valid`;let a=h(e,t);if(a===void 0)return t.cache.set(n,`resolved-indeterminate`),`resolved-indeterminate`;let o=await g(e,a,t);return t.cache.set(n,o),o}function h(e,t){let n=[];for(let e of t.extraCertificates){let t=l(e);t!==void 0&&n.push(t)}let r=[...t.chain,...n];for(let t of r)if(e.authorityKeyIdentifier!==void 0&&t.subjectKeyIdentifier!==void 0&&f(e.authorityKeyIdentifier)===f(t.subjectKeyIdentifier)||e.issuer.derHex===t.subject.derHex)return t}async function g(e,n,r){let i=r.chain.some(e=>u(e,n));for(let i of r.crls){let a;try{a=c(i)}catch{continue}let o=await t({certificate:e,issuerCertificate:n,crl:a,at:r.at});if(o.ok){if(o.value.status===`revoked`)return`resolved-revoked`;if(o.value.status===`good`&&await m(n,r)===`resolved-valid`)return`resolved-valid`}}return i?`resolved-valid`:`resolved-indeterminate`}function _(e,t,n,r,i,a){return n===`revoked`&&i!==void 0?{certificate:e,status:`revoked`,source:{type:`crl`,signerCertificate:t,thisUpdate:r},revocationInfo:{date:i,...a===void 0?{}:{reason:a}}}:{certificate:e,status:`good`,source:{type:`crl`,signerCertificate:t,thisUpdate:r}}}function v(e){return typeof e==`string`?o(e):a(e)}function y(e){switch(e){case`stale_response`:return`ocsp_response_expired`;case`responder_id_mismatch`:case`responder_chain_invalid`:case`ocsp_signing_missing`:return`ocsp_responder_not_authorized`;case`responder_revoked`:return`ocsp_responder_revoked`;case`signature_invalid`:case`responder_revocation_unknown`:return`ocsp_responder_indeterminate`;case`response_status_invalid`:case`issuer_mismatch`:case`nonce_mismatch`:case`request_mismatch`:return`no_applicable_ocsp`}}const b=new Set([`signature_invalid`,`responder_id_mismatch`,`responder_chain_invalid`,`ocsp_signing_missing`]);async function x(e,t,n,r){let i={issuerCertificate:t,at:r,...n.trustedOcspResponders===void 0?{}:{trustedResponderCertificates:n.trustedOcspResponders},...n.policy?.ocspResponderRevocation===void 0?{}:{responderRevocationPolicy:n.policy.ocspResponderRevocation},...n.crls===void 0?{}:{responderRevocationCrls:n.crls}},a=await s({response:e,...i});if(a.ok||!b.has(a.code))return a;for(let t of n.extraCertificates??[]){let n=l(t);if(n===void 0)continue;let r=await s({response:e,...i,responderCertificate:n});if(r.ok)return r}return a}async function S(e,t,n){let{ocspResponses:r=[],at:a=new Date}=n,o=[],s=new Set;for(let c of r){let r;try{r=v(c)}catch(e){o.push({kind:`parse_error`,message:e instanceof Error?e.message:`OCSP response parse failed`});continue}let l=(r.responses??[]).find(t=>f(t.certId.serialNumberHex)===f(e.serialNumberHex));if(l===void 0)continue;let u=await x(r,t,n,a);if(!u.ok){s.add(y(u.code));continue}if(l.certStatus===`revoked`){let t=i(l.revocationReasonCode);return{status:{certificate:e,status:`revoked`,source:{type:`ocsp`,thisUpdate:l.thisUpdate},revocationInfo:{date:l.revokedAt??l.thisUpdate,...t===void 0?{}:{reason:t}}},executionErrors:o}}if(l.certStatus===`good`)return{status:{certificate:e,status:`good`,source:{type:`ocsp`,thisUpdate:l.thisUpdate}},executionErrors:o};s.add(`ocsp_status_unknown`)}return s.size===0&&s.add(`no_applicable_ocsp`),{status:{certificate:e,status:`indeterminate`,indeterminateReasons:[...s]},executionErrors:o}}const C=[`keyCompromise`,`cACompromise`,`affiliationChanged`,`superseded`,`cessationOfOperation`,`certificateHold`,`privilegeWithdrawn`,`aACompromise`];async function w(e,n,r,i){let{crls:a=[],extraCertificates:o=[],chain:s=[],at:l=new Date}=r,f=[],p=!1,h=!1,g=!1,v,y=new Set,b=[];for(let e of a)try{b.push(c(e))}catch(e){f.push({kind:`parse_error`,message:e instanceof Error?e.message:`CRL parse failed`})}let x=b.filter(e=>e.baseCrlNumber===void 0),S=b.filter(e=>e.baseCrlNumber!==void 0),w=async(n,r,i)=>t({certificate:e,issuerCertificate:i,crl:n,...r===void 0?{}:{deltaCrl:r},at:l});for(let t of x){let r=S.find(e=>e.issuer.derHex===t.issuer.derHex&&e.baseCrlNumber!==void 0&&t.crlNumber!==void 0&&BigInt(e.baseCrlNumber)<=BigInt(t.crlNumber)),a=await w(t,r,n),c=n;if(!a.ok){let e=d(t,o,s);e!==void 0&&!u(e,n)&&(a=await w(t,r,e),c=e)}if(!a.ok)continue;let l=await m(c,i);if(l===`resolved-revoked`){p=!0;continue}if(l===`resolved-indeterminate`){h=!0;continue}let b=r!==void 0&&r.thisUpdate.getTime()>t.thisUpdate.getTime()?r.thisUpdate:t.thisUpdate;if(a.value.status===`revoked`)return{status:_(e,c,`revoked`,b,a.value.revocationDate,a.value.reasonCode),executionErrors:f};g=!0,(v===void 0||b.getTime()>v.thisUpdate.getTime())&&(v={signer:c,thisUpdate:b});let x=t.issuingDistributionPoint?.onlySomeReasons?.flags;if(x===void 0)for(let e of C)y.add(e);else for(let e of x)y.add(e)}if(g)return C.every(e=>y.has(e))?{status:{certificate:e,status:`good`,...v===void 0?{}:{source:{type:`crl`,signerCertificate:v.signer,thisUpdate:v.thisUpdate}}},executionErrors:f}:{status:{certificate:e,status:`indeterminate`,indeterminateReasons:[`reason_coverage_incomplete`]},executionErrors:f};let T=[];return p?T.push(`crl_signer_revoked`):h?T.push(`crl_signer_indeterminate`):T.push(`no_applicable_crl`),{status:{certificate:e,status:`indeterminate`,indeterminateReasons:T},executionErrors:f}}async function T(e,t,n,r){let i=n.policy?.prefer??`best-available`,a=await S(e,t,n),o=await w(e,t,n,r),s=[...a.executionErrors,...o.executionErrors],c=i===`crl`?[o,a]:i===`ocsp`?[a,o]:[a,o].sort((e,t)=>(t.status.source?.thisUpdate?.getTime()??0)-(e.status.source?.thisUpdate?.getTime()??0)),l=c.find(e=>e.status.status===`revoked`);if(l!==void 0)return{status:l.status,executionErrors:s};let u=c.find(e=>e.status.status===`good`);if(u!==void 0)return{status:u.status,executionErrors:s};let d=new Set;for(let e of c)for(let t of e.status.indeterminateReasons??[])d.add(t);return{status:{certificate:e,status:`indeterminate`,indeterminateReasons:[...d]},executionErrors:s}}async function E(e){let{chain:t,policy:n,crls:r=[],extraCertificates:i=[],at:a=new Date}=e,o=n?.mode??`soft-fail`;if(t.length===0)return{ok:!0,value:{decision:`allow`,summary:{revokedCertificates:[],indeterminateCertificates:[]},certificates:[]}};let s={cache:new Map,chain:t,crls:r,extraCertificates:i,at:a},c=t.slice(0,-1),l=[],u=[],d=[],f=[];for(let n=0;n<c.length;n++){let r=c[n],i=t[n+1];if(r===void 0||i===void 0)continue;let{status:a,executionErrors:o}=await T(r,i,e,s);l.push(a),f.push(...o),a.status===`revoked`?u.push(r):a.status===`indeterminate`&&d.push(r)}let p=u.length>0,m=d.length>0;return{ok:!0,value:{decision:p||m&&o===`hard-fail`?`deny`:`allow`,summary:{revokedCertificates:u,indeterminateCertificates:d},certificates:l,...f.length>0?{executionErrors:f}:{}}}}export{E as checkChainRevocation};
|
|
2
2
|
//# sourceMappingURL=chain.js.map
|