fix warnings and findbugs hints
[captive-validator.git] / src / com / verisign / tat / dnssec / CaptiveValidator.java
index 9bfba09..9ee511a 100644 (file)
@@ -31,7 +31,6 @@ import java.io.IOException;
 
 import java.util.*;
 
-
 /**
  * This resolver module implements a "captive" DNSSEC validator. The captive
  * validator does not have direct access to the Internet and DNS system --
@@ -48,12 +47,15 @@ public class CaptiveValidator {
 
     // The local verification utility.
     private DnsSecVerifier mVerifier;
-    private Logger         log = Logger.getLogger(this.getClass());
+    private Logger log = Logger.getLogger(this.getClass());
+
+    private List<String>   mErrorList;
 
     public CaptiveValidator() {
         mVerifier        = new DnsSecVerifier();
         mValUtils        = new ValUtils(mVerifier);
         mTrustedKeys     = new TrustAnchorStore();
+        mErrorList       = new ArrayList<String>();
     }
 
     // ---------------- Module Initialization -------------------
@@ -61,18 +63,17 @@ public class CaptiveValidator {
     /**
      * Add a set of trusted keys from a file. The file should be in DNS master
      * zone file format. Only DNSKEY records will be added.
-     *
+     * 
      * @param filename
      *            The file contains the trusted keys.
      * @throws IOException
      */
     @SuppressWarnings("unchecked")
-    public void addTrustedKeysFromFile(String filename)
-        throws IOException {
+    public void addTrustedKeysFromFile(String filename) throws IOException {
         // First read in the whole trust anchor file.
-        Master            master  = new Master(filename, Name.root, 0);
+        Master master = new Master(filename, Name.root, 0);
         ArrayList<Record> records = new ArrayList<Record>();
-        Record            r       = null;
+        Record r = null;
 
         while ((r = master.nextRecord()) != null) {
             records.add(r);
@@ -100,9 +101,9 @@ public class CaptiveValidator {
             }
 
             // If this record matches our current RRset, we can just add it.
-            if (cur_rrset.getName().equals(rec.getName()) &&
-                    (cur_rrset.getType() == rec.getType()) &&
-                    (cur_rrset.getDClass() == rec.getDClass())) {
+            if (cur_rrset.getName().equals(rec.getName())
+                    && (cur_rrset.getType() == rec.getType())
+                    && (cur_rrset.getDClass() == rec.getDClass())) {
                 cur_rrset.addRR(rec);
 
                 continue;
@@ -121,7 +122,7 @@ public class CaptiveValidator {
     }
 
     public void addTrustedKeysFromResponse(Message m) {
-        RRset [] rrsets = m.getSectionRRsets(Section.ANSWER);
+        RRset[] rrsets = m.getSectionRRsets(Section.ANSWER);
 
         for (int i = 0; i < rrsets.length; ++i) {
             if (rrsets[i].getType() == Type.DNSKEY) {
@@ -137,7 +138,7 @@ public class CaptiveValidator {
      * This routine normalizes a response. This includes removing "irrelevant"
      * records from the answer and additional sections and (re)synthesizing
      * CNAMEs from DNAMEs, if present.
-     *
+     * 
      * @param response
      */
     private SMessage normalize(SMessage m) {
@@ -145,26 +146,25 @@ public class CaptiveValidator {
             return m;
         }
 
-        if ((m.getRcode() != Rcode.NOERROR) &&
-                (m.getRcode() != Rcode.NXDOMAIN)) {
+        if ((m.getRcode() != Rcode.NOERROR) && (m.getRcode() != Rcode.NXDOMAIN)) {
             return m;
         }
 
-        Name         qname            = m.getQuestion().getName();
-        int          qtype            = m.getQuestion().getType();
+        Name qname = m.getQuestion().getName();
+        int qtype = m.getQuestion().getType();
 
-        Name         sname            = qname;
+        Name sname = qname;
 
         // For the ANSWER section, remove all "irrelevant" records and add
         // synthesized CNAMEs from DNAMEs
         // This will strip out-of-order CNAMEs as well.
-        List<SRRset> rrset_list       = m.getSectionList(Section.ANSWER);
-        Set<Name>    additional_names = new HashSet<Name>();
+        List<SRRset> rrset_list = m.getSectionList(Section.ANSWER);
+        Set<Name> additional_names = new HashSet<Name>();
 
         for (ListIterator<SRRset> i = rrset_list.listIterator(); i.hasNext();) {
             SRRset rrset = i.next();
-            int    type  = rrset.getType();
-            Name   n     = rrset.getName();
+            int type = rrset.getType();
+            Name n = rrset.getName();
 
             // Handle DNAME synthesis; DNAME synthesis does not occur at the
             // DNAME name itself.
@@ -182,16 +182,16 @@ public class CaptiveValidator {
                     Name cname_alias = sname.fromDNAME(dname);
 
                     // Note that synthesized CNAMEs should have a TTL of zero.
-                    CNAMERecord cname       = new CNAMERecord(sname,
-                            dname.getDClass(), 0, cname_alias);
-                    SRRset      cname_rrset = new SRRset();
+                    CNAMERecord cname = new CNAMERecord(sname, dname
+                            .getDClass(), 0, cname_alias);
+                    SRRset cname_rrset = new SRRset();
                     cname_rrset.addRR(cname);
                     i.add(cname_rrset);
 
                     sname = cname_alias;
                 } catch (NameTooLongException e) {
-                    log.debug("not adding synthesized CNAME -- " +
-                        "generated name is too long", e);
+                    log.debug("not adding synthesized CNAME -- "
+                            + "generated name is too long", e);
                 }
 
                 continue;
@@ -208,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;
@@ -244,10 +244,10 @@ public class CaptiveValidator {
 
         for (Iterator<SRRset> i = rrset_list.iterator(); i.hasNext();) {
             SRRset rrset = i.next();
-            int    type  = rrset.getType();
+            int type = rrset.getType();
 
-            if (((type == Type.A) || (type == Type.AAAA)) &&
-                    !additional_names.contains(rrset.getName())) {
+            if (((type == Type.A) || (type == Type.AAAA))
+                    && !additional_names.contains(rrset.getName())) {
                 i.remove();
             }
         }
@@ -257,7 +257,7 @@ public class CaptiveValidator {
 
     /**
      * Extract additional names from the records in an rrset.
-     *
+     * 
      * @param additional_names
      *            The set to add the additional names to, if any.
      * @param rrset
@@ -269,8 +269,8 @@ public class CaptiveValidator {
         }
 
         for (Iterator<Record> i = rrset.rrs(); i.hasNext();) {
-            Record r        = i.next();
-            Name   add_name = r.getAdditionalName();
+            Record r = i.next();
+            Name add_name = r.getAdditionalName();
 
             if (add_name != null) {
                 additional_names.add(add_name);
@@ -279,8 +279,8 @@ public class CaptiveValidator {
     }
 
     private SRRset findKeys(SMessage message) {
-        Name qname  = message.getQName();
-        int  qclass = message.getQClass();
+        Name qname = message.getQName();
+        int qclass = message.getQClass();
 
         return mTrustedKeys.find(qname, qclass);
     }
@@ -291,12 +291,12 @@ public class CaptiveValidator {
      * on in the original request, the response was already validated, or the
      * response is a kind of message that is unvalidatable (i.e., SERVFAIL,
      * REFUSED, etc.)
-     *
+     * 
      * @param message
      *            The message to check.
      * @param origRequest
      *            The original request received from the client.
-     *
+     * 
      * @return true if the response could use validation (although this does not
      *         mean we can actually validate this response).
      */
@@ -310,8 +310,8 @@ public class CaptiveValidator {
             return false;
         }
 
-        if (!mTrustedKeys.isBelowTrustAnchor(message.getQName(),
-                    message.getQClass())) {
+        if (!mTrustedKeys.isBelowTrustAnchor(message.getQName(), message
+                .getQClass())) {
             return false;
         }
 
@@ -322,11 +322,11 @@ public class CaptiveValidator {
      * Given a "positive" response -- a response that contains an answer to the
      * question, and no CNAME chain, validate this response. This generally
      * consists of verifying the answer RRset and the authority RRsets.
-     *
+     * 
      * Note that by the time this method is called, the process of finding the
      * trusted DNSKEY rrset that signs this response must already have been
      * completed.
-     *
+     * 
      * @param response
      *            The response to validate.
      * @param request
@@ -336,18 +336,18 @@ public class CaptiveValidator {
      *            answer.
      */
     private void validatePositiveResponse(SMessage message, SRRset key_rrset) {
-        Name     qname = message.getQName();
-        int      qtype = message.getQType();
+        Name qname = message.getQName();
+        int qtype = message.getQType();
 
-        SMessage m     = message;
+        SMessage m = message;
 
         // validate the ANSWER section - this will be the answer itself
-        SRRset []         rrsets    = m.getSectionRRsets(Section.ANSWER);
+        SRRset[] rrsets = m.getSectionRRsets(Section.ANSWER);
 
-        Name              wc        = null;
-        boolean           wcNSEC_ok = false;
-        boolean           dname     = false;
-        List<NSEC3Record> nsec3s    = null;
+        Name wc = null;
+        boolean wcNSEC_ok = false;
+        boolean dname = false;
+        List<NSEC3Record> nsec3s = null;
 
         for (int i = 0; i < rrsets.length; i++) {
             // Skip the CNAME following a (validated) DNAME.
@@ -366,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;
@@ -392,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;
@@ -408,13 +407,12 @@ public class CaptiveValidator {
             if ((wc != null) && (rrsets[i].getType() == Type.NSEC)) {
                 NSECRecord nsec = (NSECRecord) rrsets[i].first();
 
-                if (ValUtils.nsecProvesNameError(nsec, qname,
-                            key_rrset.getName())) {
+                if (ValUtils.nsecProvesNameError(nsec, qname, key_rrset
+                        .getName())) {
                     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;
@@ -440,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;
             }
         }
@@ -469,13 +467,13 @@ public class CaptiveValidator {
         }
 
         // validate the AUTHORITY section.
-        SRRset []         rrsets            = m.getSectionRRsets(Section.AUTHORITY);
+        SRRset[] rrsets = m.getSectionRRsets(Section.AUTHORITY);
 
-        boolean           secure_delegation = false;
-        Name              delegation        = null;
-        Name              nsec3zone         = null;
-        NSECRecord        nsec              = null;
-        List<NSEC3Record> nsec3s            = null;
+        boolean secure_delegation = false;
+        Name delegation = null;
+        Name nsec3zone = null;
+        NSECRecord nsec = null;
+        List<NSEC3Record> nsec3s = null;
 
         // validate the AUTHORITY section as well - this will generally be the
         // NS rrset, plus proof of a secure delegation or not
@@ -492,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;
@@ -501,40 +499,39 @@ public class CaptiveValidator {
             }
 
             switch (type) {
-                case Type.DS:
-                    secure_delegation = true;
+            case Type.DS:
+                secure_delegation = true;
 
-                    break;
+                break;
 
-                case Type.NS:
-                    delegation = rrsets[i].getName();
+            case Type.NS:
+                delegation = rrsets[i].getName();
 
-                    break;
+                break;
 
-                case Type.NSEC:
-                    nsec = (NSECRecord) rrsets[i].first();
+            case Type.NSEC:
+                nsec = (NSECRecord) rrsets[i].first();
 
-                    break;
+                break;
 
-                case Type.NSEC3:
+            case Type.NSEC3:
 
-                    if (nsec3s == null) {
-                        nsec3s = new ArrayList<NSEC3Record>();
-                    }
+                if (nsec3s == null) {
+                    nsec3s = new ArrayList<NSEC3Record>();
+                }
 
-                    NSEC3Record nsec3 = (NSEC3Record) rrsets[i].first();
-                    nsec3s.add(nsec3);
-                    nsec3zone = rrsets[i].getSignerName(); // this is a hack of
-                                                           // sorts.
+                NSEC3Record nsec3 = (NSEC3Record) rrsets[i].first();
+                nsec3s.add(nsec3);
+                nsec3zone = rrsets[i].getSignerName(); // this is a hack of
+                // sorts.
 
-                    break;
+                break;
 
-                default:
-                    log.warn(
-                        "Encountered unexpected type in a REFERRAL response: " +
-                        Type.string(type));
+            default:
+                log.warn("Encountered unexpected type in a REFERRAL response: "
+                        + Type.string(type));
 
-                    break;
+                break;
             }
         }
 
@@ -542,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;
@@ -550,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;
@@ -568,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;
@@ -579,11 +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;
@@ -595,28 +596,30 @@ public class CaptiveValidator {
         }
 
         // failed to find proof either way.
+        mErrorList.add("Referral does not contain proof of no DS");
         m.setStatus(SecurityStatus.BOGUS);
     }
 
+    // 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
      * qtype==ANY question, with answers. This consists of simply verifying all
      * present answer/auth RRsets, with no checking that all types are present.
-     *
+     * 
      * NOTE: it may be possible to get parent-side delegation point records
      * here, which won't all be signed. Right now, this routine relies on the
      * upstream iterative resolver to not return these responses -- instead
      * treating them as referrals.
-     *
+     * 
      * NOTE: RFC 4035 is silent on this issue, so this may change upon
      * clarification.
-     *
+     * 
      * Note that by the time this method is called, the process of finding the
      * trusted DNSKEY rrset that signs this response must already have been
      * completed.
-     *
+     * 
      * @param message
      *            The response to validate.
      * @param key_rrset
@@ -628,13 +631,13 @@ public class CaptiveValidator {
 
         if (qtype != Type.ANY) {
             throw new IllegalArgumentException(
-                "ANY validation called on non-ANY response.");
+                    "ANY validation called on non-ANY response.");
         }
 
         SMessage m = message;
 
         // validate the ANSWER section.
-        SRRset [] rrsets = m.getSectionRRsets(Section.ANSWER);
+        SRRset[] rrsets = m.getSectionRRsets(Section.ANSWER);
 
         for (int i = 0; i < rrsets.length; i++) {
             int status = mValUtils.verifySRRset(rrsets[i], key_rrset);
@@ -642,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;
@@ -658,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;
@@ -679,11 +681,11 @@ public class CaptiveValidator {
      * the authority section rrsets and making certain that the authority
      * section NSEC/NSEC3s proves that the qname does exist and the qtype
      * doesn't.
-     *
+     * 
      * Note that by the time this method is called, the process of finding the
      * trusted DNSKEY rrset that signs this response must already have been
      * completed.
-     *
+     * 
      * @param response
      *            The response to validate.
      * @param request
@@ -691,11 +693,11 @@ public class CaptiveValidator {
      * @param key_rrset
      *            The trusted DNSKEY rrset that signs this response.
      */
-    private void validateNodataResponse(SMessage message, SRRset key_rrset) {
+    private void validateNodataResponse(SMessage message, SRRset key_rrset, List<String> errorList) {
         Name     qname = message.getQName();
         int      qtype = message.getQType();
 
-        SMessage m     = message;
+        SMessage m = message;
 
         // Since we are here, there must be nothing in the ANSWER section to
         // validate. (Note: CNAME/DNAME responses will not directly get here --
@@ -703,29 +705,29 @@ public class CaptiveValidator {
         // responses.)
 
         // validate the AUTHORITY section
-        SRRset []         rrsets       = m.getSectionRRsets(Section.AUTHORITY);
+        SRRset[] rrsets = m.getSectionRRsets(Section.AUTHORITY);
 
-        boolean           hasValidNSEC = false; // If true, then the NODATA has been
-                                                // proven.
+        boolean hasValidNSEC = false; // If true, then the NODATA has been
+        // proven.
 
-        Name              ce           = null; // for wildcard NODATA responses. This is the proven
-                                               // closest encloser.
+        Name ce = null; // for wildcard NODATA responses. This is the proven
+        // closest encloser.
 
-        NSECRecord        wc           = null; // for wildcard NODATA responses. This is the
-                                               // wildcard NSEC.
+        NSECRecord wc = null; // for wildcard NODATA responses. This is the
+        // wildcard NSEC.
 
-        List<NSEC3Record> nsec3s       = null; // A collection of NSEC3 RRs found in
-                                               // the authority
-                                               // section.
+        List<NSEC3Record> nsec3s = null; // A collection of NSEC3 RRs found in
+        // the authority
+        // section.
 
-        Name              nsec3Signer  = null; // The RRSIG signer field for the NSEC3 RRs.
+        Name nsec3Signer = null; // The RRSIG signer field for the NSEC3 RRs.
 
         for (int i = 0; i < rrsets.length; i++) {
             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;
@@ -742,8 +744,8 @@ public class CaptiveValidator {
                     if (nsec.getName().isWild()) {
                         wc = nsec;
                     }
-                } else if (ValUtils.nsecProvesNameError(nsec, qname,
-                            rrsets[i].getSignerName())) {
+                } else if (ValUtils.nsecProvesNameError(nsec, qname, rrsets[i]
+                        .getSignerName())) {
                     ce = ValUtils.closestEncloser(qname, nsec);
                 }
             }
@@ -781,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.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;
@@ -802,11 +805,11 @@ public class CaptiveValidator {
      * Rcode. This consists of verifying the authority section rrsets and making
      * certain that the authority section NSEC proves that the qname doesn't
      * exist and the covering wildcard also doesn't exist..
-     *
+     * 
      * Note that by the time this method is called, the process of finding the
      * trusted DNSKEY rrset that signs this response must already have been
      * completed.
-     *
+     * 
      * @param response
      *            The response to validate.
      * @param request
@@ -815,13 +818,14 @@ public class CaptiveValidator {
      *            The trusted DNSKEY rrset that signs this response.
      */
     private void validateNameErrorResponse(SMessage message, SRRset key_rrset) {
-        Name     qname = message.getQName();
+        Name qname = message.getQName();
 
-        SMessage m     = message;
+        SMessage m = message;
 
         if (message.getCount(Section.ANSWER) > 0) {
             log.warn(
-                "NAME ERROR response contained records in the ANSWER SECTION");
+                "NameError response contained records in the ANSWER SECTION");
+            mErrorList.add("NameError response contained records in the ANSWER SECTION");
             message.setStatus(SecurityStatus.INVALID);
 
             return;
@@ -830,18 +834,18 @@ public class CaptiveValidator {
         // Validate the authority section -- all RRsets in the authority section
         // must be signed and valid.
         // In addition, the NSEC record(s) must prove the NXDOMAIN condition.
-        boolean           hasValidNSEC   = false;
-        boolean           hasValidWCNSEC = false;
-        SRRset []         rrsets         = m.getSectionRRsets(Section.AUTHORITY);
-        List<NSEC3Record> nsec3s         = null;
-        Name              nsec3Signer    = null;
+        boolean hasValidNSEC = false;
+        boolean hasValidWCNSEC = false;
+        SRRset[] rrsets = m.getSectionRRsets(Section.AUTHORITY);
+        List<NSEC3Record> nsec3s = null;
+        Name nsec3Signer = null;
 
         for (int i = 0; i < rrsets.length; i++) {
             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;
@@ -850,13 +854,13 @@ public class CaptiveValidator {
             if (rrsets[i].getType() == Type.NSEC) {
                 NSECRecord nsec = (NSECRecord) rrsets[i].first();
 
-                if (ValUtils.nsecProvesNameError(nsec, qname,
-                            rrsets[i].getSignerName())) {
+                if (ValUtils.nsecProvesNameError(nsec, qname, rrsets[i]
+                        .getSignerName())) {
                     hasValidNSEC = true;
                 }
 
-                if (ValUtils.nsecProvesNoWC(nsec, qname,
-                            rrsets[i].getSignerName())) {
+                if (ValUtils.nsecProvesNoWC(nsec, qname, rrsets[i]
+                        .getSignerName())) {
                     hasValidWCNSEC = true;
                 }
             }
@@ -885,25 +889,23 @@ public class CaptiveValidator {
             }
 
             hasValidNSEC       = NSEC3ValUtils.proveNameError(nsec3s, qname,
-                    nsec3Signer);
+                    nsec3Signer, mErrorList);
 
             // Note that we assume that the NSEC3ValUtils proofs encompass the
             // wildcard part of the proof.
-            hasValidWCNSEC     = hasValidNSEC;
+            hasValidWCNSEC = hasValidNSEC;
         }
 
         // 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;
@@ -915,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);
@@ -936,58 +939,59 @@ 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;
         }
 
         ValUtils.ResponseType subtype = ValUtils.classifyResponse(message, zone);
 
         switch (subtype) {
-            case POSITIVE:
-                log.trace("Validating a positive response");
-                validatePositiveResponse(message, key_rrset);
+        case POSITIVE:
+            log.trace("Validating a positive response");
+            validatePositiveResponse(message, key_rrset);
 
-                break;
+            break;
 
-            case REFERRAL:
-                validateReferral(message, key_rrset);
+        case REFERRAL:
+            validateReferral(message, key_rrset);
 
-                break;
+            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;
+            break;
 
-            case NAMEERROR:
-                log.trace("Validating a NXDOMAIN response");
-                validateNameErrorResponse(message, key_rrset);
+        case NAMEERROR:
+            log.trace("Validating a NXDOMAIN response");
+            validateNameErrorResponse(message, key_rrset);
 
-                break;
+            break;
 
-            case CNAME:
-                log.trace("Validating a CNAME response");
-                validateCNAMEResponse(message, key_rrset);
+        case CNAME:
+            log.trace("Validating a CNAME response");
+            validateCNAMEResponse(message, key_rrset);
 
-                break;
+            break;
 
-            case ANY:
-                log.trace("Validating a positive ANY response");
-                validateAnyResponse(message, key_rrset);
+        case ANY:
+            log.trace("Validating a positive ANY response");
+            validateAnyResponse(message, key_rrset);
 
-                break;
+            break;
 
-            default:
-                log.error("unhandled response subtype: " + subtype);
+        default:
+            log.error("unhandled response subtype: " + subtype);
         }
 
         return message.getSecurityStatus().getStatus();
     }
 
     public byte validateMessage(Message message, String zone)
-        throws TextParseException {
+            throws TextParseException {
         SMessage sm = new SMessage(message);
-        Name     z  = Name.fromString(zone);
+        Name z = Name.fromString(zone);
 
         return validateMessage(sm, z);
     }
@@ -995,4 +999,8 @@ public class CaptiveValidator {
     public List<String> listTrustedKeys() {
         return mTrustedKeys.listTrustAnchors();
     }
-}
+
+    public List<String> getErrorList() {
+        return mErrorList;
+    }
+ }