The bridge between mail and CMS: TstSMIMEBroker descends from the CMS
broker in StreamSec.DSI.PkixCms and adds Encode/Decode overloads that take
TsmEmail messages instead of streams - the S/MIME wrapping and unwrapping
of RFC 8551. It supersedes the Indy-based demo broker (stSMIMEId10Broker),
and closes that demo's documented gaps:
- multipart/signed is both PRODUCED and VERIFIED. The demo could do
neither half properly, because TIdMessage discards the raw octets of a
parsed part and a detached signature is computed over exactly those
octets. TsmEmail retains them (see StreamSec.Mail.Message), so the
signed body part travels byte-exact through wrapping and verification.
- everything stays in memory (tSecureMemoryStream); the demo routed
ciphertext and recovered plaintext through Indy attachment temp FILES.
- the signer lookup is algorithm-agnostic (RSA, ECDSA, EdDSA, ML-DSA)
where the demo hard-coded rsaEncryption; OnAddSigner still overrides.
- what is protected is the MIME CONTENT ENTITY (the Content-* headers and
the body), not the whole message with its address headers, matching what
interoperating mail clients sign and encrypt. Messages produced by the
old demo - which wrapped the complete message - are still decoded: a
recovered entity that turns out to be a full message replaces the
destination wholesale.
LAYERING follows the CMS broker's convention: aActions is INNERMOST FIRST,
so MakeContentTypeArray([pSignedData,pEnvelopedData]) is sign-then-encrypt.
Each CMS layer carries a MIME entity, so every layer's eContentType is
id-data (RFC 8551 s3.1). SignedFormat selects multipart/signed (the
default - readable by agents without S/MIME support) or opaque
application/pkcs7-mime signing; it applies to the OUTERMOST layer only,
since a clear signature buried inside an encryption layer clarifies
nothing, and inner signing layers are always opaque.
The cryptography is entirely the attached TstMPSignedData and
TstMPEnvelopedData workers', exactly as for the stream broker: wire
SignedData, EnvelopedData and KeysAndCerts before calling.Feature notes: Mail subsystem notes (SMTP / POP3 / IMAP)
inherits from TstCustomMPCMSBroker
class function CheckIsSMIMEEntity(aEntity: tMimeEntity): Boolean;
class function CheckIsMultipartSignedEntity(aEntity: tMimeEntity): Boolean;
class function CheckIsSMIME(aSrc: TsmEmail): Boolean;
class function CheckIsMultipartSigned(aSrc: TsmEmail): Boolean;
function Encode(aActions: tContentTypeArray; aSrc, aDest: TsmEmail; aDataType: tPKCS7DataType = pData): Boolean; overload;
function Decode(aSrc, aDest: TsmEmail; aActionDescriptions: TStrings): Boolean; overload;
function Decode(aSrc, aDest: TsmEmail; var aActions: tContentTypeArray): Boolean; overload;
inherits from TstCustomSMIMEBroker
Ready-to-use S/MIME broker: wire SignedData, EnvelopedData and KeysAndCerts exactly as for TstMPCMSBroker, then Encode/Decode whole TsmEmail messages. The inherited stream overloads remain available for raw CMS work.
property AllowExpiredCertificates;
property SMIMECapabilities;
property SignedFormat;
property KeysAndCerts;
property EnvelopedData;
property SignedData;
property OnAddRecipient;
property OnAddSigner;
How a signing layer is rendered when it is the outermost layer:
ssfMultipartSigned = multipart/signed with a detached application/pkcs7-signature part (readable without S/MIME support),
ssfOpaque = application/pkcs7-mime smime-type=signed-data.