Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 72 additions & 14 deletions conformance/stack-encrypt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ These files read or copy cases, and are not runners:

| File | Profile | What it reads |
|---|---|---|
| `languages/typescript/packages/recipher-js/value-napi/tests/testdata/corpus-frames.json` | `record-values-v1` | The frames of the corpus cases that the TypeScript value bridge must write. `tests/frames.cjs` regenerates it with `RECIPHER_UPDATE_FIXTURES=1`, and `scripts/__tests__/recipher-js-frame-parity.test.mjs` holds it to the corpus. |
| `languages/typescript/packages/recipher-js/value-napi/tests/testdata/corpus-frames.json` | `record-values-v1`, `record-scalars-v1` | The frames of the corpus cases that the TypeScript value bridge must write. It also holds the text and spellings of each UUID case of `record-scalars-v1`, which `tests/frames.cjs` writes a frame from. `tests/frames.cjs` regenerates it with `RECIPHER_UPDATE_FIXTURES=1`, and `scripts/__tests__/recipher-js-frame-parity.test.mjs` holds it to the corpus. |
| `scripts/__tests__/stack-exchange-conformance.test.mjs` | `record-values-v1` | The IDs of the positive cases, to build test artifacts. |
| `scripts/__tests__/stack-eql-conformance.test.mjs` | `eql-json-v1` | The documents and the reasons of `invalid_documents`. |
`fixture-enrollment.json` is the one file not named after a profile: it maps
Expand Down Expand Up @@ -253,13 +253,33 @@ versions, profiles, capabilities and input types fail. Every case must run.
The profile fixes a one-field record with ciphertext (`c`) and equality (`eq`)
outputs. Its field context is the record context followed by the field name.
Each case declares the field's `kind` and a typed `input`. `input.text` is the
literal string value, canonical base-10 integer, `true`/`false`, or empty text
for null, as determined by `input.type`. Runners construct real typed host
values, preserving integer width. JSON numbers are deliberately not used for
values: future TypeScript runners must not pass 64-bit integers through Number.
literal string value, canonical base-10 integer, `true`/`false`, bytes in hex,
a UUID, or empty text for null, as determined by `input.type`. Runners
construct real typed host values, preserving integer width. JSON numbers are
deliberately not used for values: future TypeScript runners must not pass
64-bit integers through Number.

The initial positives cover int32 and int64 bounds, uint64 max, an integer
above JavaScript's safe-integer limit, Unicode text and empty text. For each:
A UUID is written in lowercase hex, in groups of 8, 4, 4, 4, and 12 digits,
with `-` between them.

An accepted case with a UUID input can also have
`spellings`: the same UUID in other letter cases. The Rust and Go runners
and the frame parity test refuse `spellings` on any other case. A runner whose language makes a UUID
from text reads each spelling. Each spelling must give the same UUID and the
same frozen frame. Go reads them with `vcvalue.ParseUUID`, Rust with the `uuid`
crate, and the TypeScript value bridge with `VcUuid`.

The engine itself never reads UUID text: a string is not a UUID, so a UUID
field refuses one.

The positive cases cover these values:

- the int32 and int64 bounds, and the uint64 maximum
- an integer above JavaScript's safe-integer limit
- Unicode text, and empty text
- an ordinary UUID, the nil UUID (all zeros), and the max UUID (all ones)

For each positive case:

1. The encoded typed frame must equal the frozen frame, including its type.
2. Record encryption and opening must preserve both value and type.
Expand All @@ -279,13 +299,38 @@ above JavaScript's safe-integer limit, Unicode text and empty text. For each:
Negative cases have `expected_error` and exercise the equality query only.
They require the exact engine diagnostic `code`, `reason`, and field name;
Go must also expose `ErrEncoding`. Native Rust verifies rejection occurs
before data-key generation or retrieval. String/bool inputs for an integer
field and a null query are currently covered. Error prose is not contractual.

Boolean equality is not admitted by the current engine. Boolean scalar
encryption, nullable records, other numeric kinds, bytes, JSON, EQL targets,
other operators, declarations, cancellation and provider failures need later
profiles or cases. The full SQL behavior is not part of this initial profile.
before data-key generation or retrieval. Error prose is not contractual. The
negative cases query these values:

- a string or a bool against an integer field
- a string that spells a UUID, or the same sixteen bytes as a bytes value,
against a UUID field
- a UUID against a bytes field or a string field
- a null, against an integer field and against a UUID field

A null is refused as `null_query`, and every other value as `field_type`.
The engine converts nothing to or from a UUID.

Boolean equality is not admitted by the current engine. Later profiles or
cases need to cover these: Boolean scalar encryption, nullable records, and
other numeric kinds. Bytes need accepted cases and frozen equality terms: the
one bytes field here only refuses a UUID. JSON, EQL targets, other operators,
declarations, cancellation, and provider failures also need later cases. The
full SQL behavior is not part of this initial profile.

