| 1 | package Zonemaster::LDNS::RR::DNSKEYscip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/; |
| 2 | |
| 3 | use strictscip-perl cpan Zonemaster-LDNS 5.0.2 strict/; |
| 4 | use warningsscip-perl cpan Zonemaster-LDNS 5.0.2 warnings/; |
| 5 | |
| 6 | use parentscip-perl cpan Zonemaster-LDNS 5.0.2 parent/ 'Zonemaster::LDNS::RR'; |
| 7 | |
| 8 | sub keysizescip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/keysize(). { |
| 9 | my ( $self ) = @_scip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/`@_`.; |
| 10 | |
| 11 | my $algo = $self->algorithmscip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/algorithm().; |
| 12 | my $data = $self->keydatascip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/keydata().; |
| 13 | |
| 14 | # RSA variants |
| 15 | if ( $algo == 1 || $algo == 5 || $algo == 7 || $algo == 8 || $algo == 10 ) { |
| 16 | |
| 17 | # Read first byte |
| 18 | return -1 |
| 19 | if lengthscip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/length(). $data < 1; |
| 20 | my $byte = unpackscip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/unpack().( "c1", $data ); |
| 21 | |
| 22 | my $remaining; |
| 23 | if ( $byte > 0 ) { |
| 24 | $remaining = lengthscip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/length().( $data ) - 1 - $byte; |
| 25 | } |
| 26 | else { |
| 27 | # Read bytes 1 and 2 as big-endian |
| 28 | return -1 |
| 29 | if lengthscip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/length(). $data < 3; |
| 30 | my $short = unpackscip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/unpack().( "x1s>1", $data ); |
| 31 | |
| 32 | $remaining = lengthscip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/length().( $data ) - 3 - $short; |
| 33 | } |
| 34 | |
| 35 | if ( $remaining < 0 ) { |
| 36 | return -1; |
| 37 | } |
| 38 | else { |
| 39 | return 8 * $remaining; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | # DSA variants |
| 44 | elsif ( $algo == 3 || $algo == 6 ) { |
| 45 | |
| 46 | # Read first byte (the T value) |
| 47 | return -1 |
| 48 | if lengthscip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/length(). $data < 1; |
| 49 | return unpackscip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/unpack().( "c1", $data ); |
| 50 | } |
| 51 | |
| 52 | # Diffie-Hellman |
| 53 | elsif ( $algo == 2 ) { |
| 54 | |
| 55 | # Read bytes 4 and 5 as big-endian |
| 56 | return -1 |
| 57 | if lengthscip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/length(). $data < 6; |
| 58 | return unpackscip-perl cpan Zonemaster-LDNS 5.0.2 Zonemaster/LDNS/RR/DNSKEY/unpack().( "x4s>1", $data ); |
| 59 | } |
| 60 | |
| 61 | # No idea what this is |
| 62 | else { |
| 63 | return 0; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | 1; |
| 68 | |
| 69 | =head1 NAME |
| 70 | |
| 71 | Zonemaster::LDNS::RR::DNSKEY - Type DNSKEY record |
| 72 | |
| 73 | =head1 DESCRIPTION |
| 74 | |
| 75 | A subclass of L<Zonemaster::LDNS::RR>, so it has all the methods of that class available in addition to the ones documented here. |
| 76 | |
| 77 | =head1 METHODS |
| 78 | |
| 79 | =over |
| 80 | |
| 81 | =item flags() |
| 82 | |
| 83 | Returns the flag field as a number. |
| 84 | |
| 85 | =item protocol() |
| 86 | |
| 87 | Returns the protocol number. |
| 88 | |
| 89 | =item algorithm() |
| 90 | |
| 91 | Returns the algorithm number. |
| 92 | |
| 93 | =item keydata() |
| 94 | |
| 95 | Returns the cryptographic key in binary form. |
| 96 | |
| 97 | =item hexkeydata() |
| 98 | |
| 99 | Returns the cryptographic key as a hexadecimal string. |
| 100 | |
| 101 | =item keytag() |
| 102 | |
| 103 | Calculates the keytag. |
| 104 | |
| 105 | =item ds($hash) |
| 106 | |
| 107 | Returns a L<Zonemaster::LDNS::RR::DS> record matching this key. The argument must be one of the strings 'sha1', 'sha256', 'sha384' or 'gost'. GOST may not |
| 108 | be available, depending on how you ldns library was compiled. |
| 109 | |
| 110 | =item keysize() |
| 111 | |
| 112 | The size of the key stored in the record. For RSA variants, it's the length in bits of the prime number. For DSA variants, it's the key's "T" value |
| 113 | (see RFC2536). For DH, it's the value of the "prime length" field (and probably useless, since DH keys can't have signature records). |
| 114 | If there is insufficient data in the public key field to calculate the key size, C<-1> is returned. |
| 115 | |
| 116 | =back |