I am trying to send and encrypt mail using openssl.
So far, I figure I should use theese commands:
cat ${content} | \
openssl smime -encrypt -inkey lib/me.crt -aes256 -subject "$titre (cs)" -to [email protected] lib/MAQUETTE1-me.pem | \
openssl smime -sign -inkey lib/myroot.key -signer lib/MAQUETTE1-myroot.pem -passin pass:myroot1 | \
tee ~/tmp7/$T/mail-cs-$c |\
sendmail -t [email protected]
another way without cat
and tee
openssl smime -encrypt -in ${contents} -out tmp1 -inkey lib/me.crt -aes256 -subject "$titre (cs)" -to [email protected] lib/MAQUETTE1-me.pem
openssl smime -sign -in tmp2 -out tmp2 -inkey lib/myroot.key -signer lib/MAQUETTE1-myroot.pem -passin pass:myroot1
sendmail -t [email protected] < tmp2
same result.
This work fine, except that I loose the first few line of ${content}
, which is annoying for plain text content, and fatal when sending binary file.
Have I missed something ?
first lines of ~/tmp7/$T/mail-cs-$c
(before being sent to sendmail)
MIME-Version: 1.0
Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg="sha1"; boun
dary="----396B3702CFDE34F2D44DF5C360D9F6FD"
This is an S/MIME signed message
------396B3702CFDE34F2D44DF5C360D9F6FD
To: [email protected]
Subject: contenu du tex 17 (cs)
MIME-Version: 1.0
Content-Disposition: attachment; filename="smime.p7m"
Content-Type: application/x-pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"
Content-Transfer-Encoding: base64
MII5sgYJKoZIhvcNAQcDoII5ozCCOZ8CAQAxgfcwgfQCAQAwXTBQMQswCQYDVQQG
EwJGUjEPMA0GA1UECAwGRnJhbmNlMQ0wCwYDVQQHDARMeW9uMQ0wCwYDVQQKDARP
EDIT:
- I want to use command line, I already use thunderbird with proper plugin, and it works fine.
cat
andtee
are standard unix command, use very often, I don't believe they can p be part of the problem.- I edited body to remove cat and tee.
cat
ortee
?cat
out and just usingopenssl smime -encript .... < ${content}
?(echo Content-type: text/plain; echo; cat $contents) | openssl smime ...
-- or add option-text
which does that for you. For a 'binary file' the receiving MUA probably needs you to be specific, likeimage/png
or whatever it is. Aside:smime -encrypt
doesn't need or use-inkey
(the only key it uses is the publickey in the recipient cert, which is a positional argument).