Kantoor.KnownLoginIps (Kantoor v1.0.0)

Remembers which IPs recently verified successfully for a login, so a flood of failures against that login (see Kantoor.AppPasswords) can refuse unknown IPs while the owner's usual networks keep working.

Why a table and not ETS: ETS is forgotten on every deploy or restart, and the moment right after a restart is exactly when an ongoing attack would lock the real user out. The table is tiny: one row per (login, IP) pair, at most max_per_login rows per login, entries expire after ttl_days. Logins and IPs are stored only as HMAC-SHA256 digests keyed from secret_key_base.

Summary

Functions

Keyed digest of an IP, normalised with Kantoor.IP.normalize/1.

Did ip_hash verify for login_hash within the last ttl_days?

Short, safe-to-log label for a login hash.

Keyed digest of a normalised login (32 bytes).

Records a successful verification. Writes at most once a day per pair, drops expired rows and keeps only the newest max_per_login rows for the login.

Functions

ip_hash(ip)

@spec ip_hash(term()) :: binary()

Keyed digest of an IP, normalised with Kantoor.IP.normalize/1.

known?(login_hash, ip_hash, now, opts \\ [])

@spec known?(binary(), binary(), DateTime.t(), keyword()) :: boolean()

Did ip_hash verify for login_hash within the last ttl_days?

label(hash)

@spec label(binary()) :: String.t()

Short, safe-to-log label for a login hash.

login_hash(login)

@spec login_hash(String.t()) :: binary()

Keyed digest of a normalised login (32 bytes).

record(login_hash, ip_hash, now, opts \\ [])

@spec record(binary(), binary(), DateTime.t(), keyword()) :: :ok

Records a successful verification. Writes at most once a day per pair, drops expired rows and keeps only the newest max_per_login rows for the login.