summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/leap/mx/_version.py541
-rw-r--r--src/leap/mx/alias_resolver.py3
-rw-r--r--src/leap/mx/check_recipient_access.py4
-rw-r--r--src/leap/mx/couchdbhelper.py70
-rw-r--r--src/leap/mx/fingerprint_resolver.py98
-rw-r--r--src/leap/mx/mail_receiver.py120
-rw-r--r--src/leap/mx/tcp_map.py1
-rw-r--r--src/leap/mx/tests/__init__.py1
-rw-r--r--src/leap/mx/tests/test_mail_receiver.py304
-rw-r--r--src/leap/mx/tests/tester.py (renamed from src/leap/mx/tester.py)0
10 files changed, 941 insertions, 201 deletions
diff --git a/src/leap/mx/_version.py b/src/leap/mx/_version.py
index 2367de5..ed9fc86 100644
--- a/src/leap/mx/_version.py
+++ b/src/leap/mx/_version.py
@@ -1,74 +1,157 @@
-IN_LONG_VERSION_PY = True
# This file helps to compute a version number in source trees obtained from
# git-archive tarball (such as those provided by githubs download-from-tag
-# feature). Distribution tarballs (build by setup.py sdist) and build
+# feature). Distribution tarballs (built by setup.py sdist) and build
# directories (produced by setup.py build) will contain a much shorter file
# that just contains the computed version number.
# This file is released into the public domain. Generated by
-# versioneer-0.7+ (https://github.com/warner/python-versioneer)
-
-# these strings will be replaced by git during git-archive
-git_refnames = "$Format:%d$"
-git_full = "$Format:%H$"
+# versioneer-0.16 (https://github.com/warner/python-versioneer)
+"""Git implementation of _version.py."""
+import errno
+import os
+import re
import subprocess
import sys
-def run_command(args, cwd=None, verbose=False):
- try:
- # remember shell=False, so use git.cmd on windows, not just git
- p = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=cwd)
- except EnvironmentError:
- e = sys.exc_info()[1]
+
+def get_keywords():
+ """Get the keywords needed to look up the version information."""
+ # these strings will be replaced by git during git-archive.
+ # setup.py/versioneer.py will grep for the variable names, so they must
+ # each be defined on a line of their own. _version.py will just call
+ # get_keywords().
+ git_refnames = "$Format:%d$"
+ git_full = "$Format:%H$"
+ keywords = {"refnames": git_refnames, "full": git_full}
+ return keywords
+
+
+class VersioneerConfig:
+ """Container for Versioneer configuration parameters."""
+
+
+def get_config():
+ """Create, populate and return the VersioneerConfig() object."""
+ # these strings are filled in when 'setup.py versioneer' creates
+ # _version.py
+ cfg = VersioneerConfig()
+ cfg.VCS = "git"
+ cfg.style = "pep440"
+ cfg.tag_prefix = ""
+ cfg.parentdir_prefix = "None"
+ cfg.versionfile_source = "src/leap/mx/_version.py"
+ cfg.verbose = False
+ return cfg
+
+
+class NotThisMethod(Exception):
+ """Exception raised if a method is not valid for the current scenario."""
+
+
+LONG_VERSION_PY = {}
+HANDLERS = {}
+
+
+def register_vcs_handler(vcs, method): # decorator
+ """Decorator to mark a method as the handler for a particular VCS."""
+ def decorate(f):
+ """Store f in HANDLERS[vcs][method]."""
+ if vcs not in HANDLERS:
+ HANDLERS[vcs] = {}
+ HANDLERS[vcs][method] = f
+ return f
+ return decorate
+
+
+def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
+ """Call the given command(s)."""
+ assert isinstance(commands, list)
+ p = None
+ for c in commands:
+ try:
+ dispcmd = str([c] + args)
+ # remember shell=False, so use git.cmd on windows, not just git
+ p = subprocess.Popen([c] + args, cwd=cwd, stdout=subprocess.PIPE,
+ stderr=(subprocess.PIPE if hide_stderr
+ else None))
+ break
+ except EnvironmentError:
+ e = sys.exc_info()[1]
+ if e.errno == errno.ENOENT:
+ continue
+ if verbose:
+ print("unable to run %s" % dispcmd)
+ print(e)
+ return None
+ else:
if verbose:
- print("unable to run %s" % args[0])
- print(e)
+ print("unable to find command, tried %s" % (commands,))
return None
stdout = p.communicate()[0].strip()
- if sys.version >= '3':
+ if sys.version_info[0] >= 3:
stdout = stdout.decode()
if p.returncode != 0:
if verbose:
- print("unable to run %s (error)" % args[0])
+ print("unable to run %s (error)" % dispcmd)
return None
return stdout
-import sys
-import re
-import os.path
+def versions_from_parentdir(parentdir_prefix, root, verbose):
+ """Try to determine the version from the parent directory name.
+
+ Source tarballs conventionally unpack into a directory that includes
+ both the project name and a version string.
+ """
+ dirname = os.path.basename(root)
+ if not dirname.startswith(parentdir_prefix):
+ if verbose:
+ print("guessing rootdir is '%s', but '%s' doesn't start with "
+ "prefix '%s'" % (root, dirname, parentdir_prefix))
+ raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
+ return {"version": dirname[len(parentdir_prefix):],
+ "full-revisionid": None,
+ "dirty": False, "error": None}
-def get_expanded_variables(versionfile_source):
+
+@register_vcs_handler("git", "get_keywords")
+def git_get_keywords(versionfile_abs):
+ """Extract version information from the given file."""
# the code embedded in _version.py can just fetch the value of these
- # variables. When used from setup.py, we don't want to import
- # _version.py, so we do it with a regexp instead. This function is not
- # used from _version.py.
- variables = {}
+ # keywords. When used from setup.py, we don't want to import _version.py,
+ # so we do it with a regexp instead. This function is not used from
+ # _version.py.
+ keywords = {}
try:
- f = open(versionfile_source,"r")
+ f = open(versionfile_abs, "r")
for line in f.readlines():
if line.strip().startswith("git_refnames ="):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
- variables["refnames"] = mo.group(1)
+ keywords["refnames"] = mo.group(1)
if line.strip().startswith("git_full ="):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
- variables["full"] = mo.group(1)
+ keywords["full"] = mo.group(1)
f.close()
except EnvironmentError:
pass
- return variables
+ return keywords
+
-def versions_from_expanded_variables(variables, tag_prefix, verbose=False):
- refnames = variables["refnames"].strip()
+@register_vcs_handler("git", "keywords")
+def git_versions_from_keywords(keywords, tag_prefix, verbose):
+ """Get version information from git keywords."""
+ if not keywords:
+ raise NotThisMethod("no keywords at all, weird")
+ refnames = keywords["refnames"].strip()
if refnames.startswith("$Format"):
if verbose:
- print("variables are unexpanded, not using")
- return {} # unexpanded, so not in an unpacked git-archive tarball
+ print("keywords are unexpanded, not using")
+ raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
refs = set([r.strip() for r in refnames.strip("()").split(",")])
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
@@ -93,111 +176,309 @@ def versions_from_expanded_variables(variables, tag_prefix, verbose=False):
r = ref[len(tag_prefix):]
if verbose:
print("picking %s" % r)
- return { "version": r,
- "full": variables["full"].strip() }
- # no suitable tags, so we use the full revision id
+ return {"version": r,
+ "full-revisionid": keywords["full"].strip(),
+ "dirty": False, "error": None
+ }
+ # no suitable tags, so version is "0+unknown", but full hex is still there
if verbose:
- print("no suitable tags, using full revision id")
- return { "version": variables["full"].strip(),
- "full": variables["full"].strip() }
-
-def versions_from_vcs(tag_prefix, versionfile_source, verbose=False):
- # this runs 'git' from the root of the source tree. That either means
- # someone ran a setup.py command (and this code is in versioneer.py, so
- # IN_LONG_VERSION_PY=False, thus the containing directory is the root of
- # the source tree), or someone ran a project-specific entry point (and
- # this code is in _version.py, so IN_LONG_VERSION_PY=True, thus the
- # containing directory is somewhere deeper in the source tree). This only
- # gets called if the git-archive 'subst' variables were *not* expanded,
- # and _version.py hasn't already been rewritten with a short version
- # string, meaning we're inside a checked out source tree.
+ print("no suitable tags, using unknown + full revision id")
+ return {"version": "0+unknown",
+ "full-revisionid": keywords["full"].strip(),
+ "dirty": False, "error": "no suitable tags"}
- try:
- here = os.path.abspath(__file__)
- except NameError:
- # some py2exe/bbfreeze/non-CPython implementations don't do __file__
- return {} # not always correct
-
- # versionfile_source is the relative path from the top of the source tree
- # (where the .git directory might live) to this file. Invert this to find
- # the root from __file__.
- root = here
- if IN_LONG_VERSION_PY:
- for i in range(len(versionfile_source.split("/"))):
- root = os.path.dirname(root)
- else:
- root = os.path.dirname(here)
+
+@register_vcs_handler("git", "pieces_from_vcs")
+def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
+ """Get version from 'git describe' in the root of the source tree.
+
+ This only gets called if the git-archive 'subst' keywords were *not*
+ expanded, and _version.py hasn't already been rewritten with a short
+ version string, meaning we're inside a checked out source tree.
+ """
if not os.path.exists(os.path.join(root, ".git")):
if verbose:
print("no .git in %s" % root)
- return {}
+ raise NotThisMethod("no .git directory")
- GIT = "git"
+ GITS = ["git"]
if sys.platform == "win32":
- GIT = "git.cmd"
- stdout = run_command([GIT, "describe", "--tags", "--dirty", "--always"],
- cwd=root)
- if stdout is None:
- return {}
- if not stdout.startswith(tag_prefix):
- if verbose:
- print("tag '%s' doesn't start with prefix '%s'" % (stdout, tag_prefix))
- return {}
- tag = stdout[len(tag_prefix):]
- stdout = run_command([GIT, "rev-parse", "HEAD"], cwd=root)
- if stdout is None:
- return {}
- full = stdout.strip()
- if tag.endswith("-dirty"):
- full += "-dirty"
- return {"version": tag, "full": full}
-
-
-def versions_from_parentdir(parentdir_prefix, versionfile_source, verbose=False):
- if IN_LONG_VERSION_PY:
- # We're running from _version.py. If it's from a source tree
- # (execute-in-place), we can work upwards to find the root of the
- # tree, and then check the parent directory for a version string. If
- # it's in an installed application, there's no hope.
- try:
- here = os.path.abspath(__file__)
- except NameError:
- # py2exe/bbfreeze/non-CPython don't have __file__
- return {} # without __file__, we have no hope
+ GITS = ["git.cmd", "git.exe"]
+ # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
+ # if there isn't one, this yields HEX[-dirty] (no NUM)
+ describe_out = run_command(GITS, ["describe", "--tags", "--dirty",
+ "--always", "--long",
+ "--match", "%s*" % tag_prefix],
+ cwd=root)
+ # --long was added in git-1.5.5
+ if describe_out is None:
+ raise NotThisMethod("'git describe' failed")
+ describe_out = describe_out.strip()
+ full_out = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
+ if full_out is None:
+ raise NotThisMethod("'git rev-parse' failed")
+ full_out = full_out.strip()
+
+ pieces = {}
+ pieces["long"] = full_out
+ pieces["short"] = full_out[:7] # maybe improved later
+ pieces["error"] = None
+
+ # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty]
+ # TAG might have hyphens.
+ git_describe = describe_out
+
+ # look for -dirty suffix
+ dirty = git_describe.endswith("-dirty")
+ pieces["dirty"] = dirty
+ if dirty:
+ git_describe = git_describe[:git_describe.rindex("-dirty")]
+
+ # now we have TAG-NUM-gHEX or HEX
+
+ if "-" in git_describe:
+ # TAG-NUM-gHEX
+ mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
+ if not mo:
+ # unparseable. Maybe git-describe is misbehaving?
+ pieces["error"] = ("unable to parse git-describe output: '%s'"
+ % describe_out)
+ return pieces
+
+ # tag
+ full_tag = mo.group(1)
+ if not full_tag.startswith(tag_prefix):
+ if verbose:
+ fmt = "tag '%s' doesn't start with prefix '%s'"
+ print(fmt % (full_tag, tag_prefix))
+ pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
+ % (full_tag, tag_prefix))
+ return pieces
+ pieces["closest-tag"] = full_tag[len(tag_prefix):]
+
+ # distance: number of commits since tag
+ pieces["distance"] = int(mo.group(2))
+
+ # commit: short hex revision ID
+ pieces["short"] = mo.group(3)
+
+ else:
+ # HEX: no tags
+ pieces["closest-tag"] = None
+ count_out = run_command(GITS, ["rev-list", "HEAD", "--count"],
+ cwd=root)
+ pieces["distance"] = int(count_out) # total number of commits
+
+ return pieces
+
+
+def plus_or_dot(pieces):
+ """Return a + if we don't already have one, else return a ."""
+ if "+" in pieces.get("closest-tag", ""):
+ return "."
+ return "+"
+
+
+def render_pep440(pieces):
+ """Build up version string, with post-release "local version identifier".
+
+ Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
+ get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
+
+ Exceptions:
+ 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]
+ """
+ if pieces["closest-tag"]:
+ rendered = pieces["closest-tag"]
+ if pieces["distance"] or pieces["dirty"]:
+ rendered += plus_or_dot(pieces)
+ rendered += "%d.g%s" % (pieces["distance"], pieces["short"])
+ if pieces["dirty"]:
+ rendered += ".dirty"
+ else:
+ # exception #1
+ rendered = "0+untagged.%d.g%s" % (pieces["distance"],
+ pieces["short"])
+ if pieces["dirty"]:
+ rendered += ".dirty"
+ return rendered
+
+
+def render_pep440_pre(pieces):
+ """TAG[.post.devDISTANCE] -- No -dirty.
+
+ Exceptions:
+ 1: no tags. 0.post.devDISTANCE
+ """
+ if pieces["closest-tag"]:
+ rendered = pieces["closest-tag"]
+ if pieces["distance"]:
+ rendered += ".post.dev%d" % pieces["distance"]
+ else:
+ # exception #1
+ rendered = "0.post.dev%d" % pieces["distance"]
+ return rendered
+
+
+def render_pep440_post(pieces):
+ """TAG[.postDISTANCE[.dev0]+gHEX] .
+
+ The ".dev0" means dirty. Note that .dev0 sorts backwards
+ (a dirty tree will appear "older" than the corresponding clean one),
+ but you shouldn't be releasing software with -dirty anyways.
+
+ Exceptions:
+ 1: no tags. 0.postDISTANCE[.dev0]
+ """
+ if pieces["closest-tag"]:
+ rendered = pieces["closest-tag"]
+ if pieces["distance"] or pieces["dirty"]:
+ rendered += ".post%d" % pieces["distance"]
+ if pieces["dirty"]:
+ rendered += ".dev0"
+ rendered += plus_or_dot(pieces)
+ rendered += "g%s" % pieces["short"]
+ else:
+ # exception #1
+ rendered = "0.post%d" % pieces["distance"]
+ if pieces["dirty"]:
+ rendered += ".dev0"
+ rendered += "+g%s" % pieces["short"]
+ return rendered
+
+
+def render_pep440_old(pieces):
+ """TAG[.postDISTANCE[.dev0]] .
+
+ The ".dev0" means dirty.
+
+ Eexceptions:
+ 1: no tags. 0.postDISTANCE[.dev0]
+ """
+ if pieces["closest-tag"]:
+ rendered = pieces["closest-tag"]
+ if pieces["distance"] or pieces["dirty"]:
+ rendered += ".post%d" % pieces["distance"]
+ if pieces["dirty"]:
+ rendered += ".dev0"
+ else:
+ # exception #1
+ rendered = "0.post%d" % pieces["distance"]
+ if pieces["dirty"]:
+ rendered += ".dev0"
+ return rendered
+
+
+def render_git_describe(pieces):
+ """TAG[-DISTANCE-gHEX][-dirty].
+
+ Like 'git describe --tags --dirty --always'.
+
+ Exceptions:
+ 1: no tags. HEX[-dirty] (note: no 'g' prefix)
+ """
+ if pieces["closest-tag"]:
+ rendered = pieces["closest-tag"]
+ if pieces["distance"]:
+ rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
+ else:
+ # exception #1
+ rendered = pieces["short"]
+ if pieces["dirty"]:
+ rendered += "-dirty"
+ return rendered
+
+
+def render_git_describe_long(pieces):
+ """TAG-DISTANCE-gHEX[-dirty].
+
+ Like 'git describe --tags --dirty --always -long'.
+ The distance/hash is unconditional.
+
+ Exceptions:
+ 1: no tags. HEX[-dirty] (note: no 'g' prefix)
+ """
+ if pieces["closest-tag"]:
+ rendered = pieces["closest-tag"]
+ rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
+ else:
+ # exception #1
+ rendered = pieces["short"]
+ if pieces["dirty"]:
+ rendered += "-dirty"
+ return rendered
+
+
+def render(pieces, style):
+ """Render the given version pieces into the requested style."""
+ if pieces["error"]:
+ return {"version": "unknown",
+ "full-revisionid": pieces.get("long"),
+ "dirty": None,
+ "error": pieces["error"]}
+
+ if not style or style == "default":
+ style = "pep440" # the default
+
+ if style == "pep440":
+ rendered = render_pep440(pieces)
+ elif style == "pep440-pre":
+ rendered = render_pep440_pre(pieces)
+ elif style == "pep440-post":
+ rendered = render_pep440_post(pieces)
+ elif style == "pep440-old":
+ rendered = render_pep440_old(pieces)
+ elif style == "git-describe":
+ rendered = render_git_describe(pieces)
+ elif style == "git-describe-long":
+ rendered = render_git_describe_long(pieces)
+ else:
+ raise ValueError("unknown style '%s'" % style)
+
+ return {"version": rendered, "full-revisionid": pieces["long"],
+ "dirty": pieces["dirty"], "error": None}
+
+
+def get_versions():
+ """Get version information or return default if unable to do so."""
+ # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
+ # __file__, we can work backwards from there to the root. Some
+ # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which
+ # case we can only use expanded keywords.
+
+ cfg = get_config()
+ verbose = cfg.verbose
+
+ try:
+ return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,
+ verbose)
+ except NotThisMethod:
+ pass
+
+ try:
+ root = os.path.realpath(__file__)
# versionfile_source is the relative path from the top of the source
- # tree to _version.py. Invert this to find the root from __file__.
- root = here
- for i in range(len(versionfile_source.split("/"))):
+ # tree (where the .git directory might live) to this file. Invert
+ # this to find the root from __file__.
+ for i in cfg.versionfile_source.split('/'):
root = os.path.dirname(root)
- else:
- # we're running from versioneer.py, which means we're running from
- # the setup.py in a source tree. sys.argv[0] is setup.py in the root.
- here = os.path.abspath(sys.argv[0])
- root = os.path.dirname(here)
+ except NameError:
+ return {"version": "0+unknown", "full-revisionid": None,
+ "dirty": None,
+ "error": "unable to find root of source tree"}
- # Source tarballs conventionally unpack into a directory that includes
- # both the project name and a version string.
- dirname = os.path.basename(root)
- if not dirname.startswith(parentdir_prefix):
- if verbose:
- print("guessing rootdir is '%s', but '%s' doesn't start with prefix '%s'" %
- (root, dirname, parentdir_prefix))
- return None
- return {"version": dirname[len(parentdir_prefix):], "full": ""}
-
-tag_prefix = ""
-parentdir_prefix = "leap.mx-"
-versionfile_source = "src/leap/mx/_version.py"
-
-def get_versions(default={"version": "unknown", "full": ""}, verbose=False):
- variables = { "refnames": git_refnames, "full": git_full }
- ver = versions_from_expanded_variables(variables, tag_prefix, verbose)
- if not ver:
- ver = versions_from_vcs(tag_prefix, versionfile_source, verbose)
- if not ver:
- ver = versions_from_parentdir(parentdir_prefix, versionfile_source,
- verbose)
- if not ver:
- ver = default
- return ver
+ try:
+ pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
+ return render(pieces, cfg.style)
+ except NotThisMethod:
+ pass
+
+ try:
+ if cfg.parentdir_prefix:
+ return versions_from_parentdir(cfg.parentdir_prefix, root, verbose)
+ except NotThisMethod:
+ pass
+ return {"version": "0+unknown", "full-revisionid": None,
+ "dirty": None,
+ "error": "unable to compute version"}
diff --git a/src/leap/mx/alias_resolver.py b/src/leap/mx/alias_resolver.py
index bf7a58b..a5b5107 100644
--- a/src/leap/mx/alias_resolver.py
+++ b/src/leap/mx/alias_resolver.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# alias_resolver.py
-# Copyright (C) 2013 LEAP
+# Copyright (C) 2013, 2015 LEAP
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -60,6 +60,7 @@ class LEAPPostfixTCPMapAliasServer(postfix.PostfixTCPMapServer):
TCP_MAP_CODE_PERMANENT_FAILURE,
postfix.quote("NOT FOUND SRY"))
else:
+ uuid += "@deliver.local"
# properly encode uuid, otherwise twisted complains when replying
if isinstance(uuid, unicode):
uuid = uuid.encode("utf8")
diff --git a/src/leap/mx/check_recipient_access.py b/src/leap/mx/check_recipient_access.py
index f994e78..67bfd04 100644
--- a/src/leap/mx/check_recipient_access.py
+++ b/src/leap/mx/check_recipient_access.py
@@ -43,7 +43,6 @@ class LEAPPostFixTCPMapAccessServer(postfix.PostfixTCPMapServer):
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):
"""
Return a code and message depending on the result of the factory's
@@ -65,7 +64,7 @@ class LEAPPostFixTCPMapAccessServer(postfix.PostfixTCPMapServer):
elif pubkey is None:
self.sendCode(
TCP_MAP_CODE_TEMPORARY_FAILURE,
- postfix.quote("4.7.13 USER ACCOUNT DISABLED"))
+ postfix.quote("4.7.13 NO PUBKEY FOUND"))
else:
self.sendCode(
TCP_MAP_CODE_SUCCESS,
@@ -85,4 +84,3 @@ class CheckRecipientAccessFactory(LEAPPostfixTCPMapServerFactory):
@property
def _query_message(self):
return "check recipient access"
-
diff --git a/src/leap/mx/couchdbhelper.py b/src/leap/mx/couchdbhelper.py
index 1752b4e..e9cf4a4 100644
--- a/src/leap/mx/couchdbhelper.py
+++ b/src/leap/mx/couchdbhelper.py
@@ -23,7 +23,9 @@ maps, user UUIDs, and GPG keyIDs.
from paisley import client
+from twisted.internet import defer
from twisted.python import log
+from leap.soledad.common.couch import CouchDatabase
class ConnectedCouchDB(client.CouchDB):
@@ -50,6 +52,10 @@ class ConnectedCouchDB(client.CouchDB):
:param str password: (optional) The password for authorization.
:type password: str
"""
+ self._mail_couch_url = "http://%s:%s@%s:%s" % (username,
+ password,
+ host,
+ port)
client.CouchDB.__init__(self,
host,
port=port,
@@ -94,9 +100,10 @@ class ConnectedCouchDB(client.CouchDB):
pubkey = None
if result["rows"]:
doc = result["rows"][0]["doc"]
- uuid = doc["user_id"]
- if "keys" in doc:
- pubkey = doc["keys"]["pgp"]
+ if doc["enabled"]:
+ uuid = doc["user_id"]
+ if "keys" in doc:
+ pubkey = doc["keys"]["pgp"]
return uuid, pubkey
d.addCallback(_get_uuid_and_pubkey_cbk)
@@ -131,3 +138,60 @@ class ConnectedCouchDB(client.CouchDB):
d.addCallbacks(_get_pubkey_cbk, log.err)
return d
+
+ def getCertExpiry(self, fingerprint):
+ """
+ Query couch and return a deferred that will fire with the expiration
+ date for the cert with the given fingerprint.
+
+ :param fingerprint: The cert fingerprint
+ :type fingerprint: str
+
+ :return: A deferred that will fire with the cert expiration date as a
+ str.
+ :rtype: Deferred
+ """
+ d = self.openView(docId="Identity",
+ viewId="cert_expiry_by_fingerprint/",
+ key=fingerprint,
+ reduce=False,
+ include_docs=True)
+
+ def _get_cert_expiry_cbk(result):
+ try:
+ expiry = result["rows"][0]["value"]
+ except (KeyError, IndexError):
+ expiry = None
+ return expiry
+
+ d.addCallback(_get_cert_expiry_cbk)
+ return d
+
+ def put_doc(self, uuid, doc):
+ """
+ Update a document.
+
+ If the document currently has conflicts, put will fail.
+ If the database specifies a maximum document size and the document
+ exceeds it, put will fail and raise a DocumentTooBig exception.
+
+ :param uuid: The uuid of a user
+ :type uuid: str
+ :param doc: A Document with new content.
+ :type doc: leap.soledad.common.couch.CouchDocument
+
+ :return: A deferred which fires with the new revision identifier for
+ the document if the Document object has being updated, or
+ which fails with CouchDBError if there was any error.
+ """
+ # TODO: that should be implemented with paisley
+ url = self._mail_couch_url + "/user-%s" % (uuid,)
+ try:
+ db = CouchDatabase.open_database(url, create=False)
+ return defer.succeed(db.put_doc(doc))
+ except Exception as e:
+ return defer.fail(CouchDBError(e.message))
+
+
+class CouchDBError(Exception):
+ pass
diff --git a/src/leap/mx/fingerprint_resolver.py b/src/leap/mx/fingerprint_resolver.py
new file mode 100644
index 0000000..0a0850d
--- /dev/null
+++ b/src/leap/mx/fingerprint_resolver.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+# fingerprint_resolver.py
+# Copyright (C) 2015 LEAP
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+Classes for resolve expiration date of certs.
+
+Test this with postmap -v -q "fingerprint" tcp:localhost:2424
+"""
+
+
+from datetime import datetime
+from twisted.internet.protocol import ServerFactory
+from twisted.protocols import postfix
+from twisted.python import log
+
+from leap.mx.tcp_map import TCP_MAP_CODE_SUCCESS
+from leap.mx.tcp_map import TCP_MAP_CODE_PERMANENT_FAILURE
+
+
+class LEAPPostfixTCPMapFingerprintServer(postfix.PostfixTCPMapServer):
+ """
+ A postfix tcp map fingerprint resolver server.
+ """
+
+ def _cbGot(self, res):
+ """
+ Return a code and message depending on the result of the factory's
+ get().
+
+ :param res: The fingerprint and expiration date of the cert
+ :type res: (str, str)
+ """
+ fingerprint, expiry = (None, None)
+ if res is not None:
+ fingerprint, expiry = res
+
+ if expiry is None:
+ code = TCP_MAP_CODE_PERMANENT_FAILURE
+ msg = "NOT FOUND SRY"
+ elif expiry < datetime.utcnow().strftime("%Y-%m-%d"):
+ code = TCP_MAP_CODE_PERMANENT_FAILURE
+ msg = "EXPIRED CERT"
+ else:
+ # properly encode expiry, otherwise twisted complains when replying
+ if isinstance(expiry, unicode):
+ expiry = expiry.encode("utf8")
+ code = TCP_MAP_CODE_SUCCESS
+ msg = fingerprint + " " + expiry
+
+ self.sendCode(code, postfix.quote(msg))
+
+
+class FingerprintResolverFactory(ServerFactory, object):
+ """
+ A factory for postfix tcp map fingerprint resolver servers.
+ """
+
+ protocol = LEAPPostfixTCPMapFingerprintServer
+
+ def __init__(self, couchdb):
+ """
+ Initialize the factory.
+
+ :param couchdb: A CouchDB client.
+ :type couchdb: leap.mx.couchdbhelper.ConnectedCouchDB
+ """
+ self._cdb = couchdb
+
+ def get(self, fingerprint):
+ """
+ Look up the cert expiration date based on fingerprint.
+
+ :param fingerprint: The cert fingerprint.
+ :type fingerprint: str
+
+ :return: A deferred that will be fired with the expiration date.
+ :rtype: Deferred
+ """
+ log.msg("look up: %s" % (fingerprint,))
+ d = self._cdb.getCertExpiry(fingerprint.lower())
+ d.addCallback(lambda expiry: (fingerprint, expiry))
+ d.addErrback(log.err)
+ return d
diff --git a/src/leap/mx/mail_receiver.py b/src/leap/mx/mail_receiver.py
index 446fd38..7c5a368 100644
--- a/src/leap/mx/mail_receiver.py
+++ b/src/leap/mx/mail_receiver.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# mail_receiver.py
-# Copyright (C) 2013 LEAP
+# Copyright (C) 2013, 2015 LEAP
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -40,6 +40,7 @@ import signal
import json
import email.utils
+from datetime import datetime, timedelta
from email import message_from_string
from twisted.application.service import Service, IService
@@ -51,7 +52,7 @@ from zope.interface import implements
from leap.soledad.common.crypto import EncryptionSchemes
from leap.soledad.common.crypto import ENC_JSON_KEY
from leap.soledad.common.crypto import ENC_SCHEME_KEY
-from leap.soledad.common.couch import CouchDatabase, CouchDocument
+from leap.soledad.common.document import ServerDocument
from leap.keymanager import openpgp
@@ -75,15 +76,16 @@ class MailReceiver(Service):
"""
RETRY_DIR_WATCH_DELAY = 60 * 5 # 5 minutes
- def __init__(self, mail_couch_url, users_cdb, directories, bounce_from,
+ """
+ Time delta to keep stalled emails
+ """
+ MAX_BOUNCE_DELTA = timedelta(days=5)
+
+ def __init__(self, users_cdb, directories, bounce_from,
bounce_subject):
"""
Constructor
- :param mail_couch_url: URL prefix for the couchdb where mail
- should be stored
- :type mail_couch_url: str
-
:param users_cdb: CouchDB instance from where to get the uuid
and pubkey for a user
:type users_cdb: ConnectedCouchDB
@@ -98,11 +100,11 @@ class MailReceiver(Service):
:type bounce_subject: str
"""
# IService doesn't define an __init__
- self._mail_couch_url = mail_couch_url
self._users_cdb = users_cdb
self._directories = directories
self._bounce_from = bounce_from
self._bounce_subject = bounce_subject
+ self._bounce_timestamp = {}
self._processing_skipped = False
def startService(self):
@@ -171,24 +173,21 @@ class MailReceiver(Service):
:param pubkey: public key for the owner of the message
:type pubkey: str
:param message: message contents
- :type message: email.message.Message
+ :type message: str
:return: doc to sync with Soledad or None, None if something
went wrong.
- :rtype: CouchDocument
+ :rtype: ServerDocument
"""
if pubkey is None or len(pubkey) == 0:
log.msg("_encrypt_message: Something went wrong, here's all "
"I know: %r" % (pubkey,))
return None
- # find message's encoding
- message_as_string = message.as_string()
-
- doc = CouchDocument(doc_id=str(pyuuid.uuid4()))
+ doc = ServerDocument(doc_id=str(pyuuid.uuid4()))
# store plain text if pubkey is not available
- data = {'incoming': True, 'content': message_as_string}
+ data = {'incoming': True, 'content': message}
if pubkey is None or len(pubkey) == 0:
doc.content = {
self.INCOMING_KEY: True,
@@ -203,16 +202,6 @@ class MailReceiver(Service):
with openpgp.TempGPGWrapper(gpgbinary='/usr/bin/gpg') as gpg:
gpg.import_keys(pubkey)
key = gpg.list_keys().pop()
-
- # add X-Leap-Provenance header if message is not encrypted
- if message.get_content_type() != 'multipart/encrypted' and \
- '-----BEGIN PGP MESSAGE-----' not in \
- message_as_string:
- message.add_header(
- 'X-Leap-Provenance',
- email.utils.formatdate(),
- pubkey=key["keyid"])
- data = {'incoming': True, 'content': message.as_string()}
doc.content = {
self.INCOMING_KEY: True,
self.ERROR_DECRYPTING_KEY: False,
@@ -225,55 +214,44 @@ class MailReceiver(Service):
return doc
+ @defer.inlineCallbacks
def _export_message(self, uuid, doc):
"""
- Given a UUID and a CouchDocument, it saves it directly in the
+ Given a UUID and a ServerDocument, it saves it directly in the
couchdb that serves as a backend for Soledad, in a db
accessible to the recipient of the mail.
:param uuid: the mail owner's uuid
:type uuid: str
- :param doc: CouchDocument that represents the email
- :type doc: CouchDocument
+ :param doc: ServerDocument that represents the email
+ :type doc: ServerDocument
- :return: True if it's ok to remove the message, False
- otherwise
- :rtype: bool
+ :return: A Deferred which fires if it's ok to remove the message,
+ or fails otherwise
+ :rtype: Deferred
"""
if uuid is None or doc is None:
log.msg("_export_message: Something went wrong, here's all "
"I know: %r | %r" % (uuid, doc))
- return False
+ raise Exception("No uuid or doc")
log.msg("Exporting message for %s" % (uuid,))
-
- db = CouchDatabase(self._mail_couch_url, "user-%s" % (uuid,))
- db.put_doc(doc)
-
+ yield self._users_cdb.put_doc(uuid, doc)
log.msg("Done exporting")
- return True
-
- def _conditional_remove(self, do_remove, filepath):
+ def _remove(self, filepath):
"""
- Removes the message if do_remove is True.
+ Removes the message.
- :param do_remove: True if the message should be removed, False
- otherwise
- :type do_remove: bool
:param filepath: path to the mail
:type filepath: twisted.python.filepath.FilePath
"""
- if do_remove:
- # remove the original mail
- try:
- log.msg("Removing %r" % (filepath.path,))
- filepath.remove()
- log.msg("Done removing")
- except Exception:
- log.err()
- else:
- log.msg("Not removing %r" % (filepath.path,))
+ try:
+ log.msg("Removing %r" % (filepath.path,))
+ filepath.remove()
+ log.msg("Done removing")
+ except Exception:
+ log.err()
def _get_owner(self, mail):
"""
@@ -295,7 +273,7 @@ class MailReceiver(Service):
return None
final_address = delivereds.pop(0)
_, addr = email.utils.parseaddr(final_address)
- uuid, _ = addr.split("@")
+ uuid = addr.split("@")[0]
return uuid
@defer.inlineCallbacks
@@ -317,7 +295,7 @@ class MailReceiver(Service):
except InvalidReturnPathError:
# give up bouncing this message!
log.msg("Will not bounce message because of invalid return path.")
- yield self._conditional_remove(True, filepath)
+ yield self._remove(filepath)
def sleep(self, secs):
"""
@@ -395,10 +373,6 @@ class MailReceiver(Service):
defer.returnValue(None)
log.msg("Mail owner: %s" % (uuid,))
- if uuid is None:
- log.msg("BUG: There was no uuid!")
- defer.returnValue(None)
-
pubkey = yield self._users_cdb.getPubkey(uuid)
if pubkey is None or len(pubkey) == 0:
log.msg(
@@ -411,10 +385,31 @@ class MailReceiver(Service):
defer.returnValue(None)
log.msg("Encrypting message to %s's pubkey" % (uuid,))
- doc = yield self._encrypt_message(pubkey, msg)
+ try:
+ doc = yield self._encrypt_message(pubkey, mail_data)
- do_remove = yield self._export_message(uuid, doc)
- yield self._conditional_remove(do_remove, filepath)
+ yield self._export_message(uuid, doc)
+ yield self._remove(filepath)
+ except Exception as e:
+ yield self._bounce_with_timeout(filepath, msg, e)
+
+ @defer.inlineCallbacks
+ def _bounce_with_timeout(self, filepath, msg, error):
+ if filepath not in self._bounce_timestamp:
+ self._bounce_timestamp[filepath] = datetime.now()
+ log.msg("New stalled email {0!r}: {1!r}".format(filepath, error))
+ defer.returnValue(None)
+
+ current_delta = datetime.now() - self._bounce_timestamp[filepath]
+ if current_delta > self.MAX_BOUNCE_DELTA:
+ log.msg("Bouncing stalled email {0!r}: {1!r}"
+ .format(filepath, error))
+ bounce_reason = "There was a problem in the server and the " \
+ "email could not be delivered."
+ yield self._bounce_message(msg, filepath, bounce_reason)
+ else:
+ log.msg("Still stalled email {0!r} for the last {1}: {2!r}"
+ .format(filepath, str(current_delta), error))
@defer.inlineCallbacks
def _process_incoming_email(self, otherself, filepath, mask):
@@ -440,4 +435,3 @@ class MailReceiver(Service):
except Exception as e:
log.msg("Something went wrong while processing {0!r}: {1!r}"
.format(filepath, e))
- log.err()
diff --git a/src/leap/mx/tcp_map.py b/src/leap/mx/tcp_map.py
index 96db70a..07bf51d 100644
--- a/src/leap/mx/tcp_map.py
+++ b/src/leap/mx/tcp_map.py
@@ -41,7 +41,6 @@ class LEAPPostfixTCPMapServerFactory(ServerFactory, object):
__metaclass__ = ABCMeta
-
def __init__(self, couchdb):
"""
Initialize the factory.
diff --git a/src/leap/mx/tests/__init__.py b/src/leap/mx/tests/__init__.py
index 2002c48..13df919 100644
--- a/src/leap/mx/tests/__init__.py
+++ b/src/leap/mx/tests/__init__.py
@@ -22,6 +22,7 @@ code, using twisted.trial, for testing leap_mx.
__all__ = ['test_alias_resolver']
+
def run():
"""xxx fill me in"""
pass
diff --git a/src/leap/mx/tests/test_mail_receiver.py b/src/leap/mx/tests/test_mail_receiver.py
new file mode 100644
index 0000000..33967ea
--- /dev/null
+++ b/src/leap/mx/tests/test_mail_receiver.py
@@ -0,0 +1,304 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+# test_mail_receiver.py
+# Copyright (C) 2015 LEAP
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+MailReceiver tests
+"""
+
+import codecs
+import json
+import os
+import os.path
+import shutil
+import tempfile
+
+from email.message import Message
+from twisted.internet import defer, reactor
+from twisted.trial import unittest
+
+from leap.keymanager import openpgp
+from leap.mx.couchdbhelper import CouchDBError
+from leap.mx.mail_receiver import MailReceiver
+
+
+BOUNCE_ADDRESS = "bounce@leap.se"
+BOUNCE_SUBJECT = "bounce subject"
+ADDRESS = "leap@leap.se"
+UUID = "13d5203bdd09be1e638bdb1d315251cb"
+
+
+class MailReceiverTestCase(unittest.TestCase):
+ def setUp(self):
+ self.directory = tempfile.mkdtemp(prefix="leap_tests-")
+ os.mkdir(os.path.join(self.directory, "new"))
+
+ self.users_cdb = self.usersCdb()
+ self.receiver = MailReceiver(
+ users_cdb=self.users_cdb,
+ directories=[(self.directory, True)],
+ bounce_from=BOUNCE_ADDRESS,
+ bounce_subject=BOUNCE_SUBJECT)
+ self.receiver.startService()
+
+ def tearDown(self):
+ self.receiver.stopService()
+ shutil.rmtree(self.directory)
+
+ def usersCdb(self):
+ self.pubKey = PUBLIC_KEY
+ self.docs = []
+ self.defer_put_doc = defer.Deferred()
+
+ class UsersCdb(object):
+ def getPubkey(_, uuid):
+ return self.pubKey
+
+ def put_doc(_, uuid, doc):
+ self.docs.append({'uuid': uuid, 'doc': doc})
+ if not self.defer_put_doc.called:
+ reactor.callLater(1, self.defer_put_doc.callback,
+ (uuid, doc))
+ return defer.succeed(None)
+
+ return UsersCdb()
+
+ @defer.inlineCallbacks
+ def test_single_mail(self):
+ msg, path = self.addMail("foo bar")
+ uuid, doc = yield self.defer_put_doc
+ self.assertEqual(uuid, UUID)
+ decmsg = self.decryptDoc(doc)
+ self.assertEqual(msg, decmsg)
+ self.assertFalse(os.path.exists(path))
+
+ @defer.inlineCallbacks
+ def test_put_doc_raises(self):
+ defer_called = defer.Deferred()
+
+ def put_doc_raise(*args):
+ defer_called.callback(None)
+ return defer.fail(CouchDBError())
+
+ self.users_cdb.put_doc = put_doc_raise
+ _, path = self.addMail()
+ yield defer_called
+ self.assertTrue(os.path.exists(path))
+
+ @defer.inlineCallbacks
+ def test_misleading_encoding(self):
+ msg, path = self.addMail(
+ "ñáûä", headers={'Content-Transfer-Encoding': '7Bit'})
+ uuid, doc = yield self.defer_put_doc
+ self.assertEqual(uuid, UUID)
+ decmsg = self.decryptDoc(doc)
+ self.assertEqual(unicode(msg, "utf-8"), decmsg)
+ self.assertFalse(os.path.exists(path))
+
+ def addMail(self, body="", filename="foo", to=ADDRESS,
+ frm="someone@domain.org", subject="sent subject",
+ headers={}):
+ msg = Message()
+ msg.add_header("To", to)
+ msg.add_header(
+ "Delivered-To", UUID + "@deliver.local")
+ msg.add_header("From", frm)
+ msg.add_header("Subject", subject)
+ for header, value in headers.iteritems():
+ msg.add_header(header, value)
+ msg.set_payload(body)
+
+ path = os.path.join(self.directory, "new", filename)
+ with open(path, "w") as f:
+ f.write(msg.as_string())
+
+ return msg.as_string(), path
+
+ def decryptDoc(self, doc):
+ encdoc = doc.content['_enc_json']
+ decdoc = {}
+
+ with openpgp.TempGPGWrapper(gpgbinary='/usr/bin/gpg') as gpg:
+ gpg.import_keys(PRIVATE_KEY)
+ decstr = gpg.decrypt(encdoc)
+ decdoc = json.loads(decstr.data)
+
+ self.assertTrue(decdoc['incoming'])
+ return decdoc['content']
+
+
+# key 24D18DDF: public key "Leap Test Key <leap@leap.se>"
+KEY_FINGERPRINT = "E36E738D69173C13D709E44F2F455E2824D18DDF"
+PUBLIC_KEY = """
+-----BEGIN PGP PUBLIC KEY BLOCK-----
+Version: GnuPG v1.4.10 (GNU/Linux)
+
+mQINBFC9+dkBEADNRfwV23TWEoGc/x0wWH1P7PlXt8MnC2Z1kKaKKmfnglVrpOiz
+iLWoiU58sfZ0L5vHkzXHXCBf6Eiy/EtUIvdiWAn+yASJ1mk5jZTBKO/WMAHD8wTO
+zpMsFmWyg3xc4DkmFa9KQ5EVU0o/nqPeyQxNMQN7px5pPwrJtJFmPxnxm+aDkPYx
+irDmz/4DeDNqXliazGJKw7efqBdlwTHkl9Akw2gwy178pmsKwHHEMOBOFFvX61AT
+huKqHYmlCGSliwbrJppTG7jc1/ls3itrK+CWTg4txREkSpEVmfcASvw/ZqLbjgfs
+d/INMwXnR9U81O8+7LT6yw/ca4ppcFoJD7/XJbkRiML6+bJ4Dakiy6i727BzV17g
+wI1zqNvm5rAhtALKfACha6YO43aJzairO4II1wxVHvRDHZn2IuKDDephQ3Ii7/vb
+hUOf6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Bzk5c121snXh9Swovm
+laBbw6ate3BmbXLh64jVE9Za5sbTWi7PCcbO/bpRy4d6oLmitmNw6cq0vjTLxUYy
+bwuiJxWREkfxuU85EKdouN062YDevH+/YResmlJrcCE7LRlJFeRlKsrrwBU3BqYd
+GgFJjKjQC1peeQ9fj62Y7xfwE9+PXbkiWO5u/Bk8hb1VZH1SoIRU98NHVcp6BVvp
+VK0jLAXuSauSczULmpRjbyt1lhaAqivDTWEEZXiNNbRyp17c3nVdPWOcgBr42hdQ
+z25CgZgyLCsvu82wuXLKJblrIPJX3Yf+si6KqEWBsmwdOWybsjygaF5HvzgFqAAD
+U0goPWoQ71PorP2XOUNp5ZLkBQp5etvtkksjVNMIhnHn8PGMuoxO39EUGlWj2B5l
+Cu8tSosAzB1pS8NcLZzoNoI9dOHrmgJmP+GrOUkcf5GhNZbMoj4GNfGBRYX0SZlQ
+GuDrwNKYj73C4MWyNnnUFyq8nDHJ/G1NpaF2hiof9RBL4PUU/f92JkceXPBXA8gL
+Mz2ig1OButwPPLFGQhWqxXAGrsS3Ny+BhTJfnfIbbkaLLphBpDZm1D9XKbAUvdd1
+RZXoH+FTg9UAW87eqU610npOkT6cRaBxaMK/mDtGNdc=
+=JTFu
+-----END PGP PRIVATE KEY BLOCK-----
+"""
diff --git a/src/leap/mx/tester.py b/src/leap/mx/tests/tester.py
index 05d2d05..05d2d05 100644
--- a/src/leap/mx/tester.py
+++ b/src/leap/mx/tests/tester.py