Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.DSI.PkixKeyIndex

Feature notes: PKIX / CMS implementation notes

Classes, interfaces and records

classTstBaseKeyIndexCertUnique

inherits from TstAbstractKeyIndex

Abstract base for certificate key-index components whose identifier is unique per key: at most one stored key can match a given identifier (e.g. a certificate thumbprint or issuer+serial). Applications do not use this class directly; pick a concrete descendant (TstKeyIndexCertThumbprint, TstKeyIndexTBSThumbprint, TstKeyIndexSerialIssuer, ...) and attach it to a TstKeyManager so that key lookups by that identifier resolve to one key. The constructor sets Duplicates to dupIgnore, so a second key with the same identifier is silently dropped from the index.

constructor Create(AOwner: TComponent); override;
Sets Duplicates := dupIgnore so the index keeps only one key per identifier. Not called directly by applications; the key manager owns and constructs the index component. » member page
class function Unique: Boolean; override;
True -- only one key per identifier for this index family » member page
class function KeyPair: Boolean; override;
False -- a private key and its public key get different identifiers here » member page

classTstBaseKeyIndexCertNonUnique

inherits from TstAbstractKeyIndex

Abstract base for certificate key-index components whose identifier is NOT unique per key: several stored keys may share the same identifier (e.g. a subject Distinguished Name or a cert-type classification). Applications do not use this class directly; pick a concrete descendant (TstKeyIndexSubjectName, TstKeyIndexCertType, TstKeyIndexSubjectClearTextName, ...) and attach it to a TstKeyManager. The constructor enables startup caching and accepts duplicates, so a lookup can return a set of matching keys rather than exactly one.

constructor Create(AOwner: TComponent); override;
Sets CacheKind := kicStartup and Duplicates := dupAccept so several keys may share one identifier. Not called directly by applications; the key manager owns and constructs the index component. » member page
class function Unique: Boolean; override;
False -- several keys may share one identifier for this index family » member page
class function KeyPair: Boolean; override;
False -- a private key and its public key get different identifiers here » member page

classTstCustomKeyIndexCertThumbprint

inherits from TstBaseKeyIndexCertUnique

Base class (Custom prefix, no palette registration) for the certificate thumbprint index. Its identifier is DigestAlgorithm applied to the DER of the whole certificate, so applications use a descendant (TstKeyIndexCertThumbprint) when they want to look up a stored key by the fingerprint of its certificate -- e.g. matching a peer certificate seen on the wire to a locally held private key. Instantiate the Custom base only to subclass it; drop the registered TstKeyIndexCertThumbprint on a form.

procedure SuggestRequiredUnits(aProc: tGetStringMethod); override;
Reports to the key manager which runtime unit must be linked in for the configured DigestAlgorithm to be available. Applications rarely call this directly; it feeds the design-time "required units" collection so a saved project pulls in the hash implementation. Extends the inherited list. » member page
class function Unequivocal: Boolean; override;
True -- one key yields exactly one thumbprint identifier » member page
property DigestAlgorithm: tHashAlgorithm read fDigestAlgorithm write SetDigestAlgorithm;
The hash algorithm used to fingerprint the DER-encoded certificate. Set this to match whatever produced the thumbprint you will search by (e.g. haSHA1 or haSHA256); changing it re-resolves the hash class and silently controls which unit SuggestRequiredUnits will demand. » member page

classTstKeyIndexCertThumbprint — component reference

inherits from TstCustomKeyIndexCertThumbprint

(no public members)

classtKeyIndexCertThumbprint

inherits from TstCustomKeyIndexCertThumbprint

class function Description: string; override;
Returns the value of rsUseKeyIndexCertThum.

classTstCustomKeyIndexTBSThumbprint

inherits from TstBaseKeyIndexCertUnique

Base class (Custom prefix, no palette registration) for the "TBS thumbprint" index: the identifier is the certificate's iCertificate.TBSThumbprint -- a fingerprint over the to-be-signed portion of the certificate, computed with whatever hash the certificate's own signatureAlgorithm uses. Applications use the registered descendant (TstKeyIndexTBSThumbprint) when they want to match a stored key by a fingerprint that stays stable even if only the outer signature encoding changes; the accepted hash(es) are restricted through AllowedDigestAlgorithms. Instantiate the Custom base only to subclass it.

