@@ -289,7 +289,7 @@ connection({call, From}, {application_data, AppData},
289289 send_application_data (Data , From , connection , StateData )
290290 end ;
291291connection ({call , From }, {post_handshake_data , HSData }, StateData ) ->
292- send_post_handshake_data (HSData , From , connection , StateData );
292+ send_post_handshake_data (HSData , From , connection , StateData , [{ reply , From , ok }] );
293293connection ({call , From }, {ack_alert , # alert {} = Alert }, StateData0 ) ->
294294 StateData = send_tls_alert (Alert , StateData0 ),
295295 {next_state , connection , StateData ,
@@ -340,7 +340,7 @@ connection({call, From}, get_application_traffic_secret, #data{env = #env{num_ke
340340connection (internal , {application_packets , From , Data }, StateData ) ->
341341 send_application_data (Data , From , connection , StateData );
342342connection (internal , {post_handshake_data , From , HSData }, StateData ) ->
343- send_post_handshake_data (HSData , From , connection , StateData );
343+ send_post_handshake_data (HSData , From , connection , StateData , [] );
344344connection (cast , # alert {} = Alert , StateData0 ) ->
345345 StateData = send_tls_alert (Alert , StateData0 ),
346346 {next_state , connection , StateData };
@@ -439,6 +439,9 @@ death_row(_Type, _Msg, _StateData) ->
439439 keep_state_and_data .
440440
441441% % State entry function that starts shutdown state_timeout
442+ % % distribution otherwise shuts down the sender
443+ death_row_shutdown (Reason , # data {env = # env {dist_handle = false }} = StateData ) ->
444+ {stop , {shutdown , Reason }, StateData };
442445death_row_shutdown (Reason , StateData ) ->
443446 {next_state , death_row , StateData , [{state_timeout , 5000 , Reason }]}.
444447
@@ -532,7 +535,7 @@ send_application_data(Data, From, StateName,
532535 case time_to_rekey (Version , DataSz , ConnectionStates0 , RenegotiateAt , KeyUpdateAt , BytesSent ) of
533536 key_update ->
534537 KeyUpdate = tls_handshake_1_3 :key_update (update_requested ),
535- {keep_state_and_data , [{next_event , internal , {post_handshake_data , From , KeyUpdate }},
538+ {keep_state_and_data , [{next_event , internal , {post_handshake_data , undefined , KeyUpdate }},
536539 {next_event , internal , {application_packets , From , Data }}]};
537540 renegotiate ->
538541 tls_dtls_gen_connection :internal_renegotiation (Pid , ConnectionStates0 ),
@@ -542,8 +545,8 @@ send_application_data(Data, From, StateName,
542545 KeyUpdate = tls_handshake_1_3 :key_update (update_requested ),
543546 % % Prevent infinite loop of key updates
544547 {Chunk , Rest } = split_binary (iolist_to_binary (Data ), KeyUpdateAt ),
545- {keep_state_and_data , [{next_event , internal , {post_handshake_data , From , KeyUpdate }},
546- {next_event , internal , {application_packets , From , [Chunk ]}},
548+ {keep_state_and_data , [{next_event , internal , {post_handshake_data , undefined , KeyUpdate }},
549+ {next_event , internal , {application_packets , undefined , [Chunk ]}},
547550 {next_event , internal , {application_packets , From , [Rest ]}}]};
548551 false ->
549552 {Msgs , ConnectionStates } = tls_record :encode_data (Data , Version , ConnectionStates0 ),
@@ -552,29 +555,29 @@ send_application_data(Data, From, StateName,
552555 ssl_logger :debug (LogLevel , outbound , 'record' , Msgs ),
553556 StateData1 = update_bytes_sent (Version , ConnectionStates , StateData0 , DataSz ),
554557 hibernate_after (StateName , StateData1 , []);
555- Reason when DistHandle =/= undefined ->
556- StateData = StateData0 # data {connection_states = ConnectionStates },
557- death_row_shutdown (Reason , StateData );
558558 ok ->
559559 ssl_logger :debug (LogLevel , outbound , 'record' , Msgs ),
560560 StateData = update_bytes_sent (Version , ConnectionStates , StateData0 , DataSz ),
561- gen_statem : reply (From , ok ),
561+ send_reply (From , ok ),
562562 hibernate_after (StateName , StateData , []);
563563 Result ->
564- gen_statem : reply (From , Result ),
564+ send_reply (From , Result ),
565565 StateData = StateData0 # data {connection_states = ConnectionStates },
566566 hibernate_after (StateName , StateData , [])
567567 end
568568 end .
569569
570+ send_reply (undefined , _Msg ) -> ok ;
571+ send_reply (From , Msg ) -> gen_statem :reply (From , Msg ).
572+
570573% % TLS 1.3 Post Handshake Data
571- send_post_handshake_data (Handshake , From , StateName ,
574+ send_post_handshake_data (Handshake , _From , StateName ,
572575 # data {env = # env {socket = Socket ,
573- dist_handle = DistHandle ,
574- negotiated_version = Version ,
575- transport_cb = Transport ,
576- log_level = LogLevel },
577- connection_states = ConnectionStates0 } = StateData0 ) ->
576+ dist_handle = DistHandle ,
577+ negotiated_version = Version ,
578+ transport_cb = Transport ,
579+ log_level = LogLevel },
580+ connection_states = ConnectionStates0 } = StateData0 , AckAction ) ->
578581 BinHandshake = tls_handshake :encode_handshake (Handshake , Version ),
579582 {Encoded , ConnectionStates } =
580583 tls_record :encode_handshake (BinHandshake , Version , ConnectionStates0 ),
@@ -584,15 +587,13 @@ send_post_handshake_data(Handshake, From, StateName,
584587 ok when DistHandle =/= undefined ->
585588 ssl_logger :debug (LogLevel , outbound , 'record' , Encoded ),
586589 StateData = maybe_update_cipher_key (StateData1 , Handshake ),
587- {next_state , StateName , StateData , []};
588- Reason when DistHandle =/= undefined ->
589- death_row_shutdown (Reason , StateData1 );
590+ {next_state , StateName , StateData , AckAction };
590591 ok ->
591592 ssl_logger :debug (LogLevel , outbound , 'record' , Encoded ),
592593 StateData = maybe_update_cipher_key (StateData1 , Handshake ),
593- {next_state , StateName , StateData , [{ reply , From , ok }] };
594- Result ->
595- { next_state , StateName , StateData1 , [{ reply , From , Result }]}
594+ {next_state , StateName , StateData , AckAction };
595+ { error , Reason } ->
596+ death_row_shutdown ( Reason , StateData1 )
596597 end .
597598
598599maybe_update_cipher_key (# data {connection_states = ConnectionStates0 ,
0 commit comments