Exemplo n.º 1
0
 /** Converts the RRSIG/SIG Record to a String */
 public String rdataToString() {
   StringBuffer sb = new StringBuffer();
   if (signature != null) {
     sb.append(Type.string(covered));
     sb.append(" ");
     sb.append(alg);
     sb.append(" ");
     sb.append(labels);
     sb.append(" ");
     sb.append(origttl);
     sb.append(" ");
     if (Options.check("multiline")) sb.append("(\n\t");
     sb.append(FormattedTime.format(expire));
     sb.append(" ");
     sb.append(FormattedTime.format(timeSigned));
     sb.append(" ");
     sb.append(footprint);
     sb.append(" ");
     sb.append(signer);
     if (Options.check("multiline")) {
       sb.append("\n");
       sb.append(base64.formatString(signature, 64, "\t", true));
     } else {
       sb.append(" ");
       sb.append(base64.toString(signature));
     }
   }
   return sb.toString();
 }
Exemplo n.º 2
0
 /** Converts a Record into a String representation */
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(name);
   if (sb.length() < 8) sb.append("\t");
   if (sb.length() < 16) sb.append("\t");
   sb.append("\t");
   if (Options.check("BINDTTL")) sb.append(TTL.format(ttl));
   else sb.append(ttl);
   sb.append("\t");
   if (dclass != DClass.IN || !Options.check("noPrintIN")) {
     sb.append(DClass.string(dclass));
     sb.append("\t");
   }
   sb.append(Type.string(type));
   String rdata = rrToString();
   if (!rdata.equals("")) {
     sb.append("\t");
     sb.append(rdata);
   }
   return sb.toString();
 }
Exemplo n.º 3
0
 /** Converts rdata to a String */
 String rrToString() {
   StringBuffer sb = new StringBuffer();
   sb.append(certType);
   sb.append(" ");
   sb.append(keyTag);
   sb.append(" ");
   sb.append(alg);
   if (cert != null) {
     if (Options.check("multiline")) {
       sb.append(" (\n");
       sb.append(Base64.formatString(cert, 64, "\t", true));
     } else {
       sb.append(" ");
       sb.append(Base64.toString(cert));
     }
   }
   return sb.toString();
 }
Exemplo n.º 4
0
 /** Converts a KEY/DNSKEY record into a PublicKey */
 static PublicKey parseRecord(int alg, byte[] data) {
   DataByteInputStream dbs = new DataByteInputStream(data);
   try {
     switch (alg) {
       case DNSSEC.RSAMD5:
       case DNSSEC.RSASHA1:
         return parseRSA(dbs);
       case DNSSEC.DH:
         return parseDH(dbs);
       case DNSSEC.DSA:
         return parseDSA(dbs);
       default:
         return null;
     }
   } catch (IOException e) {
     if (Options.check("verboseexceptions")) System.err.println(e);
     return null;
   }
 }
Exemplo n.º 5
0
  private static final Record getTypedObject(int type) {
    if (type < 0 || type > knownRecords.length) return unknownRecord.getObject();
    if (knownRecords[type] != null) return knownRecords[type];

    /* Construct the class name by putting the type before "Record". */
    String s =
        Record.class.getPackage().getName() + "." + Type.string(type).replace('-', '_') + "Record";
    try {
      Class c = Class.forName(s);
      Constructor m = c.getDeclaredConstructor(emptyClassArray);
      knownRecords[type] = (Record) m.newInstance(emptyObjectArray);
    } catch (ClassNotFoundException e) {
      /* This is normal; do nothing */
    } catch (Exception e) {
      if (Options.check("verbose")) System.err.println(e);
    }
    if (knownRecords[type] == null) knownRecords[type] = unknownRecord.getObject();
    return knownRecords[type];
  }
Exemplo n.º 6
0
 /** Converts to a String */
 public String toString() {
   StringBuffer sb = toStringNoData();
   if (key != null || (flags & (FLAG_NOKEY)) == (FLAG_NOKEY)) {
     if (!Options.check("nohex")) {
       sb.append("0x");
       sb.append(Integer.toHexString(flags & 0xFFFF));
     } else sb.append(flags & 0xFFFF);
     sb.append(" ");
     sb.append(proto);
     sb.append(" ");
     sb.append(alg);
     if (key != null) {
       sb.append(" (\n");
       sb.append(base64.formatString(key, 64, "\t", true));
       sb.append(" ; key_tag= ");
       sb.append(getFootprint());
     }
   }
   return sb.toString();
 }
Exemplo n.º 7
0
  /**
   * Looks up Records in the Cache. This follows CNAMEs and handles negatively cached data.
   *
   * @param name The name to look up
   * @param type The type to look up
   * @param minCred The minimum acceptable credibility
   * @return A SetResponse object
   * @see SetResponse
   * @see Credibility
   */
  public SetResponse lookupRecords(Name name, short type, byte minCred) {
    SetResponse cr = null;
    boolean verbose = Options.check("verbosecache");
    Object o = lookup(name, type);

    if (verbose) logLookup(name, type, "Starting");

    if (o == null || o == NXRRSET) {
      /*
       * The name exists, but the type was not found.  Or, the
       * name does not exist and no parent does either.  Punt.
       */
      if (verbose) logLookup(name, type, "no information found");
      return SetResponse.ofType(SetResponse.UNKNOWN);
    }

    Object[] objects;
    if (o instanceof Element) objects = new Object[] {o};
    else objects = (Object[]) o;

    int nelements = 0;
    for (int i = 0; i < objects.length; i++) {
      Element element = (Element) objects[i];
      if (element.expired()) {
        if (verbose) {
          logLookup(name, type, element.toString());
          logLookup(name, type, "expired: ignoring");
        }
        removeSet(name, type, element);
        objects[i] = null;
      } else if (element.credibility < minCred) {
        if (verbose) {
          logLookup(name, type, element.toString());
          logLookup(name, type, "not credible: ignoring");
        }
        objects[i] = null;
      } else {
        nelements++;
      }
    }
    if (nelements == 0) {
      /* We have data, but can't use it.  Punt. */
      if (verbose) logLookup(name, type, "no useful data found");
      return SetResponse.ofType(SetResponse.UNKNOWN);
    }

    /*
     * We have something at the name.  It could be the answer,
     * a CNAME, DNAME, or NS, or a negative cache entry.
     *
     * Ignore wildcards, since it's pretty unlikely that any will be
     * cached.  The occasional extra query is easily balanced by the
     * reduced number of lookups.
     */

    for (int i = 0; i < objects.length; i++) {
      if (objects[i] == null) continue;
      Element element = (Element) objects[i];
      if (verbose) logLookup(name, type, element.toString());
      RRset rrset = null;
      if (element instanceof PositiveElement) rrset = ((PositiveElement) element).rrset;

      /* Is this a negatively cached entry? */
      if (rrset == null) {
        /*
         * If this is an NXDOMAIN entry, return NXDOMAIN.
         */
        if (element.getType() == 0) {
          if (verbose) logLookup(name, type, "NXDOMAIN");
          return SetResponse.ofType(SetResponse.NXDOMAIN);
        }

        /*
         * If we're not looking for type ANY, return NXRRSET.
         * Otherwise ignore this.
         */
        if (type != Type.ANY) {
          if (verbose) logLookup(name, type, "NXRRSET");
          return SetResponse.ofType(SetResponse.NXRRSET);
        } else {
          if (verbose) logLookup(name, type, "ANY query; " + "ignoring NXRRSET");
          continue;
        }
      }

      short rtype = rrset.getType();
      Name rname = rrset.getName();
      if (name.equals(rname)) {
        if (type != Type.CNAME && type != Type.ANY && rtype == Type.CNAME) {
          if (verbose) logLookup(name, type, "cname");
          return new SetResponse(SetResponse.CNAME, rrset);
        } else if (type != Type.NS && type != Type.ANY && rtype == Type.NS) {
          if (verbose) logLookup(name, type, "exact delegation");
          return new SetResponse(SetResponse.DELEGATION, rrset);
        } else {
          if (verbose) logLookup(name, type, "exact match");
          if (cr == null) cr = new SetResponse(SetResponse.SUCCESSFUL);
          cr.addRRset(rrset);
        }
      } else if (name.subdomain(rname)) {
        if (rtype == Type.DNAME) {
          if (verbose) logLookup(name, type, "dname");
          return new SetResponse(SetResponse.DNAME, rrset);
        } else if (rtype == Type.NS) {
          if (verbose) logLookup(name, type, "parent delegation");
          return new SetResponse(SetResponse.DELEGATION, rrset);
        } else {
          if (verbose)
            logLookup(name, type, "ignoring rrset (" + rname + " " + Type.string(rtype) + ")");
        }
      } else {
        if (verbose)
          logLookup(name, type, "ignoring rrset (" + rname + " " + Type.string(rtype) + ")");
      }
    }

    /*
     * As far as I can tell, the only legitimate time cr will be null is
     * if we queried for ANY and only saw negative responses, but not an
     * NXDOMAIN.  Return UNKNOWN.
     */
    if (cr == null && type == Type.ANY) return SetResponse.ofType(SetResponse.UNKNOWN);
    else if (cr == null)
      throw new IllegalStateException(
          "looking up (" + name + " " + Type.string(type) + "): " + "cr == null.");
    return cr;
  }