[Pgp-tools-commit] r636 - in trunk/keyart: . doc

Aaron Toponce atoponce-guest at moszumanska.debian.org
Wed Jun 11 14:31:09 UTC 2014


Author: atoponce-guest
Date: 2014-06-11 14:31:09 +0000 (Wed, 11 Jun 2014)
New Revision: 636

Modified:
   trunk/keyart/BUGS
   trunk/keyart/README
   trunk/keyart/doc/keyart.1
   trunk/keyart/doc/party-worksheet
   trunk/keyart/keyart
Log:
Color update and changed functionality

keyart now accepts any valid input that will uniquely identify a key in your
keyring, rather than relying on an exported key file. This identification can
be a name, email address, short keyid, long keyid, fingerprint, etc.

Updated the printed ANSI colors to give less emphasis on the blues.

Finally, changed one of the coins from '{' to '(', as printing a literal curly
brace in Python with .format() is tricky, and not worth the effort.


Modified: trunk/keyart/BUGS
===================================================================
--- trunk/keyart/BUGS	2014-06-03 17:23:11 UTC (rev 635)
+++ trunk/keyart/BUGS	2014-06-11 14:31:09 UTC (rev 636)
@@ -1,5 +1,4 @@
 BUGS
 ----
 
-* Keys with a direct signature on the key will not display the ^fpr line.
-  See https://bugs.g10code.com/gnupg/issue1640.
+None at this time.

Modified: trunk/keyart/README
===================================================================
--- trunk/keyart/README	2014-06-03 17:23:11 UTC (rev 635)
+++ trunk/keyart/README	2014-06-11 14:31:09 UTC (rev 636)
@@ -1,22 +1,18 @@
 OpenPGP Random Art
 ------------------
 
-keyart takes a single exported public key file as an argument, and prints
-out its random visualization ASCII art based on the public key fingerprint.
-Please see 'doc/drunken-bishop.txt' for more information about the algorithm
-and changes compared to OpenSSH keys.
+keyart takes any argument that can uniquely identify a key (name, email
+address, short key ID, long key ID, fingerprint, etc), and prints out its
+random visualization ASCII art based on the public key fingerprint. Please see
+'doc/drunken-bishop.txt' for more information about the algorithm and changes
+compared to OpenSSH keys.
 
 Usage
 -----
 
-The exported public key file can be in binary or ASCII armor format. To
-export the desired key:
+The key must be in your keyring. To produce the random art for a key:
 
-    $ gpg --output /tmp/0x808606060F.pgp --export 0x8086060F
-
-Then to produce the random art for that key:
-
-    $ keyart /tmp/0x8086060F.pgp
+    $ keyart 0x8086060F
     +----[DSA 1024]-----+
     |l^  . ^^?^.        |
     |l. . .l:.?         |

Modified: trunk/keyart/doc/keyart.1
===================================================================
--- trunk/keyart/doc/keyart.1	2014-06-03 17:23:11 UTC (rev 635)
+++ trunk/keyart/doc/keyart.1	2014-06-11 14:31:09 UTC (rev 636)
@@ -8,10 +8,10 @@
 .B keyart [-a|--ansi] FILE
 .SH DESCRIPTION
 .B keyart
-creates an ASCII art representation of a supplied exported public
-OpenPGP key file. The art is an implementation of the Drunken Bishop by Dirk
-Loss. Documentation about the algorithm can be found /usr/share/doc/keyart/,
-or as appropriate for your distribution.
+creates an ASCII art representation of a public OpenPGP key. The art is an
+implementation of the Drunken Bishop by Dirk Loss. Documentation about the
+algorithm can be found /usr/share/doc/keyart/, or as appropriate for your
+distribution.
 
 .B keyart
 supports printing the ASCII art in both plain text (default) and ANSI

Modified: trunk/keyart/doc/party-worksheet
===================================================================
--- trunk/keyart/doc/party-worksheet	2014-06-03 17:23:11 UTC (rev 635)
+++ trunk/keyart/doc/party-worksheet	2014-06-11 14:31:09 UTC (rev 636)
@@ -1,13 +1,13 @@
 BASICS
 ------
-To create a worksheet for a keysigning party, you will need to export each of
-the participants keys to their own file in a directory. If you've been storing
-them in a separate keyring, this should be easy.
+To create a worksheet for a keysigning party, you will need to import each of
+the participants keys to your GPG keyring. If you've been storing them in a
+separate keyring, this should be easy.
 
-Once each key is in its own file, create a single "art.txt" file with all the
+Once each key has been imported, create a single "art.txt" file with all the
 keys. Something like:
 
-    $ for KEY in *.gpg; do keyart $KEY; done > art.txt
+    $ for KEY in 8086060F F34D3BC5 C22D2FCF; do keyart $KEY; done > art.txt
 
 In the examples/ directory of this documentation, is a 'party.sh' script that
 can transform that art.txt file to 5 key art per line. It will print the output
@@ -28,7 +28,7 @@
 could then be used to print the worksheet:
 
     $ sudo easy_install ansi2html
-    $ for KEY in *.gpg; do keyart -a $KEY; done > art.txt
+    $ for KEY in 8086060F F34D3BC5 C22D2FCF; do keyart -a $KEY; done > art.txt
     $ ./party.sh | ansi2html > worksheet.html
 
 You may need to make some HTML adjustments to prevent the printer from breaking

Modified: trunk/keyart/keyart
===================================================================
--- trunk/keyart/keyart	2014-06-03 17:23:11 UTC (rev 635)
+++ trunk/keyart/keyart	2014-06-11 14:31:09 UTC (rev 636)
@@ -9,10 +9,10 @@
 parser = argparse.ArgumentParser(description='Create an ASCII art of a PGP key.')
 parser.add_argument('-a','--ansi', help='Print the art with ANSI color.',
     action='store_true')
