Skip to content
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

Add Transport.isKeyExchangeRequired() to avoid unnecessary KEXINIT #811

Merged
merged 2 commits into from
Sep 16, 2022

Conversation

exceptionfactory
Copy link
Contributor

This pull request addresses SSH_MSG_UNIMPLEMENTED errors during key exchange described in issue #810.

Changes include adding isKeyExchangeRequired() to the Transport interface, with an implementation in TransportImpl that checks the status of Key Exchange completion and processing.

Checking KeyExchanger.isKexDone() indicates that at least one key exchange has not been completed, and checking KeyExchanger.isKexOngoing() indicates that a key exchange is not in progress. Checking Transport.isKeyExchangeRequired() in SSHClient.onConnect() avoids sending an additional SSH_MSG_KEXINIT packet when a key exchange is already in progress or completed.

Additional changes include adding a started timestamp when setting a thread name in ThreadNameProvider. The started timestamp makes it easier to distinguished between threads for multiple connections to the same remote host and port.

@codecov-commenter
Copy link

codecov-commenter commented Sep 16, 2022

Codecov Report

Merging #811 (7446307) into master (430cbfc) will decrease coverage by 0.02%.
The diff coverage is 57.14%.

@@             Coverage Diff              @@
##             master     #811      +/-   ##
============================================
- Coverage     64.71%   64.68%   -0.03%     
- Complexity     1459     1460       +1     
============================================
  Files           210      210              
  Lines          8519     8524       +5     
  Branches        778      779       +1     
============================================
+ Hits           5513     5514       +1     
- Misses         2601     2603       +2     
- Partials        405      407       +2     
Impacted Files Coverage Δ
...java/net/schmizz/sshj/transport/TransportImpl.java 64.87% <0.00%> (-0.27%) ⬇️
src/main/java/net/schmizz/sshj/SSHClient.java 58.52% <50.00%> (-0.44%) ⬇️
...com/hierynomus/sshj/common/ThreadNameProvider.java 71.42% <100.00%> (+4.76%) ⬆️
...t/schmizz/sshj/connection/ConnectionException.java 33.33% <0.00%> (-11.12%) ⬇️
...zz/sshj/connection/channel/ChannelInputStream.java 77.27% <0.00%> (-3.04%) ⬇️
.../java/net/schmizz/sshj/transport/KeyExchanger.java 77.17% <0.00%> (+0.54%) ⬆️
.../main/java/net/schmizz/sshj/sftp/PacketReader.java 95.74% <0.00%> (+4.25%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@hierynomus
Copy link
Owner

@exceptionfactory 1 test failed, can you have a look?

- Updated SSHClient.onConnect() to check isKeyExchangeRequired() before calling doKex()
- Added started timestamp in ThreadNameProvider for improved tracking
@exceptionfactory
Copy link
Contributor Author

Thanks for the feedback @hierynomus!

The test succeeded on a local build, but it appears to be an intermittent timing issue where the KeepAlive Thread may not have started. I pushed a new commit that moves the TIMED_WAITING status assertion after attempting authentication, which should make the test more reliable.

@hierynomus hierynomus merged commit 2551f8e into hierynomus:master Sep 16, 2022
@hierynomus
Copy link
Owner

Merged! Thanks for the improvement

@exceptionfactory
Copy link
Contributor Author

Thank you very much @hierynomus! Are you planning to do a new release of SSHJ soon? This would be very helpful for downstream consumers, and the internal nature of the Transport changes make it difficult to patch around without upgrading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants