From 55a139db82ef9df9541f60c44076224143261ab9 Mon Sep 17 00:00:00 2001 From: David Blacka Date: Sun, 15 Jul 2018 14:57:41 +0000 Subject: [PATCH] Allow for epoch start/expire times; add verboseSigning to jdnssec-signrrset --- src/com/verisignlabs/dnssec/cl/CLBase.java | 28 +++++++++++++++---- src/com/verisignlabs/dnssec/cl/SignRRset.java | 13 +++++---- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/com/verisignlabs/dnssec/cl/CLBase.java b/src/com/verisignlabs/dnssec/cl/CLBase.java index e8b3ed4..d541bc4 100644 --- a/src/com/verisignlabs/dnssec/cl/CLBase.java +++ b/src/com/verisignlabs/dnssec/cl/CLBase.java @@ -65,7 +65,7 @@ public abstract class CLBase /** * The base constructor. This will setup the command line options. - * + * * @param usage * The command line usage string (e.g., * "jdnssec-foo [..options..] zonefile") @@ -106,7 +106,7 @@ public abstract class CLBase /** * This is an overridable method for subclasses to add their own command * line options. - * + * * @param opts * the options object to add (via OptionBuilder, typically) new * options to. @@ -121,7 +121,7 @@ public abstract class CLBase * Subclasses generally override processOptions() rather than this method. * This method create the parsing objects and processes the standard * options. - * + * * @param args * The command line arguments. * @throws ParseException @@ -188,7 +188,7 @@ public abstract class CLBase /** * Process additional tool-specific options. Subclasses generally override * this. - * + * * @param cli * The {@link CommandLine} object containing the parsed command * line state. @@ -247,9 +247,22 @@ public abstract class CLBase } } + public static long parseLong(String s, long def) + { + try + { + long v = Long.parseLong(s); + return v; + } + catch (NumberFormatException e) + { + return def; + } + } + /** * Calculate a date/time from a command line time/offset duration string. - * + * * @param start * the start time to calculate offsets from. * @param duration @@ -272,6 +285,11 @@ public abstract class CLBase long offset = (long) parseInt(duration.substring(1), 0) * 1000; return new Date(start.getTime() + offset); } + if (duration.length() <= 10) + { + long epoch = parseLong(duration, 0) * 1000; + return new Date(epoch); + } SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMddHHmmss"); dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); diff --git a/src/com/verisignlabs/dnssec/cl/SignRRset.java b/src/com/verisignlabs/dnssec/cl/SignRRset.java index b92898e..23d4938 100644 --- a/src/com/verisignlabs/dnssec/cl/SignRRset.java +++ b/src/com/verisignlabs/dnssec/cl/SignRRset.java @@ -42,7 +42,7 @@ import com.verisignlabs.dnssec.security.*; * RRset. Note that it will sign any RRset with any private key without * consideration of whether or not the RRset *should* be signed in the context * of a zone. - * + * * @author David Blacka */ public class SignRRset extends CLBase @@ -61,6 +61,7 @@ public class SignRRset extends CLBase public String inputfile = null; public String outputfile = null; public boolean verifySigs = false; + public boolean verboseSigning = false; public CLIState() { @@ -74,6 +75,7 @@ public class SignRRset extends CLBase { // boolean options opts.addOption("a", "verify", false, "verify generated signatures>"); + opts.addOption("V", "verbose-signing", false, "Display verbose signing activity."); OptionBuilder.hasArg(); OptionBuilder.withArgName("dir"); @@ -104,6 +106,7 @@ public class SignRRset extends CLBase String optstr = null; if (cli.hasOption('a')) verifySigs = true; + if (cli.hasOption('V')) verboseSigning = true; if ((optstr = cli.getOptionValue('D')) != null) { @@ -155,7 +158,7 @@ public class SignRRset extends CLBase /** * Verify the generated signatures. - * + * * @param zonename * the origin name of the zone. * @param records @@ -198,7 +201,7 @@ public class SignRRset extends CLBase /** * Load the key pairs from the key files. - * + * * @param keyfiles * a string array containing the base names or paths of the keys * to be loaded. @@ -310,7 +313,7 @@ public class SignRRset extends CLBase state.outputfile = state.inputfile + ".signed"; } - JCEDnsSecSigner signer = new JCEDnsSecSigner(); + JCEDnsSecSigner signer = new JCEDnsSecSigner(state.verboseSigning); List sigs = signer.signRRset(rrset, keypairs, state.start, state.expire); for (RRSIGRecord s : sigs) @@ -355,7 +358,7 @@ public class SignRRset extends CLBase { SignRRset tool = new SignRRset(); tool.state = new CLIState(); - + tool.run(tool.state, args); } }