@@ -2499,9 +2499,13 @@ def _parse_kex_init(self, m):
24992499
25002500 # CVE mitigation: expect zeroed-out seqno anytime we are performing kex
25012501 # init phase, if strict mode was negotiated.
2502- if self .agreed_on_strict_kex and m .seqno != 0 :
2502+ if (
2503+ self .agreed_on_strict_kex
2504+ and not self .initial_kex_done
2505+ and m .seqno != 0
2506+ ):
25032507 raise MessageOrderError (
2504- f"Got nonzero seqno ( { m . seqno } ) during strict KEXINIT !"
2508+ "In strict-kex mode, but KEXINIT was not the first packet !"
25052509 )
25062510
25072511 # as a server, we pick the first item in the client's list that we
@@ -2703,13 +2707,27 @@ def _activate_inbound(self):
27032707 ):
27042708 self ._log (DEBUG , "Switching on inbound compression ..." )
27052709 self .packetizer .set_inbound_compressor (compress_in ())
2710+ # Reset inbound sequence number if strict mode.
2711+ if self .agreed_on_strict_kex :
2712+ self ._log (
2713+ DEBUG ,
2714+ f"Resetting inbound seqno after NEWKEYS due to strict mode" ,
2715+ )
2716+ self .packetizer .reset_seqno_in ()
27062717
27072718 def _activate_outbound (self ):
27082719 """switch on newly negotiated encryption parameters for
27092720 outbound traffic"""
27102721 m = Message ()
27112722 m .add_byte (cMSG_NEWKEYS )
27122723 self ._send_message (m )
2724+ # Reset outbound sequence number if strict mode.
2725+ if self .agreed_on_strict_kex :
2726+ self ._log (
2727+ DEBUG ,
2728+ f"Resetting outbound sequence number after NEWKEYS due to strict mode" ,
2729+ )
2730+ self .packetizer .reset_seqno_out ()
27132731 block_size = self ._cipher_info [self .local_cipher ]["block-size" ]
27142732 if self .server_mode :
27152733 IV_out = self ._compute_key ("B" , block_size )
0 commit comments