org.xbill.DNS.Flags Java Examples

The following examples show how to use org.xbill.DNS.Flags. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleDoTResolver.java    From androdns with Apache License 2.0 6 votes vote down vote up
private Message
sendAXFR(Message query) throws IOException {
    Name qname = query.getQuestion().getName();
    ZoneTransferIn xfrin = ZoneTransferIn.newAXFR(qname, address, tsig);
    xfrin.setTimeout((int)(getTimeout() / 1000));
    xfrin.setLocalAddress(localAddress);
    try {
        xfrin.run();
    }
    catch (ZoneTransferException e) {
        throw new WireParseException(e.getMessage());
    }
    List records = xfrin.getAXFR();
    Message response = new Message(query.getHeader().getID());
    response.getHeader().setFlag(Flags.AA);
    response.getHeader().setFlag(Flags.QR);
    response.addRecord(query.getQuestion(), Section.QUESTION);
    Iterator it = records.iterator();
    while (it.hasNext())
        response.addRecord((Record)it.next(), Section.ANSWER);
    return response;
}
 
Example #2
Source File: OpenAliasHelper.java    From xmrwallet with Apache License 2.0 5 votes vote down vote up
@Override
protected Boolean doInBackground(String... args) {
    //main();
    if (args.length != 1) return false;
    String name = args[0];
    if ((name == null) || (name.isEmpty()))
        return false; //pointless trying to lookup nothing
    Timber.d("Resolving %s", name);
    try {
        SimpleResolver sr = new SimpleResolver(DNSSEC_SERVERS[new Random().nextInt(DNSSEC_SERVERS.length)]);
        ValidatingResolver vr = new ValidatingResolver(sr);
        vr.setTimeout(0, DNS_LOOKUP_TIMEOUT);
        vr.loadTrustAnchors(new ByteArrayInputStream(ROOT.getBytes("ASCII")));
        Record qr = Record.newRecord(Name.fromConstantString(name + "."), Type.TXT, DClass.IN);
        Message response = vr.send(Message.newQuery(qr));
        final int rcode = response.getRcode();
        if (rcode != Rcode.NOERROR) {
            Timber.i("Rcode: %s", Rcode.string(rcode));
            for (RRset set : response.getSectionRRsets(Section.ADDITIONAL)) {
                if (set.getName().equals(Name.root) && set.getType() == Type.TXT
                        && set.getDClass() == ValidatingResolver.VALIDATION_REASON_QCLASS) {
                    Timber.i("Reason:  %s", ((TXTRecord) set.first()).getStrings().get(0));
                }
            }
            return false;
        } else {
            dnssec = response.getHeader().getFlag(Flags.AD);
            for (Record record : response.getSectionArray(Section.ANSWER)) {
                if (record.getType() == Type.TXT) {
                    txts.addAll(((TXTRecord) record).getStrings());
                }
            }
        }
    } catch (IOException | IllegalArgumentException ex) {
        return false;
    }
    return true;
}
 
Example #3
Source File: DNSFormActivity.java    From androdns with Apache License 2.0 5 votes vote down vote up
private void setAnswerFlagsToState(Header header, AnswerScreenState state) {
    state.flag_AA = header.getFlag(Flags.AA);
    state.flag_AD = header.getFlag(Flags.AD);
    state.flag_TC = header.getFlag(Flags.TC);
    state.flag_RD = header.getFlag(Flags.RD);
    state.flag_RA = header.getFlag(Flags.RA);
    state.flag_CD = header.getFlag(Flags.CD);
}
 
Example #4
Source File: DnsUpdateWriterTest.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private Message messageWithResponseCode(int responseCode) {
  Message message = new Message();
  message.getHeader().setOpcode(Opcode.UPDATE);
  message.getHeader().setFlag(Flags.QR);
  message.getHeader().setRcode(responseCode);
  return message;
}
 
Example #5
Source File: DnsMessageTransportTest.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private Message responseMessageWithCode(Message query, int responseCode) {
  Message message = new Message(query.getHeader().getID());
  message.getHeader().setOpcode(query.getHeader().getOpcode());
  message.getHeader().setFlag(Flags.QR);
  message.getHeader().setRcode(responseCode);
  return message;
}
 
Example #6
Source File: jnamed.java    From dnsjava with BSD 2-Clause "Simplified" License 4 votes vote down vote up
byte[] generateReply(Message query, byte[] in, Socket s) {
  Header header;
  boolean badversion;
  int maxLength;
  int flags = 0;

  header = query.getHeader();
  if (header.getFlag(Flags.QR)) {
    return null;
  }
  if (header.getRcode() != Rcode.NOERROR) {
    return errorMessage(query, Rcode.FORMERR);
  }
  if (header.getOpcode() != Opcode.QUERY) {
    return errorMessage(query, Rcode.NOTIMP);
  }

  Record queryRecord = query.getQuestion();

  TSIGRecord queryTSIG = query.getTSIG();
  TSIG tsig = null;
  if (queryTSIG != null) {
    tsig = TSIGs.get(queryTSIG.getName());
    if (tsig == null || tsig.verify(query, in, null) != Rcode.NOERROR) {
      return formerrMessage(in);
    }
  }

  OPTRecord queryOPT = query.getOPT();
  if (s != null) {
    maxLength = 65535;
  } else if (queryOPT != null) {
    maxLength = Math.max(queryOPT.getPayloadSize(), 512);
  } else {
    maxLength = 512;
  }

  if (queryOPT != null && (queryOPT.getFlags() & ExtendedFlags.DO) != 0) {
    flags = FLAG_DNSSECOK;
  }

  Message response = new Message(query.getHeader().getID());
  response.getHeader().setFlag(Flags.QR);
  if (query.getHeader().getFlag(Flags.RD)) {
    response.getHeader().setFlag(Flags.RD);
  }
  response.addRecord(queryRecord, Section.QUESTION);

  Name name = queryRecord.getName();
  int type = queryRecord.getType();
  int dclass = queryRecord.getDClass();
  if (type == Type.AXFR && s != null) {
    return doAXFR(name, query, tsig, queryTSIG, s);
  }
  if (!Type.isRR(type) && type != Type.ANY) {
    return errorMessage(query, Rcode.NOTIMP);
  }

  byte rcode = addAnswer(response, name, type, dclass, 0, flags);
  if (rcode != Rcode.NOERROR && rcode != Rcode.NXDOMAIN) {
    return errorMessage(query, rcode);
  }

  addAdditional(response, flags);

  if (queryOPT != null) {
    int optflags = (flags == FLAG_DNSSECOK) ? ExtendedFlags.DO : 0;
    OPTRecord opt = new OPTRecord((short) 4096, rcode, (byte) 0, optflags);
    response.addRecord(opt, Section.ADDITIONAL);
  }

  response.setTSIG(tsig, Rcode.NOERROR, queryTSIG);
  return response.toWire(maxLength);
}