-parser.add_argument('file', type=argparse.FileType('r'))
+parser.add_argument('keyid')
 args = parser.parse_args()
 
-def draw_art(keyfile):
+def draw_art(key):
     try:
         if os.access('/usr/bin/gpg',os.X_OK):
             gpg_bin = '/usr/bin/gpg'
@@ -20,9 +20,8 @@
             gpg_bin = '/usr/bin/gpg2'
 
         DEVNULL = open(os.devnull, 'wb')
-        gpg = subprocess.Popen(
-            (gpg_bin,'--with-fingerprint','--with-colons', keyfile),
-            stdout=subprocess.PIPE, stderr=DEVNULL)
+        gpg = subprocess.Popen(('gpg', '--fingerprint', '--with-colons',
+            key),stdout=subprocess.PIPE, stderr=DEVNULL)
         out = gpg.communicate()
         DEVNULL.close()
     except OSError:
@@ -30,43 +29,28 @@
         sys.exit(4)
 
     try:
-        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]
+        key_size = out[0].split('\n')[1].split(':')[2]
+        key_algo = out[0].split('\n')[1].split(':')[3]
+        key_fpr =  out[0].split('\n')[2].split(':')[9]
 
-        ### BEGIN ugly work around for GnuPG bug #1640
-        # See: https://bugs.g10code.com/gnupg/issue1640
-        pattern = re.compile('[A-Z0-9]{40}')
-
-        if not pattern.match(key_fpr):
-            DEVNULL = open(os.devnull, 'wb')
-            gpg = subprocess.Popen((gpg_bin,'--import',keyfile), stderr=DEVNULL)
-            out = gpg.communicate()
-            gpg = subprocess.Popen(
-                (gpg_bin,'--fingerprint','--with-colons',os.path.splitext(keyfile)[0]),
-                stdout=subprocess.PIPE)
-            out = gpg.communicate()
-            DEVNULL.close()
-            key_fpr = [i.strip() for i in out[0].split(':')][28]
-        ### END ugly work around
-
     except IndexError:
-        print "It appears that {0} is not an exported public PGP key.".format(keyfile)
+        print "It appears that {0} is not an exported public PGP key.".format(key)
         sys.exit(5)
 
-    coin = ''
     art = ''
     f_bytes = []
     pos = 104
     walk = [pos]
     visits = [0]*209
+    temp = ''
 
-    zfill = str.zfill
+    key_bin = bin(int(key_fpr, 16))[2:].zfill(len(key_fpr)*4)
+    for i,c in enumerate(key_bin):
+        temp += c
+        if i % 2 == 1:
+            f_bytes.append(temp)
+            temp = ''
 
-    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
-
     for d in f_bytes:
         if (20 <= pos <=  36 or  39 <= pos <=  55 or  58 <= pos <=  74 or
             77 <= pos <=  93 or  96 <= pos <= 112 or 115 <= pos <= 131 or
@@ -165,27 +149,29 @@
 
         # Insert the 'coin' into the art at this position
         if i == 104: # Starting position
-            art = art.format(_get_coin(v, args.ansi, token='S'))
+            art = art.format(_get_coin(v, args.ansi, coin='S'))
         elif i == walk[len(walk)-1]: # Ending position
-            art = art.format(_get_coin(v, args.ansi, token='E'))
+            art = art.format(_get_coin(v, args.ansi, coin='E'))
         else:
             art = art.format(_get_coin(v, args.ansi))
 
     art += '+----[{0}]-----+'.format(key_fpr[-8:])
     return art
 
-def _get_coin(num_of_hits, ansi_art=False, token=None):
+def _get_coin(num_of_hits, ansi_art=False, coin=None):
     '''
     Returns the coin for this humber of hits. If ansi_art is enabled the coin
-    will be colorized with ansi codes. If token is not None, it will use that
-    token instead of the default (used for the 'S' and 'E', start end tokens)
+    will be colorized with ansi codes. If coin is not None, it will use that
+    coin instead of the default (used for the 'S' and 'E', start end coins)
     '''
-    tokens = [' ','.','^',':','l','i','?','{','f','x','X','Z','#','M','W','&','8','%','@']
+    coins = [' ','.','^',':','l','i','?','(','f','x','X','Z','#','M','W','&','8','%','@']
+    colors = ['','','','','','','','','','','','','','','','','','']
+    reset = ''
     if ansi_art:
         colors = [
-            '\033[38;5;21m', # blue
-            '\033[38;5;33m',
-            '\033[38;5;45m',
+            '', # no coin
+            '\033[38;5;21m', # blue (cold)
+            '\033[38;5;39m',
             '\033[38;5;50m',
             '\033[38;5;48m',
             '\033[38;5;46m', # green
@@ -201,18 +187,15 @@
             '\033[38;5;210m',
             '\033[38;5;217m', # pink
             '\033[38;5;224m',
+            '\033[38;5;231m'  # white (hot)
         ]
         reset = '\033[0m'
-    else:
-        colors = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
-                  '', '', '', ]
-        reset = ''
 
     color = colors[num_of_hits]
-    if not token:
-        token = tokens[num_of_hits]
-    return '{}{}{}'.format(color, token, reset)
+    if not coin:
+        coin = coins[num_of_hits]
+    return '{}{}{}'.format(color, coin, reset)
 
 if __name__ == '__main__':
-    key = args.file.name
+    key = args.keyid
     print draw_art(key)




More information about the Pgp-tools-commit mailing list