]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blob - modules/sign.py
- allow filtering source and debugfiles in rpmfiles() method
[projects/pld-ftp-admin.git] / modules / sign.py
1 #!/usr/bin/env python
2 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
3
4 import os
5 import sys
6 import rpm
7 import subprocess
8 import pexpect
9 from config import sign_key
10
11 def getSigInfo(hdr):
12     """checks signature from an hdr hand back signature information and/or
13        an error code"""
14     # yum-3.2.22/rpmUtils/miscutils.py
15
16     string = '%|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|'
17     siginfo = hdr.sprintf(string)
18     if siginfo == '(none)':
19         return None
20    
21     return siginfo.split(',')[2].lstrip()
22
23 def is_signed(rpm_file):
24     """Returns rpm information is package signed by the same key"""
25     # http://code.activestate.com/recipes/306705/
26
27     if sign_key == None:
28         return None
29
30     ts = rpm.ts()
31     ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
32     fdno = os.open(rpm_file, os.O_RDONLY)
33     hdr = ts.hdrFromFdno(fdno)
34     os.close(fdno)
35
36     sigid = getSigInfo(hdr)
37     if sigid == None:
38         return None
39
40     return sign_key == sigid[-len(sign_key):]
41
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'
47
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)
55     child.close()
56     rc = child.exitstatus
57     if rc != 0:
58         raise OSError, 'package signing failed'
This page took 0.030556 seconds and 3 git commands to generate.