line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Cipher.pm,v 1.12 2008/09/24 19:21:20 turnstep Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Net::SSH::Perl::Cipher; |
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
7798
|
use strict; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
209
|
|
6
|
6
|
|
|
6
|
|
42
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
235
|
|
7
|
6
|
|
|
6
|
|
44
|
use Carp qw( croak ); |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
433
|
|
8
|
6
|
|
|
6
|
|
1767
|
use Crypt::Digest::SHA512 qw( sha512 ); |
|
6
|
|
|
|
|
23112
|
|
|
6
|
|
|
|
|
398
|
|
9
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
49
|
use vars qw( %CIPHERS %CIPHERS_SSH2 %CIPH_REVERSE %SUPPORTED ); |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
1047
|
|
11
|
|
|
|
|
|
|
BEGIN { |
12
|
6
|
|
|
6
|
|
76
|
%CIPHERS = ( |
13
|
|
|
|
|
|
|
None => 0, |
14
|
|
|
|
|
|
|
IDEA => 1, |
15
|
|
|
|
|
|
|
DES => 2, |
16
|
|
|
|
|
|
|
DES3 => 3, |
17
|
|
|
|
|
|
|
RC4 => 5, |
18
|
|
|
|
|
|
|
Blowfish => 6, |
19
|
|
|
|
|
|
|
AES128_CTR => 7, |
20
|
|
|
|
|
|
|
AES192_CTR => 8, |
21
|
|
|
|
|
|
|
AES256_CTR => 9, |
22
|
|
|
|
|
|
|
AES128_CBC => 10, |
23
|
|
|
|
|
|
|
AES192_CBC => 11, |
24
|
|
|
|
|
|
|
AES256_CBC => 12, |
25
|
|
|
|
|
|
|
ChachaPoly => 13, |
26
|
|
|
|
|
|
|
); |
27
|
6
|
|
|
|
|
51
|
%CIPHERS_SSH2 = ( |
28
|
|
|
|
|
|
|
'3des-cbc' => 'DES3', |
29
|
|
|
|
|
|
|
'blowfish-cbc' => 'Blowfish', |
30
|
|
|
|
|
|
|
'arcfour' => 'RC4', |
31
|
|
|
|
|
|
|
'aes128-ctr' => 'AES128_CTR', |
32
|
|
|
|
|
|
|
'aes192-ctr' => 'AES192_CTR', |
33
|
|
|
|
|
|
|
'aes256-ctr' => 'AES256_CTR', |
34
|
|
|
|
|
|
|
'aes128-cbc' => 'AES128_CBC', |
35
|
|
|
|
|
|
|
'aes192-cbc' => 'AES192_CBC', |
36
|
|
|
|
|
|
|
'aes256-cbc' => 'AES256_CBC', |
37
|
|
|
|
|
|
|
'chacha20-poly1305@openssh.com' => 'ChachaPoly', |
38
|
|
|
|
|
|
|
); |
39
|
6
|
|
|
|
|
4472
|
%CIPH_REVERSE = reverse %CIPHERS; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _determine_supported { |
43
|
1
|
|
|
1
|
|
7
|
for my $ciph (keys %CIPHERS) { |
44
|
13
|
|
|
|
|
83
|
my $pack = sprintf "%s::%s", __PACKAGE__, $ciph; |
45
|
13
|
|
|
1
|
|
1038
|
eval "use $pack"; |
|
1
|
|
|
1
|
|
161
|
|
|
0
|
|
|
1
|
|
0
|
|
|
0
|
|
|
1
|
|
0
|
|
|
1
|
|
|
1
|
|
508
|
|
|
1
|
|
|
1
|
|
5
|
|
|
1
|
|
|
1
|
|
27
|
|
|
1
|
|
|
1
|
|
418
|
|
|
1
|
|
|
1
|
|
5
|
|
|
1
|
|
|
1
|
|
35
|
|
|
1
|
|
|
1
|
|
420
|
|
|
1
|
|
|
1
|
|
6
|
|
|
1
|
|
|
1
|
|
23
|
|
|
1
|
|
|
|
|
507
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
28
|
|
|
1
|
|
|
|
|
404
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
19
|
|
|
1
|
|
|
|
|
376
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
23
|
|
|
1
|
|
|
|
|
396
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
22
|
|
|
1
|
|
|
|
|
383
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
21
|
|
|
1
|
|
|
|
|
397
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
20
|
|
|
1
|
|
|
|
|
386
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
47
|
|
|
1
|
|
|
|
|
398
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
21
|
|
|
1
|
|
|
|
|
379
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
22
|
|
46
|
13
|
100
|
|
|
|
116
|
$SUPPORTED{$CIPHERS{$ciph}}++ unless $@; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new { |
51
|
49
|
|
|
49
|
1
|
16302
|
my $class = shift; |
52
|
49
|
|
|
|
|
99
|
my $type = shift; |
53
|
49
|
|
|
|
|
155
|
my($ciph); |
54
|
49
|
100
|
|
|
|
194
|
unless ($type eq "None") { |
55
|
43
|
|
66
|
|
|
213
|
$type = $CIPHERS_SSH2{$type} || $type; |
56
|
43
|
|
|
|
|
137
|
my $ciph_class = join '::', __PACKAGE__, $type; |
57
|
43
|
|
|
|
|
436
|
(my $lib = $ciph_class . ".pm") =~ s!::!/!g; |
58
|
43
|
|
|
|
|
742
|
require $lib; |
59
|
43
|
|
|
|
|
288
|
$ciph = $ciph_class->new(@_); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
6
|
|
|
|
|
19
|
$ciph = bless { }, __PACKAGE__; |
63
|
|
|
|
|
|
|
} |
64
|
49
|
|
|
|
|
452
|
$ciph; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub new_from_key_str { |
68
|
32
|
|
|
32
|
0
|
19642
|
my $class = shift; |
69
|
32
|
50
|
|
|
|
160
|
defined $_[1] ? |
70
|
|
|
|
|
|
|
$class->new($_[0], sha512($_[1])) : |
71
|
|
|
|
|
|
|
$class->new(@_); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
0
|
0
|
0
|
sub enabled { $_[0]->{enabled} } |
75
|
0
|
|
|
0
|
0
|
0
|
sub enable { $_[0]->{enabled} = 1 } |
76
|
1
|
|
|
1
|
0
|
2
|
sub authlen { 0 } |
77
|
1
|
|
|
1
|
0
|
3
|
sub ivlen { shift->blocksize } |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub id { |
80
|
8
|
|
|
8
|
1
|
73921
|
my $this = shift; |
81
|
8
|
|
|
|
|
18
|
my $type; |
82
|
8
|
50
|
|
|
|
24
|
if (my $class = ref $this) { |
83
|
0
|
|
|
|
|
0
|
my $pack = __PACKAGE__; |
84
|
0
|
|
|
|
|
0
|
($type = $class) =~ s/^${pack}:://; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
8
|
|
|
|
|
17
|
$type = $this; |
88
|
|
|
|
|
|
|
} |
89
|
8
|
|
|
|
|
31
|
$CIPHERS{$type}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub name { |
93
|
0
|
|
|
0
|
1
|
0
|
my $this = shift; |
94
|
0
|
|
|
|
|
0
|
my $name; |
95
|
0
|
0
|
|
|
|
0
|
if (my $class = ref $this) { |
96
|
0
|
|
|
|
|
0
|
my $pack = __PACKAGE__; |
97
|
0
|
|
|
|
|
0
|
($name = $class) =~ s/^${pack}:://; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
else { |
100
|
0
|
|
|
|
|
0
|
$name = $CIPH_REVERSE{$this}; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
0
|
$name; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub mask { |
106
|
0
|
|
|
0
|
0
|
0
|
my $mask = 0; |
107
|
0
|
|
|
|
|
0
|
$mask |= (1<<$_) for keys %SUPPORTED; |
108
|
0
|
|
|
|
|
0
|
$mask; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub supported { |
112
|
8
|
100
|
|
8
|
1
|
44
|
unless (keys %SUPPORTED) { |
113
|
1
|
|
|
|
|
5
|
_determine_supported(); |
114
|
|
|
|
|
|
|
} |
115
|
8
|
|
|
|
|
19
|
my $protocol = 1; |
116
|
8
|
50
|
66
|
|
|
54
|
shift, $protocol = shift |
|
|
|
66
|
|
|
|
|
117
|
|
|
|
|
|
|
if not ref $_[0] and $_[0] and $_[0] eq 'protocol'; |
118
|
8
|
50
|
|
|
|
22
|
unless(@_) { |
119
|
0
|
0
|
|
|
|
0
|
return [ keys %SUPPORTED ] unless 2 == $protocol; |
120
|
0
|
|
|
|
|
0
|
return [ grep $SUPPORTED{$_}, map $CIPHERS{$_}, values %CIPHERS_SSH2 ]; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
8
|
50
|
|
|
|
21
|
my $id = ref $_[0] ? shift->id : shift; |
124
|
8
|
50
|
66
|
|
|
53
|
return $id == 0 || exists $SUPPORTED{$id} unless @_; |
125
|
0
|
|
|
|
|
0
|
my $ssupp = shift; |
126
|
0
|
|
|
|
|
0
|
mask() & $ssupp & (1 << $id); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
3
|
|
|
3
|
1
|
3428
|
sub encrypt { $_[1] } |
130
|
|
|
|
|
|
|
|
131
|
3
|
|
|
3
|
1
|
16
|
sub decrypt { $_[1] } |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
__END__ |