Skip to content
This repository was archived by the owner on May 25, 2025. It is now read-only.

updates jsch version and fixes test to match exception correctly#389

Merged
int128 merged 4 commits intoint128:masterfrom
johnjaylward:master
Mar 9, 2025
Merged

updates jsch version and fixes test to match exception correctly#389
int128 merged 4 commits intoint128:masterfrom
johnjaylward:master

Conversation

@johnjaylward
Copy link
Contributor

@johnjaylward johnjaylward commented Feb 22, 2025

Fixes #301
Fixes #308
Fixes #356

Steps to verify the fix

  1. Bumped the version
  2. Corrected failing test. Was expecting IllegalArgumentException, but with the bump a corrected JSCHException is thrown with the message "AUTH FAIL"
  3. ran gradle build and confirmed all tests passed
// Paste the snippet

Backward compatibility

If someone is expecting an "IllegalArgumentException" on wrong passphrases for ssh keys, they will need to change their exception to the JSCHException.

@johnjaylward
Copy link
Contributor Author

@int128 I believe I fixed the build issue. The actions in my Repo completed successfully.

@johnjaylward
Copy link
Contributor Author

wait. I missed the release actions file. I will correct that too

@johnjaylward
Copy link
Contributor Author

ok, that should be all the gradle build actions.

@johnjaylward johnjaylward force-pushed the master branch 3 times, most recently from 173a93a to 2b14289 Compare February 27, 2025 02:37
@johnjaylward
Copy link
Contributor Author

rebased to current master

@elijahfhopp
Copy link
Contributor

My $0.02: looks good. Is that change in exception from jsch/documented by jsch? Worth looking into the code that test covers. Glad this update would fix the CVE.

@johnjaylward
Copy link
Contributor Author

Based on what I see in the change logs and java docs, all Identity Passphrase related errors should always have thrown JSchException... I'll dig in further to see if it was a bugfix on their side to correct the function, or if there is an API issue that needs to be addressed due to the update.

@johnjaylward
Copy link
Contributor Author

Findings for change from IllegalArgumentException to JSchException

  1. Test started failing at dependency change to com.github.mwiede:jsch:0.2.7
  2. Reviewed 0.2.7 changelog for JSchException and "USERAUTH fail" and there are a lot of changes around that.
  3. All Javadoc from the initial import (1.5.15) to current 0.2.23 show that passphrase errors should be JSchException
  4. I reverted back to the 0.2.5 and got this stack trace for the exception:
    java.lang.IllegalArgumentException: Could not sucessfully decrypt openssh v1 key
    	at com.jcraft.jsch.KeyPairDeferred.decrypt(KeyPairDeferred.java:49)
    	at com.jcraft.jsch.IdentityFile.setPassphrase(IdentityFile.java:64)
    	at com.jcraft.jsch.JSch.addIdentity(JSch.java:551)
    	at com.jcraft.jsch.JSch.addIdentity(JSch.java:496)
    	at com.jcraft.jsch.JSch.addIdentity(JSch.java:476)
    	at org.hidetake.groovy.ssh.connection.UserAuthentication$Trait$Helper.configureUserAuthentication(UserAuthentication.groovy:41)
    
  5. The stack trace for the current 0.2.23 is
    Caused by: com.jcraft.jsch.JSchException: USERAUTH fail
    	at app//com.jcraft.jsch.UserAuthPublicKey.decryptKey(UserAuthPublicKey.java:388)
    	at app//com.jcraft.jsch.UserAuthPublicKey._start(UserAuthPublicKey.java:157)
    	at app//com.jcraft.jsch.UserAuthPublicKey.start(UserAuthPublicKey.java:119)
    	at app//com.jcraft.jsch.Session.connect(Session.java:479)
    	at app//com.jcraft.jsch.Session.connect(Session.java:198)
    	at app//org.hidetake.groovy.ssh.connection.ConnectionManager.connectInternal(ConnectionManager.groovy:107)
    

This given the difference in stack traces, this looks like an intentional fix on their part to accomplish 2 goals:

  1. Simplify the call stack in general for key handling
  2. Bring the code up to match the javadocs

You can see that the new exception is happening later in the process when the connection is established instead of at the configuration point.

@johnjaylward
Copy link
Contributor Author

also took the opportunity to add the exception message to the test case validation.

@elijahfhopp
Copy link
Contributor

elijahfhopp commented Feb 28, 2025

Thank you for the robust documentation. That clears up any uncertainty I have about it. IllegalArgumentException was quite a confusing choice, glad they changed it. +1 to exception message in test.

@johnjaylward
Copy link
Contributor Author

@int128 , is there anything else I should do for this?

@int128 int128 merged commit 75ec565 into int128:master Mar 9, 2025
2 of 3 checks passed
@int128
Copy link
Owner

int128 commented Mar 9, 2025

Thank you very much!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bump core dependency com.github.mwiede:jsch to 0.2.7

3 participants

Comments