Native Rust and Go run every case. A Rust build without the `uuid` feature
has no typed UUID. For a UUID case it checks the record path and the
equality term, and skips the owned scalar API and the spellings.

The TypeScript runner is pending. The TypeScript value bridge checks only
the frames. Its `tests/frames.cjs` reads the text and the spellings of each
UUID case from the corpus. It writes a frame from each one, and compares the
frame with the frozen one.

The `@cipherstash/recipher` addon cannot store a UUID yet. So no
TypeScript test encrypts these cases, queries them, or opens their frozen
ciphertexts. Pull request #1996 lets the addon store a UUID, and the
TypeScript runner of the whole profile waits on it.

## Artifacts and evolution

Expand All @@ -309,6 +354,19 @@ STACK_CONFORMANCE_UPDATE=1 mise x --env test -- cargo nextest run --locked \
mise run test:conformance
```

`STACK_CONFORMANCE_UPDATE=1` keeps the frozen ciphertext of a case whose
frame and equality term have not changed, if that ciphertext still opens. So
adding a case adds one entry, and the diff does not rewrite the ciphertexts
of the other cases. A frozen ciphertext that no longer opens is replaced
with a fresh one. A previous file that is missing or does not parse keeps
nothing.

`STACK_CONFORMANCE_UPDATE=all` writes every artifact fresh, every ciphertext
included. Use it after a change to how a ciphertext is written.

`STACK_CONFORMANCE_OUTPUT` always gets the artifacts this run made, never a
kept ciphertext.

Review the case and artifact diff together. Never regenerate artifacts merely
to make a regression pass.

Expand Down
2 changes: 1 addition & 1 deletion conformance/stack-encrypt/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Paths are relative to the repository root. New profile cases run from `v1/`.

| Requirement | Existing evidence | Remaining work |
|---|---|---|
| Scalar value widths and lossless transport | Initial scalar cases, [value-kind requirements](fixture-contract.md#value-kind-requirements) and the [value boundary profile](values-contract.md) (`v1/record-values-v1.cases.json`: every kind's edges, float specials, bytes, decimal and timestamp precision, sealed/SQL nulls per kind, exact write conversions between widths, cross-kind write refusals, `undefined` on a typed field, Go host conversions); every positive case written fresh by each runner and opened by the other ([exchange profile](exchange-contract.md)) | Python/TS mappings; dates before year 1 and the timestamp range ends |
| Scalar value widths and lossless transport | Initial scalar cases, [value-kind requirements](fixture-contract.md#value-kind-requirements) and the [value boundary profile](values-contract.md) (`v1/record-values-v1.cases.json`: every kind's edges, float specials, bytes, decimal and timestamp precision, sealed/SQL nulls per kind, exact write conversions between widths, cross-kind write refusals, `undefined` on a typed field, Go host conversions); every positive case written fresh by each runner and opened by the other ([exchange profile](exchange-contract.md)); UUIDs in the scalar profile (`v1/record-scalars-v1.cases.json`: an ordinary UUID, the nil and max UUIDs, other letter cases, the refusal of a string, bytes or null for a UUID field and of a UUID for a bytes or string field, with frozen frames, equality terms and ciphertexts), run by native Rust and Go, and their frames checked by the TypeScript value bridge (`value-napi/tests/frames.cjs`) | Python/TS mappings; dates before year 1 and the timestamp range ends; UUIDs in the value boundary profile (sealed and SQL nulls) and the exchange profile; the TypeScript runner of the UUID cases, which waits on the addon storing a UUID (#1996) |
| Owned opaque ciphertext and storage envelope | `packages/stack-encrypt/tests/scalar.rs`, `frozen_bytes.rs`; initial cross-opening cases; `owned_records.rs`, which tests the owned record derives: passthrough fields are moved, sealed fields are wiped, nested and renamed fields work, a record can store its context, and a column makes one batch. Whole-value blobs: `packages/stack-encrypt/tests/opaque_blob.rs` (round trips, the bytes leaf shared with the structural writer, a pinned storage blob and a pinned sealed ciphertext, refusals by class after authentication, source wipe) and `languages/golang/encrypt/gensupport/gensupport_internal_test.go::TestOpaqueReadsARustWrittenBlob`; the storage profile itself is pinned upstream by Vitamin C's golden corpus; fresh sealed blobs exchanged in both directions by the [exchange profile](exchange-contract.md). One value of a kind known only at run time, as one ciphertext: the [single-value profile](single-value-contract.md), run by native Rust (`v1/single-value-v1.cases.json`: every scalar kind, exact conversions, JSON documents, batches, and the refusals, with the plaintext of each leaf and a frozen ciphertext). `packages/stack-encrypt/tests/single_value.rs` compares the run-time interface with the typed interface. JSON documents as one ciphertext: `packages/stack-encrypt/tests/json_plaintext.rs` (round trips, the text leaf shared with a sealed string, refusals after authentication, a generated-document property) and, as the EQL type `Json`, `packages/eql/tests/encryption/tests/v4_types.rs` with the Go-sealed rows `v4_json_rows.json` and the frozen `stored_v4_json_rows_v1.json`, opened in Rust and Go | Encoded targets; supported version matrix; the Go runner of the single-value profile (issue #2010), and Python and TypeScript runners |
| Record declaration and lowering | [Declaration grammar](declaration-grammar.md); `v1/record-declarations-v1.cases.json` shared by native Rust and Go; native normalization observations; existing record lowering suites; `packages/stack-encrypt/tests/owned_equivalence.rs`, which seals one mixed, searchable record three ways: through a hand-written owned target, the owned derive, and the data plan. All three use one provider that records its requests. The test compares the descriptors and the term bytes, and checks that each way decrypts the records of the others | EQL-resolver profile; SDK-to-declaration mappings; runtime source/read shapes |
| Context binding and composition | `packages/stack-encrypt/tests/target.rs`, `descriptor.rs`, `record_lowering.rs`; `languages/golang/encrypt/context_field_test.go`; initial wrong-context cases | Shared composition vectors; expected-context and required-input matrix |
Expand Down
89 changes: 89 additions & 0 deletions conformance/stack-encrypt/v1/record-scalars-v1.cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,35 @@
"text": ""
}
},
{
"id": "uuid",
"kind": "uuid",
"input": {
"type": "uuid",
"text": "123e4567-e89b-12d3-a456-426614174000"
},
"spellings": [
"123E4567-E89B-12D3-A456-426614174000",
"123e4567-E89B-12d3-A456-426614174000"
]
},
{
"id": "uuid-nil",
"kind": "uuid",
"input": {
"type": "uuid",
"text": "00000000-0000-0000-0000-000000000000"
}
},
{
"id": "uuid-max",
"kind": "uuid",
"input": {
"type": "uuid",
"text": "ffffffff-ffff-ffff-ffff-ffffffffffff"
},
"spellings": ["FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"]
},
{
"id": "query-text-for-integer",
"kind": "int64",
Expand All @@ -99,6 +128,66 @@
"reason": "field_type"
}
},
{
"id": "query-text-for-uuid",
"kind": "uuid",
"input": {
"type": "string",
"text": "123e4567-e89b-12d3-a456-426614174000"
},
"expected_error": {
"code": "stack_encrypt::dynamic_source",
"reason": "field_type"
}
},
{
"id": "query-bytes-for-uuid",
"kind": "uuid",
"input": {
"type": "bytes",
"text": "123e4567e89b12d3a456426614174000"
},
"expected_error": {
"code": "stack_encrypt::dynamic_source",
"reason": "field_type"
}
},
{
"id": "query-uuid-for-bytes",
"kind": "bytes",
"input": {
"type": "uuid",
"text": "123e4567-e89b-12d3-a456-426614174000"
},
"expected_error": {
"code": "stack_encrypt::dynamic_source",
"reason": "field_type"
}
},
{
"id": "query-uuid-for-string",
"kind": "string",
"input": {
"type": "uuid",
"text": "123e4567-e89b-12d3-a456-426614174000"
},
"expected_error": {
"code": "stack_encrypt::dynamic_source",
"reason": "field_type"
}
},
{
"id": "query-uuid-null",
"kind": "uuid",
"input": {
"type": "null",
"text": ""
},
"expected_error": {
"code": "stack_encrypt::dynamic_source",
"reason": "null_query"
}
},
{
"id": "query-null",
"kind": "int64",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@
"frame": "07ffffffffffffffff",
"ciphertext": "01000000000000000000000000000000001aaf730b6c6bc77770144918b59a35932000ef235e515a8e50ff41f3a26ba62e5de76f5331373f245ced6bce3a5638acffd302e975cc6e364604b6b1c0563752772c462fc353b94531ddca1436504262400183186ff2f004",
"equality": "04c8d7f02d9555152bdd770106eab974e517a0eba6b339e3ad1b0108796359d8"
},
"uuid": {
"frame": "f305000b10000000123e4567e89b12d3a456426614174000",
"ciphertext": "0100000000000000000000000000000000f5b12c40ee6ffb7a9c85c69b03a779e4200056236fd096aafaed2275d4ad190e4d59db87adce04e5559e5bba3890896c5757024521688cff5eb89ecfab224ebc094626626e93d4f075e081d56792100f20d92e4e426972135dfd40bed6f730fdbd73c7",
"equality": "7634298ccb1ad44050b51acacd0771a8239d1b62733f2e304a22d0fbc171b4c8"
},
"uuid-max": {
"frame": "f305000b10000000ffffffffffffffffffffffffffffffff",
"ciphertext": "0100000000000000000000000000000000a8ce1a0d8006f7f520bf442ccfb5e29b20004729b5919422affbfcc9adbd176531ab347d92efeffb29b2b490c0ea43b8ac7502d2148d315e954cbaeb917ef64b262406a0813f4450778f9e50ade56bec3f2b6e6bffd27fe00fbe99c51f99a1d10e9993",
"equality": "f6c58ca90a253859c9df165ca399f8f011cc35ae875cb5752a49c88f20bb5a61"
},
"uuid-nil": {
"frame": "f305000b1000000000000000000000000000000000000000",
"ciphertext": "0100000000000000000000000000000000c7b57f8c77688afcb27fb34d7402cc102000a0662e0d9bdcae5e59de239b25fb140cfcae05d5ea7a77df8374e47031a8a9b902f41ea529a50937d4b7bddb8f255b6397f6e9931ade53a726cb6347f511dabd6b2202aa35c447ce707500ba23119a0748",
"equality": "fa20cfc9c2f9dcca704759a2751541fcac573fcaaaae5df9ec31bf843fb911cf"
}
}
}
36 changes: 31 additions & 5 deletions languages/golang/encrypt/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/cipherstash/stack/languages/golang/encrypt"
"github.com/cipherstash/stack/languages/golang/internal/record"
"github.com/cipherstash/vitaminc/bindings/go/vcffi"
"github.com/cipherstash/vitaminc/bindings/go/vcvalue"
)

// This runner tests the record interface used by generated SDK code. Generated
Expand All @@ -37,9 +38,12 @@ type conformanceCorpus struct {
}

type conformanceCase struct {
ID string `json:"id"`
Kind string `json:"kind"`
Input conformanceInput `json:"input"`
ID string `json:"id"`
Kind string `json:"kind"`
Input conformanceInput `json:"input"`
// Spellings are other spellings of a UUID input's text, in another
// letter case, that vcvalue.ParseUUID must read as the same UUID.
Spellings []string `json:"spellings"`
ExpectedError *struct {
Code string `json:"code"`
Reason string `json:"reason"`
Expand Down Expand Up @@ -83,8 +87,8 @@ type conformanceInput struct {

// conformanceValue is the typed Go value an input names: every integer at
// its own width, the SDK's Int128, Uint128, Date and Decimal, a time.Time
// for a timestamp, and bytes from hex. A text the type cannot carry fails
// the test; nothing is rounded.
// for a timestamp, a vcvalue.UUID, and bytes from hex. A text the type
// cannot carry fails the test; nothing is rounded.
func conformanceValue(t testing.TB, input conformanceInput) any {
t.Helper()
signed := func(bits int) int64 {
Expand Down Expand Up @@ -172,6 +176,14 @@ func conformanceValue(t testing.TB, input conformanceInput) any {
return input.Text == "true"
case "string":
return input.Text
case "uuid":
// The corpus spells a UUID in lowercase only, as Rust's reader
// requires; other spellings are a case's Spellings.
u, err := vcvalue.ParseUUID(input.Text)
if err != nil || u.String() != input.Text {
t.Fatalf("%q: not a canonical lowercase UUID", input.Text)
}
return u
case "null":
if input.Text != "" {
t.Fatal("null has empty text")
Expand Down Expand Up @@ -200,6 +212,14 @@ func TestStackConformance(t *testing.T) {
t.Fatalf("empty or duplicate case ID %q", c.ID)
}
seen[c.ID] = true
if len(c.Spellings) > 0 && (c.Input.Type != "uuid" || c.ExpectedError != nil) {
t.Fatalf("%s: only an accepted case with a UUID input has other spellings", c.ID)
}
for _, spelling := range c.Spellings {
if spelling == c.Input.Text || !strings.EqualFold(spelling, c.Input.Text) {
t.Fatalf("%s: %q is not the input's text in another letter case", c.ID, spelling)
}
}
if c.ExpectedError == nil {
positive[c.ID] = true
}
Expand Down Expand Up @@ -255,6 +275,12 @@ func TestStackConformance(t *testing.T) {
if hex.EncodeToString(encoded) != want.Frame || hex.EncodeToString(query.Terms[0]) != want.Equality {
t.Fatal("typed frame or equality bytes disagree with the native vector")
}
for _, spelling := range c.Spellings {
u, err := vcvalue.ParseUUID(spelling)
if err != nil || u != input {
t.Fatalf("%q: does not read as the input's UUID: %v", spelling, err)
}
}
decode := func(text string) []byte {
t.Helper()
b, err := hex.DecodeString(text)
Expand Down
Loading
Loading