Repository navigation
feat(persistence): add opt-in associated data to AESGCMCodec - #134
Merged
Merged
Conversation
AESGCMCodec sealed without associated data, so with one key shared by two stores a file saved by one decoded as valid state for the other when copied over it. The new AESGCMCodec.AssociatedData field is authenticated with the ciphertext on Encode and Decode under every key the provider returns, current or historical, and is not stored in the envelope. The field is a string rather than []byte so AESGCMCodec stays comparable; apidiff reports a []byte field as an incompatible change. The empty value seals with no associated data, byte for byte the format written before, which a golden envelope produced by the previous code verifies. Reads and writes must use the same value; adding or changing it for existing data needs a migration that loads with the old value and saves with the new one, as the doc comment, docs/architecture.md and docs/public-api.md now state.
The field doc, docs/architecture.md and docs/public-api.md now say the associated data must stay the same for the data's whole lifetime and recommend a stable logical name such as com.example.app/settings; a file path is mentioned only with the warning that moving or renaming it leaves the primary and backup unreadable until migrated. The root swapped-file test uses logical names instead of absolute temp paths.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AESGCMCodecsealed without associated data. When two stores shared one key, a file saved by one store could be copied over the other's file and would decode as valid state for it. This PR adds an opt-inAESGCMCodec.AssociatedDatafield that binds each ciphertext to a store identity.What
AssociatedData stringonAESGCMCodec. It is passed as the GCM additional data on bothEncode(Seal) andDecode(Open), under every key theKeyProviderreturns, current or historical. It is authenticated but neither encrypted nor stored in the envelope.string, not[]byte, soAESGCMCodecstays comparable; apidiff treats a[]bytefield as an incompatible change.docs/architecture.mdanddocs/public-api.mdcover four points:com.example.app/settingsis the recommended identity.LoadWithRecoveryreturns aRecoveryError.Tests
Replacing the AD with nil makes the binding, rotation and swapped-file tests fail.
How tested
go test ./...,go test -race -count=1 ./...,go vet ./...,go mod tidy -diff,golangci-lint run ./...: all passscripts/check-api.shagainst a clone ofmain(0defa75): onlyAESGCMCodec.AssociatedData: added, a compatible changeCompatibility
Additive and v1-compatible. The zero value keeps today's format and behaviour exactly. Applications that opt in must migrate existing data, as documented.
Trade-offs
site/) will be updated in a separate site-only PR, per the repository rule that keeps website and library changes apart.Screenshots
None