IdentityLeakConfig

1. Overview

The IdentityLeakConfig module manages persistent configuration for the Identity Leak subsystem of BastionGuard. It provides a simple JSON-based configuration layer used to store API keys and feature flags related to identity monitoring.

This component is intentionally lightweight and file-based, avoiding external dependencies beyond the filesystem and JSON parsing.


2. Configuration Storage

2.1 Configuration Path

All configuration is stored in the user’s home directory under:

~/.config/BastionGuard/identity_leak.json

The module automatically ensures the directory exists before reading or writing the configuration file.


2.2 File Format

The configuration file uses JSON format. Example structure:

{
  "hibp_api_key": "your-hibp-api-key",
  "leakcheck_api_key": "your-leakcheck-api-key",
  "monitor_enabled": true
}

All fields are optional; missing fields are interpreted using safe defaults.


3. Path Resolution

3.1 configPath()

std::string IdentityLeakConfig::configPath()

Builds and returns the absolute path to the configuration file.

Behavior:

  • Reads the HOME environment variable
  • Creates ~/.config/BastionGuard if missing
  • Returns an empty string if HOME is not set

4. JSON Handling

4.1 loadJson()

json IdentityLeakConfig::loadJson()

Loads the configuration file and parses it into a JSON object.

Failure handling:

  • If the file does not exist → returns an empty JSON object
  • If JSON parsing fails → returns an empty JSON object

This design ensures configuration errors never crash the application.


4.2 saveJson(j)

void IdentityLeakConfig::saveJson(const json& j)

Serializes the provided JSON object and writes it to disk.

Details:

  • Overwrites the existing configuration file
  • Uses 4-space indentation for human readability
  • Assumes directory already exists (guaranteed by configPath())

5. API Key Management

5.1 hibpApiKey()

std::string IdentityLeakConfig::hibpApiKey()

Returns the stored API key for the Have I Been Pwned (HIBP) service.

Default behavior:

  • Returns an empty string if the key is not configured

5.2 setHibpApiKey(key)

void IdentityLeakConfig::setHibpApiKey(const std::string& key)

Stores or updates the HIBP API key in the configuration file.

Notes:

  • Overwrites any existing value
  • Does not validate the key format

5.3 leakCheckApiKey()

std::string IdentityLeakConfig::leakCheckApiKey()

Returns the API key for the LeakCheck service.

Default behavior:

  • Returns an empty string if not configured

5.4 setLeakCheckApiKey(key)

void IdentityLeakConfig::setLeakCheckApiKey(const std::string& key)

Stores or updates the LeakCheck API key.


6. Monitor Configuration

6.1 monitorEnabled()

bool IdentityLeakConfig::monitorEnabled()

Indicates whether the Identity Leak background monitor is enabled.

Behavior:

  • Returns false if the key is missing
  • Acts as a feature flag for background monitoring threads

6.2 setMonitorEnabled(enabled)

void IdentityLeakConfig::setMonitorEnabled(bool enabled)

Enables or disables the Identity Leak monitor.

This value is persisted and read at application startup.


7. Error Handling and Robustness

  • No function throws exceptions intentionally
  • Malformed JSON or missing files are handled gracefully
  • Configuration corruption results in fallback to defaults

This makes the module safe to call from UI, background services, and early startup code.


8. Security Considerations

  • API keys are stored in plaintext within the user’s home directory
  • Filesystem permissions determine confidentiality
  • No encryption or obfuscation is applied

If stronger security is required, consider:

  • Storing secrets in a system keyring
  • Encrypting the configuration file at rest
  • Restricting file permissions explicitly after write

9. Usage Context

The IdentityLeakConfig module is consumed by:

  • Identity Leak monitor initialization
  • HIBP and LeakCheck provider setup
  • Settings UI and onboarding flows

It acts as the single source of truth for Identity Leak configuration state.