Debian Codegraph @

debian/patches/extra_gpgverify

raw
1 --- /dev/null
2 +++ b/extra/gpgverify
3 @@ -0,0 +1,230 @@
4 +#!/usr/bin/perl -w
5 +require '/usr/lib/news/innshellvars.pl';
6 +
7 +# written April 1996, [email protected] (David C Lawrence)
8 +# mostly rewritten 2001-03-21 by Marco d'Itri <[email protected]>
9 +#
10 +# requirements:
11 +# - GnuPG
12 +# - perl 5.004_03 and working Sys::Syslog
13 +# - syslog daemon
14 +#
15 +# There is no locking because gpg is supposed to not need it and controlchan
16 +# will serialize control messages processing anyway.
17 +
18 +require 5.004_03;
19 +use strict;
20 +
21 +# if you keep your keyring somewhere that is not the default used by gpg,
22 +# set appropriately the next line.
23 +my $keyring = '/etc/news/pgp/pubring.pgp';
24 +
25 +# If you have INN and the script is able to successfully include your
26 +# innshellvars.pl file, the value of the next two variables will be
27 +# overridden.
28 +my $tmpdir = '/var/log/news/';
29 +my $syslog_facility = 'news';
30 +
31 +# 1: print PGP output
32 +my $debug = 0;
33 +$debug = 1 if -t 1;
34 +
35 +### Exit value:
36 +### 0 good signature
37 +### 1 no signature
38 +### 2 unknown signature
39 +### 3 bad signature
40 +### 255 problem not directly related to gpg analysis of signature
41 +
42 +##############################################################################
43 +################ NO USER SERVICEABLE PARTS BELOW THIS COMMENT ################
44 +##############################################################################
45 +my $tmp = ($inn::pathtmp ? $inn::pathtmp : $tmpdir) . "/pgp$$";
46 +$syslog_facility = $inn::syslog_facility if $inn::syslog_facility;
47 +
48 +my $nntp_format = 0;
49 +$0 =~ s#^.*/##; # trim /path/to/prog to prog
50 +
51 +die "Usage: $0 < message\n" if $#ARGV != -1;
52 +
53 +# Path to gpg binary
54 +my $gpg;
55 +foreach (split(/:/, $ENV{PATH}), qw(/usr/local/bin /opt/gnu/bin)) {
56 + if (-x "$_/gpgv") {
57 + $gpg = "$_/gpgv"; last;
58 + }
59 +}
60 +fail('cannot find the gpgv binary') if not $gpg;
61 +
62 +# this is, by design, case-sensitive with regards to the headers it checks.
63 +# it's also insistent about the colon-space rule.
64 +my ($label, $value, %dup, %header);
65 +while (<STDIN>) {
66 + # if a header line ends with \r\n, this article is in the encoding
67 + # it would be in during an NNTP session. some article storage
68 + # managers keep them this way for efficiency.
69 + $nntp_format = /\r\n$/ if $. == 1;
70 + s/\r?\n$//;
71 +
72 + last if /^$/;
73 + if (/^(\S+):[ \t](.+)/) {
74 + ($label, $value) = ($1, $2);
75 + $dup{$label} = 1 if $header{$label};
76 + $header{$label} = $value;
77 + } elsif (/^\s/) {
78 + fail("non-header at line $.: $_") unless $label;
79 + $header{$label} .= "\n$_";
80 + } else {
81 + fail("non-header at line $.: $_");
82 + }
83 +}
84 +
85 +my $pgpheader = 'X-PGP-Sig';
86 +$_ = $header{$pgpheader};
87 +exit 1 if not $_; # no signature
88 +
89 +# the $sep value means the separator between the radix64 signature lines
90 +# can have any amount of spaces or tabs, but must have at least one space
91 +# or tab, if there is a newline then the space or tab has to follow the
92 +# newline. any number of newlines can appear as long as each is followed
93 +# by at least one space or tab. *phew*
94 +my $sep = "[ \t]*(\n?[ \t]+)+";
95 +# match all of the characters in a radix64 string
96 +my $r64 = '[a-zA-Z0-9+/]';
97 +fail("$pgpheader not in expected format")
98 + unless /^(\S+)$sep(\S+)(($sep$r64{64})+$sep$r64+=?=?$sep=$r64{4})$/;
99 +
100 +my ($version, $signed_headers, $signature) = ($1, $3, $4);
101 +$signature =~ s/$sep/\n/g;
102 +
103 +my $message = "-----BEGIN PGP SIGNED MESSAGE-----\n\n"
104 + . "X-Signed-Headers: $signed_headers\n";
105 +
106 +foreach $label (split(',', $signed_headers)) {
107 + fail("duplicate signed $label header, can't verify") if $dup{$label};
108 + $message .= "$label: ";
109 + $message .= $header{$label} if $header{$label};
110 + $message .= "\n";
111 +}
112 +$message .= "\n"; # end of headers
113 +
114 +while (<STDIN>) { # read body lines
115 + if ($nntp_format) {
116 + # check for end of article; some news servers (eg, Highwind's
117 + # "Breeze") include the dot-CRLF of the NNTP protocol in the
118 + # article data passed to this script
119 + last if $_ eq ".\r\n";
120 +
121 + # remove NNTP encoding
122 + s/^\.\./\./;
123 + s/\r\n$/\n/;
124 + }
125 +
126 + s/^-/- -/; # pgp quote ("ASCII armor") dashes
127 + $message .= $_;
128 +}
129 +
130 +$message .=
131 + "\n-----BEGIN PGP SIGNATURE-----\n" .
132 + "Version: $version\n" .
133 + $signature .
134 + "\n-----END PGP SIGNATURE-----\n";
135 +
136 +open(TMP, ">$tmp") or fail("open $tmp: $!");
137 +print TMP $message;
138 +close TMP or errmsg("close $tmp: $!");
139 +
140 +my $opts = '--quiet --status-fd=1 --logger-fd=1';
141 +$opts .= " --keyring=$keyring" if $keyring;
142 +
143 +open(PGP, "$gpg $opts $tmp |") or fail("failed to execute $gpg: $!");
144 +
145 +undef $/;
146 +$_ = <PGP>;
147 +
148 +unlink $tmp or errmsg("unlink $tmp: $!");
149 +
150 +if (not close PGP) {
151 + if ($? >> 8) {
152 + my $status = $? >> 8;
153 + errmsg("gpg exited status $status") if $status > 1;
154 + } else {
155 + errmsg('gpg died on signal ' . ($? & 255));
156 + }
157 +}
158 +
159 +print STDERR $_ if $debug;
160 +
161 +my $ok = 255; # default exit status
162 +my $signer;
163 +if (/^\[GNUPG:\]\s+GOODSIG\s+\S+\s+(\S+)/m) {
164 + $ok = 0;
165 + $signer = $1;
166 +} elsif (/^\[GNUPG:\]\s+NODATA/m or /^\[GNUPG:\]\s+UNEXPECTED/m) {
167 + $ok = 1;
168 +} elsif (/^\[GNUPG:\]\s+NO_PUBKEY/m) {
169 + $ok = 2;
170 +} elsif (/^\[GNUPG:\]\s+BADSIG\s+/m) {
171 + $ok = 3;
172 +}
173 +
174 +print "$signer\n" if $signer;
175 +exit $ok;
176 +
177 +sub errmsg {
178 + my $msg = $_[0];
179 +
180 + eval 'use Sys::Syslog qw(:DEFAULT setlogsock)';
181 + die "$0: cannot use Sys::Syslog: $@ [$msg]\n" if $@;
182 +
183 + die "$0: cannot set syslog method [$msg]\n"
184 + if not (setlogsock('unix') or setlogsock('inet'));
185 +
186 + $msg .= " processing $header{'Message-ID'}" if $header{'Message-ID'};
187 +
188 + openlog($0, 'pid', $syslog_facility);
189 + syslog('err', '%s', $msg);
190 + closelog();
191 +}
192 +
193 +sub fail {
194 + errmsg($_[0]);
195 + unlink $tmp;
196 + exit 255;
197 +}
198 +
199 +__END__
200 +
201 +# Copyright 2000 by Marco d'Itri
202 +
203 +# License of the original version distributed by David C. Lawrence:
204 +
205 +# Copyright (c) 1996 UUNET Technologies, Inc.
206 +# All rights reserved.
207 +#
208 +# Redistribution and use in source and binary forms, with or without
209 +# modification, are permitted provided that the following conditions
210 +# are met:
211 +# 1. Redistributions of source code must retain the above copyright
212 +# notice, this list of conditions and the following disclaimer.
213 +# 2. Redistributions in binary form must reproduce the above copyright
214 +# notice, this list of conditions and the following disclaimer in the
215 +# documentation and/or other materials provided with the distribution.
216 +# 3. All advertising materials mentioning features or use of this software
217 +# must display the following acknowledgement:
218 +# This product includes software developed by UUNET Technologies, Inc.
219 +# 4. The name of UUNET Technologies ("UUNET") may not be used to endorse or
220 +# promote products derived from this software without specific prior
221 +# written permission.
222 +#
223 +# THIS SOFTWARE IS PROVIDED BY UUNET ``AS IS'' AND ANY EXPRESS OR
224 +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
225 +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
226 +# ARE DISCLAIMED. IN NO EVENT SHALL UUNET BE LIABLE FOR ANY DIRECT,
227 +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
228 +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
229 +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
230 +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
231 +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
232 +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
233 +# OF THE POSSIBILITY OF SUCH DAMAGE.
234 --- /dev/null
235 +++ b/extra/pgpverify.8
236 @@ -0,0 +1,118 @@
237 +.\"
238 +.\" $Id: pgpverify.8,v 1.1 1999/06/21 16:44:22 bdale Exp $
239 +.\"
240 +.\" This manual page was provided by James Ralston <[email protected]>
241 +.TH pgpverify 8
242 +.SH NAME
243 +pgpverify - cryptographically verify Usenet control messages
244 +.SH SYNOPSIS
245 +.B pgpverify
246 +.SH DESCRIPTION
247 +The
248 +.I pgpverify
249 +program reads (on standard input) a Usenet control message that has
250 +been cryptographically signed using the
251 +.I signcontrol
252 +program.
253 +.I pgpverify
254 +then uses the
255 +.I pgp
256 +program to determine who signed the control message. If the control
257 +message was validly signed,
258 +.I pgpverify
259 +outputs (to stdout) the User ID of the key ID that signed the message.
260 +.SH OPTIONS
261 +The
262 +.I pgpverify
263 +program takes no options.
264 +.SH EXIT STATUS
265 +.I pgpverify
266 +returns the follow exit statuses for the following cases:
267 +.P
268 +.TP
269 +.B 0
270 +The control message had a good PGP signature.
271 +.TP
272 +.B 1
273 +The control message had no PGP signature.
274 +.TP
275 +.B 2
276 +The control message had an unknown PGP signature.
277 +.TP
278 +.B 3
279 +The control message had a bad PGP signature.
280 +.TP
281 +.B 255
282 +A problem occurred not directly related to PGP analysis of signature.
283 +.SH AUTHOR
284 +David C Lawrence <[email protected]>
285 +.SH ENVIRONMENT
286 +.I pgpverify
287 +does not modify or otherwise alter the environment before invoking the
288 +.I pgp
289 +program. It is the responsibility of the person who installs
290 +.I pgpverify
291 +to ensure that when
292 +.I pgp
293 +runs, it has the ability to locate and read a PGP key file that
294 +contains the PGP public keys for the appropriate Usenet hierarchy
295 +administrators.
296 +.SH SEE ALSO
297 +pgp(1)
298 +.SH NOTES
299 +Historically, Usenet news server administrators have configured their
300 +news servers to automatically honor Usenet control messages based on
301 +the originator of the control messages and the hierarchies for which
302 +the control messages applied. For example, in the past, David C
303 +Lawrence <[email protected]> always issued control messages for the
304 +"Big 8" hierarchies (comp, humanities, misc, news, rec, sci, soc,
305 +talk). Usenet news administrators would configure their news server
306 +software to automatically honor newgroup and rmgroup control messages
307 +that originated from David Lawrence and applied to any of the Big 8
308 +hierarchies.
309 +.P
310 +Unfortunately, Usenet news articles (including control messages) are
311 +notoriously easy to forge. Soon, malicious users realized they could
312 +create or remove (at least temporarily) any Big 8 newsgroup they
313 +wanted by simply forging an appropriate control message in David
314 +Lawrence's name. As Usenet became more widely used, forgeries became
315 +more common.
316 +.P
317 +The
318 +.I pgpverify
319 +program was designed to allow Usenet news administrators to configure
320 +their servers to cryptographically verify control messages before
321 +automatically acting on them. Under the pgpverify system, a Usenet
322 +hierarchy maintainer creates a PGP public/private key pair and
323 +disseminates the public key. Whenever the hierarchy maintainer issues
324 +a control message, he uses the
325 +.I signcontrol
326 +program to sign the control message with the PGP private key. Usenet
327 +news administrators configure their news servers to run the
328 +.I pgpverify
329 +program on the appropriate control messages, and take action based on
330 +the PGP key User ID that signed the control message, not the name and
331 +address that appear in the control message's From or Sender headers.
332 +.P
333 +Thus, using the
334 +.I signcontrol
335 +and
336 +.I pgpverify programs
337 +appropriately essentially eliminates the possibility of malicious
338 +users forging Usenet control messages that sites will act upon, as
339 +such users would have to obtain the PGP private key in order to forge
340 +a control message that would pass the cryptographic verification step.
341 +If the hierarchy administrators properly protect their PGP private
342 +keys, the only way a malicious user could forge a validly-signed
343 +control message would be by breaking the RSA encryption algorithm,
344 +which (at least at this time) is believed to be an NP-complete
345 +problem. If this is indeed the case, discovering the PGP private key
346 +based on the PGP public key is computationally impossible for PGP keys
347 +of a sufficient bit length.
348 +.P
349 +<URL:ftp://ftp.isc.org/pub/pgpcontrol/> is where the most recent
350 +versions of
351 +.I signcontrol
352 +and
353 +.I pgpverify
354 +live, along with PGP public keys used for hierarchy administration.