2b35d69985bda30fa0a9a14860d107be18e20dee
[captive-validator.git] / src / com / verisign / cl / DNSSECReconciler.java
1 package com.verisign.cl;
2
3 import java.util.*;
4
5 import org.xbill.DNS.*;
6 import com.verisign.tat.dnssec.CaptiveValidator;
7
8 public class DNSSECReconciler {
9
10     /**
11      * Invoke with java -jar dnssecreconciler.jar server=127.0.0.1 \
12      * query_file=queries.txt dnskey_query=net dnskey_query=edu
13      */
14     private CaptiveValidator validator;
15
16     // Options
17     public String            server;
18     public String            query;
19     public String            queryFile;
20     public String            dnskeyFile;
21     public List<String>      dnskeyNames;
22
23     DNSSECReconciler() {
24         validator = new CaptiveValidator();
25     }
26
27     public void execute() {
28
29     }
30
31     private static void usage() {
32         System.err.println("usage: java -jar dnssecreconiler.jar [..options..]");
33         System.err.println("       server: the DNS server to query.");
34         System.err.println("       query: a name [type [flags]] string.");
35         System.err.println("       query_file: a list of queries, one query per line.");
36         System.err.println("       dnskey_file: a file containing DNSKEY RRs to trust.");
37         System.err.println("       dnskey_query: query 'server' for DNSKEY at given name to trust, may repeat");
38     }
39
40     public static int main(String[] argv) {
41
42         DNSSECReconciler dr = new DNSSECReconciler();
43
44         try {
45             // Parse the command line options
46             for (String arg : argv) {
47
48                 if (arg.indexOf('=') < 0) {
49                     System.err.println("Unrecognized option: " + arg);
50                     usage();
51                     return 1;
52                 }
53                 
54                 String[] split_arg = arg.split("[ \t]*=[ \t]*", 2);
55                 String opt = split_arg[0];
56                 String optarg = split_arg[1];
57
58                 if (opt.equals("server")) {
59                     dr.server = optarg;
60                 } else if (opt.equals("query_file")) {
61                     dr.queryFile = optarg;
62                 } else if (opt.equals("dnskey_file")) {
63                     dr.dnskeyFile = optarg;
64                 } else if (opt.equals("dnskey_query")) {
65                     if (dr.dnskeyNames == null) {
66                         dr.dnskeyNames = new ArrayList<String>();
67                     }
68                     dr.dnskeyNames.add(optarg);
69                 } else {
70                     System.err.println("Unrecognized option: " + opt);
71                     usage();
72                     return 1;
73                 }
74             }
75
76             // Check for minimum usage
77             if (dr.server == null) {
78                 System.err.println("'server' must be specified");
79                 usage();
80                 return 1;
81             }
82             if (dr.query == null && dr.queryFile == null) {
83                 System.err.println("Either 'query' or 'query_file' must be specified");
84                 usage();
85                 return 1;
86             }
87             if (dr.dnskeyFile == null && dr.dnskeyNames == null) {
88                 System.err.println("Either 'dnskey_file' or 'dnskey_query' must be specified");
89                 usage();
90                 return 1;
91             }
92             
93             
94             // Execute the job
95             dr.execute();
96
97         } catch (Exception e) {
98             e.printStackTrace();
99             return 1;
100         }
101
102         return 0;
103     }
104 }