]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blame - modules/sign.py
- _RPMVSF_NOSIGNATURES and _RPMVSF_NODIGESTS have been removed in rpm 5
[projects/pld-ftp-admin.git] / modules / sign.py
CommitLineData
7b5c7734
ER
1#!/usr/bin/env python
2# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
3
4import os
89b8ea8d 5import sys
7b5c7734 6import rpm
89b8ea8d 7import pexpect
7b5c7734
ER
8from config import sign_key
9
10def getSigInfo(hdr):
11 """checks signature from an hdr hand back signature information and/or
12 an error code"""
13 # yum-3.2.22/rpmUtils/miscutils.py
14
15 string = '%|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|'
16 siginfo = hdr.sprintf(string)
17 if siginfo == '(none)':
18 return None
5a666fec 19
7b5c7734
ER
20 return siginfo.split(',')[2].lstrip()
21
22def is_signed(rpm_file):
23 """Returns rpm information is package signed by the same key"""
24 # http://code.activestate.com/recipes/306705/
25
26 if sign_key == None:
27 return None
28
29 ts = rpm.ts()
7b5c7734
ER
30 fdno = os.open(rpm_file, os.O_RDONLY)
31 hdr = ts.hdrFromFdno(fdno)
32 os.close(fdno)
33
34 sigid = getSigInfo(hdr)
35 if sigid == None:
36 return None
37
38 return sign_key == sigid[-len(sign_key):]
39
89b8ea8d 40def signpkgs(files, password):
7b5c7734
ER
41 if not os.path.isfile('/usr/bin/gpg'):
42 raise OSError, 'Missing gnupg binary'
43 if not os.path.isfile('/bin/rpm'):
44 raise OSError, 'Missing rpm binary'
45
89b8ea8d
AM
46 os.putenv('LC_ALL', 'C')
47 args = ['--resign', '--define', '_signature gpg', '--define', '_gpg_name ' + sign_key] + files
48 child = pexpect.spawn('/bin/rpm', args)
866a153b 49 child.logfile_read = sys.stderr
89b8ea8d
AM
50 child.expect('Enter pass phrase:', timeout=30)
51 child.sendline(password)
866a153b 52 child.expect(pexpect.EOF, timeout=None)
89b8ea8d
AM
53 child.close()
54 rc = child.exitstatus
7b5c7734
ER
55 if rc != 0:
56 raise OSError, 'package signing failed'
This page took 0.05187 seconds and 4 git commands to generate.