line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
########################################### |
2
|
|
|
|
|
|
|
package Net::SSH::AuthorizedKey::SSH2; |
3
|
|
|
|
|
|
|
########################################### |
4
|
12
|
|
|
12
|
|
48
|
use strict; |
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
325
|
|
5
|
12
|
|
|
12
|
|
43
|
use warnings; |
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
329
|
|
6
|
12
|
|
|
12
|
|
47
|
use Net::SSH::AuthorizedKey::Base; |
|
12
|
|
|
|
|
13
|
|
|
12
|
|
|
|
|
246
|
|
7
|
12
|
|
|
12
|
|
48
|
use base qw(Net::SSH::AuthorizedKey::Base); |
|
12
|
|
|
|
|
14
|
|
|
12
|
|
|
|
|
876
|
|
8
|
12
|
|
|
12
|
|
129
|
use Log::Log4perl qw(:easy); |
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
58
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# No additional options, only global ones |
11
|
|
|
|
|
|
|
our %VALID_OPTIONS = (); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $KEYTYPE_REGEX = qr/rsa|dsa|ssh-rsa|ssh-dss|ssh-ed25519|ecdsa-\S+/; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @REQUIRED_FIELDS = qw( |
16
|
|
|
|
|
|
|
encryption |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
__PACKAGE__->make_accessor( $_ ) for |
20
|
|
|
|
|
|
|
(@REQUIRED_FIELDS); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
########################################### |
23
|
|
|
|
|
|
|
sub new { |
24
|
|
|
|
|
|
|
########################################### |
25
|
35
|
|
|
35
|
0
|
52
|
my($class, %options) = @_; |
26
|
|
|
|
|
|
|
|
27
|
35
|
|
|
|
|
111
|
return $class->SUPER::new( %options, type => "ssh-2" ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
########################################### |
31
|
|
|
|
|
|
|
sub as_string { |
32
|
|
|
|
|
|
|
########################################### |
33
|
47
|
|
|
47
|
0
|
49
|
my($self) = @_; |
34
|
|
|
|
|
|
|
|
35
|
47
|
|
|
|
|
102
|
my $string = $self->options_as_string(); |
36
|
47
|
100
|
|
|
|
81
|
$string .= " " if length $string; |
37
|
|
|
|
|
|
|
|
38
|
47
|
|
|
|
|
84
|
$string .= "$self->{encryption} $self->{key}"; |
39
|
47
|
100
|
|
|
|
95
|
$string .= " $self->{email}" if length $self->{email}; |
40
|
|
|
|
|
|
|
|
41
|
47
|
|
|
|
|
107
|
return $string; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
########################################### |
45
|
|
|
|
|
|
|
sub parse_multi_line { |
46
|
|
|
|
|
|
|
########################################### |
47
|
0
|
|
|
0
|
0
|
0
|
my($self, $string) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
my @fields = (); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
while($string =~ s/^(.*):\s+(.*)//gm) { |
52
|
0
|
|
|
|
|
0
|
my($field, $value) = ($1, $2); |
53
|
|
|
|
|
|
|
# remove quotes |
54
|
0
|
|
|
|
|
0
|
$value =~ s/^"(.*)"$/$1/; |
55
|
0
|
|
|
|
|
0
|
push @fields, $field, $value; |
56
|
0
|
|
|
|
|
0
|
my $lcfield = lc $field; |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
0
|
if( $self->accessor_exists( $lcfield ) ) { |
59
|
0
|
|
|
|
|
0
|
$self->$lcfield( $value ); |
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
|
|
|
|
0
|
WARN "Ignoring unknown field '$field'"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Rest is the key, split across several lines |
66
|
0
|
|
|
|
|
0
|
$string =~ s/\n//g; |
67
|
0
|
|
|
|
|
0
|
$self->key( $string ); |
68
|
0
|
|
|
|
|
0
|
$self->type( "ssh-2" ); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Comment: "rsa-key-20090703" |
71
|
0
|
0
|
|
|
|
0
|
if($self->comment() =~ /\b(.*?)-key/) { |
|
|
0
|
|
|
|
|
|
72
|
0
|
|
|
|
|
0
|
$self->encryption( "ssh-" . $1 ); |
73
|
|
|
|
|
|
|
} elsif( ! $self->{strict} ) { |
74
|
0
|
|
|
|
|
0
|
WARN "Unknown encryption [", $self->comment(), |
75
|
|
|
|
|
|
|
"] fixed to ssh-rsa"; |
76
|
0
|
|
|
|
|
0
|
$self->encryption( "ssh-rsa" ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
########################################### |
81
|
|
|
|
|
|
|
sub key_read { |
82
|
|
|
|
|
|
|
############################################ |
83
|
92
|
|
|
92
|
0
|
85
|
my($class, $line) = @_; |
84
|
|
|
|
|
|
|
|
85
|
92
|
100
|
|
|
|
722
|
if($line !~ s/^($KEYTYPE_REGEX)\s*//) { |
86
|
57
|
|
|
|
|
84
|
DEBUG "No SSH2 keytype found"; |
87
|
57
|
|
|
|
|
266
|
return undef; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
35
|
|
|
|
|
64
|
my $encryption = $1; |
91
|
35
|
|
|
|
|
74
|
DEBUG "Parsed encryption $encryption"; |
92
|
|
|
|
|
|
|
|
93
|
35
|
50
|
|
|
|
218
|
if($line !~ s/^(\S+)\s*//) { |
94
|
0
|
|
|
|
|
0
|
DEBUG "No SSH2 key found"; |
95
|
0
|
|
|
|
|
0
|
return undef; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
35
|
|
|
|
|
48
|
my $key = $1; |
99
|
35
|
|
|
|
|
63
|
DEBUG "Parsed key $key"; |
100
|
|
|
|
|
|
|
|
101
|
35
|
|
|
|
|
109
|
my $email = $line; |
102
|
|
|
|
|
|
|
|
103
|
35
|
|
|
|
|
72
|
my $obj = __PACKAGE__->new(); |
104
|
35
|
|
|
|
|
850
|
$obj->encryption( $encryption ); |
105
|
35
|
|
|
|
|
698
|
$obj->key( $key ); |
106
|
35
|
|
|
|
|
735
|
$obj->email( $email ); |
107
|
35
|
|
|
|
|
710
|
$obj->comment( $email ); |
108
|
|
|
|
|
|
|
|
109
|
35
|
|
|
|
|
99
|
return $obj; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
########################################### |
113
|
|
|
|
|
|
|
sub sanity_check { |
114
|
|
|
|
|
|
|
########################################### |
115
|
2
|
|
|
2
|
0
|
6
|
my($self) = @_; |
116
|
|
|
|
|
|
|
|
117
|
2
|
|
|
|
|
6
|
for my $field (@REQUIRED_FIELDS) { |
118
|
2
|
50
|
|
|
|
85
|
if(! length $self->$field()) { |
119
|
0
|
|
|
|
|
0
|
WARN "ssh-2 sanity check failed '$field' requirement"; |
120
|
0
|
|
|
|
|
0
|
return undef; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
2
|
|
|
|
|
14
|
return 1; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
########################################### |
128
|
|
|
|
|
|
|
sub option_type { |
129
|
|
|
|
|
|
|
########################################### |
130
|
0
|
|
|
0
|
0
|
|
my($self, $option) = @_; |
131
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
if(exists $VALID_OPTIONS{ $option }) { |
133
|
0
|
|
|
|
|
|
return $VALID_OPTIONS{ $option }; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
return undef; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
__END__ |