Kleidos API Search

In development. It changes without notice.

Topic

Security

The lockout after wrong secrets, which lasts through a sleep or a cut in power, the log of security events, and the rule for a new secret.

  • The lockout (BruteForceGuard) counts a wrong PIN or passphrase before it is derived. From the fourth failure in a row the board waits 30 s between tries, from the seventh 300 s, and the tenth is a factory reset (Change of Owner & Resets). The count is in NVS. On a board whose clock can be trusted the end of a wait is a time; on the others it is measured from the start of the board, so a restart begins the wait again.
  • The log (AuditLog) keeps the last 16 events in NVS, with one CSV form for the SD card and the portal.
  • The rule for a new secret says, for each kind of entry, how long it may be, and which kind this board has (Unlock Entry).

The vault and every screen read the guard; nothing here reads the vault.

See also
Vault Storage, Change of Owner & Resets, Unlock Entry

Files

file src/security/audit_csv.h
Single CSV wire shape for audit-log exports.
file src/security/audit_log.h
Circular buffer of 16 security events persisted in NVS.
file src/security/board_set_surface.h
The entry surface this board sets a new unlock secret on.
file src/security/brute_force_guard.h
Counts wrong secrets and locks out the unlock, longer as they repeat.
file src/security/pin_policy.h
Single source of truth for unlock-secret length policy and for the character class of a numeric PIN.

Classes

struct kleidos::AuditEntry
Single audit entry — 6 bytes on the wire. More about kleidos::AuditEntry
class kleidos::AuditLog
Append-only circular log of AuditEvent records persisted in NVS. More about kleidos::AuditLog
class kleidos::BruteForceGuard
The unlock's attempt counter, its lockout windows and its wipe threshold. More about kleidos::BruteForceGuard
struct kleidos::security::pin_policy::PinRange
The shortest and the longest new PIN a surface with a range takes. More about kleidos::security::pin_policy::PinRange

Enumerations

enum class kleidos::AuditEvent : uint8_t { kleidos::AuditEvent::PinOk, kleidos::AuditEvent::PinFail, kleidos::AuditEvent::VaultWipe, kleidos::AuditEvent::BleType, kleidos::AuditEvent::OtaUpdate, kleidos::AuditEvent::AdminLogin, kleidos::AuditEvent::BondsForgotten, kleidos::AuditEvent::VaultExport, kleidos::AuditEvent::VaultRekey, kleidos::AuditEvent::VaultCleared }
Security-relevant event categories recorded by the audit log. More about kleidos::AuditEvent
enum class kleidos::AuditTime : uint8_t { kleidos::AuditTime::Now , kleidos::AuditTime::Later }
When an entry's time is read. More about kleidos::AuditTime
enum class kleidos::security::pin_policy::SecretKind : uint8_t { kleidos::security::pin_policy::SecretKind::Pin , kleidos::security::pin_policy::SecretKind::Passphrase }
Which kind of unlock secret a vault was provisioned with. More about kleidos::security::pin_policy::SecretKind
enum class kleidos::security::pin_policy::PinMethod : uint8_t { kleidos::security::pin_policy::PinMethod::OneHold , kleidos::security::pin_policy::PinMethod::TwoHolds }
How a board whose unlock is a timed hold of one key dials each digit. More about kleidos::security::pin_policy::PinMethod
enum class kleidos::security::pin_policy::SetSurface : uint8_t { kleidos::security::pin_policy::SetSurface::Dial , kleidos::security::pin_policy::SetSurface::Keypad , kleidos::security::pin_policy::SetSurface::Keyboard }
Which entry surface a board sets a new unlock secret on. More about kleidos::security::pin_policy::SetSurface

Functions

