| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | ▶ | $pack->{data} = Net::SSH::Perl::Buffer->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | MP => $ssh->protocol == PROTOCOL_SSH2 ? 'SSH2' : 'SSH1'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | ▶ | if ($pack->{type}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | if (!defined $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | next if $! == EAGAIN || $! == EWOULDBLOCK; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$! == 11 or $! == 11
MC/DC0%0/2
$! == 11 or $! == 11
$! == 11
$! == 11
Truth table0%0/3
A or B
A= $! == 11B= $! == 11
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 5 | my $type = $packet->type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 5 | ▶ | if ($ssh->protocol == PROTOCOL_SSH2) { ## Handle DISCONNECT msg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ($type == SSH2_MSG_DISCONNECT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | croak "Received disconnect message: ", $packet->get_str, "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | ▶ | if ($type == $debug) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | eval "use Net::SSH::Perl::Util qw( _crc32 );"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 9 | my $incoming = $ssh->incoming_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 9 | ▶ | return if $incoming->length < 4 + 8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 5 | my $len = unpack "N", $incoming->bytes(0, 4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 5 | ▶ | $len = 0 unless defined $len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 5 | my $pad_len = ($len + 8) & ~7; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 5 | ▶ | return if $incoming->length < 4 + $pad_len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$ciph && $ciph->authlen
MC/DC0%0/2
$ciph && $ciph->authlen
$ciph
$ciph->authlen
Truth table0%0/3
A && B
A= $ciphB= $ciph->authlen
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | my $maclen = $mac && $mac->enabled ? $mac->len : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mac and $mac->enabled
MC/DC0%0/2
$mac and $mac->enabled
$mac
$mac->enabled
Truth table0%0/3
A and B
A= $macB= $mac->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my $block_size = $ciph && $ciph->enabled ? $ciph->blocksize : 8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ciph and $ciph->enabled
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph
$ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | my $aadlen = ($mac && $mac->enabled && $mac->etm) || $authlen ? 4 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$mac and $mac->enabled and $mac->etm or $authlen
$mac and $mac->enabled and $mac->etm
$mac and $mac->enabled
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | return if $incoming->length < $block_size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my $b = Net::SSH::Perl::Buffer->new( MP => 'SSH2' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ($authlen) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$ciph and $ciph->enabled
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph
$ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$plen < 5 or $plen > 262144
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | croak "padding error: need $need block $block_size" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | if $need % $block_size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | return if ( $aadlen && ($incoming->length < $aadlen + $need + $maclen + $authlen)) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$aadlen and $incoming->length < $aadlen + $need + $maclen + $authlen or not $aadlen and $incoming->length < $need + $block_size + $maclen
$aadlen and $incoming->length < $aadlen + $need + $maclen + $authlen
not $aadlen and $incoming->length < $need + $block_size + $maclen
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$mac and $mac->enabled
MC/DC0%0/2
$mac and $mac->enabled
$mac
$mac->enabled
Truth table0%0/3
A and B
A= $macB= $mac->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if ($mac->etm) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$mac and $mac->enabled
MC/DC0%0/2
$mac and $mac->enabled
$mac
$mac->enabled
Truth table0%0/3
A and B
A= $macB= $mac->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | unless ($mac->etm) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | $buffer->append( $ciph && $ciph->enabled ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ciph and $ciph->enabled
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph
$ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$ciph and $ciph->enabled
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph
$ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | $ciph->decrypt($p_str) : $p_str ) if $mac->etm; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | $buffer->append( $ciph && $ciph->enabled ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ciph and $ciph->enabled
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph
$ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$comp and $comp->enabled
MC/DC0%0/2
$comp and $comp->enabled
$comp
$comp->enabled
Truth table0%0/3
A and B
A= $compB= $comp->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | ▶ | if ($pack->type == SSH2_MSG_GLOBAL_REQUEST) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'}
MC/DC0%0/2
shift() || $pack->{'data'}
shift()
$pack->{'data'}
Truth table33%1/3
A || B
A= shift()B= $pack->{'data'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 5 | my $ssh = $pack->{ssh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 5 | ▶ | unless (defined &_crc32) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'}
MC/DC0%0/2
shift() || $pack->{'data'}
shift()
$pack->{'data'}
Truth table0%0/3
A || B
A= shift()B= $pack->{'data'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$ciph && $ciph->authlen
MC/DC0%0/2
$ciph && $ciph->authlen
$ciph
$ciph->authlen
Truth table0%0/3
A && B
A= $ciphB= $ciph->authlen
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | my $block_size = $ciph && $ciph->enabled ? $ciph->blocksize : 8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ciph and $ciph->enabled
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph
$ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | my $aadlen = ($mac && $mac->enabled && $mac->etm) || $authlen ? 4 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$mac and $mac->enabled and $mac->etm or $authlen
$mac and $mac->enabled and $mac->etm
$mac and $mac->enabled
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my $seqnr = $ssh->{session}{seqnr_out}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | if ($comp && $comp->enabled) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$comp and $comp->enabled
MC/DC0%0/2
$comp and $comp->enabled
$comp
$comp->enabled
Truth table0%0/3
A and B
A= $compB= $comp->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | my $junk = $ciph ? random_bytes($padlen) : ("\0" x $padlen); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$mac and $mac->etm
MC/DC0%0/2
$mac and $mac->etm
$mac
$mac->etm
Truth table0%0/3
A and B
A= $macB= $mac->etm
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | my $out = $ciph && $ciph->enabled ? $ciph->encrypt($buffer->bytes,$seqnr,$aadlen) : $buffer->bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ciph and $ciph->enabled
MC/DC0%0/2
$ciph and $ciph->enabled
$ciph
$ciph->enabled
Truth table0%0/3
A and B
A= $ciphB= $ciph->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | substr($out,0,0,pack("N", $packet_len)) if $mac && $mac->etm; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mac and $mac->etm
MC/DC0%0/2
$mac and $mac->etm
$mac
$mac->etm
Truth table0%0/3
A and B
A= $macB= $mac->etm
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my($macbuf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | if ($mac && $mac->enabled) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mac and $mac->enabled
MC/DC0%0/2
$mac and $mac->enabled
$mac
$mac->enabled
Truth table0%0/3
A and B
A= $macB= $mac->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | my $data = $mac->etm ? $out : $buffer->bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$mac and $mac->enabled
MC/DC0%0/2
$mac and $mac->enabled
$mac
$mac->enabled
Truth table0%0/3
A and B
A= $macB= $mac->enabled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 4 | ▶ | if ( $pack->{data}->can($meth) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||