@@ -261,8 +261,6 @@ func feeParams(space did.DID, digest []byte) registry.BlobEncryptionParams {
261261 return registry.BlobEncryptionParams {
262262 Space : space ,
263263 Digest : digest ,
264- RegionWrappedCEK : []byte ("wrapped-cek" ),
265- RegionKeyVersion : "region-v1" ,
266264 TenantRecipientKID : "did:key:tenant#wrap" ,
267265 HeaderLen : 212 ,
268266 BaseNonce : []byte ("nonce07" ),
@@ -302,7 +300,7 @@ func TestEncryptionParams_MissingIsNotFound(t *testing.T) {
302300 }
303301}
304302
305- func TestEncryptionParams_DeleteShreds (t * testing.T ) {
303+ func TestEncryptionParams_DeleteRemovesRow (t * testing.T ) {
306304 ctx := context .Background ()
307305 m := NewMemStore ()
308306 space := testutil .RandomDID (t )
@@ -328,7 +326,7 @@ func TestEncryptionParams_DeleteIsIdempotent(t *testing.T) {
328326 }
329327}
330328
331- // The store must not alias the caller's key material , nor let a caller reach
329+ // The store must not alias the caller's byte slices , nor let a caller reach
332330// back into it through a returned copy.
333331func TestEncryptionParams_NoSliceAliasing (t * testing.T ) {
334332 ctx := context .Background ()
@@ -340,15 +338,14 @@ func TestEncryptionParams_NoSliceAliasing(t *testing.T) {
340338 if err := m .PutEncryptionParams (ctx , params ); err != nil {
341339 t .Fatalf ("PutEncryptionParams: %v" , err )
342340 }
343- params .RegionWrappedCEK [0 ] = 'X'
344341 params .BaseNonce [0 ] = 'X'
345342 params .AAD [0 ] = 'X'
346343
347344 got , err := m .GetEncryptionParams (ctx , space , digest )
348345 if err != nil {
349346 t .Fatalf ("GetEncryptionParams: %v" , err )
350347 }
351- got .RegionWrappedCEK [0 ] = 'Y'
348+ got .BaseNonce [0 ] = 'Y'
352349
353350 again , err := m .GetEncryptionParams (ctx , space , digest )
354351 if err != nil {
@@ -359,105 +356,6 @@ func TestEncryptionParams_NoSliceAliasing(t *testing.T) {
359356 }
360357}
361358
362- // A region-key rotation re-wraps in place: same blob, new CEK + key version,
363- // every other parameter untouched.
364- func TestEncryptionParams_RewrapInPlace (t * testing.T ) {
365- ctx := context .Background ()
366- m := NewMemStore ()
367- space := testutil .RandomDID (t )
368- digest := []byte ("enc-digest" )
369- if err := m .PutEncryptionParams (ctx , feeParams (space , digest )); err != nil {
370- t .Fatalf ("PutEncryptionParams: %v" , err )
371- }
372-
373- want := feeParams (space , digest )
374- want .RegionWrappedCEK = []byte ("wrapped-cek-v2" )
375- want .RegionKeyVersion = "region-v2"
376- if err := m .RewrapEncryptionParams (ctx , space , digest , want .RegionWrappedCEK , want .RegionKeyVersion ); err != nil {
377- t .Fatalf ("RewrapEncryptionParams: %v" , err )
378- }
379-
380- got , err := m .GetEncryptionParams (ctx , space , digest )
381- if err != nil {
382- t .Fatalf ("GetEncryptionParams: %v" , err )
383- }
384- if ! reflect .DeepEqual (* got , want ) {
385- t .Fatalf ("after re-wrap = %+v, want %+v" , * got , want )
386- }
387- }
388-
389- // Nothing to re-wrap means the blob is not encrypted (or was already shredded),
390- // which a rotation must hear about rather than take for success.
391- func TestEncryptionParams_RewrapMissingIsNotFound (t * testing.T ) {
392- ctx := context .Background ()
393- m := NewMemStore ()
394-
395- err := m .RewrapEncryptionParams (ctx , testutil .RandomDID (t ), []byte ("absent" ), []byte ("wrapped-cek-v2" ), "region-v2" )
396- if ! errors .Is (err , registry .ErrNotFound ) {
397- t .Fatalf ("RewrapEncryptionParams(absent) err = %v, want ErrNotFound" , err )
398- }
399- }
400-
401- // A re-wrap may not blank out the key material the decrypt path needs.
402- func TestEncryptionParams_RewrapIncompleteRejected (t * testing.T ) {
403- space := testutil .RandomDID (t )
404- digest := []byte ("enc-digest" )
405-
406- cases := map [string ]struct {
407- wrappedCEK []byte
408- keyVersion string
409- }{
410- "no wrapped CEK" : {nil , "region-v2" },
411- "empty wrapped CEK" : {[]byte {}, "region-v2" },
412- "no key version" : {[]byte ("wrapped-cek-v2" ), "" },
413- }
414- for name , tc := range cases {
415- t .Run (name , func (t * testing.T ) {
416- ctx := context .Background ()
417- m := NewMemStore ()
418- if err := m .PutEncryptionParams (ctx , feeParams (space , digest )); err != nil {
419- t .Fatalf ("PutEncryptionParams: %v" , err )
420- }
421-
422- err := m .RewrapEncryptionParams (ctx , space , digest , tc .wrappedCEK , tc .keyVersion )
423- if ! errors .Is (err , registry .ErrInvalidEncryptionParams ) {
424- t .Fatalf ("RewrapEncryptionParams err = %v, want ErrInvalidEncryptionParams" , err )
425- }
426- got , getErr := m .GetEncryptionParams (ctx , space , digest )
427- if getErr != nil {
428- t .Fatalf ("GetEncryptionParams: %v" , getErr )
429- }
430- if ! reflect .DeepEqual (* got , feeParams (space , digest )) {
431- t .Fatalf ("rejected re-wrap altered the row: %+v" , * got )
432- }
433- })
434- }
435- }
436-
437- // The re-wrap path must not alias the caller's key material either.
438- func TestEncryptionParams_RewrapNoSliceAliasing (t * testing.T ) {
439- ctx := context .Background ()
440- m := NewMemStore ()
441- space := testutil .RandomDID (t )
442- digest := []byte ("enc-digest" )
443- if err := m .PutEncryptionParams (ctx , feeParams (space , digest )); err != nil {
444- t .Fatalf ("PutEncryptionParams: %v" , err )
445- }
446- wrappedCEK := []byte ("wrapped-cek-v2" )
447- if err := m .RewrapEncryptionParams (ctx , space , digest , wrappedCEK , "region-v2" ); err != nil {
448- t .Fatalf ("RewrapEncryptionParams: %v" , err )
449- }
450- wrappedCEK [0 ] = 'X'
451-
452- got , err := m .GetEncryptionParams (ctx , space , digest )
453- if err != nil {
454- t .Fatalf ("GetEncryptionParams: %v" , err )
455- }
456- if ! reflect .DeepEqual (got .RegionWrappedCEK , []byte ("wrapped-cek-v2" )) {
457- t .Fatalf ("re-wrapped CEK was aliased: %q" , got .RegionWrappedCEK )
458- }
459- }
460-
461359// Every parameter is required: a row missing any one of them could not be
462360// decrypted with, so PutEncryptionParams rejects it and stores nothing.
463361func TestEncryptionParams_IncompleteRejected (t * testing.T ) {
@@ -470,9 +368,6 @@ func TestEncryptionParams_IncompleteRejected(t *testing.T) {
470368 }{
471369 {"no space" , func (p * registry.BlobEncryptionParams ) { p .Space = did .Undef }},
472370 {"no digest" , func (p * registry.BlobEncryptionParams ) { p .Digest = nil }},
473- {"no wrapped CEK" , func (p * registry.BlobEncryptionParams ) { p .RegionWrappedCEK = nil }},
474- {"empty wrapped CEK" , func (p * registry.BlobEncryptionParams ) { p .RegionWrappedCEK = []byte {} }},
475- {"no key version" , func (p * registry.BlobEncryptionParams ) { p .RegionKeyVersion = "" }},
476371 {"no recipient kid" , func (p * registry.BlobEncryptionParams ) { p .TenantRecipientKID = "" }},
477372 {"no header length" , func (p * registry.BlobEncryptionParams ) { p .HeaderLen = 0 }},
478373 {"no base nonce" , func (p * registry.BlobEncryptionParams ) { p .BaseNonce = nil }},
0 commit comments