File: SSHFP.pm

package info (click to toggle)
libnet-dns-perl 0.59-1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 828 kB
  • ctags: 400
  • sloc: perl: 6,650; sh: 220; ansic: 101; makefile: 60
file content (217 lines) | stat: -rw-r--r-- 4,122 bytes parent folder | download | duplicates (2)
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
package Net::DNS::RR::SSHFP;
#
# $Id: SSHFP.pm 388 2005-06-22 10:06:05Z olaf $
#
use strict;
BEGIN { 
    eval { require bytes; }
} 
use vars qw(@ISA $VERSION $HasBabble);

BEGIN {
	eval {
		require Digest::BubbleBabble; 
		Digest::BubbleBabble->import(qw(bubblebabble))
	};
		
	$HasBabble = $@ ? 0 : 1;
	
}

$VERSION = (qw$LastChangedRevision: 388 $)[1];

@ISA = qw(Net::DNS::RR);

my %algtype = (
	RSA => 1,
	DSA => 2,
);

my %fingerprinttype = (
	'SHA-1' => 1,
);

my %fingerprinttypebyval = reverse %fingerprinttype;
my %algtypebyval	     = reverse %algtype;


sub new {
    my ($class, $self, $data, $offset) = @_;
    
	if ($self->{'rdlength'} > 0) {
		my $offsettoalg    = $offset;
		my $offsettofptype = $offset+1;
		my $offsettofp     = $offset+2;
		my $fplength       = 20;   # This will need to change if other fingerprint types
								   # are being deployed.
	
	
		$self->{'algorithm'} = unpack('C', substr($$data, $offsettoalg, 1));
		$self->{'fptype'}    = unpack('C', substr($$data, $offsettofptype, 1));
	
		die "This fingerprint type $self->{'fptype'} has not yet been implemented\n." . 
			"Contact developer of Net::DNS::RR::SSHFP.\n" 
				unless defined $fingerprinttypebyval{$self->{'fptype'}};
							   
		# All this is SHA-1 dependend
		$self->{'fpbin'} = substr($$data,$offsettofp, $fplength); # SHA1 digest 20 bytes long
	
		$self->{'fingerprint'} = uc unpack('H*', $self->{'fpbin'});
    }
    
    
    return bless $self, $class;
}


sub new_from_string {
	my ($class, $self, $string) = @_;
	
	if ($string) {		
		$string =~ tr/()//d;
		$string =~ s/;.*$//mg;
		$string =~ s/\n//g;
		
		@{$self}{qw(algorithm fptype fingerprint)} = split(m/\s+/, $string, 3);
					
		# We allow spaces in the fingerprint.
		$self->{'fingerprint'} =~ s/\s//g;		
    }
	    
	return bless $self, $class;
}



sub rdatastr {
	my $self     = shift;
	my $rdatastr = '';

	if (exists $self->{"algorithm"}) {
		$rdatastr = join('  ', @{$self}{qw(algorithm fptype fingerprint)}) 
					.' ; ' . $self->babble;
	} 

	return $rdatastr;
}

sub rr_rdata {
    my $self = shift;

    if (exists $self->{"algorithm"}) {   	    
    	return pack('C2',  @{$self}{qw(algorithm fptype)}) . $self->fpbin;
    }
    
    return '';

}



sub babble {
    my $self = shift;
    
    if ($HasBabble) {
		return bubblebabble(Digest => $self->fpbin);	
    } else {
		return "";
    }
}


sub fpbin {
	my ($self) = @_;
			
	return $self->{'fpbin'} ||= pack('H*', $self->{'fingerprint'});
}
	

1;


=head1 NAME

Net::DNS::RR::SSHFP - DNS SSHFP resource record

=head1 SYNOPSIS

C<use Net::DNS::RR>;

=head1 DESCRIPTION

Class for Delegation signer (SSHFP) resource records.

=head1 METHODS

In addition to the regular methods 


=head2 algorithm

    print "algoritm" = ", $rr->algorithm, "\n";

Returns the RR's algorithm field in decimal representation

    1 = RSA
    2 = DSS


=head2 fingerprint

    print "fingerprint" = ", $rr->fingerprint, "\n";

Returns the SHA1 fingerprint over the label and key in hexadecimal
representation.


=head2 fpbin

    $fpbin = $rr->fpbin;

Returns the fingerprint as binary material.


=head2 fptype

   print "fingerprint type" . " = " . $rr->fptype ."\n";

Returns the fingerprint type of the SSHFP RR.

=head2 babble

   print $rr->babble;

If Digest::BubbleBabble is available on the sytem this method returns the
'BabbleBubble' representation of the fingerprint. The 'BabbleBubble'
string may be handy for telephone confirmation.

The 'BabbleBubble' string returned as a comment behind the RDATA when
the string method is called.

The method returns an empty string if Digest::BubbleBable is not installed.

=head1 TODO 

=head1 ACKNOWLEDGEMENT

Jakob Schlyter for code review and supplying patches.

=head1 COPYRIGHT

Copyright (c) 2004 RIPE NCC, Olaf Kolkman.

"All rights reserved, This program is free software; you may redistribute it
and/or modify it under the same terms as Perl itself.

=head1 SEE ALSO

L<perl(1)>, L<Net::DNS>, L<Net::DNS::Resolver>, L<Net::DNS::Packet>,
L<Net::DNS::Header>, L<Net::DNS::Question>, L<Net::DNS::RR>,
draft-ietf-dnssext-delegation-signer

=cut