CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::mod_2fa::TwoFaModule Class Reference

#include <TwoFaModule.h>

Inheritance diagram for cdc::mod_2fa::TwoFaModule:
cdc::core::ModuleBase cdc::core::IChallengeResponder cdc::core::IModule cdc::core::IService

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::IViewgetEntryView ()
 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

Detailed Description

Definition at line 8 of file TwoFaModule.h.

Member Function Documentation

◆ challengeResponse()

int cdc::mod_2fa::TwoFaModule::challengeResponse ( const char * entryName,
const uint8_t * challenge,
size_t clen,
uint8_t * out )
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.

Parameters
entryNameCR credential name.
challengeChallenge bytes.
clenChallenge length.
outOutput buffer (>= IChallengeResponder::MAX_RESPONSE_LEN).
Returns
Response length, or -1 on failure.

Implements cdc::core::IChallengeResponder.

Definition at line 1295 of file TwoFaModule.cpp.

References cdc::mod_2fa::OathStore::challengeResponse(), and cdc::mod_2fa::OathStore::instance().

◆ challengeResponseUsbSlot()

int cdc::mod_2fa::TwoFaModule::challengeResponseUsbSlot ( const uint8_t * challenge,
size_t clen,
uint8_t * out,
bool * touchRequiredOut )
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.

Parameters
challengeChallenge bytes.
clenChallenge length.
outOutput buffer (>= IChallengeResponder::MAX_RESPONSE_LEN).
touchRequiredOutOptional; receives the entry's touch-required flag.
Returns
Response length, or -1 when no entry is designated.

Implements cdc::core::IChallengeResponder.

Definition at line 1312 of file TwoFaModule.cpp.

References cdc::mod_2fa::OathStore::challengeResponseUsbSlot(), and cdc::mod_2fa::OathStore::instance().

◆ exportBackup()

bool cdc::mod_2fa::TwoFaModule::exportBackup ( cJSON * out)
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.

Parameters
outcJSON object that forms the module's section in the backup file.
Returns
true if at least one entry was exported.

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.

◆ getMenuItems()

uint8_t cdc::mod_2fa::TwoFaModule::getMenuItems ( core::ModuleMenuItem * items,
uint8_t maxItems )
overridevirtual

Provides main-menu entry for the 2FA module.

Parameters
itemsOutput array for menu items.
maxItemsMaximum number of writable entries in items.
Returns
Number of populated menu 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().

◆ getSlotRequest()

core::IModule::SlotRequest cdc::mod_2fa::TwoFaModule::getSlotRequest ( ) const
overridevirtual

Declares minimum slot requirements for the 2FA module.

Returns
Slot request structure for registry planning.

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.

◆ getVersion()

const char * cdc::mod_2fa::TwoFaModule::getVersion ( ) const
inlineoverridevirtual

Returns the module version string.

Returns
Pointer to a null-terminated version string.

Implements cdc::core::IModule.

Definition at line 15 of file TwoFaModule.h.

◆ importBackup()

cdc::core::IModule::BackupResult cdc::mod_2fa::TwoFaModule::importBackup ( const cJSON * in)
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.

Parameters
incJSON object holding the previously exported section.
Returns
Tally of imported and failed records.

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.

◆ init()

◆ instance()

TwoFaModule & cdc::mod_2fa::TwoFaModule::instance ( )
static

Returns singleton 2FA module instance.

Returns
Module singleton reference.

Definition at line 1227 of file TwoFaModule.cpp.

Referenced by cdc::mod_2fa::rebuildList().

◆ onTick()

void cdc::mod_2fa::TwoFaModule::onTick ( uint32_t nowMs)
overridevirtual

Forwards the BLE CR state machine on the main task.

Parameters
nowMsCurrent uptime in milliseconds.

Reimplemented from cdc::core::IModule.

Definition at line 1279 of file TwoFaModule.cpp.

References cdc::mod_2fa::ble_chalresp_tick().

◆ setSlotRange()

void cdc::mod_2fa::TwoFaModule::setSlotRange ( const core::IModule::SlotRange & range)
overridevirtual

Stores assigned Tropic slot range for the module.

Parameters
rangeSlot assignment from module registry.

Reimplemented from cdc::core::IModule.

Definition at line 1330 of file TwoFaModule.cpp.

◆ start()

bool cdc::mod_2fa::TwoFaModule::start ( )
overridevirtual

Starts the 2FA module service.

Returns
true if the start transition succeeded.

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.

◆ stop()

void cdc::mod_2fa::TwoFaModule::stop ( )
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().


The documentation for this class was generated from the following files: