| 1 | ############################################################################ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # WebSocket support | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ############################################################################ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | package Net::Inspect::L7::HTTP::WebSocket; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Scalar::Util 'weaken'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Carp 'croak'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Digest::SHA 'sha1_base64'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | sub upgrade_websocket { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | my ($self,$conn,$req,$rsp) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upgrade_websocket: called CC=16 SCAR=33.4
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # Websocket: RFC6455, Sec.4.1 Page 16ff | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | my $wskey = $req->{fields}{'sec-websocket-key'} || []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$req->{'fields'}{'sec-websocket-key'} || []
MC/DC0%0/1
$req->{'fields'}{'sec-websocket-key'} || []
$req->{'fields'}{'sec-websocket-key'}
Truth table50%1/2
A
A= $req->{'fields'}{'sec-websocket-key'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | if (@$wskey > 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my %x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | $wskey = [ map { $x{$_}++ ? ():($_) } @$wskey ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # Check request | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | die "no sec-websocket-key given in request" if ! @$wskey; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | die "multiple sec-websocket-key given in request" if @$wskey > 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | die "method must be GET but is $req->{method}" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | if $req->{method} ne 'GET'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | my $v = $req->{fields}{'sec-websocket-version'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | die "no sec-websocket-version field in request" if !$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | die "sec-websocket-version must be 13 not '@$v'" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | if grep { $_ ne '13' } @$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # Check response | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my $wsa = $rsp->{fields}{'sec-websocket-accept'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | if (@$wsa > 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my %x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | $wsa = [ map { $x{$_}++ ? ():($_) } @$wsa ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | die "no sec-websocket-accept given in response" if ! @$wsa; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | die "multiple sec-websocket-accept given in response" if @$wsa > 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # Check that sec-websocket-accept in response matches sec-websocket-key. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # Beware its magic! see RFC6455 page 7. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # sha1_base64 does no padding, so we need to add a single '=' (pad to 4*7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # byte) at the end for comparison. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if ( @$wsa != 1 or $wsa->[0] ne sha1_base64( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$wsa != 1 or $wsa->[0] ne &sha1_base64($wskey->[0] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11') . '='
MC/DC0%0/2
@$wsa != 1 or $wsa->[0] ne &sha1_base64($wskey->[0] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11') . '='
@$wsa != 1
$wsa->[0] ne &sha1_base64($wskey->[0] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11') . '='
Truth table33%1/3
A or B
A= @$wsa != 1B= $wsa->[0] ne &sha1_base64($wskey->[0] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11') . '='
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | $wskey->[0].'258EAFA5-E914-47DA-95CA-C5AB0DC85B11').'=') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | die "sec-websocket-accept does not match sec-websocket-key"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | my @sub; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | weaken($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | for my $dir (0,1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | my $dir = $dir; # old $dir is only alias | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | my $rbuf = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # If $clen is defined we are inside a frame ($current_frame). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # If $clen is not defined all other variables here do not matter. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # Since control messages might be in-between fragmented data messages we | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # need to keep this information for an open data message. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | my ($clen,$clenhi,$current_frame,$data_frame,$ctl_frame,$got_close); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | $sub[$dir] = sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 18 | ▶ | my ($data,$eof,$time) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=78 SCAR=58.8
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 18 | my $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # Handle data gaps. These are only allowed inside data frames. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ############################################################ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 18 | ▶ | if (ref($data)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | ▶ | croak "unknown type $data->[0]" if $data->[0] ne 'gap'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 5 | my $gap = $data->[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | ▶ | if (!defined $clen) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $err = "gap outside websocket frame"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | goto bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | ▶ | if (!$data_frame || $current_frame != $data_frame) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $data_frame or $current_frame != $data_frame
MC/DC0%0/2
not $data_frame or $current_frame != $data_frame
not $data_frame
$current_frame != $data_frame
Truth table33%1/3
not(A) or B
A= not $data_frameB= $current_frame != $data_frame
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $err = "gap inside control frame"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | goto bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 5 | my $eom = 0; # end of message on end-of-frame + FIN frame | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 5 | ▶ | while ($gap>0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | ▶ | if ($clen == 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if (!$clenhi) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $err = "gap larger than frame size"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | goto bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $clenhi--; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $clen = 0xffffffff; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $gap--; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | $current_frame->{mask_offset} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | = (($current_frame->{mask_offset}||0) + 1) % 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$current_frame->{'mask_offset'} || 0
MC/DC0%0/1
$current_frame->{'mask_offset'} || 0
$current_frame->{'mask_offset'}
Truth table0%0/2
A
A= $current_frame->{'mask_offset'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } elsif ($gap > $clen) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $gap -= $clen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | $current_frame->{mask_offset} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | = (($current_frame->{mask_offset}||0) + $clen) % 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$current_frame->{'mask_offset'} || 0
MC/DC0%0/1
$current_frame->{'mask_offset'} || 0
$current_frame->{'mask_offset'}
Truth table0%0/2
A
A= $current_frame->{'mask_offset'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $clen = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } else { # $gap <= $clen | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 5 | $clen -= $gap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | $current_frame->{mask_offset} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 5 | ▶ | = (($current_frame->{mask_offset}||0) + $gap) % 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$current_frame->{'mask_offset'} || 0
MC/DC100%1/1
$current_frame->{'mask_offset'} || 0
$current_frame->{'mask_offset'}
Truth table100%2/2
A
A= $current_frame->{'mask_offset'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 5 | $gap = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 5 | ▶ | if (!$clen && !$clenhi) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$clen or $clenhi
MC/DC0%0/2
$clen or $clenhi
$clen
$clenhi
Truth table33%1/3
A or B
A= $clenB= $clenhi
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # frame done | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $eom = $data_frame->{fin} ? 1:0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $clen = undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | ▶ | if (defined $clen) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 5 | $data_frame->{bytes_left} = [$clenhi,$clen]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | delete $data_frame->{bytes_left}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 5 | $self->in_wsdata($dir,$data,$eom,$time,$data_frame); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 5 | ▶ | if ($eom) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $data_frame = $current_frame = undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $conn->set_gap_diff($dir,undef); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 5 | delete $data_frame->{init}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 5 | delete $data_frame->{header}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 5 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 13 | $rbuf .= $data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | PARSE_DATA: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # data for existing frame | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ############################################################ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 21 | ▶ | if (defined $clen) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 10 | my $size = length($rbuf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 10 | ▶ | if (!$size and $clen || $clenhi and $eof) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
not $size and $clen || $clenhi and $eof
not $size and $clen || $clenhi
$clen or $clenhi
MC/DC0%0/4
not $size and $clen || $clenhi and $eof
not $size
$clen
$clenhi
$eof
Truth table33%2/6
not(A) and B or C and D
A= not $sizeB= $clenC= $clenhiD= $eof
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $err = "eof inside websocket frame"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | goto bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 10 | my $fwd = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 10 | my $eom = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 10 | ▶ | while ($size>0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 9 | ▶ | if ($clen == 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | last if !$clenhi; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $clenhi--; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $clen = 0xffffffff; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $size--; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $fwd .= substr($rbuf,0,1,''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } elsif ($size > $clen) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $size -= $clen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $fwd .= substr($rbuf,0,$clen,''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $clen = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } else { # $size < $clen | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 9 | $clen -= $size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 9 | $size = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 9 | $fwd .= $rbuf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 9 | $rbuf = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 10 | ▶ | if (!$clen && !$clenhi) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$clen or $clenhi
MC/DC50%1/2
$clen or $clenhi
$clen
$clenhi
Truth table66%2/3
A or B
A= $clenB= $clenhi
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # frame done | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 8 | ▶ | $eom = $current_frame->{fin} ? 1:0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 8 | $clen = undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 10 | ▶ | if ($data_frame && $current_frame == $data_frame) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$data_frame and $current_frame == $data_frame
MC/DC100%2/2
$data_frame and $current_frame == $data_frame
$data_frame
$current_frame == $data_frame
Truth table100%3/3
A and B
A= $data_frameB= $current_frame == $data_frame
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 6 | ▶ | if (defined $clen) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | $data_frame->{bytes_left} = [$clenhi,$clen]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 4 | delete $data_frame->{bytes_left}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 6 | $self->in_wsdata($dir,$fwd,$eom,$time,$data_frame); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 6 | ▶ | if ($eom) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 2 | $data_frame = undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 4 | delete $data_frame->{init}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | delete $data_frame->{header}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | $current_frame->{mask_offset} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | ▶ | = (($current_frame->{mask_offset}||0) + length($fwd)) % 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$current_frame->{'mask_offset'} || 0
MC/DC0%0/1
$current_frame->{'mask_offset'} || 0
$current_frame->{'mask_offset'}
Truth table50%1/2
A
A= $current_frame->{'mask_offset'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | if defined $clen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # Control frames are read in full and we make sure about | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # this when reading the header already. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 4 | ▶ | die "expected to read full control frame" if defined $clen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 4 | ▶ | if ($current_frame->{opcode} == 0x8) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # extract status + reason for close | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | ▶ | if ($fwd eq '') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $current_frame->{status} = 1005; # RFC6455, 7.1.5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } elsif (length($fwd) < 2) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # if payload it must be at least 2 byte for status | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $err = "invalid length for close control frame"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | goto bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | ($current_frame->{status},$current_frame->{reason}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 2 | = unpack("na*",$current_frame->unmask($fwd)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | $self->in_wsctl($dir,$fwd,$time,$current_frame); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 10 | ▶ | goto done if !$size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | goto PARSE_DATA; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # start of new frame: read frame header | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | ############################################################ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 11 | ▶ | goto done if $eof; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 9 | ▶ | goto hdr_need_more if length($rbuf)<2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 9 | (my $flags,$clen) = unpack("CC",$rbuf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 9 | my $mask = $clen & 0x80; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 9 | $clen &= 0x7f; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 9 | $clenhi = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 9 | my $off = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 9 | ▶ | if ($clen == 126) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | ▶ | goto hdr_need_more if length($rbuf)<4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | ($clen) = unpack("xxn",$rbuf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | ▶ | goto bad_length if $clen<126; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | $off = 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } elsif ($clen == 127) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 2 | ▶ | goto hdr_need_more if length($rbuf)<10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | ($clenhi,$clen) = unpack("xxNN",$rbuf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 2 | ▶ | goto bad_length if !$clenhi && $clen<2**16; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $clenhi and $clen < 65536
MC/DC0%0/2
not $clenhi and $clen < 65536
not $clenhi
$clen < 65536
Truth table33%1/3
not(A) and B
A= not $clenhiB= $clen < 65536
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 2 | $off = 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 9 | ▶ | if ($mask) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 7 | ▶ | goto hdr_need_more if length($rbuf)<$off+4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 6 | ($mask) = unpack("x${off}a4",$rbuf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 6 | $off+=4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 2 | $mask = undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 8 | my $opcode = $flags & 0b00001111; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 8 | my $fin = $flags & 0b10000000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 8 | ▶ | goto reserved_flag if $flags & 0b01110000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 8 | ▶ | if ($opcode >= 0x8) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # control frame | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 4 | ▶ | goto reserved_opcode if $opcode >= 0xb; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | ▶ | if (!$fin) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $err = "fragmented control frames are forbidden"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | goto bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 4 | ▶ | if ($clenhi || $clen>125) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$clenhi or $clen > 125
MC/DC0%0/2
$clenhi or $clen > 125
$clenhi
$clen > 125
Truth table33%1/3
A or B
A= $clenhiB= $clen > 125
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | $err = "control frames should be <= 125 bytes"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | goto bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # We like to forward control frames as a single entity, so make | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # sure we get the whole (small) frame at once. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 4 | ▶ | goto hdr_need_more if $off+$clen > length($rbuf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | ▶ | $current_frame = $ctl_frame | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$ctl_frame ||= "Net::Inspect::L7::HTTP::WebSocket::_WSFrame"->new
MC/DC0%0/2
$ctl_frame ||= "Net::Inspect::L7::HTTP::WebSocket::_WSFrame"->new
$ctl_frame
"Net::Inspect::L7::HTTP::WebSocket::_WSFrame"->new
Truth table66%2/3
A ||= B
A= $ctl_frameB= "Net::Inspect::L7::HTTP::WebSocket::_WSFrame"->new
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | ||= Net::Inspect::L7::HTTP::WebSocket::_WSFrame->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 4 | ▶ | %$current_frame = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | opcode => $opcode, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | defined($mask) ? ( mask => $mask ):() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 4 | ▶ | $got_close = 1 if $opcode == 0x8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } elsif ($opcode>0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # data frame, but no continuation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 2 | ▶ | goto reserved_opcode if $opcode >= 0x3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | ▶ | if ($got_close) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $err = "data frame after close"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | goto bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | ▶ | if ($data_frame) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | $err = "new data message before end of previous message"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | goto bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 2 | $current_frame = $data_frame | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | = Net::Inspect::L7::HTTP::WebSocket::_WSFrame->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 2 | ▶ | %$current_frame = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | opcode => $opcode, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | $fin ? ( fin => 1 ):(), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | init => 1, # initial data | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | defined($mask) ? ( mask => $mask ):() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # continuation frame | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 2 | ▶ | if (!$data_frame) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $err = "continuation frame without previous data frame"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | goto bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | $current_frame = $data_frame; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | %$current_frame = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | opcode => $data_frame->{opcode}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 2 | ▶ | $fin ? ( fin => 1 ):(), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | defined($mask) ? ( mask => $mask ):() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # done with frame header | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 8 | $current_frame->{header} = substr($rbuf,0,$off,''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 8 | goto PARSE_DATA; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # Done | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | ############################################################ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | hdr_need_more: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | $clen = undef; # re-read from start if frame next time | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | done: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 12 | ▶ | if ($eof) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # forward eof as special wsctl with no frame | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # FIXME: complain if we have eof but the current frame is not | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # done yet. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | $self->in_wsctl($dir,'',$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } elsif (defined $clen) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # We have at least the header of a data frame (control frames | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # are read as a single entity) and might need more data | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # (clen>0). Set gap_diff. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 2 | ▶ | $clen>0 and $conn->set_gap_diff($dir, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | ! $clenhi ? $clen : # len <=32 bit | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 << 32 == 1 ? 0xffffffff : # maxint on 32-bit platform | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | ($clenhi << 32) + $clen # full 64 bit | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 12 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | bad_length: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$err ||= "non-minimal length representation in websocket frame"
MC/DC0%0/1
$err ||= "non-minimal length representation in websocket frame"
$err
Truth table0%0/2
A
A= $err
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | $err ||= "non-minimal length representation in websocket frame"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | reserved_flag: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$err ||= "extensions using reserved flags are not supported"
MC/DC0%0/1
$err ||= "extensions using reserved flags are not supported"
$err
Truth table0%0/2
A
A= $err
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | $err ||= "extensions using reserved flags are not supported"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | reserved_opcode: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$err ||= "no support for opcode $opcode"
MC/DC0%0/1
$err ||= "no support for opcode $opcode"
$err
Truth table0%0/2
A
A= $err
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | $err ||= "no support for opcode $opcode"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | bad: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $conn->{error} = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | $self->fatal($err,$dir,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | return sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 18 | ▶ | my $dir = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 18 | goto &{$sub[$dir]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | package Net::Inspect::L7::HTTP::WebSocket::_WSFrame; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 4 | ▶ | sub new { bless {}, shift }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | sub unmask { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 11 | ▶ | my ($self,$data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unmask: called CC=4 SCAR=13.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 11 | ▶ | return $data if $data eq '' or ! $self->{mask}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$data eq "" or not $self->{"mask"}
MC/DC50%1/2
$data eq "" or not $self->{"mask"}
$data eq ""
not $self->{"mask"}
Truth table66%2/3
A or not(B)
A= $data eq ""B= not $self->{"mask"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 8 | my $l = length($data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 8 | ▶ | $data ^= substr($self->{mask} x int($l/4+2),$self->{mask_offset}||0,$l); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'mask_offset'} || 0
MC/DC100%1/1
$self->{'mask_offset'} || 0
$self->{'mask_offset'}
Truth table100%2/2
A
A= $self->{'mask_offset'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 8 | return $data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||