From c4d78c10c1d8134de2e5625832ebddcf63fbb2db Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Wed, 10 Jan 2007 20:18:52 +0000 Subject: [PATCH] - add gpg_export() to export keys from a public keyring to ASCII --- PLC/GPG.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/PLC/GPG.py b/PLC/GPG.py index 4182f60..1652b94 100644 --- a/PLC/GPG.py +++ b/PLC/GPG.py @@ -7,7 +7,7 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: GPG.py,v 1.2 2007/01/05 18:50:40 mlhuang Exp $ +# $Id: GPG.py,v 1.3 2007/01/08 18:11:54 mlhuang Exp $ # import xmlrpclib @@ -38,6 +38,33 @@ def canonicalize(methodname, args): return xml +def gpg_export(keyring, armor = True): + """ + Exports the specified public keyring file. + """ + + homedir = mkdtemp() + args = ["gpg", "--batch", "--no-tty", + "--homedir", homedir, + "--no-default-keyring", + "--keyring", keyring, + "--export"] + if armor: + args.append("--armor") + + p = Popen(args, stdin = PIPE, stdout = PIPE, stderr = PIPE) + export = p.stdout.read() + err = p.stderr.read() + rc = p.wait() + + # Clean up + shutil.rmtree(homedir) + + if rc: + raise PLCAuthenticationFailure, "GPG export failed with return code %d: %s" % (rc, err) + + return export + def gpg_sign(methodname, args, secret_keyring, keyring): """ Signs the specified method call using the specified keyring files. -- 2.43.0