public TSIGRecord generate ( Message m , byte [ ] b , int error , TSIGRecord old ) { Date timeSigned ; if ( error != Rcode . BADTIME ) timeSigned = new Date ( ) ; else timeSigned = old . getTimeSigned ( ) ; int fudge ; HMAC hmac = null ; if ( error == Rcode . NOERROR || error == Rcode . BADTIME ) hmac = new HMAC ( digest , digestBlockLength , key ) ; fudge = Options . intValue ( "tsigfudge" ) ; if ( fudge < 0 || fudge > 0x7FFF ) fudge = FUDGE ; if ( old != null ) { DNSOutput out = new DNSOutput ( ) ; out . writeU16 ( old . getSignature ( ) . length ) ; if ( hmac != null ) { hmac . update ( out . toByteArray ( ) ) ; hmac . update ( old . getSignature ( ) ) ; } } /* Digest the message */ if ( hmac != null ) hmac . update ( b ) ; DNSOutput out = new DNSOutput ( ) ; name . toWireCanonical ( out ) ; out . writeU16 ( DClass . ANY ) ; /* class */ out . writeU32 ( 0 ) ; /* ttl */ alg . toWireCanonical ( out ) ; long time = timeSigned . getTime ( ) / 1000 ; int timeHigh = ( int ) ( time >> 32 ) ; long timeLow = ( time & 0xFFFFFFFF L ) ; out . writeU16 ( timeHigh ) ; out . writeU32 ( timeLow ) ; out . writeU16 ( fudge ) ; out . writeU16 ( error ) ; out . writeU16 ( 0 ) ; /* No other data */ if ( hmac != null ) hmac . update ( out . toByteArray ( ) ) ; byte [ ] signature ; if ( hmac != null ) signature = hmac . sign ( ) ; else signature = new byte [ 0 ] ; byte [ ] other = null ; if ( error == Rcode . BADTIME ) { out = new DNSOutput ( ) ; time = new Date ( ) . getTime ( ) / 1000 ; timeHigh = ( int ) ( time >> 32 ) ; timeLow = ( time & 0xFFFFFFFF L ) ; out . writeU16 ( timeHigh ) ; out . writeU32 ( timeLow ) ; other = out . toByteArray ( ) ; } return ( new TSIGRecord ( name , DClass . ANY , 0 , alg , timeSigned , fudge , signature , m . getHeader ( ) . getID ( ) , error , other ) ) ; }
Generates a TSIG record with a specific error for a message that has been rendered .