2 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
9 from config import sign_key
12 """checks signature from an hdr hand back signature information and/or
14 # yum-3.2.22/rpmUtils/miscutils.py
16 string = '%|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|'
17 siginfo = hdr.sprintf(string)
18 if siginfo == '(none)':
21 return siginfo.split(',')[2].lstrip()
23 def is_signed(rpm_file):
24 """Returns rpm information is package signed by the same key"""
25 # http://code.activestate.com/recipes/306705/
31 ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
32 fdno = os.open(rpm_file, os.O_RDONLY)
33 hdr = ts.hdrFromFdno(fdno)
36 sigid = getSigInfo(hdr)
40 return sign_key == sigid[-len(sign_key):]
42 def signpkgs(files, password):
43 if not os.path.isfile('/usr/bin/gpg'):
44 raise OSError, 'Missing gnupg binary'
45 if not os.path.isfile('/bin/rpm'):
46 raise OSError, 'Missing rpm binary'
48 os.putenv('LC_ALL', 'C')
49 args = ['--resign', '--define', '_signature gpg', '--define', '_gpg_name ' + sign_key] + files
50 child = pexpect.spawn('/bin/rpm', args)
51 child.logfile_read = sys.stderr
52 child.expect('Enter pass phrase:', timeout=30)
53 child.sendline(password)
54 child.expect(pexpect.EOF, timeout=None)
58 raise OSError, 'package signing failed'