Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.DSI.PkixCms

Feature notes: PKIX / CMS implementation notes

Classes, interfaces and records

classtSMIMECapabilityItem

inherits from TCollectionItem

constructor Create(Collection: TCollection); override; property AutoFilled: Boolean read fAutoFilled;
True for the items the component constructor pre-filled from the cipher registry, False for items added or assigned by the application. Items the application configures take precedence when the EnvelopedData content cipher is selected.
property CipherAlg: TCipherAlg read fCipherAlg write SetCipherAlg;
Deprecated - an RC2 item (CipherAlg caARC2). Its parameter is written, and read back by AssignStruct, as the RFC 2268 RC2 parameter version (58 for a 128-bit key, 120 for 64 bits), not as the effective key length in bits that RFC 3851 section 2.5.2.1 puts there (128, 64) and OpenSSL writes; from... Full description »
property CipherMode: TCipherMode read fCipherMode write SetCipherMode; property KeyedIV: Boolean read fKeyedIV write SetKeyedIV;
Deprecated - leave False. A keyed-IV (KIV) item names StreamSec's own cipher OIDs (id_kivcipher in stOIDs), which only this library reads; the items filled in by default never set it.
property KeyLength: Word read fKeyLength write SetKeyLength; property OID: ObjectIdentifier read GetOID write SetOID stored False;

classtSMIMECapabilities

inherits from TOwnedCollection

function AssignStruct(aStruct: iSMIMECapabilities; aIntersect: Boolean = True): Boolean; function HasCapability(aCC: tCipherClass; aKeyLength: Integer; aKeyedIV: Boolean): Boolean; overload; function HasCapability(aCC: tCipherClass; aCEParam: iCEParams): Boolean; overload; property Items[Index: Integer]: tSMIMECapabilityItem read GetItem write SetItem;

classTstBaseMPCMSComponent

inherits from TComponent

constructor Create(AOwner: TComponent); override;
Shared base of the CMS message-processing components (SignedData, EnvelopedData and the Broker). Apps do not instantiate this class directly; use one of the published descendants. Full description »
destructor Destroy; override;
Standard component teardown; apps do not call it directly (the owner form or Free disposes the instance). It runs Clear to drop the cached certificate/key reference, then releases the internal lock, the SMIMECapabilities lists and the working file stream. » member page
procedure Clear; virtual;
Releases the cached certificate/private-key reference held from the last operation. Call between operations if you want to drop references early; it is invoked automatically on Destroy and by the descendants' Clear. » member page

classTstCustomMPCMSBroker

(no public members)

classTstCustomMPSignedData

inherits from TstBaseMPCMSComponent

