def validate_signature(self, keyrings): ''' Validate the GPG signature of a .changes file. ''' cmd = ['gpg', '--batch', '--status-fd', '1', '--no-default-keyring'] for k in keyrings: cmd.extend(['--keyring', k]) cmd.extend(['--verify', self.get_dud_file()]) (gpg_output, gpg_output_stderr, exit_status) = run_command(cmd) if exit_status == -1: raise DudFileException('Unknown problem while verifying signature') if gpg_output.count('[GNUPG:] GOODSIG'): pass elif gpg_output.count('[GNUPG:] BADSIG'): raise DudFileException('Bad signature') elif gpg_output.count('[GNUPG:] ERRSIG'): raise DudFileException('Error verifying signature') elif gpg_output.count('[GNUPG:] NODATA'): raise DudFileException('No signature') else: raise DudFileException('Unknown problem while verifying signature') key = None for line in gpg_output.split('\n'): if line.startswith('[GNUPG:] VALIDSIG'): key = line.split()[2] return key
def _run_dak(self, args): from laniakea.utils import run_command cmd = [self._dak_exe] cmd.extend(args) out, err, ret = run_command(cmd, capture_output=not get_verbose()) if ret != 0: raise Exception('Failed to run dak: {}\n{}'.format( out if out else '', err if err else '')) return out
def _run_germinate(self, wdir, args): from laniakea.utils import run_command, cd ge_args = [self._germinate_exe] ge_args.extend(args) with cd(wdir): out, err, ret = run_command(ge_args, capture_output=not get_verbose()) if ret != 0: return False, '{}\n{}'.format(out, err) return True, out
def _run_dak(self, args, input_data=None, check=True): from laniakea.utils import run_command cmd = [self._dak_exe] cmd.extend(args) out, err, ret = run_command(cmd, input=input_data, capture_output=not get_verbose()) out = out if out else '' err = err if err else '' if check and ret != 0: raise Exception('Failed to run dak: {}\n{}'.format(out, err)) return ret, out + err
def _run_git(self, command, args, clone_dir=None, throw_error=True): git_cmd = [self._git_exe] if command == 'clone': git_cmd.append(command) elif clone_dir: git_cmd.extend(['-C', clone_dir, command]) if args: git_cmd.extend(args) out, err, ret = run_command(git_cmd) if ret == 0: return True elif throw_error: raise Exception('Failed to run Git ({}): {}\n{}'.format( ' '.join(git_cmd), out, err))
def _run_git(self, command, args, clone_dir=None, throw_error=True): git_cmd = [self._git_exe] if command == 'clone': git_cmd.append(command) elif clone_dir: git_cmd.extend(['-C', clone_dir, command]) if args: git_cmd.extend(args) out, err, ret = run_command(git_cmd) if ret == 0: return True elif throw_error: raise Exception('Failed to run Git ({}): {}\n{}', ' '.join(git_cmd), out, err) return False
def validate_signature(self, keyrings): ''' Validate the GPG signature of a .changes file. ''' cmd = ['gpg', '--batch', '--status-fd', '1', '--no-default-keyring'] for k in keyrings: cmd.extend(['--keyring', k]) cmd.extend(['--verify', self.get_dud_file()]) (gpg_output, gpg_output_stderr, exit_status) = run_command(cmd) if exit_status == -1: raise DudFileException( 'Unknown problem while verifying signature') if gpg_output.count('[GNUPG:] GOODSIG'): pass elif gpg_output.count('[GNUPG:] BADSIG'): raise DudFileException('Bad signature') elif gpg_output.count('[GNUPG:] ERRSIG'): raise DudFileException('Error verifying signature') elif gpg_output.count('[GNUPG:] NODATA'): raise DudFileException('No signature') else: raise DudFileException( 'Unknown problem while verifying signature' ) key = None for line in gpg_output.split('\n'): if line.startswith('[GNUPG:] VALIDSIG'): key = line.split()[2] return key