address merge conflicts
[captive-validator.git] / src / com / verisign / tat / dnssec / CaptiveValidator.java
index 4ada2aa..07311ce 100644 (file)
@@ -49,10 +49,13 @@ public class CaptiveValidator {
     private DnsSecVerifier mVerifier;
     private Logger log = Logger.getLogger(this.getClass());
 
+    private List<String>   mErrorList;
+
     public CaptiveValidator() {
-        mVerifier = new DnsSecVerifier();
-        mValUtils = new ValUtils(mVerifier);
-        mTrustedKeys = new TrustAnchorStore();
+        mVerifier        = new DnsSecVerifier();
+        mValUtils        = new ValUtils(mVerifier);
+        mTrustedKeys     = new TrustAnchorStore();
+        mErrorList       = new ArrayList<String>();
     }
 
     // ---------------- Module Initialization -------------------
@@ -205,7 +208,7 @@ public class CaptiveValidator {
             // Follow the CNAME chain.
             if (type == Type.CNAME) {
                 if (rrset.size() > 1) {
-                    log.debug("Found CNAME rrset with size > 1: " + rrset);
+                    mErrorList.add("Found CNAME rrset with size > 1: " + rrset);
                     m.setStatus(SecurityStatus.INVALID);
 
                     return m;
@@ -363,8 +366,8 @@ public class CaptiveValidator {
             // If the (answer) rrset failed to validate, then this message is
             // BAD.
             if (status != SecurityStatus.SECURE) {
-                log.debug("Positive response has failed ANSWER rrset: "
-                        + rrsets[i]);
+                mErrorList.add("Positive response has failed ANSWER rrset: " +
+                         rrsets[i]);
                 m.setStatus(SecurityStatus.BOGUS);
 
                 return;
@@ -389,11 +392,10 @@ public class CaptiveValidator {
             int status = mValUtils.verifySRRset(rrsets[i], key_rrset);
 
             // If anything in the authority section fails to be secure, we have
-            // a
-            // bad message.
+            // a bad message.
             if (status != SecurityStatus.SECURE) {
-                log.debug("Positive response has failed AUTHORITY rrset: "
-                        + rrsets[i]);
+                mErrorList.add("Positive response has failed AUTHORITY rrset: " +
+                         rrsets[i]);
                 m.setStatus(SecurityStatus.BOGUS);
 
                 return;
@@ -410,8 +412,7 @@ public class CaptiveValidator {
                     Name nsec_wc = ValUtils.nsecWildcard(qname, nsec);
 
                     if (!wc.equals(nsec_wc)) {
-                        // log.debug("Positive wildcard response wasn't generated "
-                        // + "by the correct wildcard");
+                        mErrorList.add("Positive wildcard response wasn't generated by the correct wildcard");
                         m.setStatus(SecurityStatus.BOGUS);
 
                         return;
@@ -437,7 +438,7 @@ public class CaptiveValidator {
         // records.
         if ((wc != null) && !wcNSEC_ok && (nsec3s != null)) {
             if (NSEC3ValUtils.proveWildcard(nsec3s, qname, key_rrset.getName(),
-                    wc)) {
+                        wc, mErrorList)) {
                 wcNSEC_ok = true;
             }
         }
@@ -489,8 +490,8 @@ public class CaptiveValidator {
                 // have
                 // a bad message.
                 if (status != SecurityStatus.SECURE) {
-                    log.debug("Positive response has failed AUTHORITY rrset: "
-                            + rrsets[i]);
+                    mErrorList.add("Positive response has failed AUTHORITY rrset: " +
+                             rrsets[i]);
                     m.setStatus(SecurityStatus.BOGUS);
 
                     return;
@@ -538,6 +539,7 @@ public class CaptiveValidator {
         // Now to check to see if we have a valid combination of things.
         if (delegation == null) {
             // somehow we have a referral without an NS rrset.
+            mErrorList.add("Apparent referral does not contain NS RRset");
             m.setStatus(SecurityStatus.BOGUS);
 
             return;
@@ -546,6 +548,7 @@ public class CaptiveValidator {
         if (secure_delegation) {
             if ((nsec != null) || ((nsec3s != null) && (nsec3s.size() > 0))) {
                 // we found both a DS rrset *and* NSEC/NSEC3 rrsets!
+                mErrorList.add("Referral contains both DS and NSEC/NSEC3 RRsets");
                 m.setStatus(SecurityStatus.BOGUS);
 
                 return;
@@ -564,6 +567,7 @@ public class CaptiveValidator {
             if (status != SecurityStatus.SECURE) {
                 // The NSEC *must* prove that there was no DS record. The
                 // INSECURE state here is still bogus.
+                mErrorList.add("Referral does not contain a NSEC record proving no DS");
                 m.setStatus(SecurityStatus.BOGUS);
 
                 return;
@@ -575,12 +579,12 @@ public class CaptiveValidator {
         }
 
         if (nsec3s.size() > 0) {
-            byte status = NSEC3ValUtils
-                    .proveNoDS(nsec3s, delegation, nsec3zone);
+            byte status = NSEC3ValUtils.proveNoDS(nsec3s, delegation, nsec3zone, mErrorList);
 
             if (status != SecurityStatus.SECURE) {
                 // the NSEC3 RRs MUST prove no DS, so the INDETERMINATE state is
                 // actually bogus
+                mErrorList.add("Referral does not contain NSEC3 record(s) proving no DS");
                 m.setStatus(SecurityStatus.BOGUS);
 
                 return;
@@ -592,11 +596,12 @@ public class CaptiveValidator {
         }
 
         // failed to find proof either way.
+        mErrorList.add("Referral does not contain proof of no DS");
         m.setStatus(SecurityStatus.BOGUS);
     }
 
-    private void validateCNAMEResponse(SMessage message, SRRset key_rrset) {
-    }
+    // FIXME: write CNAME validation code.
+    private void validateCNAMEResponse(SMessage message, SRRset key_rrset) {}
 
     /**
      * Given an "ANY" response -- a response that contains an answer to a
@@ -640,8 +645,8 @@ public class CaptiveValidator {
             // If the (answer) rrset failed to validate, then this message is
             // BAD.
             if (status != SecurityStatus.SECURE) {
-                log.debug("Positive response has failed ANSWER rrset: "
-                        + rrsets[i]);
+                mErrorList.add("Positive response has failed ANSWER rrset: " +
+                         rrsets[i]);
                 m.setStatus(SecurityStatus.BOGUS);
 
                 return;
@@ -656,11 +661,10 @@ public class CaptiveValidator {
             int status = mValUtils.verifySRRset(rrsets[i], key_rrset);
 
             // If anything in the authority section fails to be secure, we have
-            // a
-            // bad message.
+            // a bad message.
             if (status != SecurityStatus.SECURE) {
-                log.debug("Positive response has failed AUTHORITY rrset: "
-                        + rrsets[i]);
+                mErrorList.add("Positive response has failed AUTHORITY rrset: " +
+                         rrsets[i]);
                 m.setStatus(SecurityStatus.BOGUS);
 
                 return;
@@ -689,9 +693,9 @@ public class CaptiveValidator {
      * @param key_rrset
      *            The trusted DNSKEY rrset that signs this response.
      */
-    private void validateNodataResponse(SMessage message, SRRset key_rrset) {
-        Name qname = message.getQName();
-        int qtype = message.getQType();
+    private void validateNodataResponse(SMessage message, SRRset key_rrset, List<String> errorList) {
+        Name     qname = message.getQName();
+        int      qtype = message.getQType();
 
         SMessage m = message;
 
@@ -722,8 +726,8 @@ public class CaptiveValidator {
             int status = mValUtils.verifySRRset(rrsets[i], key_rrset);
 
             if (status != SecurityStatus.SECURE) {
-                log.debug("NODATA response has failed AUTHORITY rrset: "
-                        + rrsets[i]);
+                mErrorList.add("NODATA response has failed AUTHORITY rrset: " +
+                         rrsets[i]);
                 m.setStatus(SecurityStatus.BOGUS);
 
                 return;
@@ -779,13 +783,14 @@ public class CaptiveValidator {
         if (!hasValidNSEC && (nsec3s != null) && (nsec3s.size() > 0)) {
             // try to prove NODATA with our NSEC3 record(s)
             hasValidNSEC = NSEC3ValUtils.proveNodata(nsec3s, qname, qtype,
-                    nsec3Signer);
+                    nsec3Signer, errorList);
         }
 
         if (!hasValidNSEC) {
             log.debug("NODATA response failed to prove NODATA "
                     + "status with NSEC/NSEC3");
             log.trace("Failed NODATA:\n" + m);
+            mErrorList.add("NODATA response failed to prove NODATA status with NSEC/NSEC3");
             m.setStatus(SecurityStatus.BOGUS);
 
             return;
@@ -818,8 +823,9 @@ public class CaptiveValidator {
         SMessage m = message;
 
         if (message.getCount(Section.ANSWER) > 0) {
-            log
-                    .warn("NAME ERROR response contained records in the ANSWER SECTION");
+            log.warn(
+                "NameError response contained records in the ANSWER SECTION");
+            mErrorList.add("NameError response contained records in the ANSWER SECTION");
             message.setStatus(SecurityStatus.INVALID);
 
             return;
@@ -838,8 +844,8 @@ public class CaptiveValidator {
             int status = mValUtils.verifySRRset(rrsets[i], key_rrset);
 
             if (status != SecurityStatus.SECURE) {
-                log.debug("NameError response has failed AUTHORITY rrset: "
-                        + rrsets[i]);
+                mErrorList.add("NameError response has failed AUTHORITY rrset: " +
+                         rrsets[i]);
                 m.setStatus(SecurityStatus.BOGUS);
 
                 return;
@@ -882,8 +888,8 @@ public class CaptiveValidator {
                 return;
             }
 
-            hasValidNSEC = NSEC3ValUtils.proveNameError(nsec3s, qname,
-                    nsec3Signer);
+            hasValidNSEC       = NSEC3ValUtils.proveNameError(nsec3s, qname,
+                    nsec3Signer, mErrorList);
 
             // Note that we assume that the NSEC3ValUtils proofs encompass the
             // wildcard part of the proof.
@@ -892,16 +898,14 @@ public class CaptiveValidator {
 
         // If the message fails to prove either condition, it is bogus.
         if (!hasValidNSEC) {
-            log.debug("NameError response has failed to prove: "
-                    + "qname does not exist");
+            mErrorList.add("NameError response has failed to prove qname does not exist");
             m.setStatus(SecurityStatus.BOGUS);
 
             return;
         }
 
         if (!hasValidWCNSEC) {
-            log.debug("NameError response has failed to prove: "
-                    + "covering wildcard does not exist");
+            mErrorList.add("NameError response has failed to prove covering wildcard does not exist");
             m.setStatus(SecurityStatus.BOGUS);
 
             return;
@@ -913,6 +917,7 @@ public class CaptiveValidator {
     }
 
     public byte validateMessage(SMessage message, Name zone) {
+        mErrorList.clear();
         if (!zone.isAbsolute()) {
             try {
                 zone = Name.concatenate(zone, Name.root);
@@ -934,6 +939,7 @@ public class CaptiveValidator {
         SRRset key_rrset = findKeys(message);
 
         if (key_rrset == null) {
+            mErrorList.add("Failed to find matching DNSKEYs for the response");
             return SecurityStatus.BOGUS;
         }
 
@@ -952,9 +958,9 @@ public class CaptiveValidator {
 
             break;
 
-        case NODATA:
-            log.trace("Validating a NODATA response");
-            validateNodataResponse(message, key_rrset);
+            case NODATA:
+                log.trace("Validating a NODATA response");
+                validateNodataResponse(message, key_rrset, mErrorList);
 
             break;
 
@@ -994,4 +1000,8 @@ public class CaptiveValidator {
     public List<String> listTrustedKeys() {
         return mTrustedKeys.listTrustAnchors();
     }
-}
+
+    public List<String> getErrorList() {
+        return mErrorList;
+    }
+ }