]> granicus.if.org Git - ejabberd/commitdiff
Only allow compression after SASL
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Wed, 13 Dec 2017 13:52:44 +0000 (16:52 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Wed, 13 Dec 2017 13:52:44 +0000 (16:52 +0300)
See XEP-0170 for details
Thanks to Vitaly Takmazov for spotting this

src/xmpp_stream_in.erl

index caad482c562b6e0da5ce96e16d76478960aa3635..4c690be3bac9fe23b46f1139256478ef97c4b9e0 100644 (file)
@@ -565,8 +565,6 @@ process_element(Pkt, #{stream_state := StateName, lang := Lang} = State) ->
            send_pkt(State, #sasl_failure{reason = 'aborted'});
        #sasl_success{} ->
            State;
-       #compress{} when StateName == wait_for_sasl_response ->
-           send_pkt(State, #compress_failure{reason = 'setup-failed'});
        #compress{} ->
            process_compress(Pkt, State);
        #handshake{} when StateName == wait_for_handshake ->
@@ -694,7 +692,10 @@ process_stream_established(#{mod := Mod} = State) ->
     end.
 
 -spec process_compress(compress(), state()) -> state().
-process_compress(#compress{}, #{stream_compressed := true} = State) ->
+process_compress(#compress{},
+                #{stream_compressed := Compressed,
+                  stream_authenticated := Authenticated} = State)
+  when Compressed or not Authenticated ->
     send_pkt(State, #compress_failure{reason = 'setup-failed'});
 process_compress(#compress{methods = HisMethods},
                 #{socket := Socket, sockmod := SockMod, mod := Mod} = State) ->
@@ -913,7 +914,8 @@ get_sasl_feature(_) ->
     [].
 
 -spec get_compress_feature(state()) -> [compression()].
-get_compress_feature(#{stream_compressed := false, mod := Mod} = State) ->
+get_compress_feature(#{stream_compressed := false, mod := Mod,
+                      stream_authenticated := true} = State) ->
     try Mod:compress_methods(State) of
        [] -> [];
        Ms -> [#compression{methods = Ms}]