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