You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Go SDK: KeysetID on a cipher from Client.Keyset(nil) returns the default keyset's id with no error #1998
In the Go SDK (languages/golang/encrypt), Client.Keyset(sel) returns a *Cipher bound to one keyset. It makes no request. Cipher.KeysetID(ctx) is the one call that resolves the keyset, and its doc comment says to use it "at boot to validate a tenant's keyset and learn its id".
Client.Keyset(nil) is a mistake: the default keyset is Client.DefaultKeyset. Its doc comment says it gives "a cipher whose every call fails with ErrEncoding". It stores that error on the cipher, and binds the cipher to the default keyset in the meantime.
Problem
KeysetID does not check the stored error. So client.Keyset(nil).KeysetID(ctx) returns the default keyset's id and a nil error.
A program that checks a tenant's keyset at boot with KeysetID then believes it holds a valid keyset when it does not. With a selector that came from configuration and turned out nil, the program sees the default keyset's id and carries on.
The other calls on the cipher (Seal, Open, QueryTerm, Verify, TargetLimit, Contexts and JSONOpen) all report the stored error, so encrypting through this cipher fails later. KeysetID is the only call that skips it.
The same gap applies to any other error the cipher stores: a refused Scope, Bind, Context or Audit value. KeysetID ignores those too.
The code is in languages/golang/encrypt/cipher.go (Cipher.KeysetID) and languages/golang/encrypt/client.go (Client.Keyset).
Proposal
Make Cipher.KeysetID return the cipher's stored error before it resolves anything, as every other call on the cipher does.
Add a test that calls every error-returning method on a cipher with a stored error, and checks that each one returns that error.
Activity