Skip to content

feat(core): add alter ego model, keyed digests and token registry - #3

Merged
net0well merged 2 commits into
mainfrom
feat/core-domain-registry
Oct 23, 2026
Merged

net0well merged 2 commits into
mainfrom
feat/core-domain-registry

Conversation

@net0well

Copy link
Copy Markdown
Contributor

What changed

  • Alter ego model (namespace WalterEgo): HoneyToken with a mandatory placement, HoneyTokenId (lowercase slug, stable across restarts), HoneyTokenKind, DecoyClass (generic or unique), Severity and TriggerDomain. The constructor validates every field, so an invalid alter ego cannot exist. Tags are copied into a frozen dictionary and validated after the copy.
  • Keyed digests: ISecretHasher and SecretDigest. A digest is HMAC-SHA256 with one subkey per trigger domain, derived with HKDF-SHA256 from a key of at least 32 bytes, so the same value has a different digest in each domain. The canonical text form is 43 base64url characters without padding. Digest equality runs in constant time, and the buffer that held the hashed value is cleared after use.
  • Token registry: ITokenRegistry finds alter egos by identifier or by raw value (hashed internally, so sensors never handle keys or digests). HasTriggers lets a sensor skip a domain that has no decoys. The internal builder validates the whole set at once (identifiers, kind and trigger domain rules, duplicates, triggers shared between alter egos, text and tag limits) and reports every problem without echoing digests or values. Defaults: unique class for every kind except endpoints and users, which must state their class; low severity for generic decoys and high for unique ones.
  • Benchmark for registry lookups.

There is no entry point yet: dependency injection and configuration binding come in a later change, so no sample is affected (no-sample-impact).

How it was tested

  • dotnet build -c Release: 0 warnings, 0 errors, AOT analyzers included.
  • dotnet test: 259 passed, 152 of them in WalterEgo.Core.Tests. The digest construction is pinned by known-answer vectors computed outside .NET with an independent HKDF and HMAC implementation, including a non-ASCII value and a lone surrogate. An allocation test checks that lookups allocate nothing; adding a deliberate allocation to the lookup made it fail.
  • dotnet format --verify-no-changes: clean. dotnet list package --vulnerable --include-transitive: no vulnerable packages.
  • Benchmark on Windows, .NET 10.0.11, Xeon E5-2670 v3, registry with 100 alter egos:
Method Mean Allocated
TryMatch without a match 1.52 µs 0 B
TryMatch with a match 1.65 µs 0 B
TryMatch in a domain without triggers 0.9 ns 0 B
TryGet by identifier 17 ns 0 B

Public API impact

New public types in WalterEgo.Core: HoneyToken, HoneyTokenId, HoneyTokenKind, DecoyClass, Severity, TriggerDomain, SecretDigest, ISecretHasher and ITokenRegistry. No existing API changed.

Alter egos carry a mandatory placement and a decoy class (generic or
unique), with severity defaults derived from the class. The constructor
validates every field, so an invalid alter ego cannot exist.

Decoy values are registered only as HMAC-SHA256 digests, with one subkey
per trigger domain derived through HKDF from a key of at least 32 bytes.
Reading the configuration therefore does not reveal which values are
decoys, and the same value has a different digest in each domain.

The registry is immutable, validates the whole set at once and reports
every problem without echoing digests or values. Lookups by identifier
and by raw value do not allocate.
Measures lookups with and without a match, in a domain without
triggers and by identifier, with the memory diagnoser on.
@net0well net0well added the no-sample-impact Contract change that does not affect any sample (applied by a maintainer) label Oct 23, 2026
@net0well
net0well merged commit d5682cd into main Oct 23, 2026
10 of 11 checks passed
@net0well
net0well deleted the feat/core-domain-registry branch October 23, 2026 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-sample-impact Contract change that does not affect any sample (applied by a maintainer)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant