Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/mariaex/password.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Mariaex.Password do

@spec save!(String.t) :: :ets.tid()
def save!(password) do
tid = :ets.new(:password, [:private])
true = :ets.insert(tid, {:password, password})
tid
end

@spec get(:ets.tid()) :: String.t
def get(tid) do
[password: password] = :ets.lookup(tid, :password)
password
end
end
6 changes: 4 additions & 2 deletions lib/mariaex/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Mariaex.Protocol do
alias Mariaex.Query
alias Mariaex.Cursor
alias Mariaex.Column
alias Mariaex.Password
import Mariaex.Messages
import Mariaex.ProtocolHelper

Expand Down Expand Up @@ -130,6 +131,7 @@ defmodule Mariaex.Protocol do
opts
|> Keyword.put_new(:username, System.get_env("MDBUSER") || System.get_env("USER"))
|> Keyword.put_new(:password, System.get_env("MDBPASSWORD"))
|> Keyword.update!(:password, &Password.save!/1)
|> Keyword.put_new(:hostname, System.get_env("MDBHOST") || "localhost")
|> Keyword.put_new(:port, System.get_env("MDBPORT") || 3306)
|> Keyword.put_new(:timeout, @timeout)
Expand Down Expand Up @@ -206,7 +208,7 @@ defmodule Mariaex.Protocol do
<<flag :: size(32)>> = <<flag2 :: size(16), flag1 :: size(16)>>
deprecated_eof = (flag &&& @client_deprecate_eof) == @client_deprecate_eof
handshake(auth_plugin_data1: salt1, auth_plugin_data2: salt2) = handshake
scramble = case password = opts[:password] do
scramble = case password = Password.get(opts[:password]) do
nil -> ""
"" -> ""
_ -> password(plugin, password, <<salt1 :: binary, salt2 :: binary>>)
Expand Down Expand Up @@ -1077,7 +1079,7 @@ defmodule Mariaex.Protocol do

def dispatch(packet(msg: :mysql_old_password), state = %{opts: opts, handshake: handshake}) do
if opts[:insecure_auth] do
password = opts[:password]
password = Password.get(opts[:password])
%{salt: {salt1, salt2}, seqnum: seqnum} = handshake
password = password(@mysql_old_password, password, <<salt1 :: binary, salt2 :: binary>>)
# TODO: rethink seqnum handling
Expand Down