summaryrefslogtreecommitdiff
path: root/service/pixelated/bitmask_libraries/keymanager.py
diff options
context:
space:
mode:
authorBruno Wagner <bwagner@riseup.net>2016-08-19 21:37:34 -0300
committerBruno Wagner <bwagner@riseup.net>2016-08-19 21:37:34 -0300
commit9cdd52be577fff75830c854bd7738ee1649e7083 (patch)
treeef560dd628bda40832503250e1325283c49ede83 /service/pixelated/bitmask_libraries/keymanager.py
parent9c5811c6b760415372c6cc67a9d34680c990cdd8 (diff)
Started deferring leap session creation #759
Started adapting get_leap_session to deferreds Soledad and keymanager setup calls will now happen in deferreds and leap session creation itself is a deferred with callbacks This is a start in breaking the big blocking calls we were doing on the main thread, this was done without changing code inside the leap libraries yet so things can be further optimized This breaks the ~4 seconds get_leap_session piece into smaller 1 seconds one, that can be further optimized and deferred to even smaller calls There are requests calls happening on the main thread that should get this number even further down Also moved some pieces from bitmask libraries to our bootstrap, because they are not bitmask libraries anymore and that was causing confusion
Diffstat (limited to 'service/pixelated/bitmask_libraries/keymanager.py')
-rw-r--r--service/pixelated/bitmask_libraries/keymanager.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/service/pixelated/bitmask_libraries/keymanager.py b/service/pixelated/bitmask_libraries/keymanager.py
new file mode 100644
index 00000000..78d6e935
--- /dev/null
+++ b/service/pixelated/bitmask_libraries/keymanager.py
@@ -0,0 +1,58 @@
+#
+# Copyright (c) 2014 ThoughtWorks, Inc.
+#
+# Pixelated is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pixelated is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+from leap.keymanager import KeyManager, KeyNotFound
+from pixelated.config import leap_config
+from .certs import LeapCertificate
+from twisted.internet import defer
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class Keymanager(object):
+ def __init__(self, provider, soledad, email_address, token, uuid):
+ nicknym_url = provider._discover_nicknym_server()
+ self._email = email_address
+ self.keymanager = KeyManager(self._email, nicknym_url,
+ soledad,
+ token=token, ca_cert_path=LeapCertificate(provider).provider_api_cert, api_uri=provider.api_uri,
+ api_version=provider.api_version,
+ uid=uuid, gpgbinary=leap_config.gpg_binary)
+
+ @defer.inlineCallbacks
+ def generate_openpgp_key(self):
+ key_present = yield self._key_exists(self._email)
+ if not key_present:
+ logger.info("Generating keys - this could take a while...")
+ yield self._gen_key()
+ yield self._send_key_to_leap()
+
+ @defer.inlineCallbacks
+ def _key_exists(self, email):
+ try:
+ yield self.fetch_key(email, private=True, fetch_remote=False)
+ defer.returnValue(True)
+ except KeyNotFound:
+ defer.returnValue(False)
+
+ def fetch_key(self, email, private=False, fetch_remote=True):
+ return self.keymanager.get_key(email, private=private, fetch_remote=fetch_remote)
+
+ def _gen_key(self):
+ return self.keymanager.gen_key()
+
+ def _send_key_to_leap(self):
+ return self.keymanager.send_key()