fix(gcm): reset AEAD packet/nonce counters during key exchanges (#165) - #14
Merged
Conversation
…jilau#165) Re-applies upstream vicajilau#166 that was lost during the local 'Fix AES-GCM padding' commit (4518047). AES-GCM AEAD ciphers must use a dedicated invocation counter that restarts at 0 on every NEWKEYS / key exchange, rather than the transport packet sequence number (_localPacketSN/_remotePacketSN) which keeps growing across rekeys. Using the SN as the GCM nonce causes 'message authentication code incorrect' failures against OpenSSH servers configured with aes256-gcm@openssh.com / aes128-gcm@openssh.com. Changes: - Add _localAeadPacketCount / _remoteAeadPacketCount fields. - Use them as the AEAD sequence (with post-increment) in _sendAeadPacket and _consumeAeadPacket. - Reset both counters to 0 in _applyLocalKeys / _applyRemoteKeys when an AEAD cipher is selected. Refs: lollipopkit/flutter_server_box#1193
📝 Walkthrough概览在 变更AEAD 独立计数器
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/src/ssh_transport.dart`:
- Around line 1039-1043: The rekey reset logic in the AEAD path only clears
`_localAeadPacketCount` when that branch is reached, but the server-side
`NEWKEYS` flow does not go through `_handleMessageKexReply()`. Update the server
rekey handling so `_localAeadPacketCount` is reset whenever new keys are
activated, using the same reset point as the client path in `ssh_transport.dart`
to keep AEAD nonce sequencing aligned after rekey.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d831aa14-594f-4843-a9eb-c5f0145fe9aa
📒 Files selected for processing (1)
lib/src/ssh_transport.dart
📜 Review details
🔇 Additional comments (4)
lib/src/ssh_transport.dart (4)
213-216: LGTM!
376-383: LGTM!
747-754: LGTM!
1109-1113: LGTM!
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.
Re-applies upstream vicajilau#166 that was lost during the local 'Fix AES-GCM padding' commit (4518047).
AES-GCM AEAD ciphers must use a dedicated invocation counter that restarts at 0 on every NEWKEYS / key exchange, rather than the transport packet sequence number (_localPacketSN/_remotePacketSN) which keeps growing across rekeys. Using the SN as the GCM nonce causes 'message authentication code incorrect' failures against OpenSSH servers configured with aes256-gcm@openssh.com / aes128-gcm@openssh.com.
Changes:
Refs: lollipopkit/flutter_server_box#1193
Summary by CodeRabbit