aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'slave/autotua/crypt/__init__.py')
-rw-r--r--slave/autotua/crypt/__init__.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/slave/autotua/crypt/__init__.py b/slave/autotua/crypt/__init__.py
index bb97d17..29e37f3 100644
--- a/slave/autotua/crypt/__init__.py
+++ b/slave/autotua/crypt/__init__.py
@@ -20,6 +20,8 @@ class Crypto(object):
self.gpghome = gpghome
self.gpgcmd = 'gpg -a --keyid-format long --trust-model always '
self.gpgcmd += '--homedir="%s" ' % self.gpghome
+
+ def _validate_gpghome(self):
if not os.path.exists(self.gpghome+'/secring.gpg'):
raise Exception('"%s": Invalid GPG homedir' % self.gpghome)
@@ -36,11 +38,13 @@ class Crypto(object):
return line.split(':')[-2]
def export_pubkey(self, file, which):
+ self._validate_gpghome()
gpg_args = '--export "%s" > "%s"' % (which, file)
print self.gpgcmd+gpg_args
subprocess.check_call(self.gpgcmd+gpg_args, shell=True)
def import_pubkey(self, pubkey):
+ self._validate_gpghome()
gpg_args = '--import <<<"%s"' % pubkey
subprocess.check_call(self.gpgcmd+gpg_args, shell=True)
@@ -75,6 +79,7 @@ class Crypto(object):
returns: encrypted_data
"""
+ self._validate_gpghome()
gpg_args = '--encrypt --sign --recipient "%s" <<<"%s"' % (recipient, data)
process = subprocess.Popen(self.gpgcmd+gpg_args, shell=True,
stdout=subprocess.PIPE)
@@ -91,6 +96,7 @@ class Crypto(object):
returns: (decrypted_data, sender)
"""
+ self._validate_gpghome()
gpg_args = '--decrypt <<<"%s"' % data
process = subprocess.Popen(self.gpgcmd+gpg_args, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)