Skip to content

Commit a6a491c

Browse files
committed
ssl: Dissalow two change_cipher_specs in a row in TLS-1.2 statemachine
This would always end up in a failed connection, but we like to have early failure and not fail due to a broken state but instead due to discovery of an unexpected protocol message.
1 parent 940ec0f commit a6a491c

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

lib/ssl/src/dtls_gen_connection.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ reinit_handshake_data(#state{static_env = #static_env{data_tag = DataTag},
596596
State#state{handshake_env = HsEnv#handshake_env{tls_handshake_history = ssl_handshake:init_handshake_history(),
597597
public_key_info = undefined,
598598
premaster_secret = undefined,
599+
expecting_finished = false,
599600
flight_buffer = new_flight()},
600601
protocol_specific = PS#{flight_state => initial_flight_state(DataTag)},
601602
protocol_buffers =

lib/ssl/src/tls_dtls_gen_connection.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ abbreviated({call, From}, Msg, State) ->
289289
handle_call(Msg, From, ?STATE(abbreviated), State);
290290
abbreviated(internal,
291291
#change_cipher_spec{type = <<1>>},
292-
#state{static_env = #static_env{protocol_cb = Connection},
293-
connection_states = ConnectionStates0,
294-
handshake_env = HsEnv} = State) ->
292+
#state{handshake_env = #handshake_env{expecting_finished = false} = HsEnv,
293+
static_env = #static_env{protocol_cb = Connection},
294+
connection_states = ConnectionStates0} = State) ->
295295
ConnectionStates1 =
296296
ssl_record:activate_pending_connection_state(ConnectionStates0, read, Connection),
297297
Connection:next_event(?STATE(abbreviated), no_record,
@@ -323,7 +323,7 @@ certify(Type, Event, State) ->
323323
cipher({call, From}, Msg, State) ->
324324
handle_call(Msg, From, ?STATE(cipher), State);
325325
cipher(internal, #change_cipher_spec{type = <<1>>},
326-
#state{handshake_env = HsEnv,
326+
#state{handshake_env = #handshake_env{expecting_finished = false} = HsEnv,
327327
static_env = #static_env{protocol_cb = Connection},
328328
connection_states = ConnectionStates0} = State) ->
329329
ConnectionStates =

lib/ssl/src/tls_gen_connection.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ reinit_handshake_data(#state{handshake_env = HsEnv} =State) ->
245245
handshake_env = HsEnv#handshake_env{tls_handshake_history =
246246
ssl_handshake:init_handshake_history(),
247247
public_key_info = undefined,
248-
premaster_secret = undefined}
248+
premaster_secret = undefined,
249+
expecting_finished = false}
249250
}.
250251

251252
select_sni_extension(#client_hello{extensions = #{sni := SNI}}) ->

0 commit comments

Comments
 (0)