| 1 | # Copyright (c) 2003-2009 Graham Barr, Djamel Boudjerda, Paul Connolly, Julian | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Onions, Nexor and Yann Kerherve. | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # All rights reserved. This program is free software; you can redistribute | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | # See http://www.ietf.org/rfc/rfc2831.txt for details | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | package Authen::SASL::Perl::DIGEST_MD5 2.2100; | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use vars qw(@ISA $CNONCE $NONCE); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Crypt::URandom qw(urandom); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Digest::MD5 qw(md5_hex md5); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use Digest::HMAC_MD5 qw(hmac_md5); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | warnings::warnif( | |||||||||||||||||||||||||||||||||||||||||
| 18 | 'deprecated', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 'The DIGEST-MD5 SASL mechanism is deprecated by RFC6331 and should no longer be used' | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # TODO: complete qop support in server, should be configurable | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | @ISA = qw(Authen::SASL::Perl); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | my %secflags = ( | |||||||||||||||||||||||||||||||||||||||||
| 27 | noplaintext => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | noanonymous => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # some have to be quoted - some don't - sigh! | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | my (%cqdval, %sqdval); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | @cqdval{qw( | |||||||||||||||||||||||||||||||||||||||||
| 34 | username authzid realm nonce cnonce digest-uri | ||||||||||||||||||||||||||||||||||||||||||
| 35 | )} = (); | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | ## ...and server behaves different than client - double sigh! | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | @sqdval{keys %cqdval, qw(qop cipher)} = (); | |||||||||||||||||||||||||||||||||||||||||
| 39 | # username authzid realm nonce cnonce digest-uri qop cipher | ||||||||||||||||||||||||||||||||||||||||||
| 40 | #)} = (); | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | my %multi; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | @{$multi{server}}{qw(realm auth-param)} = (); | |||||||||||||||||||||||||||||||||||||||||
| 44 | 5 | @{$multi{client}}{qw()} = (); | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 5 | my @server_required = qw(algorithm nonce); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 5 | my @client_required = qw(username nonce cnonce nc qop response); | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # available ciphers | ||||||||||||||||||||||||||||||||||||||||||
| 50 | my @ourciphers = ( | ||||||||||||||||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||||||||||||||||
| 52 | name => 'rc4', | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ssf => 128, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | bs => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ks => 16, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | pkg => 'Crypt::RC4', | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | key => sub { $_[0] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | iv => sub {}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | fixup => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | # retrofit the Crypt::RC4 module with standard subs | ||||||||||||||||||||||||||||||||||||||||||
| 61 | *Crypt::RC4::encrypt = *Crypt::RC4::decrypt = | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub { goto &Crypt::RC4::RC4; }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | *Crypt::RC4::keysize = sub {128}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | *Crypt::RC4::blocksize = sub {1}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | name => '3des', | ||||||||||||||||||||||||||||||||||||||||||
| 69 | ssf => 112, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | bs => 8, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | ks => 16, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | pkg => 'Crypt::DES3', | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | key => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | pack('B8' x 16, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | map { $_ . '0' } | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | map { unpack('a7' x 16, $_); } | |||||||||||||||||||||||||||||||||||||||||
| 77 | unpack('B*', substr($_[0], 0, 14)) ); | ||||||||||||||||||||||||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | iv => sub { substr($_[0], -8, 8) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | name => 'des', | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ssf => 56, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | bs => 8, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | ks => 16, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | pkg => 'Crypt::DES', | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | key => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | pack('B8' x 8, | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | map { $_ . '0' } | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | map { unpack('a7' x 8, $_); } | |||||||||||||||||||||||||||||||||||||||||
| 91 | unpack('B*',substr($_[0], 0, 7)) ); | ||||||||||||||||||||||||||||||||||||||||||
| 92 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | iv => sub { substr($_[0], -8, 8) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | name => 'rc4-56', | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ssf => 56, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | bs => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | ks => 7, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | pkg => 'Crypt::RC4', | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | key => sub { $_[0] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | iv => sub {}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | fixup => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | *Crypt::RC4::encrypt = *Crypt::RC4::decrypt = | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub { goto &Crypt::RC4::RC4; }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | *Crypt::RC4::keysize = sub {56}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | *Crypt::RC4::blocksize = sub {1}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | name => 'rc4-40', | ||||||||||||||||||||||||||||||||||||||||||
| 112 | ssf => 40, | ||||||||||||||||||||||||||||||||||||||||||
| 113 | bs => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | ks => 5, | ||||||||||||||||||||||||||||||||||||||||||
| 115 | pkg => 'Crypt::RC4', | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | key => sub { $_[0] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | iv => sub {}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | fixup => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | *Crypt::RC4::encrypt = *Crypt::RC4::decrypt = | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub { goto &Crypt::RC4::RC4; }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | *Crypt::RC4::keysize = sub {40}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | *Crypt::RC4::blocksize = sub {1}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | ## The system we are on, might not be able to crypt the stream | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 5 | our $NO_CRYPT_AVAILABLE = 1; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 5 | for (@ourciphers) { | |||||||||||||||||||||||||||||||||||||||||
| 130 | 25 | eval "require $_->{pkg}"; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 25 | ▶ | unless ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $NO_CRYPT_AVAILABLE = 0; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 16 | ▶ | sub _order { 3 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_order: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 12 | ▶ | sub _secflags { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_secflags: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 12 | shift; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 12 | scalar grep { $secflags{$_} } @_; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 9 | ▶ | sub mechanism { 'DIGEST-MD5' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mechanism: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 22 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 22 | my ($pkg, $self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 22 | bless $self, $pkg; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | # set default security properties | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 22 | $self->property('minssf', 0); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 22 | $self->property('maxssf', int 2**31 - 1); # XXX - arbitrary "high" value | |||||||||||||||||||||||||||||||||||||||||
| 152 | 22 | $self->property('maxbuf', 0xFFFFFF); # maximum supported by GSSAPI mech | |||||||||||||||||||||||||||||||||||||||||
| 153 | 22 | $self->property('externalssf', 0); | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 22 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 10 | ▶ | sub _init_server { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_server: called CC=8 SCAR=22.5
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 10 | my $server = shift; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 10 | ▶ | my $options = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 10 | ▶ | if (!ref $options or ref $options ne 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $options or ref $options ne "HASH"
MC/DC0%0/2
not ref $options or ref $options ne "HASH"
not ref $options
ref $options ne "HASH"
Truth table33%1/3
not(A) or B
A= not ref $optionsB= ref $options ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | warn "options for DIGEST_MD5 should be a hashref"; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $options = {}; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | ## new server, means new nonce_counts | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 10 | $server->{nonce_counts} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | ## determine supported qop | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 10 | my @qop = ('auth'); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 10 | ▶ | push @qop, 'auth-int' unless $options->{no_integrity}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | push @qop, 'auth-conf' unless $options->{no_integrity} | ||||||||||||||||||||||||||||||||||||||||||
| 173 | or $options->{no_confidentiality} | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 10 | ▶ | or $NO_CRYPT_AVAILABLE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$options->{"no_integrity"} or $options->{"no_confidentiality"} or $Authen::SASL::Perl::DIGEST_MD5::NO_CRYPT_AVAILABLE
$options->{"no_integrity"} or $options->{"no_confidentiality"}
MC/DC0%0/3
$options->{"no_integrity"} or $options->{"no_confidentiality"} or $Authen::SASL::Perl::DIGEST_MD5::NO_CRYPT_AVAILABLE
$options->{"no_integrity"}
$options->{"no_confidentiality"}
$Authen::SASL::Perl::DIGEST_MD5::NO_CRYPT_AVAILABLE
Truth table50%2/4
A or B or C
A= $options->{"no_integrity"}B= $options->{"no_confidentiality"}C= $Authen::SASL::Perl::DIGEST_MD5::NO_CRYPT_AVAILABLE
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 10 | $server->{supported_qop} = { map { $_ => 1 } @qop }; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 18 | ▶ | sub init_sec_layer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_sec_layer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 18 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 18 | $self->{cipher} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 18 | $self->{khc} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 18 | $self->{khs} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 18 | $self->{sndseqnum} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 18 | $self->{rcvseqnum} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | # reset properties for new session | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 18 | $self->property(maxout => undef); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 18 | $self->property(ssf => undef); | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | # no initial value passed to the server | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 7 | ▶ | sub client_start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
client_start: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 7 | $self->{need_step} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 7 | $self->{error} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 7 | $self->{state} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 7 | $self->init_sec_layer; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 7 | ''; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 11 | ▶ | sub server_start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server_start: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 11 | my $challenge = shift; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 11 | ▶ | my $cb = shift || sub {}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Condition66%2/3
shift() || sub {
}
MC/DC0%0/2
shift() || sub {
}
shift()
sub {
}
Truth table66%2/3
A || B
A= shift()B= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 11 | $self->{need_step} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 11 | $self->{error} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 11 | ▶ | $self->{nonce} = $NONCE ? md5_hex($NONCE) : unpack('H32',urandom(16)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 11 | $self->init_sec_layer; | |||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 11 | my $qop = [ sort keys %{$self->{supported_qop}} ]; | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | ## get the realm using callbacks but default to the host specified | ||||||||||||||||||||||||||||||||||||||||||
| 217 | ## during the instantiation of the SASL object | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 11 | my $realm = $self->_call('realm'); | |||||||||||||||||||||||||||||||||||||||||
| 219 | 11 | ▶ | $realm ||= $self->host; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$realm ||= $self->host
MC/DC0%0/2
$realm ||= $self->host
$realm
$self->host
Truth table33%1/3
A ||= B
A= $realmB= $self->host
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | my %response = ( | ||||||||||||||||||||||||||||||||||||||||||
| 222 | nonce => $self->{nonce}, | ||||||||||||||||||||||||||||||||||||||||||
| 223 | charset => 'utf-8', | ||||||||||||||||||||||||||||||||||||||||||
| 224 | algorithm => 'md5-sess', | ||||||||||||||||||||||||||||||||||||||||||
| 225 | realm => $realm, | ||||||||||||||||||||||||||||||||||||||||||
| 226 | maxbuf => $self->property('maxbuf'), | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | ## IN DRAFT ONLY: | ||||||||||||||||||||||||||||||||||||||||||
| 229 | # If this directive is present multiple times the client MUST treat | ||||||||||||||||||||||||||||||||||||||||||
| 230 | # it as if it received a single qop directive containing a comma | ||||||||||||||||||||||||||||||||||||||||||
| 231 | # separated value from all instances. I.e., | ||||||||||||||||||||||||||||||||||||||||||
| 232 | # 'qop="auth",qop="auth-int"' is the same as 'qop="auth,auth-int" | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 'qop' => $qop, | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 11 | 'cipher' => [ map { $_->{name} } @ourciphers ], | |||||||||||||||||||||||||||||||||||||||||
| 236 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 11 | my $final_response = _response(\%response); | |||||||||||||||||||||||||||||||||||||||||
| 238 | 11 | $cb->($final_response); | |||||||||||||||||||||||||||||||||||||||||
| 239 | 11 | return; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 11 | ▶ | sub client_step { # $self, $server_sasl_credentials | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
client_step: called CC=16 SCAR=28.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 11 | my ($self, $challenge) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 11 | $self->{server_params} = \my %sparams; | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | # Parse response parameters | ||||||||||||||||||||||||||||||||||||||||||
| 247 | $self->_parse_challenge(\$challenge, server => $self->{server_params}) | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 11 | ▶ | or return $self->set_error("Bad challenge: '$challenge'"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 11 | ▶ | if ($self->{state} == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | # check server's `rspauth' response | ||||||||||||||||||||||||||||||||||||||||||
| 252 | return $self->set_error("Server did not send rspauth in step 2") | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | ▶ | unless ($sparams{rspauth}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | return $self->set_error("Invalid rspauth in step 2") | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 4 | ▶ | unless ($self->{rspauth} eq $sparams{rspauth}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | # all is well | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 4 | $self->set_success; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 4 | return ''; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | # check required fields in server challenge | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 7 | ▶ | if (my @missing = grep { !exists $sparams{$_} } @server_required) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | return $self->set_error("Server did not provide required field(s): @missing") | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | my %response = ( | ||||||||||||||||||||||||||||||||||||||||||
| 268 | nonce => $sparams{'nonce'}, | ||||||||||||||||||||||||||||||||||||||||||
| 269 | cnonce => $CNONCE ? md5_hex($CNONCE) : unpack('H32',urandom(16)), | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 'digest-uri' => $self->service . '/' . $self->host, | ||||||||||||||||||||||||||||||||||||||||||
| 271 | # calc how often the server nonce has been seen; server expects "00000001" | ||||||||||||||||||||||||||||||||||||||||||
| 272 | nc => sprintf("%08d", ++$self->{nonce_counts}{$sparams{'nonce'}}), | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 7 | ▶ | charset => $sparams{'charset'}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 7 | ▶ | return $self->set_error("Server qop too weak (qop = $sparams{'qop'})") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | unless ($self->_client_layer(\%sparams,\%response)); | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | # let caller-provided fields override defaults: authorization ID, service name, realm | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 7 | ▶ | my $s_realm = $sparams{realm} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sparams{'realm'} || []
MC/DC0%0/1
$sparams{'realm'} || []
$sparams{'realm'}
Truth table50%1/2
A
A= $sparams{'realm'}
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 7 | my $realm = $self->_call('realm', @$s_realm); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 7 | ▶ | unless (defined $realm) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | # If the user does not pick a realm, use the first from the server | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 7 | $realm = $s_realm->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 7 | ▶ | if (defined $realm) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 7 | $response{realm} = $realm; | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 7 | my $authzid = $self->_call('authname'); | |||||||||||||||||||||||||||||||||||||||||
| 292 | 7 | ▶ | if (defined $authzid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 2 | $response{authzid} = $authzid; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 7 | my $serv_name = $self->_call('serv'); | |||||||||||||||||||||||||||||||||||||||||
| 297 | 7 | ▶ | if (defined $serv_name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $response{'digest-uri'} .= '/' . $serv_name; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 7 | my $user = $self->_call('user'); | |||||||||||||||||||||||||||||||||||||||||
| 302 | 7 | ▶ | return $self->set_error("Username is required") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | unless defined $user; | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 7 | $response{username} = $user; | |||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 7 | my $password = $self->_call('pass'); | |||||||||||||||||||||||||||||||||||||||||
| 307 | 7 | ▶ | return $self->set_error("Password is required") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | unless defined $password; | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 7 | ▶ | $self->property('maxout', $sparams{maxbuf} || 65536); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$sparams{'maxbuf'} || 65536
MC/DC100%1/1
$sparams{'maxbuf'} || 65536
$sparams{'maxbuf'}
Truth table100%2/2
A
A= $sparams{'maxbuf'}
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | # Generate the response value | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 7 | $self->{state} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 7 | my ($response, $rspauth) | |||||||||||||||||||||||||||||||||||||||||
| 316 | = $self->_compute_digests_and_set_keys($password, \%response); | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 7 | $response{response} = $response; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 7 | $self->{rspauth} = $rspauth; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | # finally, return our response token | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 7 | return _response(\%response, "is_client"); | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 13 | ▶ | sub _compute_digests_and_set_keys { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compute_digests_and_set_keys: called CC=9 SCAR=26.3
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 13 | my $password = shift; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 13 | my $params = shift; | |||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 13 | ▶ | if (defined $params->{realm} and ref $params->{realm} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $params->{"realm"} and ref $params->{"realm"} eq "ARRAY"
MC/DC0%0/2
defined $params->{"realm"} and ref $params->{"realm"} eq "ARRAY"
defined $params->{"realm"}
ref $params->{"realm"} eq "ARRAY"
Truth table33%1/3
A and B
A= defined $params->{"realm"}B= ref $params->{"realm"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $params->{realm} = $params->{realm}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 13 | my $realm = $params->{realm}; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 13 | ▶ | $realm = "" unless defined $realm; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | my $A1 = join (":", | ||||||||||||||||||||||||||||||||||||||||||
| 338 | md5(join (":", $params->{username}, $realm, $password)), | ||||||||||||||||||||||||||||||||||||||||||
| 339 | @$params{defined($params->{authzid}) | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 13 | ▶ | ? qw(nonce cnonce authzid) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | : qw(nonce cnonce) | ||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | # pre-compute MD5(A1) and HEX(MD5(A1)); these are used multiple times below | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 13 | my $hdA1 = unpack("H*", (my $dA1 = md5($A1)) ); | |||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | # derive keys for layer encryption / integrity | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 13 | $self->{kic} = md5($dA1, | |||||||||||||||||||||||||||||||||||||||||
| 350 | 'Digest session key to client-to-server signing key magic constant'); | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 13 | $self->{kis} = md5($dA1, | |||||||||||||||||||||||||||||||||||||||||
| 353 | 'Digest session key to server-to-client signing key magic constant'); | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 13 | ▶ | if (my $cipher = $self->{cipher}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | &{ $cipher->{fixup} || sub{} }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$cipher->{'fixup'} || sub {
}
MC/DC0%0/2
$cipher->{'fixup'} || sub {
}
$cipher->{'fixup'}
sub {
}
Truth table0%0/3
A || B
A= $cipher->{'fixup'}B= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | # compute keys for encryption | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my $ks = $cipher->{ks}; | |||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $self->{kcc} = md5(substr($dA1,0,$ks), | |||||||||||||||||||||||||||||||||||||||||
| 361 | 'Digest H(A1) to client-to-server sealing key magic constant'); | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $self->{kcs} = md5(substr($dA1,0,$ks), | |||||||||||||||||||||||||||||||||||||||||
| 363 | 'Digest H(A1) to server-to-client sealing key magic constant'); | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | # get an encryption and decryption handle for the chosen cipher | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $self->{khc} = $cipher->{pkg}->new($cipher->{key}->($self->{kcc})); | |||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $self->{khs} = $cipher->{pkg}->new($cipher->{key}->($self->{kcs})); | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | # initialize IVs | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $self->{ivc} = $cipher->{iv}->($self->{kcc}); | |||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $self->{ivs} = $cipher->{iv}->($self->{kcs}); | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 13 | my $A2 = "AUTHENTICATE:" . $params->{'digest-uri'}; | |||||||||||||||||||||||||||||||||||||||||
| 375 | 13 | ▶ | $A2 .= ":00000000000000000000000000000000" if ($params->{qop} ne 'auth'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | my $response = md5_hex( | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 13 | join (":", $hdA1, @$params{qw(nonce nc cnonce qop)}, md5_hex($A2)) | |||||||||||||||||||||||||||||||||||||||||
| 379 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | # calculate server `rspauth' response, so we can check in step 2 | ||||||||||||||||||||||||||||||||||||||||||
| 382 | # the only difference here is in the A2 string which from which | ||||||||||||||||||||||||||||||||||||||||||
| 383 | # `AUTHENTICATE' is omitted in the calculation of `rspauth' | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 13 | $A2 = ":" . $params->{'digest-uri'}; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 13 | ▶ | $A2 .= ":00000000000000000000000000000000" if ($params->{qop} ne 'auth'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | my $rspauth = md5_hex( | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 13 | join (":", $hdA1, @$params{qw(nonce nc cnonce qop)}, md5_hex($A2)) | |||||||||||||||||||||||||||||||||||||||||
| 389 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 13 | return ($response, $rspauth); | |||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 10 | ▶ | sub server_step { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server_step: called CC=16 SCAR=30.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 10 | my $challenge = shift; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 10 | ▶ | my $cb = shift || sub {}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Condition66%2/3
shift() || sub {
}
MC/DC0%0/2
shift() || sub {
}
shift()
sub {
}
Truth table66%2/3
A || B
A= shift()B= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 10 | $self->{client_params} = \my %cparams; | |||||||||||||||||||||||||||||||||||||||||
| 400 | 10 | ▶ | unless ( $self->_parse_challenge(\$challenge, client => $self->{client_params}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 1 | $self->set_error("Bad challenge: '$challenge'"); | |||||||||||||||||||||||||||||||||||||||||
| 402 | 1 | return $cb->(); | |||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | # check required fields in server challenge | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 9 | ▶ | if (my @missing = grep { !exists $cparams{$_} } @client_required) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | $self->set_error("Client did not provide required field(s): @missing"); | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | return $cb->(); | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | # RFC 2831 section 2.1.2: the nonce in the digest-response is "the | ||||||||||||||||||||||||||||||||||||||||||
| 412 | # server-specified data string received in the preceding digest-challenge". | ||||||||||||||||||||||||||||||||||||||||||
| 413 | # The replay resistance of section 3.3 rests on the server binding the | ||||||||||||||||||||||||||||||||||||||||||
| 414 | # response to the nonce it issued, so check that before anything else uses | ||||||||||||||||||||||||||||||||||||||||||
| 415 | # the client-supplied value. | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 9 | ▶ | unless (defined $self->{nonce} and $cparams{nonce} eq $self->{nonce}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"nonce"} and $cparams{"nonce"} eq $self->{"nonce"}
MC/DC50%1/2
defined $self->{"nonce"} and $cparams{"nonce"} eq $self->{"nonce"}
defined $self->{"nonce"}
$cparams{"nonce"} eq $self->{"nonce"}
Truth table66%2/3
A and B
A= defined $self->{"nonce"}B= $cparams{"nonce"} eq $self->{"nonce"}
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 1 | $self->set_error("nonce does not match the one issued"); | |||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | return $cb->(); | |||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 8 | ▶ | my $count = hex ($cparams{'nc'} || 0); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$cparams{'nc'} || 0
MC/DC0%0/1
$cparams{'nc'} || 0
$cparams{'nc'}
Truth table50%1/2
A
A= $cparams{'nc'}
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 8 | ▶ | unless ($count == ++$self->{nonce_counts}{$cparams{nonce}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | $self->set_error("nonce-count doesn't match: $count"); | |||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | return $cb->(); | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 8 | ▶ | my $qop = $cparams{'qop'} || "auth"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$cparams{'qop'} || 'auth'
MC/DC0%0/1
$cparams{'qop'} || 'auth'
$cparams{'qop'}
Truth table50%1/2
A
A= $cparams{'qop'}
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 8 | ▶ | unless ($self->is_qop_supported($qop)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | $self->set_error("Client qop not supported (qop = '$qop')"); | |||||||||||||||||||||||||||||||||||||||||
| 430 | 1 | return $cb->(); | |||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 7 | my $username = $cparams{'username'}; | |||||||||||||||||||||||||||||||||||||||||
| 434 | 7 | ▶ | unless ($username) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | $self->set_error("Client didn't provide a username"); | |||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | return $cb->(); | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | # "The authzid MUST NOT be an empty string." | ||||||||||||||||||||||||||||||||||||||||||
| 440 | 7 | ▶ | if (exists $cparams{authzid} && $cparams{authzid} eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $cparams{"authzid"} and $cparams{"authzid"} eq ""
MC/DC0%0/2
exists $cparams{"authzid"} and $cparams{"authzid"} eq ""
exists $cparams{"authzid"}
$cparams{"authzid"} eq ""
Truth table66%2/3
A and B
A= exists $cparams{"authzid"}B= $cparams{"authzid"} eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | $self->set_error("authzid cannot be empty"); | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | return $cb->(); | |||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 7 | my $authzid = $cparams{authzid}; | |||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | # digest-uri: "Servers SHOULD check that the supplied value is correct. | ||||||||||||||||||||||||||||||||||||||||||
| 447 | # This will detect accidental connection to the incorrect server, as well as | ||||||||||||||||||||||||||||||||||||||||||
| 448 | # some redirection attacks" | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 7 | my $digest_uri = $cparams{'digest-uri'}; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 7 | my ($cservice, $chost, $cservname) = split '/', $digest_uri, 3; | |||||||||||||||||||||||||||||||||||||||||
| 451 | 7 | ▶ | if ($cservice ne $self->service or $chost ne $self->host) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cservice ne $self->service or $chost ne $self->host
MC/DC50%1/2
$cservice ne $self->service or $chost ne $self->host
$cservice ne $self->service
$chost ne $self->host
Truth table66%2/3
A or B
A= $cservice ne $self->serviceB= $chost ne $self->host
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | # XXX deal with serv_name | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | $self->set_error("Incorrect digest-uri"); | |||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | return $cb->(); | |||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 6 | ▶ | unless (defined $self->callback('getsecret')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | $self->set_error("a getsecret callback MUST be defined"); | |||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | $cb->(); | |||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 6 | my $realm = $self->{client_params}->{'realm'}; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 6 | ▶ | my $response_check = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 6 | my $password = shift; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 6 | ▶ | return $self->set_error("Cannot get the passord for $username") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | unless defined $password; | ||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | ## configure the security layer | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 6 | ▶ | $self->_server_layer($qop) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | or return $self->set_error("Cannot negociate the security layer"); | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | my ($expected, $rspauth) | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 6 | = $self->_compute_digests_and_set_keys($password, $self->{client_params}); | |||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | return $self->set_error("Incorrect response $self->{client_params}->{response} <> $expected") | ||||||||||||||||||||||||||||||||||||||||||
| 477 | 6 | ▶ | unless $expected eq $self->{client_params}->{response}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | 4 | my %response = ( | |||||||||||||||||||||||||||||||||||||||||
| 480 | rspauth => $rspauth, | ||||||||||||||||||||||||||||||||||||||||||
| 481 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | # I'm not entirely sure of what I am doing | ||||||||||||||||||||||||||||||||||||||||||
| 484 | 4 | $self->{answer}{$_} = $self->{client_params}->{$_} for qw/username authzid realm serv/; | |||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 4 | $self->set_success; | |||||||||||||||||||||||||||||||||||||||||
| 487 | 4 | return _response(\%response); | |||||||||||||||||||||||||||||||||||||||||
| 488 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | $self->callback('getsecret')->( | ||||||||||||||||||||||||||||||||||||||||||
| 491 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 492 | { user => $username, realm => $realm, authzid => $authzid }, | ||||||||||||||||||||||||||||||||||||||||||
| 493 | 6 | ▶ | sub { $cb->( $response_check->( shift ) ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | 8 | ▶ | sub is_qop_supported { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_qop_supported: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 499 | 8 | my $qop = shift; | |||||||||||||||||||||||||||||||||||||||||
| 500 | 8 | return $self->{supported_qop}{$qop}; | |||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 22 | ▶ | sub _response { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_response: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 22 | my $response = shift; | |||||||||||||||||||||||||||||||||||||||||
| 505 | 22 | my $is_client = shift; | |||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | 22 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 508 | 22 | for my $k (sort keys %$response) { | |||||||||||||||||||||||||||||||||||||||||
| 509 | 146 | ▶ | my $is_array = ref $response->{$k} && ref $response->{$k} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $response->{$k} && ref $response->{$k} eq 'ARRAY'
MC/DC50%1/2
ref $response->{$k} && ref $response->{$k} eq 'ARRAY'
ref $response->{$k}
ref $response->{$k} eq 'ARRAY'
Truth table66%2/3
A && B
A= ref $response->{$k}B= ref $response->{$k} eq 'ARRAY'
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | 146 | ▶ | my @values = $is_array ? @{$response->{$k}} : ($response->{$k}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | # Per spec, one way of doing it: multiple k=v | ||||||||||||||||||||||||||||||||||||||||||
| 512 | #push @out, [$k, $_] for @values; | ||||||||||||||||||||||||||||||||||||||||||
| 513 | # other way: comma separated list | ||||||||||||||||||||||||||||||||||||||||||
| 514 | 146 | push @out, [$k, join (',', @values)]; | |||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 22 | return join (",", map { _qdval($_->[0], $_->[1], $is_client) } @out); | |||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | 21 | ▶ | sub _parse_challenge { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_challenge: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 521 | 21 | my $challenge_ref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 522 | 21 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 523 | 21 | my $params = shift; | |||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | 21 | ▶ | while($$challenge_ref =~ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | s/^(?:\s*,)*\s* # remaining or crap | ||||||||||||||||||||||||||||||||||||||||||
| 527 | ([\w-]+) # key, eg: qop | ||||||||||||||||||||||||||||||||||||||||||
| 528 | = | ||||||||||||||||||||||||||||||||||||||||||
| 529 | ("([^\\"]+|\\.)*"|[^,]+) # value, eg: auth-conf or "NoNcE" | ||||||||||||||||||||||||||||||||||||||||||
| 530 | \s*(?:,\s*)* # remaining | ||||||||||||||||||||||||||||||||||||||||||
| 531 | //x) { | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | 135 | my ($k, $v) = ($1,$2); | |||||||||||||||||||||||||||||||||||||||||
| 534 | 135 | ▶ | if ($v =~ /^"(.*)"$/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | 75 | ($v = $1) =~ s/\\(.)/$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 135 | ▶ | if (exists $multi{$type}{$k}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | 7 | ▶ | my $aref = $params->{$k} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params->{$k} ||= []
MC/DC0%0/1
$params->{$k} ||= []
$params->{$k}
Truth table50%1/2
A
A= $params->{$k}
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | 7 | push @$aref, $v; | |||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | elsif (defined $params->{$k}) { | ||||||||||||||||||||||||||||||||||||||||||
| 542 | 1 | return $self->set_error("Bad challenge: '$$challenge_ref'"); | |||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||
| 544 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 127 | $params->{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||
| 548 | 20 | ▶ | return length $$challenge_ref ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | 146 | ▶ | sub _qdval { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_qdval: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 146 | my ($k, $v, $is_client) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | 146 | ▶ | my $qdval = $is_client ? \%cqdval : \%sqdval; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | 146 | ▶ | if (!defined $v) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | elsif (exists $qdval->{$k}) { | ||||||||||||||||||||||||||||||||||||||||||
| 560 | 81 | $v =~ s/([\\"])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 561 | 81 | return qq{$k="$v"}; | |||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | 65 | return "$k=$v"; | |||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | 6 | ▶ | sub _server_layer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_server_layer: called CC=8 SCAR=22.8
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | 6 | my ($self, $auth) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | # XXX dupe | ||||||||||||||||||||||||||||||||||||||||||
| 571 | # construct our qop mask | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 6 | my $maxssf = $self->property('maxssf') - $self->property('externalssf'); | |||||||||||||||||||||||||||||||||||||||||
| 573 | 6 | ▶ | $maxssf = 0 if ($maxssf < 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | 6 | my $minssf = $self->property('minssf') - $self->property('externalssf'); | |||||||||||||||||||||||||||||||||||||||||
| 575 | 6 | ▶ | $minssf = 0 if ($minssf < 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | 6 | ▶ | return undef if ($maxssf < $minssf); # sanity check | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | 6 | my $ciphers = [ map { $_->{name} } @ourciphers ]; | |||||||||||||||||||||||||||||||||||||||||
| 580 | 6 | ▶ | if (( $auth eq 'auth-conf') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$auth eq "auth-conf" and $self->_select_cipher($minssf, $maxssf, $ciphers)
MC/DC0%0/2
$auth eq "auth-conf" and $self->_select_cipher($minssf, $maxssf, $ciphers)
$auth eq "auth-conf"
$self->_select_cipher($minssf, $maxssf, $ciphers)
Truth table33%1/3
A and B
A= $auth eq "auth-conf"B= $self->_select_cipher($minssf, $maxssf, $ciphers)
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | and $self->_select_cipher($minssf, $maxssf, $ciphers )) { | ||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | $self->property('ssf', $self->{cipher}->{ssf}); | |||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | 6 | ▶ | if ($auth eq 'auth-int') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | 3 | $self->property('ssf', 1); | |||||||||||||||||||||||||||||||||||||||||
| 587 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||
| 589 | 3 | ▶ | if ($auth eq 'auth') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 590 | 3 | $self->property('ssf', 0); | |||||||||||||||||||||||||||||||||||||||||
| 591 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | 7 | ▶ | sub _client_layer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_client_layer: called CC=18 SCAR=33.0
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | 7 | my ($self, $sparams, $response) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||
| 600 | # construct server qop mask | ||||||||||||||||||||||||||||||||||||||||||
| 601 | # qop in server challenge is optional: if not there "auth" is assumed | ||||||||||||||||||||||||||||||||||||||||||
| 602 | 7 | my $smask = 0; | |||||||||||||||||||||||||||||||||||||||||
| 603 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 604 | 13 | ▶ | m/^auth$/ and $smask |= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 605 | 13 | ▶ | m/^auth-int$/ and $smask |= 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | 13 | ▶ | m/^auth-conf$/ and $smask |= 4; | ||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
/^auth-conf$/ && ($smask |= 4)
$sparams->{'qop'} || 'auth'
MC/DC0%0/2
/^auth-conf$/ && ($smask |= 4)
/^auth-conf$/
($smask |= 4)
MC/DC0%0/1
$sparams->{'qop'} || 'auth'
$sparams->{'qop'}
Truth table33%1/3
A && B
A= /^auth-conf$/B= ($smask |= 4)
Truth table50%1/2
A
A= $sparams->{'qop'}
| |||||||||||||||||||||||||||||||||||||||||||
| 607 | 7 | } split(/,/, $sparams->{qop}||'auth'); # XXX I think we might have a bug here bc. of LWS | |||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | # construct our qop mask | ||||||||||||||||||||||||||||||||||||||||||
| 610 | 7 | my $cmask = 0; | |||||||||||||||||||||||||||||||||||||||||
| 611 | 7 | my $maxssf = $self->property('maxssf') - $self->property('externalssf'); | |||||||||||||||||||||||||||||||||||||||||
| 612 | 7 | ▶ | $maxssf = 0 if ($maxssf < 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 613 | 7 | my $minssf = $self->property('minssf') - $self->property('externalssf'); | |||||||||||||||||||||||||||||||||||||||||
| 614 | 7 | ▶ | $minssf = 0 if ($minssf < 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 7 | ▶ | return undef if ($maxssf < $minssf); # sanity check | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | # ssf values > 1 mean integrity and confidentiality | ||||||||||||||||||||||||||||||||||||||||||
| 619 | # ssf == 1 means integrity but no confidentiality | ||||||||||||||||||||||||||||||||||||||||||
| 620 | # ssf < 1 means neither integrity nor confidentiality | ||||||||||||||||||||||||||||||||||||||||||
| 621 | # no security layer can be had if buffer size is 0 | ||||||||||||||||||||||||||||||||||||||||||
| 622 | 7 | ▶ | $cmask |= 1 if ($minssf < 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | 7 | ▶ | $cmask |= 2 if ($minssf <= 1 and $maxssf >= 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$minssf <= 1 and $maxssf >= 1
MC/DC0%0/2
$minssf <= 1 and $maxssf >= 1
$minssf <= 1
$maxssf >= 1
Truth table33%1/3
A and B
A= $minssf <= 1B= $maxssf >= 1
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | 7 | ▶ | $cmask |= 4 if ($maxssf > 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | # find common bits | ||||||||||||||||||||||||||||||||||||||||||
| 627 | 7 | $cmask &= $smask; | |||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | # parse server cipher options | ||||||||||||||||||||||||||||||||||||||||||
| 630 | 7 | ▶ | my @sciphers = split(/,/, $sparams->{'cipher-opts'}||$sparams->{cipher}||''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$sparams->{'cipher-opts'} || $sparams->{'cipher'} || ''
$sparams->{"cipher-opts"} or $sparams->{"cipher"}
MC/DC50%1/2
$sparams->{'cipher-opts'} || $sparams->{'cipher'} || ''
$sparams->{"cipher-opts"}
$sparams->{"cipher"}
Truth table66%2/3
A or B
A= $sparams->{"cipher-opts"}B= $sparams->{"cipher"}
| |||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||
| 632 | 7 | ▶ | if (($cmask & 4) and $self->_select_cipher($minssf,$maxssf,\@sciphers)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cmask & 4 and $self->_select_cipher($minssf, $maxssf, \@sciphers)
MC/DC0%0/2
$cmask & 4 and $self->_select_cipher($minssf, $maxssf, \@sciphers)
$cmask & 4
$self->_select_cipher($minssf, $maxssf, \@sciphers)
Truth table33%1/3
A and B
A= $cmask & 4B= $self->_select_cipher($minssf, $maxssf, \@sciphers)
| |||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | $response->{qop} = 'auth-conf'; | |||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | $response->{cipher} = $self->{cipher}->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | $self->property('ssf', $self->{cipher}->{ssf}); | |||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||
| 638 | 7 | ▶ | if ($cmask & 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 639 | 4 | $response->{qop} = 'auth-int'; | |||||||||||||||||||||||||||||||||||||||||
| 640 | 4 | $self->property('ssf', 1); | |||||||||||||||||||||||||||||||||||||||||
| 641 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||
| 643 | 3 | ▶ | if ($cmask & 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 644 | 3 | $response->{qop} = 'auth'; | |||||||||||||||||||||||||||||||||||||||||
| 645 | 3 | $self->property('ssf', 0); | |||||||||||||||||||||||||||||||||||||||||
| 646 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | ▶ | sub _select_cipher { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_select_cipher: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | my ($self, $minssf, $maxssf, $ciphers) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||
| 655 | # compose a subset of candidate ciphers based on ssf and peer list | ||||||||||||||||||||||||||||||||||||||||||
| 656 | my @a = map { | ||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | my $c = $_; | |||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | (grep { $c->{name} eq $_ } @$ciphers and | |||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | ▶ | $c->{ssf} >= $minssf and $c->{ssf} <= $maxssf) ? $_ : () | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
grep {$c->{"name"} eq $_;} @$ciphers and $c->{"ssf"} >= $minssf and $c->{"ssf"} <= $maxssf
grep {$c->{"name"} eq $_;} @$ciphers and $c->{"ssf"} >= $minssf
MC/DC0%0/3
grep {$c->{"name"} eq $_;} @$ciphers and $c->{"ssf"} >= $minssf and $c->{"ssf"} <= $maxssf
grep {$c->{"name"} eq $_;} @$ciphers
$c->{"ssf"} >= $minssf
$c->{"ssf"} <= $maxssf
Truth table0%0/4
A and B and C
A= grep {$c->{"name"} eq $_;} @$ciphersB= $c->{"ssf"} >= $minssfC= $c->{"ssf"} <= $maxssf
| |||||||||||||||||||||||||||||||||||||||||||
| 660 | } @ourciphers; | ||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | # from these, select the first one we can create an instance of | ||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | for (@a) { | |||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | ▶ | next unless eval "require $_->{pkg}"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | $self->{cipher} = $_; | |||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | 5 | ▶ | use Digest::HMAC_MD5 qw(hmac_md5); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | ▶ | sub encode { # input: self, plaintext buffer,length (length not used here) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | my $seqnum = pack('N', $self->{sndseqnum}++); | |||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | my $mac = substr(hmac_md5($seqnum . $_[0], $self->{kic}), 0, 10); | |||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||
| 679 | # if integrity only, return concatenation of buffer, MAC, TYPE and SEQNUM | ||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | return $_[0] . $mac.pack('n',1) . $seqnum unless ($self->{khc}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | # must encrypt, block ciphers need padding bytes | ||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | my $pad = ''; | |||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | my $bs = $self->{cipher}->{bs}; | |||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | ▶ | if ($bs > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | # padding is added in between BUF and MAC | ||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | my $n = $bs - ((length($_[0]) + 10) & ($bs - 1)); | |||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | $pad = chr($n) x $n; | |||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | # XXX - for future AES cipher support, the currently used common _crypt() | ||||||||||||||||||||||||||||||||||||||||||
| 692 | # function probably wont do; we might to switch to per-cipher routines | ||||||||||||||||||||||||||||||||||||||||||
| 693 | # like so: | ||||||||||||||||||||||||||||||||||||||||||
| 694 | # return $self->{khc}->encrypt($_[0] . $pad . $mac) . pack('n', 1) . $seqnum; | ||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | return $self->_crypt(0, $_[0] . $pad . $mac) . pack('n', 1) . $seqnum; | |||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | ▶ | sub decode { # input: self, cipher buffer,length | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | my ($self, $buf, $len) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | return if ($len <= 16); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||
| 703 | # extract TYPE/SEQNUM from end of buffer | ||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | my ($type,$seqnum) = unpack('na[4]', substr($buf, -6, 6, '')); | |||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | # decrypt remaining buffer, if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | ▶ | if ($self->{khs}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 708 | # XXX - see remark above in encode() #$buf = $self->{khs}->decrypt($buf); | ||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | $buf = $self->_crypt(1, $buf); | |||||||||||||||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | ▶ | return unless ($buf); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||
| 713 | # extract 10-byte MAC from the end of (decrypted) buffer | ||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | my ($mac) = unpack('a[10]', substr($buf, -10, 10, '')); | |||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | ▶ | if ($self->{khs} and $self->{cipher}->{bs} > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"khs"} and $self->{"cipher"}{"bs"} > 1
MC/DC0%0/2
$self->{"khs"} and $self->{"cipher"}{"bs"} > 1
$self->{"khs"}
$self->{"cipher"}{"bs"} > 1
Truth table0%0/3
A and B
A= $self->{"khs"}B= $self->{"cipher"}{"bs"} > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 717 | # remove padding | ||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | my $n = ord(substr($buf, -1, 1)); | |||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | substr($buf, -$n, $n, ''); | |||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||
| 722 | # check the MAC | ||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | my $check = substr(hmac_md5($seqnum . $buf, $self->{kis}), 0, 10); | |||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | ▶ | return if ($mac ne $check); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | ▶ | return if (unpack('N', $seqnum) != $self->{rcvseqnum}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | $self->{rcvseqnum}++; | |||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | return $buf; | |||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | ▶ | sub _crypt { # input: op(decrypting=1/encrypting=0)), buffer | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_crypt: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | my ($self,$d) = (shift,shift); | |||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | my $bs = $self->{cipher}->{bs}; | |||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | ▶ | if ($bs <= 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 736 | # stream cipher | ||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | ▶ | return $d ? $self->{khs}->decrypt($_[0]) : $self->{khc}->encrypt($_[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||
| 740 | # the remainder of this sub is for block ciphers | ||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||
| 742 | # get current IV | ||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | ▶ | my $piv = \$self->{$d ? 'ivs' : 'ivc'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | my $iv = $$piv; | |||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||
| 746 | my $result = join '', map { | ||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | my $x = $d | |||||||||||||||||||||||||||||||||||||||||
| 748 | ? $iv ^ $self->{khs}->decrypt($_) | ||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | ▶ | : $self->{khc}->encrypt($iv ^ $_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | ▶ | $iv = $d ? $_ : $x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | $x; | |||||||||||||||||||||||||||||||||||||||||
| 752 | } unpack("a$bs "x(int(length($_[0])/$bs)), $_[0]); | ||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | # store current IV | ||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | $$piv = $iv; | |||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||
| 759 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | __END__ | ||||||||||||||||||||||||||||||||||||||||||