private boolean checkSequenceNumber ( MAC mac , byte type ) throws IOException { /* * Don't bother to check the sequence number for error or * closed connections, or NULL MAC */ if ( connectionState >= cs_ERROR || mac == MAC . NULL ) { return false ; } /* * Conservatively, close the connection immediately when the * sequence number is close to overflow */ if ( mac . seqNumOverflow ( ) ) { /* * TLS protocols do not define a error alert for sequence * number overflow. We use handshake_failure error alert * for handshaking and bad_record_mac for other records. */ if ( debug != null && Debug . isOn ( "ssl" ) ) { System . out . println ( threadName ( ) + ", sequence number extremely close to overflow " + "(2^64-1 packets). Closing connection." ) ; } fatal ( Alerts . alert_handshake_failure , "sequence number overflow" ) ; return true ; // make the compiler happy } /* * Ask for renegotiation when need to renew sequence number. * * Don't bother to kickstart the renegotiation when the local is * asking for it. */ if ( ( type != Record . ct_handshake ) && mac . seqNumIsHuge ( ) ) { if ( debug != null && Debug . isOn ( "ssl" ) ) { System . out . println ( threadName ( ) + ", request renegotiation " + "to avoid sequence number overflow" ) ; } beginHandshake ( ) ; return true ; } return false ; }
Check the sequence number state