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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
|
#!/usr/bin/perl
#
# Copyright 2012 SPARTA, Inc. All rights reserved. See the COPYING
# file distributed with this software for details.
#
#
# keymod
#
# This script modifies key parameters in a keyrec file.
# The new key parameters will be used by zonesigner in future executions.
#
use strict;
use Getopt::Long qw(:config no_ignore_case_always);
use Net::DNS::SEC::Tools::keyrec;
use Net::DNS::SEC::Tools::tooloptions;
#
# Version information.
#
my $NAME = "keymod";
my $VERS = "$NAME version: 1.13.0";
my $DTVERS = "DNSSEC-Tools Version: 1.13";
#######################################################################
my %options = (); # Filled option array.
my @opts =
(
'zone=s', # Zone to edit.
'kskcount=i', # New kskcount.
'ksklength=i', # New ksklength.
'ksklife=i', # New ksklife.
'random=s', # New random.
'revperiod=i', # New revperiod.
'zskcount=i', # New zskcount.
'zsklength=i', # New zsklength.
'zsklife=i', # New zsklife.
'nocheck', # Don't run krfcheck after edit.
'verbose', # Give lotsa output.
'Version', # Display the version number.
'help', # Give a usage message and exit.
);
#
# Flag variables for options.
#
my $zone;
my $random;
my $revperiod;
my $kskcnt;
my $ksklen;
my $zsklen;
my $zskcnt;
my $ksklife;
my $zsklife;
#
# Data required for command line options.
#
my $verbose = 0; # Verbose flag.
my $check = 1; # No-check flag.
#-----------------------------------------------------------------------------
my $zonemods; # Count of mods made to a zone.
my $ret; # Return code from main().
$ret = main();
exit($ret);
#-----------------------------------------------------------------------------
# Routine: main()
#
# Purpose: This routine controls everything.
#
sub main()
{
my $krf; # Keyrec we're editing.
#
# Check our options.
#
doopts();
#
# Modify the keyrec file and validate the changes.
#
foreach $krf (@ARGV)
{
editkrf($krf);
#
# Maybe check the keyrec file for validity.
#
system("krfcheck $krf") if($check);
}
return(0);
}
#-----------------------------------------------------------------------------
# Routine: doopts()
#
# Purpose: This routine gets the options from the command line and does
# a bit of validity checking.
#
sub doopts
{
my $errs = 0; # Error count.
#
# Ensure we were given a keyrec file to check.
#
usage() if(@ARGV == 0);
#
# Parse the options.
#
GetOptions(\%options,@opts) || usage();
#
# Show the version number or help info if requested.
#
version() if(defined($options{'Version'}));
usage() if(defined($options{'help'}));
#
# Set some flags based on the command line.
#
$zone = $options{'zone'};
$kskcnt = $options{'kskcount'};
$ksklen = $options{'ksklength'};
$ksklife = $options{'ksklife'};
$random = $options{'random'};
$revperiod = $options{'revperiod'};
$zskcnt = $options{'zskcount'};
$zsklen = $options{'zsklength'};
$zsklife = $options{'zsklife'};
$check = $options{'check'};
$verbose = $options{'verbose'};
#
# Ensure we're not being asked to do the impossible.
# (The stupid, actually.)
#
if(defined($kskcnt) && ($kskcnt < 0))
{
print STDERR "KSK length must not be negative\n";
$errs++;
}
if(defined($ksklen) && ($ksklen < 0))
{
print STDERR "KSK length must not be negative\n";
$errs++;
}
if(defined($ksklife) && ($ksklife < 0))
{
print STDERR "KSK life must not be negative\n";
$errs++;
}
if(defined($revperiod) && ($revperiod < 0))
{
print STDERR "revocation period must not be negative\n";
$errs++;
}
if(defined($zskcnt) && ($zskcnt < 0))
{
print STDERR "ZSK length must not be negative\n";
$errs++;
}
if(defined($zsklen) && ($zsklen < 0))
{
print STDERR "ZSK length must not be negative\n";
$errs++;
}
if(defined($zsklife) && ($zsklife < 0))
{
print STDERR "ZSK life must not be negative\n";
$errs++;
}
#
# Exit if we hit any errors.
#
exit(1) if($errs);
#
# Delete the non-command options and ensure that we were given
# something to do.
#
delete $options{'zone'};
delete $options{'nocheck'};
delete $options{'verbose'};
if(keys(%options) == 0)
{
print STDERR "you must specify something to be changed\n";
exit(2);
}
if(@ARGV == 0)
{
print STDERR "no keyrec file specified\n";
exit(3);
}
}
#-----------------------------------------------------------------------------
# Routine: editkrf()
#
# Purpose: This routine reads a keyrec file and copies the keyrec
# records into either the roll hash or the skip hash,
# depending on each record's type. Any unrecognized keyrec
# entries are reported.
#
sub editkrf
{
my $krf = shift; # Keyrec file to modify.
#
# Load the keyrec file.
#
if(keyrec_read($krf) < 0)
{
print STDERR "unable to read keyrec file \"$krf\"\n";
exit(4);
}
#
# Go through the keyrecs and apply the needed changes.
#
foreach my $zname (keyrec_names())
{
my $kt; # Keyrec's type.
#
# Go to the next record if:
# - this isn't a zone record
# - we aren't doing everything and
# this isn't the specified record
#
$kt = keyrec_recval($zname,'keyrec_type');
next if($kt ne 'zone');
next if(($zone ne '') && ($zname ne $zone));
#
# Set the keyrec fields as requested by the user.
#
$zonemods = 0;
setter($zname,'new_kskcount',$kskcnt);
setter($zname,'new_ksklength',$ksklen);
setter($zname,'new_ksklife',$ksklife);
setter($zname,'new_random',$random);
setter($zname,'new_revperiod',$revperiod);
setter($zname,'new_zskcount',$zskcnt);
setter($zname,'new_zsklength',$zsklen);
setter($zname,'new_zsklife',$zsklife);
print "zone $zname updated\n" if($zonemods);
}
#
# Close and write the keyrec file.
#
keyrec_close();
}
#----------------------------------------------------------------------
# Routine: setter()
#
# Purpose: Set a new value for a key parameter.
# If the new value is zero (or null), then the field will
# be deleted from the keyrec..
#
sub setter
{
my $zname = shift; # Keyrec name.
my $field = shift; # Field to change.
my $val = shift; # Field's new value.
my $oldval; # Old value.
#
# Do nothing if this field shouldn't be changed.
#
return if(! defined($val));
#
# If the verbose flag was given, we'll show the old value and
# the new value.
#
#
# Change the keyrec field's value or delete the keyrec field.
#
if($val)
{
if($verbose)
{
$oldval = keyrec_recval($zname,$field);
print "$zname: changing $field \"$oldval\" to \"$val\"\n";
}
keyrec_setval('zone',$zname,$field,$val);
}
else
{
if($verbose)
{
$oldval = keyrec_recval($zname,$field);
print "$zname: deleting $field \"$oldval\"\n";
}
keyrec_delval($zname,$field);
}
$zonemods++;
}
#----------------------------------------------------------------------
# Routine: version()
#
# Purpose: Print the version number(s) and exit.
#
sub version
{
print STDERR "$VERS\n";
print STDERR "$DTVERS\n";
exit(0);
}
#-----------------------------------------------------------------------------
# Routine: usage()
#
sub usage
{
print STDERR "usage: keymod [options] <keyrec files>\n";
print STDERR " options:\n";
print STDERR " -zone zonename\n";
print STDERR " -kskcount kskcount\n";
print STDERR " -ksklength ksklength\n";
print STDERR " -ksklife ksklife\n";
print STDERR " -random random\n";
print STDERR " -revperiod revperiod\n";
print STDERR " -zskcount zskcount\n";
print STDERR " -zsklength zsklength\n";
print STDERR " -zsklife zsklife\n";
print STDERR " -nocheck\n";
print STDERR " -verbose\n";
print STDERR " -Version\n";
print STDERR " -help\n";
exit(0);
}
1;
##############################################################################
#
=pod
=head1 NAME
keymod - Modifies key parameters in a DNSSEC-Tools I<keyrec> file
=head1 SYNOPSIS
keymod [options] keyrec1 ... keyrecN
=head1 DESCRIPTION
B<keymod> modifies the key parameters in a keyrec file that are used to
generate cryptographics keys used to sign zones. The new parameters
will be used by B<zonesigner> when generating I<new> keys. It has no
effect on existing keys.
B<zonesigner> will use the new parameter for a zone the next time it
generates a key that requires that parameter. This means that, for example,
a new ZSK length will not be used during the I<next> invocation of
B<zonesigner> if that invocation will be performing KSK-rollover actions.
The following fields may be modified:
kskcount - count of KSK keys
ksklength - length of KSK keys
ksklife - lifetime of KSK keys
random - random number generator device file
revperiod - revocation period for KSK keys
zskcount - count of ZSK keys
zsklength - length of ZSK keys
zsklife - lifetime of ZSK keys
New key/value fields will be added to a zone I<keyrec> file to inform
B<zonesigner> that new values should be used. The key portion of the added
fields will begin with "new_". For example, a new KSK length of 2048 will
be written to the I<keyrec> file as:
new_ksklength 2048
All zone records in the specified I<keyrec> file will be modified, unless the
B<-zone> option is given. In that case, only the named zone will be modified.
If a zone I<keyrec> already contains a new key/value field, then the value
will be modified on subsequent runs of B<keymod>.
=head1 OPTIONS
B<keymod> recognizes the following options. Multiple options may be combined
in a single B<keymod> execution.
All numeric values must be positive or zero.
If a new key/value field should be deleted from a zone I<keyrec>, then a
zero or empty string value should be specified for the appropriate option.
=over 4
=item B<-zone zonename>
The zone I<keyrec> whose name matches I<zonename> is selected as the only
I<keyrec> that will be modified. If this name is not given, then all zone
I<keyrec> records will be modified.
=item B<-ksklength ksklength>
The I<ksklength> field will be modified in the selected I<keyrec> records
to the given value. This is a numeric field whose values depend on the
cryptographic algorithm to be used to generate keys for the zone.
=item B<-kskcount kskcount>
The I<kskcount> field will be modified in the selected I<keyrec> records to the
given value. This is a numeric field.
=item B<-ksklife ksklife>
The I<ksklife> field will be modified in the selected I<keyrec> records to the
given value. This is a numeric field.
=item B<-random random>
The I<random> field will be modified in the selected I<keyrec> records to the
given value. This is a text field that will be passed to the key generator.
=item B<-revperiod revperiod>
The I<revperiod> field will be modified in the selected I<keyrec> records to
the given value. This is a numeric field.
=item B<-zskcount zskcount>
The I<zskcount> field will be modified in the selected I<keyrec> records to the
given value. This is a numeric field.
=item B<-zsklength zsklength>
The I<zsklength> field will be modified in the selected I<keyrec> records
to the given value. This is a numeric field whose values depend on the
cryptographic algorithm to be used to generate keys for the zone.
=item B<-zsklife zsklife>
The I<zsklife> field will be modified in the selected I<keyrec> records to the
given value. This is a numeric field.
=item B<-nocheck>
If this option is given, the B<krfcheck> command will B<not> be run on
the modified I<keyrec> file.
=item B<-verbose>
Display information about every modification made to the I<keyrec> file.
=item B<-Version>
Displays the version information for B<keymod> and the DNSSEC-Tools package.
=item B<-help>
Display a usage message.
=back
=head1 COPYRIGHT
Copyright 2012 SPARTA, Inc. All rights reserved.
See the COPYING file included with the DNSSEC-Tools package for details.
=head1 AUTHOR
Wayne Morrison, tewok@tislabs.com
=head1 SEE ALSO
B<zonesigner(8)>,
B<krfcheck(8)>
B<Net::DNS::SEC::Tools::keyrec.pm(3)>
B<file-keyrec(5)>
=cut
|