121121
122122-include (" dtls_connection.hrl" ).
123123-include (" dtls_handshake.hrl" ).
124+ -include (" dtls_record.hrl" ).
124125-include (" ssl_alert.hrl" ).
125126-include (" ssl_cipher.hrl" ).
126127-include (" ssl_internal.hrl" ).
@@ -206,6 +207,10 @@ initial_hello({call, From}, {start, {Opts, EmOpts}, Timeout},
206207 catch throw :Error ->
207208 {stop_and_reply , {shutdown , normal }, {reply , From , {error , Error }}, State0 }
208209 end ;
210+ initial_hello (internal , {protocol_record , # ssl_tls {type = ? APPLICATION_DATA }},
211+ # state {handshake_env = # handshake_env {renegotiation = {false , first }}} = State ) ->
212+ Alert = ? ALERT_REC (? FATAL , ? UNEXPECTED_MESSAGE , application_data_before_initial_handshake ),
213+ ssl_gen_statem :handle_own_alert (Alert , ? STATE (initial_hello ), State );
209214initial_hello (Type , Event , State ) ->
210215 tls_dtls_server_connection :initial_hello (Type , Event , State ).
211216
@@ -302,7 +307,10 @@ hello(internal, #change_cipher_spec{type = <<1>>}, State0) ->
302307 {stop , _ , _ } = Stop ->
303308 Stop
304309 end ;
305-
310+ hello (internal , {protocol_record , # ssl_tls {type = ? APPLICATION_DATA }},
311+ # state {handshake_env = # handshake_env {renegotiation = {false , first }}} = State ) ->
312+ Alert = ? ALERT_REC (? FATAL , ? UNEXPECTED_MESSAGE , application_data_before_initial_handshake ),
313+ ssl_gen_statem :handle_own_alert (Alert , ? STATE (hello ), State );
306314hello (info , Event , State ) ->
307315 dtls_gen_connection :gen_info (Event , ? STATE (hello ), State );
308316hello (state_timeout , Event , State ) ->
@@ -338,6 +346,10 @@ abbreviated(internal = Type, #change_cipher_spec{} = Event,
338346 ConnectionStates = dtls_record :next_epoch (ConnectionStates1 , read ),
339347 gen_state (? STATE (abbreviated ), Type , Event ,
340348 State # state {connection_states = ConnectionStates });
349+ abbreviated (internal , {protocol_record , # ssl_tls {type = ? APPLICATION_DATA }},
350+ # state {handshake_env = # handshake_env {renegotiation = {false , first }}} = State ) ->
351+ Alert = ? ALERT_REC (? FATAL , ? UNEXPECTED_MESSAGE , application_data_before_initial_handshake ),
352+ ssl_gen_statem :handle_own_alert (Alert , ? STATE (abbreviated ), State );
341353abbreviated (Type , Event , State ) ->
342354 gen_state (? STATE (abbreviated ), Type , Event , State ).
343355
@@ -362,6 +374,10 @@ certify(internal, #change_cipher_spec{type = <<1>>}, State0) ->
362374 end ;
363375certify (state_timeout , Event , State ) ->
364376 dtls_gen_connection :handle_state_timeout (Event , ? STATE (certify ), State );
377+ certify (internal , {protocol_record , # ssl_tls {type = ? APPLICATION_DATA }},
378+ # state {handshake_env = # handshake_env {renegotiation = {false , first }}} = State ) ->
379+ Alert = ? ALERT_REC (? FATAL , ? UNEXPECTED_MESSAGE , application_data_before_initial_handshake ),
380+ ssl_gen_statem :handle_own_alert (Alert , ? STATE (certify ), State );
365381certify (info , Event , State ) ->
366382 dtls_gen_connection :gen_info (Event , ? STATE (certify ), State );
367383certify (Type , Event , State ) ->
@@ -378,6 +394,10 @@ wait_cert_verify(state_timeout, Event, State) ->
378394 dtls_gen_connection :handle_state_timeout (Event , ? STATE (wait_cert_verify ), State );
379395wait_cert_verify (info , Event , State ) ->
380396 dtls_gen_connection :gen_info (Event , ? STATE (wait_cert_verify ), State );
397+ wait_cert_verify (internal , {protocol_record , # ssl_tls {type = ? APPLICATION_DATA }},
398+ # state {handshake_env = # handshake_env {renegotiation = {false , first }}} = State ) ->
399+ Alert = ? ALERT_REC (? FATAL , ? UNEXPECTED_MESSAGE , application_data_before_initial_handshake ),
400+ ssl_gen_statem :handle_own_alert (Alert , ? STATE (wait_cert_verify ), State );
381401wait_cert_verify (Type , Event , State ) ->
382402 gen_state (? STATE (wait_cert_verify ), Type , Event , State ).
383403
@@ -404,6 +424,10 @@ cipher(internal = Type, #finished{} = Event, #state{connection_states = Connecti
404424 State # state {connection_states = ConnectionStates ,
405425 protocol_specific =
406426 PS #{flight_state => connection }}));
427+ cipher (internal , {protocol_record , # ssl_tls {type = ? APPLICATION_DATA }},
428+ # state {handshake_env = # handshake_env {renegotiation = {false , first }}} = State ) ->
429+ Alert = ? ALERT_REC (? FATAL , ? UNEXPECTED_MESSAGE , application_data_before_initial_handshake ),
430+ ssl_gen_statem :handle_own_alert (Alert , ? STATE (cipher ), State );
407431cipher (Type , Event , State ) ->
408432 gen_state (? STATE (cipher ), Type , Event , State ).
409433
0 commit comments