Files

4.2 KiB

Security Hardening, SecureBuffer, Versioned Envelopes, Authorization & Authenticator

Task ID: M-SECURITY-01..04 Phase: P2 (Wave 6B) Status: APPROVED Contracts: C-02, C-03, C-04, C-05, C-07, C-09, C-13

1. Context and baseline

Void::Security preserves all 1.x APIs (generateToken, hashToken, verifyToken, hashPassword, verifyPassword, generateSecretKey, sealSecret, openSecret) and the exact legacy secret envelope format (24B nonce || secretbox_easy(16B MAC + ciphertext)), while adding SecureBuffer, input/cost validation (parse_argon2id_cost, verify_password_budgeted), versioned VSEC v1 AEAD envelopes + SecretKeyRing rotation, typed default-deny Authorization, and a separate SecurityAsync module (Authenticator, AccountSessionPort, InMemoryAccountSessionStore, PasswordJobBudget, AuditSink) so primitive Security remains free of Async/Resilience/Storage dependencies.

2. Deliverables

  • src/Security/module.cmake (INTERNAL_DEPS Functional Time, EXTERNAL_DEPS Sodium::Sodium, EXCLUDE_HEADERS Void/Security/Authenticator.hpp) & src/SecurityAsync/module.cmake (INTERNAL_DEPS Security Async Time Resilience Functional, EXTRA_HEADERS Void/Security/Authenticator.hpp).
  • include/Void/Security/Types.hpp: kSecurityErrorDomain = 19, SecurityErrorCode, make_security_error, SecurityLimits (1 KiB password/hash, 512 B token, 16 MiB plaintext, 64 roles, 4096 rules, 16 predicate depth), PasswordVerifyBudget, Argon2idCost.
  • include/Void/Security/SecureBuffer.hpp & src/Security/SecureBuffer.cpp: move-only SecureBuffer with LockPolicy::{StandardWiped, LockedOptional, LockedRequired} (fail-closed if locked allocation fails), sodium_memzero wipe on release/move, optional fault hook.
  • include/Void/Security/Security.hpp & src/Security/Security.cpp: preserve 1.x surface + enforce input caps, parse_argon2id_cost, verify_password_budgeted rejecting excessive m/t before Argon2id allocation, backend init/randomness fault seam.
  • include/Void/Security/Envelope.hpp & src/Security/Envelope.cpp: versioned VSEC v1 crypto_aead_xchacha20poly1305_ietf envelope authenticating header + key_id + aad, SecretKeyRing (active-key writes, multi-key reads, checked retirement), zero silent legacy fallback.
  • include/Void/Security/Authorization.hpp & src/Security/Authorization.cpp: Principal (<=64 roles), typed Predicate (depth <=16), PolicySnapshot (<=4096 rules, default-deny, deny-overrides-allow, authorize).
  • include/Void/Security/Authenticator.hpp & src/SecurityAsync/Authenticator.cpp: AccountSessionPort, InMemoryAccountSessionStore, PasswordJobBudget (512 MiB / 2 active / 32 waiters), SessionPolicy (10,000 total / 16 per subject / 1h TTL / 60s civil-clock rollback check / 256 cleanup batch), mandatory AuditSink, Authenticator (dummy-hash timing-work parity, credential-version CAS, non-interruptible drain-on-stop, zero positive session cache, close_and_join).
  • tests/standalone/Security/SecurityHardening.cpp, tests/standalone/SecurityAsync/SecurityAsync.cpp, tests/package/{SecurityOnly,SecurityAsyncOnly}/*, registered in tests/package/InstalledComponents.cmake.

3. Edge cases

  • Legacy sealSecret/openSecret bytes remain bit-for-bit compatible; Envelope never guesses legacy decoding after AEAD failure.
  • Unknown account and wrong password execute comparable Argon2id work via a precomputed dummy hash and return identical public denial while recording distinct internal audit reasons.
  • Cancelling during password verification returns cancelled, retains budget/buffers until the Argon2id job completes, discards output, and never writes a session.
  • Civil-clock rollback exceeding configured tolerance (default 60s) fails session admission until reconciled.

4. Verification commands

dev cpp-gcc -p libsodium -c bash -lc 'cmake -S . -B /tmp/void-w6b-security -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DVOID_ENABLED_MODULES="Security;SecurityAsync;Testing" -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-w6b-security && /tmp/void-w6b-security/tests/VoidTests --filter "Security*|security_*" && ctest --test-dir /tmp/void-w6b-security --output-on-failure --timeout 120'