line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SSH::Perl::Cipher; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
8621
|
use strict; |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
244
|
|
4
|
7
|
|
|
7
|
|
44
|
use warnings; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
182
|
|
5
|
7
|
|
|
7
|
|
35
|
use Carp qw( croak ); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
348
|
|
6
|
7
|
|
|
7
|
|
2983
|
use Crypt::Digest::SHA512 qw( sha512 ); |
|
7
|
|
|
|
|
15584
|
|
|
7
|
|
|
|
|
422
|
|
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
50
|
use vars qw( %CIPHERS %CIPHERS_SSH2 %CIPH_REVERSE %SUPPORTED ); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
847
|
|
9
|
|
|
|
|
|
|
BEGIN { |
10
|
7
|
|
|
7
|
|
110
|
%CIPHERS = ( |
11
|
|
|
|
|
|
|
None => 0, |
12
|
|
|
|
|
|
|
IDEA => 1, |
13
|
|
|
|
|
|
|
DES => 2, |
14
|
|
|
|
|
|
|
DES3 => 3, |
15
|
|
|
|
|
|
|
RC4 => 5, |
16
|
|
|
|
|
|
|
Blowfish => 6, |
17
|
|
|
|
|
|
|
AES128_CTR => 7, |
18
|
|
|
|
|
|
|
AES192_CTR => 8, |
19
|
|
|
|
|
|
|
AES256_CTR => 9, |
20
|
|
|
|
|
|
|
AES128_CBC => 10, |
21
|
|
|
|
|
|
|
AES192_CBC => 11, |
22
|
|
|
|
|
|
|
AES256_CBC => 12, |
23
|
|
|
|
|
|
|
ChachaPoly => 13, |
24
|
|
|
|
|
|
|
); |
25
|
7
|
|
|
|
|
51
|
%CIPHERS_SSH2 = ( |
26
|
|
|
|
|
|
|
'3des-cbc' => 'DES3', |
27
|
|
|
|
|
|
|
'blowfish-cbc' => 'Blowfish', |
28
|
|
|
|
|
|
|
'arcfour' => 'RC4', |
29
|
|
|
|
|
|
|
'aes128-ctr' => 'AES128_CTR', |
30
|
|
|
|
|
|
|
'aes192-ctr' => 'AES192_CTR', |
31
|
|
|
|
|
|
|
'aes256-ctr' => 'AES256_CTR', |
32
|
|
|
|
|
|
|
'aes128-cbc' => 'AES128_CBC', |
33
|
|
|
|
|
|
|
'aes192-cbc' => 'AES192_CBC', |
34
|
|
|
|
|
|
|
'aes256-cbc' => 'AES256_CBC', |
35
|
|
|
|
|
|
|
'chacha20-poly1305@openssh.com' => 'ChachaPoly', |
36
|
|
|
|
|
|
|
); |
37
|
7
|
|
|
|
|
5565
|
%CIPH_REVERSE = reverse %CIPHERS; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _determine_supported { |
41
|
1
|
|
|
1
|
|
8
|
for my $ciph (keys %CIPHERS) { |
42
|
13
|
|
|
|
|
59
|
my $pack = sprintf "%s::%s", __PACKAGE__, $ciph; |
43
|
13
|
|
|
1
|
|
835
|
eval "use $pack"; |
|
1
|
|
|
1
|
|
804
|
|
|
1
|
|
|
1
|
|
3
|
|
|
1
|
|
|
1
|
|
24
|
|
|
1
|
|
|
1
|
|
514
|
|
|
1
|
|
|
1
|
|
3
|
|
|
1
|
|
|
1
|
|
18
|
|
|
1
|
|
|
1
|
|
503
|
|
|
1
|
|
|
1
|
|
3
|
|
|
1
|
|
|
1
|
|
23
|
|
|
1
|
|
|
1
|
|
455
|
|
|
1
|
|
|
1
|
|
7
|
|
|
1
|
|
|
1
|
|
15
|
|
|
1
|
|
|
|
|
501
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
471
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
22
|
|
|
1
|
|
|
|
|
471
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
19
|
|
|
1
|
|
|
|
|
473
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
464
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
20
|
|
|
1
|
|
|
|
|
505
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
287
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
468
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
20
|
|
|
1
|
|
|
|
|
451
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
44
|
13
|
100
|
|
|
|
106
|
$SUPPORTED{$CIPHERS{$ciph}}++ unless $@; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
49
|
|
|
49
|
1
|
10119
|
my $class = shift; |
50
|
49
|
|
|
|
|
83
|
my $type = shift; |
51
|
49
|
|
|
|
|
70
|
my($ciph); |
52
|
49
|
100
|
|
|
|
112
|
unless ($type eq "None") { |
53
|
43
|
|
66
|
|
|
156
|
$type = $CIPHERS_SSH2{$type} || $type; |
54
|
43
|
|
|
|
|
106
|
my $ciph_class = join '::', __PACKAGE__, $type; |
55
|
43
|
|
|
|
|
261
|
(my $lib = $ciph_class . ".pm") =~ s!::!/!g; |
56
|
43
|
|
|
|
|
738
|
require $lib; |
57
|
43
|
|
|
|
|
351
|
$ciph = $ciph_class->new(@_); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
6
|
|
|
|
|
16
|
$ciph = bless { }, __PACKAGE__; |
61
|
|
|
|
|
|
|
} |
62
|
49
|
|
|
|
|
356
|
$ciph; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub new_from_key_str { |
66
|
32
|
|
|
32
|
0
|
9800
|
my $class = shift; |
67
|
32
|
50
|
|
|
|
130
|
defined $_[1] ? |
68
|
|
|
|
|
|
|
$class->new($_[0], sha512($_[1])) : |
69
|
|
|
|
|
|
|
$class->new(@_); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
0
|
0
|
0
|
sub enabled { $_[0]->{enabled} } |
73
|
0
|
|
|
0
|
0
|
0
|
sub enable { $_[0]->{enabled} = 1 } |
74
|
1
|
|
|
1
|
0
|
2
|
sub authlen { 0 } |
75
|
1
|
|
|
1
|
0
|
3
|
sub ivlen { shift->blocksize } |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub id { |
78
|
8
|
|
|
8
|
1
|
105027
|
my $this = shift; |
79
|
8
|
|
|
|
|
11
|
my $type; |
80
|
8
|
50
|
|
|
|
15
|
if (my $class = ref $this) { |
81
|
0
|
|
|
|
|
0
|
my $pack = __PACKAGE__; |
82
|
0
|
|
|
|
|
0
|
($type = $class) =~ s/^${pack}:://; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else { |
85
|
8
|
|
|
|
|
15
|
$type = $this; |
86
|
|
|
|
|
|
|
} |
87
|
8
|
|
|
|
|
25
|
$CIPHERS{$type}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub name { |
91
|
0
|
|
|
0
|
1
|
0
|
my $this = shift; |
92
|
0
|
|
|
|
|
0
|
my $name; |
93
|
0
|
0
|
|
|
|
0
|
if (my $class = ref $this) { |
94
|
0
|
|
|
|
|
0
|
my $pack = __PACKAGE__; |
95
|
0
|
|
|
|
|
0
|
($name = $class) =~ s/^${pack}:://; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
0
|
|
|
|
|
0
|
$name = $CIPH_REVERSE{$this}; |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
0
|
$name; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub mask { |
104
|
0
|
|
|
0
|
0
|
0
|
my $mask = 0; |
105
|
0
|
|
|
|
|
0
|
$mask |= (1<<$_) for keys %SUPPORTED; |
106
|
0
|
|
|
|
|
0
|
$mask; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub supported { |
110
|
8
|
100
|
|
8
|
1
|
28
|
unless (keys %SUPPORTED) { |
111
|
1
|
|
|
|
|
13
|
_determine_supported(); |
112
|
|
|
|
|
|
|
} |
113
|
8
|
|
|
|
|
13
|
my $protocol = 1; |
114
|
8
|
50
|
66
|
|
|
37
|
shift, $protocol = shift |
|
|
|
66
|
|
|
|
|
115
|
|
|
|
|
|
|
if not ref $_[0] and $_[0] and $_[0] eq 'protocol'; |
116
|
8
|
50
|
|
|
|
17
|
unless(@_) { |
117
|
0
|
0
|
|
|
|
0
|
return [ keys %SUPPORTED ] unless 2 == $protocol; |
118
|
0
|
|
|
|
|
0
|
return [ grep $SUPPORTED{$_}, map $CIPHERS{$_}, values %CIPHERS_SSH2 ]; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
8
|
50
|
|
|
|
16
|
my $id = ref $_[0] ? shift->id : shift; |
122
|
8
|
50
|
66
|
|
|
33
|
return $id == 0 || exists $SUPPORTED{$id} unless @_; |
123
|
0
|
|
|
|
|
0
|
my $ssupp = shift; |
124
|
0
|
|
|
|
|
0
|
mask() & $ssupp & (1 << $id); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
3
|
|
|
3
|
1
|
1785
|
sub encrypt { $_[1] } |
128
|
|
|
|
|
|
|
|
129
|
3
|
|
|
3
|
1
|
12
|
sub decrypt { $_[1] } |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
__END__ |