From 9a01c2e99e89160386d697fa8851d1d1554b8cb2 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Tue, 14 Oct 2008 18:23:04 +0530 Subject: [bugfix] Don't check gpghome while init_gpghome() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the kind of bug that is easy to miss without proper testing :) init_gpghome() would never work because it would check if self.gpghome was a valid gpghome before creating it :p Reported by Anielkis Herrera González (p0w3r3d) --- slave/autotua/crypt/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) 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) -- cgit v1.2.3-65-gdbad