line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SSH::Perl::Cipher; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
8929
|
use strict; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
206
|
|
4
|
7
|
|
|
7
|
|
33
|
use warnings; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
179
|
|
5
|
7
|
|
|
7
|
|
37
|
use Carp qw( croak ); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
385
|
|
6
|
7
|
|
|
7
|
|
2919
|
use Crypt::Digest::SHA512 qw( sha512 ); |
|
7
|
|
|
|
|
15385
|
|
|
7
|
|
|
|
|
426
|
|
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
51
|
use vars qw( %CIPHERS %CIPHERS_SSH2 %CIPH_REVERSE %SUPPORTED ); |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
806
|
|
9
|
|
|
|
|
|
|
BEGIN { |
10
|
7
|
|
|
7
|
|
75
|
%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
|
|
|
|
|
57
|
%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
|
|
|
|
|
5545
|
%CIPH_REVERSE = reverse %CIPHERS; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _determine_supported { |
41
|
1
|
|
|
1
|
|
5
|
for my $ciph (keys %CIPHERS) { |
42
|
13
|
|
|
|
|
57
|
my $pack = sprintf "%s::%s", __PACKAGE__, $ciph; |
43
|
13
|
|
|
1
|
|
933
|
eval "use $pack"; |
|
1
|
|
|
1
|
|
311
|
|
|
0
|
|
|
1
|
|
0
|
|
|
0
|
|
|
1
|
|
0
|
|
|
1
|
|
|
1
|
|
568
|
|
|
1
|
|
|
1
|
|
8
|
|
|
1
|
|
|
1
|
|
44
|
|
|
1
|
|
|
1
|
|
428
|
|
|
1
|
|
|
1
|
|
3
|
|
|
1
|
|
|
1
|
|
20
|
|
|
1
|
|
|
1
|
|
444
|
|
|
1
|
|
|
1
|
|
3
|
|
|
1
|
|
|
1
|
|
17
|
|
|
1
|
|
|
|
|
471
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
19
|
|
|
1
|
|
|
|
|
482
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
444
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
20
|
|
|
1
|
|
|
|
|
468
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
447
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
465
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
|
1
|
|
|
|
|
480
|
|
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
483
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
491
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
44
|
13
|
100
|
|
|
|
97
|
$SUPPORTED{$CIPHERS{$ciph}}++ unless $@; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
49
|
|
|
49
|
1
|
11159
|
my $class = shift; |
50
|
49
|
|
|
|
|
79
|
my $type = shift; |
51
|
49
|
|
|
|
|
90
|
my($ciph); |
52
|
49
|
100
|
|
|
|
147
|
unless ($type eq "None") { |
53
|
43
|
|
66
|
|
|
190
|
$type = $CIPHERS_SSH2{$type} || $type; |
54
|
43
|
|
|
|
|
113
|
my $ciph_class = join '::', __PACKAGE__, $type; |
55
|
43
|
|
|
|
|
287
|
(my $lib = $ciph_class . ".pm") =~ s!::!/!g; |
56
|
43
|
|
|
|
|
715
|
require $lib; |
57
|
43
|
|
|
|
|
342
|
$ciph = $ciph_class->new(@_); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
6
|
|
|
|
|
14
|
$ciph = bless { }, __PACKAGE__; |
61
|
|
|
|
|
|
|
} |
62
|
49
|
|
|
|
|
430
|
$ciph; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub new_from_key_str { |
66
|
32
|
|
|
32
|
0
|
13026
|
my $class = shift; |
67
|
32
|
50
|
|
|
|
146
|
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
|
104837
|
my $this = shift; |
79
|
8
|
|
|
|
|
12
|
my $type; |
80
|
8
|
50
|
|
|
|
19
|
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
|
|
|
|
|
22
|
$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
|
29
|
unless (keys %SUPPORTED) { |
111
|
1
|
|
|
|
|
5
|
_determine_supported(); |
112
|
|
|
|
|
|
|
} |
113
|
8
|
|
|
|
|
16
|
my $protocol = 1; |
114
|
8
|
50
|
66
|
|
|
40
|
shift, $protocol = shift |
|
|
|
66
|
|
|
|
|
115
|
|
|
|
|
|
|
if not ref $_[0] and $_[0] and $_[0] eq 'protocol'; |
116
|
8
|
50
|
|
|
|
16
|
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
|
|
|
|
17
|
my $id = ref $_[0] ? shift->id : shift; |
122
|
8
|
50
|
66
|
|
|
32
|
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
|
2313
|
sub encrypt { $_[1] } |
128
|
|
|
|
|
|
|
|
129
|
3
|
|
|
3
|
1
|
14
|
sub decrypt { $_[1] } |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
__END__ |