File: genkrf

package info (click to toggle)
dnssec-tools 1.13-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 16,064 kB
  • sloc: perl: 44,399; ansic: 31,547; cpp: 21,306; sh: 15,813; xml: 2,113; makefile: 1,390; pascal: 836; python: 290; csh: 11
file content (977 lines) | stat: -rwxr-xr-x 22,743 bytes parent folder | download
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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
#!/usr/bin/perl
#
# Copyright 2005-2012 SPARTA, Inc.  All rights reserved.  See the COPYING
# file distributed with this software for details.
#
#
# genkrf
#
#	This script generates a keyrec file.
#

use strict;

use Getopt::Long qw(:config no_ignore_case_always);
use Net::DNS::SEC::Tools::conf;
use Net::DNS::SEC::Tools::defaults;
use Net::DNS::SEC::Tools::keyrec;
use Net::DNS::SEC::Tools::tooloptions;

#
# Version information.
#
my $NAME   = "genkrf";
my $VERS   = "$NAME version: 1.13.0";
my $DTVERS = "DNSSEC-Tools Version: 1.13";

#######################################################################
#
# Constants
#
our $DEF_TOOLSCONF = "/usr/local/etc/dnssec/dnssec-tools.conf";

#
# A hash mapping algorithm numbers to algorithm names.
#
our %algos = (
	"001" => "rsa",
	"002" => "dh",
	"003" => "dsa",
	"005" => "rsasha1",
	"157" => "hmac_md5"
);

#
# Names of fields from bind-9.3.1/lib/dns/dst_parse.c.
# Private-key-format:  v1.2
# These help in finding the size of the key from the .private key file.
#
our %algofields = (
	"001" => "Modulus:",
	"002" => "Prime(p):",
	"003" => "Prime(p):",
	"005" => "Modulus:",
	"157" => "Key:"
);
		  
#
# Data required for command line options.
#
my $zone;				# Name of the zone.
my $kskcur;				# Name of current KSK.
my $zskcur;				# Name of current ZSK.
my $zskpub;				# Name of published ZSK.
my $zonefile;				# Name of the zone file.
my $signedfile;				# Name of the signed zone file.
my $kskcount;				# Count of KSKs to generate.
my $kskdir;				# Directory where the KSK resides.
my $zskdir;				# Directory where the ZSKs reside.
my $endtime;				# Endtime of signature validity.
my $random;				# The source of randomness.
my $krfile;				# Name of the keyrec file to generate.
my $ksklife;				# Lifespan of the KSK.
my $zsklife;				# Lifespan of the ZSK.
my $algo;				# The encryption algorithm.
my $ksksize;				# The KSK size.
my $zsksize;				# The ZSK size.
my $zskcount;				# Count of ZSKs to generate.

my $verbose;				# Verbose-output flag.

#
# Command-line options specifically for this program.
#
my @opts = (
		"kskcur=s",			# Specify the current KSK.
		"zskcur=s",			# Specify the current ZSK.
		"zskpub=s",			# Specify the published ZSK.
		"kskdir=s",			# Specify the KSK directory.
		"zskdir=s",			# Specify the ZSK directory.
		"Version",			# Display the version number.
	   );

#
# Data from the dnssec-tools.conf file.
#
my $keygen;					# The key-generation program.

#
# Standard paths.
#
my $MKDIR = "/bin/mkdir";
my $MV	  = "/bin/mv";

#
# Lists of KSKs and ZSKs.
#
my @ksklist = ();		# List of current KSKs.
my @curlist = ();		# List of current ZSKs.
my @publist = ();		# List of published ZSKs.

#######################################################################

my $ret;					# Return code from main().

$ret = main();
exit($ret);

