-
Notifications
You must be signed in to change notification settings - Fork 5
Fix key ratchet race condition during DAVE epoch transitions #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MohmmedAshraf
wants to merge
2
commits into
disgoorg:master
Choose a base branch
from
MohmmedAshraf:fix/dave-epoch-key-ratchet-race
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -192,6 +192,10 @@ func (s *session) prepareEpoch(epoch int, protocolVersion uint16) { | |
| return | ||
| } | ||
|
|
||
| s.logger.Warn("prepareEpoch: resetting MLS session via Init", | ||
| slog.Int("epoch", epoch), | ||
| slog.Int("protocol_version", int(protocolVersion)), | ||
| ) | ||
| s.session.Init(protocolVersion, uint64(s.channelID), string(s.selfUserID)) | ||
| } | ||
|
|
||
|
|
@@ -228,17 +232,33 @@ func (s *session) setupKeyRatchetForUser(userID godave.UserID, protocolVersion u | |
| disabled := protocolVersion == disabledProtocolVersion | ||
|
|
||
| if userID == s.selfUserID { | ||
| kr := s.session.GetKeyRatchet(string(userID)) | ||
| if !disabled && kr == nil { | ||
| s.logger.Warn("nil key ratchet for self after GetKeyRatchet", | ||
| slog.String("user_id", string(userID)), | ||
| slog.Int("protocol_version", int(protocolVersion)), | ||
| ) | ||
| return | ||
| } | ||
| s.encryptor.SetPassthroughMode(disabled) | ||
| if !disabled { | ||
| s.encryptor.SetKeyRatchet(s.session.GetKeyRatchet(string(userID))) | ||
| s.encryptor.SetKeyRatchet(kr) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| decryptor := s.decryptors[userID] | ||
| kr := s.session.GetKeyRatchet(string(userID)) | ||
| if !disabled && kr == nil { | ||
| s.logger.Warn("nil key ratchet for user after GetKeyRatchet", | ||
| slog.String("user_id", string(userID)), | ||
| slog.Int("protocol_version", int(protocolVersion)), | ||
| ) | ||
| return | ||
| } | ||
|
Comment on lines
+251
to
+258
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto the above |
||
| decryptor.TransitionToPassthroughMode(disabled) | ||
| if !disabled { | ||
| decryptor.TransitionToKeyRatchet(s.session.GetKeyRatchet(string(userID))) | ||
| decryptor.TransitionToKeyRatchet(kr) | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will never happen. If it did, we would be getting crashes everywhere due to
newKeyRatchet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's literally how I found the bug lol. my bot was crashing nonstop with
ErrMissingKeyRatchetevery time someone joined/left a voice channel until I traced it back to this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That isn't a crash, thats just a warning/error raised by the underlying library.
I will take a look when I find some time, but thank you for raising this issue. I am bit skeptical on changing the current behaviour because this is a very finiky system and I don't want to break it when DAVE fully rolls out and it breaks because we are always sending unencrypted packets / being unable to decrypt any packages correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davfsa honestly I'm glad you're pushing back, I'm not a Go developer so having someone who actually knows the internals review this properly is exactly what I need. switching from discordgo to disgo was the right move.
no rush, appreciate it 👍