refactor(e2eecrypto): move accountKey wrap/unwrap out of e2eeclient - #321
Merged
Conversation
Password → wrap_key derivation (Argon2id) + AEAD seal/open of the account_key envelope are cryptographic primitives, not HTTP-client concerns. The functions lived inside internal/e2eeclient/client.go by history — that package is otherwise the OPAQUE HTTP round-tripper, and now drags in golang.org/x/crypto/argon2 + chacha20poly1305 for no reason. Move to internal/e2eecrypto/accountkey.go, exported as `WrapAccountKey` / `UnwrapAccountKey`. Consolidates all account_key crypto in one package alongside the session-key derivation (HKDF) and frame envelope AEAD that were already there. - Renamed `wrapAccountKey` → `e2eecrypto.WrapAccountKey` - Renamed `unwrapAccountKey` → `e2eecrypto.UnwrapAccountKey` - `KDFParams` + `DefaultKDFParams` + `KDFParams.Marshal` move with them (no consumer outside e2eeclient). - AAD constant `atterm-account-key-v1` promoted to a named const so future migrations flip it in one place. - Error text `e2eeclient: invalid password` → `e2eecrypto: invalid password` (matches the new package location). - e2eeclient/client.go: drop argon2 / chacha20poly1305 imports, drop the local functions, import e2eecrypto at the two call sites (Register + Login). Package doc-comment rewrites the "SDK owns the crypto" sentence — it doesn't anymore. - Tests: TestWrapUnwrap_RoundTrip + TestUnwrap_WrongPassword move to e2eecrypto/accountkey_test.go (same-package internal test in the new home). TestClient_* stay in e2eeclient. - e2eecrypto/sessionkey.go package doc updated to list the three files (accountkey / sessionkey / envelope) and note that e2eeclient now imports this package rather than duplicating. Wire format is unchanged: same AccountKeyWrap struct in opaquesuite, same Argon2id parameters, same AAD string. `go test ./...` green.
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
Milestone 6-b. Password → wrap_key derivation (Argon2id) + AEAD seal/open of the `account_key` envelope are cryptographic primitives, not HTTP-client concerns. The functions lived inside `internal/e2eeclient/client.go` by history — that package is otherwise the OPAQUE HTTP round-tripper, and it was dragging in `golang.org/x/crypto/argon2` + `chacha20poly1305` for no reason.
Move to `internal/e2eecrypto/accountkey.go`, exported as `WrapAccountKey` / `UnwrapAccountKey`. Consolidates all `account_key` crypto in one package alongside the session-key derivation (HKDF) and frame envelope AEAD that were already there.
Changes:
Wire format is unchanged: same `AccountKeyWrap` struct in `opaquesuite`, same Argon2id parameters (64 MiB, t=3, p=1), same AAD string. A wrap envelope written by main can be opened by this branch and vice-versa.
Test plan