summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2012-12-03 12:12:01 -0200
committerdrebs <drebs@leap.se>2012-12-03 12:12:01 -0200
commit2980e61298dc3a17715ce5693470c3d7f3a86497 (patch)
tree89d1cf3002f25b5c3f075c13d5dc85b9077ff6e2
parent9c63f2becc0caa1f684852224375b54f828cc42e (diff)
Add python-gnupg simple wrapper
-rw-r--r--src/leap/soledad/__init__.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/leap/soledad/__init__.py b/src/leap/soledad/__init__.py
index 6ba64a61..7991f898 100644
--- a/src/leap/soledad/__init__.py
+++ b/src/leap/soledad/__init__.py
@@ -4,3 +4,40 @@
from leap import *
from openstack import *
+
+import gnupg
+
+class GPGWrapper():
+ """
+ This is a temporary class for handling GPG requests, and should be
+ replaced by a more general class used throughout the project.
+ """
+
+ GNUPG_HOME = "~/.config/leap/gnupg"
+ GNUPG_BINARY = "/usr/bin/gpg" # this has to be changed based on OS
+
+ def __init__(self, gpghome=GNUPG_HOME, gpgbinary=GNUPG_BINARY):
+ self.gpg = gnupg.GPG(gnupghome=gpghome, gpgbinary=gpgbinary)
+
+ def find_key(self, email):
+ """
+ Find user's key based on their email.
+ """
+ for key in self.gpg.list_keys():
+ for uid in key['uids']:
+ if re.search(email, uid):
+ return key
+ raise LookupError("GnuPG public key for %s not found!" % email)
+
+ def encrypt(self, data, recipient, sign=None, always_trust=False,
+ passphrase=None, symmetric=False):
+ return self.gpg.encrypt(data, recipient, sign=sign,
+ always_trust=always_trust,
+ passphrase=passphrase, symmetric=symmetric)
+
+ def decrypt(self, data, always_trust=False, passphrase=None):
+ return self.gpg.decrypt(data, always_trust=always_trust,
+ passphrase=passphrase)
+
+ def import_keys(self, data):
+ return self.gpg.import_keys(data)