constructor Create(AOwner: TComponent); override;
At design time only, opens AllowedDigestAlgorithms to every hash so the component accepts any thumbprint until you narrow it. Not called directly by applications; the key manager owns and constructs the index component. » member page
procedure SuggestRequiredUnits(aProc: tGetStringMethod); override;
Reports to the key manager which runtime units must be linked in for the AllowedDigestAlgorithms hashes to be available. Applications rarely call this directly; it feeds the design-time "required units" collection so a saved project pulls in the hash implementations. Extends the inherited list. » member page
class function Unequivocal: Boolean; override;
True -- one certificate yields exactly one TBS-thumbprint identifier, so lookups resolve by direct find » member page
property AllowedDigestAlgorithms: tHashAlgorithms read fAllowedDigestAlgorithms write SetAllowedDigestAlgorithms;
Restricts which digest algorithms this index will accept. A key is only indexed when its certificate's own signature digest is in this set (or the set contains haDefault, which accepts any); assigning it also recomputes the matching digest lengths used to sanity-check identifiers. Leave it empty to index nothing, or set the specific hashes your stored thumbprints use. » member page

classTstKeyIndexTBSThumbprint — component reference

inherits from TstCustomKeyIndexTBSThumbprint

(no public members)

classtKeyIndexTBSThumbprint

inherits from TstCustomKeyIndexTBSThumbprint

class function Description: string; override;
Returns the value of rsUseKeyIndexTBSThumb.

classTstCustomKeyIndexSubjectName

inherits from TstBaseKeyIndexCertNonUnique

Base class (Custom prefix, no palette registration) for the subject-DN index: the identifier is the DER encoding of the certificate's subject Distinguished Name. Applications use the registered descendant (TstKeyIndexSubjectName) when they want to look up a stored key by exact subject name -- e.g. finding the private key whose certificate names a given subject. Several certificates may share one subject, so results are ordered by validity (see DoCompareEqual) with the longest-lived certificate preferred. Instantiate only to subclass.

class function Unequivocal: Boolean; override;
True -- the DER subject name is an exact identifier, so a lookup resolves by direct find rather than a linear scan » member page

classTstKeyIndexSubjectName — component reference

inherits from TstCustomKeyIndexSubjectName

(no public members)

classtKeyIndexSubjectName

inherits from TstCustomKeyIndexSubjectName

class function Description: string; override;
Returns the value of rsUseKeyIndexSubjectN.

classTstBaseKeyIndexSubjectKeyPair

inherits from TstBaseKeyIndexCertNonUnique

Abstract base for indexes whose identifier is derived from the public key itself (public-key value or subjectPublicKey identifier), so the SAME identifier is produced whether the stored item is the private key or its matching public key/certificate. Applications use a descendant (TstKeyIndexPublicKey, TstKeyIndexSubjectPublicKeyIdentifier) when they hold one half of a key pair and need to find the other -- e.g. locate the private key for a public key extracted from a received certificate. Do not instantiate directly.

class function KeyPair: Boolean; override;
True -- the private key and its public key map to the same identifier, so one lookup finds either » member page

classTstCustomKeyIndexSubjectPublicKeyIdentifier

inherits from TstBaseKeyIndexSubjectKeyPair

Base class (Custom prefix, no palette registration) for the subjectKeyIdentifier index: the identifier is the RFC 5280 key identifier (a SHA-1 hash of the public key by default) rather than the raw key value. Because it descends from the key-pair base, the SAME identifier is produced whether the stored item is the private key, the public key or the certificate. Applications use the registered descendant (TstKeyIndexSubjectPublicKeyIdentifier) to resolve a key from an authorityKeyIdentifier/subjectKeyIdentifier seen in a certificate or CMS structure. Match also accepts the alternative identifier (PublicKeyIdentifier2) for bare keys. Instantiate only to subclass.

procedure SuggestRequiredUnits(aProc: tGetStringMethod); override;
Reports that the SHA-1 unit must be linked in, since the key identifier is a SHA-1 digest of the public key. Applications rarely call this directly; it feeds the design-time "required units" collection. Extends the inherited list. » member page
class function Unequivocal: Boolean; override;
False -- a key can match by either its primary or its alternative identifier, so the key manager falls back to a linear scan » member page

