docs(19.6): decide the OTP, WebAuthn and QR libraries

pquerna/otp v1.5.0, go-webauthn/webauthn v0.18.2 and boombuler/barcode
v1.1.0 (QR, with the plugin's own SVG writer), imported only by
sm-mfa-plugin and gated by a blocking human package check.
This commit is contained in:
2026-10-26 09:49:40 +01:00
parent ecc34bc35a
commit 24d9d2a401
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
# Decision: second factors use pquerna/otp, go-webauthn and boombuler/barcode, in sm-mfa-plugin only
**Date:** 2026-10-21
**Status:** Accepted
**Context:** Phase 19.6 (two-factor auth and device flow, D-01, D-04, D-06, D-08, D-14), 19.6-RESEARCH.md Q1, Q2, Q3 and Package Legitimacy Audit
## Decision
The second factors (TOTP, WebAuthn, email codes, recovery codes, trusted devices) live in the new shared plugin `sm-mfa-plugin`, which requires `sm-user-plugin` (D-01). Three third-party modules carry the protocol work; everything else is the standard library and the framework.
- **`github.com/pquerna/otp` pinned at v1.5.0.** Published 2024-12-31, Apache-2.0. Packages `totp` and `hotp` only. Issuer is the application name, the account is the user's email, the validation window is plus or minus one step, SHA1, 6 digits, 30 s period (the Google Authenticator defaults PHP used). Replay protection is done per counter with `hotp` (RESEARCH Pitfall 5).
- **`github.com/go-webauthn/webauthn` pinned at v0.18.2.** Published 2026-09-19, BSD-3-Clause. Packages `webauthn` and `protocol` only. Attestation `none`, timeout 60 s, user verification `preferred` for second-factor use and `required` for passkeys (D-14). Ceremony state stays server-side.
- **`github.com/boombuler/barcode` pinned at v1.1.0 (package `qr` only) for the TOTP QR code.** MIT. It is already a requirement of pquerna/otp (for `Key.Image()`), so it adds no module and no maintainer. sm-mfa-plugin writes the SVG itself (a small serializer emitting one `<path>` for the dark modules, `width="200" height="200"` with a `viewBox`, as PHP's Bacon `RendererStyle(200)` did), so PHP's TOTP setup contract `{secret, qr_code_svg, qr_code_url}` stays. The round trip was proven during research: a TOTP URL encoded at level M was read back byte for byte by an independent decoder (RESEARCH Q2, Assumption A1).
- **Slow hash for recovery and email codes: bcrypt** through `bouncer.HashPassword` / `bouncer.CheckPassword` at `golem15.user.password.bcrypt_cost`, exactly as the user plugin hashes passwords (D-06). No argon2: it would add `golang.org/x/crypto/argon2` usage the framework does not have. Ten compares at cost 10 measured 631 ms (RESEARCH Q3).
## Measurements (RESEARCH Q1)
- **Binary size: +2,269,184 bytes (+2.16 MiB)** on a stripped build of the demo application (`-trimpath -ldflags="-s -w"`): 51,802,375 to 54,071,559 bytes, with TOTP generate and validate, QR encode, and the WebAuthn registration, login and passkey-login paths driven by a probe.
- **Nine newly linked modules** (`go version -m` diff): `github.com/boombuler/barcode` v1.1.0, `github.com/fxamacker/cbor/v2` v2.9.4, `github.com/go-webauthn/webauthn` v0.18.2, `github.com/go-webauthn/x` v0.3.1, `github.com/google/go-tpm` v0.9.8, `github.com/philhofer/fwd` v1.2.0, `github.com/pquerna/otp` v1.5.0, `github.com/tinylib/msgp` v1.6.4, `github.com/x448/float16` v0.8.4.
- **One version bump in consuming graphs:** minimal version selection moves `github.com/go-viper/mapstructure/v2` from v2.4.0 to v2.5.0 in the module graph of applications that mount the plugin. `golang-jwt/jwt/v5` v5.3.1, `google/uuid` v1.6.0 and `golang.org/x/crypto` v0.57.0 are already at go-webauthn's versions.
- **Vulnerabilities:** `govulncheck` v1.9.0 reports no reachable vulnerability. The only module-level advisory, GO-2026-5932 (`golang.org/x/crypto/openpgp`, unmaintained), sits in a package nothing imports.
- go-webauthn's go.mod lists the archived YAML v3 module as an indirect, test-only requirement outside the import graph. Plugin code never imports it (CLAUDE.md: `goccy/go-yaml` only).
## Deviation from PHP recorded here (D-08)
WebAuthn requests and responses use go-webauthn's standard base64url shapes (`PublicKeyCredentialCreationOptions`, `PublicKeyCredentialRequestOptions` and the attestation and assertion JSON that `navigator.credentials` and `@simplewebauthn/browser` produce), not PHP's lbuchs plain-base64 layout. The paths and outer keys stay PHP's. This is acceptable because no client implements the PHP layout yet. PHP stored PEM public keys while go-webauthn verifies COSE keys, so the Phase 30 Winter import must convert or drop WebAuthn rows.
## Rejected alternatives
- **`github.com/piglig/go-qr` v1.1.0** (native `ToSVGBytes`). 67 stars, one maintainer, and a new module for what boombuler already provides through pquerna/otp's graph.
- **argon2id for codes.** Not what the user plugin uses for passwords; D-06 asks to match it.
- **A hand-written TOTP or WebAuthn implementation.** Protocol and security code goes to a maintained library with a decision note (project preference).
## Related dependencies
- `golang.org/x/crypto`, `github.com/golang-jwt/jwt/v5` and `github.com/google/uuid` are already in the framework and application graphs at the versions go-webauthn needs.
## Package legitimacy
The package-legitimacy seam cannot check Go modules (as in 19.4 and 19.5), so all three are [ASSUMED] for legitimacy and gated by a blocking human check (plan 19.6-01 Task 5) before any `go get`. Signals gathered by hand: pquerna/otp v1.5.0 on proxy.golang.org (2,963 stars, Apache-2.0); go-webauthn/webauthn v0.18.2 (1,351 stars, BSD-3-Clause, pushed 2026-10-20); boombuler/barcode v1.1.0 (published 2025-07-22, 1,563 stars, MIT).
## Consequences
- Only `sm-mfa-plugin`'s go.mod requires the three modules. `sm-user-plugin`, the framework and fonoteka.go require none, and applications without the plugin link none of the nine modules (D-01).
- go-webauthn is pre-1.0 and the research is valid until 2026-11-20. After that date the executor re-checks the pin with `go list -m -json github.com/go-webauthn/webauthn@latest` before installing.
- Installation, only after the human check: `go get github.com/pquerna/otp@v1.5.0 github.com/go-webauthn/webauthn@v0.18.2 github.com/boombuler/barcode@v1.1.0` inside `sm-mfa-plugin`, then `go mod tidy`.

View File

@@ -55,6 +55,9 @@ This extends `.planning/research/go-ecosystem.md` (2026-09-16 GitHub-API-verifie
| `github.com/charmbracelet/colorprofile` | v0.4.3 | Color profile detection and downsampling writer (`--ansi`, `--no-ansi`, `NO_COLOR`) | Decided in .planning/notes/2026-10-21-console-charm-stack.md (Phase 19.8 D-02); imported only by modules/bonfire and modules/diary |
| `github.com/modelcontextprotocol/go-sdk` (packages `mcp`, `auth`, `oauthex`, `jsonrpc`) | v1.8.0 | MCP server, sessions, streamable HTTP transport, bearer middleware, RFC 9728 metadata, test client for the `pier` module | Decided in .planning/notes/2026-10-22-mcp-go-sdk.md (Phase 19.7 D-24, D-33); imported only by modules/pier and the tagged modules/surf/pier_on.go, linked only with the `summercms_mcp` build tag |
| `github.com/google/jsonschema-go` (package `jsonschema`) | v0.4.3 | Reflects MCP tool input and output schemas from Go structs and validates call arguments | Decided in .planning/notes/2026-10-22-mcp-go-sdk.md (Phase 19.7 D-24); the schema library the SDK itself uses; imported only by modules/pier |
| `github.com/pquerna/otp` (packages `totp`, `hotp`) | v1.5.0 | TOTP generation and validation, otpauth URL, for the TOTP second factor | Decided in .planning/notes/2026-10-21-mfa-otp-webauthn.md (Phase 19.6 D-04); imported only by sm-mfa-plugin |
| `github.com/go-webauthn/webauthn` (packages `webauthn`, `protocol`) | v0.18.2 | WebAuthn registration and assertion, passkeys | Decided in .planning/notes/2026-10-21-mfa-otp-webauthn.md (Phase 19.6 D-04); imported only by sm-mfa-plugin |
| `github.com/boombuler/barcode` (package `qr`) | v1.1.0 | QR matrix for the TOTP setup SVG (the plugin writes the SVG) | Decided in .planning/notes/2026-10-21-mfa-otp-webauthn.md (Phase 19.6 D-04); imported only by sm-mfa-plugin |
### Development Tools