summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2015-02-13 10:27:51 -0200
committerDuda Dornelles <ddornell@thoughtworks.com>2015-02-13 12:47:12 -0200
commitc52ce25ac49cdfdc1791bcb65c5262aec63dadbd (patch)
treed7c5ce18b12f9a86f4a0cb09cc163d4534ddbbeb /service
parent2e88b9d9d68bae91cfde466edfc027f19f7c74b8 (diff)
Adding encryption info for a recipient when composing.
To do that we look into the KeysResouce to see if we will find a key for each address entered for the recipients.
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/config/app_factory.py3
-rw-r--r--service/pixelated/resources/keys_resource.py27
-rw-r--r--service/pixelated/resources/root_resource.py4
3 files changed, 32 insertions, 2 deletions
diff --git a/service/pixelated/config/app_factory.py b/service/pixelated/config/app_factory.py
index 8281ea97..8671eaa6 100644
--- a/service/pixelated/config/app_factory.py
+++ b/service/pixelated/config/app_factory.py
@@ -96,6 +96,7 @@ def stop_incoming_mail_fetcher(reactor_stop_function, leap_session):
def init_app(app, leap_home, leap_session):
leap_session.start_background_jobs()
+ keymanager = leap_session.nicknym.keymanager
soledad_querier = SoledadQuerier(soledad=leap_session.account._soledad)
@@ -110,7 +111,7 @@ def init_app(app, leap_home, leap_session):
MailboxIndexerListener.SEARCH_ENGINE = search_engine
InputMail.FROM_EMAIL_ADDRESS = leap_session.account_email()
- app.resource.initialize(soledad_querier, search_engine, mail_service, draft_service)
+ app.resource.initialize(soledad_querier, keymanager, search_engine, mail_service, draft_service)
register(signal=proto.SOLEDAD_DONE_DATA_SYNC,
callback=init_index_and_remove_dupes(querier=soledad_querier,
diff --git a/service/pixelated/resources/keys_resource.py b/service/pixelated/resources/keys_resource.py
new file mode 100644
index 00000000..f8affb73
--- /dev/null
+++ b/service/pixelated/resources/keys_resource.py
@@ -0,0 +1,27 @@
+from email.utils import parseaddr
+from leap.keymanager import OpenPGPKey
+from pixelated.resources import respond_json_deferred
+from twisted.internet.threads import deferToThread
+from twisted.web import server
+from twisted.web.resource import Resource
+
+
+class KeysResource(Resource):
+
+ def __init__(self, keymanager):
+ Resource.__init__(self)
+ self._keymanager = keymanager
+
+ def render_GET(self, request):
+ def finish_request(key):
+ respond_json_deferred(key.get_json(), request)
+
+ def key_not_found(_):
+ respond_json_deferred(None, request, status_code=404)
+
+ _, key_to_find = parseaddr(request.args.get('search')[0])
+ d = deferToThread(lambda: self._keymanager.get_key_from_cache(key_to_find, OpenPGPKey))
+ d.addCallback(finish_request)
+ d.addErrback(key_not_found)
+
+ return server.NOT_DONE_YET
diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py
index 71fe1fce..b45bd00f 100644
--- a/service/pixelated/resources/root_resource.py
+++ b/service/pixelated/resources/root_resource.py
@@ -6,6 +6,7 @@ from pixelated.resources.mail_resource import MailResource
from pixelated.resources.mails_resource import MailsResource
from pixelated.resources.sync_info_resource import SyncInfoResource
from pixelated.resources.tags_resource import TagsResource
+from pixelated.resources.keys_resource import KeysResource
from twisted.web.resource import Resource
from twisted.web.static import File
@@ -21,8 +22,9 @@ class RootResource(Resource):
return self
return Resource.getChild(self, path, request)
- def initialize(self, querier, search_engine, mail_service, draft_service):
+ def initialize(self, querier, keymanager, search_engine, mail_service, draft_service):
self.putChild('assets', File(self._static_folder))
+ self.putChild('keys', KeysResource(keymanager))
self.putChild('attachment', AttachmentsResource(querier))
self.putChild('contacts', ContactsResource(search_engine))
self.putChild('features', FeaturesResource())