classTstKeyIndexSubjectPublicKeyIdentifier — component reference

inherits from TstCustomKeyIndexSubjectPublicKeyIdentifier

(no public members)

classtKeyIndexSubjectPublicKeyIdentifier

inherits from TstCustomKeyIndexSubjectPublicKeyIdentifier

class function Description: string; override;
Returns the value of rsUseKeyIndexSubjectP.

classTstCustomKeyIndexPublicKey

inherits from TstBaseKeyIndexSubjectKeyPair

Base class (Custom prefix, no palette registration) for the public-key index: the identifier is the DER of the raw subjectPublicKey (the key value itself), covering RSA/DSA/EC as well as the ML-DSA/ML-KEM/composite/SLH-DSA families via GetCertOrSPKIFromKey. Applications use the registered descendant (TstKeyIndexPublicKey) when they must correlate a private key, public key and certificate purely by matching key material -- for instance finding the private key that goes with a public key parsed from a signature or certificate. Instantiate only to subclass.

class function Unequivocal: Boolean; override;
True -- each key produces exactly one public-key identifier » member page

classTstKeyIndexPublicKey — component reference

inherits from TstCustomKeyIndexPublicKey

(no public members)

classtKeyIndexPublicKey

inherits from TstCustomKeyIndexPublicKey

class function Description: string; override;
Returns the value of rsUseKeyIndexPublicKe.

classTstCustomKeyIndexSerialIssuer

inherits from TstBaseKeyIndexCertUnique

Base class (Custom prefix, no palette registration) for the issuer+serial index keyed as an authorityKeyIdentifier: the identifier is the DER of an iAuthorityKeyIdentifier holding the certificate's issuer name and serial number. Applications use the registered descendant (TstKeyIndexSerialIssuer) to resolve a key from an authorityKeyIdentifier extension -- e.g. locating the CA/issuer key a certificate points at. See TstCustomKeyIndexSerialIssuerCMS for the CMS IssuerAndSerialNumber variant used by SignedData/EnvelopedData. Instantiate only to subclass.

class function Unequivocal: Boolean; override;
True -- issuer+serial identifies exactly one certificate, so lookups resolve by direct find » member page
function GetSerialIssuerFromKey(const aPubl: iUnknown): iAuthorityKeyIdentifier;
Builds (or passes through) the issuer+serial key identifier for a key. Given something that already supports iAuthorityKeyIdentifier it returns that; given a key/certificate it derives one from the certificate's issuer name and serial number. Full description »

classTstKeyIndexSerialIssuer — component reference

inherits from TstCustomKeyIndexSerialIssuer

(no public members)

classtKeyIndexSerialIssuer

inherits from TstCustomKeyIndexSerialIssuer

class function Description: string; override;
Returns the value of rsUseKeyIndexSerialIs.

classTstCustomKeyIndexSerialIssuerCMS

inherits from TstCustomKeyIndexSerialIssuer

Base class (Custom prefix, no palette registration) for the CMS issuer+serial index: like TstCustomKeyIndexSerialIssuer but the identifier is the DER of a CMS iIssuerAndSerialNumber (RFC 5652) rather than an authorityKeyIdentifier. Applications use the registered descendant (TstKeyIndexSerialIssuerCMS) so that a SignerInfo/RecipientInfo that names its certificate by IssuerAndSerialNumber resolves directly to the matching stored key. Instantiate only to subclass.

function GetSerialIssuerFromKey(const aPubl: iUnknown): iIssuerAndSerialNumber;
CMS-flavoured override of the inherited helper: returns an iIssuerAndSerialNumber (RFC 5652 form) instead of an iAuthorityKeyIdentifier. Full description »

classTstKeyIndexSerialIssuerCMS — component reference

inherits from TstCustomKeyIndexSerialIssuerCMS

(no public members)

classtKeyIndexSerialIssuerCMS

inherits from TstCustomKeyIndexSerialIssuerCMS

class function Description: string; override;
Returns the value of rsUseKeyIndexSerialIsCMS.

classTstCustomKeyIndexOcspCertID

inherits from TstBaseKeyIndexCertUnique

