auth: fixes errors when adding a new device after removing devices #128
+267
−34
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.
I ran into the error "Can't decrypt link: don't have the correct keyset" while trying to join with a new device after I removed other devices of the same user. I observed that the new device cannot decrypt the whole team graph because it can only unlock the latest generation of team keys using the latest generation of user keys. These were the only user keys that the new device received on joining, while there have been several generations of user and team keys since the key rotations following the device removals.
My proposed solution is to put all generations of user keys in lockboxes when creating a device invitation, so the new device can unlock all generations of team keys.
With these changes, the next thing I had was an ENCRYPTION_FAILURE when the new device started to sync with the server after joining, because the server was still using generation 0 user keys when talking to the new device. It turned out that the user keys in
team.state.members
andcontext.user
were not updated after the key rotation when removing a device, so I changed that.