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
17 """Return <data> signed with the default GPG key."""
18 msg = dumps((data,), methodresponse = True)
19 p = _popen_gpg('--armor', '--sign', '--keyring', '/etc/planetlab/secring.gpg', '--no-default-keyring')
22 signed_msg = p.stdout.read()
28 def verify(signed_msg):
29 """If <signed_msg> is a valid signed document, return its contents. Otherwise, return None."""
30 p = _popen_gpg('--decrypt', '--keyring', '/usr/boot/pubring.gpg', '--no-default-keyring')
31 p.stdin.write(signed_msg)
36 if p.wait(): return None # verification failed
41 def _popen_gpg(*args):
42 """Return a Popen object to GPG."""
43 return Popen((GPG, '--batch', '--no-tty') + args, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)