1 package com.verisign.cl;
5 import org.xbill.DNS.*;
7 import com.verisign.tat.dnssec.CaptiveValidator;
9 public class DNSSECReconciler {
12 * Invoke with java -jar dnssecreconciler.jar server=127.0.0.1 \
13 * query_file=queries.txt dnskey_query=net dnskey_query=edu
15 private CaptiveValidator validator;
20 public String queryFile;
21 public String dnskeyFile;
22 public List<String> dnskeyNames;
25 validator = new CaptiveValidator();
29 * Convert a query line of the form: <qname> <qtype> <flags> to a request
33 * @return A query message
34 * @throws TextParseException
35 * @throws NameTooLongException
37 private Message queryFromString(String query_line)
38 throws TextParseException, NameTooLongException {
40 String[] tokens = query_line.split("[ \t]+");
46 if (tokens.length < 1)
48 qname = Name.fromString(tokens[0]);
49 if (!qname.isAbsolute()) {
50 qname = Name.concatenate(qname, Name.root);
53 for (int i = 1; i < tokens.length; i++) {
54 if (tokens[i].startsWith("+")) {
55 // For now, we ignore flags as uninteresting
59 int type = Type.value(tokens[i]);
64 int cls = DClass.value(tokens[i]);
77 Message query = Message.newQuery(Record.newRecord(qname, qtype, qclass));
82 public void execute() {
85 private static void usage() {
86 System.err.println("usage: java -jar dnssecreconiler.jar [..options..]");
87 System.err.println(" server: the DNS server to query.");
88 System.err.println(" query: a name [type [flags]] string.");
89 System.err.println(" query_file: a list of queries, one query per line.");
90 System.err.println(" dnskey_file: a file containing DNSKEY RRs to trust.");
91 System.err.println(" dnskey_query: query 'server' for DNSKEY at given name to trust, may repeat");
94 public static int main(String[] argv) {
96 DNSSECReconciler dr = new DNSSECReconciler();
99 // Parse the command line options
100 for (String arg : argv) {
102 if (arg.indexOf('=') < 0) {
103 System.err.println("Unrecognized option: " + arg);
108 String[] split_arg = arg.split("[ \t]*=[ \t]*", 2);
109 String opt = split_arg[0];
110 String optarg = split_arg[1];
112 if (opt.equals("server")) {
114 } else if (opt.equals("query_file")) {
115 dr.queryFile = optarg;
116 } else if (opt.equals("dnskey_file")) {
117 dr.dnskeyFile = optarg;
118 } else if (opt.equals("dnskey_query")) {
119 if (dr.dnskeyNames == null) {
120 dr.dnskeyNames = new ArrayList<String>();
122 dr.dnskeyNames.add(optarg);
124 System.err.println("Unrecognized option: " + opt);
130 // Check for minimum usage
131 if (dr.server == null) {
132 System.err.println("'server' must be specified");
136 if (dr.query == null && dr.queryFile == null) {
137 System.err.println("Either 'query' or 'query_file' must be specified");
141 if (dr.dnskeyFile == null && dr.dnskeyNames == null) {
142 System.err.println("Either 'dnskey_file' or 'dnskey_query' must be specified");
150 } catch (Exception e) {