diff options
| author | Simponic <loganhunt@simponic.xyz> | 2022-12-29 17:49:42 -0700 |
|---|---|---|
| committer | Simponic <loganhunt@simponic.xyz> | 2022-12-29 18:04:38 -0700 |
| commit | 0aab3c2027d54fc1ba834ab73fd53328952b7a1b (patch) | |
| tree | 4df45d7fc9df4668f5a6bd8d49895d12fafd7448 /lib/chessh | |
| parent | 1a2bdccf124de6207899f59538cc0ed2efc97b5a (diff) | |
| download | chessh-0aab3c2027d54fc1ba834ab73fd53328952b7a1b.tar.gz chessh-0aab3c2027d54fc1ba834ab73fd53328952b7a1b.zip | |
Make tests pass, rename jail threshold
Diffstat (limited to 'lib/chessh')
| -rw-r--r-- | lib/chessh/ssh/daemon.ex | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/chessh/ssh/daemon.ex b/lib/chessh/ssh/daemon.ex index cd0d466..9f17f75 100644 --- a/lib/chessh/ssh/daemon.ex +++ b/lib/chessh/ssh/daemon.ex @@ -22,24 +22,24 @@ defmodule Chessh.SSH.Daemon do end def pwd_authenticate(username, password, inet) do - [jail_timeout_ms, jail_threshold] = + [jail_timeout_ms, jail_attempt_threshold] = Application.get_env(:chessh, RateLimits) - |> Keyword.take([:jail_timeout_ms, :jail_threshold]) + |> Keyword.take([:jail_timeout_ms, :jail_attempt_threshold]) |> Keyword.values() {ip, _port} = inet rateId = "failed_password_attempts:#{Enum.join(Tuple.to_list(ip), ".")}" - case Hammer.check_rate(rateId, jail_timeout_ms, jail_threshold) do - {:allow, _count} -> - pwd_authenticate(username, password) || - (fn -> - Hammer.check_rate_inc(rateId, jail_timeout_ms, jail_threshold, 1) - false - end).() + if pwd_authenticate(username, password) do + true + else + case Hammer.check_rate_inc(rateId, jail_timeout_ms, jail_attempt_threshold, 1) do + {:allow, _count} -> + false - {:deny, _limit} -> - :disconnect + {:deny, _limit} -> + :disconnect + end end end |
