In development. It changes without notice.
Topic
Change of Owner & Resets
What a factory reset, a vault wipe and a settings reset erase, one sequence for every way of asking for each.
A factory reset leaves nothing of the previous owner readable on the flash. The tenth wrong secret is one, and so are the reset in settings, the portal's, and the one a board with an unreadable vault offers. It has two halves with a restart between them:
- a mark says that a wipe is pending; the vault's partition is erased and read back blank; the bonds, the host names and the access point's identity are erased; the failure count is reset once the vault is gone; and a tag on the blank partition says that the second half is owed;
- first thing in the next boot, before anything opens NVS, the whole NVS partition is erased and read back, a fresh one is made with one entry in its log that says a wipe happened, and the tag is cleared.
A cut in power at any point finishes the wipe at the next boot, before anything mounts. What holds nothing of the owner's stays: the eFuses, the firmware and which copy of it runs.
A vault wipe empties the vault under a new salt and a new vault key and keeps the secret, which must be proven in the same call, with the bonds, the access point and the preferences. A wrong secret counts as a failure.
A settings reset erases the preferences and nothing of the vault.
- See also
- Security, Vault Storage, Application States
Files | |
| file | src/ |
| The destructive effects every wipe and reset surface shares. | |
| file | src/ |
| The first half of a factory reset, as one sequence over platform steps. | |
| file | src/ |
| The second half of a factory reset, as one sequence over platform steps. | |
| file | src/ |
| The part of a change of owner that lies outside the vault, as one sequence. | |
| file | src/ |
| The Reset-Settings preference scope (kPreferenceKeys) and the NVS erase helpers. | |
| file | src/ |
| The vault-only wipe: empty the vault, keep the owner. | |
Functions | |
| bool | kleidos:: |
| Erase what ties the device to its owner outside the vault. | |
| bool | kleidos:: |
| Erase everything a change of owner must not hand over: a factory reset. | |
| bool | kleidos:: |
| Record the wipe in the audit log, then eraseForChangeOfOwner. | |
| bool | kleidos:: |
| Restore every preference to its default. The vault is untouched. | |
| FactoryResetFinish | kleidos:: |
Finish a factory reset: the second half, first thing in setup(). | |
| bool | kleidos:: |
Give the factory reset's VAULT_WIPE entry its time, once the HAL is up. | |
| WipeFinish | kleidos:: |
| Finish a wipe a power cut or a refused erase left pending. | |
| bool | kleidos:: |
| Clear the marker of a vault-only wipe the boot finished, once the owner has been told. | |
| bool | kleidos:: |
Ask arm for the wipe-pending marker up to kMarkerArmAsks times. | |
| template<typename EraseVault> | |
| ChangeOfOwnerErased | kleidos:: |
| Run the first half of a factory reset: arm the marker, erase the vault and prove it blank, erase the owner links, reset the counter, erase the core dump and write the tag. | |
| FactoryResetFinish | kleidos:: |
| Run the second half of a factory reset: erase NVS, bring it up fresh, write the audit entry, forget the crash ring, and clear the tag under the wipe-pending marker. | |
| constexpr OwnerLinksErased | kleidos:: |
| Erase the bonds, the access-point identity and the pending-admin flag. | |
| constexpr bool | kleidos:: |
Whether ns / key is in the Reset-Settings preference scope. | |
| bool | kleidos:: |
| Erase every preference key so the next boot reloads defaults. | |
| bool | kleidos:: |
| Clear the first-run onboarding state. | |
| VaultOnlyResult | kleidos:: |
Empty the vault under the secret in input, keeping that secret, the BLE bonds, the access point and the preferences. | |
| constexpr VaultOnlyResult | kleidos:: |
| The verdict for the counter's answer to a wrong secret. | |
Variables | |
| constexpr int | kleidos:: |
| constexpr PrefKey | kleidos:: |
| Every device-preference NVS entry that Reset Settings restores. | |
| constexpr std::size_t | kleidos:: |
| Number of preference entries in kPreferenceKeys. | |
Enumeration Type Documentation
FactoryResetFinish #
How the second half ended.
TagFound #
VaultOnlyVerdict #
What the vault-only wipe did, and what a surface tells the owner.
WipeFinish #
What finishInterruptedWipe did at boot.
| Enumerator | |
|---|---|
| Nothing | No wipe was pending. |
| FinishedFull | A pending FULL wipe's first half ran again: the partition is blank and the tag down; a restart finishes it. |
| FinishedVaultOnly | A pending vault-only wipe was finished: the partition was erased and read back blank; the secret it meant to keep is gone with it. The marker stays armed until acknowledgeResumedWipe. |
| StorageFault | The partition would not erase, or did not read back blank: no vault is created over it. |
| Unfinished | The partition is blank and the tag down, but NVS would not erase at the top of this boot: no vault is created, and nothing here starts another wipe. |
| Unreadable | The marker or the tag could not be read: nothing was erased on a guess, and no vault is created until a read answers. |
Function Documentation
acknowledgeResumedWipe() #
Clear the marker of a vault-only wipe the boot finished, once the owner has been told.
finishInterruptedWipe leaves it armed after a FinishedVaultOnly, so that a power cut before the boot has said the secret went has the next boot erase the (blank) partition again and say it then. BOOT_CHECK calls this once the alert has been dismissed or has timed out, before anything can provision.
- Return values
-
Value Meaning true The marker reads None. false It could not be written: no provision runs this boot, and the next boot finishes and says it again.
askMarkerArm() #
Ask arm for the wipe-pending marker up to kMarkerArmAsks times.
- Parameters
-
Name Direction Meaning arm in The platform's arm step (not null).
- Return values
-
Value Meaning true One ask armed the marker. false Every ask was refused.
clearOnboardingState() #
Clear the first-run onboarding state.
Erases the onboarding namespace so the next boot runs first-time setup. Only the debug console calls it, which leaves a device as a lost flag would: its vault, bonds and access point still stored. A factory reset takes the namespace with the rest of NVS instead (reset/).
- Return values
-
Value Meaning true The onboarding namespace is empty. false It would not open or would not clear; the next boot skips first-run setup on a device reported as factory-reset.
emptyVaultKeepingSecret() #
Empty the vault under the secret in input, keeping that secret, the BLE bonds, the access point and the preferences.
The caller holds the vault mounted (VaultStore::) for the input's assembly; this ends the mount.
- Parameters
-
Name Direction Meaning input in The typed secret, assembled against the stored vault. onProgress in Progress hook for the erase's logical fallback, or null. progressUser in Cookie for onProgress.
- Returns
- The verdict.
eraseForChangeOfOwner() #
Erase everything a change of owner must not hand over: a factory reset.
Every change-of-owner wipe is a factory reset, so nothing of the previous owner's stays recoverable from the device's flash. It runs in two halves with a restart between them, and the caller owes that restart: this is the first half, and finishFactoryReset, at the top of the next boot, is the second.
This half, in order (runChangeOfOwner):
- the wipe-pending marker is armed (kleidos::
vault:: wipe_ marker); - the whole vault partition is erased raw and walked back blank, formatting nothing (the unlock secret goes with it);
- the owner links go (eraseOwnerLinks(), which takes the BLE radio down and empties the in-RAM bond list);
- the brute-force counter is reset once the vault is gone;
- the core dump partition of a debug build's partition table is erased;
- the factory-reset tag (kleidos::
vault:: factory_ reset_ tag) is written over the blank partition.
The second half erases the whole NVS partition at the sector level (every preference, the language, the audit history, the bond keys, the host names, the access-point password, the classic ESP32's pepper, the marker) and the boot lands in first-run setup on the compile-time defaults. A cut or a refused step before the tag leaves the marker armed, so the next boot runs this half again before anything mounts (finishInterruptedWipe) and no vault is provisioned meanwhile.
Whichever task calls it, boot recovery included, every step but the owner links (the marker, the vault erase, the blank walk, the counter, the core dump erase, the tag) runs on the vault worker (Core 0), and the caller blocks feeding its own task watchdog meanwhile; a step whose dispatch could not be set up counts as not done. The owner links run on the caller. A full worker queue, or a worker that never started or has stopped, runs a step inline on the caller instead.
Writes no audit entry: use it only where the caller has already recorded the decision, as the unlock screen does when it arms its countdown. Every other surface calls performChangeOfOwnerWipe.
- Note
- De-bonding needs the BLE radio off, which the bond erase guarantees itself: it stops the radio before touching the store, so the call is safe whether or not a pairing window or a typing session left it up.
A failed raw erase falls back to removing every record-log segment, credential and one-time-code file and index segment one by one, which takes minutes on a full vault. A caller whose own clock expires over that (the admin portal tears its access point down after an unstamped idle window) passes onProgress and is called once per file.
- Parameters
-
Name Direction Meaning onProgress in Progress hook, or null when the caller needs no heartbeat (the on-device flows hold no session). progressUser in Cookie handed to onProgress.
- Return values
-
Value Meaning true The vault partition reads blank and the tag is down: the restart the caller owes finishes the reset. false The partition would not erase or read back blank, or the tag did not write. The marker stays armed; the next boot tries again. Do not tell the owner the device was reset.
eraseOwnerLinks() [1/2] #
Erase what ties the device to its owner outside the vault.
Every BLE bond, every admin access-point identity (kleidos::) and the RTC pending-admin flag, through eraseOwnerLinks(const OwnerLinkSteps&), each attempted whatever the others report. It is the part of eraseForChangeOfOwner that does not touch the vault, and that function runs it through here, so the two cannot drift apart.
Every provision in a production build runs it on its own before it writes the vault (only a debug build's console provisions without it): the unlock screen over an absent vault on a device whose first-run setup was done (what a wipe leaves, and a partition erased from outside the firmware), and first-run setup when the repeated secret matches (it runs whenever the onboarding flag reads unset, so it cannot assume a new device). The new vault must not inherit the hosts and the access point of the one before it. On a new device, and after a wipe, it finds nothing left and changes nothing.
- Note
- De-bonding needs the BLE radio off, which the bond erase guarantees itself: it stops the radio before touching the store.
- Return values
-
Value Meaning true No bond and no admin-AP identity remain. false A bond or an access-point identity survived. Do not provision a vault over it.
eraseOwnerLinks() [2/2] #
Erase the bonds, the access-point identity and the pending-admin flag.
Every step runs whatever the others report, so one that refuses never leaves the next one standing. A step a platform does not provide (a null pointer) counts as not done, so a missing hook fails closed.
- Parameters
-
Name Direction Meaning steps in The platform's erases.
- Returns
- What was erased.
finishFactoryReset() #
Finish a factory reset: the second half, first thing in setup().
Runs runFactoryResetFinish over the device: when the vault partition carries the factory-reset tag, the whole NVS partition is erased at the sector level and read back blank, a fresh NVS comes up with one VAULT_WIPE audit entry, the crash ring RTC memory holds is forgotten, and the tag's sector is erased under the wipe-pending marker, which a cut inside that erase leaves for finishInterruptedWipe. Every other boot reads 32 bytes and returns.
It must run before anything opens NVS (the crash record's mirror is the first reader): with nothing open and no radio up, no task can hold a handle the erase would pull from under it. A test asserts the order in setup().
- Returns
- How it ended;
NotPendingon every ordinary boot.
finishInterruptedWipe() #
Finish a wipe a power cut or a refused erase left pending.
BOOT_CHECK calls it before anything mounts the vault, in this order: a factory-reset tag still present (the second half failed at the top of this boot) is Unfinished; an unreadable marker or tag is Unreadable; a pending FULL wipe runs eraseForChangeOfOwner again, and the caller restarts so the second half runs; a pending vault-only wipe erases the partition again, since the secret it meant to keep has nothing left to be proven against. Without this, a partly erased partition could mount from its second superblock, or a vault be minted over un-erased blocks, and the old records would open with the old secret. A marker it cannot read erases nothing: a moment's NVS fault must not cost an owner a vault, and the provision gate keeps refusing until a read answers.
- Returns
- What it found and did.
isPreferenceKey() #
Whether ns / key is in the Reset-Settings preference scope.
Pure predicate over kPreferenceKeys (host-testable). Both strings are compared by value.
- Parameters
-
Name Direction Meaning ns in NVS namespace to test. key in NVS key to test.
- Return values
-
Value Meaning true if the entry is a device preference Reset Settings restores.
performChangeOfOwnerWipe() #
Record the wipe in the audit log, then eraseForChangeOfOwner.
The audit entry is written BEFORE acting, so a vault destroyed this way leaves a trail even when the erase does not complete (a completed reset takes it with the rest of NVS and writes one fresh VAULT_WIPE after). This is the factory reset every surface but the unlock screen runs: the admin portal's two brute-force branches and its factory reset, boot recovery, Settings' factory reset and a debug build's serial console, so none of them can drift into skipping a step. The settings menu's and the portal's "erase the vault" are the vault-only wipe instead (emptyVaultKeepingSecret), which keeps the owner's secret, links and preferences. The caller restarts afterwards, whatever it reports.
- Parameters
-
Name Direction Meaning onProgress in Handed to eraseForChangeOfOwner. progressUser in Cookie handed to onProgress.
- Returns
- What eraseForChangeOfOwner reports.
performSettingsReset() #
Restore every preference to its default. The vault is untouched.
Non-destructive to credentials by construction: kPreferenceKeys excludes onboarding, the brute-force counter and the stored secret length.
- Return values
-
Value Meaning true Every preference key was erased. false At least one survived; those settings come back at the next boot, so the surface must not report a reset.
resetPreferencesToDefaults() #
Erase every preference key so the next boot reloads defaults.
Restores device preferences to their defaults by deleting each kPreferenceKeys entry from NVS (the loaders re-seed the default when the key is absent). Leaves the vault, BLE bonds, the onboarding flag, and the brute-force counter untouched — Reset Settings keeps the vault fully usable. The caller restarts afterwards so every subsystem re-reads its default.
- Return values
-
Value Meaning true Every preference key is gone from NVS. false At least one namespace would not open or one key would not erase; the settings the owner was told were reset are still stored and come back at the next boot.
runChangeOfOwner() #
Run the first half of a factory reset: arm the marker, erase the vault and prove it blank, erase the owner links, reset the counter, erase the core dump and write the tag.
A step a platform does not provide (a null pointer) counts as not done, so a missing hook fails closed: no blank proof, no tag, and the marker stays armed. The vault erase is a callable of its own, so a platform hands it the progress hook it was given in the call that names it.
- Template Parameters
-
Name Meaning EraseVault A callable returning VaultEraseResult.
- Parameters
-
Name Direction Meaning steps in The platform's other steps. eraseVault in The vault erase.
- Returns
- What was erased.
runFactoryResetFinish() #
Run the second half of a factory reset: erase NVS, bring it up fresh, write the audit entry, forget the crash ring, and clear the tag under the wipe-pending marker.
A step a platform does not provide counts as failed, so a missing hook leaves the tag for the next boot.
- Parameters
-
Name Direction Meaning steps in The platform's steps.
- Returns
- How it ended.
timeFactoryResetEntry() #
Give the factory reset's VAULT_WIPE entry its time, once the HAL is up.
finishFactoryReset runs before hal::begin(), when a battery-backed clock's bus does not exist yet, so it writes its audit entry with no time (AuditTime::) instead of reading the clock there. Called after hal::begin() in the boot whose finishFactoryReset returned FactoryResetFinish::, this stamps that entry with the clock's time; without a trusted clock it keeps its explicit none.
- Return values
-
Value Meaning true The entry carries the clock's time. false It keeps no time (no trusted clock, or NVS refused).
wrongSecretVerdict() #
The verdict for the counter's answer to a wrong secret.
- Parameters
-
Name Direction Meaning preFail in BruteForceGuard::answer, counted.registerFailure's
- Returns
WipeDueat the threshold, elseWrongSecretwith its lockout.
Variable Documentation
kMarkerArmAsks #
How many times the first half asks for the marker: a refused NVS write is asked once more before the erase goes on without it.
kPreferenceKeys #
Every device-preference NVS entry that Reset Settings restores.
Reset Settings erases each of these so the next boot re-seeds its compile-time default. The list is every value-backed settings-model option that is a real NVS key (all of them but the pinned access-point identity, which kleidos::