1 |
wakaba |
1.1 |
#!/usr/bin/perl
|
2 |
|
|
|
3 |
|
|
=head1 NAME
|
4 |
|
|
|
5 |
|
|
sign.pl --- Sample script of Message::* Perl Modules
|
6 |
|
|
--- Signing a (new) message with GnuPG
|
7 |
|
|
|
8 |
|
|
=cut
|
9 |
|
|
|
10 |
|
|
## This file is written in EUC-japan.
|
11 |
|
|
|
12 |
|
|
use strict;
|
13 |
|
|
use vars qw($VERSION);
|
14 |
|
|
$VERSION=do{my @r=(q$Revision: 1.10 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
|
15 |
|
|
use Message::MIME::Charset::Jcode 'jcode.pl';
|
16 |
|
|
$Message::MIME::Charset::Jcode::CODE{input} = 'euc';
|
17 |
|
|
use Getopt::Long;
|
18 |
|
|
my $gpg_path = 'gpg';
|
19 |
|
|
my $tmp_path = './';
|
20 |
|
|
GetOptions (
|
21 |
|
|
'--gpg-path=s' => \$gpg_path,
|
22 |
|
|
'--temp-dir=s' => \$tmp_path,
|
23 |
|
|
) or die;
|
24 |
|
|
|
25 |
|
|
my $msgbody = <<'EOH';
|
26 |
|
|
GnuPG を使って電子署名、とか言ってみるテスト。
|
27 |
|
|
EOH
|
28 |
|
|
|
29 |
|
|
require Message::Entity;
|
30 |
|
|
my $msg = new Message::Entity;
|
31 |
|
|
$msg->header->field ('user-agent')->add ($0 => $VERSION);
|
32 |
|
|
my $ct = $msg->header->field ('content-type');
|
33 |
|
|
$ct->media_type ('multipart/signed');
|
34 |
|
|
$ct->parameter (micalg => 'pgp-sha1');
|
35 |
|
|
my $body = $msg->body->data_part;
|
36 |
|
|
$body->body ($msgbody);
|
37 |
|
|
my $signature = $msg->body->control_part;
|
38 |
|
|
my $sct = $signature->header->field ('content-type');
|
39 |
|
|
$sct->media_type ('application/pgp-signature');
|
40 |
|
|
|
41 |
|
|
open MSG, "> $tmp_path.signmsg.tmp";
|
42 |
|
|
binmode MSG;
|
43 |
|
|
print MSG $body;
|
44 |
|
|
close MSG;
|
45 |
|
|
|
46 |
|
|
{
|
47 |
|
|
`$gpg_path --detach-sign --armor --digest-algo sha1 $tmp_path.signmsg.tmp`;
|
48 |
|
|
open GPG, "$tmp_path.signmsg.tmp.asc";
|
49 |
|
|
binmode GPG;
|
50 |
|
|
local $/ = undef;
|
51 |
|
|
$signature->body (<GPG>);
|
52 |
|
|
close GPG;
|
53 |
|
|
unlink "$tmp_path.signmsg.tmp";
|
54 |
|
|
unlink "$tmp_path.signmsg.tmp.asc";
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
binmode STDOUT;
|
58 |
|
|
print $msg;
|
59 |
|
|
|
60 |
|
|
=head1 LICENSE
|
61 |
|
|
|
62 |
|
|
Copyright 2002 wakaba E<lt>w@suika.fam.cxE<gt>.
|
63 |
|
|
|
64 |
|
|
This program is free software; you can redistribute it and/or modify
|
65 |
|
|
it under the terms of the GNU General Public License as published by
|
66 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
67 |
|
|
(at your option) any later version.
|
68 |
|
|
|
69 |
|
|
This program is distributed in the hope that it will be useful,
|
70 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
71 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
72 |
|
|
GNU General Public License for more details.
|
73 |
|
|
|
74 |
|
|
You should have received a copy of the GNU General Public License
|
75 |
|
|
along with this program; see the file COPYING. If not, write to
|
76 |
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
77 |
|
|
Boston, MA 02111-1307, USA.
|
78 |
|
|
|
79 |
|
|
=head1 CHANGE
|
80 |
|
|
|
81 |
|
|
See F<ChangeLog>.
|
82 |
|
|
$Date: 2002/07/20 03:11:47 $
|
83 |
|
|
|
84 |
|
|
=cut
|
85 |
|
|
|
86 |
|
|
### sign.pl ends here
|