summaryrefslogtreecommitdiff
path: root/service/app
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2014-08-06 12:05:32 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2014-08-06 12:05:32 +0200
commite4b81f84ca0946382cbd6f09c3f700afcc166cf9 (patch)
treec1a920fd5d0097005f6d5c6a3ac7711b7176f895 /service/app
parent1e1fd328bc43e820e178de7c08f626b1488505e1 (diff)
Added openpgp key generation.
- Not yet usable because of API incompatibilities - (needs upgrade of LEAP python deps to latest version)
Diffstat (limited to 'service/app')
-rw-r--r--service/app/bitmask_libraries/nicknym.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/service/app/bitmask_libraries/nicknym.py b/service/app/bitmask_libraries/nicknym.py
index 5d9c5308..8f5f06d1 100644
--- a/service/app/bitmask_libraries/nicknym.py
+++ b/service/app/bitmask_libraries/nicknym.py
@@ -1,18 +1,38 @@
-from leap.keymanager import KeyManager
+from leap.keymanager import KeyManager, openpgp, KeyNotFound
from .certs import which_bundle
-SOLEDAD_CERT = '/tmp/ca.crt'
-
class NickNym(object):
-
def __init__(self, provider, config, soledad_session, srp_session):
nicknym_url = _discover_nicknym_server(provider)
- self.keymanager = KeyManager('%s@%s' % (srp_session.user_name, provider.domain), nicknym_url, soledad_session.soledad,
+ self._email = '%s@%s' % (srp_session.user_name, provider.domain)
+ self.keymanager = KeyManager('%s@%s' % (srp_session.user_name, provider.domain), nicknym_url,
+ soledad_session.soledad,
srp_session.session_id, which_bundle(provider), provider.api_uri,
provider.api_version,
srp_session.uuid, config.gpg_binary)
+ def generate_openpgp_key(self):
+ if not self._key_exists(self._email):
+ self._gen_key()
+ self._send_key_to_leap()
+
+ def _key_exists(self, email):
+ try:
+ self.keymanager.get_key(email, openpgp.OpenPGPKey, private=True, fetch_remote=False)
+ return True
+ except KeyNotFound:
+ return False
+
+ def _gen_key(self):
+ self.keymanager.gen_key(openpgp.OpenPGPKey)
+
+ def _send_key_to_leap(self):
+ if True:
+ raise NotImplementedError(
+ 'No key sent to leap provider. Reason: leap.keymanager.KeyManager.send_key in latest python module is not compatible with latest LEAP provider')
+ self.keymanager.send_key(openpgp.OpenPGPKey)
+
def _discover_nicknym_server(provider):
- return 'https://nicknym.%s:6425/' % provider.domain
+ return 'https://nicknym.%s:6425/' % provider.domain