Bug 576604 - JGit should not overwrite JSch properties, if they are already set.
Summary: JGit should not overwrite JSch properties, if they are already set.
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.13   Edit
Hardware: PC Windows 10
: P3 minor with 1 vote (vote)
Target Milestone: 6.0   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 576605
  Show dependency tree
 
Reported: 2021-10-13 08:39 EDT by D T CLA
Modified: 2021-11-23 17:14 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description D T CLA 2021-10-13 08:39:50 EDT
I tried to replace the original jsch with an updated variant, but that caused an NPE.

CloneCommand cloneCommand = Git.cloneRepository()
                .setURI("git@github.com:mwiede/jsch.git")
                .setDirectory(new File("target/junit/clone-test));
assertDoesNotThrow(cloneCommand::call).close(); // <-- Error

This is caused by the following line: https://gerrit.googlesource.com/jgit/+/refs/tags/v5.13.0.202109080827-r/org.eclipse.jgit.ssh.jsch/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java#401

JSch.setConfig("ssh-rsa", JSch.getConfig("signature.rsa"));
JSch.setConfig("ssh-dss", JSch.getConfig("signature.dss"));

These properties are already renamed in that fork, so the old properties are no longer present. IMO jgit should only set the properties if they aren't already set. (As they may already be set to a custom value).

"Original" JSch: https://github.com/is/jsch/blob/master/src/main/java/com/jcraft/jsch/JSch.java
Forked JSch: https://github.com/mwiede/jsch

Related issue in the forked libary:

https://github.com/mwiede/jsch/issues/85

The issue can be worked around using the following code, prior to invoking jgit:

JSch.setConfig("signature.rsa", JSch.getConfig("ssh-rsa"));

My preferred solution would be setting the property, only if it isn't already set:

if (JSch.getConfig("ssh-rsa") == null) {
  JSch.setConfig("ssh-rsa", JSch.getConfig("signature.rsa"));
}
if (JSch.getConfig("ssh-dss") == null) {
  JSch.setConfig("ssh-dss", JSch.getConfig("signature.dss"));
}

As proposed here: https://github.com/mwiede/jsch/issues/85#issuecomment-940985400
Comment 1 Thomas Wolf CLA 2021-10-13 10:14:13 EDT
JSch support is deprecated and is dropped completely in JGit 6.0.
Comment 2 Thomas Wolf CLA 2021-10-19 02:44:17 EDT
Let's fix this. I suppose we can drop JSch only once we have agent support for o.e.j.ssh.apache.
Comment 3 Eclipse Genie CLA 2021-10-19 03:14:24 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/186638
Comment 4 D T CLA 2021-10-19 05:10:35 EDT
Looks good to me.
Comment 6 Hiroshi Miura CLA 2021-11-03 21:53:14 EDT
Do you have any plan to port it to stable-5.13, and other stable branches such as stable-5.9, stable-5.10, stable-5.11, stable-5.12?
Comment 7 Thomas Wolf CLA 2021-11-04 06:18:06 EDT
(In reply to Hiroshi Miura from comment #6)
> Do you have any plan to port it to stable-5.13, and other stable branches
> such as stable-5.9, stable-5.10, stable-5.11, stable-5.12?

We could do 5.13, but we won't backport to any earlier branches.