skip to content

In CMS SignedData as S/MIME uses it, why is the signature computed over the signedAttrs, and what does the messageDigest attribute bind?

level: middleimportance: should knowfreq 18%

answer

  1. signature over metadata
  2. content enters as a digest
  3. two attributes always required
  4. DER encoding, explicit SET OF

basics

~20 s

When signedAttrs is present, the signer puts the content's digest into a messageDigest attribute and signs the DER encoding of all signed attributes, so one signature covers the content, through its digest, and metadata such as content type and signing time.

solid answer

~40 s

A CMS `SignerInfo` may carry `signedAttrs`. If it does, RFC 5652 requires at least a content-type attribute and a `messageDigest` attribute holding the digest of the signed content, and the signature is computed over the DER encoding of the whole attribute set rather than over the content directly. The content is bound indirectly: change one byte and the recomputed digest no longer matches `messageDigest`. The design lets one signature also cover what RFC 8551 says S/MIME senders SHOULD include — `signingTime`, `SMIMECapabilities`, the Encryption Key Preference attribute and `signingCertificateV2` — so none of them can be altered or swapped without breaking it. A verifier must compute the digest itself, compare it with `messageDigest`, check that the content-type attribute matches `eContentType`, and verify the signature over the attributes.

go deeper

for a junior

Recall that an S/MIME signature carries signed attributes, and that the messageDigest attribute holds the digest of the message content.

for a middle

Explain the chain: content digest into messageDigest, signature over the DER-encoded attribute set, and the verifier's own recomputation and content-type check.

for a senior

Show what each failure means in a report: a messageDigest mismatch is changed content, a bad signature value is a key or attribute problem, and signingTime is only the signer's claim.

for a principal

Connect the design to policy: attributes like signingCertificateV2 and SMIMECapabilities are only as useful as the clients that emit and honour them, so verify that before relying on them.

## Where the signed attributes live A CMS `SignedData` (RFC 5652, section 5) holds the content — or, for a detached signature, nothing in its place — optional certificates, and one `SignerInfo` per signer. Each `SignerInfo` names the signer's certificate (`sid`, by issuer and serial number or by subject key identifier), the `digestAlgorithm`, an optional set of **signed attributes** (`signedAttrs`), the `signatureAlgorithm`, the `signature` value and an optional set of **unsigned attributes**. `signedAttrs` is optional in CMS: it must be present only when the signed content type is something other than `id-data`. S/MIME signs MIME content as `id-data`, so CMS alone would allow leaving it out. RFC 8551 fills that gap: sending agents **SHOULD** generate one instance each of the signing time, S/MIME capabilities, encryption key preference, message digest and content type attributes. An S/MIME signature therefore normally carries `signedAttrs`, and an interviewer expects you to know what that changes. ## What the signature covers when they are present RFC 5652 section 5.4 changes what is signed: 1. The signer computes the digest of the content with the `digestAlgorithm`: the `eContent` octets for an opaque message, or the first part of a `multipart/signed` message for a detached one. 2. That digest becomes the value of the **`messageDigest`** attribute. 3. The signer DER-encodes the complete set of signed attributes — with an explicit `SET OF` tag, not the `[0]` tag the field carries inside the structure — and computes the signature over that encoding with the **signer's private key**. So the signature never covers the content directly. The content is bound **indirectly**, through the digest stored in an attribute the signature does cover. Without `signedAttrs`, the signature input is the content's digest alone and no metadata is protected. | Attribute | Defined in | What it adds | |---|---|---| | content type | RFC 5652 11.1; required when `signedAttrs` is present | the type of the signed content, which must match `eContentType` | | `messageDigest` | RFC 5652 11.2; required when `signedAttrs` is present | the digest that ties the attributes to the content | | `signingTime` | RFC 5652 11.3; S/MIME senders SHOULD include it | when the signer says it signed | | `SMIMECapabilities` | RFC 8551 2.5.2; SHOULD | algorithms and features the signer supports | | Encryption Key Preference | RFC 8551 2.5.3; SHOULD | which of the signer's certificates to use when encrypting to the signer | | `signingCertificateV2` | RFC 5035; SHOULD | which certificate the signer meant to be verified with | ## Why the design is worth it - **Metadata under the same signature.** Anything in `signedAttrs` is as tamper-evident as the content. An unsigned attribute can be added or stripped without affecting the signature, and CMS forbids the content-type and message-digest attributes from ever being unsigned. - **Pinning the signer's certificate.** The signing certificate attribute (RFC 2634, with version 2 in RFC 5035) was designed against the substitution or re-issue of the certificate used for verification; placing it under the signature fixes which certificate the signer intended. - **Detached signatures fall out naturally.** Because the content enters only through its digest, it can travel elsewhere — as the first part of a `multipart/signed` message — and the verifier supplies it at verification time. ## What a verifier must do RFC 5652 section 5.6 sets the checks, and each one is a different failure an administrator may see reported: 1. **Recompute the digest.** The recipient MUST NOT rely on a digest the originator computed; it digests the content itself and compares the result with `messageDigest`. A mismatch means the content changed after signing. 2. **Match the content type.** The content-type attribute must equal the `eContentType` of the signed content. 3. **Verify the signature** over the DER-encoded attributes, using the public key from the **signer's certificate**. Validating that certificate up to a trust anchor is a separate step, covered in the material on certificate chains. ## Limits worth stating in an interview - **`signingTime` is the signer's claim.** RFC 8551 says the time will most likely be created by the signer and is only as trustworthy as that signer; it is not an independent timestamp. - **Two algorithm choices, not one.** The content digest and the signature algorithm are chosen separately; RFC 8551 recommends a content digest of similar or greater strength than the signature algorithm, and requires agents to support SHA-256 and SHA-512 for it. - **Header fields stay outside.** `signedAttrs` protects the attributes and the content, not the outer mail header fields, which are signed only when the sender wraps the message in `message/rfc822`.

  • What does a CMS signature protect if its SignerInfo carries no signedAttrs at all?
    Only the content: RFC 5652 then feeds the digest of the content alone into the signature, so a changed body is still detected, but there is no signed time, no capabilities and no pin on the signer's certificate. CMS allows this for `id-data` content; RFC 8551 says S/MIME senders SHOULD include signed attributes, so their absence is unusual and worth noticing.
  • Why must CMS signedAttrs be DER-encoded even when the rest of the SignedData uses BER?
    Because the verifier has to rebuild exactly the bytes that were signed. DER gives each value a single encoding, so signer and verifier arrive at the same octets. RFC 5652 requires `SignedAttributes` to be DER-encoded, and the digest is taken over an explicit `SET OF` tag rather than the `[0]` tag the field carries inside the structure.

  • With signed attributes, the signature is computed directly over the message body.
  • A verifier can rely on the messageDigest value the sender put in the message.
  • signingTime is an independent timestamp vouched for by a third party.
  • Unsigned attributes are protected by the signature just like signed ones.
  • CMS requires signed attributes on every signature, whatever the content type.