Base class (Custom prefix, no palette registration) for the clear-text subject index: instead of the DER subject name, the identifier is a human-readable "/CN=.../O=..." string built from the certificate's subject, limited to the attributes chosen in IndexedAttributes. Applications use the registered descendant (TstKeyIndexSubjectClearTextName) when they want to look up a stored key by a readable name fragment (typically just the Common Name) rather than by an exact binary DN -- a lookup succeeds when every requested attribute is present among the certificate's attributes, so it acts as a subset/contains match. Several certificates may share a name; results are ordered by validity. Instantiate only to subclass. Base class (Custom prefix, no palette registration) for the OCSP CertID index: the identifier is the DER of an RFC 6960 CertID, which is the exact value an OCSP request names a certificate by. An OCSP responder can therefore take the CertID straight out of the request it received and ask the key manager for the certificate, with no knowledge of which CA issued it - so ONE responder can serve any number of CAs, which is what an issuer-and-serial index cannot do: that identifier needs the issuer's NAME, and a CertID carries only a hash of it.

THE FOUR FIELDS, and where each comes from when indexing a stored certificate. They are computed exactly as TstAbstractOcsp.BuildCertID computes them for a request, because an identifier that did not agree with the client's would never match:

hashAlgorithm SHA-1, the RFC 5019 interoperable default. A CertID's hash algorithm is the CLIENT's choice, and one certificate has one identifier here, so this index answers for SHA-1 CertIDs. Every lightweight client sends SHA-1; RFC 5019 s2.1 requires it. issuerNameHash SHA-1 over the DER of the certificate's own issuer DN.
issuerKeyHash the certificate's authorityKeyIdentifier keyIdentifier. This is the one field a certificate does not carry directly - it is a hash of the ISSUER's public key - and the AKI is where the issuer put exactly that (RFC 5280 s4.2.1.1 method 1, and what this library writes). A certificate with no AKI is therefore NOT INDEXABLE here rather than indexed under an empty hash: a silent mismatch would look like a certificate nobody has.
serialNumber copied from the certificate.

Instantiate only to subclass; applications add the registered descendant TstKeyIndexOcspCertID.

class function Unequivocal: Boolean; override;
True -- a CertID identifies exactly one certificate, so lookups resolve by direct find » member page
function GetCertIDFromKey(const aPubl: iUnknown): iCertID;
Builds (or passes through) the CertID identifier for a key. Given something that already supports iCertID - the reqCert of a request just received, say - it returns that unchanged, which is how a responder looks up what it was asked about. Given a key or certificate it derives the CertID from the certificate. Answers nil when neither is possible. » member page

classTstKeyIndexOcspCertID — component reference

inherits from TstCustomKeyIndexOcspCertID

(no public members)

classtKeyIndexOcspCertID

inherits from TstCustomKeyIndexOcspCertID

class function Description: string; override;
Returns the value of rsUseKeyIndexOcspCertID.

classTstCustomKeyIndexSubjectClearTextName

inherits from TstBaseKeyIndexCertNonUnique

constructor Create(AOwner: TComponent); override;
Defaults IndexedAttributes to just the Common Name. Not called directly by applications; the key manager owns and constructs the index component. » member page
class function Unequivocal: Boolean; override;
False -- the identifier is a subset match, so the key manager linearly scans candidate keys rather than doing a direct find » member page
function AttributeToText(const aAttr: iAttributeTypeAndValue): string;
Renders a single subject attribute (type and value) as a "/XX=value" fragment, mapping well-known attribute OIDs to their short labels (CN, O, OU, ...) and escaping any embedded slash. Chiefly the building block NameToText uses; applications can call it to format one attribute for display. » member page
function NameToText(const aName: iRDNSequence): string; overload;
Renders a whole subject/DN into the "/CN=.../O=..." clear-text form, including every attribute. Applications can call this to produce a readable rendering of a certificate subject, or to construct the identifier string to search by. » member page
function NameToText(const aName : iRDNSequence; const aAttrs: tAttrValueEnumSet) : string; overload;
As above but only emits the attributes in aAttrs. This is exactly how the index derives its identifier (using IndexedAttributes); pass the same set to build a matching lookup string. » member page
property IndexedAttributes: tAttrValueEnumSet read fIndexedAttributes write SetIndexedAttributes;
Which subject attributes take part in the identifier and in matching. Narrow it (default: Common Name only) so a lookup can succeed on, say, just the CN even when the stored certificate carries a fuller DN; widen it to require more attributes to agree. Full description »

