Repeater, room server, sensor: passwords can no longer be guessed over the air at full speed, and a replayed login no longer floods a reply

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-11-18 13:03:59 +01:00
1 parent de92ca9ba2
commit dbdae14566
8 files changed
+123

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
#pragma once
#include <stdint.h>
// CUSTOM (TeTeHacko): a cap on wrong passwords. Upstream checks every login,
// so a password can be guessed over the air as fast as the channel carries
// packets, from a fresh identity each time, and a wrong one is not even
// answered. After LOGIN_FAIL_MAX wrong passwords within LOGIN_FAIL_SECS no
// password is checked until that window ends.
//
// The caller lets a client that is already an admin in the ACL through anyway:
// a login is encrypted with the sender's key, so nobody can send one in an
// admin's name, and a guessing attack cannot lock the admins out.
//
// Times are millis(), compared by difference: a clock set backwards or the
// 49-day wrap cannot stretch the window.
#ifndef LOGIN_FAIL_MAX
#define LOGIN_FAIL_MAX 4
#endif
#ifndef LOGIN_FAIL_SECS
#define LOGIN_FAIL_SECS 180
#endif
class LoginGuard {
uint32_t _since = 0; // millis() of the first failure in the window
uint16_t _fails = 0;
bool inWindow(uint32_t now_ms) const { return now_ms - _since < LOGIN_FAIL_SECS * 1000UL; }
public:
bool locked(uint32_t now_ms) const { return _fails >= LOGIN_FAIL_MAX && inWindow(now_ms); }
void failed(uint32_t now_ms) {
if (_fails == 0 || !inWindow(now_ms)) {
_since = now_ms;
_fails = 0;
}
if (_fails < LOGIN_FAIL_MAX) _fails++;
}
};