summaryrefslogtreecommitdiff
path: root/src/leap/email/smtp
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2012-11-05 11:01:20 -0200
committerdrebs <drebs@leap.se>2012-11-05 11:01:20 -0200
commit4d303f98650b1cbcfa102a6771a88a9f5c9884d5 (patch)
treededc13e5573f3617443c66f49f4b89cdc45fdeee /src/leap/email/smtp
parent728eef32a7eab7d90db4a9b72d74cc7ecd1b6265 (diff)
relay raises exception if recipient's key is not found
Diffstat (limited to 'src/leap/email/smtp')
-rw-r--r--src/leap/email/smtp/smtprelay.tac24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/leap/email/smtp/smtprelay.tac b/src/leap/email/smtp/smtprelay.tac
index 8226bf3d..7d8e426d 100644
--- a/src/leap/email/smtp/smtprelay.tac
+++ b/src/leap/email/smtp/smtprelay.tac
@@ -28,6 +28,9 @@ class SMTPDelivery(object):
"""
implements(smtp.IMessageDelivery)
+
+ def __init__(self):
+ self.gpg = GPGWrapper()
def receivedHeader(self, helo, origin, recipients):
myHostname, clientIP = helo
@@ -37,10 +40,15 @@ class SMTPDelivery(object):
return "Received: %s" % Header(headerValue)
def validateTo(self, user):
- """Assert existence of GPG public key for a recipient."""
- # for now just accept any receipient
- print "Accepting mail for %s..." % user.dest
- return lambda: EncryptedMessage(user)
+ """Assert existence of and trust on recipient's GPG public key."""
+ # try to find recipient's public key
+ try:
+ fp = self.gpg.get_fingerprint(user.dest.addrstr)
+ print "Accepting mail for %s..." % user.dest
+ return lambda: EncryptedMessage(user)
+ # TODO: verify if key is trusted
+ except LookupError:
+ raise smtp.SMTPBadRcpt(user)
def validateFrom(self, helo, originAddress):
# accept mail from anywhere. To reject an address, raise
@@ -73,8 +81,11 @@ class EncryptedMessage():
print "Message data complete."
self.lines.append('') # add a trailing newline
self.parseMessage()
- self.encrypt()
- return self.sendMessage()
+ try:
+ self.encrypt()
+ return self.sendMessage()
+ except LookupError:
+ return None
def parseMessage(self):
"""Separate message headers from body."""
@@ -150,6 +161,7 @@ class GPGWrapper():
for uid in key['uids']:
if re.search(email, uid):
return key['fingerprint']
+ raise LookupError("GnuPG public key for %s not found!" % email)
def encrypt(self, data, recipient):
return self.gpg.encrypt(data, recipient)