[Pgp-tools-commit] r644 - in trunk/keyart: . doc
Aaron Toponce
atoponce-guest at moszumanska.debian.org
Wed Jun 18 05:35:06 UTC 2014
Author: atoponce-guest
Date: 2014-06-18 05:35:06 +0000 (Wed, 18 Jun 2014)
New Revision: 644
Modified:
trunk/keyart/doc/keyart.1
trunk/keyart/keyart
Log:
Full public key and keyring support. Change option
Rather than '-k|--keyring' for the option to read a file, '-f|--file' was used.
This allows the exported file to be either an individual exported GPG key or a
public keyring. Similarly with '-i|--id', multiple files or keyrings may be
passed to '-f|--file'. The keyart.1 manpage is updated to reflect this change.
Modified: trunk/keyart/doc/keyart.1
===================================================================
--- trunk/keyart/doc/keyart.1 2014-06-17 13:04:39 UTC (rev 643)
+++ trunk/keyart/doc/keyart.1 2014-06-18 05:35:06 UTC (rev 644)
@@ -1,11 +1,12 @@
.\" Manpage for keyart
.\" Aaron Toponce <aaron.toponce at gmail.com>
-.TH keyart 1 "17 May 2014"
+.TH keyart 1 "17 Jun 2014"
.SH NAME
.B keyart
\- Create ASCII art of an OpenPGP key.
.SH SYNOPSIS
-.B keyart [-a|--ansi] (-i|--id KEYID [KEYID ...] | -k|--keyring KEYRING [KEYRING ...])
+.B keyart
+[-a|--ansi] (-i|--id KEYID [KEYID ...] | -f|--file FILE [FILE ...])
.SH DESCRIPTION
.B keyart
creates an ASCII art representation of a public OpenPGP key. The art is an
@@ -21,18 +22,18 @@
color to printed character.
.SH OPTIONS
.TP 8
-.B \-a \fR|\fI \-\-ansi
+.B -a | --ansi
Print the ASCII art using ANSI color to the terminal.
.TP 8
-.B \-i \fR|\fI \-\-id KEYID [KEYID ...]
-A key identifier. Can be an email, fingerprint, keyid, name, etc. Either \-i or
-\-k are required.
+.B -i | --id KEYID [KEYID ...]
+A key identifier. Can be an email, fingerprint, keyid, name, etc. Either -i or
+-k are required.
.TP 8
-.B \-k \fR|\fI \-\-keyring KEYRING [KEYRING ...]
-A pubic GPG keyring file. Code currently not implemented. Either \-i or \-k are
-required.
+.B -f | --file FILE [FILE ...]
+A pubicly exported GPG key file. Can be an individual key or a public keyring.
+Either -i or -k are required.
.TP 8
-.B \-h \fR|\fI \-\-help
+.B -h | --help
Print the help message and quit.
.SH SEE ALSO
.BR gpg (1)
Modified: trunk/keyart/keyart
===================================================================
--- trunk/keyart/keyart 2014-06-17 13:04:39 UTC (rev 643)
+++ trunk/keyart/keyart 2014-06-18 05:35:06 UTC (rev 644)
@@ -12,12 +12,37 @@
GROUP = PARSER.add_mutually_exclusive_group(required=True)
PARSER.add_argument('-a', '--ansi', help='Print the art with ANSI color.',
action='store_true')
-GROUP.add_argument('-i', '--id', type=str, nargs='+', metavar=('KEID'),
- help='A key identifier.')
-GROUP.add_argument('-k', '--keyring', type=str, nargs='+', metavar=('KEYRING'),
- help='A GPG keyring.')
+GROUP.add_argument('-i', '--id', type=str, nargs='+', metavar=('KEYID'),
+ help='A key identifier (email, ID, fingerprint, etc.).')
+GROUP.add_argument('-f', '--file', type=str, nargs='+', metavar=('FILE'),
+ help='A publicly exported GPG key or keyring.')
ARGS = PARSER.parse_args()
+def fix_gpg(gpg_bin, keyid, keyfile):
+ """Temporary work around for GnuPG bug #1640.
+ See https://bugs.g10code.com/gnupg/issue1640."""
+ with open(os.devnull, 'wb') as devnull:
+ cmd = (gpg_bin, '--quiet', '--yes', '--output', '/tmp/.0x%s.gpg' % keyid,
+ '--no-default-keyring', '--keyring=%s' % keyfile, '--export',
+ keyid)
+ gpg = subprocess.Popen(cmd, stdout=devnull)
+ gpg.communicate()
+
+ cmd = (gpg_bin, '--quiet', '--import', '/tmp/.0x%s.gpg' % keyid)
+ gpg = subprocess.Popen(cmd, stdout=devnull)
+ gpg.communicate()
+
+ os.remove('/tmp/.0x%s.gpg' % keyid)
+
+ cmd = (gpg_bin, '--fingerprint', '--with-colons', keyid)
+ gpg = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+ cmd = ('grep', '^fpr')
+ grep = subprocess.Popen(cmd, stdin=gpg.stdout, stdout=subprocess.PIPE)
+ out = grep.communicate()[0]
+ fpr = out.split(':')[9]
+
+ return fpr
+
def test_env():
"""Test if and where GPG is installed."""
try:
@@ -232,27 +257,37 @@
return '{}{}{}'.format(color, coin, reset)
if __name__ == '__main__':
- GPG_BIN = test_env()
- DEVNULL = open(os.devnull, 'wb')
+ gpg_bin = test_env()
if ARGS.id:
for key in ARGS.id:
- gpg = subprocess.Popen((GPG_BIN, '--fingerprint', '--with-colons',
- key), stdout=subprocess.PIPE, stderr=DEVNULL
- )
- out = gpg.communicate()
+ cmd = (gpg_bin, '--fingerprint', '--with-colons', key)
+ gpg = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+ out = gpg.communicate()[0].split('\n')
- size = out[0].split('\n')[1].split(':')[2]
- algo = out[0].split('\n')[1].split(':')[3]
- fpr = out[0].split('\n')[2].split(':')[9]
+ size = out[1].split(':')[2]
+ algo = out[1].split(':')[3]
+ fpr = out[2].split(':')[9]
print draw_art(size, algo, fpr)
- if ARGS.keyring:
- print "This code isn't ready."
- #for keyring in ARGS.keyring:
- # gpg = subprocess.Popen((GPG_BIN, '--with-fingerprint',
- # '--with-colons', key),stdout=subprocess.PIPE, stderr=DEVNULL)
- # out = gpg.communicate()
+ if ARGS.file:
+ for key in ARGS.file:
+ cmd = (gpg_bin, '--with-fingerprint', '--with-colons', key)
+ gpg = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+ cmd = ('grep', '-E', '^(pub|fpr)')
+ grep = subprocess.Popen(cmd, stdin=gpg.stdout,
+ stdout=subprocess.PIPE)
+ out = grep.communicate()[0].split('\n')
- DEVNULL.close()
+ for i in xrange(len(out)):
+ if out[i].split(':')[0] == 'pub':
+ size = out[i].split(':')[2]
+ algo = out[i].split(':')[3]
+ if out[i+1].split(':')[0] == 'fpr':
+ fpr = out[i+1].split(':')[9]
+ else:
+ keyid = out[i].split(':')[4]
+ fpr = fix_gpg(gpg_bin, keyid, os.path.abspath(key))
+
+ print draw_art(size, algo, fpr)
More information about the Pgp-tools-commit
mailing list