@@ -128,7 +128,11 @@ get_connection_state_by_epoch(Epoch, #{current_read := #{epoch := Epoch} = Curre
128128 Current ;
129129get_connection_state_by_epoch (Epoch , #{saved_read := #{epoch := Epoch } = Saved },
130130 read ) ->
131- Saved .
131+ Saved ;
132+ % % This can be an attack on read side so return undefined so we can trigger alert
133+ % % on write side this would be a programming error, so let it crash.
134+ get_connection_state_by_epoch (_ , _ , read ) ->
135+ undefined .
132136
133137set_connection_state_by_epoch (WriteState , Epoch , #{current_write := #{epoch := Epoch }} = States ,
134138 write ) ->
@@ -253,10 +257,13 @@ encode_plain_text(Type, Version, Epoch, Data, ConnectionStates) ->
253257% % Decoding
254258% %====================================================================
255259
256- decode_cipher_text (# ssl_tls {epoch = Epoch } = CipherText , ConnnectionStates0 ) ->
257- ReadState = get_connection_state_by_epoch (Epoch , ConnnectionStates0 , read ),
258- decode_cipher_text (CipherText , ReadState , ConnnectionStates0 ).
259-
260+ decode_cipher_text (# ssl_tls {epoch = Epoch } = CipherText , ConnectionStates0 ) ->
261+ case get_connection_state_by_epoch (Epoch , ConnectionStates0 , read ) of
262+ undefined ->
263+ ? ALERT_REC (? FATAL , ? BAD_RECORD_MAC );
264+ ReadState ->
265+ decode_cipher_text (CipherText , ReadState , ConnectionStates0 )
266+ end .
260267
261268% %====================================================================
262269% % Protocol version handling
0 commit comments