1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
=head1 NAME |
4 |
|
|
|
5 |
|
|
verify.pl --- Sample script of Message::* Perl Modules |
6 |
|
|
--- Verifying signed message with GnuPG |
7 |
|
|
|
8 |
|
|
=cut |
9 |
|
|
|
10 |
|
|
use strict; |
11 |
|
|
use vars qw($VERSION); |
12 |
|
|
$VERSION=do{my @r=(q$Revision: 1.10 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
13 |
|
|
use Message::Entity; |
14 |
|
|
use Getopt::Long; |
15 |
|
|
my $gpg_path = 'gpg'; |
16 |
|
|
my $tmp_path = './'; |
17 |
|
|
GetOptions ( |
18 |
|
|
'--gpg-path=s' => \$gpg_path, |
19 |
|
|
'--temp-dir=s' => \$tmp_path, |
20 |
|
|
) or die; |
21 |
|
|
|
22 |
|
|
my $msg; |
23 |
|
|
{ |
24 |
|
|
binmode STDIN; |
25 |
|
|
local $/ = undef; |
26 |
|
|
$msg = Message::Entity->parse (<STDIN>, -linebreak_strict => 0); |
27 |
|
|
} |
28 |
|
|
die "This message is not signed" unless $msg->media_type eq 'multipart/signed'; |
29 |
|
|
my $protocol = lc $msg->header->field ('content-type')->item ('protocol'); |
30 |
|
|
die "Protocol $protocol is not supported" unless $protocol eq 'application/pgp-signature'; |
31 |
|
|
my $body = $msg->body->data_part (-parse => 0); |
32 |
|
|
my $signature = $msg->body->control_part; |
33 |
|
|
|
34 |
|
|
die "Media type of signature (@{[scalar $signature->media_type]}) does not match with $protocol" unless $signature->media_type eq 'application/pgp-signature'; |
35 |
|
|
|
36 |
|
|
open MSG, ">$tmp_path.signedmsg.tmp"; |
37 |
|
|
binmode MSG; |
38 |
|
|
print MSG $body; |
39 |
|
|
close MSG; |
40 |
|
|
open SIG, ">$tmp_path.signature.tmp"; |
41 |
|
|
binmode SIG; |
42 |
|
|
print SIG $signature->body; |
43 |
|
|
close SIG; |
44 |
|
|
|
45 |
|
|
print `$gpg_path --verify --batch $tmp_path.signature.tmp $tmp_path.signedmsg.tmp`; |
46 |
|
|
`rm $tmp_path.signature.tmp $tmp_path.signedmsg.tmp`; |
47 |
|
|
|
48 |
|
|
=head1 LICENSE |
49 |
|
|
|
50 |
|
|
Copyright 2002 wakaba E<lt>w@suika.fam.cxE<gt>. |
51 |
|
|
|
52 |
|
|
This program is free software; you can redistribute it and/or modify |
53 |
|
|
it under the terms of the GNU General Public License as published by |
54 |
|
|
the Free Software Foundation; either version 2 of the License, or |
55 |
|
|
(at your option) any later version. |
56 |
|
|
|
57 |
|
|
This program is distributed in the hope that it will be useful, |
58 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
59 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
60 |
|
|
GNU General Public License for more details. |
61 |
|
|
|
62 |
|
|
You should have received a copy of the GNU General Public License |
63 |
|
|
along with this program; see the file COPYING. If not, write to |
64 |
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
65 |
|
|
Boston, MA 02111-1307, USA. |
66 |
|
|
|
67 |
|
|
=head1 CHANGE |
68 |
|
|
|
69 |
|
|
See F<ChangeLog>. |
70 |
|
|
$Date: 2002/07/20 03:11:47 $ |
71 |
|
|
|
72 |
|
|
=cut |
73 |
|
|
|
74 |
|
|
### verify.pl ends here |