/** * Returns the OPT record from the ADDITIONAL section, if one is present. * @see OPTRecord * @see Section */ public OPTRecord getOPT() { Record [] additional = getSectionArray(Section.ADDITIONAL); for (int i = 0; i < additional.length; i++) if (additional[i] instanceof OPTRecord) return (OPTRecord) additional[i]; return null; }
/** * Returns the OPT record from the ADDITIONAL section, if one is present. * @see OPTRecord * @see Section */ public OPTRecord getOPT() { Record [] additional = getSectionArray(Section.ADDITIONAL); for (int i = 0; i < additional.length; i++) if (additional[i] instanceof OPTRecord) return (OPTRecord) additional[i]; return null; }
/** * Returns the OPT record from the ADDITIONAL section, if one is present. * @see OPTRecord * @see Section */ public OPTRecord getOPT() { Record [] additional = getSectionArray(Section.ADDITIONAL); for (int i = 0; i < additional.length; i++) if (additional[i] instanceof OPTRecord) return (OPTRecord) additional[i]; return null; }
/** * Returns the OPT record from the ADDITIONAL section, if one is present. * @see OPTRecord * @see Section */ public OPTRecord getOPT() { Record [] additional = getSectionArray(Section.ADDITIONAL); for (int i = 0; i < additional.length; i++) if (additional[i] instanceof OPTRecord) return (OPTRecord) additional[i]; return null; }
public static Record[] extractRecords(final Message message, final int... sections) { Record[] records = EMPTY_RECORDS; for (int section : sections) { Record[] tempRecords = message.getSectionArray(section); if ((tempRecords != null) && (tempRecords.length > 0)) { int size = records.length + tempRecords.length; Record[] newRecords = new Record[size]; System.arraycopy(records, 0, newRecords, 0, records.length); System.arraycopy(tempRecords, 0, newRecords, records.length, tempRecords.length); records = newRecords; } } return records; }
/** * Converts the given section of the Message to a String. * @see Section */ public String sectionToString(int i) { if (i > 3) return null; StringBuffer sb = new StringBuffer(); Record [] records = getSectionArray(i); for (int j = 0; j < records.length; j++) { Record rec = records[j]; if (i == Section.QUESTION) { sb.append(";;\t" + rec.name); sb.append(", type = " + Type.string(rec.type)); sb.append(", class = " + DClass.string(rec.dclass)); } else sb.append(rec); sb.append("\n"); } return sb.toString(); }
/** * Converts the given section of the Message to a String. * @see Section */ public String sectionToString(int i) { if (i > 3) return null; StringBuffer sb = new StringBuffer(); Record [] records = getSectionArray(i); for (int j = 0; j < records.length; j++) { Record rec = records[j]; if (i == Section.QUESTION) { sb.append(";;\t" + rec.name); sb.append(", type = " + Type.string(rec.type)); sb.append(", class = " + DClass.string(rec.dclass)); } else sb.append(rec); sb.append("\n"); } return sb.toString(); }
private void addAdditional2(Message response, int section, int flags) { Record [] records = response.getSectionArray(section); for (int i = 0; i < records.length; i++) { Record r = records[i]; Name glueName = r.getAdditionalName(); if (glueName != null) addGlue(response, glueName, flags); } }
private void addAdditional2(final Message response, final int section, final int flags) { final Record[] records = response.getSectionArray(section); for (int i = 0; i < records.length; i++) { final Record r = records[i]; final Name glueName = r.getAdditionalName(); if (glueName != null) addGlue(response, glueName, flags); } }
private void addAdditional2(Message response, int section, int flags) { final Record[] records = response.getSectionArray(section); for (int i = 0; i < records.length; i++) { final Record r = records[i]; final Name glueName = r.getAdditionalName(); if (glueName != null) { addGlue(response, glueName, flags); } } }
private void addAdditional2(Message response, int section, int flags) { Record[] records = response.getSectionArray(section); for (Record r : records) { Name glueName = r.getAdditionalName(); if (glueName != null) { addGlue(response, glueName, flags); } } }
assertArrayEquals(new Record[] {}, responseMsg.getSectionArray(Section.ANSWER)); assertNotEquals(0, responseMsg.getSectionArray(Section.AUTHORITY).length); assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0] instanceof SOARecord); assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0].getTTL() > 0);
/** * Add additional information to a DNS response section if a glue name is * specified. * * @param response the response message. * @param section the section of the response (e.g. ANSWER, AUTHORITY) * @param flags the flags. */ private void addAdditional2(Message response, int section, int flags) { Record[] records = response.getSectionArray(section); for (int i = 0; i < records.length; i++) { Record r = records[i]; Name glueName = r.getAdditionalName(); if (glueName != null) { addGlue(response, glueName, flags); } } }
static void doAXFR(Message response) throws IOException { System.out.println("; java dig 0.0 <> " + name + " axfr"); if (response.isSigned()) { System.out.print(";; TSIG "); if (response.isVerified()) System.out.println("ok"); else System.out.println("failed"); } if (response.getRcode() != Rcode.NOERROR) { System.out.println(response); return; } Record [] records = response.getSectionArray(Section.ANSWER); for (int i = 0; i < records.length; i++) System.out.println(records[i]); System.out.print(";; done ("); System.out.print(response.getHeader().getCount(Section.ANSWER)); System.out.print(" records, "); System.out.print(response.getHeader().getCount(Section.ADDITIONAL)); System.out.println(" additional)"); }
assertArrayEquals(new Record[] {}, responseMsg.getSectionArray(Section.ANSWER)); assertNotEquals(0, responseMsg.getSectionArray(Section.AUTHORITY).length); assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0] instanceof SOARecord); assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0].getTTL() > 0);
/** * Verify a message using SIG(0). * @param message The message to be signed * @param b An array containing the message in unparsed form. This is * necessary since SIG(0) signs the message in wire format, and we can't * recreate the exact wire format (with the same name compression). * @param key The KEY record to verify the signature with. * @param previous If this message is a response, the SIG(0) from the query */ public static void verifyMessage(Message message, byte [] b, KEYRecord key, SIGRecord previous) throws DNSSEC.DNSSECException { SIGRecord sig = null; Record [] additional = message.getSectionArray(Section.ADDITIONAL); for (int i = 0; i < additional.length; i++) { if (additional[i].getType() != Type.SIG) continue; if (((SIGRecord) additional[i]).getTypeCovered() != 0) continue; sig = (SIGRecord) additional[i]; break; } DNSSEC.verifyMessage(message, b, sig, previous, key); }
protected Message convertUpdateToQueryResponse(final Message update) { Message m = new Message(); Header h = m.getHeader(); h.setOpcode(Opcode.QUERY); h.setFlag(Flags.AA); h.setFlag(Flags.QR); Record[] records = update.getSectionArray(Section.UPDATE); for (int index = 0; index < records.length; index++ ) { m.addRecord(records[index], Section.ANSWER); } records = update.getSectionArray(Section.ADDITIONAL); for (int index = 0; index < records.length; index++ ) { m.addRecord(records[index], Section.ADDITIONAL); } return m; }
/** * Add the NXT record to the authority * section of the response. * * @param response the response message. */ private void addNXT(Message response, int flags) throws DNSSEC.DNSSECException, IOException { Record nxtRecord = getNXTRecord( response.getSectionArray(Section.QUESTION)[0]); Zone zone = findBestZone(nxtRecord.getName()); addRecordCommand.exec(zone, nxtRecord); RRset nxtRR = zone.findExactMatch(nxtRecord.getName(), Type.NXT); addRRset(nxtRecord.getName(), response, nxtRR, Section.AUTHORITY, flags); removeRecordCommand.exec(zone, nxtRecord); }
public static String reverseDns(String hostIp) throws IOException { Resolver res = new ExtendedResolver(); // set the timeout, defaults to 200 milliseconds int timeout = ConfigurationManager.getIntProperty("solr-statistics", "resolver.timeout", 200); res.setTimeout(0, timeout); Name name = ReverseMap.fromAddress(hostIp); int type = Type.PTR; int dclass = DClass.IN; Record rec = Record.newRecord(name, type, dclass); Message query = Message.newQuery(rec); Message response = res.send(query); Record[] answers = response.getSectionArray(Section.ANSWER); if (answers.length == 0) { return hostIp; } else { return answers[0].rdataToString(); } } }
Record[] assertDNSQueryNotNull(String lookup, int type, int answerCount) throws IOException { Name name = Name.fromString(lookup); Record question = Record.newRecord(name, type, DClass.IN); Message query = Message.newQuery(question); OPTRecord optRecord = new OPTRecord(4096, 0, 0, Flags.DO, null); query.addRecord(optRecord, Section.ADDITIONAL); byte[] responseBytes = getRegistryDNS().generateReply(query, null); Message response = new Message(responseBytes); assertEquals("not successful", Rcode.NOERROR, response.getRcode()); assertNotNull("Null response", response); assertEquals("Questions do not match", query.getQuestion(), response.getQuestion()); Record[] recs = response.getSectionArray(Section.ANSWER); assertEquals(answerCount, recs.length); assertEquals(recs[0].getType(), type); return recs; }