summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2016-03-30 13:51:01 +0200
committerRuben Pollan <meskio@sindominio.net>2016-04-07 17:25:47 +0200
commit939fefc012213d3aa433caec47e2e0b19d64901e (patch)
tree96094ae463549509625c931e7a9460020eef7620
parent3340e1a898bacdd05fb6e6bf8d37596f7aff81a2 (diff)
[feat] Write service tokens to a file
The thunderbird plugin will read the tokens from there. - Related: #6041
-rw-r--r--changes/next-changelog.rst1
-rw-r--r--src/leap/bitmask/backend/components.py22
2 files changed, 23 insertions, 0 deletions
diff --git a/changes/next-changelog.rst b/changes/next-changelog.rst
index b20efdc8..3240d2bb 100644
--- a/changes/next-changelog.rst
+++ b/changes/next-changelog.rst
@@ -13,6 +13,7 @@ Features
- `#7552 <https://leap.se/code/issues/7552>`_: Improve UI message and add some margin above the msg box.
- `#7656 <https://leap.se/code/issues/7656>`_: Adapt to multi-user aware events.
- `#4469 <https://leap.se/code/issues/4469>`_: Display randomly generated service token on the Help Window.
+- `#6041 <https://leap.se/code/issues/6041>`_: Write service tokens to a file to allow email clients to read them from there.
- Use cred-based authentication on SMTP.
- Experimental support for the Pixelated WebMail.
diff --git a/src/leap/bitmask/backend/components.py b/src/leap/bitmask/backend/components.py
index f9ad1480..bc34c84c 100644
--- a/src/leap/bitmask/backend/components.py
+++ b/src/leap/bitmask/backend/components.py
@@ -20,8 +20,11 @@ Backend components
# TODO [ ] Get rid of all this deferToThread mess, or at least contain
# all of it into its own threadpool.
+import json
import os
+import shutil
import socket
+import tempfile
import time
from functools import partial
@@ -789,6 +792,8 @@ class Soledad(object):
download_if_needed=True)
self._soledad_defer.addCallback(self._set_proxies_cb)
self._soledad_defer.addCallback(self._set_service_tokens_cb)
+ self._soledad_defer.addCallback(self._write_tokens_file,
+ username, domain)
else:
if self._signaler is not None:
self._signaler.signal(self._signaler.soledad_bootstrap_failed)
@@ -811,6 +816,23 @@ class Soledad(object):
d.addCallback(lambda _: result)
return d
+ def _write_tokens_file(self, result, username, domain):
+ tokens_folder = os.path.join(tempfile.gettempdir(), "bitmask_tokens")
+ if os.path.exists(tokens_folder):
+ try:
+ shutil.rmtree(tokens_folder)
+ except OSError as e:
+ logger.error("Can't remove tokens folder %s: %s"
+ % (tokens_folder, e))
+ return
+ os.mkdir(tokens_folder, 0700)
+
+ tokens_path = os.path.join(tokens_folder,
+ "%s@%s.json" % (username, domain))
+ with open(tokens_path, 'w') as ftokens:
+ json.dump(self._service_tokens, ftokens)
+ return result
+
def _set_proxies_cb(self, _):
"""
Update the soledad and keymanager proxies to reference the ones created