#!/usr/bin/perl
#$Id: getkeyset 1862 2021-12-24 10:09:08Z willem $

use strict;
use warnings;
use Net::DNS::SEC;
use Net::DNS::SEC::Keyset;


my $domain = shift || die "At least one argument needed";
my $nameserver = shift;


my $res = Net::DNS::Resolver->new;
$res->dnssec(1);
$res->nameservers($nameserver) if defined $nameserver;

my $packet = $res->query( $domain, 'DNSKEY', 'IN' )
		|| die "No results for query $domain DNSKEY";

my $keyset = Net::DNS::SEC::Keyset->new($packet)
		|| die $Net::DNS::SEC::Keyset::keyset_err;


# Print DS records to STD out
#
my @ds = $keyset->extract_ds;
foreach my $ds (@ds) {
	$ds->print;
}

# write keyset in current dir.
#
$keyset->writekeyset;

1;

__END__


=head1 NAME

getkeyset.pl - DS extraction demo

=head1 SYNOPSIS

getkeyset.pl <domain> [auth_nameserver]

=head1 DESCRIPTION

The program queries for the key-set of 'domain'. Spits out the DS
records and writes the keyset to the current directory.

If the second argument is specified the query is performed to that
nameserver.


=head1 TODO

This is only a demonstration program to show how the interface can be used.


=head1 COPYRIGHT

Copyright (c) 2002 RIPE NCC.  Author Olaf M. Kolkman

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
