A certificate is trusted when it chains, signature by signature, to a certificate you trust explicitly - a trust anchor - and when no certificate in the chain has been revoked. TsmX509TrustedCertificates checks both.
The TLS components do all of this themselves during the handshake. This page is for checking a certificate outside TLS: a signed document, a code signature, a certificate a user uploads.
function CheckChain(const aRootFile, aIntermediateFile, aLeafFile: string; const aCrlFiles: array of string; aPolicy: TRevocationPolicy): TCertStatusCode; var lStore: TsmX509TrustedCertificates; lStatus: TCertStatusCode; lCrlFile: string; lCrl: iCertificateList; begin lStore := TsmX509TrustedCertificates.Create(nil); try { rpHardFail refuses a certificate whose revocation status cannot be established; rpSoftFail accepts it, but still refuses one a list says is revoked. } lStore.RevocationPolicy := aPolicy; { The trust anchor: True = trusted explicitly, on your say-so. } lStore.AddCertificate(LoadCertificate(aRootFile), True, lStatus); { The revocation lists, before the certificates they speak about. } for lCrlFile in aCrlFiles do begin lCrl := tCertificateList.Create(gcamFirstAssignment); lCrl.GetStruct.LoadFromFile(lCrlFile, fmtDER); lStore.AddCRL(lCrl, lStatus); end; { The intermediate: False = trusted only if it verifies up to the anchor. } lStore.AddCertificate(LoadCertificate(aIntermediateFile), False, lStatus); Result := crcSyntax; lStore.VerifyCertificate(LoadCertificate(aLeafFile), False, Result); finally lStore.Free; end; end;
The certificates are read as in Read a certificate file.
VerifyCertificate gives a TCertStatusCode: crcOK when the chain is complete and nothing in it is known to be revoked. Under the default rpSoftFail that includes a certificate whose status could not be established; rpHardFail gives crcOK only when it was. Among the others:
crcCANotTrusted - the chain does not reach a trust anchor.crcRevoked - a revocation list names the certificate.crcRevocationUnknown - under rpHardFail, no current list from the issuing CA was available, so the status could not be established.crcExpired, crcInvalidSignature, crcInvalidKeyUsage - what their names say.A revocation list (CRL) is published by a CA and speaks only about the certificates that CA issued. To check a root-intermediate-leaf chain completely, you need the root's list (for the intermediate) and the intermediate's list (for the leaf).
rpHardFail refuses a certificate whose status it cannot establish. Choose it where a revoked certificate getting through is worse than a valid one being refused for a while.rpSoftFail, the default, accepts a certificate whose status is unknown but refuses one that a list it has says is revoked.A list must be signed by the CA it speaks for; a forged one is refused. The TLS notes describe fetching lists from the addresses in the certificates, and OCSP.
TsmX509TrustedCertificates · StreamSec.Mobile.X509Comp