File: make-signed-keyset

package info (click to toggle)
libnet-dns-sec-perl 1.26-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 296 kB
  • sloc: perl: 1,425; makefile: 5
file content (157 lines) | stat: -rw-r--r-- 3,696 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
#!/usr/bin/perl
#$Id: make-signed-keyset 1862 2021-12-24 10:09:08Z willem $

#
# takes a bind public key file and creates a self-signed keyset
#

use strict;
use warnings;
use Getopt::Std;
use Net::DNS::SEC;
use Net::DNS::SEC::Keyset;
use Net::DNS::ZoneFile;
use File::Basename;

# global variables
$VERSION  = "0.2";
$verbose  = 0;
$printds  = 0;
$progname = basename($0);
chomp($progname);

# main program
getopts('dvhVf:n:');

if ( defined($opt_d) ) {
	$printds = 1;
}
if ( defined($opt_v) ) {
	$verbose = 1;
}
if ( defined($opt_h) ) {
	&usage();
}
if ( defined($opt_V) ) {
	&version();
}
if ( $#ARGV < 0 ) {
	&usage();
}

# silent some compiler warnings until i figure them out
$opt_d = 0;
$opt_v = 0;
$opt_h = 0;
$opt_V = 0;
&make_keyset(@ARGV);
exit(0);

# print the usage and exit
sub usage {
	print("usage: $progname [-vhV] file\n");
	print("Options:\n");
	print("	      -d    Print the DS record for each key in the keyset.\n");
	print("	      -v    Be verbose.\n");
	print("	      -h    Print this usage message.\n");
	print("	      -V    Print version information.\n");
	print("	      file  BIND public key file.\n");
	exit(0);
}

# print version information
sub version {
	print( "$progname v$VERSION using Net::DNS v", Net::DNS->version, "\n" );
	exit(0);
}

sub make_keyset {
	my $source    = Net::DNS::ZoneFile->new(shift);
	my $file      = $source->name;
	my $directory = dirname($file);
	print("Processing file: $file\n");

	my @keys;
	while ( my $keyrr = $source->read ) {
		next unless $keyrr->isa('Net::DNS::RR::DNSKEY');
		print("Read DNSKEY RR\n") if $verbose;
		push @keys, $keyrr;
	}

	print("Creating keyset\n") if $verbose;

	my $keyset = Net::DNS::SEC::Keyset->new( \@keys, "$directory" )
			or die("$progname: unable to create keyset. $Net::DNS::SEC::Keyset::keyset_err.\n");

	print("Verifying keyset\n") if $verbose;
	$keyset->verify()
			or die("$progname: unable to verify keyset. $Net::DNS::SEC::Keyset::keyset_err.\n");

	if ($verbose) {
		print("Keyset:\n");
		$keyset->print();
		print("Writing keyset\n");
	}
	$keyset->writekeyset("signed-")
			or die("$progname: unable to write keyset. $Net::DNS::SEC::Keyset::keyset_err.\n");

	if ($printds) {
		print("Extracting DS RR\n") if $verbose;
		my @ds = $keyset->extract_ds();
		foreach my $ds (@ds) {
			$ds->print();
		}
	}

	return;
}


=head1 NAME

make-signed-keyset - create a self-signed keyset

=head1 SYNOPSIS

make-signed-keyset [-v] file

=head1 DESCRIPTION

make-signed-keyset is a program that creates a self-signed keyset from
a BIND public key file specified on the command line.

The options are as follows:

=over

=item -v Be verbose.

=item -d Print the DS record for each key in the keyset.

=back


=head1 COPYRIGHT

Copyright (c)2002 Wes Griffin

All Rights Reserved


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.

=cut