diff options
| author | drebs <drebs@leap.se> | 2012-12-24 11:31:58 -0200 | 
|---|---|---|
| committer | drebs <drebs@leap.se> | 2012-12-24 11:31:58 -0200 | 
| commit | 15198a7473398a6aa66ac4ab8d6da70bda745bf7 (patch) | |
| tree | 5494d578e605d367dfb9bbdbb34b8dc07c3e2632 | |
| parent | e6fc834f64863a7b3b9a60e540107bbcbd554981 (diff) | |
GPGWrapper extends gnupg.GPG
| -rw-r--r-- | __init__.py | 5 | ||||
| -rw-r--r-- | util.py | 37 | 
2 files changed, 24 insertions, 18 deletions
| diff --git a/__init__.py b/__init__.py index 6a3707ea..abec6488 100644 --- a/__init__.py +++ b/__init__.py @@ -7,7 +7,7 @@ import string  import random  import cStringIO  import hmac -from soledad.util import GPGWrapper +from util import GPGWrapper  class Soledad(object): @@ -85,3 +85,6 @@ class Soledad(object):      def decrypt_symmetric(self, doc_id, data):          h = hmac.new(self._secret, doc_id).hexdigest()          return self.decrypt(data, passphrase=h) + +    #def publish_pubkey(self): +    #    return self._gpg.export_keys( @@ -2,7 +2,7 @@ import os  import gnupg  import re -class GPGWrapper(): +class GPGWrapper(gnupg.GPG):      """      This is a temporary class for handling GPG requests, and should be      replaced by a more general class used throughout the project. @@ -12,13 +12,15 @@ class GPGWrapper():      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) +        super(GPGWrapper, self).__init__(gpgbinary=gpgbinary, +                                         gnupghome=gpghome, verbose=False, +                                         use_agent=False, keyring=None, options=None)      def find_key(self, email):          """          Find user's key based on their email.          """ -        for key in self.gpg.list_keys(): +        for key in self.list_keys():              for uid in key['uids']:                  if re.search(email, uid):                      return key @@ -26,23 +28,24 @@ class GPGWrapper():      def encrypt(self, data, recipient, sign=None, always_trust=True,                  passphrase=None, symmetric=False): -        return self.gpg.encrypt(data, recipient, sign=sign, -                                always_trust=always_trust, -                                passphrase=passphrase, symmetric=symmetric) +        # TODO: manage keys in a way we don't need to "always trust" +        return super(GPGWrapper, self).encrypt(data, recipient, sign=sign, +                                               always_trust=always_trust, +                                               passphrase=passphrase, +                                               symmetric=symmetric)      def decrypt(self, data, always_trust=True, passphrase=None): -        result = self.gpg.decrypt(data, always_trust=always_trust, -                                passphrase=passphrase) -        return result +        # TODO: manage keys in a way we don't need to "always trust" +        return super(GPGWrapper, self).decrypt(data, +                                               always_trust=always_trust, +                                               passphrase=passphrase) -    def import_keys(self, data): -        return self.gpg.import_keys(data) - -    def gen_key_input(self, **kwargs): -        return self.gpg.gen_key_input(**kwargs) - -    def gen_key(self, input): -        return self.gpg.gen_key(input) +    def send_keys(self, keys, keyserver): +        """ +        Send keys to a keyserver. +        """ +        pass +          #---------------------------------------------------------------------------- | 