constructor Create(aOwner: TComponent); override;
Base class implementing CMS/PKCS#7 SignedData. Apps normally drop the published TstMPSignedData component and use it via SignData / CounterSignData / VerifySignedData; this custom base exists so descendants can choose which properties to publish. The constructor defaults the content digest to SHA-1 and IncludeSigningTime to True. » member page
destructor Destroy; override;
Standard component teardown; apps do not call it directly. It releases the cached SignedData structure and the extracted S/MIME-capabilities interface references before the inherited destructor runs. » member page
procedure Clear; override;
Drops the loaded SignedData structure and cached S/MIME capabilities and forces two GC sweeps. Call it when reusing the component for an unrelated message; it is chained by the Broker's Clear. » member page
function CheckTrust(const aFileName: string): Boolean;
Convenience verifier: opens the named file read-only and runs VerifySignedData over it with no output stream (signature validity only, the content is not extracted). Use it to answer "is this signed file trusted?" without handling streams yourself. » member page
function SignData(aCert : iCertificate; aContent, aDest : TStream) : Boolean; overload;
Produces a CMS SignedData over aContent, writing the encoding to aDest. Pass the signer's iCertificate (which must carry a usable private key) in aCert, or pass nil to have OnAddSigner supply it. Returns False if no signer certificate was resolved or the format check failed. This is the signing (producer) side of the SignedData workflow. » member page
function CounterSignData(aCert : iCertificate; aStream, aDest : TStream) : Boolean; overload;
Adds a counter-signature (a signature over an existing signer's signature) to the already-signed message in aStream, writing the result to aDest. aCert is the counter-signer's certificate/key, or nil to defer to OnAddSigner. Use this for notarizing or timestamping a message another party already signed. » member page
function VerifySignedData(aStream, aDest: TStream): Boolean;
Verifies the CMS SignedData in aStream and, for an attached (non-detached) signature, writes the recovered content to aDest (pass nil to check the signature only). This is the verifying (consumer) side; results surface through CertificateNotFound / IllegalFormat and the OnGoodSignature / OnBadSignature events. » member page
property LastTimeStampError: string read fLastTimeStampError;
LastTimeStampError describes why the most recent RFC 3161 signature time-stamp operation (producing one in DoCounterSign or verifying the id-aa-signatureTimeStampToken attribute) failed; empty otherwise. » member page

classTstMPSignedData — component reference

inherits from TstCustomMPSignedData

property CertificateNotFound;
The published CMS/PKCS#7 SignedData component. Drop it on a form (or create it in code), assign KeysAndCerts, then call SignData / CounterSignData / VerifySignedData to produce or verify detached or attached signatures. Full description »
property ContentOnly;
When True the component reads/writes only the bare inner SignedData structure without the outer ContentInfo wrapper. Apps rarely set it directly; the CMS broker uses it when nesting one CMS layer inside another (it is reset to False at the start of CounterSignData). » member page
property IllegalFormat;
Read after an operation: True when the input could not be parsed as a valid CMS SignedData (malformed / wrong content type). Check it alongside the Boolean result of VerifySignedData. » member page
property ContentDigestAlg;
Producer side: the message-digest algorithm used over the content and, for RSA/ECDSA, the pre-hash. Defaults to haDefault, which picks per signer: the messageDigest hash the RFC prescribes for EdDSA and ML-DSA (RFC 8419, RFC 9882), else the signing key's SignatureDigestAlg when it is SHA-256 or stronger, else SHA-256 - never SHA-1. Set a value to force one hash. » member page
property RSAPSSSaltLen;
Producer side: salt length (bytes) for an RSASSA-PSS signature. Only relevant when the signing key is RSA and PSS padding is selected; ignored for PKCS#1 v1.5, ECDSA, EdDSA and PQ signatures. » member page
property RSAPSSMFGHashAlgorithm;
Producer side: the MGF1 hash algorithm for an RSASSA-PSS signature. Applies only to RSA-PSS signing; leave at its default unless a verifier requires a specific MGF hash. » member page
property AllowExpiredCertificates;
When True, a signer/recipient certificate that is outside its validity period is still accepted rather than rejected. Set False for strict validity checking; it affects the verify (consumer) side. » member page
property ExtKeyCompatibility;
Producer side: when True, keep a copy of the signed content available during signing (also forced automatically for raw-signing keys such as EdDSA / ML-DSA / composite). Enable it for interoperability with external key operations that need the to-be-signed bytes retained. » member page
property IncludeRootCertificate;
Producer side: when True, the self-signed root of the signer's chain is included in the SignedData certificate set. Usually left False (verifiers supply their own trusted roots); enable only when the recipient needs the full chain embedded. » member page
property IncludeCertificates;
Producer side: when True (the default), the SignedData carries the signer's certificate - and, subject to IncludeRootCertificate, the rest of its chain - in the OPTIONAL certificates field of RFC 5652. Full description »
property AllowCMSv3;
Producer side: when True, a SignerInfo identifies the signer by subjectKeyIdentifier (CMS v3) where the certificate carries that extension, instead of by issuerAndSerialNumber. Full description »
property IncludeSigningTime;
Producer side: when True (the default), a signing-time signed attribute is added to each SignerInfo. Turn it off to omit the timestamp attribute from the produced signature. » member page
property IncludeSigningCertificateV2;
Producer side: adds the RFC 5035 signing-certificate-v2 signed attribute (CAdES/PAdES requirement). Default False. » member page
property SMIMECapabilities;
The advertised set of S/MIME symmetric-cipher / algorithm capabilities. On signing it is emitted as an SMIMECapabilities signed attribute so a replying party can pick a cipher; pre-filled with the ciphers and PQ/hybrid OIDs this build supports. » member page
property TimeStampURL;
Producer side: URL of an RFC 3161 time-stamp authority used together with the OnExternalCounterSign event to obtain a trusted timestamp counter- signature over a produced signature. Leave empty for no external timestamp. » member page
property ContentType;
Per-message values: The encapsulated content-type OID recorded in (produce) or read from (verify) the SignedData. Defaults to pData; change it when signing a specific S/MIME content type rather than raw data. » member page
property SigningDescription;
Producer side: an optional human-readable description carried as a signed attribute (SigningDescription). Set it per message to annotate what/why was signed; leave empty to omit the attribute. » member page
property DetachedSignature;
Producer side: when True, SignData emits a detached signature (the content is not embedded, only its digest is signed). On verify this reflects whether the loaded message was detached, in which case OnGetDetachedMessage must supply the original content to check against. » member page
property KeysAndCerts;
Associated components: The certificate/private-key store this component draws signer keys from and resolves verification chains against. Assign it before any sign or verify call; without it CertificateNotFound will be set. » member page
property OnAddSigner;
Events: Producer side: fires once per signer (with a nil aCert to fill in) while SignData builds the message, letting the app choose the signing certificate when none was passed explicitly. » member page
property OnBadSignature;
Verify side: fires for each SignerInfo whose signature failed to verify, so the app can report or log the offending signer certificate. » member page
property OnGoodSignature;
Verify side: fires for each SignerInfo that verified successfully, giving the app the validated signer certificate (use it to record who signed). » member page
property OnGoodCounterSignature;
Verify side: fires when a counter-signature (e.g. a timestamp) over a signer's signature verifies, reporting both the signer and counter-signer certificates plus the counter-signed time. » member page
property OnGetDetachedMessage;
Verify side: fires when a detached signature is being verified, so the app can hand back the original (detached) content stream that the signature was computed over. » member page
property OnExternalCounterSign;
Producer side: fires while finalizing a produced signature (from either SignData or CounterSignData) when this event is assigned, letting the app obtain an external RFC 3161 timestamp over the signer's signature; the app posts the request to the TSA (typically at TimeStampURL) and returns the response to embed as an unsigned counter-signature attribute. » member page
property OnGetSignatureAlgorithm;
Producer side: lets the app override the CMS signatureAlgorithm OID (and the raw-vs-digest signing mode) auto-derived for a signer; used for non-default algorithm identifiers. » member page

classTstCustomMPEnvelopedData

inherits from TstBaseMPCMSComponent

constructor Create(AOwner: TComponent); override;
Base class implementing CMS/PKCS#7 EnvelopedData (hybrid public-key encryption to one or more recipients). Apps normally use the published TstMPEnvelopedData component via the Encrypt overloads and Decrypt; this custom base lets descendants decide which properties to publish. » member page
destructor Destroy; override;
Standard component teardown; apps do not call it directly. It frees the internal recipient-e-mail list used by the multi-recipient Encrypt overloads before the inherited destructor runs. » member page
procedure Clear; override;
Drops the loaded EnvStruct structure and cached Content Encryption parameters and forces two GC sweeps. Call it when reusing the component for an unrelated message; it is chained by the Broker's Clear. » member page
function Decrypt(aStream, aDest: TStream): Boolean;
Consumer side: opens the EnvelopedData in aStream, finds a RecipientInfo addressed to a certificate whose private key is available in KeysAndCerts, unwraps the content-encryption key and writes the decrypted content to aDest (pass nil to test decryptability only). Returns False on bad format or when no matching recipient key is found. » member page
function Encrypt(aCert: iCertificate; aContent, aDest: TStream): Boolean; overload;
Producer side: encrypts aContent to the single recipient identified by the certificate aCert, writing the EnvelopedData to aDest. Pass nil to have OnAddRecipient supply the recipient certificate. » member page
function Encrypt(aRecipientEMail: string; aContent, aDest: TStream): Boolean; overload;
Encrypts aContent to the recipient whose certificate is located by e-mail address in KeysAndCerts. If no certificate matches, CertificateNotFound is set and OnRecipientCertNotFound fires. Use this when addressing by e-mail (S/MIME style) rather than holding the certificate. » member page
function Encrypt(aRecipientEMailList: TStrings; AContent, ADest: TStream): Boolean; overload;
Encrypts aContent to every recipient whose certificate is found by e-mail in the aRecipientEMailList; addresses with no matching certificate are skipped (firing OnRecipientCertNotFound). Fails only if not one recipient certificate could be resolved. Use this for multi-recipient enveloping. » member page

classTstMPEnvelopedData — component reference

inherits from TstCustomMPEnvelopedData

Ready-to-use CMS/PKCS#7 EnvelopedData component (hybrid public-key encryption to one or more recipients). Drop it on a form or create it at run time, point KeysAndCerts at a certificate store, then call one of the inherited Encrypt overloads to produce an encrypted message and Decrypt to open one addressed to a certificate whose private key the store holds.

property CertificateNotFound;
Run-time result values: Result flag set by both Encrypt and Decrypt: on the producer side True when a recipient certificate could not be resolved (see OnRecipientCertNotFound); on the consumer side True when no RecipientInfo matched a private key held in KeysAndCerts. » member page
property ContentOnly;
When True the component reads/writes only the bare inner EnvelopedData structure without the outer ContentInfo wrapper. Apps rarely set this directly; the CMS broker uses it when nesting one CMS layer inside another. » member page
property EnvelopeType;
Which CMS envelope this is - pEnvelopedData or pAuthEnvelopedData. Read it after Encrypt to see which the chosen content cipher produced, or after Decrypt to see which arrived. See the declaration on the custom base for the one case where it is an input. » member page
property IllegalFormat;
Read after Decrypt: True when the input stream was not a well-formed EnvelopedData message. Consumer-side status flag. » member page
property SMIMECapabilities;
The set of symmetric ciphers this component advertises/accepts as S/MIME capabilities; pre-filled at construction with the locally supported algorithms. Adjust it to restrict or reorder the content-encryption algorithms offered. » member page
property ContentType;
Per-message values: CMS content-type tag applied to the innermost data (default pData). Set it when enveloping content that is itself a CMS structure so the recipient knows what the decrypted bytes represent. » member page
property RSAOAEPMGFHashAlgorithm;
Hash used inside the MGF1 mask-generation function for RSAES-OAEP key transport; only consulted when UseRSAOAEPEncryption is True. » member page
property RSAOAEPHashAlgorithm;
Hash used for the RSAES-OAEP label/seed when wrapping the content key to an RSA recipient; only consulted when UseRSAOAEPEncryption is True. » member page
property UseRSAOAEPEncryption;
When True, RSA recipients get the content key wrapped with RSAES-OAEP instead of the legacy PKCS#1 v1.5 padding. Enable this for modern interop/security; leave off only for old receivers that require v1.5. » member page
property KeysAndCerts;
Associated components: The certificate/key store used to locate recipient certificates (encrypt side) and the matching private keys (decrypt side). Must be assigned before any Encrypt/Decrypt call. » member page
property OnAddRecipient;
Events: Fires once per recipient slot while encrypting, letting the app supply or substitute the recipient certificate (e.g. when Encrypt was called with a nil certificate). Producer-side only. » member page
property OnRecipientCertNotFound;
Fires while encrypting when a recipient addressed by e-mail has no certificate in KeysAndCerts, so the app can prompt for or fetch one. Producer-side only. » member page
property OnGetKEMRecipientParams;
Per-recipient hook to override the KEMRecipientInfo (RFC 9629) algorithm choices (KEM/KDF/key-wrap OIDs and KEK length) when encrypting to a post-quantum KEM recipient such as ML-KEM. Producer-side only. » member page
property OnGetKeyAgreeRecipientParams;
Per-recipient hook to override the KeyAgreeRecipientInfo (RFC 5753/8418) algorithm choices (key-agreement scheme, key-wrap OID, KEK length) when encrypting to an ECDH/X25519/X448 recipient. Producer-side only. » member page

classTstCustomMPCMSBroker

inherits from TstBaseMPCMSComponent

function Decode(aStream, aDest: TStream; var aActions: TContentTypeArray): Boolean; overload;
Broker that combines a SignedData and an EnvelopedData component so an app can process arbitrarily nested CMS messages (e.g. sign-then-encrypt) with a single call. Full description »
function Decode(aStream, aDest: TStream; aActionDescriptions: TStrings): Boolean; overload;
As the array overload, but reports the peeled layers (and, per signer, the signing certificate's distinguished-name fields) as human-readable lines appended to aActionDescriptions. Use this when you want a displayable summary of who signed / who it was encrypted to. » member page
function Encode(aActions: TContentTypeArray; aStream, aDest: TStream; aDataType: tPKCS7DataType = pData): Boolean; overload;
Builds a nested CMS message: applies each protection in aActions in turn (element 0 wraps the raw content first, so it is the innermost layer; later elements wrap around it and end up outermost) to aStream, writing the result to aDest. Full description »
procedure Clear; override;
Clears the Broker and cascades Clear to the attached EnvelopedData and SignedData components. Call between unrelated messages. » member page

classTstMPCMSBroker — component reference

inherits from TstCustomMPCMSBroker

Ready-to-use CMS broker component that processes arbitrarily nested CMS messages (e.g. signed-then-enveloped) in a single Encode/Decode call by driving an attached EnvelopedData and SignedData helper. Use this instead of wiring the two helper components by hand when a message may carry several stacked protection layers.

property AllowExpiredCertificates;
When True, certificates encountered while verifying/importing a signed or enveloped layer are accepted even if expired. Set False to reject messages whose signer or recipient certificate is out of its validity period. » member page
property SMIMECapabilities;
S/MIME capabilities advertised when the broker produces a message; forwarded to the underlying SignedData/EnvelopedData helpers. » member page
property KeysAndCerts;
Associated components: The certificate/key store shared by the enveloping and signing operations the broker performs. Assign before Encode/Decode. » member page
property EnvelopedData;
The EnvelopedData helper the broker calls to peel or apply an encryption layer. Wire it to a TstMPEnvelopedData instance; required for any message that has an enveloped layer. » member page
property SignedData;
The SignedData helper the broker calls to peel or apply a signature layer. Wire it to a TstMPSignedData instance; required for any message that has a signed layer. » member page
property OnAddRecipient;
Forwarded to the EnvelopedData helper: fires per recipient while the broker builds an enveloped layer, letting the app supply recipient certificates. Producer-side only. » member page
property OnAddSigner;
Forwarded to the SignedData helper: fires per signer while the broker builds a signed layer, letting the app supply signing certificates. Producer-side only. » member page

Types (enumerations, sets, aliases)

proctSignatureEvent

  tSignatureEvent = procedure (Sender: TObject; aSignerCert: iCertificate) of object;

proctCounterSignatureEvent

  tCounterSignatureEvent = procedure (Sender            : TObject;
                                      aSignerCert       : iCertificate;
                                      aCounterSignerCert: iCertificate;
                                      aTimeStamp        : TDateTime) of object;

proctAddCertificateEvent

  tAddCertificateEvent = procedure (Sender: TObject;
                                    aIndex: Integer;
                                var aCert : iCertificate;
                                var aDone : Boolean) of object;

proctEmailEvent

  tEmailEvent = procedure (Sender: TObject; aEmailAddress: string) of object;

proctGetCMSSignatureAlgorithmEvent

Lets the application override the CMS signatureAlgorithm chosen for a signer. aSigAlgOID defaults to the auto-derived OID and aRawSigning to whether the to-be-signed bytes are signed directly (EdDSA/ML-DSA/composite) rather than as a pre-computed digest (RSA/ECDSA).

  tGetCMSSignatureAlgorithmEvent = procedure (Sender       : TObject;
                                              const aCert  : iCertificate;
                                              var aSigAlgOID: ObjectIdentifier;
                                              var aRawSigning: Boolean) of object;

proctGetKEMRecipientParamsEvent

Per-recipient override of the CMS EnvelopedData KEMRecipientInfo (RFC 9629) algorithm choices: the KEM OID, the KDF OID, the key-wrap OID and the KEK length (in bytes). Defaults are the recipient's ML-KEM OID, HKDF-SHA256, AES-256 key wrap and a 32-byte KEK.

  tGetKEMRecipientParamsEvent = procedure (Sender         : TObject;
                                           const aCert    : iCertificate;
                                           var aKemOID,
                                               aKdfOID,
                                               aWrapOID   : ObjectIdentifier;
                                           var aKekLength : Integer) of object;

proctGetKeyAgreeRecipientParamsEvent

Per-recipient override of the CMS EnvelopedData KeyAgreeRecipientInfo (RFC 5753 / RFC 8418) algorithm choices: the key-agreement scheme OID (dhSinglePass-stdDH-*kdf-scheme), the key-wrap OID and the KEK length (in bytes). Defaults are sha256kdf (sha512kdf for X448), AES-256 key wrap and a 32-byte KEK.

  tGetKeyAgreeRecipientParamsEvent = procedure (Sender         : TObject;
                                                const aCert    : iCertificate;
                                                var aSchemeOID,
                                                    aWrapOID   : ObjectIdentifier;
                                                var aKekLength : Integer) of object;

proctGetDetachedMessageEvent

  tGetDetachedMessageEvent = procedure (Sender  : TObject;
                                    var aMessage: TCustomMemoryStream) of object;

procTExternalCounterSignEvent

  TExternalCounterSignEvent = procedure (Sender   : TObject;
                                   const aURL     : string;
                                         aRequest : TMemoryStream;
                                         aResponse: TMemoryStream) of object;

arraytContentTypeArray

  tContentTypeArray = array of tPKCS7DataType;

Routines