# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id$
+# $Id: GPG.py,v 1.3 2007/01/08 18:11:54 mlhuang Exp $
#
import xmlrpclib
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.
message = canonicalize(methodname, args)
+ homedir = mkdtemp()
p = Popen(["gpg", "--batch", "--no-tty",
+ "--homedir", homedir,
"--no-default-keyring",
"--secret-keyring", secret_keyring,
"--keyring", keyring,
p.stdin.write(message)
p.stdin.close()
signature = p.stdout.read()
+ err = p.stderr.read()
rc = p.wait()
+
+ # Clean up
+ shutil.rmtree(homedir)
+
if rc:
- raise PLCAuthenticationFailure, "GPG signing failed with return code %d" % rc
+ raise PLCAuthenticationFailure, "GPG signing failed with return code %d: %s" % (rc, err)
return signature