Verifies a TSIG record on an incoming message that is part of a multiple message response. TSIG records must be present on the first and last messages, and at least every 100 records in between. After calling this routine, Message.isVerified() may be called on this message. @param m The message @par
(Message m, byte [] b)
| 575 | * @see Rcode |
| 576 | */ |
| 577 | public int |
| 578 | verify(Message m, byte [] b) { |
| 579 | TSIGRecord tsig = m.getTSIG(); |
| 580 | |
| 581 | nresponses++; |
| 582 | |
| 583 | if (nresponses == 1) { |
| 584 | int result = key.verify(m, b, lastTSIG); |
| 585 | if (result == Rcode.NOERROR) { |
| 586 | byte [] signature = tsig.getSignature(); |
| 587 | DNSOutput out = new DNSOutput(); |
| 588 | out.writeU16(signature.length); |
| 589 | verifier.update(out.toByteArray()); |
| 590 | verifier.update(signature); |
| 591 | } |
| 592 | lastTSIG = tsig; |
| 593 | return result; |
| 594 | } |
| 595 | |
| 596 | if (tsig != null) |
| 597 | m.getHeader().decCount(Section.ADDITIONAL); |
| 598 | byte [] header = m.getHeader().toWire(); |
| 599 | if (tsig != null) |
| 600 | m.getHeader().incCount(Section.ADDITIONAL); |
| 601 | verifier.update(header); |
| 602 | |
| 603 | int len; |
| 604 | if (tsig == null) |
| 605 | len = b.length - header.length; |
| 606 | else |
| 607 | len = m.tsigstart - header.length; |
| 608 | verifier.update(b, header.length, len); |
| 609 | |
| 610 | if (tsig != null) { |
| 611 | lastsigned = nresponses; |
| 612 | lastTSIG = tsig; |
| 613 | } |
| 614 | else { |
| 615 | boolean required = (nresponses - lastsigned >= 100); |
| 616 | if (required) { |
| 617 | m.tsigState = Message.TSIG_FAILED; |
| 618 | return Rcode.FORMERR; |
| 619 | } else { |
| 620 | m.tsigState = Message.TSIG_INTERMEDIATE; |
| 621 | return Rcode.NOERROR; |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | if (!tsig.getName().equals(key.name) || |
| 626 | !tsig.getAlgorithm().equals(key.alg)) |
| 627 | { |
| 628 | if (Options.check("verbose")) |
| 629 | System.err.println("BADKEY failure"); |
| 630 | m.tsigState = Message.TSIG_FAILED; |
| 631 | return Rcode.BADKEY; |
| 632 | } |
| 633 | |
| 634 | DNSOutput out = new DNSOutput(); |
no test coverage detected