| 1 | package Net::DNS::SEC::Private; | ||||||||||
| 2 | |||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 10 | our $VERSION = (qw$Id: Private.pm 2063 2026-10-05 11:02:58Z willem $)[2]; | |||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | Net::DNS::SEC::Private - DNSSEC Private key object | ||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||
| 15 | |||||||||||
| 16 | use Net::DNS::SEC::Private; | ||||||||||
| 17 | |||||||||||
| 18 | $private = Net::DNS::SEC::Private->new( $keypath ); | ||||||||||
| 19 | |||||||||||
| 20 | $private = Net::DNS::SEC::Private->new( | ||||||||||
| 21 | 'algorithm' => '13', | ||||||||||
| 22 | 'keytag' => '26512', | ||||||||||
| 23 | 'privatekey' => 'h/mc+iq9VDUbNAjQgi8S8JzlEX29IALchwJmNM3QYKk=', | ||||||||||
| 24 | 'signame' => 'example.com.' | ||||||||||
| 25 | ); | ||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||
| 29 | |||||||||||
| 30 | Class representing private keys as read from a keyfile generated by BIND | ||||||||||
| 31 | dnssec-keygen. The class is written to be used only in the context of the | ||||||||||
| 32 | Net::DNS::RR::RRSIG create method. This class is not designed to interact | ||||||||||
| 33 | with any other system. | ||||||||||
| 34 | |||||||||||
| 35 | =cut | ||||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | 10 | ▶ | use integer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 39 | 10 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 10 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 10 | ▶ | use IO::File; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | |||||||||||
| 43 | 10 | ▶ | use constant SYMLINK => defined(&CORE::readlink); # Except Win32, VMS, RISC OS | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | 20 | ▶ | sub new { return scalar(@_) > 2 ? &_new_params : &_new_keyfile } | ||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | 18 | ▶ | sub _new_keyfile { | ||||||||
|
Subroutine
_new_keyfile: called CC=6 SCAR=17.9
| |||||||||||
| 49 | 18 | my ( $class, $file ) = @_; | |||||||||
| 50 | |||||||||||
| 51 | 18 | my ($keypath) = SYMLINK ? grep( {$_} readlink($file), $file ) : $file; | |||||||||
| 52 | 18 | my ( $vol, $dir, $name ) = File::Spec->splitpath($keypath); | |||||||||
| 53 | |||||||||||
| 54 | # Format something like: 'Kbla.foo.+001+12345.private' as created by BIND dnssec-keygen. | ||||||||||
| 55 | 18 | ▶ | croak "$file does not appear to be a BIND private key" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | unless $name =~ /^K([^+]+)\+(\d+)\+(\d+)\.private$/; | ||||||||||
| 57 | 17 | my @identifier = ( signame => $1, algorithm => 0 + $2, keytag => 0 + $3 ); | |||||||||
| 58 | |||||||||||
| 59 | 17 | ▶ | my $handle = IO::File->new( $file, '<' ) or croak qq("$file": $!); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | |||||||||||
| 61 | 16 | my @content; | |||||||||
| 62 | 16 | local $_; | |||||||||
| 63 | 16 | ▶ | while (<$handle>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 135 | chomp; | |||||||||
| 65 | 135 | ▶ | next if /^$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 134 | ▶ | next if /^\s*[;]/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 132 | s/\(.+\)//; | |||||||||
| 68 | 132 | my ( $name, $value ) = split; | |||||||||
| 69 | 132 | push @content, $name, $value; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 16 | return $class->_new_params( @content, @identifier ); | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | |||||||||||
| 76 | 18 | ▶ | sub _new_params { | ||||||||
|
Subroutine
_new_params: called CC=4 SCAR=13.9
| |||||||||||
| 77 | 18 | my ( $class, %parameter ) = @_; | |||||||||
| 78 | 18 | my $hashref = {}; | |||||||||
| 79 | |||||||||||
| 80 | 18 | ▶ | while ( my ( $name, $value ) = each %parameter ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 182 | $name =~ tr/A-Za-z0-9\000-\377/a-za-z0-9/d; | |||||||||
| 82 | 182 | $hashref->{$name} = $value; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 18 | ▶ | my $self = bless sub { $hashref->{shift()} }, $class; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 86 | 18 | ▶ | croak 'no algorithm specified' unless $self->algorithm; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 17 | ▶ | croak 'no signame specified' unless $self->signame; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 16 | return $self; | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | 20 | ▶ | sub _deprecate { return my @empty } ## dummy deprecation list | ||||||||
|
Subroutine
_deprecate: called CC=1 SCAR=0.0
| |||||||||||
| 93 | 10 | ▶ | sub _index { return &_deprecate } ## dummy algorithm index | ||||||||
|
Subroutine
_index: called CC=1 SCAR=0.0
| |||||||||||
| 94 | |||||||||||
| 95 | 50 | ▶ | sub AUTOLOAD { ## Dynamic instance methods | ||||||||
|
Subroutine
AUTOLOAD: called CC=1 SCAR=0.0
| |||||||||||
| 96 | 50 | my ($self) = @_; | |||||||||
| 97 | 50 | our $AUTOLOAD; | |||||||||
| 98 | |||||||||||
| 99 | 50 | my ($attribute) = $AUTOLOAD =~ m/::([^:]*)$/; | |||||||||
| 100 | 50 | $attribute =~ tr/A-Za-z0-9\000-\377/a-za-z0-9/d; | |||||||||
| 101 | |||||||||||
| 102 | # Build a method in the class | ||||||||||
| 103 | 10 | ▶ | no strict 'refs'; ## no critic ProhibitNoStrict | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 104 | 50 | ▶ | *{$AUTOLOAD} = sub { &{shift()}($attribute) }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 105 | |||||||||||
| 106 | # and jump to it | ||||||||||
| 107 | 50 | goto &{$AUTOLOAD}; | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | |||||||||||
| 111 | 10 | 1; | |||||||||
| 112 | __END__ | ||||||||||