#-----------------------------------------------------------------------------
# Routine:	main()
#
# Purpose:	Uses global variables in this file.
#
sub main()
{
	my $argc = @ARGV;		# Number of command line arguments.
	my $errors = 0;			# Total error count.
	my $retval;			# Return value.

	my $signset;			# Signing-set name prefix.
	my $curkey;			# Path to current ZSK.
	my $pubkey;			# Path to published ZSK.

	erraction(ERR_EXIT);

	#
	# Parse the command line options.
	#
	optsandargs();

	#
	# Build the signing-set name prefix.
	#
	$signset = keyrec_signset_prefix($zone);
	$signset =~ s/\-$//;

	#
	# Generate the keyrec file.
	#
	$retval = keyrec_creat($krfile);
	keyrec_read($krfile);

	#
	# Add the zone keyrec.
	#
	keyrec_add('zone', $zone, {
				     'keyrec_type'	=> "zone",
				     'zonefile'		=> $zonefile,
				     'signedzone'	=> $signedfile,
				     'endtime'		=> $endtime,
				     'kskcur'		=> "$signset-00001",
				     'kskcount'		=> $kskcount,
				     'kskdirectory'	=> $kskdir,
				     'zskcount'		=> $zskcount,
				     'zskdirectory'	=> $zskdir,
				     'zskcur'		=> "$signset-00002",
				     'zskpub'		=> "$signset-00003",
				     'lastset'		=> "$signset-00003",
				     'keyrec_signdate'	=> "",
				     'keyrec_signsecs'	=> "",
				  });

	#
	# Add the KSK set keyrec.
	#
	keyrec_add('set', "$signset-00001",
				{
				   'zonename'		=> $zone,
				   'set_type'		=> 'kskcur',
				   'keys'		=> "",
				   'keyrec_setdate'	=> "",
				   'keyrec_setsecs'	=> "",
				});

	#
	# Add the ZSKCUR set keyrec.
	#
	keyrec_add('set', "$signset-00002",
				{
				   'zonename'		=> $zone,
				   'set_type'		=> 'zskcur',
				   'keys'		=> "",
				   'keyrec_setdate'	=> "",
				   'keyrec_setsecs'	=> "",
				});

	#
	# Add the ZSKPUB set keyrec.
	#
	keyrec_add('set', "$signset-00003",
				{
				   'zonename'		=> $zone,
				   'set_type'		=> 'zskpub',
				   'keys'		=> "",
				   'keyrec_setdate'	=> "",
				   'keyrec_setsecs'	=> "",
				});

	#
	# Build all our KSKs and add them to the keyrec file.
	#
	if($kskcur)
	{
		#
		# Create the key and save its name.
		#
		addksk($kskcur);
		push @ksklist, $kskcur;
	}
	else
	{
		for(my $ind=0; $ind < $kskcount ; $ind++)
		{
			my $ksk;				# Name of KSK.

			#
			# Generate our KSK.
			#
			$ksk = genksk($kskdir);
			if(!$ksk)
			{
				print STDERR "unable to generate KSK.\nPlease check the $DEF_TOOLSCONF file for correctness\n";
				exit(1);
			}

			#
			# Add this KSK's keyrec to the keyrec file.
			#
			addksk($ksk);

			#
			# Save the name of this key.
			#
			push @ksklist, $ksk;
		}
	}

	#
	# Build all our current ZSKs and add them to the keyrec file.
	#
	if($zskcur)
	{
		#
		# Create the key and save its name.
		#
		addzsk("zskcur",$zskcur);
		push @curlist, $zskcur;
	}
	else
	{
		for(my $ind=0; $ind < $zskcount ; $ind++)
		{
			#
			# Generate our ZSK.
			#
			$zskcur = genzsk($zskdir);
			if(!$zskcur)
			{
				print STDERR "unable to generate current ZSK.\nPlease check the $DEF_TOOLSCONF file for correctness\n";
				exit(1);
			}

			#
			# Add this ZSK's keyrec to the keyrec file.
			#
			addzsk("zskcur",$zskcur);

			#
			# Save the name of this key.
			#
			push @curlist, $zskcur;
		}

	}

	#
	# Build all our published ZSKs and add them to the keyrec file.
	#
	if($zskpub)
	{
		#
		# Create the key and save its name.
		#
		addzsk("zskpub",$zskpub);
		push @publist, $zskpub;
	}
	else
	{
		for(my $ind=0; $ind < $zskcount ; $ind++)
		{
			#
			# Generate our ZSK.
			#
			$zskpub = genzsk($zskdir);
			if(!$zskpub)
			{
				print STDERR "unable to generate published ZSK.\nPlease check the $DEF_TOOLSCONF file for correctness\n";
				exit(1);
			}

			#
			# Add this ZSK's keyrec to the keyrec file.
			#
			addzsk("zskpub",$zskpub);

			#
			# Save the name of this key.
			#
			push @publist, $zskpub;
		}

	}

	#
	# Add all the keys to their respective signing sets.
	#
	foreach my $key (@ksklist)
	{
		keyrec_signset_addkey("$signset-00001",$key);
	}
	foreach my $key (@curlist)
	{
		keyrec_signset_addkey("$signset-00002",$key);
	}
	foreach my $key (@publist)
	{
		keyrec_signset_addkey("$signset-00003",$key);
	}

	#
	# Write the keyrec file.
	#
	keyrec_write();
	keyrec_close();

	print "genkrf:  keyrec file $krfile created successfully\n" if($verbose);
	return(0);
}

