tenseleyflow/shithub / 1bd7d1d

Browse files

S33: wire repo handler SecretBox from Auth.TOTPKeyB64

Authored by espadonne
SHA
1bd7d1d30a9b7d311d35624bb8fc9a1be1edb599
Parents
73d0735
Tree
023cef3

1 changed file

StatusFile+-
M internal/web/repo_wiring.go 16 0
internal/web/repo_wiring.gomodified
@@ -13,6 +13,7 @@ import (
1313
 	"github.com/jackc/pgx/v5/pgxpool"
1414
 
1515
 	"github.com/tenseleyFlow/shithub/internal/auth/audit"
16
+	"github.com/tenseleyFlow/shithub/internal/auth/secretbox"
1617
 	"github.com/tenseleyFlow/shithub/internal/auth/throttle"
1718
 	"github.com/tenseleyFlow/shithub/internal/infra/config"
1819
 	"github.com/tenseleyFlow/shithub/internal/infra/storage"
@@ -55,6 +56,20 @@ func buildRepoHandlers(
5556
 		}
5657
 	}
5758
 
59
+	// Webhook secret box (S33). Reuses the TOTP key — they're both
60
+	// at-rest AEAD-wrapped secrets. nil-tolerant: if the key is
61
+	// missing/invalid the webhook surface renders a placeholder.
62
+	var hookBox *secretbox.Box
63
+	if cfg.Auth.TOTPKeyB64 != "" {
64
+		if box, err := secretbox.FromBase64(cfg.Auth.TOTPKeyB64); err == nil {
65
+			hookBox = box
66
+		} else if logger != nil {
67
+			logger.Warn("repo: webhook secretbox unavailable",
68
+				"hint", "set Auth.TOTPKeyB64 to a base64 32-byte key",
69
+				"error", err)
70
+		}
71
+	}
72
+
5873
 	return repoh.New(repoh.Deps{
5974
 		Logger:       logger,
6075
 		Render:       rr,
@@ -62,6 +77,7 @@ func buildRepoHandlers(
6277
 		RepoFS:       rfs,
6378
 		Audit:        audit.NewRecorder(),
6479
 		Limiter:      throttle.NewLimiter(),
80
+		SecretBox:    hookBox,
6581
 		ShithubdPath: shithubdPath,
6682
 		CloneURLs: repoh.CloneURLs{
6783
 			BaseURL:    cfg.Auth.BaseURL,