[Pgp-tools-commit] r611 - trunk/keyart

Aaron Toponce atoponce-guest at moszumanska.debian.org
Tue May 13 21:40:06 UTC 2014


Author: atoponce-guest
Date: 2014-05-13 21:40:06 +0000 (Tue, 13 May 2014)
New Revision: 611

Modified:
   trunk/keyart/TODO
   trunk/keyart/keyart
Log:
Remove the python-gnupg requirement


Modified: trunk/keyart/TODO
===================================================================
--- trunk/keyart/TODO	2014-05-13 19:36:20 UTC (rev 610)
+++ trunk/keyart/TODO	2014-05-13 21:40:06 UTC (rev 611)
@@ -1,7 +1,6 @@
 TODO
 ----
 
-* Replace the python-gnupg module with subprocess.
 * Add support for providing multiple exported keys.
 * Add support for providing a 40-character OpenPGP fingerprint string.
 * Add support for keyrings.

Modified: trunk/keyart/keyart
===================================================================
--- trunk/keyart/keyart	2014-05-13 19:36:20 UTC (rev 610)
+++ trunk/keyart/keyart	2014-05-13 21:40:06 UTC (rev 611)
@@ -1,11 +1,8 @@
 #!/usr/bin/env python
 
-# Currently the GnuPG python module is used. The search_keys() requires an
-# online connection. This is less than optimal, and slow. Eventually, it
-# will be replaced with subprocess, and fully offline.
-import gnupg
 import os
 import os.path
+import subprocess
 import sys
 
 try:
@@ -14,24 +11,21 @@
     print "Usage: keyart /path/to/exported-key"
     sys.exit(1)
 
-if os.path.isfile(keyfile) and os.access(keyfile, os.R_OK):
-    with open(keyfile) as f:
-        key_data = f.read()
 elif not os.path.isfile(keyfile):
     print "No such file or directory: {0}".format(keyfile)
     sys.exit(2)
-else:
+elif not os.access(keyfile, os.R_OK):
     print "{0} is not readable. Check permissions.".format(keyfile)
     sys.exit(3)
 
-gpg = gnupg.GPG(gnupghome='/tmp', keyring='/tmp/keyring.pgp')
-key = gpg.import_keys(key_data)
-fingerprint = key.fingerprints[0]
+gpg = subprocess.Popen(
+    ('gpg','--with-fingerprint','--with-colons', keyfile),
+    stdout=subprocess.PIPE)
+out = gpg.communicate()
 
-# search_keys(query, keyserver='pgp.mit.edu')
-key_dict = gpg.search_keys(fingerprint[-16:])[0]
-key_size = key_dict['length']
-key_algo = key_dict['algo']
+key_size = [i.strip() for i in out[0].split(':')][2]
+key_algo = [i.strip() for i in out[0].split(':')][3]
+key_fpr = [i.strip() for i in out[0].split(':')][19]
 
 coin = ''
 f_bytes = []
@@ -42,7 +36,7 @@
 
 zfill = str.zfill
 
-for c in fingerprint:
+for c in key_fpr:
     f_bytes.append(zfill(bin(int(c,16))[2:],4)[:2]) # last 2 bits
     f_bytes.append(zfill(bin(int(c,16))[2:],4)[2:]) # first 2 bits
 
@@ -148,4 +142,4 @@
     if i % 19 == 18:
         print "%s|" % coin
         coin = ''
-print '+----[{0}]-----+'.format(fingerprint[-8:])
+print '+----[{0}]-----+'.format(key_fpr[-8:])




More information about the Pgp-tools-commit mailing list