Skip to content

Commit e4990e4

Browse files
authored
Merge pull request #1501 from cipherstash/feat/stack-encrypt-owned-collections
feat(stack-encrypt): encrypt and decrypt owned `Vec<S>` collections as one batch
2 parents a2e4520 + feee160 commit e4990e4

68 files changed

Lines changed: 3181 additions & 1157 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Cargo.lock‎

Lines changed: 83 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ cts-common = { version = "0.43.0", default-features = false }
8282
zerokms-protocol = "0.12.31"
8383
recipher = "=0.3.1"
8484
# The two order-preserving schemes Stack Encrypt's order terms encrypt
85-
# through. Both implement vitaminc-ore's `OrderScheme` against vitaminc 0.8:
85+
# through. Both implement vitaminc-ore's `OrderScheme` against vitaminc 0.9:
8686
# `clww-ore` (cllw-ore renamed) for CLWW ORE and OPE, and ore-rs's
8787
# `BlockOre` for block ORE, which routes a value to its 6-bit fixed-width
8888
# engine (up to ten bytes) or its chained one (wider, or variable length),
8989
# the terms EQL v4's `_ord_ore` domains store.
9090
# vitaminc is a plain dependency of both from here, not a feature. Both are
9191
# pinned exactly: a new release can change every stored order term.
92-
clww-ore = { version = "=0.6.0", default-features = false }
93-
ore-rs = { version = "=0.10.0", default-features = false }
92+
clww-ore = { version = "=0.7.0", default-features = false }
93+
ore-rs = { version = "=0.11.0", default-features = false }
9494

9595
# External dependencies, with the suite's feature lists.
9696
base64 = "0.22.0"
@@ -139,18 +139,18 @@ web-time = "1.1"
139139
zeroize = { version = "1.8.1", features = ["derive"] }
140140
# This is needed because lock_api 0.4.6 was breaking things and the branch forces the use of 0.4.12
141141
temp-env = { git = "https://github.com/cipherstash/temp-env", branch = "main" }
142-
vitaminc = { version = "0.8.0", features = ["random", "protected", "encrypt"] }
143-
vitaminc-aead = "0.8.0"
142+
vitaminc = { version = "0.9.0", features = ["random", "protected", "encrypt"] }
143+
vitaminc-aead = "0.9.0"
144144
# The transport frame and ciphertext codec every language binding carries
145145
# across its FFI boundary. Optional in stack-encrypt (the `dynamic` feature).
146-
vitaminc-aead-frame = "0.8.0"
147-
vitaminc-encrypt = "0.8.0"
148-
vitaminc-hmac = "0.8.0"
146+
vitaminc-aead-frame = "0.9.0"
147+
vitaminc-encrypt = "0.9.0"
148+
vitaminc-hmac = "0.9.0"
149149
# Normalized equality terms (Unicode 16 NFC text, one integer encoding for
150150
# every width), which `vitaminc-prf`'s `normalize` feature derives over.
151-
vitaminc-normalize = "0.8.0"
151+
vitaminc-normalize = "0.9.0"
152152
# The text order key: the system ADR-0002's fold, pinned to Unicode 16,
153153
# which text ORE and OPE terms are derived over (ADR-0009).
154-
vitaminc-ore = "0.8.0"
155-
vitaminc-prf = { version = "0.8.0", features = ["normalize"] }
156-
vitaminc-protected = "0.8.0"
154+
vitaminc-ore = "0.9.0"
155+
vitaminc-prf = { version = "0.9.0", features = ["normalize"] }
156+
vitaminc-protected = "0.9.1"

‎conformance/stack-encrypt/coverage.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ The [lifecycle contract](lifecycle-contract.md) enrolls native pending/KMS tests
129129
heap observations, guest ABI cleanup, Go cancellation/memory tests and public SDK
130130
diagnostics. New probes cover unpolled and in-flight drops, provider failure,
131131
cleanup after a late authenticated type failure, and chunk concurrency/drop.
132+
The owned `Vec<S>` to `Vec<T>` conversion is enrolled under the same
133+
requirements. The conversion's tests cover:
134+
135+
- dropping a collection before it is polled
136+
- dropping a collection while its key request is running
137+
- one logical batch of key requests for each collection, and none for an
138+
empty collection
139+
- wiping the source `Vec` through its guard
140+
- wiping the elements already decrypted, when a later element fails
141+
142+
The owned conversion is a native Rust API. Go reaches batching through its
143+
record interface, and the runtime profile covers that interface.
132144
Existing runtime/read/context vectors retain their provider-call counters.
133145

134146
This adds required execution and explicit observation limits; it removes no

‎conformance/stack-encrypt/lifecycle-contract.md‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ process. Python and TypeScript are explicitly not enrolled.
1010

