|
|
|
@ -31,8 +31,12 @@ LINE_USER_ID = 'uid'
|
|
|
|
|
|
|
|
|
|
POS_FINGERPRINT = 9
|
|
|
|
|
|
|
|
|
|
def build_command(key_home, *args, **kwargs):
|
|
|
|
|
cmd = ["gpg", '--homedir', key_home] + list(args)
|
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
|
|
def private_keys( keyhome ):
|
|
|
|
|
cmd = ['/usr/bin/gpg', '--homedir', keyhome, '--list-secret-keys', '--with-colons']
|
|
|
|
|
cmd = build_command(keyhome, '--list-secret-keys', '--with-colons')
|
|
|
|
|
p = subprocess.Popen( cmd, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
|
|
|
|
|
p.wait()
|
|
|
|
|
keys = dict()
|
|
|
|
@ -46,7 +50,7 @@ def private_keys( keyhome ):
|
|
|
|
|
return keys
|
|
|
|
|
|
|
|
|
|
def public_keys( keyhome ):
|
|
|
|
|
cmd = ['/usr/bin/gpg', '--homedir', keyhome, '--list-keys', '--with-colons']
|
|
|
|
|
cmd = build_command(keyhome, '--list-keys', '--with-colons')
|
|
|
|
|
p = subprocess.Popen( cmd, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
|
|
|
|
|
p.wait()
|
|
|
|
|
|
|
|
|
@ -78,7 +82,7 @@ def confirm_key( content, email ):
|
|
|
|
|
os.mkdir(tmpkeyhome)
|
|
|
|
|
localized_env = os.environ.copy()
|
|
|
|
|
localized_env["LANG"] = "C"
|
|
|
|
|
p = subprocess.Popen( ['/usr/bin/gpg', '--homedir', tmpkeyhome, '--import', '--batch'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=localized_env )
|
|
|
|
|
p = subprocess.Popen( build_command(tmpkeyhome, '--import', '--batch'), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=localized_env )
|
|
|
|
|
result = p.communicate(input=content)[1]
|
|
|
|
|
confirmed = False
|
|
|
|
|
|
|
|
|
@ -97,7 +101,7 @@ def confirm_key( content, email ):
|
|
|
|
|
|
|
|
|
|
# adds a key and ensures it has the given email address
|
|
|
|
|
def add_key( keyhome, content ):
|
|
|
|
|
p = subprocess.Popen( ['/usr/bin/gpg', '--homedir', keyhome, '--import', '--batch'], stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE )
|
|
|
|
|
p = subprocess.Popen( build_command(keyhome, '--import', '--batch'), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
|
|
|
|
|
p.communicate(input=content)
|
|
|
|
|
p.wait()
|
|
|
|
|
|
|
|
|
@ -107,7 +111,7 @@ def delete_key( keyhome, email ):
|
|
|
|
|
|
|
|
|
|
if result[1]:
|
|
|
|
|
# delete all keys matching this email address
|
|
|
|
|
p = subprocess.Popen( ['/usr/bin/gpg', '--homedir', keyhome, '--delete-key', '--batch', '--yes', result[1]], stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
|
|
|
|
|
p = subprocess.Popen( build_command(keyhome, '--delete-key', '--batch', '--yes', result[1]), stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
|
|
|
|
|
p.wait()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
@ -131,7 +135,7 @@ class GPGEncryptor:
|
|
|
|
|
return (encdata, p.returncode)
|
|
|
|
|
|
|
|
|
|
def _command(self):
|
|
|
|
|
cmd = ["/usr/bin/gpg", "--trust-model", "always", "--homedir", self._keyhome, "--batch", "--yes", "--pgp7", "--no-secmem-warning", "-a", "-e"]
|
|
|
|
|
cmd = build_command(self._keyhome, "--trust-model", "always", "--batch", "--yes", "--pgp7", "--no-secmem-warning", "-a", "-e")
|
|
|
|
|
|
|
|
|
|
# add recipients
|
|
|
|
|
for recipient in self._recipients:
|
|
|
|
@ -159,6 +163,4 @@ class GPGDecryptor:
|
|
|
|
|
return (decdata, p.returncode)
|
|
|
|
|
|
|
|
|
|
def _command(self):
|
|
|
|
|
cmd = ["/usr/bin/gpg", "--trust-model", "always", "--homedir", self._keyhome, "--batch", "--yes", "--no-secmem-warning", "-a", "-d"]
|
|
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
|
return build_command(self._keyhome, "--trust-model", "always", "--batch", "--yes", "--no-secmem-warning", "-a", "-d")
|
|
|
|
|