feat(storage): persist re-encrypted token on keychain key rotation#2847
Open
afonsojramos wants to merge 6 commits intomainfrom
Open
feat(storage): persist re-encrypted token on keychain key rotation#2847afonsojramos wants to merge 6 commits intomainfrom
afonsojramos wants to merge 6 commits intomainfrom
Conversation
|
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
Closes the second half of the #2839 review feedback: when
safeStorage.decryptStringAsyncreportsshouldReEncrypt: true(the OS keychain rotated keys), we now re-encrypt the token with the current key and persist the new ciphertext, so future sessions stay aligned with the active keychain.Without this, key rotation works for the current session (the plaintext is correctly decrypted under the old key) but the stored ciphertext silently drifts behind the keychain. Eventually it would fail.
Changes
SAFE_STORAGE_DECRYPTnow returnsISafeStorageDecryptResult = { token: string; reEncryptedToken?: string }instead ofstring. The contract is enforced via theEventContractsmap added in refactor(events): add typed IPC contracts for compile-time safety #2843.src/main/handlers/storage.ts): whenshouldReEncryptfires, callsencryptStringAsyncon the decrypted plaintext to produce a new ciphertext; returns it underreEncryptedToken. Otherwise returns just{token}.src/renderer/utils/system/comms.ts):decryptValuereturns the result object.octokit.ts: destructures.tokenforauth. Per-request decrypts don't persist (rotation is rare; next app start picks it up viamigrateAuthTokens). Keeps octokit decoupled from the auth store.App.tsx migrateAuthTokens: now the canonical persistence path. On startup, if any account's token comes back withreEncryptedToken, it swaps the stored ciphertext andpersistAuth's the change.Tests
encryptStringAsyncis called andreEncryptedTokenis in the response).comms.test.tsupdated to expect the new return shape.octokit.test.tsupdated to mock the new shape.vitest.setup.ts) updated.pnpm tsc --noEmitclean.pnpm test938/938.