summaryrefslogtreecommitdiff
path: root/src
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 /src
parent3340e1a898bacdd05fb6e6bf8d37596f7aff81a2 (diff)
[feat] Write service tokens to a file
The thunderbird plugin will read the tokens from there. - Related: #6041
Diffstat (limited to 'src')
-rw-r--r--src/leap/bitmask/backend/components.py22
1 files changed, 22 insertions, 0 deletions
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