CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
TwoFaModule.cpp File Reference
#include "mod_2fa/TwoFaModule.h"
#include "mod_2fa/OathStore.h"
#include "mod_2fa/ble_chalresp.h"
#include "cdc_core/ModuleRegistry.h"
#include "cdc_core/ServiceRegistry.h"
#include "cdc_core/StringUtils.h"
#include "cdc_core/TropicStorage.h"
#include "cdc_ui/BackupImport.h"
#include "cdc_core/IKeyboardProvider.h"
#include "cdc_ui/I18n.h"
#include "cdc_ui/ViewStack.h"
#include "cdc_views/ListView.h"
#include "cdc_views/T9InputView.h"
#include "cdc_views/ToastView.h"
#include "cdc_views/RenderHelpers.h"
#include "cdc_hal/IDisplay.h"
#include "serial_cmd/ICommandRegistry.h"
#include "serial_cmd/SubCommand.h"
#include "serial_cmd/Console.h"
#include "cdc_log.h"
#include "esp_attr.h"
#include "cJSON.h"
#include <goodisplay/gdey029T94.h>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <new>

Go to the source code of this file.

Classes

class  cdc::mod_2fa::OathCodeView
struct  cdc::mod_2fa::WizardState

Namespaces

namespace  cdc
namespace  cdc::mod_2fa

Functions

static void cdc::mod_2fa::registerStrings ()
static uint8_t cdc::mod_2fa::parseAlgo (const char *token)
 Parses textual or numeric algorithm identifiers into store values.
static uint8_t cdc::mod_2fa::parseType (const char *token)
 Parses a textual or numeric entry-type token.
static bool cdc::mod_2fa::findSlotByIndex (uint16_t index, uint16_t *slotOut)
 Resolves a displayed list index to the logical OATH slot number.
static void cdc::mod_2fa::cmd_totp_list (const char *args)
 Serial command handler printing all configured OATH entries.
static void cdc::mod_2fa::cmd_totp_add (const char *args)
 Serial command handler adding an OATH entry from tokens.
static void cdc::mod_2fa::cmd_totp_del (const char *args)
 Serial command handler deleting an OATH entry by index.
static void cdc::mod_2fa::cmd_totp_get (const char *args)
 Serial command handler generating one code by index.
static int cdc::mod_2fa::hexDecode (const char *hex, uint8_t *out, size_t outMax)
 Decodes a hex string into bytes.
static void cdc::mod_2fa::cmd_chalresp (const char *args)
 Serial command computing a raw challenge-response for a named CR entry.
static void cdc::mod_2fa::cmd_totp (const char *args)
static void cdc::mod_2fa::registerCommands ()
 Registers serial commands exposed by the 2FA module.
static void cdc::mod_2fa::wizardEdit (uint16_t slot)
 OATH code detail view implementation.
static void cdc::mod_2fa::pushT9WizardStep (const char *title, const char *initialText, uint16_t maxLen, ui::T9InputView::SaveCallback onSave)
 Pushes a configured T9 input step for the account wizard flow.
static void cdc::mod_2fa::freeListBuffers ()
 Frees dynamically allocated list buffers used by the account list.
static void cdc::mod_2fa::rebuildList ()
 Rebuilds the account list view content from Tropic storage cache.
static void cdc::mod_2fa::onListSelect (uint16_t index, void *userData)
 Handles selection from the account list.
static void cdc::mod_2fa::wizardStart ()
 Starts the add-account wizard with default values.
static void cdc::mod_2fa::onWizardType (uint16_t index, void *userData)
 Saves selected entry type and opens the name step.
static void cdc::mod_2fa::onWizardName (const char *text)
 Saves wizard account name and opens secret step.
static void cdc::mod_2fa::onWizardSecret (const char *text)
 Saves wizard secret and opens issuer step.
static void cdc::mod_2fa::onWizardIssuer (const char *text)
 Saves wizard issuer and opens digit-selection step.
static void cdc::mod_2fa::onWizardDigits (uint16_t index, void *userData)
 Saves selected code length and opens algorithm-selection step.