1111
| Requirement | Native evidence | Go evidence and limits |
1212
|---|---|---|
13-
| `lifecycle-ownership-v1` | Actual record operations release fulfilment captures exactly once on success, provider failure and unpolled drop; an unpolled encrypt or decrypt makes no key request. Zipped fulfilments do not share key material. | Client keys are consumed/redacted; explicit close and unreachable-client cleanup release guest memory; calls on a closed client fail. GC cleanup is eventual, so callers should close explicitly. |
14-
| `lifecycle-cancellation-v1` | Dropping an encrypt future paused in key generation, or a decrypt future paused in key retrieval, drops the provider future and operation captures; subsequent work on the cipher succeeds. Guest ABI abort spends the handle and drops the operation. | Cancellation before a call sends no request; cancellation between steps or during token fetch leaves unrelated operations usable. A guest step that overruns cancellation closes the client. Discarded late output is wiped. |
15-
| `lifecycle-partial-output-v1` | A batch with a valid first row and a later authenticated type mismatch releases its decoded prefix without marked heap residue. Existing context cases reject late authentication failures without returning partial output. | Generated and raw batch APIs return no partial rows on failure; interrupted HTTP bodies fail; cancelled output is wiped. SDK conversion diagnostics contain no decrypted values. This does not assert erasure of partially populated caller-owned Go objects. |
16-
| `lifecycle-buffer-cleanup-v1` | The existing allocator observer checks selected write/read/JSON parse paths and has a negative control. Guest ABI tests check buffer-registry cleanup, error-buffer release and protected text drop. | Request bodies survive until their owner closes them, then wipe; refused requests wipe; heap growth wipes abandoned backing arrays; guest runtime close releases memory. Post-encryption memory scans are supplementary observations. |
13+
| `lifecycle-ownership-v1` | Actual record operations and owned `Vec<S>` to `Vec<T>` conversions release fulfilment captures exactly once on success, provider failure and unpolled drop; an unpolled encrypt or decrypt makes no key request. Zipped fulfilments do not share key material. | Client keys are consumed/redacted; explicit close and unreachable-client cleanup release guest memory; calls on a closed client fail. GC cleanup is eventual, so callers should close explicitly. |
14+
| `lifecycle-cancellation-v1` | Dropping an encrypt future paused in key generation, or a decrypt future paused in key retrieval, drops the provider future and operation captures, for a record operation or an owned collection; subsequent work on the cipher succeeds. Guest ABI abort spends the handle and drops the operation. | Cancellation before a call sends no request; cancellation between steps or during token fetch leaves unrelated operations usable. A guest step that overruns cancellation closes the client. Discarded late output is wiped. |
15+
| `lifecycle-partial-output-v1` | A batch with a valid first row and a later authenticated type mismatch releases its decoded prefix without marked heap residue. Tests check this for the dynamic record path and for the owned `Vec<Ciphertext>` to `Vec<String>` conversion. For owned collections, drop witnesses are test values that record whether they were wiped. They show that the prefix is wiped, not leaked, after a late failure or an element's panic. Existing context cases reject late authentication failures without returning partial output. | Generated and raw batch APIs return no partial rows on failure; interrupted HTTP bodies fail; cancelled output is wiped. SDK conversion diagnostics contain no decrypted values. This does not assert erasure of partially populated caller-owned Go objects. |
16+
| `lifecycle-buffer-cleanup-v1` | The existing allocator observer checks selected write/read/JSON parse paths and has a negative control. One of those paths encrypts an owned `Vec<String>` collection through its guard. Drop witnesses show that an owned collection's source is wiped before its pending request is returned. That includes a refused context, and a context conversion that panics. Guest ABI tests check buffer-registry cleanup, error-buffer release and protected text drop. | Request bodies survive until their owner closes them, then wipe; refused requests wipe; heap growth wipes abandoned backing arrays; guest runtime close releases memory. Post-encryption memory scans are supplementary observations. |
1717
| `lifecycle-diagnostics-v1` | Guest errors discard untrusted foreign cause messages; failed/successful exports do not hand over stale diagnostics. | Structured errors remain available after failures; SDK errors and redacted display/logging expose types or fields rather than plaintext values. |
1818
| `lifecycle-validation-before-io-v1` | Existing runtime/read/context cases count provider calls. Wrong shape, independently detectable context mismatch and oversized descriptors fail before key I/O; lazy assembly stops after local failure. | Host refusals happen before entering the guest, and shared runtime/read cases exercise the uninitialised guest's preflight boundary. Go does not yet expose native provider counters. |
19-
| `lifecycle-logical-batching-v1` | Instrumented `DataKeySource` calls establish one logical generation batch, retrieval grouping by keyset, descriptor ordering and no work for empty batches. | Go uses the same engine, but this profile does not claim independently instrumented Go key-request counts. |
19+
| `lifecycle-logical-batching-v1` | Instrumented `DataKeySource` calls establish one logical generation batch, retrieval grouping by keyset, descriptor ordering and no work for empty batches, for record operations and for an owned `Vec<S>` collection of any length, including an empty one. | Go uses the same engine, but this profile does not claim independently instrumented Go key-request counts. |
2020
| `lifecycle-provider-chunks-v1` | The actual KMS chunking helper preserves order, handles a final short chunk, fails the whole call on a chunk error, bounds in-flight chunks and releases their futures on cancellation. | This is a native algorithm observation, not a measurement of live HTTP request counts. |
2121

