| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
# SPDX-FileCopyrightText: 2001,2002 Progeny Linux Systems, Inc. |
| 4 |
# Authors: John Goerzen, Branden Robinson |
| 5 |
# SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
|
| 7 |
use strict; |
| 8 |
|
| 9 |
use File::Copy; |
| 10 |
use Getopt::Long; |
| 11 |
|
| 12 |
use Debian::debsigs::debsigsmain; |
| 13 |
|
| 14 |
sub processfile($); |
| 15 |
sub cleanup($; $); |
| 16 |
sub copyfiles(); |
| 17 |
sub syntax($); |
| 18 |
sub version(); |
| 19 |
|
| 20 |
my ($showhelp, $showversion); |
| 21 |
Getopt::Long::Configure('no_ignore_case'); |
| 22 |
GetOptions ('help|h' => \$showhelp, |
| 23 |
'version|V' => \$showversion); |
| 24 |
|
| 25 |
version() if $showversion; |
| 26 |
syntax(0) if $showhelp; |
| 27 |
exit(0) if $showhelp || $showversion; |
| 28 |
|
| 29 |
syntax(1) unless @ARGV; |
| 30 |
|
| 31 |
# What we need to add: |
| 32 |
|
| 33 |
my $KEY = 'E435EC07'; |
| 34 |
my $KEYTYPE = 'origin'; |
| 35 |
my $KEYRING = '/usr/local/debsigs/origin-secring.gpg'; |
| 36 |
my $TMPDIR = "/tmp/debsigs-installer.$$"; |
| 37 |
my $COUNTER = 0; |
| 38 |
|
| 39 |
my $file; |
| 40 |
|
| 41 |
my %copyfiles; |
| 42 |
|
| 43 |
mkdir($TMPDIR, 0700) or die |
| 44 |
"Couldn't mkdir $TMPDIR: $!"; |
| 45 |
|
| 46 |
foreach $file (@ARGV) { |
| 47 |
$COUNTER++; |
| 48 |
processfile($file); |
| 49 |
} |
| 50 |
|
| 51 |
copyfiles(); |
| 52 |
cleanup($TMPDIR); |
| 53 |
exit(0); |
| 54 |
|
| 55 |
sub processfile($) { |
| 56 |
my ($file) = shift @_; |
| 57 |
|
| 58 |
my $TMPFILE = "$TMPDIR/file-$COUNTER.deb"; |
| 59 |
|
| 60 |
# Copy the file to $TMPDIR. |
| 61 |
|
| 62 |
copy($file, $TMPFILE) or die |
| 63 |
"Couldn't copy file to $TMPFILE: $!"; |
| 64 |
|
| 65 |
# Add the signature to it. |
| 66 |
|
| 67 |
(system("debsigs", "-K", $KEYRING, |
| 68 |
"--default-key=$KEY", "--sign=$KEYTYPE", $TMPFILE) == 0) or die |
| 69 |
"Error signing!"; |
| 70 |
|
| 71 |
# Now verify the result. |
| 72 |
|
| 73 |
if (system("debsig-verify", "-q", $TMPFILE) != 0) { |
| 74 |
print STDERR "Error validating $file!\n"; |
| 75 |
cleanup($TMPDIR, $TMPFILE); |
| 76 |
exit(2); |
| 77 |
} |
| 78 |
|
| 79 |
# We're OK here, so flag the file for copying. |
| 80 |
|
| 81 |
$copyfiles{$TMPFILE} = $file; |
| 82 |
} |
| 83 |
|
| 84 |
sub cleanup($; $) { |
| 85 |
my ($dir, $file) = @_; |
| 86 |
|
| 87 |
# Let them pass in a file to unlink too, in case it's being |
| 88 |
# called before being added to %copyfiles. |
| 89 |
|
| 90 |
|
| 91 |
if (defined($file)) { |
| 92 |
# print STDERR "Deleting $file\n"; |
| 93 |
unlink($file); |
| 94 |
} |
| 95 |
|
| 96 |
foreach $file (keys %copyfiles) { |
| 97 |
# print STDERR "Deleting $file\n"; |
| 98 |
unlink($file); |
| 99 |
} |
| 100 |
|
| 101 |
# print STDERR "Removing $dir\n"; |
| 102 |
rmdir($dir); |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
sub copyfiles() { |
| 107 |
my ($source, $dest); |
| 108 |
|
| 109 |
foreach $source (keys %copyfiles) { |
| 110 |
copy($source, $copyfiles{$source}) or die |
| 111 |
"Couldn't copy $source to " . $copyfiles{$source} . ": $!"; |
| 112 |
# print STDERR "Copied $source to " . $copyfiles{$source} . "\n"; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
sub syntax($) { |
| 117 |
my ($err) = @_; |
| 118 |
my $s = "Usage: debsigs-installer file...\n"; |
| 119 |
|
| 120 |
if ($err) { |
| 121 |
print STDERR "$s"; |
| 122 |
exit(1); |
| 123 |
} else { |
| 124 |
print "$s"; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
sub version() { |
| 129 |
print "debsigs-installer $Debian::debsigs::debsigsmain::VERSION\n"; |
| 130 |
} |
| 131 |
|
| 132 |
__END__ |
| 133 |
|
| 134 |
=head1 NAME |
| 135 |
|
| 136 |
debsigs-installer - process signatures in .deb packages |
| 137 |
|
| 138 |
=head1 SYNOPSIS |
| 139 |
|
| 140 |
B<debsigs-installer> file [file...] |
| 141 |
|
| 142 |
=head1 DESCRIPTION |
| 143 |
|
| 144 |
B<debsigs-installer> is designed to be called in an automated fashion from |
| 145 |
an installer. It is given one or more files on the command line. For each |
| 146 |
file, it will apply the origin signature and make sure that the resulting |
| 147 |
package verifies (it will fail to verify if it is missing one of the other |
| 148 |
required signatures). It will try its best to do either an all or nothing |
| 149 |
approach; that is, if there is a problem with any .deb, all of them will be |
| 150 |
unmodified and error code is returned. It can assure this for all except |
| 151 |
system call failures (can't copy files, etc.) If success is returned, all |
| 152 |
files should be assumed to have succeeded. If failure is returned, all |
| 153 |
files should be assumed to have failed. |
| 154 |
|
| 155 |
=head1 OPTIONS |
| 156 |
|
| 157 |
None. |
| 158 |
|
| 159 |
=head1 BUGS |
| 160 |
|
| 161 |
This program isn't finished yet. It uses hard-coded values for the key ID, |
| 162 |
key type (see debsigs(1)), keyring file, and temporary directory. |
| 163 |
|
| 164 |
=head1 AUTHOR |
| 165 |
|
| 166 |
John Goerzen <[email protected]> |
| 167 |
|
| 168 |
=head1 SEE ALSO |
| 169 |
|
| 170 |
debsig-verify(1), gpg(1) |
| 171 |
|
| 172 |
=cut |