Skip to content

feat: add Roadbed.Security.Pin for rotating shared-secret PINs - #77

Merged
mattonweb merged 2 commits into
mainfrom
feature/security-pin
Nov 11, 2026
Merged

mattonweb merged 2 commits into
mainfrom
feature/security-pin

Conversation

@coding-agent-roadbed

Copy link
Copy Markdown
Contributor

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, TimeProvider injected): int Generate() returns the PIN for the current window; bool Validate(int) and bool Validate(string?) check one against the current window and, when AcceptAdjacentWindows is set, the windows before and after. Malformed text returns false and never throws. 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}, each replaced with the UTC year, month, day or hour of the window's start plus OffsetYear / OffsetMonth / OffsetDay / OffsetHour (long, summed as Int128, 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, 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 PIN length outside 4 to 9.
  • InstallSecurityPin registers PinService as a singleton from the host's registered SecurityPinOptions (or the defaults) and TimeProvider.System when no clock is registered. The options are read on first resolve, so the host's PinInstaller may run before or after it.
  • Docs: the library README, the root README, and a new reference-roadbed-security-pin.md in the code-roadbed-csharp skill (at Matt's instruction) with a section on how a host sets SecurityPinOptions at start-up.
  • Commits carry no scope: security-pin is 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).

  • The six RFC 6238 Appendix B HMAC-SHA256 vectors are reproduced exactly (secret with no placeholders, 30-second window, 8 digits), checked against the RFC text.
  • A PIN made at 2026-12-31 23:59:59Z validates at 2027-01-01 00:00:05Z, when all four placeholders change.
  • Checked outside the suite: the reflection configuration binder fills the init-only options; the source-generated binder (Native AOT) skips them and keeps the public defaults. The skill warns about it.
  • The 500-line check lists no new file.

Follow-ups

  • Matt: add security-pin to the CLAUDE.md scope list and Security.Pin to its library list.
  • Each consuming product adopts the library on its own order after the 1.2.0 set is published.

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.
@coding-agent-roadbed
coding-agent-roadbed Bot marked this pull request as ready for review November 11, 2026 03:10
@mattonweb
mattonweb merged commit 7fbca68 into main Nov 11, 2026
1 check passed
@mattonweb
mattonweb deleted the feature/security-pin branch November 11, 2026 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant