/usr/share/debomatic/Debomatic/gpg.py is in debomatic 0.22-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | # Deb-o-Matic
#
# Copyright (C) 2007-2016 Luca Falavigna
#
# Author: Luca Falavigna <dktrkranz@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
import os
from fcntl import flock, LOCK_EX, LOCK_NB, LOCK_UN
from re import findall, DOTALL
from subprocess import Popen, PIPE
from Debomatic import dom
from .exceptions import DebomaticError
class GPG:
def __init__(self, file):
self._file = file
self._error = None
if dom.opts.has_option('gpg', 'gpg'):
self._gpg = dom.opts.getboolean('gpg', 'gpg')
else:
self._gpg = False
self._sig = None
def __enter__(self):
self._fd = open(self._file, 'r')
flock(self._fd, LOCK_EX | LOCK_NB)
return self
def __exit__(self, exc_type, exc_value, traceback):
flock(self._fd, LOCK_UN)
self._fd.close()
def _check_signature(self):
if dom.opts.has_option('gpg', 'keyring'):
self._keyring = dom.opts.get('gpg', 'keyring')
if not os.path.isfile(self._keyring):
self._keyring = None
self._error = _('Keyring not found')
raise DebomaticError
gpgresult = Popen(['gpgv', '--keyring', self._keyring, self._file],
stderr=PIPE).communicate()[1]
signature = findall(b'Good signature from "(.*) <(.*)>.*"', gpgresult)
if signature:
self._sig = signature[0]
else:
self._error = _('No valid signatures found')
raise DebomaticError
def _strip_signature(self):
with open(self._file, 'r') as fd:
data = fd.read()
with open(self._file, 'w') as fd:
try:
fd.write(findall('\n\n(.*?)\n\n?-', data, DOTALL)[0])
except IndexError:
pass
def check(self):
if self._gpg:
self._check_signature()
if self._sig:
self._strip_signature()
return self._sig
def error(self):
return self._error
|