static void cdc::mod_2fa::onWizardAlgo (uint16_t index, void *userData)
 Saves selected algorithm; opens period step (TOTP) or finishes (HOTP).
static void cdc::mod_2fa::onWizardPeriod (uint16_t index, void *userData)
 Saves selected period and finalizes add/edit operation.
static void cdc::mod_2fa::onWizardTouch (uint16_t index, void *userData)
 Saves the CR touch-confirm choice and finalizes the entry.
static void cdc::mod_2fa::onWizardUsbCr (uint16_t index, void *userData)
 Saves the USB-CR-slot designation and finalizes the entry.
static void cdc::mod_2fa::pushAlgoStep ()
 Pushes the algorithm-selection step.
static void cdc::mod_2fa::pushTouchStep ()
 Pushes the CR touch-confirm toggle step.
static void cdc::mod_2fa::pushUsbCrStep ()
 Pushes the CR USB-slot-2 designation step.
static void cdc::mod_2fa::wizardFinish ()
 Validates wizard data and persists account changes.
static void cdc::mod_2fa::base32Encode (const uint8_t *data, size_t dataLen, char *out, size_t outMax)
 Encodes binary secret bytes into unpadded Base32 text.
static bool cdc::mod_2fa::ensureListBuffers ()
 Ensures account list backing buffers are allocated for current capacity.
static bool cdc::mod_2fa::importOathEntry (const cJSON *entry, void *user)
 Maps and upserts one OATH entry from its JSON representation.
void mod_2fa_register ()
 Registers 2FA module initializer in the global module registry.
const char * cdc::mod_2fa::skipSpaces (const char *s)
 Advances over leading ASCII whitespace in a C string.
const char * cdc::mod_2fa::nextToken (const char *s, char *out, size_t outSize)
 Extracts one whitespace-delimited token from a string.

Variables

static const char * TAG = "2FA"
constexpr ui::I18nEntry cdc::mod_2fa::kStrings []
static constexpr const char * cdc::mod_2fa::CMD_MODULE = "totp"
 Serial command handlers for 2FA module.
static constexpr size_t cdc::mod_2fa::SECRET_B32_LEN = 128
static bool cdc::mod_2fa::s_commandsRegistered = false
static const cdc::serial::SubCommand cdc::mod_2fa::kTotpSubs []
 Sub-command table for the TOTP serial command group.
static ui::ListView cdc::mod_2fa::s_listView
 2FA module UI state.
static ui::T9InputView cdc::mod_2fa::s_t9Input
static ui::ListView cdc::mod_2fa::s_typeMenu
static ui::ListView cdc::mod_2fa::s_digitsMenu
static ui::ListView cdc::mod_2fa::s_algoMenu
static ui::ListView cdc::mod_2fa::s_periodMenu
static ui::ListView cdc::mod_2fa::s_touchMenu
static ui::ListView cdc::mod_2fa::s_usbCrMenu
static OathCodeView cdc::mod_2fa::s_codeView
static bool cdc::mod_2fa::s_viewsInitialized = false
static ui::ListItemcdc::mod_2fa::s_listItems = nullptr
 Dynamic list buffers released by freeListBuffers.
static char(* cdc::mod_2fa::s_listLabels )[24] = nullptr
static uint16_t * cdc::mod_2fa::s_listSlots = nullptr
static uint16_t cdc::mod_2fa::s_accountCount = 0
static uint16_t cdc::mod_2fa::s_capacity = 0
static WizardState cdc::mod_2fa::s_wizard = {}
static constexpr int cdc::mod_2fa::kSchemaVer = 1
 Schema version written to and expected from the 2FA backup section.
static constexpr size_t cdc::mod_2fa::kBase32BufLen = 103 + 1
 Maximum Base32 string length for the longest supported secret (64 bytes raw).

Function Documentation

◆ mod_2fa_register()

void mod_2fa_register ( )

Registers 2FA module initializer in the global module registry.

Definition at line 1532 of file TwoFaModule.cpp.

References cdc::core::ModuleRegistry::instance(), and cdc::core::ModuleRegistry::registerInitializer().

Variable Documentation

◆ TAG

const char* TAG = "2FA"
static

Definition at line 29 of file TwoFaModule.cpp.