summaryrefslogtreecommitdiff
path: root/src/leap/mx/check_recipient_access.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2015-03-26 15:25:50 -0300
committerdrebs <drebs@leap.se>2015-04-09 18:19:53 -0300
commit45adb4d6cfdb8b9ed11e3efc398d00ec6dbdc0b0 (patch)
treefb07b5c686aa872608279679de57cd79fd2e0c4c /src/leap/mx/check_recipient_access.py
parente8fd9feb5891b6cd0840afdcae996314ea3849a9 (diff)
[bug] limit pgp key lookup to access check server
In order to minimize the number of couchdb queries and the number of mx lookups in case of junk mail this commit restricts the pgp key lookup to the access check server (and removes it from the alias server). Closes: #6795.
Diffstat (limited to 'src/leap/mx/check_recipient_access.py')
-rw-r--r--src/leap/mx/check_recipient_access.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/leap/mx/check_recipient_access.py b/src/leap/mx/check_recipient_access.py
index cf172c7..0977564 100644
--- a/src/leap/mx/check_recipient_access.py
+++ b/src/leap/mx/check_recipient_access.py
@@ -23,6 +23,7 @@ Test this with postmap -v -q "foo" tcp:localhost:2244
"""
from twisted.protocols import postfix
+from twisted.internet import defer
from leap.mx.tcp_map import LEAPPostfixTCPMapServerFactory
from leap.mx.tcp_map import TCP_MAP_CODE_SUCCESS
@@ -33,6 +34,10 @@ from leap.mx.tcp_map import TCP_MAP_CODE_PERMANENT_FAILURE
class LEAPPostFixTCPMapAccessServer(postfix.PostfixTCPMapServer):
"""
A postfix tcp map recipient access checker server.
+
+ The server potentially receives the uuid and a PGP key for the user, which
+ are looked up by the factory, and will return a permanent or a temporary
+ failure in case either the user or the key don't exist, respectivelly.
"""
def _cbGot(self, value):
@@ -61,5 +66,43 @@ class LEAPPostFixTCPMapAccessServer(postfix.PostfixTCPMapServer):
class CheckRecipientAccessFactory(LEAPPostfixTCPMapServerFactory):
+ """
+ A factory for the recipient access checker.
+
+ When queried, the factory looks up the user's uuid and a PGP key for that
+ user and returns the result to the server's _cbGot() method.
+ """
protocol = LEAPPostFixTCPMapAccessServer
+
+ def _getPubKey(self, uuid):
+ """
+ Look up PGP public key based on user uid.
+
+ :param uuid: The user uid.
+ :type uuid: str
+
+ :return: A deferred that is fired with the uuid and the public key, if
+ available.
+ :rtype: DeferredList
+ """
+ if uuid is None:
+ return defer.succeed([None, None])
+ # properly encode uuid, otherwise twisted complains when replying
+ if isinstance(uuid, unicode):
+ uuid = uuid.encode("utf8")
+ return defer.gatherResults([
+ defer.succeed(uuid),
+ self._cdb.getPubKey(uuid),
+ ])
+
+ def get(self, key):
+ """
+ Look up uuid and PGP public key based on key.
+
+ :param key: The lookup key.
+ :type key: str
+ """
+ d = LEAPPostfixTCPMapServerFactory.get(self, key)
+ d.addCallback(self._getPubKey)
+ return d