-
Notifications
You must be signed in to change notification settings - Fork 16
Fix invalid pubkey panic #331
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
Merged
Merged
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
Prevents dmsg server crashes when handling clients with invalid public keys. Changes: - Modified noise DH function to use non-panic cipher methods (NewPubKey, NewSecKey, ECDH) instead of MustNewPubKey, MustNewSecKey, MustECDH - Added panic recovery in noise handshake to catch any remaining panics - Added panic recovery in server handleSession to prevent server crashes - Added panic recovery in server stream goroutines for additional safety - Added error logging for failed session creation Invalid public keys will now cause the handshake to fail gracefully instead of crashing the entire dmsg server process. The server will log the error and continue serving other clients. Fixes a 2+ year old issue where 'Invalid public key' panic would crash production dmsg servers.
Adds TestInvalidPublicKeyNoPanic to verify the server doesn't crash when receiving connections with invalid public keys during noise handshake. The test: 1. Sends malformed handshake data with invalid public key to server 2. Verifies server logs error and rejects connection gracefully 3. Confirms server continues to accept valid client connections This is a regression test for the 2+ year old panic bug that has been fixed in the previous commits.
- Use proper error handling for conn.Close() - Add nolint directives for intentionally ignored errors - Fix ineffectual assignment in test code
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.
Fixes #221
Summary of Changes
This panic:
was caused by cipher.MustNewPubKey() in the noise handshake DH function (pkg/noise/dh.go:26), which would
crash the entire server when a client sent an invalid public key.
Fixed Files (branch fix/invalid-pubkey-panic )
Defense in Depth Approach
The fix uses multiple layers:
• Root cause: DH function now handles invalid keys gracefully, returning empty bytes that will cause handshake to fail
• Handshake layer: Panic recovery catches any remaining panics and converts to errors
• Session layer: Panic recovery prevents session crashes from affecting the server
• Stream layer: Individual stream panics won't kill the session