Get public key authenticator actually running, add password validator via hash
This commit is contained in:
parent
9cdfb6eb9c
commit
b4743f9efb
@ -1,11 +1,19 @@
|
||||
import Config
|
||||
|
||||
config :chessh, Chessh.Repo,
|
||||
database: "chessh",
|
||||
username: "postgres",
|
||||
password: "postgres",
|
||||
hostname: "localhost"
|
||||
|
||||
config :chessh, ecto_repos: [Chessh.Repo]
|
||||
|
||||
config :esshd,
|
||||
enabled: true,
|
||||
priv_dir: Path.join(Path.dirname(__DIR__), "priv/keys"),
|
||||
handler: {Chessh.Shell, :on_shell, 4},
|
||||
port: 42069,
|
||||
public_key_authenticator: Chessh.Auth.KeyAuthenticator,
|
||||
password_authenticator: Chessh.Auth.PasswordAuthenticator
|
||||
password_authenticator: Chessh.Auth.PasswordAuthenticator,
|
||||
public_key_authenticator: Chessh.Auth.KeyAuthenticator
|
||||
|
||||
import_config "#{config_env()}.exs"
|
||||
|
@ -1,9 +1 @@
|
||||
import Config
|
||||
|
||||
config :chessh, Chessh.Repo,
|
||||
database: "chessh",
|
||||
username: "postgres",
|
||||
password: "postgres",
|
||||
hostname: "localhost"
|
||||
|
||||
config :chessh, ecto_repos: [Chessh.Repo]
|
||||
|
@ -1,8 +0,0 @@
|
||||
defmodule Chessh.Auth.KeyAuthenticator do
|
||||
use Sshd.PublicKeyAuthenticator
|
||||
require Logger
|
||||
|
||||
def authenticate(_, _, _) do
|
||||
false
|
||||
end
|
||||
end
|
@ -1,7 +0,0 @@
|
||||
defmodule Chessh.Auth.PasswordAuthenticator do
|
||||
use Sshd.PasswordAuthenticator
|
||||
|
||||
def authenticate(_username, _password) do
|
||||
true
|
||||
end
|
||||
end
|
@ -1,6 +1,4 @@
|
||||
defmodule Chessh do
|
||||
require Logger
|
||||
|
||||
def hello() do
|
||||
:world
|
||||
end
|
||||
|
10
lib/chessh/auth/keys.ex
Normal file
10
lib/chessh/auth/keys.ex
Normal file
@ -0,0 +1,10 @@
|
||||
defmodule Chessh.Auth.KeyAuthenticator do
|
||||
use Sshd.PublicKeyAuthenticator
|
||||
require Logger
|
||||
|
||||
def authenticate(username, public_key, _opts) do
|
||||
Logger.debug("#{inspect(username)}")
|
||||
Logger.debug("#{inspect(public_key)}")
|
||||
true
|
||||
end
|
||||
end
|
12
lib/chessh/auth/password.ex
Normal file
12
lib/chessh/auth/password.ex
Normal file
@ -0,0 +1,12 @@
|
||||
defmodule Chessh.Auth.PasswordAuthenticator do
|
||||
alias Chessh.Player
|
||||
alias Chessh.Repo
|
||||
use Sshd.PasswordAuthenticator
|
||||
|
||||
def authenticate(username, password) do
|
||||
case Repo.get_by(Player, username: String.Chars.to_string(username)) do
|
||||
nil -> false
|
||||
x -> Player.valid_password?(x, password)
|
||||
end
|
||||
end
|
||||
end
|
1
mix.exs
1
mix.exs
@ -14,6 +14,7 @@ defmodule Chessh.MixProject do
|
||||
# Run "mix help compile.app" to learn about applications.
|
||||
def application do
|
||||
[
|
||||
mod: {Chessh.Application, []},
|
||||
extra_applications: [:esshd, :logger]
|
||||
]
|
||||
end
|
||||
|
4
test/chessh_test.exs
Normal file
4
test/chessh_test.exs
Normal file
@ -0,0 +1,4 @@
|
||||
defmodule ChesshTest do
|
||||
use ExUnit.Case
|
||||
doctest Chessh
|
||||
end
|
@ -1,8 +0,0 @@
|
||||
defmodule ChesshTest do
|
||||
use ExUnit.Case
|
||||
doctest Chessh
|
||||
|
||||
test "greets the world" do
|
||||
assert Chessh.hello() == :world
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user