| 1 | package PGP::Finger::DNS; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | extends 'PGP::Finger::Source'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # ABSTRACT: gpgfinger source to query DNS for OPENPGPKEYs | ||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '1.1'; # VERSION | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Net::DNS::Resolver; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Digest::SHA qw(sha224_hex); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use PGP::Finger::Result; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use PGP::Finger::Key; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | has 'dnssec' => ( is => 'rw', isa => 'Bool', default => 1 ); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | has _resolver => ( is => 'ro', isa => 'Net::DNS::Resolver', lazy => 1, | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 20 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 21 | 0 | my $res = Net::DNS::Resolver->new; | |||||||||||||||||||||||||||
| 22 | 0 | $res->dnssec( $self->dnssec ); | |||||||||||||||||||||||||||
| 23 | 0 | return( $res ); | |||||||||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||||||||||
| 25 | 1 | ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | has 'rr_types' => ( is => 'rw', isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||
| 28 | 0 | ▶ | default => sub { [ 'TYPE61' ] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 29 | 1 | ); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub fetch { | ||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 0 | my ( $self, $addr ) = @_; | |||||||||||||||||||||||||||
| 33 | 0 | my ($local, $domain) = split('@', $addr, 2); | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | if( ! defined $local || ! defined $domain ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $local and defined $domain
MC/DC0%0/2
defined $local and defined $domain
defined $local
defined $domain
Truth table0%0/3
A and B
A= defined $localB= defined $domain
| |||||||||||||||||||||||||||||
| 35 | 0 | die("could not parse mail address $addr"); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 0 | my $record = join('.', sha224_hex($local), '_openpgpkey', $domain); | |||||||||||||||||||||||||||
| 38 | 0 | my $result = PGP::Finger::Result->new; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | foreach my $rr_type ( @{$self->rr_types} ) { | |||||||||||||||||||||||||||
| 41 | 0 | my $reply = $self->_resolver->query( $record, $rr_type ); | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | if( ! defined $reply ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | die("error while looking up $rr_type: ".$self->_resolver->errorstring); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 0 | foreach my $rr ( $reply->answer ) { | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | if($rr->type ne $rr_type ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | next; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 0 | my $key = PGP::Finger::Key->new( | |||||||||||||||||||||||||||
| 50 | mail => $addr, | ||||||||||||||||||||||||||||
| 51 | data => $rr->rdata, | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | 0 | $key->set_attr( source => 'DNS' ); | |||||||||||||||||||||||||||
| 54 | 0 | $key->set_attr( domain => $domain ); | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | $key->set_attr( dnssec => $reply->header->ad ? 'ok' : 'unauthenticated' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | $result->add_key( $key ); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | return $result; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | 1; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||