1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
|
package Net::DNS::RR::RRSIG;
use strict;
use warnings;
our $VERSION = (qw$Id: RRSIG.pm 2003 2025-01-21 12:06:06Z willem $)[2];
use base qw(Net::DNS::RR);
=head1 NAME
Net::DNS::RR::RRSIG - DNS RRSIG resource record
=cut
use integer;
use Carp;
use Time::Local;
use Net::DNS::Parameters qw(:type);
use constant DEBUG => 0;
use constant UTIL => defined eval { require Scalar::Util; };
eval { require MIME::Base64 };
## IMPORTANT: MUST NOT include crypto packages in metadata (strong crypto prohibited in many territories)
use constant DNSSEC => defined $INC{'Net/DNS/SEC.pm'}; ## Discover how we got here, without exposing any crypto
my @index;
if (DNSSEC) {
foreach my $class ( map {"Net::DNS::SEC::$_"} qw(Private RSA DSA ECDSA EdDSA Digest SM2) ) {
my @algorithms = eval join '', qw(r e q u i r e), " $class; ${class}::_index()"; ## no critic
push @index, map { ( $_ => $class ) } @algorithms;
}
croak 'Net::DNS::SEC version not supported' unless scalar(@index);
}
my %DNSSEC_verify = @index;
my %DNSSEC_siggen = @index;
my @deprecated = ( 1, 3, 6, 12 ); # RFC8624
delete @DNSSEC_siggen{@deprecated};
my @field = qw(typecovered algorithm labels orgttl sigexpiration siginception keytag);
sub _decode_rdata { ## decode rdata from wire-format octet string
my ( $self, $data, $offset, @opaque ) = @_;
my $limit = $offset + $self->{rdlength};
@{$self}{@field} = unpack "\@$offset n C2 N3 n", $$data;
( $self->{signame}, $offset ) = Net::DNS::DomainName->decode( $data, $offset + 18, @opaque );
$self->{sigbin} = substr $$data, $offset, $limit - $offset;
return;
}
sub _encode_rdata { ## encode rdata as wire-format octet string
my $self = shift;
my $signame = $self->{signame};
return pack 'n C2 N3 n a* a*', @{$self}{@field}, $signame->canonical, $self->sigbin;
}
sub _format_rdata { ## format rdata portion of RR string.
my $self = shift;
my $signame = $self->{signame};
my @sig64 = split /\s+/, MIME::Base64::encode( $self->sigbin );
my @rdata = ( map( { $self->$_ } @field ), $signame->string, @sig64 );
$rdata[3] .= "\n";
return @rdata;
}
sub _parse_rdata { ## populate RR from rdata in argument list
my ( $self, @argument ) = @_;
foreach ( @field, qw(signame) ) { $self->$_( shift @argument ) }
$self->signature(@argument);
return;
}
sub _defaults { ## specify RR attribute default values
my $self = shift;
$self->sigval(30);
return;
}
sub typecovered {
my ( $self, @value ) = @_;
for (@value) { $self->{typecovered} = typebyname($_) }
my $typecode = $self->{typecovered};
return defined $typecode ? typebyval($typecode) : undef;
}
sub algorithm {
my ( $self, $arg ) = @_;
unless ( ref($self) ) { ## class method or simple function
my $argn = pop;
return $argn =~ /[^0-9]/ ? _algbyname($argn) : _algbyval($argn);
}
return $self->{algorithm} unless defined $arg;
return _algbyval( $self->{algorithm} ) if $arg =~ /MNEMONIC/i;
return $self->{algorithm} = _algbyname($arg);
}
sub labels {
my ( $self, @value ) = @_;
for (@value) { $self->{labels} = 0 + $_ }
return $self->{labels} || 0;
}
sub orgttl {
my ( $self, @value ) = @_;
for (@value) { $self->{orgttl} = 0 + $_ }
return $self->{orgttl} || 0;
}
sub sigexpiration {
my ( $self, @value ) = @_;
for (@value) { $self->{sigexpiration} = _string2time($_) }
my $time = $self->{sigexpiration};
return unless defined wantarray && defined $time;
return UTIL ? Scalar::Util::dualvar( $time, _time2string($time) ) : _time2string($time);
}
sub siginception {
my ( $self, @value ) = @_;
for (@value) { $self->{siginception} = _string2time($_) }
my $time = $self->{siginception};
return unless defined wantarray && defined $time;
return UTIL ? Scalar::Util::dualvar( $time, _time2string($time) ) : _time2string($time);
}
sub sigex { return &sigexpiration; } ## historical
sub sigin { return &siginception; } ## historical
sub sigval {
my ( $self, @value ) = @_;
no integer;
return ( $self->{sigval} ) = map { int( 86400 * $_ ) } @value;
}
sub keytag {
my ( $self, @value ) = @_;
for (@value) { $self->{keytag} = 0 + $_ }
return $self->{keytag} || 0;
}
sub signame {
my ( $self, @value ) = @_;
for (@value) { $self->{signame} = Net::DNS::DomainName->new($_) }
return $self->{signame} ? $self->{signame}->name : undef;
}
sub sig {
my ( $self, @value ) = @_;
return MIME::Base64::encode( $self->sigbin(), "" ) unless scalar @value;
return $self->sigbin( MIME::Base64::decode( join "", @value ) );
}
sub sigbin {
my ( $self, @value ) = @_;
for (@value) { $self->{sigbin} = $_ }
return $self->{sigbin} || "";
}
sub signature { return &sig; }
sub create {
unless (DNSSEC) {
croak qq[No "use Net::DNS::SEC" declaration in application code];
} else {
my ( $class, $rrsetref, $priv_key, %etc ) = @_;
$rrsetref = [$rrsetref] unless ref($rrsetref) eq 'ARRAY';
my $RR = $rrsetref->[0];
croak '$rrsetref is not reference to RR array' unless ref($RR) =~ /^Net::DNS::RR/;
# All the TTLs need to be the same in the data RRset.
my $ttl = $RR->ttl;
croak 'RRs in RRset do not have same TTL' if grep { $_->ttl != $ttl } @$rrsetref;
my $private = ref($priv_key) ? $priv_key : Net::DNS::SEC::Private->new($priv_key);
croak 'unable to parse private key' unless ref($private) eq 'Net::DNS::SEC::Private';
my @label = grep { $_ ne chr(42) } $RR->{owner}->_wire; # count labels
my $self = Net::DNS::RR->new(
name => $RR->name,
type => 'RRSIG',
class => 'IN',
ttl => $ttl,
typecovered => $RR->type,
labels => scalar @label,
orgttl => $ttl,
siginception => time(),
algorithm => $private->algorithm,
keytag => $private->keytag,
signame => $private->signame,
);
while ( my ( $attribute, $value ) = each %etc ) {
$self->$attribute($value);
}
$self->{sigexpiration} = $self->{siginception} + $self->{sigval}
unless $self->{sigexpiration};
my $sigdata = $self->_CreateSigData($rrsetref);
$self->_CreateSig( $sigdata, $private );
return $self;
}
}
sub verify {
# Reminder...
# $rrsetref must be a reference to an array of RR objects.
# $keyref is either a key object or a reference to an array of key objects.
unless (DNSSEC) {
croak qq[No "use Net::DNS::SEC" declaration in application code];
} else {
my ( $self, $rrsetref, $keyref ) = @_;
croak '$keyref argument is scalar or undefined' unless ref($keyref);
print '$keyref argument is ', ref($keyref), "\n" if DEBUG;
if ( ref($keyref) eq "ARRAY" ) {
# We will iterate over the supplied key list and
# return when there is a successful verification.
# If not, continue so that we survive key-id collision.
print "Iterating over ", scalar(@$keyref), " keys\n" if DEBUG;
my @error;
foreach my $keyrr (@$keyref) {
my $result = $self->verify( $rrsetref, $keyrr );
return $result if $result;
my $error = $self->{vrfyerrstr};
my $keyid = $keyrr->keytag;
push @error, "key $keyid: $error";
print "key $keyid: $error\n" if DEBUG;
next;
}
$self->{vrfyerrstr} = join "\n", @error;
return 0;
} elsif ( $keyref->isa('Net::DNS::RR::DNSKEY') ) {
print "Validating using key with keytag: ", $keyref->keytag, "\n" if DEBUG;
} else {
croak join ' ', ref($keyref), 'can not be used as DNSSEC key';
}
$rrsetref = [$rrsetref] unless ref($rrsetref) eq 'ARRAY';
my $RR = $rrsetref->[0];
croak '$rrsetref not a reference to array of RRs' unless ref($RR) =~ /^Net::DNS::RR/;
if (DEBUG) {
print "\n ---------------------- RRSIG DEBUG --------------------";
print "\n SIG:\t", $self->string;
print "\n KEY:\t", $keyref->string;
print "\n -------------------------------------------------------\n";
}
$self->{vrfyerrstr} = '';
unless ( $self->algorithm == $keyref->algorithm ) {
$self->{vrfyerrstr} = 'algorithm does not match';
return 0;
}
unless ( $self->keytag == $keyref->keytag ) {
$self->{vrfyerrstr} = 'keytag does not match';
return 0;
}
my $sigdata = $self->_CreateSigData($rrsetref);
$self->_VerifySig( $sigdata, $keyref ) || return 0;
# time to do some time checking.
my $t = time;
if ( _ordered( $self->{sigexpiration}, $t ) ) {
$self->{vrfyerrstr} = join ' ', 'Signature expired at', $self->sigexpiration;
return 0;
} elsif ( _ordered( $t, $self->{siginception} ) ) {
$self->{vrfyerrstr} = join ' ', 'Signature valid from', $self->siginception;
return 0;
}
return 1;
}
} #END verify
sub vrfyerrstr {
my $self = shift;
return $self->{vrfyerrstr};
}
########################################
{
my @algbyname = (
'DELETE' => 0, # [RFC4034][RFC4398][RFC8078]
'RSAMD5' => 1, # [RFC3110][RFC4034]
'DH' => 2, # [RFC2539]
'DSA' => 3, # [RFC3755][RFC2536]
## Reserved => 4, # [RFC6725]
'RSASHA1' => 5, # [RFC3110][RFC4034]
'DSA-NSEC3-SHA1' => 6, # [RFC5155]
'RSASHA1-NSEC3-SHA1' => 7, # [RFC5155]
'RSASHA256' => 8, # [RFC5702]
## Reserved => 9, # [RFC6725]
'RSASHA512' => 10, # [RFC5702]
## Reserved => 11, # [RFC6725]
'ECC-GOST' => 12, # [RFC5933]
'ECDSAP256SHA256' => 13, # [RFC6605]
'ECDSAP384SHA384' => 14, # [RFC6605]
'ED25519' => 15, # [RFC8080]
'ED448' => 16, # [RFC8080]
'SM2SM3' => 17, # [RFC-cuiling-dnsop-sm2-alg-15]
'ECC-GOST12' => 23, # [RFC-makarenko-gost2012-dnssec-05]
'INDIRECT' => 252, # [RFC4034]
'PRIVATEDNS' => 253, # [RFC4034]
'PRIVATEOID' => 254, # [RFC4034]
## Reserved => 255, # [RFC4034]
);
my %algbyval = reverse @algbyname;
foreach (@algbyname) { s/[\W_]//g; } # strip non-alphanumerics
my @algrehash = map { /^\d/ ? ($_) x 3 : uc($_) } @algbyname;
my %algbyname = @algrehash; # work around broken cperl
sub _algbyname {
my $arg = shift;
my $key = uc $arg; # synthetic key
$key =~ s/[\W_]//g; # strip non-alphanumerics
my $val = $algbyname{$key};
return $val if defined $val;
return $key =~ /^\d/ ? $arg : croak qq[unknown algorithm $arg];
}
sub _algbyval {
my $value = shift;
return $algbyval{$value} || return $value;
}
}
sub _CreateSigData {
# This method creates the data string that will be signed.
# See RFC4034(6) and RFC6840(5.1) on how this string is constructed
# This method is called by the method that creates a signature
# and by the method that verifies the signature. It is assumed
# that the creation method has checked that all the TTLs are
# the same for the rrsetref and that sig->orgttl has been set
# to the TTL of the data. This method will set the datarr->ttl
# to the sig->orgttl for all the RR in the rrsetref.
if (DNSSEC) {
my ( $self, $rrsetref ) = @_;
print "_CreateSigData\n" if DEBUG;
my $sigdata = pack 'n C2 N3 n a*', @{$self}{@field}, $self->{signame}->canonical;
print "\npreamble\t", unpack( 'H*', $sigdata ), "\n" if DEBUG;
my $owner = $self->{owner}; # create wildcard domain name
my $limit = $self->{labels};
my @label = $owner->_wire;
shift @label while scalar @label > $limit;
my $wild = bless {label => \@label}, ref($owner); # DIY to avoid wrecking name cache
my $suffix = $wild->canonical;
unshift @label, chr(42); # asterisk
my @RR = map { bless( {%$_}, ref($_) ) } @$rrsetref; # shallow RR clone
my $rr = $RR[0];
my $class = $rr->class;
my $type = $rr->type;
my $ttl = $self->orgttl;
my %table;
foreach my $RR (@RR) {
my $ident = $RR->{owner}->canonical;
my $match = substr $ident, -length($suffix);
croak 'RRs in RRset have different NAMEs' if $match ne $suffix;
croak 'RRs in RRset have different TYPEs' if $type ne $RR->type;
croak 'RRs in RRset have different CLASS' if $class ne $RR->class;
$RR->ttl($ttl); # reset TTL
my $offset = 10 + length($suffix); # RDATA offset
if ( $ident ne $match ) {
$RR->{owner} = $wild;
$offset += 2;
print "\nsubstituting wildcard name: ", $RR->name if DEBUG;
}
# For sorting we create a hash table of canonical data keyed on RDATA
my $canonical = $RR->canonical;
$table{substr $canonical, $offset} = $canonical;
}
$sigdata = join '', $sigdata, map { $table{$_} } sort keys %table;
if (DEBUG) {
my $i = 0;
foreach my $rdata ( sort keys %table ) {
print "\n>>> ", $i++, "\tRDATA:\t", unpack 'H*', $rdata;
print "\nRR: ", unpack( 'H*', $table{$rdata} ), "\n";
}
print "\n sigdata:\t", unpack( 'H*', $sigdata ), "\n";
}
return $sigdata;
}
}
sub _CreateSig {
if (DNSSEC) {
my ( $self, @argument ) = @_;
my $algorithm = $self->algorithm;
return eval {
my $class = $DNSSEC_siggen{$algorithm};
die "algorithm $algorithm not supported\n" unless $class;
$self->sigbin( $class->sign(@argument) );
} || return croak "${@}signature generation failed";
}
}
sub _VerifySig {
if (DNSSEC) {
my ( $self, @argument ) = @_;
my $algorithm = $self->algorithm;
my $returnval = eval {
my $class = $DNSSEC_verify{$algorithm};
die "algorithm $algorithm not supported\n" unless $class;
$class->verify( @argument, $self->sigbin );
};
unless ($returnval) {
$self->{vrfyerrstr} = "${@}signature verification failed";
print "\n", $self->{vrfyerrstr}, "\n" if DEBUG;
return 0;
}
# uncoverable branch true # unexpected return value from EVP_DigestVerify
croak "internal error in algorithm $algorithm verification" unless $returnval == 1;
print "\nalgorithm $algorithm verification successful\n" if DEBUG;
return $returnval;
}
}
sub _ordered() { ## irreflexive 32-bit partial ordering
my ( $n1, $n2 ) = @_;
return 0 unless defined $n2; # ( any, undef )
return 1 unless defined $n1; # ( undef, any )
# unwise to assume 64-bit arithmetic, or that 32-bit integer overflow goes unpunished
use integer; # fold, leaving $n2 non-negative
$n1 = ( $n1 & 0xFFFFFFFF ) ^ ( $n2 & 0x80000000 ); # -2**31 <= $n1 < 2**32
$n2 = ( $n2 & 0x7FFFFFFF ); # 0 <= $n2 < 2**31
return $n1 < $n2 ? ( $n1 > ( $n2 - 0x80000000 ) ) : ( $n2 < ( $n1 - 0x80000000 ) );
}
my $y1998 = timegm( 0, 0, 0, 1, 0, 1998 );
my $y2026 = timegm( 0, 0, 0, 1, 0, 2026 );
my $y2082 = $y2026 << 1;
my $y2054 = $y2082 - $y1998;
my $m2026 = int( 0x80000000 - $y2026 );
my $m2054 = int( 0x80000000 - $y2054 );
my $t2082 = int( $y2082 & 0x7FFFFFFF );
my $t2100 = 1960058752;
sub _string2time { ## parse time specification string
my $arg = shift;
return int($arg) if length($arg) < 12;
my ( $y, $m, @dhms ) = unpack 'a4 a2 a2 a2 a2 a2', $arg . '00';
if ( $arg lt '20380119031408' ) { # calendar folding
return timegm( reverse(@dhms), $m - 1, $y ) if $y < 2026;
return timegm( reverse(@dhms), $m - 1, $y - 56 ) + $y2026;
} elsif ( $y > 2082 ) {
my $z = timegm( reverse(@dhms), $m - 1, $y - 84 ); # expunge 29 Feb 2100
return $z < 1456790400 ? $z + $y2054 : $z + $y2054 - 86400;
}
return ( timegm( reverse(@dhms), $m - 1, $y - 56 ) + $y2054 ) - $y1998;
}
sub _time2string { ## format time specification string
my $arg = shift;
my $ls31 = int( $arg & 0x7FFFFFFF );
if ( $arg & 0x80000000 ) {
if ( $ls31 > $t2082 ) {
$ls31 += 86400 unless $ls31 < $t2100; # expunge 29 Feb 2100
my ( $yy, $mm, @dhms ) = reverse( ( gmtime( $ls31 + $m2054 ) )[0 .. 5] );
return sprintf '%d%02d%02d%02d%02d%02d', $yy + 1984, $mm + 1, @dhms;
}
my ( $yy, $mm, @dhms ) = reverse( ( gmtime( $ls31 + $m2026 ) )[0 .. 5] );
return sprintf '%d%02d%02d%02d%02d%02d', $yy + 1956, $mm + 1, @dhms;
} elsif ( $ls31 > $y2026 ) {
my ( $yy, $mm, @dhms ) = reverse( ( gmtime( $ls31 - $y2026 ) )[0 .. 5] );
return sprintf '%d%02d%02d%02d%02d%02d', $yy + 1956, $mm + 1, @dhms;
}
my ( $yy, $mm, @dhms ) = reverse( ( gmtime $ls31 )[0 .. 5] );
return sprintf '%d%02d%02d%02d%02d%02d', $yy + 1900, $mm + 1, @dhms;
}
########################################
1;
__END__
=head1 SYNOPSIS
use Net::DNS;
$rr = Net::DNS::RR->new('name RRSIG typecovered algorithm labels
orgttl sigexpiration siginception
keytag signame signature');
use Net::DNS::SEC;
$sigrr = Net::DNS::RR::RRSIG->create(
\@rrset, $keypath,
sigex => 20241230010101,
sigin => 20241201010101
);
$sigrr->verify( \@rrset, $keyrr ) || die $sigrr->vrfyerrstr;
=head1 DESCRIPTION
Class for DNS digital signature (RRSIG) resource records.
In addition to the regular methods inherited from Net::DNS::RR the
class contains a method to sign RRsets using private keys (create)
and a method for verifying signatures over RRsets (verify).
The RRSIG RR is an implementation of RFC4034.
See L<Net::DNS::RR::SIG> for an implementation of SIG0 (RFC2931).
=head1 METHODS
The available methods are those inherited from the base class augmented
by the type-specific methods defined in this package.
Use of undocumented package features or direct access to internal data
structures is discouraged and could result in program termination or
other unpredictable behaviour.
=head2 typecovered
$typecovered = $rr->typecovered;
The typecovered field identifies the type of the RRset that is
covered by this RRSIG record.
=head2 algorithm
$algorithm = $rr->algorithm;
The algorithm number field identifies the cryptographic algorithm
used to create the signature.
algorithm() may also be invoked as a class method or simple function
to perform mnemonic and numeric code translation.
=head2 labels
$labels = $rr->labels;
$rr->labels( $labels );
The labels field specifies the number of labels in the original RRSIG
RR owner name.
=head2 orgttl
$orgttl = $rr->orgttl;
$rr->orgttl( $orgttl );
The original TTL field specifies the TTL of the covered RRset as it
appears in the authoritative zone.
=head2 sigexpiration and siginception times
=head2 sigex sigin sigval
$expiration = $rr->sigexpiration;
$expiration = $rr->sigexpiration( $value );
$inception = $rr->siginception;
$inception = $rr->siginception( $value );
The signature expiration and inception fields specify a validity
time interval for the signature.
The value may be specified by a string with format 'yyyymmddhhmmss'
or a Perl time() value.
Return values are dual-valued, providing either a string value or
numerical Perl time() value.
=head2 keytag
$keytag = $rr->keytag;
$rr->keytag( $keytag );
The keytag field contains the key tag value of the DNSKEY RR that
validates this signature.
=head2 signame
$signame = $rr->signame;
$rr->signame( $signame );
The signer name field value identifies the owner name of the DNSKEY
RR that a validator is supposed to use to validate this signature.
=head2 signature
=head2 sig
$sig = $rr->sig;
$rr->sig( $sig );
The Signature field contains the cryptographic signature that covers
the RRSIG RDATA (excluding the Signature field) and the RRset
specified by the RRSIG owner name, RRSIG class, and RRSIG type
covered fields.
=head2 sigbin
$sigbin = $rr->sigbin;
$rr->sigbin( $sigbin );
Binary representation of the cryptographic signature.
=head2 create
Create a signature over a RR set.
use Net::DNS::SEC;
$keypath = '/home/olaf/keys/Kbla.foo.+001+60114.private';
$sigrr = Net::DNS::RR::RRSIG->create( \@rrsetref, $keypath );
$sigrr = Net::DNS::RR::RRSIG->create(
\@rrsetref, $keypath,
sigex => 20241230010101,
sigin => 20241201010101
);
$sigrr->print;
# Alternatively use Net::DNS::SEC::Private
$private = Net::DNS::SEC::Private->new($keypath);
$sigrr= Net::DNS::RR::RRSIG->create( \@rrsetref, $private );
create() is an alternative constructor for a RRSIG RR object.
This method returns an RRSIG with the signature over the subject rrset
(an array of RRs) made with the private key stored in the key file.
The first argument is a reference to an array that contains the RRset
that needs to be signed.
The second argument is a string which specifies the path to a file
containing the private key as generated by dnssec-keygen.
The optional remaining arguments consist of ( name => value ) pairs
as follows:
sigex => 20241230010101, # signature expiration
sigin => 20241201010101, # signature inception
sigval => 30, # validity window (days)
ttl => 3600
The sigin and sigex values may be specified as Perl time values or as
a string with the format 'yyyymmddhhmmss'. The default for sigin is
the time of signing.
The sigval argument specifies the signature validity window in days
( sigex = sigin + sigval ).
By default the signature is valid for 30 days.
By default the TTL matches the RRset that is presented for signing.
=head2 verify
$verify = $sigrr->verify( $rrsetref, $keyrr );
$verify = $sigrr->verify( $rrsetref, [$keyrr, $keyrr2, $keyrr3] );
$rrsetref contains a reference to an array of RR objects and the
method verifies the RRset against the signature contained in the
$sigrr object itself using the public key in $keyrr.
The second argument can either be a Net::DNS::RR::KEYRR object or a
reference to an array of such objects. Verification will return
successful as soon as one of the keys in the array leads to positive
validation.
Returns 0 on error and sets $sig->vrfyerrstr
=head2 vrfyerrstr
$verify = $sigrr->verify( $rrsetref, $keyrr );
print $sigrr->vrfyerrstr unless $verify;
$sigrr->verify( $rrsetref, $keyrr ) || die $sigrr->vrfyerrstr;
=head1 KEY GENERATION
Private key files and corresponding public DNSKEY records
are most conveniently generated using dnssec-keygen,
a program that comes with the ISC BIND distribution.
dnssec-keygen -a 10 -b 2048 rsa.example.
dnssec-keygen -a 13 -f ksk ecdsa.example.
dnssec-keygen -a 13 ecdsa.example.
Do not change the name of the private key file.
The create method uses the filename as generated by dnssec-keygen
to determine the keyowner, algorithm, and the keyid (keytag).
=head1 REMARKS
The code is not optimised for speed.
It is probably not suitable to be used for signing large zones.
If this code is still around in 2100 (not a leap year) you will
need to check for proper handling of times after 28th February.
=head1 ACKNOWLEDGMENTS
Although their original code may have disappeared following redesign of
Net::DNS, Net::DNS::SEC and the OpenSSL API, the following individual
contributors deserve to be recognised for their significant influence
on the development of the RRSIG package.
Andy Vaskys (Network Associates Laboratories) supplied code for RSA.
T.J. Mather provided support for the DSA algorithm.
Dick Franks added support for elliptic curve and Edwards curve algorithms.
Mike McCauley created the Crypt::OpenSSL::ECDSA perl extension module
specifically for this development.
=head1 COPYRIGHT
Copyright (c)2001-2005 RIPE NCC, Olaf M. Kolkman
Copyright (c)2007-2008 NLnet Labs, Olaf M. Kolkman
Portions Copyright (c)2014 Dick Franks
All rights reserved.
Package template (c)2009,2012 O.M.Kolkman and R.W.Franks.
=head1 LICENSE
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the original copyright notices appear in all copies and that both
copyright notice and this permission notice appear in supporting
documentation, and that the name of the author not be used in advertising
or publicity pertaining to distribution of the software without specific
prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
=head1 SEE ALSO
L<perl> L<Net::DNS> L<Net::DNS::RR>
L<Net::DNS::SEC>
L<RFC4034(3)|https://iana.org/go/rfc4034#section-3>
L<Algorithm Numbers|https://iana.org/assignments/dns-sec-alg-numbers>
L<BIND Administrator Reference Manual|https://bind9.readthedocs.io/en/latest/>
=cut
|