Mike Chirico on 23 Jul 2004 15:51:03 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PLUG] pgp encrypt to email from shell


So this is what I wanted to do: From the command prompt
send GPG encrypted email with the appropriate "pgp-encrypted"
mime types. This way, when the file gets opened, the user
is prompted for the password.  There's no cut and past of
the "pgp" section.

I think this is full-proof. At least it's working. Maybe
someone can improve upon this? If not, feel free to take
it.

First, how it works. A command is piped to this bash
script "sndmailBash". This script calls "sendmail -t"
and passes along the from user and to user, a subject line
and the pgp key. But, the correct "Content-Type" is created.
This way, the user easily opens the email.

For instance:

$  ls -l|./sndmailBash mchirico@comcast.net mchirico@comcast.net "ls listing" 0xA11C1499

A complete description of the script can be found
at the following link:

http://souptonuts.sourceforge.net/code/sndmailBash.html

Here's a listing:

#!/bin/bash
From=${1}
To=${2}
Subject=${3}

Content=$(gpg  -r ${4}  --encrypt --armor )

/usr/sbin/sendmail -t <<EOF
From: ${From}
To: ${To}
Subject: ${Subject}
Mime-Version: 1.0
Content-Type: multipart/encrypted; protocol="application/pgp-encrypted";
	boundary="B835649000072104Jul07"
Content-Disposition: inline
User-Agent: Mutt/1.4.1i


--B835649000072104Jul07
Content-Type: application/pgp-encrypted
Content-Disposition: attachment

Version: 1

--B835649000072104Jul07
Content-Type: application/octet-stream
Content-Disposition: inline; filename="msg.asc"

${Content}


--B835649000072104Jul07--

EOF
  

Did I need to create this script? From my point of view
this seems like a very common need. Maybe it's already included
in gpg...Ok, encrypting yes; but, changing the email header?

I don't think the boundry has to be dynamic. Here it's just
the static string.  I think email is smart enough never to
confuse that with the actual content. Maybe there are strict
rules for generating the "boundary"? If so, could someone
pass them along, and I'll update the script?

Regards,

Mike Chirico
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug