|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
#include <TwoFaModule.h>
Public Member Functions | |
| bool | init () override |
| Initializes module resources, translations, commands, and slot mapping. | |
| bool | start () override |
| Starts the 2FA module service. | |
| void | stop () override |
| Stops the 2FA module and releases list buffers. | |
| void | onTick (uint32_t nowMs) override |
| Forwards the BLE CR state machine on the main task. | |
| const char * | getVersion () const override |
| Returns the module version string. | |
| uint8_t | getMenuItems (core::ModuleMenuItem *items, uint8_t maxItems) override |
| Provides main-menu entry for the 2FA module. | |
| core::IModule::SlotRequest | getSlotRequest () const override |
| Declares minimum slot requirements for the 2FA module. | |
| void | setSlotRange (const core::IModule::SlotRange &range) override |
| Stores assigned Tropic slot range for the module. | |
| bool | exportBackup (cJSON *out) override |
| Exports all stored OATH entries into the module's backup section. | |
| core::IModule::BackupResult | importBackup (const cJSON *in) override |
| Restores OATH entries from the module's backup section. | |
| int | challengeResponse (const char *entryName, const uint8_t *challenge, size_t clen, uint8_t *out) override |
| Computes the raw HMAC challenge-response for a named CR entry. | |
| int | challengeResponseUsbSlot (const uint8_t *challenge, size_t clen, uint8_t *out, bool *touchRequiredOut) override |
| Computes the raw HMAC response for the designated USB-CR slot entry. | |
| Public Member Functions inherited from cdc::core::ModuleBase | |
| ModuleBase (const char *name) | |
| Constructs a module base with the given module name. | |
| const char * | getName () const override |
| Returns the module name supplied to the constructor. | |
| ServiceState | getState () const override |
| Returns the current service state. | |
| Public Member Functions inherited from cdc::core::IModule | |
| virtual ui::IView * | getEntryView () |
| Returns the module's entry view (main view when selected from menu). | |
| virtual uint8_t | getLockScreenContextItems (LockScreenContextItem *items, uint8_t maxItems) |
| Returns the module's lock screen context menu items. | |
| virtual void | onUnlock () |
| Called when device is unlocked. | |
| virtual void | onLock () |
| Called when device is locked. | |
| virtual void | onUsbConnect () |
| Called when USB is connected. | |
| virtual void | onUsbDisconnect () |
| Called when USB is disconnected. | |
| Public Member Functions inherited from cdc::core::IService | |
| virtual | ~IService ()=default |
| Public Member Functions inherited from cdc::core::IChallengeResponder | |
| virtual | ~IChallengeResponder ()=default |
Static Public Member Functions | |
| static TwoFaModule & | instance () |
| Returns singleton 2FA module instance. | |
Additional Inherited Members | |
| Static Public Attributes inherited from cdc::core::IChallengeResponder | |
| static constexpr size_t | MAX_RESPONSE_LEN = 32 |
Largest possible raw HMAC response (SHA256). Callers size out to this. | |
| Protected Attributes inherited from cdc::core::ModuleBase | |
| const char * | name_ = nullptr |
| ServiceState | state_ = ServiceState::UNINITIALIZED |
Definition at line 8 of file TwoFaModule.h.
|
overridevirtual |
Computes the raw HMAC challenge-response for a named CR entry.
Delegates to OathStore, which owns the HMAC engine and entry lookup. The touch/PIN gate is enforced by the transport, not here.
| entryName | CR credential name. |
| challenge | Challenge bytes. |
| clen | Challenge length. |
| out | Output buffer (>= IChallengeResponder::MAX_RESPONSE_LEN). |
Implements cdc::core::IChallengeResponder.
Definition at line 1295 of file TwoFaModule.cpp.
References cdc::mod_2fa::OathStore::challengeResponse(), and cdc::mod_2fa::OathStore::instance().
|
overridevirtual |
Computes the raw HMAC response for the designated USB-CR slot entry.
Delegates to OathStore, which resolves the single entry flagged OathFlag::USB_CR_SLOT and reports its touch requirement.
| challenge | Challenge bytes. |
| clen | Challenge length. |
| out | Output buffer (>= IChallengeResponder::MAX_RESPONSE_LEN). |
| touchRequiredOut | Optional; receives the entry's touch-required flag. |
Implements cdc::core::IChallengeResponder.
Definition at line 1312 of file TwoFaModule.cpp.
References cdc::mod_2fa::OathStore::challengeResponseUsbSlot(), and cdc::mod_2fa::OathStore::instance().
|
overridevirtual |
Exports all stored OATH entries into the module's backup section.
Writes schema_ver and an entries array; each element carries the full set of fields needed to reconstruct the entry. Secrets are Base32-encoded so they round-trip through the existing decoder. Returns false when there are no entries to export.
| out | cJSON object that forms the module's section in the backup file. |
Reimplemented from cdc::core::IModule.
Definition at line 1383 of file TwoFaModule.cpp.
References cdc::mod_2fa::OathEntry::algorithm, cdc::mod_2fa::base32Encode(), cdc::mod_2fa::OathEntry::counter, cdc::mod_2fa::OathEntry::digits, cdc::mod_2fa::OathEntry::flags, cdc::core::TropicStorage::forEachSlot(), cdc::mod_2fa::OathStore::hasSlotRange(), cdc::core::TropicStorage::instance(), cdc::mod_2fa::OathStore::instance(), cdc::mod_2fa::OathEntry::issuer, cdc::mod_2fa::kBase32BufLen, cdc::mod_2fa::kSchemaVer, cdc::mod_2fa::OathStore::moduleId(), cdc::mod_2fa::OathEntry::name, cdc::mod_2fa::OathEntry::period, cdc::mod_2fa::OathStore::readAccount(), cdc::mod_2fa::OathStore::rmemEnd(), cdc::mod_2fa::OathStore::rmemStart(), cdc::mod_2fa::OathEntry::secret, cdc::mod_2fa::OathEntry::secretLen, cdc::mod_2fa::OathStore::toLogicalSlot(), and cdc::mod_2fa::OathEntry::type.
|
overridevirtual |
Provides main-menu entry for the 2FA module.
| items | Output array for menu items. |
| maxItems | Maximum number of writable entries in items. |
Reimplemented from cdc::core::IModule.
Definition at line 1351 of file TwoFaModule.cpp.
References cdc::core::ModuleBase::getName(), cdc::core::MAIN_MENU, cdc::mod_2fa::onListSelect(), cdc::mod_2fa::rebuildList(), cdc::mod_2fa::s_listView, cdc::mod_2fa::s_viewsInitialized, and cdc::ui::tr().
|
overridevirtual |
Declares minimum slot requirements for the 2FA module.
Reimplemented from cdc::core::IModule.
Definition at line 1338 of file TwoFaModule.cpp.
References cdc::core::ModuleBase::getName(), cdc::core::IModule::SlotRequest::mapName, and cdc::core::IModule::SlotRequest::minRmemSlots.
|
inlineoverridevirtual |
Returns the module version string.
Implements cdc::core::IModule.
Definition at line 15 of file TwoFaModule.h.
|
overridevirtual |
Restores OATH entries from the module's backup section.
Best-effort upsert by name; malformed or unstorable entries are skipped and counted, never aborting the restore.
| in | cJSON object holding the previously exported section. |
Reimplemented from cdc::core::IModule.
Definition at line 1513 of file TwoFaModule.cpp.
References cdc::ui::importJsonArray(), cdc::mod_2fa::importOathEntry(), cdc::mod_2fa::kSchemaVer, LOG_W, and TAG.
|
overridevirtual |
Initializes module resources, translations, commands, and slot mapping.
Implements cdc::core::IService.
Definition at line 1236 of file TwoFaModule.cpp.
References cdc::mod_2fa::ble_chalresp_init(), cdc::core::CHALLENGE_RESPONDER, cdc::core::ModuleRegistry::clearModuleErrorByName(), cdc::core::ERROR, cdc::core::ModuleBase::getName(), cdc::core::INITIALIZED, cdc::core::ModuleRegistry::instance(), cdc::core::ServiceRegistry::instance(), cdc::mod_2fa::OathStore::instance(), LOG_I, LOG_W, cdc::core::ServiceRegistry::provide(), cdc::mod_2fa::registerCommands(), cdc::core::ModuleRegistry::registerModule(), cdc::mod_2fa::registerStrings(), cdc::core::ModuleRegistry::reportModuleError(), cdc::mod_2fa::OathStore::setSlotRange(), cdc::core::ModuleBase::state_, and TAG.
|
static |
Returns singleton 2FA module instance.
Definition at line 1227 of file TwoFaModule.cpp.
Referenced by cdc::mod_2fa::rebuildList().
|
overridevirtual |
Forwards the BLE CR state machine on the main task.
| nowMs | Current uptime in milliseconds. |
Reimplemented from cdc::core::IModule.
Definition at line 1279 of file TwoFaModule.cpp.
References cdc::mod_2fa::ble_chalresp_tick().
|
overridevirtual |
Stores assigned Tropic slot range for the module.
| range | Slot assignment from module registry. |
Reimplemented from cdc::core::IModule.
Definition at line 1330 of file TwoFaModule.cpp.
|
overridevirtual |
Starts the 2FA module service.
Reimplemented from cdc::core::ModuleBase.
Definition at line 1267 of file TwoFaModule.cpp.
References cdc::core::INITIALIZED, cdc::core::STARTED, cdc::core::ModuleBase::state_, and cdc::core::STOPPED.
|
overridevirtual |
Stops the 2FA module and releases list buffers.
Reimplemented from cdc::core::ModuleBase.
Definition at line 1320 of file TwoFaModule.cpp.
References cdc::mod_2fa::ble_chalresp_deinit(), and cdc::mod_2fa::freeListBuffers().