예제 #1
0
파일: Zone.java 프로젝트: lemmy/dnsjava
 private void validate() throws IOException {
   RRset rrset = (RRset) findExactSet(origin, Type.SOA);
   if (rrset == null || rrset.size() != 1)
     throw new IOException(origin + ": exactly 1 SOA must be specified");
   Iterator it = rrset.rrs();
   SOA = (SOARecord) it.next();
   NS = (RRset) findExactSet(origin, Type.NS);
   if (NS == null) throw new IOException(origin + ": no NS set specified");
 }
예제 #2
0
 private void nodeToString(StringBuffer sb, Object node) {
   RRset[] sets = allRRsets(node);
   for (int i = 0; i < sets.length; i++) {
     RRset rrset = sets[i];
     Iterator it = rrset.rrs();
     while (it.hasNext()) sb.append(it.next() + "\n");
     it = rrset.sigs();
     while (it.hasNext()) sb.append(it.next() + "\n");
   }
 }
예제 #3
0
  private void validate() throws IOException {
    originNode = exactName(origin);
    if (originNode == null) throw new IOException(origin + ": no data specified");

    RRset rrset = oneRRset(originNode, Type.SOA);
    if (rrset == null || rrset.size() != 1)
      throw new IOException(origin + ": exactly 1 SOA must be specified");
    Iterator it = rrset.rrs();
    SOA = (SOARecord) it.next();

    NS = oneRRset(originNode, Type.NS);
    if (NS == null) throw new IOException(origin + ": no NS set specified");
  }
예제 #4
0
파일: Zone.java 프로젝트: lemmy/dnsjava
 /** Returns the contents of a Zone in master file format. */
 public String toMasterFile() {
   Iterator znames = names();
   StringBuffer sb = new StringBuffer();
   while (znames.hasNext()) {
     Name name = (Name) znames.next();
     TypeMap tm = findName(name);
     Object[] sets = tm.getAll();
     for (int i = 0; i < sets.length; i++) {
       RRset rrset = (RRset) sets[i];
       Iterator it = rrset.rrs();
       while (it.hasNext()) sb.append(it.next() + "\n");
       it = rrset.sigs();
       while (it.hasNext()) sb.append(it.next() + "\n");
     }
   }
   return sb.toString();
 }
예제 #5
0
파일: DNSSEC.java 프로젝트: lemmy/dnsjava
  /**
   * Creates an array containing fields of the SIG record and the RRsets to be signed/verified.
   *
   * @param sig The SIG record used to sign/verify the rrset.
   * @param rrset The data to be signed/verified.
   * @return The data to be cryptographically signed or verified.
   */
  public static byte[] digestRRset(SIGRecord sig, RRset rrset) {
    DataByteOutputStream out = new DataByteOutputStream();
    digestSIG(out, sig);

    int size = rrset.size();
    byte[][] records = new byte[size][];

    Iterator it = rrset.rrs();
    Name name = rrset.getName();
    Name wild = null;
    if (name.labels() > sig.getLabels()) wild = name.wild(name.labels() - sig.getLabels());
    while (it.hasNext()) {
      Record rec = (Record) it.next();
      if (wild != null) rec = rec.withName(wild);
      records[--size] = rec.toWireCanonical();
    }
    Arrays.sort(records);
    for (int i = 0; i < records.length; i++) out.writeArray(records[i]);
    return out.toByteArray();
  }
예제 #6
0
파일: dns.java 프로젝트: lemmy/dnsjava
  public static Record[] getRecords(String namestr, short type, short dclass, byte cred) {
    Message query;
    Message response;
    Record question;
    Record[] answers;
    int answerCount = 0, i = 0;
    Enumeration e;
    Name name = new Name(namestr);

    /*System.out.println("lookup of " + name + " " + Type.string(type));*/
    if (!Type.isRR(type) && type != Type.ANY) return null;

    if (res == null) {
      try {
        eres = new ExtendedResolver();
      } catch (UnknownHostException uhe) {
        System.out.println("Failed to initialize resolver");
        System.exit(-1);
      }
    }
    if (cache == null) cache = new Cache();

    CacheResponse cached = cache.lookupRecords(name, type, dclass, cred);
    /*System.out.println(cached);*/
    if (cached.isSuccessful()) {
      RRset rrset = cached.answer();
      answerCount = rrset.size();
      e = rrset.rrs();
    } else if (cached.isNegative()) {
      answerCount = 0;
      e = null;
    } else {
      question = Record.newRecord(name, type, dclass);
      query = Message.newQuery(question);

      if (res != null) response = res.send(query);
      else response = eres.send(query);

      short rcode = response.getHeader().getRcode();
      if (rcode == Rcode.NOERROR || rcode == Rcode.NXDOMAIN) cache.addMessage(response);

      if (rcode != Rcode.NOERROR) return null;

      e = response.getSection(Section.ANSWER);
      while (e.hasMoreElements()) {
        Record r = (Record) e.nextElement();
        if (matchType(r.getType(), type)) answerCount++;
      }

      e = response.getSection(Section.ANSWER);
    }

    if (answerCount == 0) return null;

    answers = new Record[answerCount];

    while (e.hasMoreElements()) {
      Record r = (Record) e.nextElement();
      if (matchType(r.getType(), type)) answers[i++] = r;
    }

    return answers;
  }