line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*-cperl-*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Crypt::GPG - An Object Oriented Interface to GnuPG. |
4
|
|
|
|
|
|
|
# Copyright (c) 2000-2007 Ashish Gulhati |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# All rights reserved. This code is free software; you can |
7
|
|
|
|
|
|
|
# redistribute it and/or modify it under the same terms as Perl |
8
|
|
|
|
|
|
|
# itself. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# $Id: GPG.pm,v 1.64 2014/09/18 12:21:25 ashish Exp $ |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package Crypt::GPG; |
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
6
|
|
63200
|
use Carp; |
|
6
|
|
|
|
|
74
|
|
|
6
|
|
|
|
|
704
|
|
15
|
6
|
|
|
6
|
|
38
|
use Fcntl; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
4085
|
|
16
|
6
|
|
|
6
|
|
42
|
use strict; |
|
6
|
|
|
|
|
31
|
|
|
6
|
|
|
|
|
228
|
|
17
|
6
|
|
|
6
|
|
9875
|
use English; |
|
6
|
|
|
|
|
57032
|
|
|
6
|
|
|
|
|
37
|
|
18
|
6
|
|
|
6
|
|
4383
|
use File::Path; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
433
|
|
19
|
6
|
|
|
6
|
|
35
|
use File::Spec (); |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
105
|
|
20
|
6
|
|
|
6
|
|
6690
|
use Date::Parse; |
|
6
|
|
|
|
|
71638
|
|
|
6
|
|
|
|
|
1023
|
|
21
|
6
|
|
|
6
|
|
9325
|
use File::Temp qw( tempfile tempdir ); |
|
6
|
|
|
|
|
214062
|
|
|
6
|
|
|
|
|
730
|
|
22
|
6
|
|
|
6
|
|
11270
|
use IPC::Run qw( start pump finish timeout ); |
|
6
|
|
|
|
|
331962
|
|
|
6
|
|
|
|
|
553
|
|
23
|
6
|
|
|
6
|
|
178
|
use vars qw( $VERSION $AUTOLOAD ); |
|
6
|
|
|
|
|
25
|
|
|
6
|
|
|
|
|
71499
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
File::Temp->safe_level( File::Temp::STANDARD ); |
26
|
|
|
|
|
|
|
( $VERSION ) = '$Revision: 1.64 $' =~ /\s+([\d\.]+)/; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
6
|
|
|
6
|
1
|
1648
|
bless { GPGBIN => '/usr/local/bin/gpg', |
30
|
|
|
|
|
|
|
FORCEDOPTS => '--no-secmem-warning', |
31
|
|
|
|
|
|
|
GPGOPTS => '--lock-multiple --compress-algo 1 ' . |
32
|
|
|
|
|
|
|
'--cipher-algo cast5 --force-v3-sigs', |
33
|
|
|
|
|
|
|
VERSION => $VERSION, |
34
|
|
|
|
|
|
|
DELAY => 0, |
35
|
|
|
|
|
|
|
PASSPHRASE => '', |
36
|
|
|
|
|
|
|
COMMENT => "Crypt::GPG v$VERSION", |
37
|
|
|
|
|
|
|
ARMOR => 1, |
38
|
|
|
|
|
|
|
MARGINALS => 3, |
39
|
|
|
|
|
|
|
DETACH => 1, |
40
|
|
|
|
|
|
|
ENCRYPTSAFE => 1, |
41
|
|
|
|
|
|
|
TEXT => 1, |
42
|
|
|
|
|
|
|
SECRETKEY => '', |
43
|
|
|
|
|
|
|
DEBUG => 0, |
44
|
|
|
|
|
|
|
TMPFILES => 'fileXXXXXX', |
45
|
|
|
|
|
|
|
TMPDIRS => 'dirXXXXXX', |
46
|
|
|
|
|
|
|
TMPDIR => File::Spec->tmpdir(), |
47
|
|
|
|
|
|
|
TMPSUFFIX => '.dat', |
48
|
|
|
|
|
|
|
VKEYID => '^.+$', |
49
|
|
|
|
|
|
|
VRCPT => '^.*$', |
50
|
|
|
|
|
|
|
VPASSPHRASE => '^.*$', |
51
|
|
|
|
|
|
|
VCOMMENT => '^.*$', |
52
|
|
|
|
|
|
|
VNAME => '^[a-zA-Z][\w\.\s\-\_]+$', |
53
|
|
|
|
|
|
|
VEXPIRE => '^\d+$', |
54
|
|
|
|
|
|
|
VKEYSZ => '^\d+$', |
55
|
|
|
|
|
|
|
VKEYTYPE => '^ELG-E$', |
56
|
|
|
|
|
|
|
VTRUSTLEVEL => '^[1-5]$', |
57
|
|
|
|
|
|
|
VEMAIL => '^[\w\.\-]+\@[\w\.\-]+\.[A-Za-z]{2,3}$' |
58
|
|
|
|
|
|
|
}, shift; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub sign { |
62
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
0
|
|
|
0
|
return unless (!$self->secretkey or $self->secretkey =~ /$self->{VKEYID}/) |
|
|
|
0
|
|
|
|
|
65
|
|
|
|
|
|
|
and $self->passphrase =~ /$self->{VPASSPHRASE}/; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
0
|
my $detach = '-b' if $self->detach; |
68
|
0
|
0
|
|
|
|
0
|
my $armor = '-a' if $self->armor; |
69
|
0
|
|
|
|
|
0
|
my @extras = grep { $_ } ($detach, $armor); |
|
0
|
|
|
|
|
0
|
|
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
0
|
my @secretkey = ('--default-key', ref($self->secretkey)?$self->secretkey->{ID}:$self->secretkey) |
|
|
0
|
|
|
|
|
|
72
|
|
|
|
|
|
|
if $self->secretkey;; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
my ($tmpfh, $tmpnam) = |
75
|
|
|
|
|
|
|
tempfile( $self->tmpfiles, DIR => $self->tmpdir, |
76
|
|
|
|
|
|
|
SUFFIX => $self->tmpsuffix, UNLINK => 1); |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
0
|
my $message = join ('', @_); |
79
|
|
|
|
|
|
|
# $message .= "\n" unless $message =~ /\n$/s; |
80
|
0
|
|
|
|
|
0
|
$message =~ s/(?
|
81
|
0
|
|
|
|
|
0
|
print $tmpfh $message; close $tmpfh; |
|
0
|
|
|
|
|
0
|
|
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
84
|
0
|
0
|
|
|
|
0
|
push (@opts, ('--comment', $self->comment)) if $self->comment; |
85
|
0
|
0
|
|
|
|
0
|
my $signhow = $self->clearsign ? '--clearsign' : '--sign'; |
86
|
0
|
|
|
|
|
0
|
local $SIG{CHLD} = 'IGNORE'; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
my ($in, $out, $err, $in_q, $out_q, $err_q); |
89
|
0
|
|
|
|
|
0
|
my $h = start ([$self->gpgbin, @opts, @secretkey,'--no-tty', '--status-fd', '2', '--command-fd', |
90
|
|
|
|
|
|
|
0, '-o-', $signhow, @extras, $tmpnam], \$in, \$out, \$err, timeout( 30 )); |
91
|
0
|
|
|
|
|
0
|
my $skip = 1; my $i = 0; |
|
0
|
|
|
|
|
0
|
|
92
|
0
|
|
|
|
|
0
|
local $SIG{CHLD} = 'IGNORE'; |
93
|
0
|
|
|
|
|
0
|
local $SIG{PIPE} = 'IGNORE'; |
94
|
0
|
|
|
|
|
0
|
while ($skip) { |
95
|
0
|
|
0
|
|
|
0
|
pump $h until ($err =~ /NEED_PASSPHRASE (.{16}) (.{16}).*\n/g or |
96
|
|
|
|
|
|
|
$err =~ /GOOD_PASSPHRASE/g); |
97
|
0
|
0
|
|
|
|
0
|
if ($2) { |
98
|
0
|
|
|
|
|
0
|
$in .= $self->passphrase . "\n"; |
99
|
0
|
|
|
|
|
0
|
pump $h until $err =~ /(GOOD|BAD)_PASSPHRASE/g; |
100
|
0
|
0
|
|
|
|
0
|
if ($1 eq 'GOOD') { |
101
|
0
|
|
|
|
|
0
|
$skip = 0; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
0
|
0
|
|
|
|
0
|
$skip = 0 if $i++ == 2; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
else { |
108
|
0
|
|
|
|
|
0
|
finish $h; |
109
|
0
|
|
|
|
|
0
|
last; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
0
|
|
|
|
|
0
|
finish $h; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
0
|
my $info; |
115
|
0
|
0
|
|
|
|
0
|
if ($self->clearsign) { |
|
|
0
|
|
|
|
|
|
116
|
0
|
|
|
|
|
0
|
$out =~ /(-----BEGIN PGP SIGNED MESSAGE-----.*-----END PGP SIGNATURE-----)/s; |
117
|
0
|
|
|
|
|
0
|
$info = $1; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
elsif ($detach) { |
120
|
0
|
|
|
|
|
0
|
$out =~ /(-----BEGIN PGP SIGNATURE-----.*-----END PGP SIGNATURE-----)/s; |
121
|
0
|
|
|
|
|
0
|
$info = $1; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
else { |
124
|
0
|
|
|
|
|
0
|
$out =~ /(-----BEGIN PGP MESSAGE-----.*-----END PGP MESSAGE-----)/s; |
125
|
0
|
|
|
|
|
0
|
$info = $1; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
0
|
unlink $tmpnam; |
128
|
0
|
|
|
|
|
0
|
return $info; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
0
|
1
|
0
|
sub decrypt { shift->verify(@_); } |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub verify { |
134
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
135
|
0
|
|
|
|
|
0
|
my ($tmpfh3, $tmpnam3); |
136
|
|
|
|
|
|
|
|
137
|
0
|
0
|
0
|
|
|
0
|
return unless $self->secretkey || $_[1]; |
138
|
0
|
0
|
|
|
|
0
|
return unless $self->passphrase =~ /$self->{VPASSPHRASE}/; |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
0
|
my ($tf, $ts, $td) = ($self->tmpfiles, $self->tmpsuffix, $self->tmpdir); |
141
|
0
|
|
|
|
|
0
|
my ($tmpfh, $tmpnam) = tempfile ($tf, DIR => $td, SUFFIX => $ts, UNLINK => 1); |
142
|
0
|
|
|
|
|
0
|
my ($tmpfh2, $tmpnam2) = tempfile ($tf, DIR => $td, SUFFIX => $ts, UNLINK => 1); |
143
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
0
|
my $ciphertext = ref($_[0]) ? join '', @{$_[0]} : $_[0]; |
|
0
|
|
|
|
|
0
|
|
145
|
0
|
0
|
|
|
|
0
|
$ciphertext .= "\n" unless $ciphertext =~ /\n$/s; |
146
|
0
|
|
|
|
|
0
|
print $tmpfh $ciphertext; close $tmpfh; |
|
0
|
|
|
|
|
0
|
|
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
149
|
0
|
0
|
0
|
|
|
0
|
push (@opts, ('--comment', $self->comment)) if $self->comment and !$_[1]; |
150
|
0
|
|
|
|
|
0
|
backtick ($self->gpgbin, @opts, '--marginals-needed', $self->marginals, '--check-trustdb'); |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
0
|
local $SIG{CHLD} = 'IGNORE'; |
153
|
0
|
|
|
|
|
0
|
local $SIG{PIPE} = 'IGNORE'; |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
0
|
my $x; |
156
|
0
|
0
|
|
|
|
0
|
if ($_[1]) { |
157
|
0
|
0
|
|
|
|
0
|
my $message = ref($_[1]) ? join '', @{$_[1]} : $_[1]; |
|
0
|
|
|
|
|
0
|
|
158
|
|
|
|
|
|
|
# $message .= "\n" unless $message =~ /\n$/s; |
159
|
0
|
|
|
|
|
0
|
$message =~ s/(?
|
160
|
0
|
|
|
|
|
0
|
($tmpfh3, $tmpnam3) = tempfile ($tf, DIR => $td, SUFFIX => $ts, UNLINK => 1); |
161
|
0
|
|
|
|
|
0
|
print $tmpfh3 $message; close $tmpfh3; |
|
0
|
|
|
|
|
0
|
|
162
|
0
|
|
|
|
|
0
|
my $y = $self->gpgbin . " @opts --marginals-needed " . $self->marginals . " --status-fd 1 --logger-fd 1 --command-fd 0 --no-tty --verify $tmpnam $tmpnam3"; |
163
|
0
|
|
|
|
|
0
|
$x = `$y`; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
else { |
167
|
0
|
|
|
|
|
0
|
my ($in, $out, $err, $in_q, $out_q, $err_q); |
168
|
0
|
|
|
|
|
0
|
my $h = start ([$self->gpgbin, @opts, '--marginals-needed', $self->marginals, |
169
|
|
|
|
|
|
|
'--status-fd', '1', '--command-fd', 0, '--yes', '--no-tty', |
170
|
|
|
|
|
|
|
'--decrypt', '-o', $tmpnam2, $tmpnam], |
171
|
|
|
|
|
|
|
\$in, \$out, \$err, timeout( 30 )); |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
0
|
my $success = 0; |
174
|
0
|
0
|
|
|
|
0
|
my $seckey = (ref($self->secretkey)?$self->secretkey->{ID}:$self->secretkey); |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
0
|
while (1) { |
177
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /NEED_PASSPHRASE (.{16}) (.{16}).*\n/g |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
178
|
|
|
|
|
|
|
or $out =~ /(GOOD_PASSPHRASE)/g |
179
|
|
|
|
|
|
|
or $out =~ /(D)(E)(C)RYPTION_FAILED/g or $out =~ /(N)(O)(D)ATA/g |
180
|
|
|
|
|
|
|
or $out =~ /(SIG_ID)/g |
181
|
|
|
|
|
|
|
or $out =~ /detached_signature.filename/g |
182
|
|
|
|
|
|
|
); |
183
|
0
|
0
|
|
|
|
0
|
if ($3) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
184
|
0
|
|
|
|
|
0
|
finish $h; |
185
|
0
|
|
|
|
|
0
|
last; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
elsif ($2) { |
188
|
0
|
0
|
|
|
|
0
|
if (substr($2,-1,8) eq substr($seckey,-1,8)) { |
189
|
0
|
|
|
|
|
0
|
$in .= $self->passphrase . "\n"; |
190
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /(GOOD|BAD)_PASSPHRASE/g; |
191
|
0
|
0
|
|
|
|
0
|
if ($1 eq 'GOOD') { |
192
|
0
|
|
|
|
|
0
|
$success = 1; |
193
|
0
|
|
|
|
|
0
|
pump $h; |
194
|
0
|
|
|
|
|
0
|
finish $h; $x = $out; last; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
195
|
|
|
|
|
|
|
} |
196
|
0
|
|
|
|
|
0
|
next; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
else { |
199
|
0
|
|
|
|
|
0
|
$out = ''; $in .= "\n"; |
|
0
|
|
|
|
|
0
|
|
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
elsif ($1) { |
203
|
0
|
|
|
|
|
0
|
$success = 1; |
204
|
0
|
|
|
|
|
0
|
pump $h; |
205
|
0
|
|
|
|
|
0
|
finish $h; $x = $out; last; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
0
|
0
|
0
|
|
|
0
|
unless ($success || $_[1]) { |
211
|
0
|
|
|
|
|
0
|
close $tmpfh2; unlink ($tmpnam2); |
|
0
|
|
|
|
|
0
|
|
212
|
0
|
|
|
|
|
0
|
return undef; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
0
|
|
0
|
|
|
0
|
my $plaintext = join ('',<$tmpfh2>) || ''; |
217
|
0
|
|
|
|
|
0
|
close $tmpfh2; unlink ($tmpnam2); |
|
0
|
|
|
|
|
0
|
|
218
|
|
|
|
|
|
|
|
219
|
0
|
0
|
|
|
|
0
|
return ($plaintext) |
220
|
|
|
|
|
|
|
unless $x =~ /(GOOD|BAD)SIG/s; |
221
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
0
|
my @signatures; |
223
|
0
|
|
|
|
|
0
|
$x =~ /Signature made (\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+).*(GOOD|BAD)SIG (\S{16}).*(TRUST_(\S+))?/sg; |
224
|
|
|
|
|
|
|
|
225
|
0
|
|
|
|
|
0
|
my $signature = {'Validity' => $2, 'KeyID' => $3, |
226
|
|
|
|
|
|
|
'Time' => $1, 'Trusted' => $4}; |
227
|
0
|
|
|
|
|
0
|
$signature->{Time} = str2time ($signature->{Time}); |
228
|
0
|
|
|
|
|
0
|
bless $signature, 'Crypt::GPG::Signature'; |
229
|
0
|
|
|
|
|
0
|
return ($plaintext, $signature); |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub msginfo { |
233
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
234
|
0
|
|
|
|
|
0
|
my @return; |
235
|
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
0
|
my ($tmpfh, $tmpnam) = |
237
|
|
|
|
|
|
|
tempfile( $self->tmpfiles, DIR => $self->tmpdir, |
238
|
|
|
|
|
|
|
SUFFIX => $self->tmpsuffix, UNLINK => 1); |
239
|
0
|
|
|
|
|
0
|
warn join '',@{$_[0]}; |
|
0
|
|
|
|
|
0
|
|
240
|
0
|
|
|
|
|
0
|
print $tmpfh join '',@{$_[0]}; close $tmpfh; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
241
|
|
|
|
|
|
|
|
242
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
243
|
0
|
|
|
|
|
0
|
my ($info) = backtick ($self->gpgbin, @opts, '--status-fd', 1, '--no-tty', '--batch', $tmpnam); |
244
|
0
|
|
|
|
|
0
|
$info =~ s/ENC_TO (.{16})/{push @return, $1}/sge; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
245
|
0
|
|
|
|
|
0
|
unlink $tmpnam; |
246
|
0
|
|
|
|
|
0
|
return @return; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub encrypt { |
250
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
251
|
0
|
|
|
|
|
0
|
my ($message, $rcpts) = @_; |
252
|
0
|
|
|
|
|
0
|
my $info; |
253
|
|
|
|
|
|
|
|
254
|
0
|
0
|
0
|
|
|
0
|
my $sign = $_[2] && $_[2] eq '-sign' ? '--sign' : ''; |
255
|
0
|
0
|
|
|
|
0
|
my $armor = $self->armor ? '-a' : ''; |
256
|
|
|
|
|
|
|
|
257
|
0
|
0
|
|
|
|
0
|
if ($sign) { |
258
|
0
|
0
|
0
|
|
|
0
|
return unless (!$self->secretkey or $self->secretkey =~ /$self->{VKEYID}/) |
|
|
|
0
|
|
|
|
|
259
|
|
|
|
|
|
|
and $self->passphrase =~ /$self->{VPASSPHRASE}/; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
0
|
|
|
|
|
0
|
my @rcpts; |
263
|
0
|
0
|
|
|
|
0
|
if (ref($rcpts) eq 'ARRAY') { |
264
|
0
|
0
|
|
|
|
0
|
@rcpts = map { |
265
|
0
|
|
|
|
|
0
|
return unless /$self->{VRCPT}/; |
266
|
0
|
|
|
|
|
0
|
('-r', $_) } @$rcpts; |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
else { |
269
|
0
|
0
|
|
|
|
0
|
return unless $rcpts =~ /$self->{VRCPT}/; |
270
|
0
|
|
|
|
|
0
|
@rcpts = ('-r', $rcpts); |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
0
|
|
|
|
|
0
|
my ($tmpfh, $tmpnam) = |
274
|
|
|
|
|
|
|
tempfile( $self->tmpfiles, DIR => $self->tmpdir, |
275
|
|
|
|
|
|
|
SUFFIX => $self->tmpsuffix, UNLINK => 1); |
276
|
0
|
|
|
|
|
0
|
my ($tmpfh2, $tmpnam2) = |
277
|
|
|
|
|
|
|
tempfile( $self->tmpfiles, DIR => $self->tmpdir, |
278
|
|
|
|
|
|
|
SUFFIX => $self->tmpsuffix, UNLINK => 1); |
279
|
|
|
|
|
|
|
|
280
|
0
|
0
|
|
|
|
0
|
$message = join ('', @$message) if ref($message) eq 'ARRAY'; |
281
|
0
|
|
|
|
|
0
|
print $tmpfh $message; close $tmpfh; |
|
0
|
|
|
|
|
0
|
|
282
|
|
|
|
|
|
|
|
283
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
284
|
0
|
0
|
0
|
|
|
0
|
push (@opts, '--default-key', ref($self->secretkey)?$self->secretkey->{ID}:$self->secretkey) if $sign and $self->secretkey; |
|
|
0
|
|
|
|
|
|
285
|
0
|
0
|
|
|
|
0
|
push (@opts, $sign) if $sign; push (@opts, $armor) if $armor; |
|
0
|
0
|
|
|
|
0
|
|
286
|
0
|
0
|
|
|
|
0
|
push (@opts, ('--comment', $self->comment)) if $self->comment; |
287
|
|
|
|
|
|
|
|
288
|
0
|
|
|
|
|
0
|
my ($in, $out, $err, $in_q, $out_q, $err_q); |
289
|
0
|
|
|
|
|
0
|
my $h = start ([$self->gpgbin, @opts, '--no-tty', '--status-fd', '1', '--command-fd', 0, |
290
|
|
|
|
|
|
|
'-o', $tmpnam2, @rcpts, '--encrypt', $tmpnam], \$in, \$out, \$err, timeout( 30 )); |
291
|
0
|
|
|
|
|
0
|
local $SIG{CHLD} = 'IGNORE'; local $SIG{PIPE} = 'IGNORE'; |
|
0
|
|
|
|
|
0
|
|
292
|
0
|
|
|
|
|
0
|
my $pos; |
293
|
0
|
|
|
|
|
0
|
eval { |
294
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /(o)penfile.overwrite.okay/g |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
295
|
|
|
|
|
|
|
or $out =~ /(u)(n)trusted_key.override/g #! Test |
296
|
|
|
|
|
|
|
or $out =~ /(k)(e)(y) not found/g #! Test |
297
|
|
|
|
|
|
|
or $out =~ /(p)(a)(s)(s)phrase.enter/g); |
298
|
0
|
0
|
|
|
|
0
|
$pos = 1 if $1; $pos = 2 if $2; $pos = 3 if $3; $pos = 4 if $4; |
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
299
|
|
|
|
|
|
|
}; |
300
|
0
|
0
|
|
|
|
0
|
return if $@; |
301
|
0
|
0
|
|
|
|
0
|
if ($pos == 4) { |
302
|
0
|
|
|
|
|
0
|
undef $pos; $out = ''; |
|
0
|
|
|
|
|
0
|
|
303
|
0
|
|
|
|
|
0
|
$in .= $self->passphrase . "\n"; |
304
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /(o)penfile.overwrite.okay/g |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
305
|
|
|
|
|
|
|
or $out =~ /(u)(n)trusted_key.override/g #! Test |
306
|
|
|
|
|
|
|
or $out =~ /(I)(N)(V)_RECP/g #! Test |
307
|
|
|
|
|
|
|
or $out =~ /(p)(a)(s)(s)phrase.enter/g); #! Test |
308
|
0
|
0
|
|
|
|
0
|
$pos = 1 if $1; $pos = 2 if $2; $pos = 3 if $3; $pos = 4 if $4; |
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
309
|
0
|
0
|
|
|
|
0
|
finish $h, return undef if $pos == 4; #! Test |
310
|
|
|
|
|
|
|
} |
311
|
|
|
|
|
|
|
|
312
|
0
|
0
|
|
|
|
0
|
if ($pos == 2) { |
|
|
0
|
|
|
|
|
|
313
|
0
|
0
|
|
|
|
0
|
if ($self->encryptsafe) { |
314
|
0
|
|
|
|
|
0
|
$in .= "N\n"; |
315
|
0
|
|
|
|
|
0
|
finish $h; |
316
|
0
|
|
|
|
|
0
|
unlink $tmpnam; |
317
|
0
|
|
|
|
|
0
|
return; |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
else { |
320
|
0
|
|
|
|
|
0
|
$in .= "Y\n"; |
321
|
|
|
|
|
|
|
# finish $h; |
322
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /(o)penfile.overwrite.okay/g |
323
|
|
|
|
|
|
|
or $out =~ /(o)(p)enfile.askoutname/g); #! Test |
324
|
|
|
|
|
|
|
# or $out =~ /(I)(N)(V)_RECP/g #! Test |
325
|
|
|
|
|
|
|
# or $out =~ /(p)(a)(s)(s)phrase.enter/g); #! Test |
326
|
0
|
0
|
|
|
|
0
|
$pos = 1 if $1; $pos = 2 if $2; |
|
0
|
0
|
|
|
|
0
|
|
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
elsif ($pos == 3) { |
330
|
0
|
|
|
|
|
0
|
finish $h; |
331
|
0
|
|
|
|
|
0
|
unlink $tmpnam; |
332
|
0
|
|
|
|
|
0
|
return; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
|
335
|
0
|
0
|
|
|
|
0
|
if ($pos == 1) { |
336
|
0
|
|
|
|
|
0
|
$in .= "Y\n"; |
337
|
0
|
|
|
|
|
0
|
finish $h; |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
|
340
|
0
|
|
|
|
|
0
|
my @info = <$tmpfh2>; |
341
|
0
|
|
|
|
|
0
|
close $tmpfh2; |
342
|
0
|
|
|
|
|
0
|
unlink $tmpnam2; |
343
|
0
|
|
|
|
|
0
|
$info = join '', @info; |
344
|
|
|
|
|
|
|
|
345
|
0
|
|
|
|
|
0
|
unlink $tmpnam; |
346
|
0
|
|
|
|
|
0
|
return $info; |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
sub addkey { |
350
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
351
|
0
|
|
|
|
|
0
|
my ($key, $pretend, @keyids) = @_; |
352
|
|
|
|
|
|
|
|
353
|
0
|
0
|
|
|
|
0
|
$key = join ('', @$key) if ref($key) eq 'ARRAY'; |
354
|
0
|
0
|
|
|
|
0
|
return if grep { $_ !~ /^[a-f0-9]+$/i } @keyids; |
|
0
|
|
|
|
|
0
|
|
355
|
|
|
|
|
|
|
|
356
|
0
|
|
|
|
|
0
|
my $tmpdir = tempdir( $self->tmpdirs, |
357
|
|
|
|
|
|
|
DIR => $self->tmpdir, CLEANUP => 1); |
358
|
0
|
|
|
|
|
0
|
my ($tmpfh, $tmpnam) = |
359
|
|
|
|
|
|
|
tempfile( $self->tmpfiles, DIR => $self->tmpdir, |
360
|
|
|
|
|
|
|
SUFFIX => $self->tmpsuffix, UNLINK => 1); |
361
|
0
|
|
|
|
|
0
|
print $tmpfh $key; |
362
|
|
|
|
|
|
|
|
363
|
0
|
|
|
|
|
0
|
my @pret1 = ('--options', '/dev/null', '--homedir', $tmpdir); |
364
|
0
|
|
|
|
|
0
|
my @pret2 = ('--keyring', "$tmpdir/pubring.gpg", |
365
|
|
|
|
|
|
|
'--secret-keyring', "$tmpdir/secring.gpg"); |
366
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
367
|
0
|
|
|
|
|
0
|
my @listopts = qw(--fingerprint --fingerprint --with-colons); |
368
|
|
|
|
|
|
|
|
369
|
0
|
|
|
|
|
0
|
backtick($self->gpgbin, @opts, @pret1, '-v', '--import', $tmpnam); |
370
|
0
|
|
|
|
|
0
|
backtick ($self->gpgbin, @opts, '--marginals-needed', $self->marginals, '--check-trustdb'); |
371
|
0
|
|
|
|
|
0
|
my ($keylist) = backtick($self->gpgbin, @opts, @pret1, '--marginals-needed', |
372
|
|
|
|
|
|
|
$self->marginals, '--check-sigs', @listopts, @keyids); |
373
|
0
|
|
|
|
|
0
|
my ($seclist) = backtick($self->gpgbin, @opts, @pret1, |
374
|
|
|
|
|
|
|
'--list-secret-keys', @listopts); |
375
|
|
|
|
|
|
|
|
376
|
0
|
|
|
|
|
0
|
my @seckeys = grep { my $id = $_->{ID}; |
|
0
|
|
|
|
|
0
|
|
377
|
0
|
0
|
|
|
|
0
|
(grep { $id eq $_ } @keyids) ? $_ : '' } |
|
0
|
|
|
|
|
0
|
|
378
|
|
|
|
|
|
|
$self->parsekeys(split /\n/,$seclist); |
379
|
0
|
|
|
|
|
0
|
my @ret = ($self->parsekeys(split /\n/,$keylist), @seckeys); |
380
|
|
|
|
|
|
|
|
381
|
0
|
0
|
|
|
|
0
|
if ($pretend) { |
382
|
|
|
|
|
|
|
#! This hack needed to get real calc trusts for to-import keys. Test! |
383
|
0
|
|
|
|
|
0
|
backtick ($self->gpgbin, @opts, '--marginals-needed', $self->marginals, '--check-trustdb'); |
384
|
0
|
|
|
|
|
0
|
($keylist) = backtick($self->gpgbin, @opts, @pret2, '--marginals-needed', |
385
|
|
|
|
|
|
|
$self->marginals, '--check-sigs', @listopts); |
386
|
|
|
|
|
|
|
|
387
|
0
|
0
|
|
|
|
0
|
my @realkeylist = grep { my $id = $_->{ID} if $_; |
|
0
|
|
|
|
|
0
|
|
388
|
0
|
0
|
|
|
|
0
|
$id and grep { $id eq $_->{ID} } @ret } |
|
0
|
|
|
|
|
0
|
|
389
|
|
|
|
|
|
|
# map { ($_->{Keyring} eq "$tmpdir/secring.gpg" |
390
|
|
|
|
|
|
|
# or $_->{Keyring} eq "$tmpdir/pubring.gpg") ? $_ : 0 } |
391
|
|
|
|
|
|
|
$self->parsekeys(split /\n/,$keylist); |
392
|
0
|
|
|
|
|
0
|
@ret = (@realkeylist, @seckeys); |
393
|
|
|
|
|
|
|
} |
394
|
|
|
|
|
|
|
else { |
395
|
0
|
0
|
|
|
|
0
|
if (@keyids) { |
396
|
0
|
|
|
|
|
0
|
my ($out) = backtick($self->gpgbin, @opts, @pret1, "--export", '-a', @keyids); |
397
|
0
|
|
|
|
|
0
|
print $tmpfh $out; close $tmpfh; |
|
0
|
|
|
|
|
0
|
|
398
|
|
|
|
|
|
|
} |
399
|
0
|
|
|
|
|
0
|
backtick($self->gpgbin, @opts, '-v', '--import', $tmpnam); |
400
|
|
|
|
|
|
|
} |
401
|
0
|
|
|
|
|
0
|
rmtree($tmpdir, 0, 1); |
402
|
0
|
|
|
|
|
0
|
unlink($tmpnam); |
403
|
0
|
|
|
|
|
0
|
return @ret; |
404
|
|
|
|
|
|
|
} |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
sub export { |
407
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
408
|
0
|
|
|
|
|
0
|
my $key = shift; |
409
|
0
|
|
|
|
|
0
|
my $id = $key->{ID}; |
410
|
0
|
0
|
|
|
|
0
|
return unless $id =~ /$self->{VKEYID}/; |
411
|
|
|
|
|
|
|
|
412
|
0
|
0
|
|
|
|
0
|
my $armor = $self->armor ? '-a' : ''; |
413
|
0
|
0
|
|
|
|
0
|
my $secret = $key->{Type} eq 'sec' ? '-secret-keys' : ''; |
414
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
415
|
0
|
0
|
|
|
|
0
|
push (@opts, ('--comment', $self->comment)) if $self->comment; |
416
|
0
|
|
|
|
|
0
|
push (@opts, '--status-fd', '1'); |
417
|
|
|
|
|
|
|
|
418
|
0
|
|
|
|
|
0
|
my ($out) = backtick($self->gpgbin, @opts, "--export$secret", $armor, $id); |
419
|
0
|
|
|
|
|
0
|
$out; |
420
|
|
|
|
|
|
|
} |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
sub keygen { |
423
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
424
|
0
|
|
|
|
|
0
|
my ($name, $email, $keytype, $keysize, $expire, $pass, $comment) = @_; |
425
|
|
|
|
|
|
|
|
426
|
0
|
0
|
0
|
|
|
0
|
return unless $keysize =~ /$self->{VKEYSZ}/ |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
427
|
|
|
|
|
|
|
and $keysize > 767 and $keysize < 4097 |
428
|
|
|
|
|
|
|
and $pass =~ /$self->{VPASSPHRASE}/ |
429
|
|
|
|
|
|
|
and $keytype =~ /$self->{VKEYTYPE}/ |
430
|
|
|
|
|
|
|
and $expire =~ /$self->{VEXPIRE}/ |
431
|
|
|
|
|
|
|
and $email =~ /$self->{VEMAIL}/ |
432
|
|
|
|
|
|
|
and $name =~ /$self->{VNAME}/ |
433
|
|
|
|
|
|
|
and length ($name) > 4; |
434
|
|
|
|
|
|
|
|
435
|
0
|
0
|
0
|
|
|
0
|
unless (defined ($comment) && $comment =~ /$self->{VCOMMENT}/) { $comment = ''; } |
|
0
|
|
|
|
|
0
|
|
436
|
|
|
|
|
|
|
|
437
|
0
|
|
|
|
|
0
|
my $bigkey = ($keysize > 1536); |
438
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
439
|
0
|
|
|
|
|
0
|
for (0..1) { |
440
|
0
|
|
|
|
|
0
|
backtick ($self->{GPGBIN}, @opts, '--status-fd', '1', '--no-tty', '--gen-random', 0, 1); |
441
|
|
|
|
|
|
|
} |
442
|
|
|
|
|
|
|
|
443
|
0
|
0
|
|
|
|
0
|
if ($self->nofork) { |
444
|
0
|
|
|
|
|
0
|
$self->_exec_gen_key(@_); |
445
|
|
|
|
|
|
|
} |
446
|
|
|
|
|
|
|
else { |
447
|
0
|
|
|
|
|
0
|
my $pid = open(GPG, "-|"); |
448
|
0
|
0
|
|
|
|
0
|
return undef unless (defined $pid); |
449
|
|
|
|
|
|
|
|
450
|
0
|
0
|
|
|
|
0
|
if ($pid) { |
451
|
0
|
|
|
|
|
0
|
$SIG{CHLD} = 'IGNORE'; |
452
|
0
|
|
|
|
|
0
|
return \*GPG; |
453
|
|
|
|
|
|
|
} |
454
|
|
|
|
|
|
|
else { |
455
|
0
|
|
|
|
|
0
|
$self->_exec_gen_key(@_, 'forked'); |
456
|
0
|
|
|
|
|
0
|
CORE::exit(); |
457
|
|
|
|
|
|
|
} |
458
|
|
|
|
|
|
|
} |
459
|
|
|
|
|
|
|
} |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
sub _exec_gen_key { |
462
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
463
|
0
|
|
|
|
|
0
|
my ($name, $email, $keytype, $keysize, $expire, $pass, $comment, $forked) = @_; |
464
|
|
|
|
|
|
|
|
465
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
466
|
0
|
|
|
|
|
0
|
my ($in, $out, $err, $in_q, $out_q, $err_q); |
467
|
0
|
|
|
|
|
0
|
my $h = start ([$self->gpgbin, @opts, '--no-tty', '--status-fd', '1', '--command-fd', 0, |
468
|
|
|
|
|
|
|
'--gen-key'], \$in, \$out, \$err); |
469
|
0
|
0
|
|
|
|
0
|
if ($forked) { |
470
|
0
|
|
|
|
|
0
|
local $SIG{CHLD} = 'IGNORE'; local $SIG{PIPE} = 'IGNORE'; |
|
0
|
|
|
|
|
0
|
|
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
|
473
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /keygen\.algo/g; $in .= "1\n"; |
|
0
|
|
|
|
|
0
|
|
474
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /keygen\.size/g; $in .= "$keysize\n"; |
|
0
|
|
|
|
|
0
|
|
475
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /keygen\.valid/g; $in .= "$expire\n"; |
|
0
|
|
|
|
|
0
|
|
476
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /keygen\.name/g; $in .= "$name\n"; |
|
0
|
|
|
|
|
0
|
|
477
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /keygen\.email/g; $in .= "$email\n"; |
|
0
|
|
|
|
|
0
|
|
478
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /keygen\.comment/g; $in .= "$comment\n"; |
|
0
|
|
|
|
|
0
|
|
479
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /passphrase\.enter/g; $out = ''; $in .= "$pass\n"; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
480
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /(PROGRESS primegen [\+\.\>\<\^]|KEY_CREATED)/g; |
481
|
0
|
|
|
|
|
0
|
$out = ''; my $x = ''; my $y = $1; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
482
|
0
|
|
|
|
|
0
|
while ($y !~ /KEY_CREATED/g) { |
483
|
0
|
0
|
|
|
|
0
|
print "$x\n" if $forked; |
484
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /(PROGRESS primegen [\+\.\>\<\^]|KEY_CREATED)/g; |
485
|
0
|
|
|
|
|
0
|
my $o = $out; $out = ''; $y .= $o; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
486
|
0
|
|
|
|
|
0
|
my @progress = ($o =~ /[\+\.\>\<\^]/g); |
487
|
0
|
|
|
|
|
0
|
$x = join "\n",@progress; |
488
|
|
|
|
|
|
|
} |
489
|
0
|
0
|
|
|
|
0
|
print "|\n" if $forked; |
490
|
0
|
|
|
|
|
0
|
finish $h; |
491
|
|
|
|
|
|
|
} |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
sub keydb { |
494
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
495
|
0
|
0
|
|
|
|
0
|
my @ids = map { return unless /$self->{VKEYID}/; $_ } @_; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
496
|
0
|
|
|
|
|
0
|
my @moreopts = qw(--fingerprint --fingerprint --with-colons); |
497
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
498
|
0
|
|
|
|
|
0
|
backtick ($self->gpgbin, @opts, '--marginals-needed', $self->marginals, '--check-trustdb'); |
499
|
0
|
|
|
|
|
0
|
my ($keylist) = backtick($self->gpgbin, @opts, '--marginals-needed', $self->marginals, |
500
|
|
|
|
|
|
|
'--no-tty', '--check-sigs', @moreopts, @ids); |
501
|
0
|
|
|
|
|
0
|
my ($seclist) = backtick($self->gpgbin, @opts, |
502
|
|
|
|
|
|
|
'--no-tty', '--list-secret-keys', @moreopts, @ids); |
503
|
0
|
|
|
|
|
0
|
my @keylist = split /\n(\s*\n)?/, $keylist; |
504
|
0
|
|
|
|
|
0
|
my @seclist = split /\n(\s*\n)?/, $seclist; |
505
|
0
|
|
|
|
|
0
|
$self->parsekeys (@keylist, @seclist); |
506
|
|
|
|
|
|
|
} |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
sub keyinfo { |
509
|
0
|
|
|
0
|
0
|
0
|
shift->keydb(@_); |
510
|
|
|
|
|
|
|
} |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
sub parsekeys { |
513
|
0
|
|
|
0
|
1
|
0
|
my $self=shift; my @keylist = @_; |
|
0
|
|
|
|
|
0
|
|
514
|
0
|
|
|
|
|
0
|
my @keys; my ($i, $subkey, $subnum, $uidnum) = (-1); |
|
0
|
|
|
|
|
0
|
|
515
|
0
|
|
|
|
|
0
|
my $keyring = ''; |
516
|
0
|
|
|
|
|
0
|
$^W = 0; |
517
|
0
|
|
|
|
|
0
|
foreach (@keylist) { |
518
|
0
|
0
|
|
|
|
0
|
next if /^\-/; |
519
|
0
|
0
|
|
|
|
0
|
next if /^(gpg|tru):/; |
520
|
0
|
0
|
|
|
|
0
|
if (/^\//) { |
521
|
0
|
|
|
|
|
0
|
$keyring = $_; chomp $keyring; |
|
0
|
|
|
|
|
0
|
|
522
|
0
|
|
|
|
|
0
|
next; |
523
|
|
|
|
|
|
|
} |
524
|
0
|
0
|
|
|
|
0
|
if (/^(pub|sec)/) { |
525
|
0
|
|
|
|
|
0
|
$uidnum=-1; $subnum=-1; $subkey=0; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
526
|
0
|
|
|
|
|
0
|
my ($type, $trust, $size, $algorithm, $id, $created, |
527
|
|
|
|
|
|
|
$expires, $u2, $ownertrust, $uid) = split (':'); |
528
|
0
|
|
|
|
|
0
|
$keys[++$i] = { |
529
|
|
|
|
|
|
|
Keyring => $keyring, |
530
|
|
|
|
|
|
|
Type => $type, |
531
|
|
|
|
|
|
|
Ownertrust => $ownertrust, |
532
|
|
|
|
|
|
|
Bits => $size, |
533
|
|
|
|
|
|
|
ID => $id, |
534
|
|
|
|
|
|
|
Created => $created, |
535
|
|
|
|
|
|
|
Expires => $expires, |
536
|
|
|
|
|
|
|
Algorithm => $algorithm, |
537
|
|
|
|
|
|
|
Use => '' |
538
|
|
|
|
|
|
|
}; |
539
|
0
|
0
|
|
|
|
0
|
push (@{$keys[$i]->{UIDs}}, { 'UID' => $uid, 'Calctrust' => $trust }), |
|
0
|
|
|
|
|
0
|
|
540
|
|
|
|
|
|
|
$uidnum++ if $uid; |
541
|
|
|
|
|
|
|
} |
542
|
|
|
|
|
|
|
else { |
543
|
0
|
0
|
|
|
|
0
|
if (/^fpr:::::::::([^:]+):/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
544
|
0
|
|
|
|
|
0
|
my $fingerprint = $1; my $l = length $fingerprint; |
|
0
|
|
|
|
|
0
|
|
545
|
0
|
0
|
|
|
|
0
|
if ($l == 32) { |
|
|
0
|
|
|
|
|
|
546
|
0
|
|
|
|
|
0
|
my @f = $fingerprint =~ /(..)/g; |
547
|
0
|
|
|
|
|
0
|
$fingerprint = (join ' ', @f[0..7]) . ' ' . |
548
|
|
|
|
|
|
|
(join ' ', @f[8..15]); |
549
|
|
|
|
|
|
|
} |
550
|
|
|
|
|
|
|
elsif ($l == 40) { |
551
|
0
|
|
|
|
|
0
|
my @f = $fingerprint =~ /(....)/g; |
552
|
0
|
|
|
|
|
0
|
$fingerprint = (join ' ', @f[0..4]) . ' ' . |
553
|
|
|
|
|
|
|
(join ' ', @f[5..9]); |
554
|
|
|
|
|
|
|
} |
555
|
|
|
|
|
|
|
$subkey ? |
556
|
0
|
0
|
|
|
|
0
|
$keys[$i]->{Subkeys}->[$subnum]->{Fingerprint} : |
557
|
|
|
|
|
|
|
$keys[$i]->{Fingerprint} = $fingerprint; |
558
|
|
|
|
|
|
|
} |
559
|
|
|
|
|
|
|
elsif (/^sub/) { |
560
|
0
|
|
|
|
|
0
|
$subnum++; $subkey = 1; |
|
0
|
|
|
|
|
0
|
|
561
|
0
|
|
|
|
|
0
|
my ($type, $u1, $size, $algorithm, $id, |
562
|
|
|
|
|
|
|
$created, $expires) = split (':'); |
563
|
0
|
|
|
|
|
0
|
$keys[$i]->{Subkeys}->[$subnum] = |
564
|
|
|
|
|
|
|
{ |
565
|
|
|
|
|
|
|
Bits => $size, |
566
|
|
|
|
|
|
|
ID => $id, |
567
|
|
|
|
|
|
|
Created => $created, |
568
|
|
|
|
|
|
|
Expires => $expires, |
569
|
|
|
|
|
|
|
Algorithm => $algorithm |
570
|
|
|
|
|
|
|
}; |
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
elsif (/^sig/) { |
573
|
0
|
|
|
|
|
0
|
my ($sig, $valid, $u2, $u3, $id, $date, |
574
|
|
|
|
|
|
|
$u4, $u5, $u6, $uid) = split (':'); |
575
|
0
|
0
|
|
|
|
0
|
my ($pushto, $pushnum) = $subkey ? |
576
|
|
|
|
|
|
|
('Subkeys',$subnum) : ('UIDs',$uidnum); |
577
|
0
|
|
|
|
|
0
|
push (@{$keys[$i]->{$pushto}->[$pushnum]->{Signatures}}, |
|
0
|
|
|
|
|
0
|
|
578
|
|
|
|
|
|
|
{ ID => $id, |
579
|
|
|
|
|
|
|
Date => $date, |
580
|
|
|
|
|
|
|
UID => $uid, |
581
|
|
|
|
|
|
|
Valid => $valid |
582
|
|
|
|
|
|
|
} ); |
583
|
|
|
|
|
|
|
} |
584
|
|
|
|
|
|
|
elsif (/^uid:(.?):.*:([^:]+):$/) { |
585
|
0
|
|
|
|
|
0
|
$subkey = 0; $uidnum++; |
|
0
|
|
|
|
|
0
|
|
586
|
0
|
|
|
|
|
0
|
push (@{$keys[$i]->{UIDs}}, { UID => $2, Calctrust => $1 }); |
|
0
|
|
|
|
|
0
|
|
587
|
|
|
|
|
|
|
} |
588
|
|
|
|
|
|
|
} |
589
|
|
|
|
|
|
|
} |
590
|
0
|
|
|
|
|
0
|
$^W = 1; |
591
|
0
|
|
|
|
|
0
|
return map {bless $_, 'Crypt::GPG::Key'} @keys; |
|
0
|
|
|
|
|
0
|
|
592
|
|
|
|
|
|
|
} |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
sub keypass { |
595
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
596
|
|
|
|
|
|
|
|
597
|
0
|
|
|
|
|
0
|
my ($key, $oldpass, $newpass) = @_; |
598
|
0
|
0
|
0
|
|
|
0
|
return unless $oldpass =~ /$self->{VPASSPHRASE}/ |
|
|
|
0
|
|
|
|
|
599
|
|
|
|
|
|
|
and $newpass =~ /$self->{VPASSPHRASE}/ |
600
|
|
|
|
|
|
|
and $key->{Type} eq 'sec'; |
601
|
|
|
|
|
|
|
|
602
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
603
|
|
|
|
|
|
|
|
604
|
0
|
|
|
|
|
0
|
my ($in, $out, $err, $in_q, $out_q, $err_q); |
605
|
0
|
|
|
|
|
0
|
my $h = start ([$self->gpgbin, @opts, '--no-tty', '--status-fd', '1', '--command-fd', 0, |
606
|
|
|
|
|
|
|
'--edit-key', $key->{ID}], \$in, \$out, \$err, timeout( 30 )); |
607
|
0
|
|
|
|
|
0
|
local $SIG{CHLD} = 'IGNORE'; local $SIG{PIPE} = 'IGNORE'; |
|
0
|
|
|
|
|
0
|
|
608
|
|
|
|
|
|
|
|
609
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /keyedit\.prompt/g; $in .= "passwd\n"; |
|
0
|
|
|
|
|
0
|
|
610
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /GOOD_PASSPHRASE/g |
611
|
|
|
|
|
|
|
or $out =~ /(passphrase\.enter)/g); |
612
|
|
|
|
|
|
|
|
613
|
0
|
0
|
|
|
|
0
|
unless ($1) { |
614
|
0
|
0
|
|
|
|
0
|
finish $h, return if $oldpass; |
615
|
|
|
|
|
|
|
} |
616
|
|
|
|
|
|
|
else { |
617
|
0
|
|
|
|
|
0
|
$^W = 0; /()/; $^W = 1; $out = ''; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
618
|
0
|
|
|
|
|
0
|
$in .= "$oldpass\n"; |
619
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /BAD_PASSPHRASE/g #! Test |
620
|
|
|
|
|
|
|
or $out =~ /(passphrase\.enter)/g); |
621
|
0
|
0
|
|
|
|
0
|
unless ($1) { |
622
|
0
|
|
|
|
|
0
|
finish $h; |
623
|
0
|
|
|
|
|
0
|
return; |
624
|
|
|
|
|
|
|
} |
625
|
|
|
|
|
|
|
} |
626
|
0
|
|
|
|
|
0
|
$^W = 0; /()/; $^W = 1; $out = ''; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
627
|
0
|
|
|
|
|
0
|
$in .= "$newpass\n"; |
628
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /change_passwd\.empty\.okay/g |
629
|
|
|
|
|
|
|
or $out =~ /(keyedit\.prompt)/g); |
630
|
0
|
0
|
|
|
|
0
|
unless ($1) { |
631
|
0
|
|
|
|
|
0
|
$in .= "Y\n"; |
632
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /keyedit\.prompt/g; |
633
|
|
|
|
|
|
|
} |
634
|
0
|
|
|
|
|
0
|
$in .= "quit\n"; |
635
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /keyedit\.save\.okay/g; |
636
|
0
|
|
|
|
|
0
|
$in .= "Y\n"; |
637
|
0
|
|
|
|
|
0
|
finish $h; |
638
|
0
|
|
|
|
|
0
|
return 1; |
639
|
|
|
|
|
|
|
} |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
sub keytrust { |
642
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
643
|
0
|
|
|
|
|
0
|
my ($key, $trustlevel) = @_; |
644
|
0
|
0
|
|
|
|
0
|
return unless $trustlevel =~ /$self->{VTRUSTLEVEL}/; |
645
|
|
|
|
|
|
|
|
646
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
647
|
|
|
|
|
|
|
|
648
|
0
|
|
|
|
|
0
|
my ($in, $out, $err, $in_q, $out_q, $err_q); |
649
|
0
|
|
|
|
|
0
|
my $h = start ([$self->gpgbin, @opts, '--no-tty', |
650
|
|
|
|
|
|
|
'--status-fd', '1', '--command-fd', 0, |
651
|
|
|
|
|
|
|
'--edit-key', $key->{ID}], |
652
|
|
|
|
|
|
|
\$in, \$out, \$err, timeout( 30 )); |
653
|
0
|
|
|
|
|
0
|
local $SIG{CHLD} = 'IGNORE'; local $SIG{PIPE} = 'IGNORE'; |
|
0
|
|
|
|
|
0
|
|
654
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /keyedit\.prompt/g; $in .= "trust\n"; |
|
0
|
|
|
|
|
0
|
|
655
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /edit_ownertrust\.value/g; $in .= "$trustlevel\n"; |
|
0
|
|
|
|
|
0
|
|
656
|
0
|
0
|
|
|
|
0
|
if ($trustlevel == 5) { |
657
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /edit_ownertrust\.set_ultimate\.okay/g; $in .= "Y\n"; |
|
0
|
|
|
|
|
0
|
|
658
|
|
|
|
|
|
|
} |
659
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /keyedit\.prompt/g; $in .= "quit\n"; |
|
0
|
|
|
|
|
0
|
|
660
|
0
|
|
|
|
|
0
|
finish $h; |
661
|
0
|
|
|
|
|
0
|
return 1; |
662
|
|
|
|
|
|
|
} |
663
|
|
|
|
|
|
|
|
664
|
0
|
|
|
0
|
0
|
0
|
sub keyprimary { |
665
|
|
|
|
|
|
|
} |
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
sub certify { |
668
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
669
|
0
|
|
|
|
|
0
|
my ($key, $local, $class, @uids) = @_; |
670
|
|
|
|
|
|
|
|
671
|
0
|
0
|
0
|
|
|
0
|
return unless (!$self->secretkey or $self->secretkey =~ /$self->{VKEYID}/) |
|
|
|
0
|
|
|
|
|
672
|
|
|
|
|
|
|
and $self->passphrase =~ /$self->{VPASSPHRASE}/; |
673
|
|
|
|
|
|
|
|
674
|
0
|
0
|
0
|
|
|
0
|
return unless @uids and !grep { $_ =~ /\D/; } @uids; |
|
0
|
|
|
|
|
0
|
|
675
|
0
|
|
|
|
|
0
|
my $i = 0; my $ret = 0; |
|
0
|
|
|
|
|
0
|
|
676
|
|
|
|
|
|
|
|
677
|
0
|
|
|
|
|
0
|
($key) = $self->keydb($key); |
678
|
0
|
|
|
|
|
0
|
my $signingkey = ($self->keydb($self->secretkey))[0]->{ID}; |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
# Check if already signed. |
681
|
0
|
|
|
|
|
0
|
return 1 unless grep { !grep { $signingkey eq $_->{ID} } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
682
|
0
|
|
|
|
|
0
|
@{$_->{Signatures}} } |
683
|
0
|
0
|
|
|
|
0
|
(@{$key->{UIDs}})[@uids]; |
684
|
|
|
|
|
|
|
|
685
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
686
|
0
|
0
|
|
|
|
0
|
push (@opts, '--default-key', $self->secretkey) if $self->secretkey;; |
687
|
|
|
|
|
|
|
|
688
|
0
|
|
|
|
|
0
|
my ($in, $out, $err, $in_q, $out_q, $err_q); |
689
|
|
|
|
|
|
|
|
690
|
0
|
|
|
|
|
0
|
my $h = start ([$self->gpgbin, @opts, '--status-fd', '1', '--command-fd', 0, '--no-tty', |
691
|
|
|
|
|
|
|
'--edit-key', $key->{ID}], \$in, \$out, \$err, timeout( 30 )); |
692
|
0
|
|
|
|
|
0
|
local $SIG{CHLD} = 'IGNORE'; local $SIG{PIPE} = 'IGNORE'; |
|
0
|
|
|
|
|
0
|
|
693
|
|
|
|
|
|
|
|
694
|
0
|
|
|
|
|
0
|
for (@uids) { |
695
|
0
|
|
|
|
|
0
|
my $uid = $_+1; |
696
|
0
|
|
|
|
|
0
|
pump $h until ($out =~ /keyedit\.prompt/g); |
697
|
0
|
|
|
|
|
0
|
$in .= "uid $uid\n"; |
698
|
|
|
|
|
|
|
} |
699
|
0
|
|
|
|
|
0
|
pump $h until ($out =~ /keyedit\.prompt/g); |
700
|
0
|
|
|
|
|
0
|
$out = ''; |
701
|
0
|
0
|
|
|
|
0
|
$in .= $local ? "lsign\n" : "sign\n"; |
702
|
|
|
|
|
|
|
|
703
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /sign_uid\.okay/g |
|
|
|
0
|
|
|
|
|
704
|
|
|
|
|
|
|
or $out =~ /(s)ign_uid\.class/g |
705
|
|
|
|
|
|
|
or $out =~ /(s)(i)gn_uid\.expire/g); |
706
|
|
|
|
|
|
|
|
707
|
0
|
0
|
|
|
|
0
|
if ($2) { |
708
|
0
|
|
|
|
|
0
|
$out = ''; $in .= "0\n"; |
|
0
|
|
|
|
|
0
|
|
709
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /sign_uid\.okay/g |
|
|
|
0
|
|
|
|
|
710
|
|
|
|
|
|
|
or $out =~ /(s)ign_uid\.class/g |
711
|
|
|
|
|
|
|
or $out =~ /passphrase\.enter/g); |
712
|
|
|
|
|
|
|
} |
713
|
|
|
|
|
|
|
|
714
|
0
|
0
|
|
|
|
0
|
if ($1) { |
715
|
0
|
|
|
|
|
0
|
$out = ''; $in .= "$class\n"; |
|
0
|
|
|
|
|
0
|
|
716
|
0
|
|
|
|
|
0
|
pump $h until ($out =~ /sign_uid\.okay/g); |
717
|
|
|
|
|
|
|
} |
718
|
|
|
|
|
|
|
|
719
|
0
|
|
|
|
|
0
|
$^W = 0; /()/; $^W = 1; $out = ''; $in .= "Y\n"; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
720
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /passphrase\.enter/g |
721
|
|
|
|
|
|
|
or $out =~ /(keyedit.prompt)/g); |
722
|
0
|
|
|
|
|
0
|
$ret=1; |
723
|
0
|
0
|
|
|
|
0
|
unless ($1) { |
724
|
0
|
|
|
|
|
0
|
$out = ''; $^W = 0; /()/; $^W = 1; $in .= $self->passphrase . "\n"; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
725
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /keyedit\.prompt/g |
726
|
|
|
|
|
|
|
or $out =~ /(BAD_PASSPHRASE)/g); |
727
|
0
|
0
|
|
|
|
0
|
$ret=0 if $1; |
728
|
|
|
|
|
|
|
} |
729
|
|
|
|
|
|
|
|
730
|
0
|
|
|
|
|
0
|
$in .= "quit\n"; |
731
|
0
|
0
|
|
|
|
0
|
if ($ret) { |
732
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /save\.okay/g or $out =~ /(k)eyedit\.prompt/g); |
733
|
0
|
|
|
|
|
0
|
$in .= "Y\n"; |
734
|
|
|
|
|
|
|
} |
735
|
0
|
|
|
|
|
0
|
finish $h; |
736
|
0
|
|
|
|
|
0
|
$ret; |
737
|
|
|
|
|
|
|
} |
738
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
sub delkey { |
740
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
741
|
0
|
|
|
|
|
0
|
my $key = shift; |
742
|
0
|
0
|
|
|
|
0
|
return unless $key->{ID} =~ /$self->{VKEYID}/; |
743
|
|
|
|
|
|
|
|
744
|
0
|
0
|
|
|
|
0
|
my $del = $key->{Type} eq 'sec' ? |
745
|
|
|
|
|
|
|
'--delete-secret-and-public-key':'--delete-key'; |
746
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
747
|
|
|
|
|
|
|
|
748
|
0
|
|
|
|
|
0
|
my ($in, $out, $err, $in_q, $out_q, $err_q); |
749
|
0
|
|
|
|
|
0
|
my $h = start ([$self->gpgbin, @opts, '--no-tty', '--status-fd', '1', '--command-fd', 0, |
750
|
|
|
|
|
|
|
$del, $key->{ID}], \$in, \$out, \$err, timeout( 30 )); |
751
|
0
|
|
|
|
|
0
|
local $SIG{CHLD} = 'IGNORE'; local $SIG{PIPE} = 'IGNORE'; |
|
0
|
|
|
|
|
0
|
|
752
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /delete it first\./g or $out =~ /(delete_key)(.secret)?.okay/g); |
753
|
|
|
|
|
|
|
#! ^^^^^^^^^^^^^^^^^ to-fix. |
754
|
0
|
0
|
|
|
|
0
|
finish $h, return undef unless $1; |
755
|
0
|
|
|
|
|
0
|
$in .= "Y\n"; |
756
|
0
|
0
|
|
|
|
0
|
if ($key->{Type} eq 'sec') { |
757
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /delete_key.okay/g; $in .= "Y\n"; |
|
0
|
|
|
|
|
0
|
|
758
|
|
|
|
|
|
|
} |
759
|
0
|
|
|
|
|
0
|
finish $h; |
760
|
0
|
|
|
|
|
0
|
return 1; |
761
|
|
|
|
|
|
|
} |
762
|
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
sub disablekey { |
764
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
765
|
0
|
|
|
|
|
0
|
my $key = shift; |
766
|
0
|
0
|
|
|
|
0
|
return unless $key->{ID} =~ /$self->{VKEYID}/; |
767
|
|
|
|
|
|
|
|
768
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
769
|
|
|
|
|
|
|
|
770
|
0
|
|
|
|
|
0
|
my ($in, $out, $err, $in_q, $out_q, $err_q); |
771
|
0
|
|
|
|
|
0
|
my $h = start ([$self->gpgbin, @opts, '--no-tty', '--status-fd', '1', '--command-fd', 0, |
772
|
|
|
|
|
|
|
'--edit-key', $key->{ID}], \$in, \$out, \$err, timeout( 30 )); |
773
|
0
|
|
|
|
|
0
|
local $SIG{CHLD} = 'IGNORE'; local $SIG{PIPE} = 'IGNORE'; |
|
0
|
|
|
|
|
0
|
|
774
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /been disabled/g or $out =~ /(keyedit\.prompt)/g); |
775
|
|
|
|
|
|
|
#! ^^^^^^^^^^^^^ to-fix. |
776
|
0
|
0
|
|
|
|
0
|
finish $h, return undef unless $1; |
777
|
0
|
|
|
|
|
0
|
$in .= "disable\n"; |
778
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /keyedit\.prompt/g; $in .= "quit\n"; |
|
0
|
|
|
|
|
0
|
|
779
|
0
|
|
|
|
|
0
|
finish $h; |
780
|
0
|
|
|
|
|
0
|
return 1; |
781
|
|
|
|
|
|
|
} |
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
sub enablekey { |
784
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
785
|
0
|
|
|
|
|
0
|
my $key = shift; |
786
|
0
|
0
|
|
|
|
0
|
return unless $key->{ID} =~ /$self->{VKEYID}/; |
787
|
|
|
|
|
|
|
|
788
|
0
|
|
|
|
|
0
|
my @opts = (split (/\s+/, "$self->{FORCEDOPTS} $self->{GPGOPTS}")); |
789
|
|
|
|
|
|
|
|
790
|
0
|
|
|
|
|
0
|
my ($in, $out, $err, $in_q, $out_q, $err_q); |
791
|
0
|
|
|
|
|
0
|
my $h = start ([$self->gpgbin, @opts, '--no-tty', '--status-fd', '1', '--command-fd', 0, |
792
|
|
|
|
|
|
|
'--edit-key', $key->{ID}], \$in, \$out, \$err, timeout( 30 )); |
793
|
0
|
|
|
|
|
0
|
local $SIG{CHLD} = 'IGNORE'; local $SIG{PIPE} = 'IGNORE'; |
|
0
|
|
|
|
|
0
|
|
794
|
0
|
|
0
|
|
|
0
|
pump $h until ($out =~ /been disabled/g or $out =~ /(keyedit\.prompt)/g); |
795
|
|
|
|
|
|
|
#! ^^^^^^^^^^^^^ to-fix. |
796
|
0
|
0
|
|
|
|
0
|
finish $h, return undef unless $1; |
797
|
0
|
|
|
|
|
0
|
$in .= "enable\n"; |
798
|
0
|
|
|
|
|
0
|
pump $h until $out =~ /keyedit\.prompt/g; $in .= "quit\n"; |
|
0
|
|
|
|
|
0
|
|
799
|
0
|
|
|
|
|
0
|
finish $h; |
800
|
0
|
|
|
|
|
0
|
return 1; |
801
|
|
|
|
|
|
|
} |
802
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
sub backtick { |
804
|
0
|
|
|
0
|
0
|
0
|
my ($in, $out, $err, $in_q, $out_q, $err_q); |
805
|
0
|
|
|
|
|
0
|
my $h = start ([@_], \$in, \$out, \$err, timeout( 10 )); |
806
|
0
|
|
|
|
|
0
|
local $SIG{CHLD} = 'IGNORE'; |
807
|
0
|
|
|
|
|
0
|
local $SIG{PIPE} = 'IGNORE'; |
808
|
0
|
|
|
|
|
0
|
finish $h; |
809
|
0
|
|
|
|
|
0
|
return ($out, $err); |
810
|
|
|
|
|
|
|
} |
811
|
|
|
|
|
|
|
|
812
|
|
|
|
|
|
|
sub debug { |
813
|
6
|
|
|
6
|
1
|
37
|
my $self = shift; |
814
|
6
|
50
|
|
|
|
32
|
return $self->{DEBUG} unless defined $_[0]; |
815
|
6
|
0
|
|
|
|
41
|
unless ($_[0] == $self->{DEBUG}) { $ENV{IPCRUNDEBUG} = $_[0] ? 'data' : ''; } |
|
0
|
50
|
|
|
|
0
|
|
816
|
6
|
|
|
|
|
22
|
$self->{DEBUG} = $_[0]; |
817
|
|
|
|
|
|
|
} |
818
|
|
|
|
|
|
|
|
819
|
|
|
|
|
|
|
sub AUTOLOAD { |
820
|
32
|
|
|
32
|
|
11657
|
my $self = shift; (my $auto = $AUTOLOAD) =~ s/.*:://; |
|
32
|
|
|
|
|
170
|
|
821
|
32
|
50
|
|
|
|
156
|
if ($auto =~ /^(passphrase|secretkey|armor|gpgbin|gpgopts|delay|marginals| |
|
|
0
|
|
|
|
|
|
822
|
|
|
|
|
|
|
detach|clearsign|encryptsafe|version|comment|tmpdir|tmpdirs| |
823
|
|
|
|
|
|
|
tmpfiles|tmpsuffix|nofork)$/x) { |
824
|
32
|
100
|
|
|
|
338
|
return $self->{"\U$auto"} unless defined $_[0]; |
825
|
20
|
|
|
|
|
75
|
$self->{"\U$auto"} = shift; |
826
|
|
|
|
|
|
|
} |
827
|
|
|
|
|
|
|
elsif ($auto eq 'DESTROY') { |
828
|
|
|
|
|
|
|
} |
829
|
|
|
|
|
|
|
else { |
830
|
0
|
|
|
|
|
|
croak "Could not AUTOLOAD method $auto."; |
831
|
|
|
|
|
|
|
} |
832
|
|
|
|
|
|
|
} |
833
|
|
|
|
|
|
|
|
834
|
|
|
|
|
|
|
package Crypt::GPG::Signature; |
835
|
6
|
|
|
6
|
|
104
|
use vars qw( $AUTOLOAD ); |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
610
|
|
836
|
6
|
|
|
6
|
|
41
|
use Carp; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
1601
|
|
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
sub AUTOLOAD { |
839
|
0
|
|
|
0
|
|
|
my $self = shift; (my $auto = $AUTOLOAD) =~ s/.*:://; |
|
0
|
|
|
|
|
|
|
840
|
0
|
0
|
|
|
|
|
if ($auto =~ /^(validity|keyid|time|trusted)$/) { |
|
|
0
|
|
|
|
|
|
841
|
0
|
0
|
|
|
|
|
return $self->{"KeyID"} if ( $auto eq "keyid" ); |
842
|
0
|
|
|
|
|
|
return $self->{"\u$auto"}; |
843
|
|
|
|
|
|
|
} |
844
|
|
|
|
|
|
|
elsif ($auto eq 'DESTROY') { |
845
|
|
|
|
|
|
|
} |
846
|
|
|
|
|
|
|
else { |
847
|
0
|
|
|
|
|
|
croak "Could not AUTOLOAD method $auto."; |
848
|
|
|
|
|
|
|
} |
849
|
|
|
|
|
|
|
} |
850
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
'True Value'; |
852
|
|
|
|
|
|
|
__END__ |