#-----------------------------------------------------------------------------
# Routine:	optsandargs()
#
# Purpose:	Parse the command line for options and arguments.
#
sub optsandargs
{
	my $ropts;				# Reference to options hash.
	my %opts = ();				# Options hash.

	#
	# Slurp up the options.
	#
	opts_onerr(1);
	$ropts = opts_cmdopts(@opts);
	%opts = %$ropts 	if($ropts != undef);

	#
	# Get the option values.  If these weren't given on the command
	# line, they'll be taken from the config file or the defaults.
	#
	$kskcur	  = $opts{'kskcur'};
	$zskcur	  = $opts{'zskcur'};
	$zskpub	  = $opts{'zskpub'};

	$kskcount = $opts{'kskcount'}	|| dnssec_tools_default("kskcount");
	$kskdir	  = $opts{'kskdir'}	|| dnssec_tools_default("kskdir");
	$ksklife  = $opts{'ksklife'}	|| dnssec_tools_default("ksklife");
	$ksksize  = $opts{'ksklength'}	|| dnssec_tools_default("ksklength");
	$zskcount = $opts{'zskcount'}	|| dnssec_tools_default("zskcount");
	$zskdir	  = $opts{'zskdir'}	|| dnssec_tools_default("zskdir");
	$zsklife  = $opts{'zsklife'}	|| dnssec_tools_default("zsklife");
	$zsksize  = $opts{'zsklength'}	|| dnssec_tools_default("zsklength");

	$algo	  = $opts{'algorithm'}	|| dnssec_tools_default("algorithm");
	$endtime  = $opts{'endtime'}	|| dnssec_tools_default("enddate");
	$random	  = $opts{'random'}	|| dnssec_tools_default("random");

	$keygen	  = $opts{'keygen'}	|| dnssec_tools_default("bind-keygen");

	$verbose  = $opts{'verbose'};

	version() if(defined($opts{'Version'}));

	#
	# Give usage message in a few situations.
	#
	usage() if($#ARGV < 0);
	usage() if(defined($opts{'help'}));

	#
	# Get the zone file and signed filename.
	#
	$zonefile   = $ARGV[0];
	if($#ARGV > 0)
	{
		$signedfile = $ARGV[1];
	}
	else
	{
		$signedfile = $zonefile . ".signed";
	}

	#
	# Get the keyrec's zone and strip off a terminal ".".
	#
	$zone = $opts{'zone'} || $zonefile;
	$zone =~ s/^(.*)\.$/$1/;

	#
	# Set the output filename.
	#
	$krfile = $opts{'krfile'} || "$zone.krf";

	#
	# Default to the current directory if the KSK or ZSK directories
	# aren't given.
	#
	$kskdir = "." if(!$kskdir);
	$zskdir = "." if(!$zskdir);

	#
	# Ensure the KSK count is valid.
	#
	if($kskcount < 1)
	{
		print STDERR "invalid KSK count:  \"$kskcount\"\n";
		exit(10);
	}

	#
	# Ensure the ZSK count is valid.
	#
	if($zskcount < 1)
	{
		print STDERR "invalid ZSK count:  \"$zskcount\"\n";
		exit(10);
	}

	#
	# If the verbose flag was given, show all the values.
	#
	verbose() if($verbose);

}

#-----------------------------------------------------------------------------
# Routine:      getkeyalgo()
#
# Purpose:      This routine takes the identification string of the key
#               generated by dnssec-keygen as a parameter and returns the name
#               of the algorithm for that key.
#
#               The identification string of the key has the following format:
#
#			Knnnn.+aaa+iiiii
#
#               where:
#
#			nnnn is the key name
#			aaa  is the numeric representation of the algorithm
#			iiiii is the key identifier (or footprint)
#
sub getkeyalgo
{
	my $key = shift;
	my $algonum = $key;

	$algonum =~ s/^[^\+]*\+([^+]*)\+.*$/$1/g;
	return($algos{$algonum});
}

#-----------------------------------------------------------------------------
# Routine:      getkeysize()
#
# Purpose:      This routine takes the identification string of the key
#               and an optional key directory as parameters and returns
#               the size of the key.  If the directory is not specified
#               it defaults to the current directory.
#
sub getkeysize
{
	my $keytype = shift;			# Type of key to create.
	my $key	= shift;			# Name of key.
	my $keydir = shift;			# Key's directory.

	my $algofield;
	my $algonum;				# Algorithm number from key.
	my $keypath;
	my $keysize = 0;			# Key length.

	#
	# If the key's size field is set, we'll use it instead of
	# calculating things.
	#
	if($keytype eq "kskcur")
	{
		return($ksksize) if($ksksize > -1);
	}
	else
	{
		return($zsksize) if($zsksize > -1);
	}

	#
	# Get the path to the key.
	#
	$keydir = "." if(!$keydir);
	$keypath = $keydir . "/" . $key . ".private";

	#
	# Determine the algorithm field.
	#
	$algonum = $key;
	$algonum =~ s/^[^\+]*\+([^+]*)\+.*$/$1/g;
	$algofield = $algofields{$algonum};

	#
	# Open the key's file.
	#
	open(KF, "< $keypath") or return "";

	#
	# Get the algorithm line from the key file and calculate the
	# key's size.
	#
	while(<KF>)
	{
		my $line = $_;

		#
		# Skip any lines that don't hold the specified algorithm.
		#
		next if($line !~ /^$algofield/);

		#
		# Extract the value of the field.
		#
		$line =~ s/^$algofield(.*)$/$1/;
		$line =~ s/\s//g;

		#
		# The value is encoded in Base64, hence the following
		# algorithm for finding the keysize.
		#
		$keysize = length($line);
		$keysize = ($keysize / 4) * 3;

		#
		# Adjust the keysize a bit.
		#
		if($line =~ /==$/)
		{
			$keysize -= 2;
		}
		elsif($line =~ /=$/)
		{
			$keysize -= 1;
		}

		#
		# And one more minor tweak...
		#
		$keysize *= 8;
		last;
	}

	#
	# Close the key file and return the calculated key size.
	#
	close(KF);
	return($keysize);
}

#-----------------------------------------------------------------------------
# Routine:      genksk()
#
# Purpose:      Generate a new Key Signing Key (KSK.)
#
sub genksk
{
	my $cmdopts = "-r $random -a $algo -b $ksksize";
	my $ksk;

	#
	# Generate a new key.
	#
# print "genksk:  <$keygen $cmdopts -n zone -f KSK $zone>\n";
	$ksk = `$keygen $cmdopts -n zone -f KSK $zone`;
	chomp $ksk;

	#
	# Put the key files in their place.
	#
	if($kskdir ne ".")
	{
		`$MKDIR -p $kskdir && $MV $ksk* $kskdir`;
	}

	return($ksk || "");
}


#-----------------------------------------------------------------------------
# Routine:      genzsk()
#
# Purpose:      Generate a new Zone Signing Key (ZSK.)
#
sub genzsk
{
	my $cmdopts = "-r $random -a $algo -b $zsksize";
	my $zsk;

	#
	# Generate a new key.
	#
# print "genzsk:  <$keygen $cmdopts -n zone $zone>\n";
	$zsk = `$keygen $cmdopts -n zone $zone`;
	chomp $zsk;

	#
	# Put the key files in their place.
	#
	if($zskdir ne ".")
	{
		`$MKDIR -p $zskdir && $MV $zsk* $zskdir`;
	}

	return($zsk || "");
}

#----------------------------------------------------------------------
# Routine:	addksk()
#
# Purpose:	Add the KSK's keyrec to the keyrec file.
#
sub addksk
{
	my $keyname = shift;				# KSK's name.

	my $keypath;						# Path to KSK.
	my $alg = getkeyalgo($keyname);				# Key algorithm.
	my $len = getkeysize('kskcur',$keyname,$kskdir);	# Key length.

	#
	# Build the path to the KSK.
	#
	$keypath = "$kskdir/$keyname.key";

	#
	# Add the KSK keyrec.
	#
	keyrec_add('key', $keyname, {
				      'zonename'	=> $zone,
				      'keyrec_type'	=> "kskcur",
				      'algorithm'	=> $alg,
				      'random'		=> $random,
				      'ksklength'	=> $len,
				      'ksklife'		=> $ksklife,
				      'keypath'		=> "$keypath",
				      'keyrec_gendate'	=> "",
				      'keyrec_gensecs'	=> "",
				    });
};

#----------------------------------------------------------------------
# Routine:	addzsk()
#
# Purpose:	Add the ZSK's keyrec to the keyrec file.
#
sub addzsk
{
	my $keytype = shift;				# Type of ZSK.
	my $keyname = shift;				# ZSK's name.

	my $keypath;					# Path to ZSK.
	my $alg = getkeyalgo($keyname);			# Key algorithm.
	my $len = getkeysize('zsk',$keyname,$zskdir);	# Key length.

	#
	# Build the path to the ZSK.
	#
	$keypath = "$zskdir/$keyname.key";

	#
	# Add the ZSK keyrec.
	#
	keyrec_add('key', $keyname, {
				      'zonename'	=> $zone,
				      'keyrec_type'	=> "$keytype",
				      'algorithm'	=> $alg,
				      'random'		=> $random,
				      'zsklength'	=> $len,
				      'zsklife'		=> $zsklife,
				      'keypath'		=> "$keypath",
				      'keyrec_gendate'	=> "",
				      'keyrec_gensecs'	=> "",
				    });
};

#----------------------------------------------------------------------
# Routine:	version()
#
# Purpose:	Print the version number(s) and exit.
#
sub version
{
	print STDERR "$VERS\n";
	print STDERR "$DTVERS\n";

	exit(0);
}

#----------------------------------------------------------------------
# Routine:	verbose()
#
# Purpose:	Print the argument info.
#
sub verbose
{
	print "zonefile    - \"$zonefile\"\n";
	print "signedfile  - \"$signedfile\"\n";
	print "zone        - \"$zone\"\n";
	print "keyrec file - \"$krfile\"\n\n";

	print "algorithm   - \"$algo\"\n";
	print "endtime     - \"$endtime\"\n";
	print "random      - \"$random\"\n\n";

	print "kskcur      - \"$kskcur\"\n" if($kskcur ne "");
	print "kskcount    - \"$kskcount\"\n";
	print "kskdir      - \"$kskdir\"\n";
	print "ksksize     - \"$ksksize\"\n";
	print "ksklife     - \"$ksklife\"\n\n";

	print "zskcur      - \"$zskcur\"\n" if($zskcur ne "");
	print "zskpub      - \"$zskpub\"\n" if($zskpub ne "");
	print "zskcount    - \"$zskcount\"\n";
	print "zskdir      - \"$zskdir\"\n";
	print "zsksize     - \"$zsksize\"\n";
	print "zsklife     - \"$zsklife\"\n\n";
}

#-----------------------------------------------------------------------------
# Routine:	usage()
#
# Purpose:      This routine prints the usage and exits.
#
sub usage
{
	print STDERR "usage: genkrf [options] <zone-file> [signed-zone-file]\n";

	print STDERR "\n\t<zone-file>                     name of the zone file\n";
	print STDERR "\t[signed-zone-file]              name of the signed zone file\n";

	print STDERR "\n\toptions:\n";
	print STDERR "\t\t-zone ZONE              name of the zone\n";
	print STDERR "\t\t-krfile KEYREC          zone's keyrec file\n";
	print STDERR "\t\t-algorithm ALGORITHM    encryption algorithm\n";
	print STDERR "\t\t-endtime ENDTIME        end time of signature\n";
	print STDERR "\t\t-random RANDOMDEV       source of randomness\n\n";

	print STDERR "\t\t-kskcur KSK             name of the KSK\n";
	print STDERR "\t\t-kskcount COUNT         count of KSKs\n";
	print STDERR "\t\t-kskdir PATH            KSK directory\n";
	print STDERR "\t\t-ksklength KEYLEN       KSK length\n";
	print STDERR "\t\t-ksklife LIFESPAN       KSK lifespan\n\n";

	print STDERR "\t\t-zskcur ZSKCUR          name of the current ZSK\n";
	print STDERR "\t\t-zskpub ZSKPUB          name of the published ZSK\n";
	print STDERR "\t\t-zskcount COUNT         count of ZSKs\n";
	print STDERR "\t\t-zskdir PATH            ZSK directory\n";
	print STDERR "\t\t-zsklength KEYLEN       ZSK length\n";
	print STDERR "\t\t-zsklife LIFESPAN       ZSK lifespan\n\n";

	print STDERR "\t\t-verbose                verbose output\n";
	print STDERR "\t\t-Version                display version number\n";
	print STDERR "\t\t-help                   help message\n";

	exit(0);
}

1;

##############################################################################
#

=pod

=head1 NAME

genkrf - Generate a I<keyrec> file from Key Signing Key (KSK)
and/or Zone Signing Key (ZSK) files

=head1 SYNOPSIS

  genkrf [options] <zone-file> [<signed-zone-file>]

=head1 DESCRIPTION

B<genkrf> generates a I<keyrec> file from KSK and/or ZSK files.  It
generates new KSK and ZSK keys if needed.

The name of the I<keyrec> file to be generated is given by the B<-krfile>
option.  If this option is not specified, B<zone-name.krf> is used as the name
of the I<keyrec> file.  If the I<keyrec> file already exists, it will be
overwritten with new I<keyrec> definitions.

The I<zone-file> argument is required.  It specifies the name of the zone file
from which the signed zone file was created.  The optional I<signed-zone-file>
argument specifies the name of the signed zone file.  If it is not given, then
it defaults to B<zone-file.signed>.  The signed zone file field is, in effect,
a dummy field as the zone file is not actually signed.

=head1 OPTIONS

B<genkrf> has a number of options that assist in creation of the I<keyrec>
file.  These options will be set to the first value found from this search
path:

    command line options
    DNSSEC-Tools configuration file
    DNSSEC-Tools defaults

See I<tooloptions.pm(3)> for more details.
Exceptions to this are given in the option descriptions.

The B<genkrf> options are described below.

=head2 General B<genkrf> Options

=over 4

=item B<-zone zone-name>

This option specifies the name of the zone.  If it is not given then
I<zone-file> will be used as the name of the zone.

=item B<-krfile keyrec-file>

This option specifies the name of the I<keyrec> file to be generated.
If it is not given, then B<zone-name.krf> will be used.

=item B<-algorithm algorithm>

This option specifies the algorithm used to generate encryption keys.

=item B<-endtime endtime>

This option specifies the time that the signature on the zone expires,
measured in seconds.

=item B<-random random-device>

Source of randomness used to generate the zone's keys. See the man
page for B<dnssec-signzone> for the valid format of this field.

=item B<-verbose>

Display additional messages during processing.  If this option is given at
least once, then a message will be displayed indicating the successful
generation of the I<keyrec> file.  If it is given twice, then the values of
all options will also be displayed.

=item B<-Version>

Displays the version information for B<genkrf> and the DNSSEC-Tools package.

=item B<-help>

Display a usage message.

=back

=head2 KSK-related Options

=over 4

=item B<-kskcur KSK-name>

This option specifies the Current KSK's key file being used to sign the zone.
If this option is not given, a new KSK will be created.

=item B<-kskcount KSK-count>

This option specifies the number of KSK keys that will be generated.  If this
option is not given, the default given in the DNSSEC-Tools configuration file
will be used.

=item B<-kskdir KSK-directory>

This option specifies the absolute or relative path of the directory
where the KSK resides.  If this option is not given, it defaults to
the current directory ".".

=item B<-ksklength KSK-length>

This option specifies the length of the KSK encryption key.

=item B<-ksklife KSK-lifespan>

This option specifies the lifespan of the KSK encryption key.  This lifespan
is B<not> inherent to the key itself.  It is B<only> used to determine when
the KSK must be rolled over.

=back

=head2 ZSK-related Options

=over 4

=item B<-zskcur ZSK-name>

This option specifies the current ZSK being used to sign the zone.
If this option is not given, a new ZSK will be created.

=item B<-zskpub ZSK-name>

This option specifies the published ZSK for the zone.  If this option
is not given, a new ZSK will be created.

=item B<-zskcount ZSK-count>

This option specifies the number of current and published ZSK keys that will
be generated.  If this option is not given, the default given in the
DNSSEC-Tools configuration file will be used.

=item B<-zskdir ZSK-directory>

This option specifies the absolute or relative path of the directory
where the ZSKs reside.  If this option is not given, it defaults to
the current directory ".".

=item B<-zsklength ZSK-length>

This option specifies the length of the ZSK encryption key.

=item B<-zsklife ZSK-lifespan>

This option specifies the lifespan of the ZSK encryption key.  This lifespan
is B<not> inherent to the key itself.  It is B<only> used to determine when
the ZSK must be rolled over.

=back

=head1 COPYRIGHT

Copyright 2005-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<dnssec-keygen(8)>,
B<dnssec-signzone(8)>,
B<zonesigner(8)>

B<Net::DNS::SEC::Tools::conf.pm(3)>,
B<Net::DNS::SEC::Tools::defaults.pm(3)>,
B<Net::DNS::SEC::Tools::keyrec.pm(3)>

B<conf(5)>,
B<keyrec(5)>

=cut