| 1 | package Net::DNS::RR::TSIG; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | our $VERSION = (qw$Id: TSIG.pm 2066 2026-11-17 11:13:39Z willem $)[2]; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use base qw(Net::DNS::RR); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Net::DNS::RR::TSIG - DNS TSIG resource record | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =cut | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 7 | ▶ | use integer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 7 | ▶ | use Net::DNS::DomainName; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use Net::DNS::Parameters qw(:class :type :rcode); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 7 | ▶ | use constant SYMLINK => defined(&CORE::readlink); # Except Win32, VMS, RISC OS | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 7 | ▶ | use constant ANY => classbyname q(ANY); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 7 | ▶ | use constant TSIG => typebyname q(TSIG); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 7 | eval { require Digest::HMAC }; | |||||||||||||||||||||||||||
| 29 | 7 | eval { require Digest::MD5 }; | |||||||||||||||||||||||||||
| 30 | 7 | eval { require Digest::SHA }; | |||||||||||||||||||||||||||
| 31 | 7 | eval { require MIME::Base64 }; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 27 | ▶ | sub _decode_rdata { ## decode rdata from wire-format octet string | ||||||||||||||||||||||||||
|
Subroutine
_decode_rdata: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 35 | 27 | my ( $self, $data, $offset ) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 27 | my $limit = $offset + delete $self->{rdlength}; | |||||||||||||||||||||||||||
| 38 | 27 | ▶ | croak('misplaced or corrupt TSIG') unless $limit == length $$data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 26 | my $raw = substr $$data, 0, $self->{offset}++; | |||||||||||||||||||||||||||
| 40 | 26 | $self->{rawref} = \$raw; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 26 | ( $self->{algorithm}, $offset ) = Net::DNS::DomainName->decode( $data, $offset ); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # Design decision: Use 32 bits, which will work until the end of time()! | ||||||||||||||||||||||||||||
| 45 | 26 | @{$self}{qw(time_signed fudge)} = unpack "\@$offset xxN n", $$data; | |||||||||||||||||||||||||||
| 46 | 26 | $offset += 8; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 26 | my $mac_size = unpack "\@$offset n", $$data; | |||||||||||||||||||||||||||
| 49 | 26 | $self->{macbin} = unpack "\@$offset xx a$mac_size", $$data; | |||||||||||||||||||||||||||
| 50 | 26 | $offset += $mac_size + 2; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 26 | @{$self}{qw(original_id error)} = unpack "\@$offset nn", $$data; | |||||||||||||||||||||||||||
| 53 | 26 | $offset += 4; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 26 | my $other_size = unpack "\@$offset n", $$data; | |||||||||||||||||||||||||||
| 56 | 26 | $self->{other} = unpack "\@$offset xx a$other_size", $$data; | |||||||||||||||||||||||||||
| 57 | 26 | $offset += $other_size + 2; | |||||||||||||||||||||||||||
| 58 | 26 | return; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 36 | ▶ | sub _encode_rdata { ## encode rdata as wire-format octet string | ||||||||||||||||||||||||||
|
Subroutine
_encode_rdata: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 63 | 36 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 36 | my $offset = shift; | |||||||||||||||||||||||||||
| 66 | 36 | my $undef = shift; | |||||||||||||||||||||||||||
| 67 | 36 | my $message = shift; | |||||||||||||||||||||||||||
| 68 | 36 | ▶ | my $algorithm = $self->{algorithm} || return ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'algorithm'} || (return '')
MC/DC100%1/1
$self->{'algorithm'} || (return '')
$self->{'algorithm'}
Truth table100%2/2
A
A= $self->{'algorithm'}
| |||||||||||||||||||||||||||||
| 69 | 35 | my $macbin = $self->macbin; | |||||||||||||||||||||||||||
| 70 | 35 | ▶ | unless ($macbin) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 30 | my $sigdata = $self->sig_data($message); # form data to be signed | |||||||||||||||||||||||||||
| 72 | 30 | $macbin = $self->macbin( $self->_mac_function($sigdata) ); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 35 | my $rdata = $algorithm->canonical; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # Design decision: Use 32 bits, which will work until the end of time()! | ||||||||||||||||||||||||||||
| 78 | 35 | $rdata .= pack 'xxN n', $self->time_signed, $self->fudge; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 35 | $rdata .= pack 'na*', length($macbin), $macbin; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 35 | $rdata .= pack 'nn', $self->original_id, $self->{error}; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 35 | my $other = $self->other; | |||||||||||||||||||||||||||
| 85 | 35 | $rdata .= pack 'na*', length($other), $other; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 35 | return $rdata; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 6 | ▶ | sub _defaults { ## specify RR attribute default values | ||||||||||||||||||||||||||
|
Subroutine
_defaults: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 92 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 6 | $self->algorithm(157); | |||||||||||||||||||||||||||
| 95 | 6 | $self->class('ANY'); | |||||||||||||||||||||||||||
| 96 | 6 | $self->error(0); | |||||||||||||||||||||||||||
| 97 | 6 | $self->fudge(300); | |||||||||||||||||||||||||||
| 98 | 6 | $self->other(''); | |||||||||||||||||||||||||||
| 99 | 6 | return; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | ▶ | sub _size { ## estimate encoded size | ||||||||||||||||||||||||||
|
Subroutine
_size: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 104 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | 2 | my $clone = bless {%$self}, ref($self); # shallow clone | |||||||||||||||||||||||||||
| 106 | 2 | return length $clone->encode( 0, undef, Net::DNS::Packet->new() ); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 35 | ▶ | sub encode { ## override RR method | ||||||||||||||||||||||||||
|
Subroutine
encode: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 35 | my ( $self, @argument ) = @_; | |||||||||||||||||||||||||||
| 112 | 35 | my $kname = $self->{owner}->encode(); # uncompressed key name | |||||||||||||||||||||||||||
| 113 | 35 | ▶ | my $rdata = eval { $self->_encode_rdata(@argument) } || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
eval {
do {
$self->_encode_rdata(@argument)
}
} || ''
MC/DC100%1/1
eval {
do {
$self->_encode_rdata(@argument)
}
} || ''
eval {
do {
$self->_encode_rdata(@argument)
}
}
Truth table100%2/2
A
A= eval {
do {
$self->_encode_rdata(@argument)
}
}
| |||||||||||||||||||||||||||||
| 114 | 35 | return pack 'a* n2 N n a*', $kname, TSIG, ANY, 0, length $rdata, $rdata; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 3 | ▶ | sub string { ## override RR method | ||||||||||||||||||||||||||
|
Subroutine
string: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 120 | 3 | my $name = $self->{owner}->string; | |||||||||||||||||||||||||||
| 121 | 3 | my $type = $self->type; | |||||||||||||||||||||||||||
| 122 | 3 | ▶ | return "; $name $type ; no data" unless $self->{algorithm}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 2 | my $algorithm = $self->algorithm; | |||||||||||||||||||||||||||
| 124 | 2 | my $time_signed = $self->time_signed; | |||||||||||||||||||||||||||
| 125 | 2 | my $fudge = $self->fudge; | |||||||||||||||||||||||||||
| 126 | 2 | my $signature = $self->mac; | |||||||||||||||||||||||||||
| 127 | 2 | my $original_id = $self->original_id; | |||||||||||||||||||||||||||
| 128 | 2 | my $error = $self->error; | |||||||||||||||||||||||||||
| 129 | 2 | my $other = $self->other; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 2 | return <<"QQ"; | |||||||||||||||||||||||||||
| 132 | ; $name $type | ||||||||||||||||||||||||||||
| 133 | ; algorithm: $algorithm | ||||||||||||||||||||||||||||
| 134 | ; time signed: $time_signed fudge: $fudge | ||||||||||||||||||||||||||||
| 135 | ; signature: $signature | ||||||||||||||||||||||||||||
| 136 | ; original id: $original_id | ||||||||||||||||||||||||||||
| 137 | ; error: $error $other | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 120 | ▶ | sub algorithm { return &_algorithm; } | ||||||||||||||||||||||||||
|
Subroutine
algorithm: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 26 | ▶ | sub key { | ||||||||||||||||||||||||||
|
Subroutine
key: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 146 | 26 | my ( $self, @argument ) = @_; | |||||||||||||||||||||||||||
| 147 | 26 | ▶ | return MIME::Base64::encode( $self->keybin(), "" ) unless scalar @argument; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 25 | return $self->keybin( MIME::Base64::decode( join "", @argument ) ); | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 27 | ▶ | sub keybin { return &_keybin; } | ||||||||||||||||||||||||||
|
Subroutine
keybin: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 128 | ▶ | sub time_signed { | ||||||||||||||||||||||||||
|
Subroutine
time_signed: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 156 | 128 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 157 | 128 | for (@value) { $self->{time_signed} = 0 + $_ } | |||||||||||||||||||||||||||
| 158 | 128 | ▶ | return $self->{time_signed} ? $self->{time_signed} : ( $self->{time_signed} = time() ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 136 | ▶ | sub fudge { | ||||||||||||||||||||||||||
|
Subroutine
fudge: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | 136 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 164 | 136 | for (@value) { $self->{fudge} = 0 + $_ } | |||||||||||||||||||||||||||
| 165 | 136 | ▶ | return $self->{fudge} || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'fudge'} || 0
MC/DC100%1/1
$self->{'fudge'} || 0
$self->{'fudge'}
Truth table100%2/2
A
A= $self->{'fudge'}
| |||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 5 | ▶ | sub mac { | ||||||||||||||||||||||||||
|
Subroutine
mac: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 170 | 5 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 171 | 5 | ▶ | return MIME::Base64::encode( $self->macbin(), "" ) unless scalar @value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 1 | return $self->macbin( MIME::Base64::decode( join "", @value ) ); | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 151 | ▶ | sub macbin { | ||||||||||||||||||||||||||
|
Subroutine
macbin: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 151 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 178 | 151 | for (@value) { $self->{macbin} = $_ } | |||||||||||||||||||||||||||
| 179 | 151 | ▶ | return $self->{macbin} || ""; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'macbin'} || ''
MC/DC100%1/1
$self->{'macbin'} || ''
$self->{'macbin'}
Truth table100%2/2
A
A= $self->{'macbin'}
| |||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 3 | ▶ | sub prior_mac { | ||||||||||||||||||||||||||
|
Subroutine
prior_mac: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 184 | 3 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 185 | 3 | ▶ | return MIME::Base64::encode( $self->prior_macbin(), "" ) unless scalar @value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 1 | return $self->prior_macbin( MIME::Base64::decode( join "", @value ) ); | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 93 | ▶ | sub prior_macbin { | ||||||||||||||||||||||||||
|
Subroutine
prior_macbin: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 191 | 93 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 192 | 93 | for (@value) { $self->{prior_macbin} = $_ } | |||||||||||||||||||||||||||
| 193 | 93 | ▶ | return $self->{prior_macbin} || ""; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'prior_macbin'} || ''
MC/DC100%1/1
$self->{'prior_macbin'} || ''
$self->{'prior_macbin'}
Truth table100%2/2
A
A= $self->{'prior_macbin'}
| |||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 3 | ▶ | sub request_mac { | ||||||||||||||||||||||||||
|
Subroutine
request_mac: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 198 | 3 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 199 | 3 | ▶ | return MIME::Base64::encode( $self->request_macbin(), "" ) unless scalar @value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 1 | return $self->request_macbin( MIME::Base64::decode( join "", @value ) ); | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 60 | ▶ | sub request_macbin { | ||||||||||||||||||||||||||
|
Subroutine
request_macbin: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 205 | 60 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 206 | 60 | for (@value) { $self->{request_macbin} = $_ } | |||||||||||||||||||||||||||
| 207 | 60 | ▶ | return $self->{request_macbin} || ""; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'request_macbin'} || ''
MC/DC100%1/1
$self->{'request_macbin'} || ''
$self->{'request_macbin'}
Truth table100%2/2
A
A= $self->{'request_macbin'}
| |||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 95 | ▶ | sub original_id { | ||||||||||||||||||||||||||
|
Subroutine
original_id: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 212 | 95 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 213 | 95 | for (@value) { $self->{original_id} = 0 + $_ } | |||||||||||||||||||||||||||
| 214 | 95 | ▶ | return $self->{original_id} || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'original_id'} || 0
MC/DC100%1/1
$self->{'original_id'} || 0
$self->{'original_id'}
Truth table100%2/2
A
A= $self->{'original_id'}
| |||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 48 | ▶ | sub error { | ||||||||||||||||||||||||||
|
Subroutine
error: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 219 | 48 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 220 | 48 | for (@value) { | |||||||||||||||||||||||||||
| 221 | 20 | my $error = $self->{error} = rcodebyname($_); | |||||||||||||||||||||||||||
| 222 | 20 | ▶ | $self->other( time() ) if $error == 18; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | 48 | ▶ | return rcodebyval( $self->{error} || '' ); | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'error'} || ''
MC/DC100%1/1
$self->{'error'} || ''
$self->{'error'}
Truth table100%2/2
A
A= $self->{'error'}
| |||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 90 | ▶ | sub other { | ||||||||||||||||||||||||||
|
Subroutine
other: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 229 | 90 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 230 | 90 | ▶ | for (@value) { $self->{other} = $_ ? pack( 'xxN', $_ ) : '' } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 90 | ▶ | return $self->{other} ? unpack( 'N', $self->{other} ) : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 1 | ▶ | sub other_data { return &other; } # uncoverable pod | ||||||||||||||||||||||||||
|
Subroutine
other_data: called CC=1 SCAR=0.0
Pod
undocumented (uncoverable)
| |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 51 | ▶ | sub sig_function { | ||||||||||||||||||||||||||
|
Subroutine
sig_function: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 239 | 51 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 240 | 51 | for (@value) { $self->{sig_function} = $_ } | |||||||||||||||||||||||||||
| 241 | 51 | return $self->{sig_function}; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 1 | ▶ | sub sign_func { return &sig_function; } # uncoverable pod | ||||||||||||||||||||||||||
|
Subroutine
sign_func: called CC=1 SCAR=0.0
Pod
undocumented (uncoverable)
| |||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 60 | ▶ | sub sig_data { | ||||||||||||||||||||||||||
|
Subroutine
sig_data: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 248 | 60 | my ( $self, $message ) = @_; | |||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 60 | ▶ | if ( ref($message) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | 59 | ▶ | die 'missing packet reference' unless $message->isa('Net::DNS::Packet'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | 58 | my @unsigned = grep { ref($_) ne ref($self) } @{$message->{additional}}; | |||||||||||||||||||||||||||
| 253 | 58 | local $message->{additional} = \@unsigned; # remake header image | |||||||||||||||||||||||||||
| 254 | 58 | my @part = qw(question answer authority additional); | |||||||||||||||||||||||||||
| 255 | 58 | my @size = map { scalar @{$message->{$_}} } @part; | |||||||||||||||||||||||||||
| 256 | 58 | ▶ | if ( my $rawref = delete $self->{rawref} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | 16 | my $hbin = pack 'n6', $self->original_id, $message->{status}, @size; | |||||||||||||||||||||||||||
| 258 | 16 | $message = join '', $hbin, substr $$rawref, length $hbin; | |||||||||||||||||||||||||||
| 259 | } else { | ||||||||||||||||||||||||||||
| 260 | 42 | my $data = $message->encode; | |||||||||||||||||||||||||||
| 261 | 42 | my $id = $message->header->id; | |||||||||||||||||||||||||||
| 262 | 42 | my $hbin = pack 'n6', $id, $message->{status}, @size; | |||||||||||||||||||||||||||
| 263 | 42 | $message = join '', $hbin, substr $data, length $hbin; | |||||||||||||||||||||||||||
| 264 | 42 | $self->original_id($id); | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | # Design decision: Use 32 bits, which will work until the end of time()! | ||||||||||||||||||||||||||||
| 269 | 59 | my $time = pack 'xxN n', $self->time_signed, $self->fudge; | |||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | # Insert the prior MAC if present (multi-packet message). | ||||||||||||||||||||||||||||
| 272 | 59 | ▶ | $self->prior_macbin( $self->{link}->macbin ) if $self->{link}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | 59 | my $prior_macbin = $self->prior_macbin; | |||||||||||||||||||||||||||
| 274 | 59 | ▶ | return pack 'na* a* a*', length($prior_macbin), $prior_macbin, $message, $time if $prior_macbin; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | # Insert the request MAC if present (used to validate responses). | ||||||||||||||||||||||||||||
| 277 | 41 | my $req_mac = $self->request_macbin; | |||||||||||||||||||||||||||
| 278 | 41 | ▶ | my $sigdata = $req_mac ? pack( 'na*', length($req_mac), $req_mac ) : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 41 | ▶ | $sigdata .= $message || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$message || ''
MC/DC100%1/1
$message || ''
$message
Truth table100%2/2
A
A= $message
| |||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 41 | my $kname = $self->{owner}->canonical; # canonical key name | |||||||||||||||||||||||||||
| 283 | 41 | $sigdata .= pack 'a* n N', $kname, ANY, 0; | |||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 41 | $sigdata .= $self->{algorithm}->canonical; # canonical algorithm name | |||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 41 | $sigdata .= $time; | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 41 | $sigdata .= pack 'n', $self->{error}; | |||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 41 | my $other = $self->other; | |||||||||||||||||||||||||||
| 292 | 41 | $sigdata .= pack 'na*', length($other), $other; | |||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 41 | return $sigdata; | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 54 | ▶ | sub create { | ||||||||||||||||||||||||||
|
Subroutine
create: called CC=19 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||
| 299 | 54 | my ( $class, $karg, @argument ) = @_; | |||||||||||||||||||||||||||
| 300 | 54 | ▶ | croak 'argument undefined' unless defined $karg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 52 | ▶ | if ( ref($karg) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 303 | 32 | ▶ | if ( $karg->isa('Net::DNS::Packet') ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 304 | 5 | my $sigrr = $karg->sigrr; | |||||||||||||||||||||||||||
| 305 | 5 | ▶ | croak 'no TSIG in request packet' unless defined $sigrr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | 3 | return Net::DNS::RR->new( # ( request, options ) | |||||||||||||||||||||||||||
| 307 | name => $sigrr->name, | ||||||||||||||||||||||||||||
| 308 | type => 'TSIG', | ||||||||||||||||||||||||||||
| 309 | algorithm => $sigrr->algorithm, | ||||||||||||||||||||||||||||
| 310 | request_macbin => $sigrr->macbin, | ||||||||||||||||||||||||||||
| 311 | @argument | ||||||||||||||||||||||||||||
| 312 | ); | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | } elsif ( ref($karg) eq __PACKAGE__ ) { | ||||||||||||||||||||||||||||
| 315 | 16 | my $tsig = $karg->_chain; | |||||||||||||||||||||||||||
| 316 | 16 | $tsig->{macbin} = undef; | |||||||||||||||||||||||||||
| 317 | 16 | return $tsig; | |||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | } elsif ( ref($karg) eq 'Net::DNS::RR::KEY' ) { | ||||||||||||||||||||||||||||
| 320 | 10 | return Net::DNS::RR->new( | |||||||||||||||||||||||||||
| 321 | name => $karg->name, | ||||||||||||||||||||||||||||
| 322 | type => 'TSIG', | ||||||||||||||||||||||||||||
| 323 | algorithm => $karg->algorithm, | ||||||||||||||||||||||||||||
| 324 | key => $karg->key, | ||||||||||||||||||||||||||||
| 325 | @argument | ||||||||||||||||||||||||||||
| 326 | ); | ||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | } elsif ( ( scalar(@argument) % 2 ) == 0 ) { | ||||||||||||||||||||||||||||
| 330 | 19 | require File::Spec; # ( keyfile, options ) | |||||||||||||||||||||||||||
| 331 | 19 | require Net::DNS::ZoneFile; | |||||||||||||||||||||||||||
| 332 | 19 | my ($keypath) = SYMLINK ? grep( {$_} readlink($karg), $karg ) : $karg; | |||||||||||||||||||||||||||
| 333 | 19 | my ( $vol, $dir, $name ) = File::Spec->splitpath($keypath); | |||||||||||||||||||||||||||
| 334 | 19 | $name =~ m/^K([^+]+)\+\d+\+(\d+)\./; # BIND dnssec-keygen | |||||||||||||||||||||||||||
| 335 | 19 | my ( $keyname, $keytag ) = ( $1, $2 ); | |||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 19 | my $keyfile = Net::DNS::ZoneFile->new($karg); | |||||||||||||||||||||||||||
| 338 | 18 | my ( $algorithm, $secret ); | |||||||||||||||||||||||||||
| 339 | 18 | ▶ | while ( $keyfile->_getline ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | 65 | ▶ | /^key "([^"]+)"/ and $keyname = $1; # BIND tsig key | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 341 | 65 | ▶ | /algorithm ([^;]+);/ and $algorithm = $1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | 65 | ▶ | /secret "([^"]+)";/ and $secret = $1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 65 | ▶ | /^Algorithm:/ and ( undef, $algorithm ) = split; # BIND dnssec private key | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 345 | 65 | ▶ | /^Key:/ and ( undef, $secret ) = split; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 65 | ▶ | next unless /\bIN\s+KEY\b/; # BIND dnssec public key | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 3 | my $keyrr = Net::DNS::RR->new($_); | |||||||||||||||||||||||||||
| 349 | 3 | ▶ | carp "$karg does not appear to be a BIND dnssec public key" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$keytag || 0
MC/DC100%1/1
$keytag || 0
$keytag
Truth table100%2/2
A
A= $keytag
| |||||||||||||||||||||||||||||
| 350 | unless $keyrr->keytag == ( $keytag || 0 ); | ||||||||||||||||||||||||||||
| 351 | 3 | return $class->create( $keyrr, @argument ); | |||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 15 | foreach ( $keyname, $algorithm, $secret ) { | |||||||||||||||||||||||||||
| 355 | 44 | ▶ | croak 'key file incompatible with TSIG' unless $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 14 | return Net::DNS::RR->new( | |||||||||||||||||||||||||||
| 359 | name => $keyname, | ||||||||||||||||||||||||||||
| 360 | type => 'TSIG', | ||||||||||||||||||||||||||||
| 361 | algorithm => $algorithm, | ||||||||||||||||||||||||||||
| 362 | key => $secret, | ||||||||||||||||||||||||||||
| 363 | @argument | ||||||||||||||||||||||||||||
| 364 | ); | ||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 2 | croak "Usage: $class->create( \$keyfile, \@options )"; | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | 40 | ▶ | sub verify { | ||||||||||||||||||||||||||
|
Subroutine
verify: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||
| 372 | 40 | my ( $self, $data, @link ) = @_; | |||||||||||||||||||||||||||
| 373 | 40 | my $fail = undef; | |||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 40 | ▶ | if ( scalar @link ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 31 | my $link = shift @link; | |||||||||||||||||||||||||||
| 378 | 31 | ▶ | unless ( ref($link) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | 1 | $self->error('BADSIG'); # (multi-packet) | |||||||||||||||||||||||||||
| 380 | 1 | return $fail; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 30 | my $signerkey = lc( join '+', $self->name, $self->algorithm ); | |||||||||||||||||||||||||||
| 384 | 30 | ▶ | if ( $link->isa('Net::DNS::Packet') ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 385 | 13 | my $request = $link->sigrr; # request TSIG | |||||||||||||||||||||||||||
| 386 | 13 | my $rqstkey = lc( join '+', $request->name, $request->algorithm ); | |||||||||||||||||||||||||||
| 387 | 13 | ▶ | $self->error('BADKEY') unless $signerkey eq $rqstkey; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 388 | 13 | $self->request_macbin( $request->macbin ); | |||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | } elsif ( $link->isa(__PACKAGE__) ) { | ||||||||||||||||||||||||||||
| 391 | 16 | my $priorkey = lc( join '+', $link->name, $link->algorithm ); | |||||||||||||||||||||||||||
| 392 | 16 | ▶ | $self->error('BADKEY') unless $signerkey eq $priorkey; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 393 | 16 | $self->prior_macbin( $link->macbin ); | |||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | } else { | ||||||||||||||||||||||||||||
| 396 | 1 | croak 'Usage: $tsig->verify( $reply, $query )'; | |||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | 38 | ▶ | return $fail if $self->{error}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 30 | my $sigdata = $self->sig_data($data); # form data to be verified | |||||||||||||||||||||||||||
| 403 | 29 | my $tsigmac = $self->_mac_function($sigdata); | |||||||||||||||||||||||||||
| 404 | 29 | my $tsig = $self->_chain; | |||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 29 | my $macbin = $self->macbin; | |||||||||||||||||||||||||||
| 407 | 29 | my $maclen = length $macbin; | |||||||||||||||||||||||||||
| 408 | 29 | ▶ | $self->error('BADSIG') if $macbin ne substr $tsigmac, 0, $maclen; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | 29 | my $minlen = length($tsigmac) >> 1; # per RFC4635, 3.1 | |||||||||||||||||||||||||||
| 411 | 29 | ▶ | $self->error('BADTRUNC') if $maclen < $minlen or $maclen > length $tsigmac; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$maclen < $minlen or $maclen > length $tsigmac
MC/DC100%2/2
$maclen < $minlen or $maclen > length $tsigmac
$maclen < $minlen
$maclen > length $tsigmac
Truth table100%3/3
A or B
A= $maclen < $minlenB= $maclen > length $tsigmac
| |||||||||||||||||||||||||||||
| 412 | 29 | ▶ | $self->error('BADTRUNC') if $maclen < 10; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 29 | my $time_signed = $self->time_signed; | |||||||||||||||||||||||||||
| 415 | 29 | ▶ | if ( abs( time() - $time_signed ) > $self->fudge ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 416 | 1 | $self->error('BADTIME'); | |||||||||||||||||||||||||||
| 417 | 1 | $self->other($time_signed); | |||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 29 | ▶ | return $self->{error} ? $fail : $tsig; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 25 | ▶ | sub vrfyerrstr { return shift->error; } | ||||||||||||||||||||||||||
|
Subroutine
vrfyerrstr: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | ######################################## | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | { | ||||||||||||||||||||||||||||
| 429 | 7 | my @algbyname = ( | |||||||||||||||||||||||||||
| 430 | 'HMAC-MD5.SIG-ALG.REG.INT' => 157, # numbers are from ISC BIND keygen | ||||||||||||||||||||||||||||
| 431 | 'HMAC-SHA1' => 161, # and not blessed by IANA | ||||||||||||||||||||||||||||
| 432 | 'HMAC-SHA224' => 162, | ||||||||||||||||||||||||||||
| 433 | 'HMAC-SHA256' => 163, | ||||||||||||||||||||||||||||
| 434 | 'HMAC-SHA384' => 164, | ||||||||||||||||||||||||||||
| 435 | 'HMAC-SHA512' => 165, | ||||||||||||||||||||||||||||
| 436 | ); | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | 7 | my @algalias = ( | |||||||||||||||||||||||||||
| 439 | 'HMAC-MD5' => 157, | ||||||||||||||||||||||||||||
| 440 | 'HMAC-SHA' => 161, | ||||||||||||||||||||||||||||
| 441 | ); | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | 7 | my %algbyval = reverse @algbyname; | |||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | 7 | ▶ | my @algrehash = map { /^\d/ ? ($_) x 3 : uc($_) } @algbyname, @algalias; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 446 | 7 | foreach (@algrehash) { s/[\W_]//g; } # strip non-alphanumerics | |||||||||||||||||||||||||||
| 447 | 7 | my %algbyname = @algrehash; # work around broken cperl | |||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | 43 | ▶ | sub _algbyname { | ||||||||||||||||||||||||||
|
Subroutine
_algbyname: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 450 | 43 | my $key = uc shift; # synthetic key | |||||||||||||||||||||||||||
| 451 | 43 | $key =~ s/[\W_]//g; # strip non-alphanumerics | |||||||||||||||||||||||||||
| 452 | 43 | return $algbyname{$key}; | |||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | 41 | ▶ | sub _algbyval { | ||||||||||||||||||||||||||
|
Subroutine
_algbyval: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 456 | 41 | my $value = shift; | |||||||||||||||||||||||||||
| 457 | 41 | return $algbyval{$value}; | |||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | { | ||||||||||||||||||||||||||||
| 463 | 7 | my %digest = ( | |||||||||||||||||||||||||||
| 464 | '157' => ['Digest::MD5'], | ||||||||||||||||||||||||||||
| 465 | '161' => ['Digest::SHA'], | ||||||||||||||||||||||||||||
| 466 | '162' => ['Digest::SHA', 224, 64], | ||||||||||||||||||||||||||||
| 467 | '163' => ['Digest::SHA', 256, 64], | ||||||||||||||||||||||||||||
| 468 | '164' => ['Digest::SHA', 384, 128], | ||||||||||||||||||||||||||||
| 469 | '165' => ['Digest::SHA', 512, 128], | ||||||||||||||||||||||||||||
| 470 | ); | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | 7 | my %keytable; | |||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | 120 | ▶ | sub _algorithm { ## install sig function in key table | ||||||||||||||||||||||||||
|
Subroutine
_algorithm: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 476 | 120 | my $self = shift; | |||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 120 | ▶ | if ( my $algname = shift ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | 43 | ▶ | unless ( my $digtype = _algbyname($algname) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 481 | 2 | $self->{algorithm} = Net::DNS::DomainName->new($algname); | |||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | } else { | ||||||||||||||||||||||||||||
| 484 | 41 | $algname = _algbyval($digtype); | |||||||||||||||||||||||||||
| 485 | 41 | $self->{algorithm} = Net::DNS::DomainName->new($algname); | |||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | 41 | my ( $hash, @param ) = @{$digest{$digtype}}; | |||||||||||||||||||||||||||
| 488 | 41 | my ( undef, @block ) = @param; | |||||||||||||||||||||||||||
| 489 | 41 | my $digest = $hash->new(@param); | |||||||||||||||||||||||||||
| 490 | 93 | ▶ | my $function = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 491 | 93 | my $hmac = Digest::HMAC->new( shift, $digest, @block ); | |||||||||||||||||||||||||||
| 492 | 93 | $hmac->add(shift); | |||||||||||||||||||||||||||
| 493 | 93 | return $hmac->digest; | |||||||||||||||||||||||||||
| 494 | 41 | }; | |||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | 41 | $self->sig_function($function); | |||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 41 | ▶ | my $keyname = ( $self->{owner} || return )->canonical; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'owner'} || (return)
MC/DC100%1/1
$self->{'owner'} || (return)
$self->{'owner'}
Truth table100%2/2
A
A= $self->{'owner'}
| |||||||||||||||||||||||||||||
| 499 | 35 | $keytable{$keyname}{digest} = $function; | |||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | 114 | ▶ | return defined wantarray ? $self->{algorithm}->name : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | 27 | ▶ | sub _keybin { ## install key in key table | ||||||||||||||||||||||||||
|
Subroutine
_keybin: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 508 | 27 | my ( $self, @argument ) = @_; | |||||||||||||||||||||||||||
| 509 | 27 | ▶ | croak 'access to TSIG key material denied' unless scalar @argument; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 510 | 26 | ▶ | my $keyref = $keytable{$self->{owner}->canonical} ||= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$keytable{$self->{"owner"}->canonical} ||= {}
MC/DC100%1/1
$keytable{$self->{"owner"}->canonical} ||= {}
$keytable{$self->{"owner"}->canonical}
Truth table100%2/2
A
A= $keytable{$self->{"owner"}->canonical}
| |||||||||||||||||||||||||||||
| 511 | 26 | my $private = shift @argument; # closure keeps private key private | |||||||||||||||||||||||||||
| 512 | 59 | ▶ | $keyref->{key} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 513 | 59 | my $function = $keyref->{digest}; | |||||||||||||||||||||||||||
| 514 | 59 | return &$function( $private, @_ ); | |||||||||||||||||||||||||||
| 515 | 26 | }; | |||||||||||||||||||||||||||
| 516 | 26 | return; | |||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | 59 | ▶ | sub _mac_function { ## apply keyed hash function to argument | ||||||||||||||||||||||||||
|
Subroutine
_mac_function: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 521 | 59 | my ( $self, @argument ) = @_; | |||||||||||||||||||||||||||
| 522 | 59 | my $owner = $self->{owner}->canonical; | |||||||||||||||||||||||||||
| 523 | 59 | ▶ | $self->algorithm( $self->algorithm ) unless $keytable{$owner}{digest}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 524 | 59 | my $keyref = $keytable{$owner}; | |||||||||||||||||||||||||||
| 525 | 59 | ▶ | $keyref->{digest} = $self->sig_function unless $keyref->{digest}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 526 | 59 | my $function = $keyref->{key}; | |||||||||||||||||||||||||||
| 527 | 59 | return &$function(@argument); | |||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | # _chain() creates a new TSIG object linked to the original | ||||||||||||||||||||||||||||
| 533 | # RR, for the purpose of signing multi-message transfers. | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | 7 | ▶ | sub _chain { | ||||||||||||||||||||||||||
|
Subroutine
_chain: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 536 | 45 | my $self = shift; | |||||||||||||||||||||||||||
| 537 | 45 | $self->{link} = undef; | |||||||||||||||||||||||||||
| 538 | 45 | return bless {%$self, link => $self}, ref($self); | |||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | ######################################## | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | 7 | 1; | |||||||||||||||||||||||||||
| 545 | __END__ | ||||||||||||||||||||||||||||