<- Architecture · Back to README
NetBox stores session credentials and sensitive configuration data. The master password feature provides optional encryption for stored passwords using AES-256.
When enabled, the master password encrypts all stored session passwords with AES-256-CBC plus HMAC-SHA256 for integrity. The master password itself is never stored on disk; only a verifier hash is kept to validate the password on entry.
User enters master password
|
v
[Verifier check] ------> AES256Verify()
|
Valid password
|
v
[Password storage]
Session password ------> AES256EncryptWithMAC(master_password, plaintext)
|
v
Encrypted blob stored in registry/INI
| Component | File | Purpose |
|---|---|---|
TSecureString |
src/base/SecureString.cpp |
Secure memory buffer with VirtualLock + SecureZeroMemory |
TWinConfiguration |
src/windows/WinConfiguration.cpp |
Master password state, verifier, session counter |
AES256EncryptWithMAC |
src/core/Cryptography.cpp |
AES-256-CBC encryption with HMAC-SHA256 |
AES256Verify |
src/core/Cryptography.cpp |
Password verifier validation |
Password plaintext is held in TSecureString rather than UnicodeString:
VirtualLock— Attempts to pin the memory page to RAM (prevents swap-to-disk). Falls back gracefully if the privilege is unavailable.SecureZeroMemory— Overwrites buffer before deallocation.- Move-only — No copy constructor; prevents accidental duplication.
- RAII — Destructor automatically wipes the buffer.
Master password sessions use std::atomic counters:
FMasterPasswordSession— Tracks nested password-access sessions viafetch_add/fetch_subFMasterPasswordSessionAsked— Atomic flag prevents redundant prompts during parallel transfers
Both counters use std::memory_order_relaxed on x86/x64 where lock-free atomics are guaranteed.
To prevent brute-force attacks on the master password verifier:
- 5 consecutive failures trigger a 30-second lockout
- Successful validation resets the failure counter
GetTickCount()is used for Windows XP compatibility- Counter and timestamp are stored in
std::atomic<uint32_t>fields
When the master password is changed or cleared, all stored session passwords are re-encrypted:
ChangeMasterPassword()/ClearMasterPassword()callsRecryptPasswords()RecryptPasswords()iterates all stored sessions viaTTerminalManager::RecryptPasswords()- Errors are collected in a
TStringListand displayed to the user - Exception-safe
try__finallyblocks ensure the decrypt key is always updated/shredded even if recryption fails
IsValidPassword() enforces minimum strength:
- At least 6 characters
- Mixed case + digits + special characters recommended
- Weak passwords trigger a confirmation dialog
When no master password is set, session passwords are stored with a simple scramble (XOR-based obfuscation) rather than encryption. This provides basic protection against casual inspection but is not cryptographically secure.
- Enable master password on shared or unattended machines
- Use a strong password — at least 12 characters with mixed case, digits, and symbols
- Do not store passwords for highly sensitive environments; use key-based authentication instead
- Review logs — Passwords are masked in
LogEvent()output when master password is active
- Architecture — Layered plugin architecture
- Contributing — Code conventions