Skip to content
PKIjsPKIjsPKIjsv4.0.1

CertificateChainValidationEngine

Represents a chain-building engine for Certificate certificates.

Path validation notes:

  • The pathLenConstraint of a trusted certificate is not applied, unless CertificateChainValidationPolicy.enforceTrustAnchorPathLenConstraint is set. RFC 5280, 6.2 leaves trust anchor constraints to the application. Those of intermediate certificates are always applied.
  • A critical extension that the engine does not process makes the path invalid, even if its type is registered in ExtensionValueFactory. Use CertificateChainValidationPolicy.criticalExtensionHandler to check such extensions in the application.
  • A critical extension that does not decode, or has a value out of range, makes the path invalid. So does an extension that a certificate has more than once, and a name that a critical name constraint restricts in a form the engine does not check (otherName, x400Address, ediPartyName, registeredID).
  • When several trusted paths exist, they are checked from the shortest, and the first one that passes the basic checks (dates, name chaining, revocation, CA certificates, critical extensions, pathLenConstraint) is used. Certificate policies and name constraints are checked for that path only, so a path can be selected and then still fail.
  • Whether the key usage and the extended key usage of the end entity fit the purpose at hand is for the caller to check.

resultCode values of the checks above:

  • 6: a critical extension does not decode or has a value out of range
  • 15: a critical extension is not recognized
  • 16: a pathLenConstraint is exceeded or invalid
  • 17: a certificate has an extension more than once
  • 18: a critical name constraint applies to a name form that the engine does not check
const rootCa = pkijs.Certificate.fromBER(certRaw1);
const intermediateCa = pkijs.Certificate.fromBER(certRaw2);
const leafCert = pkijs.Certificate.fromBER(certRaw3);
const crl1 = pkijs.CertificateRevocationList.fromBER(crlRaw1);
const ocsp1 = pkijs.BasicOCSPResponse.fromBER(ocspRaw1);
const chainEngine = new pkijs.CertificateChainValidationEngine({
certs: [rootCa, intermediateCa, leafCert],
crls: [crl1],
ocsps: [ocsp1],
checkDate: new Date("2015-07-13"), // optional
trustedCerts: [rootCa],
});
const chain = await chainEngine.verify();

new CertificateChainValidationEngine(parameters?): CertificateChainValidationEngine

Constructor for CertificateChainValidationEngine class

CertificateChainValidationEngineParameters = {}

CertificateChainValidationEngine

certs: Certificate[]

Array with certificate chain. Could be only one end-user certificate in there!


checkDate: Date

The date at which the check would be


crls: CertificateRevocationList[]

Array of all CRLs for all certificates from certificate chain


findIssuer: FindIssuerCallback

Returns the possible issuers of a certificate, used to build the certificate path


findOrigin: FindOriginCallback

Returns where a certificate came from, such as “Intermediate Certificates” or “Trusted Certificates”


ocsps: BasicOCSPResponse[]

Array of all OCSP responses


trustedCerts: Certificate[]

Array of pre-defined trusted (by user) certificates


validationPolicy: CertificateChainValidationPolicy

Choices that RFC 5280 leaves to the application

defaultFindIssuer(certificate, validationEngine, crypto?): Promise<Certificate[]>

Certificate

CertificateChainValidationEngine

ICryptoEngine = ...

Promise<Certificate[]>


defaultValues(memberName): Certificate[]

Returns default values for all class members

"trustedCerts"

String name for a class member

Certificate[]

Default value

defaultValues(memberName): Certificate[]

Returns default values for all class members

"certs"

String name for a class member

Certificate[]

Default value

defaultValues(memberName): CertificateRevocationList[]

Returns default values for all class members

"crls"

String name for a class member

CertificateRevocationList[]

Default value

defaultValues(memberName): BasicOCSPResponse[]

Returns default values for all class members

"ocsps"

String name for a class member

BasicOCSPResponse[]

Default value

defaultValues(memberName): Date

Returns default values for all class members

"checkDate"

String name for a class member

Date

Default value

defaultValues(memberName): FindOriginCallback

Returns default values for all class members

"findOrigin"

String name for a class member

FindOriginCallback

Default value

defaultValues(memberName): FindIssuerCallback

Returns default values for all class members

"findIssuer"

String name for a class member

FindIssuerCallback

Default value


sort(passedWhenNotRevValues?, crypto?): Promise<Certificate[]>

boolean = false

ICryptoEngine = ...

Promise<Certificate[]>


verify(parameters?, crypto?): Promise<CertificateChainValidationEngineVerifyResult>

Major verification function for certificate chain.

CertificateChainValidationEngineVerifyParams = {}

ICryptoEngine = ...

Crypto engine

Promise<CertificateChainValidationEngineVerifyResult>


static defaultFindOrigin(certificate, validationEngine): string

Certificate

CertificateChainValidationEngine

string