size_tkleidos::security::formatAuditCsvRow (const AuditEntry &entry, char *out, size_t cap)
Format one audit entry as a CSV row: timestamp,EVENT_NAME,attempts\n.
const char *kleidos::auditEventName (AuditEvent event)
Stable wire name for an audit event.
voidkleidos::security::bruteforce::testseam::setDeviceSecretProvider (bool(*provider)(uint8_t *out32))
Native-only seam to inject a deterministic device secret.
voidkleidos::security::bruteforce::testseam::resetLockState ()
Native-only seam to clear the in-RAM volatile-lock arm point.
uint32_tkleidos::security::bruteforce::testseam::lockoutRefusalReports ()
Native-only seam: lockout refusals reported since the last reset.
constexpr boolkleidos::security::pin_policy::isValidPinLength (uint8_t n)
Whether n is one of the allowed lengths of a dialed PIN.
constexpr boolkleidos::security::pin_policy::isDigitsOnly (const char *s, size_t n)
Whether s holds the character class of a numeric PIN: at least one byte, and every byte an ASCII digit.
constexpr uint8_tkleidos::security::pin_policy::digitsToNextPinLength (uint8_t n)
How many more digits a PIN being chosen needs to reach an allowed length: the next of kPinLengthOptions at or above n.
constexpr uint8_tkleidos::security::pin_policy::pinLengthOptionIndex (uint8_t n)
Position of n in kPinLengthOptions, for a picker that preselects a length.
constexpr uint8_tkleidos::security::pin_policy::clampPinLength (uint8_t n)
Coerce a (possibly stale / out-of-range) PIN length to a valid one.
constexpr SecretKindkleidos::security::pin_policy::clampSecretKind (uint8_t raw)
Coerce a raw persisted byte to a known secret kind.
constexpr PinMethodkleidos::security::pin_policy::clampPinMethod (uint8_t raw)
Coerce a raw persisted byte to a known method.
constexpr boolkleidos::security::pin_policy::freePinLengthAllowed (std::size_t n)
Whether a free-length PIN of n digits is in range.
constexpr std::span< const uint8_t >kleidos::security::pin_policy::newPinLengths (SetSurface surface)
The lengths a new PIN may take on surface, where it offers a list.
constexpr PinRangekleidos::security::pin_policy::newPinRange (SetSurface surface)
The range of lengths a new PIN may take on surface.
constexpr boolkleidos::security::pin_policy::newPinLengthAllowed (SetSurface surface, std::size_t n)
Whether a new PIN of n digits may be set on surface.
constexpr uint8_tkleidos::security::pin_policy::recordedPinLength (SetSurface surface, std::size_t typedDigits)
The PIN length a vault records for a new PIN of typedDigits set on surface.
constexpr uint8_tkleidos::security::pin_policy::clampStoredPinLength (SetSurface surface, uint8_t raw)
Coerce a recorded PIN length to one surface can collect.
constexpr uint8_tkleidos::security::pin_policy::digitsToFreePinMin (std::size_t n)
How many more digits a free-length PIN being set needs before OK answers.
constexpr boolkleidos::security::pin_policy::newPassphraseLengthAllowed (std::size_t n)
Whether a new passphrase of n characters may be set.
constexpr boolkleidos::security::pin_policy::newSecretAllowed (SetSurface surface, SecretKind kind, std::size_t n)
Whether a new secret of kind and n characters may be set on surface: the floor every surface that sets a secret checks.

Variables

