MCPcopy Create free account
hub / github.com/DeNA/PacketProxy / generate

Method generate

src/main/java/core/org/xbill/DNS/TSIG.java:273–341  ·  view source on GitHub ↗

Generates a TSIG record with a specific error for a message that has been rendered. @param m The message @param b The rendered message @param error The error @param old If this message is a response, the TSIG from the request @return The TSIG record to be added to the message

(Message m, byte [] b, int error, TSIGRecord old)

Source from the content-addressed store, hash-verified

271 * @return The TSIG record to be added to the message
272 */
273public TSIGRecord
274generate(Message m, byte [] b, int error, TSIGRecord old) {
275 Date timeSigned;
276 if (error != Rcode.BADTIME)
277 timeSigned = new Date();
278 else
279 timeSigned = old.getTimeSigned();
280 int fudge;
281 boolean signing = false;
282 if (error == Rcode.NOERROR || error == Rcode.BADTIME) {
283 signing = true;
284 hmac.reset();
285 }
286
287 fudge = Options.intValue("tsigfudge");
288 if (fudge < 0 || fudge > 0x7FFF)
289 fudge = FUDGE;
290
291 if (old != null) {
292 DNSOutput out = new DNSOutput();
293 out.writeU16(old.getSignature().length);
294 if (signing) {
295 hmac.update(out.toByteArray());
296 hmac.update(old.getSignature());
297 }
298 }
299
300 /* Digest the message */
301 if (signing)
302 hmac.update(b);
303
304 DNSOutput out = new DNSOutput();
305 name.toWireCanonical(out);
306 out.writeU16(DClass.ANY); /* class */
307 out.writeU32(0); /* ttl */
308 alg.toWireCanonical(out);
309 long time = timeSigned.getTime() / 1000;
310 int timeHigh = (int) (time >> 32);
311 long timeLow = (time & 0xFFFFFFFFL);
312 out.writeU16(timeHigh);
313 out.writeU32(timeLow);
314 out.writeU16(fudge);
315
316 out.writeU16(error);
317 out.writeU16(0); /* No other data */
318
319 if (signing)
320 hmac.update(out.toByteArray());
321
322 byte [] signature;
323 if (signing)
324 signature = hmac.doFinal();
325 else
326 signature = new byte[0];
327
328 byte [] other = null;
329 if (error == Rcode.BADTIME) {
330 out = new DNSOutput();

Callers 2

applyMethod · 0.95
toWireMethod · 0.45

Calls 11

intValueMethod · 0.95
writeU16Method · 0.95
toByteArrayMethod · 0.95
writeU32Method · 0.95
getIDMethod · 0.80
getTimeSignedMethod · 0.45
resetMethod · 0.45
getSignatureMethod · 0.45
updateMethod · 0.45
toWireCanonicalMethod · 0.45
getHeaderMethod · 0.45

Tested by

no test coverage detected