summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2016-09-12 22:30:50 +0200
committerRuben Pollan <meskio@sindominio.net>2016-09-13 15:34:06 +0200
commiteebfd5ea79348b19fdd0c3010735580991c3cdd1 (patch)
treedf19f2952ee289ba700934cc98d7e09c0697e5fb
parent1e6a435a206a7395f8b10527054ef4f46ad37cbd (diff)
[feat] Write service tokens to a file for email clients to read.
- Resolves: #8435
-rw-r--r--docs/next-changelog.rst3
-rw-r--r--src/leap/bitmask/core/mail_services.py20
2 files changed, 22 insertions, 1 deletions
diff --git a/docs/next-changelog.rst b/docs/next-changelog.rst
index a0f048b..bac463b 100644
--- a/docs/next-changelog.rst
+++ b/docs/next-changelog.rst
@@ -12,7 +12,8 @@ Features
~~~~~~~~
- `#7965 <https://leap.se/code/issues/7965>`_: Add basic keymanagement to the cli.
- `#8265 <https://leap.se/code/issues/8265>`_: Add a REST API and bitmask.js library for it.
-- `#8400 <https://leap.se/code/issues/8265>`_: Add manual provider registration.
+- `#8400 <https://leap.se/code/issues/8400>`_: Add manual provider registration.
+- `#8435 <https://leap.se/code/issues/8435>`_: Write service tokens to a file for email clients to read.
- Use mail_auth token in the core instead of imap/smtp tokens.
- `#1234 <https://leap.se/code/issues/1234>`_: Description of the new feature corresponding with issue #1234.
diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py
index 79c1495..ea53ee0 100644
--- a/src/leap/bitmask/core/mail_services.py
+++ b/src/leap/bitmask/core/mail_services.py
@@ -22,6 +22,8 @@ This should be moved to the different packages when it stabilizes.
"""
import json
import os
+import shutil
+import tempfile
from collections import defaultdict
from collections import namedtuple
@@ -440,9 +442,11 @@ class StandardMailService(service.MultiService, HookableService):
def registerToken(token):
self._service_tokens[userid] = token
self._active_user = userid
+ return token
d = soledad.get_or_create_service_token('mail_auth')
d.addCallback(registerToken)
+ d.addCallback(self._write_tokens_file, userid)
return d
def stopInstance(self):
@@ -485,6 +489,22 @@ class StandardMailService(service.MultiService, HookableService):
def get_keymanager_session(self, userid):
return self._keymanager_sessions.get(userid)
+ def _write_tokens_file(self, token, userid):
+ tokens_folder = os.path.join(tempfile.gettempdir(), "bitmask_tokens")
+ if os.path.exists(tokens_folder):
+ try:
+ shutil.rmtree(tokens_folder)
+ except OSError as e:
+ log.msg("Can't remove tokens folder %s: %s"
+ % (tokens_folder, e))
+ return
+ os.mkdir(tokens_folder, 0700)
+
+ tokens_path = os.path.join(tokens_folder,
+ "%s.json" % (userid,))
+ with open(tokens_path, 'w') as ftokens:
+ json.dump(self._service_tokens, ftokens)
+
class IMAPService(service.Service):