summaryrefslogtreecommitdiff
path: root/src/leap
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 /src/leap
parent1e6a435a206a7395f8b10527054ef4f46ad37cbd (diff)
[feat] Write service tokens to a file for email clients to read.
- Resolves: #8435
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/bitmask/core/mail_services.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py
index 79c1495e..ea53ee07 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):