-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathLockdownDisplay.cpp
More file actions
59 lines (48 loc) · 1.75 KB
/
Copy pathLockdownDisplay.cpp
File metadata and controls
59 lines (48 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "configuration.h"
#ifdef MESHTASTIC_LOCKDOWN
#include "LockdownDisplay.h"
#ifdef MESHTASTIC_ENCRYPTED_STORAGE
#include "security/EncryptedStorage.h"
#endif
#include <atomic>
namespace meshtastic_security
{
// Screen-lock latch. Set when the display powers off (idle timeout etc.),
// cleared only when a client authenticates with the passphrase. Separate
// from storage-lock state: the device keeps routing while this is set,
// only the display is gated.
//
// Initialised to true so that even a token-auto-unlocked cold boot comes
// up with a redacted screen. Otherwise an attacker holding a screen-locked
// device could simply power-cycle it (RAM latch resets) to get back to a
// content screen. Operator must authenticate from a client to reveal
// content after any boot.
//
// std::atomic so cross-task reads (PowerFSM / Screen / InputBroker) see
// writes immediately and the compiler is not free to speculate the load.
// Plain bool happens to work on single-core Cortex-M4 today but breaks
// silently the moment lockdown ports to ESP32 / RP2040 / LTO whole-program
// elision.
static std::atomic<bool> s_screenLocked{true};
bool shouldRedactDisplay()
{
#ifdef MESHTASTIC_ENCRYPTED_STORAGE
// Lockdown not active (capable build, never provisioned or disabled):
// never redact the display - behave like stock firmware.
if (!EncryptedStorage::isLockdownActive())
return false;
if (!EncryptedStorage::isUnlocked())
return true;
#endif
return s_screenLocked.load(std::memory_order_relaxed);
}
void lockScreen()
{
s_screenLocked.store(true, std::memory_order_relaxed);
}
void unlockScreen()
{
s_screenLocked.store(false, std::memory_order_relaxed);
}
} // namespace meshtastic_security
#endif // MESHTASTIC_LOCKDOWN