Repository navigation
feat: add Roadbed.Security.Pin for rotating shared-secret PINs - #77
Merged
Merged
Conversation
Two applications that share one configuration need a cheap way to
prove it to each other on a request, without a token service. The new
library calculates a short numeric PIN from a shared secret and the
current UTC window on the producer, and recalculates it on the consumer.
Attended session with Matt; no Build Order.
- PinService (sealed, TimeProvider injected): Generate() returns the
PIN for the current window; Validate(int) and Validate(string) check
one against the current window and, when AcceptAdjacentWindows is
set, the windows before and after it. Malformed text returns false.
The calculation is TOTP (RFC 6238) with HMAC-SHA256 and the RFC 4226
truncation.
- SecurityPinOptions (init-only POCO): SecretKeyWithPatternSupport may
carry {YO} {MO} {DO} {HO}, filled from the UTC start of the window
being computed plus OffsetYear/Month/Day/Hour (long, summed as
Int128 and formatted invariant). Taking the parts from the window
start, not the call time, keeps both ends on the same key across
midnight. Defaults: the published template, four random offsets,
WindowInSeconds 600, PinLength 6 (4 to 9), AcceptAdjacentWindows
true. Every default is public; hosts override them.
- The constructor rejects a blank secret, a brace outside the four
placeholders, a window under one second and a length outside 4 to 9.
- InstallSecurityPin registers PinService as a singleton from the
host's SecurityPinOptions, or the defaults, and TimeProvider.System
when no clock is registered.
- 56 unit tests, including the six RFC 6238 Appendix B HMAC-SHA256
vectors and a PIN made at 23:59:59 on 31 December validating at
00:00:05 on 1 January.
A new library is an addition, so the set moves from 1.1.0 to 1.2.0
and CHANGELOG.md cuts 1.2.0. No existing library changes.
Verified: dotnet build 0 warnings, 0 errors; 1556 tests green.
Coding agents in the consuming products learn the Roadbed libraries from the code-roadbed-csharp skill, so the new library needs a reference there before any product adopts it. Attended session with Matt; no Build Order; the skill edit is at his instruction. - skills/code-roadbed-csharp/references/reference-roadbed-security-pin.md (new): how the PIN is calculated, MUST / MUST NOT, and the patterns for creating the values once at set-up, setting SecurityPinOptions at start-up in the host's PinInstaller (secret from KeePass, offsets from configuration, fail fast on a missing value), several purposes through keyed singletons, the producer's Bearer header, the consumer's validation, and testing with a fake clock. It warns that a missing configuration key keeps the public default, and that the source-generated configuration binder (Native AOT) skips init-only properties and keeps them all. - SKILL.md: Security.Pin in the description and its triggers, a routing-table row, and SecurityPinOptions / PinService in the options and TimeProvider bullets. - README.md: a Key Features bullet, a box in the architecture diagram and a Package Ecosystem entry. Verified: dotnet build 0 warnings, 0 errors; 1556 tests green.
mattonweb
approved these changes
Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Attended session with Matt; no Build Order.
Two applications that share one configuration need a cheap way to prove it to each other on a request, with no token service. A static API key works forever once it leaks into a log; a PIN calculated from a shared secret and the current UTC window stops working within minutes, and the secret never travels.
What
A new library, Roadbed.Security.Pin, and the set moves to 1.2.0. No existing library changes.
PinService(sealed,TimeProviderinjected):int Generate()returns the PIN for the current window;bool Validate(int)andbool Validate(string?)check one against the current window and, whenAcceptAdjacentWindowsis set, the windows before and after. Malformed text returnsfalseand never throws. The calculation is TOTP (RFC 6238) with HMAC-SHA256 and the RFC 4226 truncation.SecurityPinOptions(init-only POCO):SecretKeyWithPatternSupportmay carry{YO}{MO}{DO}{HO}, each replaced with the UTC year, month, day or hour of the window's start plusOffsetYear/OffsetMonth/OffsetDay/OffsetHour(long, summed asInt128, formatted invariant). Taking the parts from the window start rather than the call time keeps both ends on the same key across midnight, with no retry needed. Defaults: the published template, four random offsets,WindowInSeconds600,PinLength6 (4 to 9),AcceptAdjacentWindowstrue. Every default is public; hosts override them.InstallSecurityPinregistersPinServiceas a singleton from the host's registeredSecurityPinOptions(or the defaults) andTimeProvider.Systemwhen no clock is registered. The options are read on first resolve, so the host'sPinInstallermay run before or after it.reference-roadbed-security-pin.mdin thecode-roadbed-csharpskill (at Matt's instruction) with a section on how a host setsSecurityPinOptionsat start-up.security-pinis not on the charter's scope list yet, and CLAUDE.md was left alone at Matt's direction.Verification
Verified: dotnet build 0 warnings, 0 errors; 1556 tests green (1500 before, 56 new).
init-only options; the source-generated binder (Native AOT) skips them and keeps the public defaults. The skill warns about it.Follow-ups
security-pinto the CLAUDE.md scope list andSecurity.Pinto its library list.