473,394 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Decrypting GPG/PGP email messages

I know you will shake you head sadly but... I really have to perform such a
suicidal task (even if for a short time and just for internal use).

I have to send by email (over the open internet) a XML file containing
_system commands_ (yes: the kind of stuff like "rm -dfr /") to a server and
have a Python program sitting on this server, fetching and parsing the
e-mail message and executing the commands (maybe with _root privileges_).

Of course, I want to be sure that only the allowed people is able to send
such dangerous messages to my server so I will ask my users to encrypt and
digitally sign their messages using Thunderbird, Enigmail and GPG as
described in this very fine tutorial:

http://goldenspud.com/webrog/archive...crypt-encrypt/

So far, so good, but I still have a couple of doubts about the server side:

1) What would you use to decrypt the messages? The GPG module created by
Andrew Kuchling is declared "incomplete" and "no more maintained" on his
web pages (http://www.amk.ca/python/code/gpg) so I think it is out of the
game. Would you use OpenPGP (http://www.aonalu.net/openpgp/python)? Any
other module?

2) I did not find any mention of _encrypted attachments_ on the Net. Does
anybody know of a tutorial or a guide that explains how to encrypt (with
Thunderbird/Enigmail) and decrypt (with Python) the (ANSI text) files
attached to a email message?

TIA
-----------------------------------
Alessandro Bottoni
Sep 1 '05 #1
10 7654
Alessandro Bottoni <al****************@infinito.it> writes:
1) What would you use to decrypt the messages? The GPG module created by
Andrew Kuchling is declared "incomplete" and "no more maintained" on his
web pages (http://www.amk.ca/python/code/gpg) so I think it is out of the
game.
I think I'd just run gpg as an external command. I've done that from
perl scripts and it's pretty simple.
Would you use OpenPGP (http://www.aonalu.net/openpgp/python)? Any
other module?
Oh hey, I didn't know about that, I'll have to look at it. I started
writing something similar a long time ago and got as far as being able
to decrypt straightforward messages, and have been meaning to get back
to it. But it's great if someone else is doing it more seriously.q
2) I did not find any mention of _encrypted attachments_ on the Net. Does
anybody know of a tutorial or a guide that explains how to encrypt (with
Thunderbird/Enigmail) and decrypt (with Python) the (ANSI text) files
attached to a email message?


PGP/GPG have their own base64 encoding called "ascii armor" in PGP
lingo. This stuff predates widespread use of MIME and traditionally,
PGP messages are sent as ascii armored plain text, not attachments.
You'd just send messages like:

From: alice
To: bob
Subject: encrypted message

-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.2.1 (GNU/Linux)

jA0EAwMC+QyBtnf2kVxgyUgkWXDwnHHu6GR8xYJ4GuorEo8t9B HfExmcwCyUok/z
wZsmoCCdulYjLnAjgU0WZRhe7woCrgy14pzc7PSOhqRPEG1IFJ qeZuM=
=5l/P
-----END PGP MESSAGE-----

Note the complete absence of mime headers and separators. As far as
the mail agents are concerned, the message is just text.

I'm not sure how the Thunderbird/Enigmail plugins work.
Sep 1 '05 #2
<posted & mailed>

Alessandro Bottoni wrote:
I know you will shake you head sadly but... I really have to perform such
a suicidal task (even if for a short time and just for internal use).

I have to send by email (over the open internet) a XML file containing
_system commands_ (yes: the kind of stuff like "rm -dfr /") to a server
and have a Python program sitting on this server, fetching and parsing the
e-mail message and executing the commands (maybe with _root privileges_).

Of course, I want to be sure that only the allowed people is able to send
such dangerous messages to my server so I will ask my users to encrypt and
digitally sign their messages using Thunderbird, Enigmail and GPG as
described in this very fine tutorial:

http://goldenspud.com/webrog/archive...crypt-encrypt/

So far, so good, but I still have a couple of doubts about the server
side:

1) What would you use to decrypt the messages? The GPG module created by
Andrew Kuchling is declared "incomplete" and "no more maintained" on his
web pages (http://www.amk.ca/python/code/gpg) so I think it is out of the
game. Would you use OpenPGP (http://www.aonalu.net/openpgp/python)? Any
other module?
What about using the command line program via os.pipeX("gpg...")?
I've done it this way when I needed to _create_ encrypted mail attachments
using python (you'll need different gpg options for decrypting):

pipe_in, pipe_out = os.popen2("/usr/bin/gpg -q -r KEYID -s"
"--passphrase-fd 0 --batch --no-tty -a -o - -e '%s'"
% path_to_temporary_file)
pipe_in.write("passphrase")
pipe_in.close()

# read encrypted file from pipe_out
pipe_out.close()

2) I did not find any mention of _encrypted attachments_ on the Net. Does
anybody know of a tutorial or a guide that explains how to encrypt (with
Thunderbird/Enigmail) and decrypt (with Python) the (ANSI text) files
attached to a email message?


I can't help you with Thunderbird. In the worst case, you'll have to encrypt
your command file manually and attach the encrypted version to your mail.
KMail does have checkboxes for encrypt/sign every attachment separately...
--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
Sep 1 '05 #3
>>>>> Alessandro Bottoni <al****************@infinito.it> (AB) wrote:
AB> Of course, I want to be sure that only the allowed people is able to send
AB> such dangerous messages to my server so I will ask my users to encrypt and
AB> digitally sign their messages using Thunderbird, Enigmail and GPG ...
What benefit is there in encrypting the messages? It would only prevent
people intercepting the message from seeing what's inside, but it won't
give you any additional protection on the server.

And if somebody can intercept the messages there is a much bigger danger:
They could save the message and replay it later. You can't protect against
this with encryption (well, with encryption they won't know what they
are doing). Neither with a digital signature. Only checking timestamps,
keeping track of the messages received and/or a challenge/response system
will help in this case.
AB> 1) What would you use to decrypt the messages? The GPG module created by
AB> Andrew Kuchling is declared "incomplete" and "no more maintained" on his
AB> web pages (http://www.amk.ca/python/code/gpg) so I think it is out of the
AB> game. Would you use OpenPGP (http://www.aonalu.net/openpgp/python)? Any
AB> other module?


If you only sign, it will be sufficient, but there is a more complete one
(including decryption) in
http://trac.t7a.org/isconf/file/trun.../isconf/GPG.py

--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Sep 2 '05 #4
>>>>> Alessandro Bottoni <al****************@infinito.it> (AB) wrote:
AB> Of course, I want to be sure that only the allowed people is able to send
AB> such dangerous messages to my server so I will ask my users to encrypt and
AB> digitally sign their messages using Thunderbird, Enigmail and GPG ...
What benefit is there in encrypting the messages? It would only prevent
people intercepting the message from seeing what's inside, but it won't
give you any additional protection on the server.

And if somebody can intercept the messages there is a much bigger danger:
They could save the message and replay it later. You can't protect against
this with encryption (well, with encryption they won't know what they
are doing). Neither with a digital signature. Only checking timestamps,
keeping track of the messages received and/or a challenge/response system
will help in this case.
AB> 1) What would you use to decrypt the messages? The GPG module created by
AB> Andrew Kuchling is declared "incomplete" and "no more maintained" on his
AB> web pages (http://www.amk.ca/python/code/gpg) so I think it is out of the
AB> game. Would you use OpenPGP (http://www.aonalu.net/openpgp/python)? Any
AB> other module?


If you only sign, it will be sufficient, but there is a more complete one
(including decryption) in
http://trac.t7a.org/isconf/file/trun.../isconf/GPG.py

--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Sep 2 '05 #5
>>>>> Alessandro Bottoni <al****************@infinito.it> (AB) wrote:
AB> Of course, I want to be sure that only the allowed people is able to send
AB> such dangerous messages to my server so I will ask my users to encrypt and
AB> digitally sign their messages using Thunderbird, Enigmail and GPG ...
What benefit is there in encrypting the messages? It would only prevent
people intercepting the message from seeing what's inside, but it won't
give you any additional protection on the server.

And if somebody can intercept the messages there is a much bigger danger:
They could save the message and replay it later. You can't protect against
this with encryption (well, with encryption they won't know what they
are doing). Neither with a digital signature. Only checking timestamps,
keeping track of the messages received and/or a challenge/response system
will help in this case.
AB> 1) What would you use to decrypt the messages? The GPG module created by
AB> Andrew Kuchling is declared "incomplete" and "no more maintained" on his
AB> web pages (http://www.amk.ca/python/code/gpg) so I think it is out of the
AB> game. Would you use OpenPGP (http://www.aonalu.net/openpgp/python)? Any
AB> other module?


If you only sign, it will be sufficient, but there is a more complete one
(including decryption) in
http://trac.t7a.org/isconf/file/trun.../isconf/GPG.py

--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Sep 2 '05 #6
>>>>> Paul Rubin <http://ph****@NOSPAM.invalid> (PR) wrote:
PR> PGP/GPG have their own base64 encoding called "ascii armor" in PGP
PR> lingo. This stuff predates widespread use of MIME and traditionally,
PR> PGP messages are sent as ascii armored plain text, not attachments.


Most PGP/GPG message I have received recently where Mime encoded in
PGP/MIME (RFC 3156). Thunderbird/Enigmail can use PGP/MIME it says.
Theoretically you can encrypt parts of the message, e.g. only an
attachment, but I wouldn't know if Enigmail can do that.
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Sep 2 '05 #7
[Piet van Oostrum]
>> Alessandro Bottoni <al****************@infinito.it> (AB) wrote:
AB> Of course, I want to be sure that only the allowed people is
AB> able to send such dangerous messages to my server so I will ask
AB> my users to encrypt and digitally sign their messages using
AB> Thunderbird, Enigmail and GPG ...
What benefit is there in encrypting the messages? It would only
prevent people intercepting the message from seeing what's inside, but
it won't give you any additional protection on the server.
Whenever a message contains sensitive information, it is a good idea to
crypt it. Humans, and not only computers, may be harmful! :-) There
are cases where information may not leak, when it vehicles private
information about people. Companies also have industrial secrets. The
mere fact that two people are communicating is often a secret in itself.
And if somebody can intercept the messages there is a much bigger danger:
They could save the message and replay it later. You can't protect against
this with encryption (well, with encryption they won't know what they
are doing). Neither with a digital signature.


Protection against replay is easily guaranteed by sequencing requests,
that is, including a sequence number within the message, each originator
his sequence. A digital signature prevents someone from tampering with
the sequence number without being detected.

--
François Pinard http://pinard.progiciels-bpi.ca
Sep 2 '05 #8
>>>>> François Pinard <pi****@iro.umontreal.ca> (FP) wrote:

FP> Protection against replay is easily guaranteed by sequencing requests,
FP> that is, including a sequence number within the message, each originator
FP> his sequence. A digital signature prevents someone from tampering with
FP> the sequence number without being detected.


Of course. But with the originators manually sending the requests by email
(at least that's how I understood it), this may be a nuisance.
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Sep 2 '05 #9
Piet van Oostrum wrote:
What benefit is there in encrypting the messages? It would only prevent
people intercepting the message from seeing what's inside, but it won't
give you any additional protection on the server.
You are right. Bad guys can still try to send garbage to my system and, with
some luck, can mess everything up. After reading your message I decided to
add some more control over what the remote user can do and how he can reach
the server:
- a list of allowed users (based on e-mail identity plus OTP, see below)
- a list of allowed commands (still with root-level ones, I'm afraid)
- chroot for the most dangerous commands, when possible
It is still dangerous but, frankly, I could not do any better.
And if somebody can intercept the messages there is a much bigger danger:
They could save the message and replay it later. You can't protect against
this with encryption (well, with encryption they won't know what they
are doing). Neither with a digital signature. Only checking timestamps,
keeping track of the messages received and/or a challenge/response system
will help in this case.
You are right again. As a consequence, I decided to add a one-time-password
to the encrypted message, in order to be sure of the sender identity and of
the uniqueness of the message (the OTP works as a sequence item identifier,
as well).

I'm going to use my own implementation of OTP because the existing mechanism
are devoted to protect the remote login channel and cannot be easily
adapted to my weird e-mail-based mechanism. Anyway, I'm going to use a
(encrypted) very long pseudo-random alpha-numeric sequence as a OTP so it
should be quite safe.
If you only sign, it will be sufficient, but there is a more complete one
(including decryption) in
http://trac.t7a.org/isconf/file/trun.../isconf/GPG.py


Thanks for this info. I'm studying it.

-----------------------------------
Alessandro Bottoni
Sep 3 '05 #10
Alessandro Bottoni <al****************@infinito.it> writes:
I'm going to use my own implementation of OTP because the existing
mechanism are devoted to protect the remote login channel and cannot
be easily adapted to my weird e-mail-based mechanism. Anyway, I'm
going to use a (encrypted) very long pseudo-random alpha-numeric
sequence as a OTP so it should be quite safe.


Be very careful. You have to really know what you're doing to have
any chance of implementing something like this securely. See the book
"Practical Cryptography" by Schneier and Ferguson. You're much better
off using GPG/PGP if you can.
Sep 3 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Del | last post by:
I have two question on sending email messages from MS Access (Versio 2000, 2002, and 2003). I have a form with a command button to send an email message, the code behide the button is as follows;...
3
by: Sun | last post by:
If the email server goes down, I won't be able to send messages using SmtpMail. I'll get a "Could not Access CDO.Message ..." error. Is there a way to queue the message so that it can be sent out...
0
by: BL | last post by:
Hi all, I've got a number of sub-folders in my Outlook Express Inbox. I've also set up a number of message rules to make sure that email from particular individuals/organisations are moved to...
1
by: CB | last post by:
CDO is perhaps the most obscure art in web programming, but I hope someone would understand my issue. I have an ASP web application that needs to send email messages in HTML format only -- there...
3
by: Vickie | last post by:
have a client trying to send scanned images thru email. He is using RoadRunner with a 10 mb limit for an email. On Friday, I was sent a 5 mb attachment that did come thru, but it took 30 seconds...
2
by: Li-fan Chen | last post by:
Hi, We find ourselves in the unenviable position of creating an email reader, may I ask how we best parse incoming messages? Ideally we would point the parser at a email stored in a POP3--grab...
1
by: gokhanoz | last post by:
Hi. I can successfully download my email messages with their attachments from my POP3 servers. But, I can not display them correctly to the user. I need a component which is similar to the outlook...
2
by: dst393 via AccessMonster.com | last post by:
Is there a way to upload email messages (all fields, from, to, subject) into an access database? -- Message posted via http://www.accessmonster.com
7
by: cassey14 | last post by:
Hi Everyone.. I hope someone help me on this.. Is it possible that we can attach an email messages inside an access form??please help me.. tanx much in advance.. cassey
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.