2222
The drop witnesses belong to fulfilment closures and provider futures in real
@@ -59,7 +59,12 @@ These entries in the index are limitations, not successful requirements:
5959
sealing frame by backtrace and reports excluded frees. It scrubs stack residue
6060
before observing heap frees; it does not prove stack erasure. Its JSON query
6161
paths use borrowed/static path text because owned path copies have separate
62-
cleanup limitations. The lifecycle runner preserves the observer's output.
62+
cleanup limitations. The observer only scans blocks that are freed, so it
63+
misses plaintext that is leaked and never freed. For the owned `Vec<S>`
64+
conversion, the drop witnesses in `packages/stack-encrypt/tests/collections.rs`
65+
record the wipe itself. A test there fails if a source or a decrypted prefix
66+
is leaked. The lifecycle
67+
runner preserves the observer's output.
6368
- **`caller-owned-host-values` — outside the guarantee.** Caller-owned strings,
6469
bytes, objects, returned plaintext, aliases and copies remain the caller's
6570
responsibility. Ownership transfer or protected borrowing must be stated by

‎conformance/stack-encrypt/v1/lifecycle-v1.enrollment.json‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
"binary": "heap_hygiene",
2828
"success_output": "immediate"
2929
},
30+
"collections": {
31+
"language": "rust",
32+
"lane": "fast",
33+
"workspace": ".",
34+
"package": "stack-encrypt",
35+
"features": ["--all-features"],
36+
"binary": "collections"
37+
},
3038
"runtime": {
3139
"language": "rust",
3240
"lane": "fast",
@@ -90,7 +98,9 @@
9098
"lifecycle": [
9199
"dropping_unpolled_work_releases_captures_without_key_io",
92100
"dropping_unpolled_decrypt_releases_captures_without_key_io",
93-
"success_and_provider_failure_release_captures_once"
101+
"success_and_provider_failure_release_captures_once",
102+
"dropping_an_unpolled_owned_column_releases_captures_without_key_io",
103+
"an_owned_column_is_one_logical_batch_and_releases_captures_once"
94104
],
95105
"pending": [
96106
"target::pending::tests::zipped_fulfilments_never_share_key_material"
@@ -108,7 +118,8 @@
108118
"evidence": {
109119
"lifecycle": [
110120
"cancelling_in_flight_work_drops_provider_and_captures",
111-
"cancelling_in_flight_decrypt_drops_provider_and_captures"
121+
"cancelling_in_flight_decrypt_drops_provider_and_captures",
122+
"cancelling_an_owned_column_in_flight_drops_provider_and_captures"
112123
],
113124
"guest-abi": [
114125
"step::tests::an_aborted_operation_is_dropped_and_its_handle_spent",
@@ -127,7 +138,14 @@
127138
{
128139
"id": "lifecycle-partial-output-v1",
129140
"evidence": {
130-
"heap": ["a_late_read_type_failure_leaves_no_plaintext_on_the_heap"],
141+
"heap": [
142+
"a_late_read_type_failure_leaves_no_plaintext_on_the_heap",
143+
"a_late_type_failure_in_an_owned_column_leaves_no_plaintext_on_the_heap"
144+
],
145+
"collections": [
146+
"a_late_element_failure_wipes_the_plaintext_recovered_before_it",
147+
"a_panicking_element_conversion_wipes_the_plaintext_recovered_before_it"
148+
],
131149
"contexts": ["shared_context_boundaries"],
132150
"go": [
133151
"TestContextBoundaries",
@@ -142,10 +160,16 @@
142160
"evidence": {
143161
"heap": [
144162
"a_record_encrypted_from_a_value_frame_leaves_no_plaintext_on_the_heap",
163+
"an_owned_column_encrypted_leaves_no_plaintext_on_the_heap",
145164
"a_record_decrypted_with_a_nested_field_leaves_no_plaintext_on_the_heap",
146165
"a_json_document_read_from_a_frame_leaves_no_plaintext_on_the_heap",
147166
"the_spy_sees_an_unwiped_free"
148167
],
168+
"collections": [
169+
"owned_elements_are_wiped_before_the_pending_is_returned",
170+
"owned_elements_are_wiped_when_the_context_is_refused",
171+
"owned_elements_are_guarded_during_context_conversion"
172+
],
149173
"guest-abi": [
150174
"buffers::tests::wipe_all_leaves_no_live_buffer",
151175
"last_error::tests::clearing_wipes_and_frees_the_registered_buffer",
@@ -205,6 +229,10 @@
205229
"id": "lifecycle-logical-batching-v1",
206230
"evidence": {
207231
"runtime": ["shared_record_runtime_profile"],
232+
"lifecycle": [
233+
"an_owned_column_is_one_logical_batch_and_releases_captures_once",
234+
"an_empty_owned_column_makes_no_provider_call"
235+
],
208236
"pending": [
209237
"target::pending::tests::one_pending_asking_for_many_keys_is_one_call",
210238
"target::pending::tests::all_merges_a_column_into_one_call_preserving_order",

0 commit comments

Comments
 (0)