1 /***************************** -*- Java -*- ********************************\
3 * Copyright (c) 2009 VeriSign, Inc. All rights reserved. *
5 * This software is provided solely in connection with the terms of the *
6 * license agreement. Any other use without the prior express written *
7 * permission of VeriSign is completely prohibited. The software and *
8 * documentation are "Commercial Items", as that term is defined in 48 *
9 * C.F.R. section 2.101, consisting of "Commercial Computer Software" and *
10 * "Commercial Computer Software Documentation" as such terms are defined *
11 * in 48 C.F.R. section 252.227-7014(a)(5) and 48 C.F.R. section *
12 * 252.227-7014(a)(1), and used in 48 C.F.R. section 12.212 and 48 C.F.R. *
13 * section 227.7202, as applicable. Pursuant to the above and other *
14 * relevant sections of the Code of Federal Regulations, as applicable, *
15 * VeriSign's publications, commercial computer software, and commercial *
16 * computer software documentation are distributed and licensed to United *
17 * States Government end users with only those rights as granted to all *
18 * other end users, according to the terms and conditions contained in the *
19 * license agreement(s) that accompany the products and software *
22 \***************************************************************************/
24 package com.verisign.tat.dnssec;
26 import org.apache.log4j.Logger;
28 import org.xbill.DNS.*;
29 import org.xbill.DNS.utils.base64;
31 import java.io.IOException;
36 * This resolver module implements a "captive" DNSSEC validator. The captive
37 * validator does not have direct access to the Internet and DNS system --
38 * instead it attempts to validate DNS messages using only configured context.
39 * This is useful for determining if responses coming from a given authoritative
40 * server will validate independent of the normal chain of trust.
42 public class CaptiveValidator {
43 // A data structure holding all all of our trusted keys.
44 private TrustAnchorStore mTrustedKeys;
46 // The local validation utilities.
47 private ValUtils mValUtils;
49 // The local verification utility.
50 private DnsSecVerifier mVerifier;
51 private Logger log = Logger.getLogger(this.getClass());
53 private List<String> mErrorList;
55 public CaptiveValidator() {
56 mVerifier = new DnsSecVerifier();
57 mValUtils = new ValUtils(mVerifier);
58 mTrustedKeys = new TrustAnchorStore();
59 mErrorList = new ArrayList<String>();
62 // ---------------- Module Initialization -------------------
65 * Add a set of trusted keys from a file. The file should be in DNS master
66 * zone file format. Only DNSKEY records will be added.
69 * The file contains the trusted keys.
72 @SuppressWarnings("unchecked")
73 public void addTrustedKeysFromFile(String filename) throws IOException {
74 // First read in the whole trust anchor file.
75 Master master = new Master(filename, Name.root, 0);
76 ArrayList<Record> records = new ArrayList<Record>();
79 while ((r = master.nextRecord()) != null) {
83 // Record.compareTo() should sort them into DNSSEC canonical order.
84 // Don't care about canonical order per se, but do want them to be
85 // formable into RRsets.
86 Collections.sort(records);
88 SRRset cur_rrset = new SRRset();
90 for (Record rec : records) {
91 // Skip RR types that cannot be used as trusted keys. I.e.,
92 // everything not a key :)
93 if (rec.getType() != Type.DNSKEY) {
97 // If our cur_rrset is empty, we can just add it.
98 if (cur_rrset.size() == 0) {
104 // If this record matches our current RRset, we can just add it.
105 if (cur_rrset.getName().equals(rec.getName())
106 && (cur_rrset.getType() == rec.getType())
107 && (cur_rrset.getDClass() == rec.getDClass())) {
108 cur_rrset.addRR(rec);
113 // Otherwise, we add the rrset to our set of trust anchors.
114 mTrustedKeys.store(cur_rrset);
115 cur_rrset = new SRRset();
116 cur_rrset.addRR(rec);
119 // add the last rrset (if it was not empty)
120 if (cur_rrset.size() > 0) {
121 mTrustedKeys.store(cur_rrset);
125 public void addTrustedKeysFromResponse(Message m) {
126 RRset[] rrsets = m.getSectionRRsets(Section.ANSWER);
128 for (int i = 0; i < rrsets.length; ++i) {
129 if (rrsets[i].getType() == Type.DNSKEY) {
130 SRRset srrset = new SRRset(rrsets[i]);
131 mTrustedKeys.store(srrset);
136 // ----------------- Validation Support ----------------------
139 * This routine normalizes a response. This includes removing "irrelevant"
140 * records from the answer and additional sections and (re)synthesizing
141 * CNAMEs from DNAMEs, if present.
145 private SMessage normalize(SMessage m) {
150 if ((m.getRcode() != Rcode.NOERROR) && (m.getRcode() != Rcode.NXDOMAIN)) {
154 Name qname = m.getQuestion().getName();
155 int qtype = m.getQuestion().getType();
159 // For the ANSWER section, remove all "irrelevant" records and add
160 // synthesized CNAMEs from DNAMEs
161 // This will strip out-of-order CNAMEs as well.
162 List<SRRset> rrset_list = m.getSectionList(Section.ANSWER);
163 Set<Name> additional_names = new HashSet<Name>();
165 for (ListIterator<SRRset> i = rrset_list.listIterator(); i.hasNext();) {
166 SRRset rrset = i.next();
167 int type = rrset.getType();
168 Name n = rrset.getName();
170 // Handle DNAME synthesis; DNAME synthesis does not occur at the
171 // DNAME name itself.
172 if ((type == Type.DNAME) && ValUtils.strictSubdomain(sname, n)) {
173 if (rrset.size() > 1) {
174 log.debug("Found DNAME rrset with size > 1: " + rrset);
175 m.setStatus(SecurityStatus.INVALID);
180 DNAMERecord dname = (DNAMERecord) rrset.first();
183 Name cname_alias = sname.fromDNAME(dname);
185 // Note that synthesized CNAMEs should have a TTL of zero.
186 CNAMERecord cname = new CNAMERecord(sname, dname
187 .getDClass(), 0, cname_alias);
188 SRRset cname_rrset = new SRRset();
189 cname_rrset.addRR(cname);
193 } catch (NameTooLongException e) {
194 log.debug("not adding synthesized CNAME -- "
195 + "generated name is too long", e);
201 // The only records in the ANSWER section not allowed to
202 if (!n.equals(sname)) {
203 log.debug("normalize: removing irrelevant rrset: " + rrset);
209 // Follow the CNAME chain.
210 if (type == Type.CNAME) {
211 if (rrset.size() > 1) {
212 mErrorList.add("Found CNAME rrset with size > 1: " + rrset);
213 m.setStatus(SecurityStatus.INVALID);
218 CNAMERecord cname = (CNAMERecord) rrset.first();
219 sname = cname.getAlias();
224 // Otherwise, make sure that the RRset matches the qtype.
225 if ((qtype != Type.ANY) && (qtype != type)) {
226 log.debug("normalize: removing irrelevant rrset: " + rrset);
230 // Otherwise, fetch the additional names from the relevant rrset.
231 rrsetAdditionalNames(additional_names, rrset);
234 // Get additional names from AUTHORITY
235 rrset_list = m.getSectionList(Section.AUTHORITY);
237 for (SRRset rrset : rrset_list) {
238 rrsetAdditionalNames(additional_names, rrset);
241 // For each record in the additional section, remove it if it is an
242 // address record and not in the collection of additional names found in
243 // ANSWER and AUTHORITY.
244 rrset_list = m.getSectionList(Section.ADDITIONAL);
246 for (Iterator<SRRset> i = rrset_list.iterator(); i.hasNext();) {
247 SRRset rrset = i.next();
248 int type = rrset.getType();
250 if (((type == Type.A) || (type == Type.AAAA))
251 && !additional_names.contains(rrset.getName())) {
260 * Extract additional names from the records in an rrset.
262 * @param additional_names
263 * The set to add the additional names to, if any.
265 * The rrset to extract from.
267 private void rrsetAdditionalNames(Set<Name> additional_names, SRRset rrset) {
272 for (Iterator<Record> i = rrset.rrs(); i.hasNext();) {
274 Name add_name = r.getAdditionalName();
276 if (add_name != null) {
277 additional_names.add(add_name);
282 private SRRset findKeys(SMessage message) {
283 Name qname = message.getQName();
284 int qclass = message.getQClass();
286 return mTrustedKeys.find(qname, qclass);
290 * Check to see if a given response needs to go through the validation
291 * process. Typical reasons for this routine to return false are: CD bit was
292 * on in the original request, the response was already validated, or the
293 * response is a kind of message that is unvalidatable (i.e., SERVFAIL,
297 * The message to check.
299 * The original request received from the client.
301 * @return true if the response could use validation (although this does not
302 * mean we can actually validate this response).
304 private boolean needsValidation(SMessage message) {
305 int rcode = message.getRcode();
307 if ((rcode != Rcode.NOERROR) && (rcode != Rcode.NXDOMAIN)) {
308 log.debug("cannot validate non-answer.");
309 log.trace("non-answer: " + message);
314 if (!mTrustedKeys.isBelowTrustAnchor(message.getQName(), message
323 * Given a "positive" response -- a response that contains an answer to the
324 * question, and no CNAME chain, validate this response. This generally
325 * consists of verifying the answer RRset and the authority RRsets.
327 * Note that by the time this method is called, the process of finding the
328 * trusted DNSKEY rrset that signs this response must already have been
332 * The response to validate.
334 * The request that generated this response.
336 * The trusted DNSKEY rrset that matches the signer of the
339 private void validatePositiveResponse(SMessage message, SRRset key_rrset) {
340 Name qname = message.getQName();
341 int qtype = message.getQType();
343 SMessage m = message;
345 // validate the ANSWER section - this will be the answer itself
346 SRRset[] rrsets = m.getSectionRRsets(Section.ANSWER);
349 boolean wcNSEC_ok = false;
350 boolean dname = false;
351 List<NSEC3Record> nsec3s = null;
353 for (int i = 0; i < rrsets.length; i++) {
354 // Skip the CNAME following a (validated) DNAME.
355 // Because of the normalization routines in NameserverClient, there
356 // will always be an unsigned CNAME following a DNAME (unless
358 if (dname && (rrsets[i].getType() == Type.CNAME)) {
364 // Verify the answer rrset.
365 int status = mValUtils.verifySRRset(rrsets[i], key_rrset);
367 // If the (answer) rrset failed to validate, then this message is
369 if (status != SecurityStatus.SECURE) {
370 mErrorList.add("Positive response has failed ANSWER rrset: " +
372 m.setStatus(SecurityStatus.BOGUS);
377 // Check to see if the rrset is the result of a wildcard expansion.
378 // If so, an additional check will need to be made in the authority
380 wc = ValUtils.rrsetWildcard(rrsets[i]);
382 // Notice a DNAME that should be followed by an unsigned CNAME.
383 if ((qtype != Type.DNAME) && (rrsets[i].getType() == Type.DNAME)) {
388 // validate the AUTHORITY section as well - this will generally be the
389 // NS rrset (which could be missing, no problem)
390 rrsets = m.getSectionRRsets(Section.AUTHORITY);
392 for (int i = 0; i < rrsets.length; i++) {
393 int status = mValUtils.verifySRRset(rrsets[i], key_rrset);
395 // If anything in the authority section fails to be secure, we have
397 if (status != SecurityStatus.SECURE) {
398 mErrorList.add("Positive response has failed AUTHORITY rrset: " +
400 m.setStatus(SecurityStatus.BOGUS);
405 // If this is a positive wildcard response, and we have a (just
406 // verified) NSEC record, try to use it to 1) prove that qname
407 // doesn't exist and 2) that the correct wildcard was used.
408 if ((wc != null) && (rrsets[i].getType() == Type.NSEC)) {
409 NSECRecord nsec = (NSECRecord) rrsets[i].first();
411 if (ValUtils.nsecProvesNameError(nsec, qname, key_rrset
413 Name nsec_wc = ValUtils.nsecWildcard(qname, nsec);
415 if (!wc.equals(nsec_wc)) {
416 mErrorList.add("Positive wildcard response wasn't generated by the correct wildcard");
417 m.setStatus(SecurityStatus.BOGUS);
426 // Otherwise, if this is a positive wildcard response and we have
427 // NSEC3 records, collect them.
428 if ((wc != null) && (rrsets[i].getType() == Type.NSEC3)) {
429 if (nsec3s == null) {
430 nsec3s = new ArrayList<NSEC3Record>();
433 nsec3s.add((NSEC3Record) rrsets[i].first());
437 // If this was a positive wildcard response that we haven't already
438 // proven, and we have NSEC3 records, try to prove it using the NSEC3
440 if ((wc != null) && !wcNSEC_ok && (nsec3s != null)) {
441 if (NSEC3ValUtils.proveWildcard(nsec3s, qname, key_rrset.getName(),
447 // If after all this, we still haven't proven the positive wildcard
449 if ((wc != null) && !wcNSEC_ok) {
450 // log.debug("positive response was wildcard expansion and "
451 // + "did not prove original data did not exist");
452 m.setStatus(SecurityStatus.BOGUS);
457 log.trace("Successfully validated positive response");
458 m.setStatus(SecurityStatus.SECURE);
461 private void validateReferral(SMessage message, SRRset key_rrset) {
462 SMessage m = message;
464 if (m.getCount(Section.ANSWER) > 0) {
465 m.setStatus(SecurityStatus.INVALID);
470 // validate the AUTHORITY section.
471 SRRset[] rrsets = m.getSectionRRsets(Section.AUTHORITY);
473 boolean secure_delegation = false;
474 Name delegation = null;
475 Name nsec3zone = null;
476 NSECRecord nsec = null;
477 List<NSEC3Record> nsec3s = null;
479 // validate the AUTHORITY section as well - this will generally be the
480 // NS rrset, plus proof of a secure delegation or not
481 rrsets = m.getSectionRRsets(Section.AUTHORITY);
483 for (int i = 0; i < rrsets.length; i++) {
484 int type = rrsets[i].getType();
486 // The NS RRset won't be signed, but everything else should be.
487 if (type != Type.NS) {
488 int status = mValUtils.verifySRRset(rrsets[i], key_rrset);
490 // If anything in the authority section fails to be secure, we
493 if (status != SecurityStatus.SECURE) {
494 mErrorList.add("Positive response has failed AUTHORITY rrset: " +
496 m.setStatus(SecurityStatus.BOGUS);
504 secure_delegation = true;
509 delegation = rrsets[i].getName();
514 nsec = (NSECRecord) rrsets[i].first();
520 if (nsec3s == null) {
521 nsec3s = new ArrayList<NSEC3Record>();
524 NSEC3Record nsec3 = (NSEC3Record) rrsets[i].first();
526 nsec3zone = rrsets[i].getSignerName(); // this is a hack of
532 log.warn("Encountered unexpected type in a REFERRAL response: "
533 + Type.string(type));
539 // At this point, all validatable RRsets have been validated.
540 // Now to check to see if we have a valid combination of things.
541 if (delegation == null) {
542 // somehow we have a referral without an NS rrset.
543 mErrorList.add("Apparent referral does not contain NS RRset");
544 m.setStatus(SecurityStatus.BOGUS);
549 if (secure_delegation) {
550 if ((nsec != null) || ((nsec3s != null) && (nsec3s.size() > 0))) {
551 // we found both a DS rrset *and* NSEC/NSEC3 rrsets!
552 mErrorList.add("Referral contains both DS and NSEC/NSEC3 RRsets");
553 m.setStatus(SecurityStatus.BOGUS);
558 // otherwise, we are done.
559 m.setStatus(SecurityStatus.SECURE);
564 // Note: not going to care if both NSEC and NSEC3 rrsets were present.
566 byte status = ValUtils.nsecProvesNoDS(nsec, delegation);
568 if (status != SecurityStatus.SECURE) {
569 // The NSEC *must* prove that there was no DS record. The
570 // INSECURE state here is still bogus.
571 mErrorList.add("Referral does not contain a NSEC record proving no DS");
572 m.setStatus(SecurityStatus.BOGUS);
577 m.setStatus(SecurityStatus.SECURE);
582 if (nsec3s.size() > 0) {
583 byte status = NSEC3ValUtils.proveNoDS(nsec3s, delegation, nsec3zone, mErrorList);
585 if (status != SecurityStatus.SECURE) {
586 // the NSEC3 RRs MUST prove no DS, so the INDETERMINATE state is
588 mErrorList.add("Referral does not contain NSEC3 record(s) proving no DS");
589 m.setStatus(SecurityStatus.BOGUS);
594 m.setStatus(SecurityStatus.SECURE);
599 // failed to find proof either way.
600 mErrorList.add("Referral does not contain proof of no DS");
601 m.setStatus(SecurityStatus.BOGUS);
604 // FIXME: write CNAME validation code.
605 private void validateCNAMEResponse(SMessage message, SRRset key_rrset) {}
608 * Given an "ANY" response -- a response that contains an answer to a
609 * qtype==ANY question, with answers. This consists of simply verifying all
610 * present answer/auth RRsets, with no checking that all types are present.
612 * NOTE: it may be possible to get parent-side delegation point records
613 * here, which won't all be signed. Right now, this routine relies on the
614 * upstream iterative resolver to not return these responses -- instead
615 * treating them as referrals.
617 * NOTE: RFC 4035 is silent on this issue, so this may change upon
620 * Note that by the time this method is called, the process of finding the
621 * trusted DNSKEY rrset that signs this response must already have been
625 * The response to validate.
627 * The trusted DNSKEY rrset that matches the signer of the
630 private void validateAnyResponse(SMessage message, SRRset key_rrset) {
631 int qtype = message.getQType();
633 if (qtype != Type.ANY) {
634 throw new IllegalArgumentException(
635 "ANY validation called on non-ANY response.");
638 SMessage m = message;
640 // validate the ANSWER section.
641 SRRset[] rrsets = m.getSectionRRsets(Section.ANSWER);
643 for (int i = 0; i < rrsets.length; i++) {
644 int status = mValUtils.verifySRRset(rrsets[i], key_rrset);
646 // If the (answer) rrset failed to validate, then this message is
648 if (status != SecurityStatus.SECURE) {
649 mErrorList.add("Positive response has failed ANSWER rrset: " +
651 m.setStatus(SecurityStatus.BOGUS);
657 // validate the AUTHORITY section as well - this will be the NS rrset
658 // (which could be missing, no problem)
659 rrsets = m.getSectionRRsets(Section.AUTHORITY);
661 for (int i = 0; i < rrsets.length; i++) {
662 int status = mValUtils.verifySRRset(rrsets[i], key_rrset);
664 // If anything in the authority section fails to be secure, we have
666 if (status != SecurityStatus.SECURE) {
667 mErrorList.add("Positive response has failed AUTHORITY rrset: " +
669 m.setStatus(SecurityStatus.BOGUS);
675 log.trace("Successfully validated positive ANY response");
676 m.setStatus(SecurityStatus.SECURE);
680 * Validate a NOERROR/NODATA signed response -- a response that has a
681 * NOERROR Rcode but no ANSWER section RRsets. This consists of verifying
682 * the authority section rrsets and making certain that the authority
683 * section NSEC/NSEC3s proves that the qname does exist and the qtype
686 * Note that by the time this method is called, the process of finding the
687 * trusted DNSKEY rrset that signs this response must already have been
691 * The response to validate.
693 * The request that generated this response.
695 * The trusted DNSKEY rrset that signs this response.
697 private void validateNodataResponse(SMessage message, SRRset key_rrset, List<String> errorList) {
698 Name qname = message.getQName();
699 int qtype = message.getQType();
701 SMessage m = message;
703 // Since we are here, there must be nothing in the ANSWER section to
704 // validate. (Note: CNAME/DNAME responses will not directly get here --
705 // instead they are broken down into individual CNAME/DNAME/final answer
708 // validate the AUTHORITY section
709 SRRset[] rrsets = m.getSectionRRsets(Section.AUTHORITY);
711 boolean hasValidNSEC = false; // If true, then the NODATA has been
714 Name ce = null; // for wildcard NODATA responses. This is the proven
717 NSECRecord wc = null; // for wildcard NODATA responses. This is the
720 List<NSEC3Record> nsec3s = null; // A collection of NSEC3 RRs found in
724 Name nsec3Signer = null; // The RRSIG signer field for the NSEC3 RRs.
726 for (int i = 0; i < rrsets.length; i++) {
727 int status = mValUtils.verifySRRset(rrsets[i], key_rrset);
729 if (status != SecurityStatus.SECURE) {
730 mErrorList.add("NODATA response has failed AUTHORITY rrset: " +
732 m.setStatus(SecurityStatus.BOGUS);
737 // If we encounter an NSEC record, try to use it to prove NODATA.
738 // This needs to handle the ENT NODATA case.
739 if (rrsets[i].getType() == Type.NSEC) {
740 NSECRecord nsec = (NSECRecord) rrsets[i].first();
742 if (ValUtils.nsecProvesNodata(nsec, qname, qtype)) {
745 if (nsec.getName().isWild()) {
748 } else if (ValUtils.nsecProvesNameError(nsec, qname, rrsets[i]
750 ce = ValUtils.closestEncloser(qname, nsec);
754 // Collect any NSEC3 records present.
755 if (rrsets[i].getType() == Type.NSEC3) {
756 if (nsec3s == null) {
757 nsec3s = new ArrayList<NSEC3Record>();
760 nsec3s.add((NSEC3Record) rrsets[i].first());
761 nsec3Signer = rrsets[i].getSignerName();
765 // check to see if we have a wildcard NODATA proof.
767 // The wildcard NODATA is 1 NSEC proving that qname does not exists (and
768 // also proving what the closest encloser is), and 1 NSEC showing the
769 // matching wildcard, which must be *.closest_encloser.
770 if ((ce != null) || (wc != null)) {
772 Name wc_name = new Name("*", ce);
774 if (!wc_name.equals(wc.getName())) {
775 hasValidNSEC = false;
777 } catch (TextParseException e) {
782 NSEC3ValUtils.stripUnknownAlgNSEC3s(nsec3s);
784 if (!hasValidNSEC && (nsec3s != null) && (nsec3s.size() > 0)) {
785 // try to prove NODATA with our NSEC3 record(s)
786 hasValidNSEC = NSEC3ValUtils.proveNodata(nsec3s, qname, qtype,
787 nsec3Signer, errorList);
791 log.debug("NODATA response failed to prove NODATA "
792 + "status with NSEC/NSEC3");
793 log.trace("Failed NODATA:\n" + m);
794 mErrorList.add("NODATA response failed to prove NODATA status with NSEC/NSEC3");
795 m.setStatus(SecurityStatus.BOGUS);
800 log.trace("successfully validated NODATA response.");
801 m.setStatus(SecurityStatus.SECURE);
805 * Validate a NAMEERROR signed response -- a response that has a NXDOMAIN
806 * Rcode. This consists of verifying the authority section rrsets and making
807 * certain that the authority section NSEC proves that the qname doesn't
808 * exist and the covering wildcard also doesn't exist..
810 * Note that by the time this method is called, the process of finding the
811 * trusted DNSKEY rrset that signs this response must already have been
815 * The response to validate.
817 * The request that generated this response.
819 * The trusted DNSKEY rrset that signs this response.
821 private void validateNameErrorResponse(SMessage message, SRRset key_rrset) {
822 Name qname = message.getQName();
824 SMessage m = message;
826 if (message.getCount(Section.ANSWER) > 0) {
828 "NameError response contained records in the ANSWER SECTION");
829 mErrorList.add("NameError response contained records in the ANSWER SECTION");
830 message.setStatus(SecurityStatus.INVALID);
835 // Validate the authority section -- all RRsets in the authority section
836 // must be signed and valid.
837 // In addition, the NSEC record(s) must prove the NXDOMAIN condition.
838 boolean hasValidNSEC = false;
839 boolean hasValidWCNSEC = false;
840 SRRset[] rrsets = m.getSectionRRsets(Section.AUTHORITY);
841 List<NSEC3Record> nsec3s = null;
842 Name nsec3Signer = null;
844 for (int i = 0; i < rrsets.length; i++) {
845 int status = mValUtils.verifySRRset(rrsets[i], key_rrset);
847 if (status != SecurityStatus.SECURE) {
848 mErrorList.add("NameError response has failed AUTHORITY rrset: " +
850 m.setStatus(SecurityStatus.BOGUS);
855 if (rrsets[i].getType() == Type.NSEC) {
856 NSECRecord nsec = (NSECRecord) rrsets[i].first();
858 if (ValUtils.nsecProvesNameError(nsec, qname, rrsets[i]
863 if (ValUtils.nsecProvesNoWC(nsec, qname, rrsets[i]
865 hasValidWCNSEC = true;
869 if (rrsets[i].getType() == Type.NSEC3) {
870 if (nsec3s == null) {
871 nsec3s = new ArrayList<NSEC3Record>();
874 nsec3s.add((NSEC3Record) rrsets[i].first());
875 nsec3Signer = rrsets[i].getSignerName();
879 NSEC3ValUtils.stripUnknownAlgNSEC3s(nsec3s);
881 if ((nsec3s != null) && (nsec3s.size() > 0)) {
882 log.debug("Validating nxdomain: using NSEC3 records");
884 // Attempt to prove name error with nsec3 records.
885 if (NSEC3ValUtils.allNSEC3sIgnoreable(nsec3s, key_rrset, mVerifier)) {
886 // log.debug("all NSEC3s were validated but ignored.");
887 m.setStatus(SecurityStatus.INSECURE);
892 hasValidNSEC = NSEC3ValUtils.proveNameError(nsec3s, qname,
893 nsec3Signer, mErrorList);
895 // Note that we assume that the NSEC3ValUtils proofs encompass the
896 // wildcard part of the proof.
897 hasValidWCNSEC = hasValidNSEC;
900 // If the message fails to prove either condition, it is bogus.
902 mErrorList.add("NameError response has failed to prove qname does not exist");
903 m.setStatus(SecurityStatus.BOGUS);
908 if (!hasValidWCNSEC) {
909 mErrorList.add("NameError response has failed to prove covering wildcard does not exist");
910 m.setStatus(SecurityStatus.BOGUS);
915 // Otherwise, we consider the message secure.
916 log.trace("successfully validated NAME ERROR response.");
917 m.setStatus(SecurityStatus.SECURE);
920 public byte validateMessage(SMessage message, Name zone) {
922 if (!zone.isAbsolute()) {
924 zone = Name.concatenate(zone, Name.root);
925 } catch (NameTooLongException e) {
928 return SecurityStatus.UNCHECKED;
932 // FIXME: it is unclear if we should actually normalize our responses
933 // Instead, maybe we should just fail if they are not normal?
934 message = normalize(message);
936 if (!needsValidation(message)) {
937 return SecurityStatus.UNCHECKED;
940 SRRset key_rrset = findKeys(message);
942 if (key_rrset == null) {
943 mErrorList.add("Failed to find matching DNSKEYs for the response");
944 return SecurityStatus.BOGUS;
947 ValUtils.ResponseType subtype = ValUtils.classifyResponse(message, zone);
951 log.trace("Validating a positive response");
952 validatePositiveResponse(message, key_rrset);
957 validateReferral(message, key_rrset);
962 log.trace("Validating a NODATA response");
963 validateNodataResponse(message, key_rrset, mErrorList);
968 log.trace("Validating a NXDOMAIN response");
969 validateNameErrorResponse(message, key_rrset);
974 log.trace("Validating a CNAME response");
975 validateCNAMEResponse(message, key_rrset);
980 log.trace("Validating a positive ANY response");
981 validateAnyResponse(message, key_rrset);
986 log.error("unhandled response subtype: " + subtype);
989 return message.getSecurityStatus().getStatus();
992 public byte validateMessage(Message message, String zone)
993 throws TextParseException {
994 SMessage sm = new SMessage(message);
995 Name z = Name.fromString(zone);
997 return validateMessage(sm, z);
1000 public byte validateMessage(byte[] messagebytes, String zone)
1001 throws IOException {
1002 Message message = new Message(messagebytes);
1003 return validateMessage(message, zone);
1006 public byte validateMessage(String b64messagebytes, String zone)
1007 throws IOException {
1008 byte[] messagebytes = base64.fromString(b64messagebytes);
1009 return validateMessage(messagebytes, zone);
1012 public List<String> listTrustedKeys() {
1013 return mTrustedKeys.listTrustAnchors();
1016 public List<String> getErrorList() {