Repository navigation
Description
Background
Stack Encrypt (packages/stack-encrypt) is the Rust engine that every CipherStash language SDK runs on. The Go SDK (languages/golang/encrypt) runs the engine inside a WebAssembly module.
Every value is encrypted under its own data key from ZeroKMS, CipherStash's key service. A value can also be encrypted under a context: a name, such as a table or a tenant, that the ciphertext is tied to. The ciphertext then decrypts only under the same context.
In Rust, a context is optional. The simplest call takes a value and nothing else:
let ciphertext = keyset.encrypt("secret message".to_owned()).await?;
let plaintext: String = keyset.decrypt(ciphertext).await?;encrypt_with_context is the form that takes a context (packages/stack-encrypt/src/lib.rs, "Quick start").
Problem
The Go SDK cannot encrypt a value with no context. It has two gaps:
- There is no call that encrypts one value. The only way to encrypt is through a struct with
stashtags and the code thatstashgen, the SDK's generator, writes for it.CipherhasSealandOpenfor records and no method for a single value (languages/golang/encrypt/records.go:46and:114). - Every struct must declare a context.
stashgenrefuses a struct that has neither acontext=tag nor acontext_field, with "no_ struct{}field withstash:"context=..."declares the context, and no field is taggedcontext_field" (languages/golang/stashgen/read.go:255). The generator's README lists this as a refused declaration (languages/golang/cmd/stashgen/README.md:456).
So a Go program that wants to encrypt one string, a token or a file must define a struct, invent a context name, run the generator and commit the generated file. A Rust program does the same in one line.
It also means Go cannot open a value that Rust encrypted with keyset.encrypt(value), and Rust code that expects a value with no context cannot open what Go wrote.
Nothing catches this, because it is a missing feature and not a failing test. The cross-language conformance suite (conformance/stack-encrypt) has no case for a value encrypted with no context.
Proposal
- Add a call on
Cipherthat encrypts a batch of values with no context and returns oneCiphertextfor each. Add the matching call that decrypts them. They need no struct, no tag and no generated code. - Run them through the engine's own no-context path, so the bytes are the ones Rust's
keyset.encrypt(value)writes. - Keep the rule that a struct with
stashtags declares a context. This issue adds plain encryption of a value. It does not change records. - Add a conformance case: Rust encrypts a value with no context and Go opens it, and Go encrypts one and Rust opens it.
- Document the call in
languages/golang/encrypt/README.mdas the first example, before the struct tags.
Decide in the pull request whether the call also takes a form with a context, as Rust's encrypt_with_context does.
Evidence
Read on next at e62420d8e:
git grep "^func (.*\*Cipher)" -- languages/golang/encrypt/*.golists no method that takes a single value. The methods that encrypt areSeal,QueryTermand the unexportedderive, and each takes a*record.Plan.languages/golang/stashgen/read.go:255is the refusal of a struct with no context.
Not checked: whether the engine's WebAssembly guest already exports the no-context path, or needs a new export.
Relationship to other work
- docs(plans): the TypeScript SDK on Stack Encrypt, a core with EQL as an extension #1747 plans the TypeScript SDK. Its core starts with plain encryption of a value with no context. That plan first copied Go and required a context, which is how this gap was found.
Activity