blib/lib/Net/SSH/Perl/Packet.pm

filter: Statementstmt 50.2% 126 / 251 Branchbran 25.3% 36 / 142 Conditioncond 1.0% 1 / 93 MC/DCmcdc 0.0% 0 / 56 Subroutinesub 86.9% 20 / 23 Podpod 63.6% 7 / 11 totaltotal 32.9% 190 / 576 SCAR 80.8
CC
103
Cov
34%
read_poll_ssh2
1980.0
send_ssh2
702.0
read_poll_ssh1
12.6
CRAP 3217.4
« blib/lib/Net/SSH/Perl.pm ↑ Summary blib/lib/Net/SSH/Perl/SSH2.pm »
1 package Net::SSH::Perl::Packet;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use POSIX qw( :errno_h );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Crypt::PRNG qw( random_bytes );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶use Net::SSH::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 use Net::SSH::Perl::Constants qw(
11 :protocol
12 SSH_MSG_DISCONNECT
13 SSH_MSG_DEBUG
14 SSH_MSG_IGNORE
15 SSH2_MSG_GLOBAL_REQUEST
16 SSH2_MSG_DISCONNECT
17 SSH2_MSG_DEBUG
18 SSH2_MSG_IGNORE
19 5 ▶ MAX_PACKET_SIZE );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use Net::SSH::Perl::Buffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 5 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 sub new {
25 10 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=14.0
Pod documented
26 10 my $ssh = shift;
27 10 my $pack = bless { ssh => $ssh, @_ }, $class;
28 10 weaken $pack->{ssh};
29 10 ▶ unless ($pack->{data}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pack->{"data"}) 5 5 10
30 5 ▶ $pack->{data} = Net::SSH::Perl::Buffer->new(
Branch: 1 branch
BranchTrueFalseTotal
$ssh->protocol == &PROTOCOL_SSH2() ? : 0 5 5
31 MP => $ssh->protocol == PROTOCOL_SSH2 ? 'SSH2' : 'SSH1');
32 5 ▶ if ($pack->{type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pack->{"type"}) 5 0 5
33 5 $pack->{data}->put_int8($pack->{type});
34 }
35 }
36 10 $pack;
37 }
38  
39 sub read {
40 5 ▶ my $class = shift;
Subroutine read: called CC=6 SCAR=19.9
Pod documented
41 5 my $ssh = shift;
42 5 my $sock = $ssh->sock;
43  
44 5 while (1) {
45 9 ▶ if (my $packet = $class->read_poll($ssh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $packet = $class->read_poll($ssh)) 4 4 8
46 4 return $packet;
47 }
48 4 my $s = IO::Select->new( $sock );
49 4 my @ready = $s->can_read;
50 4 my $buf;
51 4 my $len = sysread $sock, $buf, 8192;
52 4 ▶ croak "Connection closed by remote host." if $len == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $len == 0 0 4 4
53 4 ▶ if (!defined $len) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $len) 0 4 4
54 0 ▶ next if $! == EAGAIN || $! == EWOULDBLOCK;
Branch: 1 branch
BranchTrueFalseTotal
if $! == 11 or $! == 11 0 0 0
Condition0%0/3
$! == 11 or $! == 11
l!l&&r!l&&!r
000
MC/DC0%0/2
$! == 11 or $! == 11
$! == 11 $! == 11
Truth table0%0/3
A or B
A= $! == 11B= $! == 11
ABresult
1X1
011
000
55 0 croak "Read from socket failed: $!";
56 }
57  
58 ## Untaint data read from sshd. This is binary data,
59 ## so there's nothing to taint-check against/for.
60 4 ($buf) = $buf =~ /(.*)/s;
61 4 $ssh->incoming_data->append($buf);
62 }
63 }
64  
65 sub read_poll {
66 9 ▶ my $class = shift;
Subroutine read_poll: called CC=8 SCAR=24.5
Pod documented
67 9 my $ssh = shift;
68  
69 9 my($packet, $debug, $ignore);
70 9 ▶ if ($ssh->protocol == PROTOCOL_SSH2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ssh->protocol == &PROTOCOL_SSH2()) { } 0 9 9
71 0 $packet = $class->read_poll_ssh2($ssh);
72 0 ($debug, $ignore) = (SSH2_MSG_DEBUG, SSH2_MSG_IGNORE);
73 }
74 else {
75 9 $packet = $class->read_poll_ssh1($ssh);
76 9 ($debug, $ignore) = (SSH_MSG_DEBUG, SSH_MSG_IGNORE);
77 }
78 9 ▶ return unless $packet;
Branch: 1 branch
BranchTrueFalseTotal
unless $packet 4 5 9
79  
80 5 my $type = $packet->type;
81 5 ▶ if ($ssh->protocol == PROTOCOL_SSH2) { ## Handle DISCONNECT msg
Branch: 1 branch
BranchTrueFalseTotal
if ($ssh->protocol == &PROTOCOL_SSH2()) { } 0 5 5
82 0 ▶ if ($type == SSH2_MSG_DISCONNECT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == &SSH2_MSG_DISCONNECT()) 0 0 0
83 0 $packet->get_int32; ## reason
84 0 croak "Received disconnect message: ", $packet->get_str, "\n";
85 }
86 }
87 else {
88 5 ▶ if ($type == SSH_MSG_DISCONNECT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == &SSH_MSG_DISCONNECT()) 1 4 5
89 1 croak "Received disconnect message: ", $packet->get_str, "\n";
90 }
91 }
92  
93 4 ▶ if ($type == $debug) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type == $debug) { } 0 4 4
elsif ($type == $ignore) { } 0 4 4
94 0 $ssh->debug("Remote: " . $packet->get_str);
95 }
96 elsif ($type == $ignore) { }
97 else {
98 4 return $packet;
99 }
100 0 return $class->read_poll($ssh);
101 }
102  
103 sub read_poll_ssh1 {
104 9 ▶ my $class = shift;
Subroutine read_poll_ssh1: called CC=9 SCAR=25.4
Pod undocumented
105 9 my $ssh = shift;
106  
107 9 ▶ unless (defined &_crc32) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &Net::SSH::Perl::Packet::_crc32) 0 9 9
108 0 eval "use Net::SSH::Perl::Util qw( _crc32 );";
109 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
110 }
111  
112 9 my $incoming = $ssh->incoming_data;
113 9 ▶ return if $incoming->length < 4 + 8;
Branch: 1 branch
BranchTrueFalseTotal
if $incoming->length < 12 4 5 9
114  
115 5 my $len = unpack "N", $incoming->bytes(0, 4);
116 5 ▶ $len = 0 unless defined $len;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 5 5
117 5 my $pad_len = ($len + 8) & ~7;
118 5 ▶ return if $incoming->length < 4 + $pad_len;
Branch: 1 branch
BranchTrueFalseTotal
if $incoming->length < 4 + $pad_len 0 5 5
119  
120 5 my $buffer = Net::SSH::Perl::Buffer->new( MP => 'SSH1' );
121 5 $buffer->append($incoming->bytes(0, $pad_len+4, ''));
122  
123 5 $buffer->bytes(0, 4, "");
124  
125 5 ▶ if (my $cipher = $ssh->receive_cipher) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cipher = $ssh->receive_cipher) 0 5 5
126 0 my $decrypted = $cipher->decrypt($buffer->bytes);
127 0 $buffer->empty;
128 0 $buffer->append($decrypted);
129 }
130  
131 5 my $crc = _crc32($buffer->bytes(0, -4));
132 5 $buffer->bytes(0, 8 - $len % 8, "");
133  
134 5 my $stored_crc = unpack "N", $buffer->bytes(-4, 4);
135 5 ▶ $ssh->fatal_disconnect("Corrupted check bytes on input")
Branch: 1 branch
BranchTrueFalseTotal
unless $crc == $stored_crc 0 5 5
136 unless $crc == $stored_crc;
137  
138 5 $buffer->bytes(-4, 4, ""); ## Cut off checksum.
139  
140 5 ▶ if (my $comp = $ssh->compression) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $comp = $ssh->compression) 0 5 5
141 0 my $inflated = $comp->uncompress($buffer->bytes);
142 0 $buffer->empty;
143 0 $buffer->append($inflated);
144 }
145  
146 5 my $type = unpack "C", $buffer->bytes(0, 1, "");
147 5 $class->new($ssh,
148 type => $type,
149 data => $buffer);
150 }
151  
152 sub read_poll_ssh2 {
153 0 ▶ my $class = shift;
Subroutine read_poll_ssh2: not called CC=44 SCAR=75.9
Pod undocumented
154 0 my $ssh = shift;
155 0 my $kex = $ssh->kex;
156  
157 0 my($ciph, $mac, $comp);
158 0 my $authlen = 0;
159 0 ▶ if ($kex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kex) 0 0 0
160 0 $ciph = $kex->receive_cipher;
161 0 $mac = $kex->receive_mac;
162 0 $comp = $kex->receive_comp;
163 0 ▶ undef $mac if $authlen = $ciph && $ciph->authlen;
Branch: 1 branch
BranchTrueFalseTotal
if $authlen = $ciph && $ciph->authlen 0 0 0
Condition0%0/3
$ciph && $ciph->authlen
!ll&&!rl&&r
000
MC/DC0%0/2
$ciph && $ciph->authlen
$ciph $ciph->authlen
Truth table0%0/3
A && B
A= $ciphB= $ciph->authlen
ABresult
0X0
100
111
164 }
165 0 ▶ my $maclen = $mac && $mac->enabled ? $mac->len : 0;
Branch: 1 branch
BranchTrueFalseTotal
$mac && $mac->enabled ? : 0 0 0
Condition0%0/3
$mac and $mac->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$mac and $mac->enabled
$mac $mac->enabled
Truth table0%0/3
A and B
A= $macB= $mac->enabled
ABresult
0X0
100
111
166 0 ▶ my $block_size = $ciph && $ciph->enabled ? $ciph->blocksize : 8;
Branch: 1 branch
BranchTrueFalseTotal
$ciph && $ciph->enabled ? : 0 0 0
Condition0%0/3
$ciph and $ciph->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph $ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
ABresult
0X0
100
111
167 0 ▶ my $aadlen = ($mac && $mac->enabled && $mac->etm) || $authlen ? 4 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$mac && $mac->enabled && $mac->etm || $authlen ? : 0 0 0
Condition0%0/9
$mac and $mac->enabled and $mac->etm or $authlen
l!l&&r!l&&!r
000
$mac and $mac->enabled and $mac->etm
!ll&&!rl&&r
000
$mac and $mac->enabled
!ll&&!rl&&r
000
MC/DC0%0/4
$mac and $mac->enabled and $mac->etm or $authlen
$mac $mac->enabled $mac->etm $authlen
Truth table0%0/7
A and B and C or D
A= $macB= $mac->enabledC= $mac->etmD= $authlen
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
168 0 my $seqnr = $ssh->{session}{seqnr_in};
169  
170 0 my $incoming = $ssh->incoming_data;
171 0 ▶ if (!$ssh->{session}{_last_packet_length}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ssh->{"session"}{"_last_packet_length"}) 0 0 0
172 0 ▶ return if $incoming->length < $block_size;
Branch: 1 branch
BranchTrueFalseTotal
if $incoming->length < $block_size 0 0 0
173 0 my $b = Net::SSH::Perl::Buffer->new( MP => 'SSH2' );
174  
175 0 ▶ if ($authlen) {
Branch: 2 branches
BranchTrueFalseTotal
if ($authlen) { } 0 0 0
elsif ($aadlen) { } 0 0 0
176 0 $b->append($ciph->get_length($incoming->bytes(0,$block_size),
177 $seqnr));
178 } elsif ($aadlen) {
179 0 $b->append($incoming->bytes(0, $block_size));
180 } else {
181 0 ▶ $b->append( $ciph && $ciph->enabled ?
Branch: 1 branch
BranchTrueFalseTotal
$ciph && $ciph->enabled ? : 0 0 0
Condition0%0/3
$ciph and $ciph->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph $ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
ABresult
0X0
100
111
182 $ciph->decrypt($incoming->bytes(0, $block_size)) :
183 $incoming->bytes(0, $block_size)
184 );
185 # replace first block of incoming buffer with decrypted contents
186 0 $incoming->bytes(0, $block_size, $b->bytes);
187 }
188 0 my $plen = $ssh->{session}{_last_packet_length} = $b->get_int32;
189 0 ▶ if ($plen < 1 + 4 || $plen > 256 * 1024) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plen < 5 or $plen > 262144) 0 0 0
Condition0%0/3
$plen < 5 or $plen > 262144
l!l&&r!l&&!r
000
MC/DC0%0/2
$plen < 5 or $plen > 262144
$plen < 5 $plen > 262144
Truth table0%0/3
A or B
A= $plen < 5B= $plen > 262144
ABresult
1X1
011
000
190 0 $ssh->fatal_disconnect("Bad packet length $plen");
191 }
192 }
193 my $need = $aadlen ? $ssh->{session}{_last_packet_length} :
194 0 ▶ 4 + $ssh->{session}{_last_packet_length} - $block_size;
Branch: 1 branch
BranchTrueFalseTotal
$aadlen ? : 0 0 0
195 0 ▶ croak "padding error: need $need block $block_size"
Branch: 1 branch
BranchTrueFalseTotal
if $need % $block_size 0 0 0
196 if $need % $block_size;
197 0 ▶ return if ( $aadlen && ($incoming->length < $aadlen + $need + $maclen + $authlen)) ||
Branch: 1 branch
BranchTrueFalseTotal
if $aadlen and $incoming->length < $aadlen + $need + $maclen + $authlen or not $aadlen and $incoming->length < $need + $block_size + $maclen 0 0 0
Condition0%0/9
$aadlen and $incoming->length < $aadlen + $need + $maclen + $authlen or not $aadlen and $incoming->length < $need + $block_size + $maclen
l!l&&r!l&&!r
000
$aadlen and $incoming->length < $aadlen + $need + $maclen + $authlen
!ll&&!rl&&r
000
not $aadlen and $incoming->length < $need + $block_size + $maclen
!ll&&!rl&&r
000
MC/DC0%0/4
$aadlen and $incoming->length < $aadlen + $need + $maclen + $authlen or not $aadlen and $incoming->length < $need + $block_size + $maclen
$aadlen $incoming->length < $aadlen + $need + $maclen + $authlen not $aadlen $incoming->length < $need + $block_size + $maclen
Truth table0%0/7
A and B or not(C) and D
A= $aadlenB= $incoming->length < $aadlen + $need + $maclen + $authlenC= not $aadlenD= $incoming->length < $need + $block_size + $maclen
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
198 (!$aadlen && ($incoming->length < $need + $block_size + $maclen));
199  
200 0 my $buffer = Net::SSH::Perl::Buffer->new( MP => 'SSH2' );
201 0 my ($macbuf,$p_str);
202 0 ▶ if ($mac && $mac->enabled) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mac and $mac->enabled) { } 0 0 0
elsif ($authlen) { } 0 0 0
Condition0%0/3
$mac and $mac->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$mac and $mac->enabled
$mac $mac->enabled
Truth table0%0/3
A and B
A= $macB= $mac->enabled
ABresult
0X0
100
111
203 0 ▶ if ($mac->etm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mac->etm) { } 0 0 0
204 0 $p_str = $incoming->bytes(0, $aadlen + $need, '');
205 0 $macbuf = $mac->hmac(pack("N", $seqnr) . $p_str);
206 # remove packet length bytes
207 0 substr($p_str,0,$aadlen,'');
208 } else {
209 # not etm mac, append bytes already decrypted above
210 0 $buffer->append( $incoming->bytes(0, $block_size, '') );
211 0 $p_str = $incoming->bytes(0, $need, '');
212 }
213 } elsif ($authlen) {
214 # cipher with auth
215 0 $p_str = $incoming->bytes(0, $aadlen + $need + $authlen, '');
216 } else {
217 0 $buffer->append( $incoming->bytes(0, $block_size, '') );
218 0 $p_str = $incoming->bytes(0, $need, '');
219 }
220  
221 0 ▶ if ($mac && $mac->enabled) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mac and $mac->enabled) { } 0 0 0
Condition0%0/3
$mac and $mac->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$mac and $mac->enabled
$mac $mac->enabled
Truth table0%0/3
A and B
A= $macB= $mac->enabled
ABresult
0X0
100
111
222 0 ▶ unless ($mac->etm) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mac->etm) 0 0 0
223 0 ▶ $buffer->append( $ciph && $ciph->enabled ?
Branch: 1 branch
BranchTrueFalseTotal
$ciph && $ciph->enabled ? : 0 0 0
Condition0%0/3
$ciph and $ciph->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph $ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
ABresult
0X0
100
111
224 $ciph->decrypt($p_str) : $p_str );
225 0 $macbuf = $mac->hmac(pack("N", $seqnr) . $buffer->bytes);
226 }
227 0 my $stored_mac = $incoming->bytes(0, $maclen, '');
228 0 ▶ $ssh->fatal_disconnect("Corrupted MAC on input")
Branch: 1 branch
BranchTrueFalseTotal
unless $macbuf eq $stored_mac 0 0 0
229 unless $macbuf eq $stored_mac;
230 # with etm macs, do not decrypt until after mac verified
231 0 ▶ $buffer->append( $ciph && $ciph->enabled ?
Branch: 2 branches
BranchTrueFalseTotal
if $mac->etm 0 0 0
$ciph && $ciph->enabled ? : 0 0 0
Condition0%0/3
$ciph and $ciph->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph $ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
ABresult
0X0
100
111
232 $ciph->decrypt($p_str) : $p_str ) if $mac->etm;
233 } else {
234 0 ▶ $buffer->append( $ciph && $ciph->enabled ?
Branch: 1 branch
BranchTrueFalseTotal
$ciph && $ciph->enabled ? : 0 0 0
Condition0%0/3
$ciph and $ciph->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph $ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
ABresult
0X0
100
111
235 $ciph->decrypt($p_str,$seqnr,$aadlen) : $p_str );
236 }
237  
238 0 $ssh->{session}{seqnr_in}++;
239  
240 0 my $padlen = unpack "C", $buffer->bytes(4-$aadlen, 1);
241 0 ▶ $ssh->fatal_disconnect("Corrupted padlen $padlen on input")
Branch: 1 branch
BranchTrueFalseTotal
unless $padlen >= 4 0 0 0
242 unless $padlen >= 4;
243  
244 # Cut off packet size + padlen, discard padding
245 0 $buffer->bytes(0, 5-$aadlen, '');
246 0 $buffer->bytes(-$padlen, $padlen, '');
247  
248 0 ▶ if ($comp && $comp->enabled) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comp and $comp->enabled) 0 0 0
Condition0%0/3
$comp and $comp->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$comp and $comp->enabled
$comp $comp->enabled
Truth table0%0/3
A and B
A= $compB= $comp->enabled
ABresult
0X0
100
111
249 0 my $inflated = $comp->uncompress($buffer->bytes);
250 0 $buffer->empty;
251 0 $buffer->append($inflated);
252 }
253  
254 0 my $type = unpack "C", $buffer->bytes(0, 1, '');
255 0 $ssh->{session}{_last_packet_length} = 0;
256 0 $class->new($ssh, type => $type, data => $buffer);
257 }
258  
259 sub read_expect {
260 1 ▶ my $class = shift;
Subroutine read_expect: called CC=3 SCAR=12.6
Pod documented
261 1 my($ssh, $type) = @_;
262 1 my $pack = $class->read($ssh);
263 1 ▶ if ($pack->type != $type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pack->type != $type) 1 0 1
264 1 ▶ if ($pack->type == SSH2_MSG_GLOBAL_REQUEST) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pack->type == &SSH2_MSG_GLOBAL_REQUEST()) { } 0 1 1
265 0 $ssh->debug("Unprocessed global request encountered");
266 # now repeat read_expect for expected type
267 0 return $class->read_expect($ssh,$type);
268 } else {
269 1 $ssh->fatal_disconnect(sprintf
270 "Protocol error: expected packet type %d, got %d",
271 $type, $pack->type);
272 }
273 }
274 0 $pack;
275 }
276  
277 sub send {
278 5 ▶ my $pack = shift;
Subroutine send: called CC=2 SCAR=7.6
Pod documented
279 5 ▶ if ($pack->{ssh}->protocol == PROTOCOL_SSH2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pack->{'ssh'}->protocol == &PROTOCOL_SSH2()) { } 0 5 5
280 0 $pack->send_ssh2(@_);
281 }
282 else {
283 5 $pack->send_ssh1(@_);
284 }
285 }
286  
287 sub send_ssh1 {
288 5 ▶ my $pack = shift;
Subroutine send_ssh1: called CC=6 SCAR=18.8
Pod undocumented
289 5 ▶ my $buffer = shift || $pack->{data};
Condition33%1/3
shift() || $pack->{'data'}
l!l&&r!l&&!r
050
MC/DC0%0/2
shift() || $pack->{'data'}
shift() $pack->{'data'}
Truth table33%1/3
A || B
A= shift()B= $pack->{'data'}
ABresult
1X1
011
000
290 5 my $ssh = $pack->{ssh};
291  
292 5 ▶ unless (defined &_crc32) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &Net::SSH::Perl::Packet::_crc32) 1 4 5
293 1 ▶ eval "use Net::SSH::Perl::Util qw( _crc32 );";
Subroutine BEGIN: called CC=1 SCAR=0.0
294 }
295  
296 5 ▶ if ($buffer->length >= MAX_PACKET_SIZE - 30) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer->length >= &MAX_PACKET_SIZE() - 30) 0 5 5
297 0 $ssh->fatal_disconnect(sprintf
298 "Sending too big a packet: size %d, limit %d",
299 $buffer->length, MAX_PACKET_SIZE);
300 }
301  
302 5 ▶ if (my $comp = $ssh->compression) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $comp = $ssh->compression) 0 5 5
303 0 my $compressed = $comp->compress($buffer->bytes);
304 0 $buffer->empty;
305 0 $buffer->append($compressed);
306 }
307  
308 5 my $len = $buffer->length + 4;
309  
310 5 my $cipher = $ssh->send_cipher;
311 #if ($cipher) {
312 5 $buffer->insert_padding;
313 #}
314  
315 5 my $crc = _crc32($buffer->bytes);
316 5 $buffer->put_int32($crc);
317  
318 5 my $output = Net::SSH::Perl::Buffer->new( MP => 'SSH1' );
319 5 $output->put_int32($len);
320 5 ▶ my $data = $cipher ? $cipher->encrypt($buffer->bytes) : $buffer->bytes;
Branch: 1 branch
BranchTrueFalseTotal
$cipher ? : 0 5 5
321 5 $output->put_chars($data);
322  
323 5 my $sock = $ssh->sock;
324 5 syswrite $sock, $output->bytes, $output->length;
325 }
326  
327 sub send_ssh2 {
328 0 ▶ my $pack = shift;
Subroutine send_ssh2: not called CC=26 SCAR=65.5
Pod undocumented
329 0 ▶ my $buffer = shift || $pack->{data};
Condition0%0/3
shift() || $pack->{'data'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $pack->{'data'}
shift() $pack->{'data'}
Truth table0%0/3
A || B
A= shift()B= $pack->{'data'}
ABresult
1X1
011
000
330 0 my $ssh = $pack->{ssh};
331  
332 0 my $kex = $ssh->kex;
333 0 my($ciph, $mac, $comp, $authlen);
334 0 ▶ if ($kex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kex) 0 0 0
335 0 $ciph = $kex->send_cipher;
336 0 $mac = $kex->send_mac;
337 0 $comp = $kex->send_comp;
338 0 ▶ undef $mac if $authlen = $ciph && $ciph->authlen;
Branch: 1 branch
BranchTrueFalseTotal
if $authlen = $ciph && $ciph->authlen 0 0 0
Condition0%0/3
$ciph && $ciph->authlen
!ll&&!rl&&r
000
MC/DC0%0/2
$ciph && $ciph->authlen
$ciph $ciph->authlen
Truth table0%0/3
A && B
A= $ciphB= $ciph->authlen
ABresult
0X0
100
111
339 }
340 0 ▶ my $block_size = $ciph && $ciph->enabled ? $ciph->blocksize : 8;
Branch: 1 branch
BranchTrueFalseTotal
$ciph && $ciph->enabled ? : 0 0 0
Condition0%0/3
$ciph and $ciph->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph $ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
ABresult
0X0
100
111
341 0 ▶ my $aadlen = ($mac && $mac->enabled && $mac->etm) || $authlen ? 4 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$mac && $mac->enabled && $mac->etm || $authlen ? : 0 0 0
Condition0%0/9
$mac and $mac->enabled and $mac->etm or $authlen
l!l&&r!l&&!r
000
$mac and $mac->enabled and $mac->etm
!ll&&!rl&&r
000
$mac and $mac->enabled
!ll&&!rl&&r
000
MC/DC0%0/4
$mac and $mac->enabled and $mac->etm or $authlen
$mac $mac->enabled $mac->etm $authlen
Truth table0%0/7
A and B and C or D
A= $macB= $mac->enabledC= $mac->etmD= $authlen
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
342 0 my $seqnr = $ssh->{session}{seqnr_out};
343  
344 0 ▶ if ($comp && $comp->enabled) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comp and $comp->enabled) 0 0 0
Condition0%0/3
$comp and $comp->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$comp and $comp->enabled
$comp $comp->enabled
Truth table0%0/3
A and B
A= $compB= $comp->enabled
ABresult
0X0
100
111
345 0 my $compressed = $comp->compress($buffer->bytes);
346 0 $buffer->empty;
347 0 $buffer->append($compressed);
348 }
349  
350 0 my $len = $buffer->length + 4 + 1;
351 0 my $padlen = $block_size - (($len - $aadlen) % $block_size);
352 0 ▶ $padlen += $block_size if $padlen < 4;
Branch: 1 branch
BranchTrueFalseTotal
if $padlen < 4 0 0 0
353 0 ▶ my $junk = $ciph ? random_bytes($padlen) : ("\0" x $padlen);
Branch: 1 branch
BranchTrueFalseTotal
$ciph ? : 0 0 0
354 0 $buffer->append($junk);
355  
356 0 my $packet_len = $buffer->length + 1;
357 0 $buffer->bytes(0, 0, pack("C", $padlen));
358 0 ▶ $buffer->bytes(0, 0, pack("N", $packet_len)) unless $mac && $mac->etm;
Branch: 1 branch
BranchTrueFalseTotal
unless $mac and $mac->etm 0 0 0
Condition0%0/3
$mac and $mac->etm
!ll&&!rl&&r
000
MC/DC0%0/2
$mac and $mac->etm
$mac $mac->etm
Truth table0%0/3
A and B
A= $macB= $mac->etm
ABresult
0X0
100
111
359  
360 0 ▶ my $out = $ciph && $ciph->enabled ? $ciph->encrypt($buffer->bytes,$seqnr,$aadlen) : $buffer->bytes;
Branch: 1 branch
BranchTrueFalseTotal
$ciph && $ciph->enabled ? : 0 0 0
Condition0%0/3
$ciph and $ciph->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph $ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
ABresult
0X0
100
111
361 0 ▶ substr($out,0,0,pack("N", $packet_len)) if $mac && $mac->etm;
Branch: 1 branch
BranchTrueFalseTotal
if $mac and $mac->etm 0 0 0
Condition0%0/3
$mac and $mac->etm
!ll&&!rl&&r
000
MC/DC0%0/2
$mac and $mac->etm
$mac $mac->etm
Truth table0%0/3
A and B
A= $macB= $mac->etm
ABresult
0X0
100
111
362  
363 0 my($macbuf);
364 0 ▶ if ($mac && $mac->enabled) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mac and $mac->enabled) 0 0 0
Condition0%0/3
$mac and $mac->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$mac and $mac->enabled
$mac $mac->enabled
Truth table0%0/3
A and B
A= $macB= $mac->enabled
ABresult
0X0
100
111
365 0 ▶ my $data = $mac->etm ? $out : $buffer->bytes;
Branch: 1 branch
BranchTrueFalseTotal
$mac->etm ? : 0 0 0
366 0 $macbuf = $mac->hmac(pack("N", $seqnr) . $data);
367 }
368  
369 0 my $output = Net::SSH::Perl::Buffer->new( MP => 'SSH2' );
370 0 $output->append($out);
371 0 ▶ $output->append($macbuf) if $mac && $mac->enabled;
Branch: 1 branch
BranchTrueFalseTotal
if $mac and $mac->enabled 0 0 0
Condition0%0/3
$mac and $mac->enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$mac and $mac->enabled
$mac $mac->enabled
Truth table0%0/3
A and B
A= $macB= $mac->enabled
ABresult
0X0
100
111
372  
373 0 $ssh->{session}{seqnr_out}++;
374  
375 0 my $sock = $ssh->sock;
376 0 syswrite $sock, $output->bytes, $output->length;
377 }
378  
379 sub type {
380 11 ▶ my $pack = shift;
Subroutine type: called CC=2 SCAR=7.1
Pod documented
381 11 ▶ $pack->{type} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 11 11
382 11 $pack->{type};
383 }
384  
385 0 ▶sub data { $_[0]->{data} }
Subroutine data: not called CC=1 SCAR=6.9
Pod documented
386  
387 5 ▶use vars qw( $AUTOLOAD );
Subroutine BEGIN: called CC=1 SCAR=0.0
388 sub AUTOLOAD {
389 14 ▶ my $pack = shift;
Subroutine AUTOLOAD: called CC=3 SCAR=11.2
390 14 (my $meth = $AUTOLOAD) =~ s/.*://;
391 14 ▶ return if $meth eq "DESTROY";
Branch: 1 branch
BranchTrueFalseTotal
if $meth eq "DESTROY" 10 4 14
392  
393 4 ▶ if ( $pack->{data}->can($meth) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pack->{'data'}->can($meth)) { } 4 0 4
394 4 $pack->{data}->$meth(@_);
395 }
396 else {
397 0 croak "Can't dispatch method $meth to Net::SSH::Perl::Buffer object.";
398 }
399 }
400  
401 5 1;
402 __END__
« blib/lib/Net/SSH/Perl.pm ↑ Summary blib/lib/Net/SSH/Perl/SSH2.pm »