line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Convert::SSH2::Format::PKCS8; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1060
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
extends 'Convert::SSH2::Format::Base'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
368
|
use Carp qw(confess); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
71
|
|
9
|
1
|
|
|
1
|
|
6
|
use MIME::Base64 qw(encode_base64); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
10
|
1
|
|
|
1
|
|
1044
|
use Convert::ASN1; |
|
1
|
|
|
|
|
48980
|
|
|
1
|
|
|
|
|
317
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Convert::SSH2::Format::PKCS8 - Format SSH key data as PKCS8 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 PURPOSE |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
This module formats SSH2 RSA public keys as PKCS8 strings. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
These look like |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
-----BEGIN PUBLIC KEY----- |
23
|
|
|
|
|
|
|
... Base64 data ... |
24
|
|
|
|
|
|
|
-----END PUBLIC KEY----- |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Generally, you shouldn't instantiate this class on its own. It will be called by L |
27
|
|
|
|
|
|
|
when needed. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=over |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item asn |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Holds an ASN converter. Defaults to L. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=back |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has 'asn' => ( |
42
|
|
|
|
|
|
|
is => 'ro', |
43
|
|
|
|
|
|
|
default => sub { Convert::ASN1->new(); }, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=over |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item asn_template |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
The ASN encoding template. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Defaults to: |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
SEQUENCE { |
55
|
|
|
|
|
|
|
SEQUENCE { |
56
|
|
|
|
|
|
|
OBJECT IDENTIFIER rsaEncryption (1 2 840 113549 1 1 1), |
57
|
|
|
|
|
|
|
NULL |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
BIT STRING { |
60
|
|
|
|
|
|
|
RSAPublicKey ::= SEQUENCE { |
61
|
|
|
|
|
|
|
modulus INTEGER, -- n |
62
|
|
|
|
|
|
|
publicExponent INTEGER -- e |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=back |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
has 'asn_template' => ( |
72
|
|
|
|
|
|
|
is => 'ro', |
73
|
|
|
|
|
|
|
default => sub { |
74
|
|
|
|
|
|
|
return <<_EOT; |
75
|
|
|
|
|
|
|
key SEQUENCE { |
76
|
|
|
|
|
|
|
algo SEQUENCE { |
77
|
|
|
|
|
|
|
id OBJECT IDENTIFIER, |
78
|
|
|
|
|
|
|
n NULL |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
bs BIT STRING |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
_EOT |
83
|
|
|
|
|
|
|
}, |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 METHOD |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=over |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item generate() |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Returns a PKCS8 formatted string, given C and C. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=back |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub generate { |
99
|
2
|
|
|
2
|
1
|
3
|
my $self = shift; |
100
|
|
|
|
|
|
|
|
101
|
2
|
50
|
|
|
|
15
|
$self->asn->prepare(q| |
102
|
|
|
|
|
|
|
rsa SEQUENCE { |
103
|
|
|
|
|
|
|
mod INTEGER, |
104
|
|
|
|
|
|
|
exp INTEGER |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|) or die; |
107
|
|
|
|
|
|
|
|
108
|
2
|
50
|
|
|
|
2209
|
my $rsa_asn = $self->asn->encode( |
109
|
|
|
|
|
|
|
rsa => { |
110
|
|
|
|
|
|
|
mod => $self->n, |
111
|
|
|
|
|
|
|
exp => $self->e, |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
) or die; |
114
|
|
|
|
|
|
|
|
115
|
2
|
50
|
|
|
|
417502
|
$self->asn->prepare($self->asn_template) or die; |
116
|
|
|
|
|
|
|
|
117
|
2
|
50
|
|
|
|
3172
|
my $pdu = $self->asn->encode( |
118
|
|
|
|
|
|
|
key => { |
119
|
|
|
|
|
|
|
algo => { |
120
|
|
|
|
|
|
|
id => '1.2.840.113549.1.1.1', |
121
|
|
|
|
|
|
|
n => '', |
122
|
|
|
|
|
|
|
}, |
123
|
|
|
|
|
|
|
bs => $rsa_asn, |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
) or die; |
126
|
|
|
|
|
|
|
|
127
|
2
|
|
|
|
|
418
|
my $b64 = encode_base64($pdu, ""); |
128
|
|
|
|
|
|
|
|
129
|
2
|
|
|
|
|
7
|
my $out = "-----BEGIN PUBLIC KEY-----\n"; |
130
|
2
|
|
|
|
|
21
|
$out .= $self->format_lines($b64); |
131
|
2
|
|
|
|
|
6
|
$out .= "-----END PUBLIC KEY-----\n"; |
132
|
|
|
|
|
|
|
|
133
|
2
|
|
|
|
|
14
|
return $out; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 SEE ALSO |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |