|
109 | 109 | -callback tls_options(state()) -> [proplists:property()].
|
110 | 110 | -callback tls_required(state()) -> boolean().
|
111 | 111 | -callback tls_enabled(state()) -> boolean().
|
| 112 | +-callback allow_unencrypted_sasl2(state()) -> boolean(). |
112 | 113 | -callback sasl_mechanisms([xmpp_sasl:mechanism()], state()) -> [xmpp_sasl:mechanism()].
|
113 | 114 | -callback sasl_options(state()) -> [tuple()].
|
114 | 115 | -callback unauthenticated_stream_features(state()) -> [xmpp_element()].
|
|
142 | 143 | tls_options/1,
|
143 | 144 | tls_required/1,
|
144 | 145 | tls_enabled/1,
|
| 146 | + allow_unencrypted_sasl2/1, |
145 | 147 | sasl_mechanisms/2,
|
146 | 148 | sasl_options/1,
|
147 | 149 | unauthenticated_stream_features/1,
|
@@ -668,6 +670,7 @@ process_stream(#stream_start{to = #jid{server = Server, lserver = LServer},
|
668 | 670 | process_element(Pkt, #{stream_state := StateName, lang := Lang,
|
669 | 671 | stream_encrypted := Encrypted} = State) ->
|
670 | 672 | Sasl2 = maps:is_key(sasl2_stream_from, State),
|
| 673 | + AllowUnencryptedSasl2 = allow_unencrypted_sasl2(State), |
671 | 674 | case Pkt of
|
672 | 675 | #starttls{} when StateName == wait_for_starttls;
|
673 | 676 | StateName == wait_for_sasl_request ->
|
@@ -698,7 +701,8 @@ process_element(Pkt, #{stream_state := StateName, lang := Lang,
|
698 | 701 | send_pkt(State, #sasl_failure{reason = 'aborted'});
|
699 | 702 | #sasl_success{} ->
|
700 | 703 | State;
|
701 |
| - #sasl2_authenticate{} when StateName == wait_for_starttls; (not Encrypted) -> |
| 704 | + #sasl2_authenticate{} when StateName == wait_for_starttls; |
| 705 | + not (Encrypted or AllowUnencryptedSasl2) -> |
702 | 706 | send_pkt(State, #sasl2_failure{reason = 'encryption-required'});
|
703 | 707 | #sasl2_authenticate{} when StateName == wait_for_sasl_request, Sasl2 ->
|
704 | 708 | process_sasl2_request(Pkt, maps:remove(sasl_state, State));
|
@@ -1421,6 +1425,12 @@ is_starttls_required(State) ->
|
1421 | 1425 | catch _:{?MODULE, undef} -> false
|
1422 | 1426 | end.
|
1423 | 1427 |
|
| 1428 | +-spec allow_unencrypted_sasl2(state()) -> boolean(). |
| 1429 | +allow_unencrypted_sasl2(State) -> |
| 1430 | + try callback(allow_unencrypted_sasl2, State) |
| 1431 | + catch _:{?MODULE, undef} -> false |
| 1432 | + end. |
| 1433 | + |
1424 | 1434 | -spec set_from_to(xmpp_element(), state()) -> {ok, xmpp_element()} |
|
1425 | 1435 | {error, stream_error()}.
|
1426 | 1436 | set_from_to(Pkt, _State) when not ?is_stanza(Pkt) ->
|
|
0 commit comments