Files
mpc/pkg/kms/derivable_key_test.go
zeekayandHanzo Dev 02988f1b80 a key share is protected by a secret, or by nothing at all
Without client credentials the master key was derived from the project id — both
the salt and the password — so anyone holding that public identifier could
compute it and open every share it protected. It logged a warning and carried on;
a warning is not a control, and encryption under a value the world can read is
not encryption.

There is no client now rather than a weak one. Real credentials build exactly as
before, so this is about having something secret to derive from and not about the
constructor being shut.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-20 09:50:05 -07:00

32 lines
1.3 KiB
Go

package kms
import "testing"
// The key that protects a share must come from something secret. Without a
// client secret there is nothing secret to derive from — a key derived from the
// project id is computable by anyone who knows it, and a share protected that
// way is readable by them. So there is no client rather than a weak one.
func TestNoCredentialsMeansNoClient(t *testing.T) {
if _, err := NewKMSClient(KMSConfig{ProjectID: "hanzo", Environment: "prod"}); err == nil {
t.Fatal("a client was built with no credentials — its key is derivable from the project id")
}
if _, err := NewKMSClient(KMSConfig{ProjectID: "hanzo", ClientID: "id"}); err == nil {
t.Fatal("a client was built with an id but no secret")
}
if _, err := NewKMSClient(KMSConfig{ProjectID: "hanzo", ClientSecret: "s"}); err == nil {
t.Fatal("a client was built with a secret but no id")
}
}
// The paired control: real credentials still build, so the refusal is about
// having nothing to derive from and not about the constructor being shut.
func TestRealCredentialsStillBuild(t *testing.T) {
c, err := NewKMSClient(KMSConfig{ProjectID: "hanzo", ClientID: "id", ClientSecret: "a-real-secret"})
if err != nil {
t.Fatalf("credentials were refused: %v", err)
}
if len(c.masterKey) != 32 {
t.Fatalf("master key is %d bytes, want 32", len(c.masterKey))
}
}