From f7c2ccbe26dc808e4a7eae9a378e6c382220961a Mon Sep 17 00:00:00 2001 From: Simponic Date: Thu, 22 Dec 2022 15:27:55 -0700 Subject: [PATCH] Remove shell and esshd - moving to erlang ssh server --- config/config.exs | 12 +++------ config/test.exs | 4 +-- lib/chessh/auth/keys.ex | 1 - lib/chessh/auth/password.ex | 1 - lib/chessh/shell.ex | 51 ------------------------------------- lib/chessh/ssh/server.ex | 0 mix.exs | 3 +-- 7 files changed, 6 insertions(+), 66 deletions(-) delete mode 100644 lib/chessh/shell.ex create mode 100644 lib/chessh/ssh/server.ex diff --git a/config/config.exs b/config/config.exs index 6fb4258..daffcad 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,15 +1,9 @@ import Config -config :chessh, ecto_repos: [Chessh.Repo] - -config :esshd, - enabled: true, +config :chessh, + ecto_repos: [Chessh.Repo], priv_dir: Path.join(Path.dirname(__DIR__), "priv/keys"), - handler: {Chessh.Shell, :on_shell, 4}, port: 42069, - password_authenticator: Chessh.Auth.PasswordAuthenticator, - public_key_authenticator: Chessh.Auth.KeyAuthenticator, - # TODO - benchmark - max_sessions: 128 + max_sessions: 255 import_config "#{config_env()}.exs" diff --git a/config/test.exs b/config/test.exs index 6ade5f8..c1d70dd 100644 --- a/config/test.exs +++ b/config/test.exs @@ -7,5 +7,5 @@ config :chessh, Chessh.Repo, hostname: "localhost", pool: Ecto.Adapters.SQL.Sandbox -config :esshd, - priv_dir: Path.join(Path.dirname(__DIR__), "priv/test_keys") +config :chessh, + priv_dir: Path.join(Path.dirname(__DIR__), "priv/keys") diff --git a/lib/chessh/auth/keys.ex b/lib/chessh/auth/keys.ex index e90f101..a29d169 100644 --- a/lib/chessh/auth/keys.ex +++ b/lib/chessh/auth/keys.ex @@ -1,6 +1,5 @@ defmodule Chessh.Auth.KeyAuthenticator do alias Chessh.{Key, Repo} - use Sshd.PublicKeyAuthenticator import Ecto.Query def authenticate(username, public_key) do diff --git a/lib/chessh/auth/password.ex b/lib/chessh/auth/password.ex index e2c26d6..8a6c683 100644 --- a/lib/chessh/auth/password.ex +++ b/lib/chessh/auth/password.ex @@ -1,7 +1,6 @@ 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 diff --git a/lib/chessh/shell.ex b/lib/chessh/shell.ex deleted file mode 100644 index cf65ad4..0000000 --- a/lib/chessh/shell.ex +++ /dev/null @@ -1,51 +0,0 @@ -defmodule Chessh.Shell do - use Sshd.ShellHandler - - def on_shell(_username, _pubkey, _ip, _port) do - IO.puts("Looks like you're on #{inspect(self())}") - loop() - end - - def on_connect(username, ip, port, method) do - Logger.debug(fn -> - """ - Incoming SSH shell #{inspect(self())} requested for #{username} from #{inspect(ip)}:#{inspect(port)} using #{inspect(method)} - """ - end) - end - - def on_disconnect(username, ip, port) do - Logger.debug(fn -> - "Disconnecting SSH shell for #{username} from #{inspect(ip)}:#{inspect(port)}" - end) - end - - defp loop() do - self_pid = self() - IO.write([IO.ANSI.home(), IO.ANSI.clear()]) - IO.puts("#{inspect(:io.columns())}") - IO.puts("#{inspect(:io.rows())}") - input = spawn(fn -> io_get(self_pid) end) - wait_input(input) - end - - defp wait_input(input) do - receive do - {:hello, message} -> - IO.puts(message) - loop() - - {:input, ^input, x} -> - IO.puts(x) - loop() - - x -> - Logger.debug(inspect(x)) - loop() - end - end - - defp io_get(pid) do - send(pid, {:input, self(), IO.gets("")}) - end -end diff --git a/lib/chessh/ssh/server.ex b/lib/chessh/ssh/server.ex new file mode 100644 index 0000000..e69de29 diff --git a/mix.exs b/mix.exs index 0a40f28..4d91dd2 100644 --- a/mix.exs +++ b/mix.exs @@ -17,7 +17,7 @@ defmodule Chessh.MixProject do def application do [ mod: {Chessh.Application, []}, - extra_applications: [:esshd, :logger] + extra_applications: [:logger, :crypto, :ssh] ] end @@ -28,7 +28,6 @@ defmodule Chessh.MixProject do defp deps do [ {:chess, "~> 0.4.1"}, - {:esshd, "~> 0.2.1"}, {:ecto, "~> 3.9"}, {:ecto_sql, "~> 3.9"}, {:postgrex, "~> 0.16.5"},