Skip to content

Commit b0447a7

Browse files
committed
Fix issue with CLIENT_PLUGIN_AUTH flag in ssl request packet
If server wanted mysql_native_password password in initial handshake, we didn't include CLIENT_PLUGIN_AUTH bit in packet to initiate ssl connection thinking that server was too old to support this, but we should consult caps presented by server for this. Missing this flag caused problem if server later needed to switch to different password format. This fixes issue ejabberd#4532
1 parent 077f014 commit b0447a7

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/p1_mysql_auth.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
%%--------------------------------------------------------------------
1717
%% External exports (should only be used by the 'p1_mysql_conn' module)
1818
%%--------------------------------------------------------------------
19-
-export([do_auth/8, password_sha2/2, get_auth_head/2]).
19+
-export([do_auth/8, password_sha2/2, get_auth_head/3]).
2020

2121
-include("p1_mysql_consts.hrl").
2222
-include("p1_mysql_state.hrl").
@@ -38,11 +38,11 @@
3838
%% External functions
3939
%%====================================================================
4040

41-
get_auth_head("old_auth", ExtraCaps) ->
41+
get_auth_head("old_auth", _, ExtraCaps) ->
4242
make_auth_head(ExtraCaps);
43-
get_auth_head("mysql_native_password", ExtraCaps) ->
43+
get_auth_head("mysql_native_password", false, ExtraCaps) ->
4444
make_new_auth_head(none, "", ExtraCaps);
45-
get_auth_head(Type, ExtraCaps) ->
45+
get_auth_head(Type, _, ExtraCaps) ->
4646
make_new_auth_head(none, Type, ExtraCaps).
4747

4848
%%--------------------------------------------------------------------

src/p1_mysql_conn.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ mysql_init(State, User, Password, LogFun, SSLOpts) ->
469469
_ ->
470470
case proplists:get_bool(ssl, SSLOpts) orelse proplists:get_bool(ssl_required, SSLOpts) of
471471
true ->
472-
case start_ssl(NState, SSLOpts, LogFun, InitSeqNum + 1, AuthPlug) of
472+
case start_ssl(NState, SSLOpts, LogFun, InitSeqNum + 1, AuthPlug, Caps band ?CLIENT_PLUGIN_AUTH /= 0) of
473473
{ok, NewState} ->
474474
authenticate(NewState, User, Password, LogFun,
475475
InitSeqNum + 1, Version, Salt, Caps, AuthPlug);
@@ -489,8 +489,8 @@ mysql_init(State, User, Password, LogFun, SSLOpts) ->
489489

490490
%% part of mysql_init/4
491491

492-
start_ssl(#state{socket = {_, Sock}} = State, SSLOpts, LogFun, SeqNum, AuthPlug) ->
493-
Packet = p1_mysql_auth:get_auth_head(AuthPlug, ?CLIENT_SSL),
492+
start_ssl(#state{socket = {_, Sock}} = State, SSLOpts, LogFun, SeqNum, AuthPlug, ServerHasPlugAuth) ->
493+
Packet = p1_mysql_auth:get_auth_head(AuthPlug, ServerHasPlugAuth, ?CLIENT_SSL),
494494
Data = <<(size(Packet)):24/little, SeqNum:8, Packet/binary>>,
495495
p1_mysql:log(LogFun, debug, "p1_mysql_conn send start ssl ~p: ~p", [SeqNum, Packet]),
496496
gen_tcp:send(Sock, Data),

0 commit comments

Comments
 (0)