41
41
renegotiate /1 ,
42
42
peer_renegotiate /1 ,
43
43
downgrade /2 ,
44
- update_connection_state /3 ,
44
+ update_connection_state /4 ,
45
45
dist_handshake_complete /3 ]).
46
46
47
47
% % gen_statem callbacks
@@ -170,12 +170,14 @@ peer_renegotiate(Pid) ->
170
170
gen_statem :call (Pid , renegotiate , ? DEFAULT_TIMEOUT ).
171
171
172
172
% %--------------------------------------------------------------------
173
- -spec update_connection_state (pid (), WriteState :: map (), tls_record :tls_version ()) -> ok .
173
+ -spec update_connection_state (pid (), WriteState :: map (),
174
+ tls_record :tls_version (),
175
+ MaxFragLen :: tls_record :tls_max_frag_len ()) -> ok .
174
176
% % Description: So TLS connection process can synchronize the
175
177
% % encryption state to be used when sending application data.
176
178
% %--------------------------------------------------------------------
177
- update_connection_state (Pid , NewState , Version ) ->
178
- gen_statem :cast (Pid , {new_write , NewState , Version }).
179
+ update_connection_state (Pid , NewState , Version , MaxFragLen ) ->
180
+ gen_statem :cast (Pid , {new_write , NewState , Version , MaxFragLen }).
179
181
180
182
% %--------------------------------------------------------------------
181
183
-spec downgrade (pid (), integer ()) -> {ok , ssl_record :connection_state ()}
@@ -339,13 +341,13 @@ connection(cast, #alert{} = Alert, #data{buff = Buff} = StateData0) ->
339
341
Async ->
340
342
{next_state , async_wait , StateData0 # data {buff = Async # async {low = 0 }}, [postpone ]}
341
343
end ;
342
- connection (cast , {new_write , WritesState , Version },
343
- # data {connection_states = ConnectionStates , env = Env } = StateData ) ->
344
- CW = maps : remove ( aead_handle , WritesState ),
344
+ connection (cast , {new_write , WritesState , Version , MaxFragLen },
345
+ # data {connection_states = ConnectionStates0 , env = Env } = StateData ) ->
346
+ ConnectionStates = handle_new_write_state ( ConnectionStates0 , WritesState , MaxFragLen ),
345
347
hibernate_after (connection ,
346
- StateData # data {connection_states = ConnectionStates #{ current_write => CW } ,
347
- env = Env # env {negotiated_version = Version }}, []);
348
- % %
348
+ StateData # data {connection_states = ConnectionStates ,
349
+ env = Env # env {negotiated_version = Version }},
350
+ []);
349
351
connection (info , dist_data ,
350
352
# data {env = # env {dist_handle = DHandle }} = StateData ) ->
351
353
case dist_data (DHandle ) of
@@ -409,15 +411,14 @@ handshake({call, _}, _, _) ->
409
411
{keep_state_and_data , [postpone ]};
410
412
handshake (internal , {application_packets ,_ ,_ }, _ ) ->
411
413
{keep_state_and_data , [postpone ]};
412
- handshake (cast , {new_write , WriteState0 , Version },
414
+ handshake (cast , {new_write , WriteState , Version , MaxFragLen },
413
415
# data {connection_states = ConnectionStates0 ,
414
416
env = # env {key_update_at = KeyUpdateAt0 ,
415
- role = Role ,
416
- num_key_updates = N ,
417
- keylog_fun = Fun } = Env } = StateData ) ->
418
- WriteState = maps :remove (aead_handle , WriteState0 ),
419
- ConnectionStates = ConnectionStates0 #{current_write => WriteState },
417
+ role = Role ,
418
+ num_key_updates = N ,
419
+ keylog_fun = Fun } = Env } = StateData ) ->
420
420
KeyUpdateAt = key_update_at (Version , WriteState , KeyUpdateAt0 ),
421
+ ConnectionStates = handle_new_write_state (ConnectionStates0 , WriteState , MaxFragLen ),
421
422
case Version of
422
423
? TLS_1_3 ->
423
424
maybe_traffic_keylog_1_3 (Fun , Role , ConnectionStates , N );
@@ -427,7 +428,7 @@ handshake(cast, {new_write, WriteState0, Version},
427
428
{next_state , connection ,
428
429
StateData # data {connection_states = ConnectionStates ,
429
430
env = Env # env {negotiated_version = Version ,
430
- key_update_at = KeyUpdateAt }}};
431
+ key_update_at = KeyUpdateAt }}};
431
432
handshake (info , dist_data , _ ) ->
432
433
{keep_state_and_data , [postpone ]};
433
434
handshake (info , tick , _ ) ->
@@ -489,6 +490,13 @@ code_change(_OldVsn, State, Data, _Extra) ->
489
490
% %%===================================================================
490
491
% %% Internal functions
491
492
% %%===================================================================
493
+ handle_new_write_state (ConnectionStates , WriteState0 , undefined ) ->
494
+ WriteState = maps :remove (aead_handle , WriteState0 ),
495
+ maps :without ([max_fragment_length ], ConnectionStates #{current_write => WriteState });
496
+ handle_new_write_state (ConnectionStates , WriteState0 , MaxFragLen ) ->
497
+ WriteState = maps :remove (aead_handle , WriteState0 ),
498
+ ConnectionStates #{max_fragment_length => MaxFragLen , current_write => WriteState }.
499
+
492
500
handle_common (StateName , {call , From }, get_application_traffic_secret ,
493
501
# data {env = # env {num_key_updates = N }} = Data ) ->
494
502
CurrentWrite = maps :get (current_write , Data # data .connection_states ),
0 commit comments