Files
pixa/internal/seal/keys_test.go
T
sneak 534b453a81
check / check (push) Canceled after 0s
Derive every key from the signing key in one place (closes #315)
seal.DeriveKeys derives the session hash and block keys, the encrypted URL
key and the CSRF key from the signing key, with their salts declared beside
it, and returns them as one seal.Keys. internal/providers calls it once at
startup and provides the value to the fx graph. The session manager, the
encrypted URL generator and the CSRF protection each take their own key.
session.NewManager, encurl.NewGenerator, newCSRFProtect and handlers.New
return no error, as nothing in them can fail now. Each key is derived as
before, with seal.DeriveKey and the same salt. The signing key itself stays
the HMAC key of signed URLs and the login password. README.md says under
signing_key what it protects.

Model: opus-5-5
2026-10-26 13:01:57 +00:00

43 lines
960 B
Go

package seal_test
import (
"bytes"
"testing"
"sneak.berlin/go/pixa/internal/seal"
)
// TestDeriveKeys_KeysDiffer verifies that the keys DeriveKeys derives differ
// from each other and from the signing key.
func TestDeriveKeys_KeysDiffer(t *testing.T) {
t.Parallel()
// 32 bytes, as long as a derived key, so that no key differs from it by
// its length alone
const signingKey = "0123456789abcdef0123456789abcdef"
keys, err := seal.DeriveKeys(signingKey)
if err != nil {
t.Fatalf("DeriveKeys() error = %v", err)
}
named := []struct {
name string
key []byte
}{
{"the signing key", []byte(signingKey)},
{"SessionHashKey", keys.SessionHashKey[:]},
{"SessionBlockKey", keys.SessionBlockKey[:]},
{"EncryptedURLKey", keys.EncryptedURLKey[:]},
{"CSRFKey", keys.CSRFKey[:]},
}
for i, a := range named {
for _, b := range named[i+1:] {
if bytes.Equal(a.key, b.key) {
t.Errorf("%s equals %s", a.name, b.name)
}
}
}
}