classTstKeyIndexSubjectClearTextName — component reference

inherits from TstCustomKeyIndexSubjectClearTextName

(no public members)

classtKeyIndexSubjectClearTextName

inherits from TstCustomKeyIndexSubjectClearTextName

class function Description: string; override;
Returns the value of rsUseKeyIndexSubjectC.

classTstCustomKeyIndexCertType

inherits from TstBaseKeyIndexCertNonUnique

Base class (Custom prefix, no palette registration) for the cert-type index: the identifier is a textual "CT/..." descriptor built from the certificate's signature algorithm, public-key algorithm, key usage and extended key usage (selected by IndexedCertType). Applications use the registered descendant (TstKeyIndexCertType) to look up keys by CAPABILITY rather than identity -- e.g. "give me any key whose certificate permits digitalSignature and TLS server authentication". The identifier syntax supports & (all-of) and | (any-of) operators over the listed values. Instantiate only to subclass.

class function Unequivocal: Boolean; override;
False -- one key can satisfy many cert-type identifiers, and one identifier many keys » member page
function CertTypeToText(const aCert: iCertificate): string; overload;
Builds the "CT/..." identifier text for a certificate using the current IndexedCertType selection. Applications call this to compute the exact string an index entry would store for aCert, e.g. for display or logging. » member page
function CertTypeToText(const aCert: iCertificate; const aICT : tIndexedCertTypes) : string; overload;
As above, but with an explicit set of cert-type components (aICT) instead of the component's IndexedCertType. Use when you want the descriptor for a different combination than the index is configured for. » member page
function CertTypesToText(const aSignatureAlgorithms: array of string; const aPublicKeyAlgorithms: array of string; const aKeyUsage : tKeyUsage; const aExtKeyUsage : array of string) : string;
Constructs a "CT/..." QUERY identifier from explicit criteria -- lists of signature and public-key algorithm OIDs, a key-usage set, and extended key-usage OIDs. Applications use this to build the search string passed to the key manager when looking up keys by capability; a single value emits the & (must-match) operator, multiple values emit | (any-of). » member page
property IndexSignatureAlgorithm: Boolean read GetIndexSignatureAlgorithm write SetIndexSignatureAlgorithm;
Convenience Boolean views of IndexedCertType: reading returns whether the corresponding tIndexedCertType flag is set, writing includes/excludes it. Use these when a UI exposes each cert-type facet as its own checkbox. » member page
property IndexPublicKeyAlgorithm: Boolean read GetIndexPublicKeyAlgorithm write SetIndexPublicKeyAlgorithm;
See IndexSignatureAlgorithm -- toggles the ictPublicKeyAlgorithm facet. » member page
property IndexKeyUsage: Boolean read GetIndexKeyUsage write SetIndexKeyUsage;
See IndexSignatureAlgorithm -- toggles the ictKeyUsage facet. » member page
property IndexExtKeyUsage: Boolean read GetIndexExtKeyUsage write SetIndexExtKeyUsage;
See IndexSignatureAlgorithm -- toggles the ictExtKeyUsage facet. » member page
property IndexedCertType: tIndexedCertTypes read fIndexedCertType write SetIndexedCertType;
The set of certificate facets that make up each index identifier. Set this (at design time or before enabling the index) to decide which of signature algorithm, public-key algorithm, key usage and extended key usage are folded into the "CT/..." descriptor keys are indexed and searched by. » member page

classTstKeyIndexCertType — component reference

inherits from TstCustomKeyIndexCertType

(no public members)

classtKeyIndexCertType

inherits from TstCustomKeyIndexCertType

class function Description: string; override;
Returns the value of rsUseKeyIndexCertType.

Types (enumerations, sets, aliases)

settHashAlgorithms

  tHashAlgorithms = set of tHashAlgorithm;

settByteSet

  tByteSet = set of Byte;

settAttrValueEnumSet

  tAttrValueEnumSet = set of tAttrValueEnum;

enumtIndexedCertType

  tIndexedCertType = (ictSignatureAlgorithm,
                      ictPublicKeyAlgorithm,
                      ictKeyUsage,
                      ictExtKeyUsage);

settIndexedCertTypes

  tIndexedCertTypes = set of tIndexedCertType;

Routines