API Reference
StreamSec.DSI.PkixCertGenerator
PKIX Certificate Generator Component Unit
Feature notes: PKIX / CMS implementation notes
Classes, interfaces and records
classeCertificateGenerator
inherits from eSecComp
(no public members)
classtNameAttributeCollectionItem
inherits from TCollectionItem
procedure Assign(Source: TPersistent); override;
Copies Attribute, Tag, LineSeparator, PreferPrintableStringEncoding and Value from another item of this class. Applications rarely call this directly; it is invoked by the collection/streaming machinery, e.g. when assigning one SubjectNameAttributes collection to another or when the designer clones an item.
property Tag: TObject read fTag write SetTag;
Free-form reference an application may attach to this attribute item to correlate it with its own data (e.g. a UI control or a source record). Ignored by certificate generation itself; carried along by Assign. Not published, so it is not streamed with the component.
property Attribute: tAttrValueEnum read fAttribute write SetAttribute;
Selects which subject Distinguished Name attribute this item supplies (e.g. common name, country, organization, e-mail).
Full description »
property LineSeparator: string read fLineSeparator write SetLineSeparator;
When non-empty, splits Value into several RDN values of the same Attribute type: the generator hands this separator to the RDN sequence so each substring becomes its own AttributeTypeAndValue. This is the only supported way to emit multiple values for one attribute, since the collection otherwise forbids duplicate Attributes.
property PreferPrintableStringEncoding: Boolean read fPreferPrintableStringEncoding write SetPreferPrintableStringEncoding;
Chooses the ASN.1 string encoding for Value: True prefers PrintableString, False allows the broader (UTF8String/IA5String) encoding.
Full description »
property Value: string read fValue write SetValue;
The text an application assigns for this DN attribute (e.g. the common name or organization string) that ends up in the generated certificate's subject. Assignments are validated against the current encoding rules (PrintableString / IA5String for e-mail) and are ignored if invalid. Applications may also supply or override it at generation time via the OnGetSubjectNameAttribute event.
classtNameAttributeCollection
inherits from TOwnedCollection
function Add: tNameAttributeCollectionItem;
Appends a new, empty attribute item and returns it. Applications call this to build a certificate's subject DN in code (rather than via the designer), then set the item's Attribute and Value.
function IndexOf(aAttribute: tAttrValueEnum): Integer;
Returns the index of the first item whose Attribute matches, or -1 if none. Because the collection forbids duplicate Attributes, this identifies the single item for that DN component; use it to test whether an application has already supplied, say, a common name.
function Find(aAttribute: tAttrValueEnum): tNameAttributeCollectionItem;
Returns the item carrying the given DN Attribute, or nil if absent. Convenience wrapper over IndexOf for reading or updating an existing attribute's Value without knowing its position.
property Items[aIndex: Integer]: tNameAttributeCollectionItem read GetItems write SetItems;
Indexed access to the attribute items. Applications iterate this to read back the subject DN they configured; the certificate generator itself walks the same list, in order, to build the subject name.
classTstBasePKIXObjectGenerator
inherits from TstBaseComponent
property SubjectNameAttributes: tNameAttributeCollection read fSubjectNameAttributes write SetSubjectNameAttributes;
The collection of relative-distinguished-name attributes (CN, O, OU, ...) an application populates before generating a PKIX object, to become the Subject name of the certificate. Assigning to this property copies the supplied collection into the component's own.
» member page
property DigestAlgorithm: tHashAlgorithm read fDigestAlgorithm write fDigestAlgorithm;
The hash algorithm used when an RSA, DSA or ECDSA issuer signs the generated object (EdDSA and ML-DSA issuers use their own). Defaults to SHA-256; applications raise it to match the issuer key and the desired signature strength.
» member page
property SubjectPublicKeyAlgorithm: tEncapsulatedPublicKeyEnum read fSubjectPublicKeyAlgorithm write SetSubjectPublicKeyAlgorithm;
The public-key algorithm of the key pair generated for the new subject (RSA, DSA/DH, ECDSA, Ed25519/Ed448, ML-DSA, ML-KEM or a composite ML-KEM). Assigning it re-runs SetDefaultSecurityStrength so the strength is clamped to a value valid for the chosen algorithm (e.g. ML-KEM-768 is pinned to ss192, RSA to ss112/ss128).
» member page
property Extensions: tExtnValues read fExtensions write SetExtensions;
The set of extensions the component should populate, either by its own default methods or via the OnGetExtensions event. Assigning always strips the sentinel evUndefined. Descendants seed this from CertificateWizard, so applications usually set the wizard first, then adjust Extensions.
» member page
property DefaultSecurityStrength: tSecurityStrength read fDefaultSecurityStrength write SetDefaultSecurityStrength;
The security strength (ss112/ss128/ss192/ss256) that drives the generated key size. Applications set it to pick e.g. a 2048- vs 3072-bit RSA key; SetSubjectPublicKeyAlgorithm clamps it to a value valid for the selected algorithm, so set the algorithm first.
» member page
property SubjectPublicKey: IInterface read fSubjectPublicKey write fSubjectPublicKey;
The public half of the subject key. It goes into the SPKI, while the interface key generation returns is the private half (which signs a root CA).
Full description »
property OnGetSubjectNameAttribute: tReturnSubjectNameAttributeEvent read fOnGetSubjectNameAttribute write fOnGetSubjectNameAttribute;
OnGetSubjectNameAttribute fires once for each item in SubjectNameAttributes while the subject name is being built. On entry aValue equals the item's Value; if the handler clears aValue the attribute is omitted from the Subject name, otherwise the (possibly modified) value is used. Applications implement it to compute name attributes at generation time rather than hard-coding them.
» member page
property OnGetExtensions: tExtensionEvent read fOnGetExtensions write fOnGetExtensions;
OnGetExtensions occurs once after the default method for setting certificate extensions has been called. aAlreadySet indicates the extensions that have been set using default methods. aToBeSet indicated the extensions that should be set by this event.
» member page
classTstBaseCertificateGenerator
inherits from TstBasePKIXObjectGenerator
constructor Create(aOwner: TComponent); override;
Standard component constructor; creates the empty SubjectNameAttributes collection. Applications normally drop the concrete descendant (TstCertificateGenerator) on a form rather than calling this directly.
» member page
destructor Destroy; override;
Frees the SubjectNameAttributes collection; standard component teardown.
» member page
procedure Execute(aInfo: TObject = nil);
Execute is the main entry point an application calls to build and sign a new certificate once CertificateWizard, SubjectNameAttributes, Extensions and the relevant events are configured.
Full description »
property CertificateWizard: tNewCertificateWizardEnum read fCertificateWizard write SetCertificateWizard;
Applications set CertificateWizard to select the profile of the certificate to be created (ncwRootCA, ncwCA, ncwEndEntityCA, ncwServer, ncwClient, ncwCodeSigning or ncwEMail).
Full description »
property DigestAlgorithm;
The hash algorithm used when the issuer signs the new certificate. Defaults to SHA-256; applications raise it to match the issuer key and desired signature strength (inherited from TstBasePKIXObjectGenerator, promoted here to the published/design-time surface).
» member page
property SubjectPublicKeyAlgorithm;
The public-key algorithm of the key pair generated for the new subject (inherited, promoted here). Changing it re-applies DefaultSecurityStrength so the key size stays consistent with the chosen algorithm.
» member page
property SubjectNameAttributes;
The collection of relative-distinguished-name attributes that make up the new certificate's Subject name; applications add items (CN, O, OU, ...) here before calling Execute (inherited, promoted here).
» member page
property DefaultSecurityStrength;
The security strength (ss112/ss128/ss192/ss256, default ss128) that drives the generated key size; SetSubjectPublicKeyAlgorithm clamps it to a value valid for the selected algorithm (inherited, promoted here).
» member page
property Extensions;
Applications should set Extensions to indicate which extensions should be set using either default methods or by the OnGetExtensions event handler.
» member page
property BeforeGetIssuerCertificate: tReturnIssuerCertificateEvent read fBeforeGetIssuerCertificate write fBeforeGetIssuerCertificate;
Applications might use BeforeGetIssuerCertificate for suppressing the default method for fetching issuer certificates implemented by descendants, e.g. if the default private issuer certificate is not to be used for the certificate to be created. This event is not fired if CertificateWizard = ncwRootCA
» member page
property AfterGetIssuerCertificate: tReturnIssuerCertificateEvent read fAfterGetIssuerCertificate write fAfterGetIssuerCertificate;
AfterGetIssuerCertificate occurs after the issuer certificate has been fetched using methods implemented by descendants, unless CertificateWizard = ncwRootCA.
» member page
property BeforeGenerateKeyPair: tReturnInterfaceEvent read fBeforeGenerateKeyPair write fBeforeGenerateKeyPair;
Applications might use BeforeGenerateKeyPair for suppressing the built-in key generation (TstBasePKIXObjectGenerator.DoGenerateKeyPair, which keys off SubjectPublicKeyAlgorithm and DefaultSecurityStrength), e.g. if a preexisting key is to be used.
Full description »
property AfterGenerateKeyPair: tReturnInterfaceEvent read fAfterGenerateKeyPair write fAfterGenerateKeyPair;
AfterGenerateKeyPair fires right after the key pair has been generated (or supplied via BeforeGenerateKeyPair), receiving it as aResult. Applications might use it to store or otherwise capture the freshly created private key.
» member page
property OnGetCertificateClass: tReturnCertificateClassEvent read fOnGetCertificateClass write fOnGetCertificateClass;
Applications rarely need OnGetCertificateClass; it lets an application override the ASN.1 structure class used to build the new certificate instance, e.g. to plug in a custom iCertificate implementation instead of the default.
» member page
property OnGetValidity: tReturnValidityEvent read fOnGetValidity write fOnGetValidity;
Applications implement OnGetValidity to supply the notBefore/notAfter validity period of the new certificate. If left unassigned, a default validity of Yesterday .. one year after Tomorrow is applied, clamped to the issuer's validity when an issuer is present. The issuer certificate is passed in so the handler can, if desired, keep the leaf validity enclosed by the issuer's.
» member page
property OnGetSerial: tReturnSerialEvent read fOnGetSerial write fOnGetSerial;
Applications must implement OnGetSerial except when CertificateWizard = ncwRootCA, in which case the serial number typically equals zero. An event handler for OnGetSerial might set the serial number using either the aSerial: tBytes parameter or aSerialInt: Int64 parameter. The aSerialInt parameter is only checked by the component if the aSerial parameter is left with Length(aSerial) = 0.
» member page
property OnGetSubjectNameAttribute;
OnGetSubjectNameAttribute occurs once for each item in the SubjectNameAttributes collection. On entry, the aValue parameter has the same value as the aItem.Value property. If the aValue parameter is assigned on exit, the attribute is added to the Subject name of the certificate; otherwise the attribute is omitted.
» member page
property OnGetSubjectName: tCertificateEvent read fOnGetSubjectName write fOnGetSubjectName;
OnGetSubjectName occurs after the iteration of the SubjectNameAttributes collection and all of the corresponding calls to OnGetSubjectNameAttribute.
» member page
property BeforeGetIssuerPrivateKey: tReturnIssuerPrivateKeyEvent read fBeforeGetIssuerPrivateKey write fBeforeGetIssuerPrivateKey;
Applications might use BeforeGetIssuerPrivateKey for obtaining the issuer private key using application specific methods. This event is not fired if CertificateWizard = ncwRootCA.
» member page
property AfterGetIssuerPrivateKey: tReturnIssuerPrivateKeyEvent read fAfterGetIssuerPrivateKey write fAfterGetIssuerPrivateKey;
AfterGetIssuerPrivateKey occurs after the issuer private key has been fetched using methods implemented by descendants, unless CertificateWizard = ncwRootCA.
» member page
property OnCertificateDone: tCertificateDoneEvent read fOnCertificateDone write fOnCertificateDone;
Applications might use OnCertificateDone for storing the certificate that has been created.
» member page
inherits from TstBaseCertificateGenerator
constructor Create(AOwner: TComponent); override;
Standard component constructor. Initialises DefaultSecurityStrength to ss128; applications normally drop the component on a form rather than calling this directly.
» member page
property KeysAndCerts: TstCustomCertificateManager read fKeysAndCerts write SetKeysAndCerts;
The certificate manager the component uses both as the source of issuer material and as the destination for generated keys.
Full description »
Types (enumerations, sets, aliases)
typeiCertificate
iCertificate = StreamSec.DSI.PkixCert.iCertificate;
typeiCertificationRequest
iCertificationRequest = StreamSec.DSI.Pkcs10.iCertificationRequest;
proctReturnIssuerCertificateEvent
tReturnIssuerCertificateEvent = procedure (Sender : TObject;
aInfo : TObject;
var aIssuer: iCertificate) of object;
proctReturnIssuerPrivateKeyEvent
tReturnIssuerPrivateKeyEvent = procedure (Sender : TObject;
aInfo : TObject;
const aIssuer: iCertificate;
var aResult: IInterface) of object;
proctReturnInterfaceEvent
tReturnInterfaceEvent = procedure (Sender : TObject;
aInfo : TObject;
var aResult: IInterface) of object;
proctReturnCertificateClassEvent
tReturnCertificateClassEvent = procedure (Sender: TObject;
aInfo : TObject;
var aClass: tASN1StructClass) of object;
proctReturnValidityEvent
tReturnValidityEvent = procedure (Sender : TObject;
aInfo : TObject;
const aIssuer : iCertificate;
var aNotBefore,
aNotAfter : TDateTime) of object;
proctReturnSerialEvent
tReturnSerialEvent = procedure (Sender : TObject;
aInfo : TObject;
const aIssuer : iCertificate;
var aSerial : tBytes;
var aSerialInt: Int64) of object;
proctCertificateEvent
tCertificateEvent = procedure (Sender : TObject;
aInfo : TObject;
const aIssuer: iCertificate;
const aCert : iCertificate) of object;
proctExtensionEvent
tExtensionEvent = procedure (Sender : TObject;
aInfo : TObject;
const aIssuer : iCertificate;
const aExtensions: iExtensions;
aAlreadySet,
aToBeSet : tExtnValues) of object;
proctReturnSubjectNameAttributeEvent
tReturnSubjectNameAttributeEvent = procedure (Sender: TObject;
aInfo : TObject;
aItem : tNameAttributeCollectionItem;
var aValue: string) of object;
proctCertificateDoneEvent
tCertificateDoneEvent = procedure (Sender: TObject;
aInfo : TObject;
const aCert : iSigned) of object;
enumtNewCertificateWizardEnum
tNewCertificateWizardEnum = (ncwUndefined,
ncwRootCA,
ncwCA,
ncwEndEntityCA,
ncwServer,
ncwClient,
ncwCodeSigning,
ncwEMail);
enumtSecurityStrength
tSecurityStrength = (ss112,ss128,ss192,ss256);