/usr/bin/debsigs-signchanges is in debsigs 0.1.19.
This file is owned by root:root, with mode 0o755.
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | #!/usr/bin/perl -w
# Copyright (C) 2001,2002 Progeny Linux Systems, Inc.
# Authors: John Goerzen, Branden Robinson
# Copyright (C) 2009 Peter Pentchev <roam@ringlet.net>
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
use strict;
use File::Basename;
use Getopt::Long;
use IO::File;
use Debian::debsigs::debsigsmain;
use Debian::debsigs::forktools qw/forkreader/;
sub syntax($);
sub version();
my ($showhelp, $showversion);
Getopt::Long::Configure('no_ignore_case');
GetOptions ('help|h' => \$showhelp,
'version|V' => \$showversion);
version() if $showversion;
syntax(0) if $showhelp;
exit(0) if $showhelp || $showversion;
syntax(1) unless (@ARGV && $ARGV[0] =~ /\.changes$/);
my $changesfile = $ARGV[0];
my $changespath = (fileparse($changesfile))[1];
my $newchangesfile = "$changesfile.debsigs-signchanges.$$";
my $ADDSIG = $ENV{DEBSIGSSIG} ? $ENV{DEBSIGSSIG} : 'maint';
my $DEBSIGSOPTIONS = $ENV{DEBSIGSOPTIONS} ? $ENV{DEBSIGSOPTIONS} : '';
open(CHANGES, "<$changesfile") or die "Couldn't open $changesfile: $!";
open(NEWCHANGES, ">$newchangesfile") or
die "Couldn't open $newchangesfile: $!";
# Look for the Files section.
my ($line, $cline, $sigtype, $defkeyname);
my @changes;
my %debs;
while (defined($line = <CHANGES>)) {
$cline = $line;
chomp $cline;
if ($sigtype && $line =~ /^\S/) {
undef $sigtype;
}
if (!defined($sigtype)) {
push @changes, $line;
# A default key?
if ($cline =~ /^Changed-By:\s+(.*)$/) {
$defkeyname = $1;
} elsif ($cline =~ /^Maintainer:\s+(.*)$/ && !defined($defkeyname)) {
$defkeyname = $1;
}
# A new section?
if ($cline =~ /Files:/) {
$sigtype = 'md5';
} elsif ($cline =~ /^Checksums-(\w+):/) {
$sigtype = $1;
}
} else {
if ($cline !~ /\s(\S+\.deb)$/) {
push @changes, $line;
next;
}
$debs{$1}{$sigtype} = $line;
push @changes, {'t' => 'sig', 'sigtype' => $sigtype, 'file' => $1};
}
}
close CHANGES;
# Do we need to determine the default key?
if ($defkeyname && $DEBSIGSOPTIONS !~ /(^|\s)--?(k|default-key)/) {
my ($defkey);
eval {
my ($fd, $pid) = forkreader(undef,
'gpg', '--list-secret-keys', '--with-colons', $defkeyname);
die("Couldn't exec gpg: $!\n") unless defined($fd);
my $keyline;
while ($keyline = <$fd>) {
if ($keyline =~ /^sec:[^:]*:[^:]*:[^:]*:([^:]+):/) {
die("More than one secret key present - $defkey, $1\n") if $defkey;
$defkey = $1;
}
}
close($fd) or die("Couldn't close the gpg reader: $!\n");
die("No secret key found\n") unless $defkey;
};
die("Couldn't determine the secret key for '$defkeyname': $@") if $@;
$DEBSIGSOPTIONS .= " --default-key='$defkey'";
}
# Sign each .deb file and recalculate the checksums
my $file;
foreach $file (keys %debs) {
my ($fname);
print "Changespath is '$changespath'\n";
$fname = "$changespath/$file";
print "Signing $file...\n";
system("debsigs $DEBSIGSOPTIONS --sign=$ADDSIG $fname") &&
die "Couldn't sign $fname\n";
foreach $sigtype (keys %{$debs{$file}}) {
my ($progname, $csum, $size, $section, $priority, $nfile);
my @el;
$cline = $debs{$file}{$sigtype};
chomp $cline;
if ($sigtype eq 'md5') {
($csum, $size, $section, $priority, $nfile) = split(' ', $cline);
} else {
($csum, $size, $nfile) = split(' ', $cline);
}
# Recalculate the checksum; $sigtype has already been validated
$progname = lc($sigtype).'sum';
$csum = `$progname $fname`;
if (!defined($csum)) {
die("$sigtype checksum for $file: $progname: $!\n");
}
chomp $csum;
@el = split /\s+/, $csum;
if ($#el != 1 || $el[1] ne $fname || $el[0] !~ /^([0-9a-f]+)$/) {
die("$sigtype checksum for $file: bad $progname output: $csum\n");
}
$csum = $el[0];
# Store it with all the other fields
$size = (stat($fname))[7];
if ($sigtype eq 'md5') {
$line = " $csum $size $section $priority $file\n";
} else {
$line = " $csum $size $file\n";
}
$debs{$file}{$sigtype} = $line;
}
}
# Output the changes file
foreach (@changes) {
if (ref($_) eq '') {
print NEWCHANGES;
next;
} elsif (ref($_) ne 'HASH') {
die("INTERNAL ERROR: invalid \@changes ref '".ref($_)."'\n");
} elsif (!defined($_->{'t'})) {
die("INTERNAL ERROR: \@changes ref without a type\n");
} elsif ($_->{'t'} eq 'sig') {
if (!defined($_->{'file'})) {
die("INTERNAL ERROR: \@changes sig without a sigtype\n");
} elsif (!defined($_->{'file'})) {
die("INTERNAL ERROR: \@changes sig $_->{sigtype} for no file\n");
}
$line = $debs{$_->{'file'}}{$_->{'sigtype'}};
if (!defined($line)) {
die("INTERNAL ERROR: \@changes sig $_->{sigtype} nofile $_->{file}\n");
}
print NEWCHANGES $line;
} else {
die("INTERNAL ERROR: \@changes ref of unknown type '$_->{t}'\n");
}
}
close NEWCHANGES;
rename($newchangesfile, $changesfile) or
die "Couldn't rename $newchangesfile to $changesfile: $!";
sub syntax($) {
my ($err) = @_;
my $s = "Usage: debsigs-signchanges file\n";
if ($err) {
print STDERR "$s";
exit(1);
} else {
print "$s";
}
}
sub version() {
print "debsigs-signchanges $Debian::debsigs::debsigsmain::VERSION\n";
}
__END__
=head1 NAME
debsigs-signchanges - cryptographically sign Debian packages based on
package changes file
=head1 SYNOPSIS
B<debsigs-signchanges> I<file>
=head1 DESCRIPTION
I<debsigs-signchanges> reads the Debian package changes file specified
as an operand and runs I<debsigs>(1) on each package listed within. It
then updates the changes file to reflect the new cryptographic hash and
size of the signed Debian packages.
=head1 OPERANDS
I<debsigs-signchanges> takes one operand: the name of a Debian package
changes file to scan and update.
=head1 AUTHORS
=over 5
=item John Goerzen <jgoerzen@complete.org>
=item Branden Robinson <branden@debian.org>
=back
=head1 SEE ALSO
debsigs(1), debsig-verify(1), gpg(1)
=cut
# vim:set et ai sts=2 sw=2 tw=72:
|