S/MIME requires the original message to be enveloped. This means that the original message is encrypted and this fact and the type of encryption is added to the outer message headers, so the client knows how to handle the message contents.
Because of this, the message headers that define the original message format need to be inside the S/MIME envelope, so the client knows which content type it is after decrypting the message.
The correct way is to extract these headers from the original message, then add them before the original message body. Note that these headers must start on the first line, and that after these headers a blank line is required before the original message body starts.
Headers that should be moved into the enveloped message data are
- MIME-Version (optional)
- Content-Type
- Content-Transfer-Encoding
- Content-Disposition (if exists)
"Moved" means that they should be included in the enveloped message data and removed from the outer message headers.
The remaining headers should be left in the envelope message. The openssl cms -encrypt
command will then add the above headers as required for S/MIME encrypted messages.
Example
Original message
From: someone@somedomain.net
To: recipient@otherdomain.net
Subject: It's a test
MIME-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Custom-Header: Additional data
This is the message text.
Good night.
Moved headers before encryption (note the additional blank line)
From: someone@somedomain.net
To: recipient@otherdomain.net
Subject: It's a test
X-Custom-Header: Additional data
MIME-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
This is the message text.
Good night.
Message after encryption
From: someone@somedomain.net
To: recipient@otherdomain.net
Subject: It's a test
X-Custom-Header: Additional data
MIME-Version: 1.0
Content-Disposition: attachment; filename="smime.p7m"
Content-Type: application/pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"
Content-Transfer-Encoding: base64
MIJ5lAYJKoZIhvcNAQcDoIJ5hTCCeYECAQAxggHZMIIB1QIBADCBvDCBtjEaMBgG
A1UEAwwRc2F2aWduYW5vIENFUlQtaTIxJTAjBgNVBAoMHHNhdmlnbmFubyBzb2Z0
d2FyZSBzb2x1dGlvbnMxHjAcBgNVBAsMFUNlcnRpZmljYXRpb24gU2VydmljZTEL
(more encrypted data removed)
Test message
And the recipient would receive after decryption (by its mail client)Test message
Without the html code being interpreted – Nic Stack Feb 28 '18 at 14:55