2022-09-21 18:24:42 +00:00
|
|
|
// Copyright (C) 2001-2003, 2011, 2022 VeriSign, Inc.
|
2006-05-03 16:34:32 +00:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA
|
|
|
|
|
|
|
|
package com.verisignlabs.dnssec.cl;
|
|
|
|
|
|
|
|
import java.io.FileWriter;
|
2024-04-08 01:12:56 +00:00
|
|
|
import java.io.IOException;
|
2006-05-03 16:34:32 +00:00
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
2022-09-21 18:24:42 +00:00
|
|
|
import org.apache.commons.cli.Option;
|
|
|
|
import org.xbill.DNS.CDSRecord;
|
2006-05-03 16:34:32 +00:00
|
|
|
import org.xbill.DNS.DLVRecord;
|
|
|
|
import org.xbill.DNS.DNSKEYRecord;
|
2022-09-21 18:24:42 +00:00
|
|
|
import org.xbill.DNS.DNSSEC;
|
2006-05-03 16:34:32 +00:00
|
|
|
import org.xbill.DNS.DSRecord;
|
|
|
|
import org.xbill.DNS.Record;
|
|
|
|
|
2022-09-21 18:24:42 +00:00
|
|
|
import com.verisignlabs.dnssec.security.BINDKeyUtils;
|
|
|
|
import com.verisignlabs.dnssec.security.DnsKeyPair;
|
|
|
|
import com.verisignlabs.dnssec.security.SignUtils;
|
2006-05-03 16:34:32 +00:00
|
|
|
|
|
|
|
/**
|
2009-02-02 05:01:03 +00:00
|
|
|
* This class forms the command line implementation of a DNSSEC DS/DLV generator
|
2006-05-03 16:34:32 +00:00
|
|
|
*
|
2011-02-12 21:25:26 +00:00
|
|
|
* @author David Blacka
|
2006-05-03 16:34:32 +00:00
|
|
|
*/
|
2022-09-21 18:24:42 +00:00
|
|
|
public class DSTool extends CLBase {
|
2024-04-08 01:12:56 +00:00
|
|
|
private dsType createType = dsType.DS;
|
|
|
|
private String outputfile = null;
|
|
|
|
private String[] keynames = null;
|
|
|
|
private int digestId = DNSSEC.Digest.SHA256;
|
|
|
|
private long dsTTL = -1;
|
|
|
|
|
|
|
|
public DSTool(String name, String usageStr) {
|
|
|
|
super(name, usageStr);
|
|
|
|
}
|
2006-05-03 16:34:32 +00:00
|
|
|
|
2022-09-21 18:24:42 +00:00
|
|
|
/** There are several records that are based on DS. */
|
|
|
|
protected enum dsType {
|
|
|
|
DS, CDS, DLV;
|
|
|
|
}
|
|
|
|
|
2006-05-03 16:34:32 +00:00
|
|
|
/**
|
|
|
|
* This is a small inner class used to hold all of the command line option
|
|
|
|
* state.
|
|
|
|
*/
|
2022-09-21 18:24:42 +00:00
|
|
|
|
|
|
|
|
2024-04-08 01:12:56 +00:00
|
|
|
/**
|
|
|
|
* Set up the command line options.
|
|
|
|
*
|
|
|
|
* @return a set of command line options.
|
|
|
|
*/
|
|
|
|
protected void setupOptions() {
|
|
|
|
opts.addOption(Option.builder("D").longOpt("dlv").desc("Generate a DLV record instead.").build());
|
|
|
|
opts.addOption(Option.builder("C").longOpt("cds").desc("Generate a CDS record instead").build());
|
|
|
|
opts.addOption(
|
|
|
|
Option.builder("d").hasArg().argName("id").longOpt("digest").desc("The digest algorithm to use").build());
|
|
|
|
opts.addOption(Option.builder("f").hasArg().argName("file").longOpt("output").desc("output to file").build());
|
|
|
|
opts.addOption(Option.builder("T").longOpt("ttl").hasArg().desc("TTL to use for generated DS/CDS record").build());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void processOptions() {
|
|
|
|
String[] digestAlgOptionKeys = { "digest_algorithm", "digest_id" };
|
|
|
|
String[] dsTTLOptionKeys = { "ds_ttl", "ttl" };
|
2006-05-03 16:34:32 +00:00
|
|
|
|
2024-04-08 01:12:56 +00:00
|
|
|
outputfile = cli.getOptionValue('f');
|
|
|
|
if (cli.hasOption("dlv")) {
|
|
|
|
createType = dsType.DLV;
|
|
|
|
} else if (cli.hasOption("cds")) {
|
|
|
|
createType = dsType.CDS;
|
2006-05-24 22:19:31 +00:00
|
|
|
}
|
2024-04-08 01:12:56 +00:00
|
|
|
String digestValue = cliOption("d", digestAlgOptionKeys, Integer.toString(digestId));
|
|
|
|
digestId = DNSSEC.Digest.value(digestValue);
|
2006-05-24 22:19:31 +00:00
|
|
|
|
2024-04-08 01:12:56 +00:00
|
|
|
dsTTL = cliLongOption("ttl", dsTTLOptionKeys, dsTTL);
|
2006-05-24 22:19:31 +00:00
|
|
|
|
2024-04-08 01:12:56 +00:00
|
|
|
String[] args = cli.getArgs();
|
2006-05-03 16:34:32 +00:00
|
|
|
|
2024-04-08 01:12:56 +00:00
|
|
|
if (args.length < 1) {
|
|
|
|
fail("missing key file");
|
2006-05-03 16:34:32 +00:00
|
|
|
}
|
|
|
|
|
2024-04-08 01:12:56 +00:00
|
|
|
keynames = args;
|
2006-05-03 16:34:32 +00:00
|
|
|
}
|
|
|
|
|
2024-04-08 01:12:56 +00:00
|
|
|
public void createDS(String keyname) throws IOException {
|
|
|
|
DnsKeyPair key = BINDKeyUtils.loadKey(keyname, null);
|
2006-05-03 16:34:32 +00:00
|
|
|
DNSKEYRecord dnskey = key.getDNSKEYRecord();
|
2006-05-24 22:19:31 +00:00
|
|
|
|
2022-09-21 18:24:42 +00:00
|
|
|
if ((dnskey.getFlags() & DNSKEYRecord.Flags.SEP_KEY) == 0) {
|
2024-04-08 01:12:56 +00:00
|
|
|
log.warning("DNSKEY " + keyname + " is not an SEP-flagged key.");
|
2006-05-03 16:34:32 +00:00
|
|
|
}
|
2006-05-24 22:19:31 +00:00
|
|
|
|
2024-04-08 01:12:56 +00:00
|
|
|
long ttl = dsTTL < 0 ? dnskey.getTTL() : dsTTL;
|
|
|
|
DSRecord ds = SignUtils.calculateDSRecord(dnskey, digestId, ttl);
|
|
|
|
Record res;
|
|
|
|
|
|
|
|
switch (createType) {
|
|
|
|
case DLV:
|
|
|
|
log.fine("creating DLV.");
|
|
|
|
DLVRecord dlv = new DLVRecord(ds.getName(), ds.getDClass(), ds.getTTL(), ds.getFootprint(), ds.getAlgorithm(),
|
|
|
|
ds.getDigestID(), ds.getDigest());
|
|
|
|
res = dlv;
|
|
|
|
break;
|
|
|
|
case CDS:
|
|
|
|
log.fine("creating CDS.");
|
|
|
|
CDSRecord cds = new CDSRecord(ds.getName(), ds.getDClass(), ds.getTTL(), ds.getFootprint(), ds.getAlgorithm(),
|
|
|
|
ds.getDClass(), ds.getDigest());
|
|
|
|
res = cds;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = ds;
|
|
|
|
break;
|
2006-05-03 16:34:32 +00:00
|
|
|
}
|
2024-03-31 02:21:32 +00:00
|
|
|
|
2024-04-08 01:12:56 +00:00
|
|
|
if (outputfile != null && !outputfile.equals("-")) {
|
|
|
|
try (PrintWriter out = new PrintWriter(new FileWriter(outputfile))) {
|
2022-09-21 18:24:42 +00:00
|
|
|
out.println(res);
|
|
|
|
}
|
|
|
|
} else {
|
2006-05-03 16:34:32 +00:00
|
|
|
System.out.println(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-08 01:12:56 +00:00
|
|
|
public void execute() throws Exception {
|
|
|
|
for (String keyname : keynames){
|
|
|
|
createDS(keyname);
|
|
|
|
}
|
|
|
|
}
|
2006-05-03 16:34:32 +00:00
|
|
|
|
2024-04-08 01:12:56 +00:00
|
|
|
public static void main(String[] args) {
|
|
|
|
DSTool tool = new DSTool("dstool", "jdnssec-dstool [..options..] keyfile [keyfile..]");
|
|
|
|
|
|
|
|
tool.run(args);
|
2006-05-03 16:34:32 +00:00
|
|
|
}
|
|
|
|
}
|