Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Mail.SMIMEBroker

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)

Classes, interfaces and records

classTstCustomSMIMEBroker

inherits from TstCustomMPCMSBroker

class function CheckIsSMIMEEntity(aEntity: tMimeEntity): Boolean;
True when the entity is an opaque S/MIME body: application/[x-]pkcs7-mime whose smime-type - when present - is signed-data or enveloped-data, or an octet-stream attachment named *.p7m. certs-only and compressed-data are NOT claimed; they pass through Decode as ordinary content. » member page
class function CheckIsMultipartSignedEntity(aEntity: tMimeEntity): Boolean;
True when the entity is multipart/signed with the pkcs7-signature protocol (x- alias included) and exactly two parts, the second being the signature. » member page
class function CheckIsSMIME(aSrc: TsmEmail): Boolean;
Delegates to CheckIsSMIMEEntity, forwarding aSrc.Root, and returns its result. » member page
class function CheckIsMultipartSigned(aSrc: TsmEmail): Boolean;
Delegates to CheckIsMultipartSignedEntity, forwarding aSrc.Root, and returns its result. » member page
function Encode(aActions: tContentTypeArray; aSrc, aDest: TsmEmail; aDataType: tPKCS7DataType = pData): Boolean; overload;
Applies the protections in aActions - innermost first, as for the stream broker - to aSrc's content entity and writes the wrapped message to aDest. Full description »
function Decode(aSrc, aDest: TsmEmail; aActionDescriptions: TStrings): Boolean; overload;
Peels every S/MIME layer of aSrc - multipart/signed and opaque pkcs7-mime alike, however deeply nested - and writes the recovered message to aDest: the original envelope headers with the recovered content entity. Full description »
function Decode(aSrc, aDest: TsmEmail; var aActions: tContentTypeArray): Boolean; overload;
As above but reports the peeled layers innermost-first, matching the stream broker's array overload. » member page

classTstSMIMEBroker — component reference

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;
When True, certificates encountered while verifying or importing a layer are accepted even if expired. » member page
property SMIMECapabilities;
S/MIME capabilities advertised when producing; forwarded to the attached workers. » member page
property SignedFormat;
multipart/signed (the default) or opaque signing for the outermost signature layer. » member page
property KeysAndCerts;
Associated components: The certificate/key store shared by signing and enveloping. » member page
property EnvelopedData;
The EnvelopedData worker; required for any encrypted layer. » member page
property SignedData;
The SignedData worker; required for any signed layer. » member page
property OnAddRecipient;
Events: Forwarded to the EnvelopedData worker: supplies recipient certificates while an enveloped layer is built. » member page
property OnAddSigner;
Forwarded to the SignedData worker: supplies the signing certificate, overriding the From-address lookup. » member page

Types (enumerations, sets, aliases)

enumtSMIMESignedFormat

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.

  tSMIMESignedFormat = (ssfMultipartSigned, ssfOpaque);