1 """An extremely simple interface to the signing/verifying capabilities
4 You must already have the key in the keyring.
7 from subprocess import PIPE, Popen
8 from xmlrpclib import dumps, loads
12 def _popen_gpg(*args):
13 """Return a Popen object to GPG."""
14 return Popen((GPG, '--batch', '--no-tty') + args,
15 stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
18 """Return <data> signed with the default GPG key."""
19 msg = dumps((data,), methodresponse = True)
20 p = _popen_gpg('--armor', '--sign', '--keyring', '/etc/planetlab/secring.gpg', '--no-default-keyring')
23 signed_msg = p.stdout.read()
29 def verify(signed_msg):
30 """If <signed_msg> is a valid signed document, return its contents. Otherwise, return None."""
31 p = _popen_gpg('--decrypt', '--keyring', '/usr/boot/pubring.gpg', '--no-default-keyring')
32 p.stdin.write(signed_msg)
38 return None # verification failed