DEV Community

StarkMan
StarkMan

Posted on

CMS SignedData verifies a signer only when the signed attributes agree

CMS SignedData verifies a signer only when the signed attributes agree

CMS SignedData appears in signed email, code-distribution formats, document workflows, and long-lived archives. The structure can contain content, one or more signers, certificates, and signed attributes. A parser that recognizes the outer object has not yet established who signed what. The verifier must connect the signer identity to the key, the signed attributes to the content, and the signature to the exact encoded bytes.

RFC 5652 defines the signed-data content type. Each SignerInfo identifies a signer and carries a signature over a digest. When signed attributes are present, the message-digest attribute and content-type attribute are mandatory. The signature is computed over the DER encoding of the signed attributes, not over a casually reconstructed map or a decoded JSON equivalent. The digest attribute must match the content being verified.

Identity and key selection are separate steps

The SignerIdentifier can identify a certificate by issuer and serial number or by subject key identifier. The verifier must resolve that identifier to the intended certificate and public key. If several certificates share similar names, or if the certificate set contains a replacement key, selecting by display name alone can produce the wrong result.

Signature validation then needs the correct algorithm parameters, signature bytes, signed attributes, and content. A valid signature from any certificate in the bag does not mean the message came from the expected signer. Applications should compare the resolved signer identity with an explicit trust or policy decision.

Signed attributes are part of the message

Content type, message digest, signing time, and application-specific attributes can change how a signature is interpreted. Applications should reject duplicate message-digest attributes, unknown critical attributes they cannot process, and attributes that conflict with detached content. They should also avoid rebuilding the signed attribute set with different ordering or encoding rules before verification.

Detached content requires a separate binding check. A document system may store the CMS signature in one record and the payload in another. If the payload changes, the message-digest attribute should fail. If the system validates only the signature over the attribute set, the signature can remain mathematically valid while the referenced document has changed.

Multi-signer objects need an explicit policy

CMS can carry multiple signatures and countersignatures. A workflow must decide whether one approved signer is sufficient, whether all required roles must sign, and how a missing signer is handled. The order of signatures in the object should not be treated as approval order unless the application stores and verifies that separately.

Long-term validation adds more dependencies. A signature may need a timestamp, revocation evidence, and an archive policy that preserves the original bytes. Rewriting the CMS object during archival can invalidate the signature if the encoding changes. Store the exact object and its hashes, then validate from that immutable copy.

Review the whole path

Operators should test a valid signature, a modified payload, a duplicate digest attribute, an unexpected signer, a revoked signer certificate, and a detached-content mismatch. Logs should identify the signer certificate fingerprint, the content digest, the validation policy, and the failure point. They should not log private keys, full documents, or unnecessary personal data.

The central rule is that CMS verification is not a single library call you can trust without knowing what it covered. A trustworthy workflow names the expected signer, verifies the exact content digest, preserves the encoded signed attributes, and records which policy accepted the result.

References

Top comments (0)