Get public key authenticator actually running, add password validator via hash

This commit is contained in:
Simponic 2022-12-19 02:39:40 -07:00
parent 9cdfb6eb9c
commit b4743f9efb
Signed by untrusted user who does not match committer: simponic
GPG Key ID: 52B3774857EB24B1
12 changed files with 37 additions and 35 deletions

View File

@ -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"

View File

@ -1,9 +1 @@
import Config
config :chessh, Chessh.Repo,
database: "chessh",
username: "postgres",
password: "postgres",
hostname: "localhost"
config :chessh, ecto_repos: [Chessh.Repo]

View File

@ -1,8 +0,0 @@
defmodule Chessh.Auth.KeyAuthenticator do
use Sshd.PublicKeyAuthenticator
require Logger
def authenticate(_, _, _) do
false
end
end

View File

@ -1,7 +0,0 @@
defmodule Chessh.Auth.PasswordAuthenticator do
use Sshd.PasswordAuthenticator
def authenticate(_username, _password) do
true
end
end

View File

@ -1,6 +1,4 @@
defmodule Chessh do
require Logger
def hello() do
:world
end

10
lib/chessh/auth/keys.ex Normal file
View 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

View 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

View File

@ -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
View File

@ -0,0 +1,4 @@
defmodule ChesshTest do
use ExUnit.Case
doctest Chessh
end

View File

@ -1,8 +0,0 @@
defmodule ChesshTest do
use ExUnit.Case
doctest Chessh
test "greets the world" do
assert Chessh.hello() == :world
end
end