line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Keyczar::Tool; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
678
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
432
|
use Crypt::Keyczar::Crypter; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
46
|
|
6
|
1
|
|
|
1
|
|
5
|
use Crypt::Keyczar::FileReader; |
|
1
|
|
|
|
|
31
|
|
|
1
|
|
|
|
|
30
|
|
7
|
1
|
|
|
1
|
|
5
|
use Crypt::Keyczar::KeyMetadata; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
8
|
1
|
|
|
1
|
|
644
|
use Crypt::Keyczar::Manager; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
9
|
1
|
|
|
1
|
|
558
|
use Crypt::Keyczar::Signer; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
52
|
|
10
|
1
|
|
|
1
|
|
6
|
use Crypt::Keyczar::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
11
|
1
|
|
|
1
|
|
6
|
use Crypt::Keyczar::FileWriter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
12
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1412
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
1
|
|
|
1
|
0
|
3
|
my $class = shift; |
17
|
1
|
|
|
|
|
2
|
my $writer = shift; |
18
|
1
|
|
33
|
|
|
5
|
$writer ||= Crypt::Keyczar::FileWriter->new(); |
19
|
1
|
|
|
|
|
5
|
return bless { writer => $writer }, $class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
143
|
|
|
143
|
0
|
773
|
sub writer { return $_[0]->{writer} } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub create { |
27
|
6
|
|
|
6
|
0
|
12170
|
my $self = shift; |
28
|
6
|
|
|
|
|
20
|
my ($location, $purpose, $opt) = @_; |
29
|
|
|
|
|
|
|
|
30
|
6
|
|
|
|
|
12
|
my $meta; |
31
|
6
|
100
|
|
|
|
33
|
if ($purpose eq 'sign') { |
|
|
50
|
|
|
|
|
|
32
|
4
|
100
|
66
|
|
|
49
|
if (!defined $opt->{asymmetric} && !defined $opt->{type}) { |
|
|
50
|
33
|
|
|
|
|
|
|
100
|
|
|
|
|
|
33
|
2
|
|
|
|
|
27
|
$meta = Crypt::Keyczar::KeyMetadata->new($opt->{name}, 'SIGN_AND_VERIFY', 'HMAC_SHA1'); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
elsif (!defined $opt->{asymmetric} && defined $opt->{type}) { |
36
|
0
|
|
|
|
|
0
|
$meta = Crypt::Keyczar::KeyMetadata->new($opt->{name}, 'SIGN_AND_VERIFY', $opt->{type}); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif (uc $opt->{asymmetric} eq 'RSA') { |
39
|
1
|
|
|
|
|
13
|
$meta = Crypt::Keyczar::KeyMetadata->new($opt->{name}, 'SIGN_AND_VERIFY', 'RSA_PRIV'); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
1
|
|
|
|
|
13
|
$meta = Crypt::Keyczar::KeyMetadata->new($opt->{name}, 'SIGN_AND_VERIFY', 'DSA_PRIV'); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif ($purpose eq 'crypt') { |
46
|
2
|
100
|
|
|
|
9
|
if (defined $opt->{asymmetric}) { |
47
|
1
|
|
|
|
|
11
|
$meta = Crypt::Keyczar::KeyMetadata->new($opt->{name}, 'DECRYPT_AND_ENCRYPT', 'RSA_PRIV'); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
1
|
|
|
|
|
15
|
$meta = Crypt::Keyczar::KeyMetadata->new($opt->{name}, 'DECRYPT_AND_ENCRYPT', 'AES'); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
0
|
croak 'unknonw purpose'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
6
|
|
|
|
|
29
|
$self->writer->location($location); |
58
|
6
|
|
|
|
|
18
|
$self->writer->put_metadata($meta); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub addkey { |
63
|
17
|
|
|
17
|
0
|
31431
|
my $self = shift; |
64
|
17
|
|
|
|
|
47
|
my ($location, $status, $opt) = @_; |
65
|
|
|
|
|
|
|
|
66
|
17
|
|
|
|
|
266
|
my $kcz = Crypt::Keyczar::Manager->new($location); |
67
|
17
|
|
|
|
|
121
|
my $v = $kcz->add_version($status, $opt->{size}); |
68
|
|
|
|
|
|
|
|
69
|
17
|
|
|
|
|
81
|
$self->writer->location($location); |
70
|
17
|
|
|
|
|
48
|
$self->writer->put_metadata($kcz->metadata); |
71
|
17
|
|
|
|
|
177
|
$self->writer->put_key($v->get_number, $kcz->get_key($v)); |
72
|
17
|
|
|
|
|
115
|
return $v->get_number; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub promote { |
77
|
13
|
|
|
13
|
0
|
10561
|
my $self = shift; |
78
|
13
|
|
|
|
|
35
|
my ($location, $version) = @_; |
79
|
13
|
|
|
|
|
107
|
my $kcz = Crypt::Keyczar::Manager->new($location); |
80
|
13
|
|
|
|
|
80
|
$kcz->promote($version); |
81
|
13
|
|
|
|
|
59
|
$self->writer->location($location); |
82
|
13
|
|
|
|
|
36
|
$self->writer->put_metadata($kcz->metadata); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub demote { |
87
|
17
|
|
|
17
|
0
|
12592
|
my $self = shift; |
88
|
17
|
|
|
|
|
42
|
my ($location, $version) = @_; |
89
|
17
|
|
|
|
|
369
|
my $kcz = Crypt::Keyczar::Manager->new($location); |
90
|
17
|
|
|
|
|
94
|
$kcz->demote($version); |
91
|
12
|
|
|
|
|
103
|
$self->writer->location($location); |
92
|
12
|
|
|
|
|
38
|
$self->writer->put_metadata($kcz->metadata); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub revoke { |
97
|
11
|
|
|
11
|
0
|
10231
|
my $self = shift; |
98
|
11
|
|
|
|
|
29
|
my ($location, $version) = @_; |
99
|
11
|
|
|
|
|
90
|
my $kcz = Crypt::Keyczar::Manager->new($location); |
100
|
11
|
|
|
|
|
62
|
$kcz->revoke($version); |
101
|
6
|
|
|
|
|
24
|
$self->writer->location($location); |
102
|
6
|
|
|
|
|
16
|
$self->writer->put_metadata($kcz->metadata); |
103
|
6
|
50
|
|
|
|
43
|
if (!$self->writer->delete_key($version)) { |
104
|
0
|
|
|
|
|
0
|
croak "can't delete revoked key file: $location/$version: $!"; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub pubkey { |
110
|
3
|
|
|
3
|
0
|
2513
|
my $self = shift; |
111
|
3
|
|
|
|
|
7
|
my ($location, $destination) = @_; |
112
|
3
|
|
|
|
|
26
|
my $kcz = Crypt::Keyczar::Manager->new($location); |
113
|
3
|
|
|
|
|
14
|
my $private = $kcz->metadata; |
114
|
|
|
|
|
|
|
|
115
|
3
|
|
|
|
|
6
|
my $public; |
116
|
3
|
100
|
|
|
|
10
|
if ($private->get_type eq 'RSA_PRIV') { |
|
|
50
|
|
|
|
|
|
117
|
2
|
100
|
|
|
|
10
|
if ($private->get_purpose eq 'DECRYPT_AND_ENCRYPT') { |
|
|
50
|
|
|
|
|
|
118
|
1
|
|
|
|
|
5
|
$public = Crypt::Keyczar::KeyMetadata->new($private->get_name, 'ENCRYPT', 'RSA_PUB'); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
elsif ($private->get_purpose eq 'SIGN_AND_VERIFY') { |
121
|
1
|
|
|
|
|
7
|
$public = Crypt::Keyczar::KeyMetadata->new($private->get_name, 'VERIFY', 'RSA_PUB'); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
else { |
124
|
0
|
|
|
|
|
0
|
croak("unknown propose: ". $private->get_purpose); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
elsif ($private->get_type eq 'DSA_PRIV') { |
128
|
1
|
50
|
|
|
|
4
|
if ($private->get_purpose eq 'SIGN_AND_VERIFY') { |
129
|
1
|
|
|
|
|
4
|
$public = Crypt::Keyczar::KeyMetadata->new($private->get_name, 'VERIFY', 'DSA_PUB'); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
else { |
132
|
0
|
|
|
|
|
0
|
croak("unknown propose: ". $private->get_purpose); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
else { |
136
|
0
|
|
|
|
|
0
|
croak("not implement"); |
137
|
|
|
|
|
|
|
} |
138
|
3
|
50
|
|
|
|
30
|
if (!$public) { |
139
|
0
|
|
|
|
|
0
|
croak("cannot export public key"); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
3
|
|
|
|
|
13
|
$self->writer->location($destination); |
143
|
3
|
|
|
|
|
13
|
for my $v ($private->get_versions) { |
144
|
9
|
100
|
|
|
|
22
|
if ($v) { |
145
|
6
|
|
|
|
|
23
|
my $p = $kcz->get_key($v)->get_public; |
146
|
6
|
|
|
|
|
20
|
$self->writer->put_key($v->get_number, $p); |
147
|
|
|
|
|
|
|
} |
148
|
9
|
|
|
|
|
48
|
$public->add_version($v); |
149
|
|
|
|
|
|
|
} |
150
|
3
|
|
|
|
|
12
|
$self->writer->put_metadata($public); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub usekey { |
155
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
156
|
0
|
|
|
|
|
|
my ($location, $message, $destination, $opt) = @_; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
my $reader = Crypt::Keyczar::FileReader->new($location); |
159
|
0
|
|
|
|
|
|
my $meta = Crypt::Keyczar::KeyMetadata->read($reader->get_metadata()); |
160
|
0
|
|
|
|
|
|
my $result = ''; |
161
|
0
|
0
|
|
|
|
|
if ($meta->get_purpose eq 'DECRYPT_AND_ENCRYPT') { |
|
|
0
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
my $crypter = Crypt::Keyczar::Crypter->new($reader); |
163
|
0
|
|
|
|
|
|
$result = $crypter->encrypt($message); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
elsif ($meta->get_purpose eq 'SIGN_AND_VERIFY') { |
166
|
0
|
|
|
|
|
|
my $signer = Crypt::Keyczar::Signer->new($reader); |
167
|
0
|
|
|
|
|
|
$result = $signer->sign($message); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
else { |
170
|
0
|
|
|
|
|
|
croak "unsupported purpose: ". $meta->get_purpose; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
0
|
0
|
|
|
|
|
if ($destination) { |
174
|
0
|
0
|
|
|
|
|
open my $fh, '>', $destination |
175
|
|
|
|
|
|
|
or croak "cannot open destination file: $destination: $!"; |
176
|
0
|
|
|
|
|
|
print $fh Crypt::Keyczar::Util::encode($result); |
177
|
0
|
|
|
|
|
|
close $fh; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
else { |
180
|
0
|
|
|
|
|
|
print Crypt::Keyczar::Util::encode($result), "\n"; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |
185
|
|
|
|
|
|
|
__END__ |