|
42 | 42 | renegotiate/1, |
43 | 43 | peer_renegotiate/1, |
44 | 44 | downgrade/2, |
45 | | - update_connection_state/3, |
46 | 45 | dist_tls_socket/1, |
| 46 | + update_connection_state/4, |
47 | 47 | dist_handshake_complete/3]). |
48 | 48 |
|
49 | 49 | %% gen_statem callbacks |
@@ -166,12 +166,14 @@ peer_renegotiate(Pid) -> |
166 | 166 | gen_statem:call(Pid, renegotiate, ?DEFAULT_TIMEOUT). |
167 | 167 |
|
168 | 168 | %%-------------------------------------------------------------------- |
169 | | --spec update_connection_state(pid(), WriteState::map(), tls_record:tls_version()) -> ok. |
| 169 | +-spec update_connection_state(pid(), WriteState::map(), |
| 170 | + tls_record:tls_version(), |
| 171 | + MaxFragLen :: tls_record:tls_max_frag_len()) -> ok. |
170 | 172 | %% Description: So TLS connection process can synchronize the |
171 | 173 | %% encryption state to be used when sending application data. |
172 | 174 | %%-------------------------------------------------------------------- |
173 | | -update_connection_state(Pid, NewState, Version) -> |
174 | | - gen_statem:cast(Pid, {new_write, NewState, Version}). |
| 175 | +update_connection_state(Pid, NewState, Version, MaxFragLen) -> |
| 176 | + gen_statem:cast(Pid, {new_write, NewState, Version, MaxFragLen}). |
175 | 177 |
|
176 | 178 | %%-------------------------------------------------------------------- |
177 | 179 | -spec downgrade(pid(), integer()) -> {ok, ssl_record:connection_state()} |
@@ -339,19 +341,19 @@ connection({call, From}, get_application_traffic_secret, #data{env = #env{num_ke |
339 | 341 | [{reply, From, {ok, ApplicationTrafficSecret, N}}]); |
340 | 342 | connection(internal, {application_packets, From, Data}, StateData) -> |
341 | 343 | send_application_data(Data, From, connection, StateData); |
| 344 | + |
342 | 345 | connection(internal, {post_handshake_data, From, HSData}, StateData) -> |
343 | 346 | send_post_handshake_data(HSData, From, connection, StateData); |
344 | 347 | connection(cast, #alert{} = Alert, StateData0) -> |
345 | 348 | StateData = send_tls_alert(Alert, StateData0), |
346 | 349 | {next_state, connection, StateData}; |
347 | | -connection(cast, {new_write, WritesState, Version}, |
348 | | - #data{connection_states = ConnectionStates, env = Env} = StateData) -> |
| 350 | +connection(cast, {new_write, WritesState, Version, MaxFragLen}, |
| 351 | + #data{connection_states = ConnectionStates0, env = Env} = StateData) -> |
| 352 | + ConnectionStates = handle_new_write_state(ConnectionStates0, WritesState, MaxFragLen), |
349 | 353 | hibernate_after(connection, |
350 | | - StateData#data{connection_states = |
351 | | - ConnectionStates#{current_write => WritesState}, |
352 | | - env = |
353 | | - Env#env{negotiated_version = Version}}, []); |
354 | | -%% |
| 354 | + StateData#data{connection_states = ConnectionStates, |
| 355 | + env = Env#env{negotiated_version = Version}}, |
| 356 | + []); |
355 | 357 | connection(info, dist_data, |
356 | 358 | #data{env = #env{dist_handle = DHandle}} = StateData) -> |
357 | 359 | case dist_data(DHandle) of |
@@ -394,24 +396,24 @@ handshake({call, _}, _, _) -> |
394 | 396 | {keep_state_and_data, [postpone]}; |
395 | 397 | handshake(internal, {application_packets,_,_}, _) -> |
396 | 398 | {keep_state_and_data, [postpone]}; |
397 | | -handshake(cast, {new_write, WriteState, Version}, |
| 399 | +handshake(cast, {new_write, WriteState, Version, MaxFragLen}, |
398 | 400 | #data{connection_states = ConnectionStates0, |
399 | 401 | env = #env{key_update_at = KeyUpdateAt0, |
400 | | - role = Role, |
401 | | - num_key_updates = N, |
402 | | - keylog_fun = Fun} = Env} = StateData) -> |
403 | | - ConnectionStates = ConnectionStates0#{current_write => WriteState}, |
| 402 | + role = Role, |
| 403 | + num_key_updates = N, |
| 404 | + keylog_fun = Fun} = Env} = StateData) -> |
404 | 405 | KeyUpdateAt = key_update_at(Version, WriteState, KeyUpdateAt0), |
405 | | - case Version of |
406 | | - ?TLS_1_3 -> |
407 | | - maybe_traffic_keylog_1_3(Fun, Role, ConnectionStates, N); |
408 | | - _ -> |
409 | | - ok |
410 | | - end, |
411 | | - {next_state, connection, |
| 406 | + ConnectionStates = handle_new_write_state(ConnectionStates0, WriteState, MaxFragLen), |
| 407 | + case Version of |
| 408 | + ?TLS_1_3 -> |
| 409 | + maybe_traffic_keylog_1_3(Fun, Role, ConnectionStates, N); |
| 410 | + _ -> |
| 411 | + ok |
| 412 | + end, |
| 413 | + {next_state, connection, |
412 | 414 | StateData#data{connection_states = ConnectionStates, |
413 | 415 | env = Env#env{negotiated_version = Version, |
414 | | - key_update_at = KeyUpdateAt}}}; |
| 416 | + key_update_at = KeyUpdateAt}}}; |
415 | 417 | handshake(info, dist_data, _) -> |
416 | 418 | {keep_state_and_data, [postpone]}; |
417 | 419 | handshake(info, tick, _) -> |
@@ -463,6 +465,13 @@ code_change(_OldVsn, State, Data, _Extra) -> |
463 | 465 | %%%=================================================================== |
464 | 466 | %%% Internal functions |
465 | 467 | %%%=================================================================== |
| 468 | +handle_new_write_state(ConnectionStates, WriteState0, undefined) -> |
| 469 | + WriteState = maps:remove(aead_handle, WriteState0), |
| 470 | + maps:without([max_fragment_length], ConnectionStates#{current_write => WriteState}); |
| 471 | +handle_new_write_state(ConnectionStates, WriteState0, MaxFragLen) -> |
| 472 | + WriteState = maps:remove(aead_handle, WriteState0), |
| 473 | + ConnectionStates#{max_fragment_length => MaxFragLen, current_write => WriteState}. |
| 474 | + |
466 | 475 | handle_set_opts(StateName, From, Opts, |
467 | 476 | #data{env = #env{socket_options = SockOpts} = Env} |
468 | 477 | = StateData) -> |
|
0 commit comments