constexpr const char *kleidos::security::kAuditCsvHeader
CSV header line shared by every audit export surface.
constexpr size_tkleidos::security::kAuditCsvRowCap
constexpr SetSurfacekleidos::security::pin_policy::kBoardSetSurface
This board's entry surface for a new secret.
constexpr uint8_tkleidos::security::pin_policy::kPinLengthDefault
constexpr uint8_tkleidos::security::pin_policy::kPinLengthMax
constexpr uint8_tkleidos::security::pin_policy::kPinLength
constexpr uint8_tkleidos::security::pin_policy::kPinLengthFree
constexpr std::array< uint8_t, 3 >kleidos::security::pin_policy::kPinLengthOptions
The allowed lengths of a dialed PIN, offered by the change-PIN length picker.
constexpr SecretKindkleidos::security::pin_policy::kSecretKindDefault
Secret kind of a vault provisioned before the kind was recorded.
constexpr PinMethodkleidos::security::pin_policy::kPinMethodDefault
The method a fresh device dials with, and the one Reset Settings restores.
constexpr uint8_tkleidos::security::pin_policy::kPinMethodCount
Number of methods a picker offers.
constexpr uint8_tkleidos::security::pin_policy::kPassphraseMin
constexpr uint8_tkleidos::security::pin_policy::kPassphraseSetMin
constexpr uint8_tkleidos::security::pin_policy::kPassphraseMax
constexpr uint8_tkleidos::security::pin_policy::kFreePinMin
constexpr uint8_tkleidos::security::pin_policy::kFreePinMax
constexpr uint8_tkleidos::security::pin_policy::kBackupPassphraseMin
Shortest passphrase an encrypted backup accepts (the envelope's floor).

Back to the top

Enumeration Type Documentation

AuditEvent #

enum class kleidos::AuditEvent : uint8_t

Security-relevant event categories recorded by the audit log.

Enumerator
PinOk 

Successful unlock (PIN or passphrase).

PinFail 

Failed unlock attempt (a wrong PIN or passphrase).

VaultWipe 

Vault wiped (manual or brute-force lockout).

BleType 

Credential typed over BLE HID.

OtaUpdate 

OTA firmware update applied.

AdminLogin 

Admin portal login.

BondsForgotten 

Every paired host de-bonded at once. Recoverable by re-pairing, but a pairing is what lets the device type into a machine, so all of them disappearing at once is exactly what a non-repudiation record is for. Appended, never renumbered: the value is what a stored entry holds.

VaultExport 

A full copy of the vault was written to removable media — the raw SD set or the passphrase-sealed envelope. The vault on flash is unchanged, which is exactly why it needs a record: nothing else on the device shows that every credential left it, and the export runs from three surfaces (the admin portal, both on-device vault menus, the debug console).

VaultRekey 

The vault key was rotated and the previous one destroyed. Every record on flash was rewritten, and anything the rotation could not read was skipped and is now unreadable for good — which is why the retirement, and not the opening of the rotation, is the moment worth recording.

VaultCleared 

The vault was emptied under the same secret (the vault-only wipe): every credential, one-time code and saved network went, the secret, the pairings and the access-point identity stayed. Recorded after the secret was proven and before the first byte is erased. Apart from VaultWipe, which means the owner's links went too.

AuditTime #

enum class kleidos::AuditTime : uint8_t

When an entry's time is read.

A timestamp of 0 is the log's "no time" (see AuditEntry::timestamp and AuditLog::record).

Enumerator
Now 

Read the trusted clock now; 0 when none runs.

Later 

Do not read the clock: the entry is written with no time, and AuditLog::stampTime gives it one once the clock can be read. For an entry written before hal::begin(), when a battery-backed clock's bus does not exist yet.

PinMethod #

enum class kleidos::security::pin_policy::PinMethod : uint8_t

How a board whose unlock is a timed hold of one key dials each digit.

Input only: both methods enter the same PIN under the same key and the same brute-force counter. Persisted as one stored byte, so the enumerator values are part of the stored representation — append, never renumber.

Enumerator
OneHold 

The timing arc: one hold per digit, release on the digit.

TwoHolds 

The two-step ring: one hold for the block, one for the digit.

SecretKind #

enum class kleidos::security::pin_policy::SecretKind : uint8_t

Which kind of unlock secret a vault was provisioned with.

On the touch boards a PIN and a passphrase are both typed on the same on-screen keyboard, so the board alone does not say which one opens the vault: the vault records the kind it was provisioned with, and the unlock surface then opens on the matching keyboard layer. The owner picks the kind with the keypad's ABC / 123 switch when creating the vault. The boards that dial record a PIN, and the boards with a keyboard a passphrase. The enumerator values are part of the persisted representation: append, never renumber.

Enumerator
Pin 

Numeric PIN, dialed or tapped on the touch keypad.

Passphrase 

Free-length passphrase in [kPassphraseMin, kPassphraseMax].

SetSurface #

enum class kleidos::security::pin_policy::SetSurface : uint8_t

Which entry surface a board sets a new unlock secret on.

It decides which new PIN lengths the board takes, wherever the secret is set: on the device, and through the portal's secret change on its behalf. A new passphrase takes [kPassphraseSetMin, kPassphraseMax] characters on every surface. The board's own value is kBoardSetSurface (board_set_surface.h).

Enumerator
Dial 

A timed hold of one key: a new PIN of 4, 6 or 8 digits.

Keypad 

The touch keypad: a new PIN of free length, 6 to 32 digits.

Keyboard 

A keyboard: no PIN, a passphrase only.

Back to the top

Function Documentation

auditEventName() #

const char * kleidos::auditEventName(AuditEvent event)
inline

Stable wire name for an audit event.

One table, for the admin portal and the SD export alike. With two — the portal answering WIPE / OTA / ADMIN while the SD export wrote VAULT_WIPE / OTA_UPDATE / ADMIN_LOGIN for the same three events — the same history read differently depending on where it was exported from.

Parameters
NameDirectionMeaning
eventinStored event byte cast to AuditEvent.
Returns
The event name, or "UNKNOWN" for a value this build does not know.

clampPinLength() #

uint8_t kleidos::security::pin_policy::clampPinLength(uint8_t n)
constexpr

Coerce a (possibly stale / out-of-range) PIN length to a valid one.

Parameters
NameDirectionMeaning
ninCandidate PIN length.
Returns
n when valid, else kPinLengthDefault.

clampPinMethod() #

PinMethod kleidos::security::pin_policy::clampPinMethod(uint8_t raw)
constexpr

Coerce a raw persisted byte to a known method.

Parameters
NameDirectionMeaning
rawinStored byte.
Returns
The matching method, or kPinMethodDefault for an unknown value.

clampSecretKind() #

SecretKind kleidos::security::pin_policy::clampSecretKind(uint8_t raw)
constexpr

Coerce a raw persisted byte to a known secret kind.

Parameters
NameDirectionMeaning
rawinStored discriminator byte.
Returns
The matching kind, or kSecretKindDefault for an unknown value.

clampStoredPinLength() #

uint8_t kleidos::security::pin_policy::clampStoredPinLength(SetSurface surface, uint8_t raw)
constexpr

Coerce a recorded PIN length to one surface can collect.

The dial collects fixed lengths only: a free length or any unknown byte opens the default. The touch keypad collects every PIN free (type, then OK), so every byte reads kPinLengthFree there, a fixed 4, 6 or 8 from a vault made before free lengths among them: its length is ignored for entry, and the gate weighs the secret by the free range. A keyboard keeps 4, 6 and 8 fixed and reads anything else as free.

Parameters
NameDirectionMeaning
surfaceinThe board's entry surface.
rawinThe record's pinLength byte.
Returns
A length the surface's entry can be sized to.

digitsToFreePinMin() #

uint8_t kleidos::security::pin_policy::digitsToFreePinMin(std::size_t n)
constexpr

How many more digits a free-length PIN being set needs before OK answers.

Parameters
NameDirectionMeaning
ninDigits entered so far.
Returns
0 at or past kFreePinMin, else the digits still missing.

digitsToNextPinLength() #

uint8_t kleidos::security::pin_policy::digitsToNextPinLength(uint8_t n)
constexpr

How many more digits a PIN being chosen needs to reach an allowed length: the next of kPinLengthOptions at or above n.

Parameters
NameDirectionMeaning
ninDigits entered so far.
Returns
0 when n is already allowed (or past the longest option), else the digits still missing.

formatAuditCsvRow() #

size_t kleidos::security::formatAuditCsvRow(const AuditEntry & entry, char * out, size_t cap)
inline

Format one audit entry as a CSV row: timestamp,EVENT_NAME,attempts\n.

Event names come from auditEventName, so the CSV carries the same stable wire names as the JSON form of /api/audit. The fields are a number, an identifier from a fixed table, and a number — none can contain a comma or quote, so no RFC-4180 quoting is needed.

Parameters
NameDirectionMeaning
entryinThe stored audit entry.
outoutDestination buffer, NUL-terminated on success.
capinCapacity of out in bytes (>= kAuditCsvRowCap always succeeds).
Returns
Bytes written excluding the NUL, or 0 when out cannot hold the row (nothing usable is left in out).

freePinLengthAllowed() #

bool kleidos::security::pin_policy::freePinLengthAllowed(std::size_t n)
constexpr

Whether a free-length PIN of n digits is in range.

Parameters
NameDirectionMeaning
ninThe PIN's length.
Returns
true when n is in [kFreePinMin, kFreePinMax].

isDigitsOnly() #

bool kleidos::security::pin_policy::isDigitsOnly(const char * s, size_t n)
constexpr

Whether s holds the character class of a numeric PIN: at least one byte, and every byte an ASCII digit.

The length rule is isValidPinLength; this is the other half of what makes a secret a SecretKind::Pin, for code that validates a PIN it did not collect on the dial or the numeric keypad (both of which can only produce digits).

Parameters
NameDirectionMeaning
sinBytes to inspect; need not be NUL-terminated at n.
ninNumber of bytes to inspect.
Returns
true when n is non-zero and every byte is in '0'..'9'.

isValidPinLength() #

bool kleidos::security::pin_policy::isValidPinLength(uint8_t n)
constexpr

Whether n is one of the allowed lengths of a dialed PIN.

Parameters
NameDirectionMeaning
ninCandidate PIN length.
Returns
true when n is in kPinLengthOptions.

lockoutRefusalReports() #

uint32_t kleidos::security::bruteforce::testseam::lockoutRefusalReports()

Native-only seam: lockout refusals reported since the last reset.

BruteForceGuard::getRemainingLockout logs a fail-closed read when its cause changes, not on every call, because the unlock screen reads it twice a second for as long as it fails closed. Logging is a no-op on the host, so this counts the reports instead.

Returns
Refusals that would have been logged since resetLockState().

newPassphraseLengthAllowed() #

bool kleidos::security::pin_policy::newPassphraseLengthAllowed(std::size_t n)
constexpr

Whether a new passphrase of n characters may be set.

Parameters
NameDirectionMeaning
ninThe new passphrase's length.
Returns
true when n is in [kPassphraseSetMin, kPassphraseMax].

newPinLengthAllowed() #

bool kleidos::security::pin_policy::newPinLengthAllowed(SetSurface surface, std::size_t n)
constexpr

Whether a new PIN of n digits may be set on surface.

Parameters
NameDirectionMeaning
surfaceinThe board's entry surface.
ninThe new PIN's length.
Returns
true when n is one of the dial's lengths on the dial, in the free range on the keypad; never on a keyboard.

newPinLengths() #

std::span< const uint8_t > kleidos::security::pin_policy::newPinLengths(SetSurface surface)
constexpr

The lengths a new PIN may take on surface, where it offers a list.

Parameters
NameDirectionMeaning
surfaceinThe board's entry surface.
Returns
The dial's lengths, shortest first; empty on the keypad (which takes a range, newPinRange) and on a keyboard (which sets no PIN).

newPinRange() #

PinRange kleidos::security::pin_policy::newPinRange(SetSurface surface)
constexpr

The range of lengths a new PIN may take on surface.

Parameters
NameDirectionMeaning
surfaceinThe board's entry surface.
Returns
[kFreePinMin, kFreePinMax] on the keypad; {0, 0} elsewhere.

newSecretAllowed() #

bool kleidos::security::pin_policy::newSecretAllowed(SetSurface surface, SecretKind kind, std::size_t n)
constexpr

Whether a new secret of kind and n characters may be set on surface: the floor every surface that sets a secret checks.

Parameters
NameDirectionMeaning
surfaceinThe board's entry surface.
kindinThe kind of the new secret.
ninIts length.
Returns
true when the secret meets the floor for its kind on surface.

pinLengthOptionIndex() #

uint8_t kleidos::security::pin_policy::pinLengthOptionIndex(uint8_t n)
constexpr

Position of n in kPinLengthOptions, for a picker that preselects a length.

Parameters
NameDirectionMeaning
ninA PIN length.
Returns
The index of n, or the index of kPinLengthDefault when n is not one of the options.

recordedPinLength() #

uint8_t kleidos::security::pin_policy::recordedPinLength(SetSurface surface, std::size_t typedDigits)
constexpr

The PIN length a vault records for a new PIN of typedDigits set on surface.

The keypad records kPinLengthFree: the real number of digits is stored nowhere, so the pre-unlock read (unauthenticated) shows no length and the entry offers none to stop at. The dial records the length it collects, which is already on its glass. A keyboard sets a passphrase, whose record carries the default (nothing reads it).

Parameters
NameDirectionMeaning
surfaceinThe board's entry surface.
typedDigitsinThe new PIN's length (checked by newSecretAllowed).
Returns
The byte the record's pinLength takes.

resetLockState() #

void kleidos::security::bruteforce::testseam::resetLockState()

Native-only seam to clear the in-RAM volatile-lock arm point.

The volatile-clock cooldown keeps its monotonic arm timestamp in RAM (it has the same lifetime as the monotonic source: both are lost on reboot / deep sleep). Tests call this to model a reboot — after it, a persisted lock has no in-RAM arm point, and the next read re-arms the whole persisted duration. It also forgets which lockout refusal was last reported, which is RAM too.

setDeviceSecretProvider() #

void kleidos::security::bruteforce::testseam::setDeviceSecretProvider(bool(* provider )(uint8_t *out32))

Native-only seam to inject a deterministic device secret.

The device-bound counter authentication keys its HMAC off the eFuse-HMAC / NVS-pepper device secret, which only exists on a board running the hardened build. On the host the backend is None (binding disabled), so this seam lets the host tests supply a fixed 32-byte secret and exercise the authenticate / fail-closed logic. When a provider is installed, binding is treated as enabled; passing nullptr disables it (plain-counter behavior).

Parameters
NameMeaning
providerCallback writing exactly 32 secret bytes to its argument and returning true on success, or nullptr to disable binding.

Back to the top

Variable Documentation

kAuditCsvRowCap #

size_t kleidos::security::kAuditCsvRowCap
inlineconstexpr

Worst-case bytes for one formatted row including the NUL: 10-digit timestamp + the longest event name ("BONDS_FORGOTTEN") + a 3-digit attempts counter + two commas + newline.

kFreePinMax #

uint8_t kleidos::security::pin_policy::kFreePinMax
inlineconstexpr

The longest free-length PIN: the longest secret any entry collects. A literal, so the site reads it from this header.

kFreePinMin #

uint8_t kleidos::security::pin_policy::kFreePinMin
inlineconstexpr

The shortest free-length PIN (the touch keypad): the default length of every board. A literal, so the site reads it from this header.

kPassphraseMax #

uint8_t kleidos::security::pin_policy::kPassphraseMax
inlineconstexpr

Keyboard passphrase: inclusive upper bound (also the largest unlock secret any modality can produce, so it sizes the validation buffers).

kPassphraseMin #

uint8_t kleidos::security::pin_policy::kPassphraseMin
inlineconstexpr

Keyboard passphrase: inclusive lower bound of a secret an entry tests (an unlock, the current secret). A vault set before the set floor rose keeps opening.

kPassphraseSetMin #

uint8_t kleidos::security::pin_policy::kPassphraseSetMin
inlineconstexpr

The shortest passphrase a new vault secret may be: wherever a passphrase is set (the keyboard boards, the touch keypad's ABC layer, the portal).

kPinLength #

uint8_t kleidos::security::pin_policy::kPinLength
inlineconstexpr

The default dialed PIN length as a compile-time constant, for call sites that want a "typical" PIN length. Runtime code uses the active length.

kPinLengthDefault #

uint8_t kleidos::security::pin_policy::kPinLengthDefault
inlineconstexpr

The length a new PIN takes where nobody chose one: the length every create surface preselects (setup's length page, the unlock screen over an absent vault) and the one a fresh vault records. Allowed on every surface that sets a PIN (newPinLengths). An existing vault's length is read from its meta, never from here.

kPinLengthFree #

uint8_t kleidos::security::pin_policy::kPinLengthFree
inlineconstexpr

A PIN length that is no number of digits: an entry field that does not stop at a length by itself and submits on its OK key only (a keyboard, and every PIN on the touch keypad).

kPinLengthMax #

uint8_t kleidos::security::pin_policy::kPinLengthMax
inlineconstexpr

Largest allowed length of a dialed PIN. Sizes the digit buffers so a runtime length change never reallocates; the whole buffer is always wiped.

Back to the top