line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Convert::SSH2::Format::PKCS1; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
951
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
extends 'Convert::SSH2::Format::Base'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
400
|
use Carp qw(confess); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
70
|
|
9
|
1
|
|
|
1
|
|
6
|
use MIME::Base64 qw(encode_base64); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
54
|
|
10
|
1
|
|
|
1
|
|
905
|
use Convert::ASN1; |
|
1
|
|
|
|
|
57755
|
|
|
1
|
|
|
|
|
280
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Convert::SSH2::Format::PKCS1 - Format SSH key data as PKCS1 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 PURPOSE |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
This module formats SSH2 RSA public keys as PKCS1 strings. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Generally, you shouldn't instantiate this class on its own. It will be called by L |
21
|
|
|
|
|
|
|
when needed. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=over |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=item asn |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Holds an ASN converter. Defaults to L. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=back |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has 'asn' => ( |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
default => sub { Convert::ASN1->new(); }, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=over |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item asn_template |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
The ASN encoding template. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Defaults to: |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
RSAPublicKey ::= SEQUENCE { |
49
|
|
|
|
|
|
|
modulus INTEGER, -- n |
50
|
|
|
|
|
|
|
publicExponent INTEGER -- e |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=back |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has 'asn_template' => ( |
58
|
|
|
|
|
|
|
is => 'ro', |
59
|
|
|
|
|
|
|
default => sub { |
60
|
|
|
|
|
|
|
return <<_EOT; |
61
|
|
|
|
|
|
|
RSAPublicKey ::= SEQUENCE { |
62
|
|
|
|
|
|
|
modulus INTEGER, -- n |
63
|
|
|
|
|
|
|
publicExponent INTEGER -- e |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
_EOT |
66
|
|
|
|
|
|
|
}, |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 METHOD |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=over |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item generate() |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Returns a PKCS#1 formatted string, given C and C. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=back |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub generate { |
83
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
84
|
|
|
|
|
|
|
|
85
|
2
|
50
|
|
|
|
22
|
$self->asn->prepare($self->asn_template) or confess; |
86
|
|
|
|
|
|
|
|
87
|
2
|
50
|
|
|
|
2433
|
my $pdu = $self->asn->encode( |
88
|
|
|
|
|
|
|
modulus => $self->n, |
89
|
|
|
|
|
|
|
publicExponent => $self->e, |
90
|
|
|
|
|
|
|
) or confess; |
91
|
|
|
|
|
|
|
|
92
|
2
|
|
|
|
|
411807
|
my $b64 = encode_base64($pdu, ""); |
93
|
|
|
|
|
|
|
|
94
|
2
|
|
|
|
|
6
|
my $out = "-----BEGIN RSA PUBLIC KEY-----\n"; |
95
|
2
|
|
|
|
|
31
|
$out .= $self->format_lines($b64); |
96
|
2
|
|
|
|
|
8
|
$out .= "-----END RSA PUBLIC KEY-----\n"; |
97
|
|
|
|
|
|
|
|
98
|
2
|
|
|
|
|
13
|
return $out; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SEE ALSO |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |