Skip to content

Commit d356454

Browse files
committed
downloader: Migrate from JSch to MINA as the SSH backend for JGit
The used `org.eclipse.jgit.ssh.apache.agent` artifact has build-in ssh-agent support. As of 43ff39e there should have been no need anymore to avoid "keyboard-interactive" prompts as the `CredentialsProvider` is explicit set to ORT's own `AuthenticatorCredentialsProvider` only. Resolves #6029. Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
1 parent a6b3bdc commit d356454

File tree

3 files changed

+27
-43
lines changed

3 files changed

+27
-43
lines changed

downloader/build.gradle.kts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,8 @@ dependencies {
2727

2828
implementation(project(":utils:ort-utils"))
2929

30-
// Force the generated Maven POM to use the same version of "jsch" Gradle resolves the version conflict to.
31-
implementation("com.jcraft:jsch") {
32-
version {
33-
strictly("0.1.55")
34-
}
35-
}
36-
3730
implementation(libs.jgit)
38-
implementation(libs.jgitJsch)
39-
implementation(libs.jschAgentProxy)
31+
implementation(libs.jgitSshApacheAgent)
4032
implementation(libs.svnkit)
4133

4234
testImplementation(libs.mockk)

downloader/src/main/kotlin/vcs/Git.kt

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@
1919

2020
package org.ossreviewtoolkit.downloader.vcs
2121

22-
import com.jcraft.jsch.JSch
23-
import com.jcraft.jsch.agentproxy.AgentProxyException
24-
import com.jcraft.jsch.agentproxy.RemoteIdentityRepository
25-
import com.jcraft.jsch.agentproxy.connector.SSHAgentConnector
26-
import com.jcraft.jsch.agentproxy.usocket.JNAUSocketFactory
27-
2822
import com.vdurmont.semver4j.Requirement
2923

3024
import java.io.File
3125
import java.io.IOException
3226
import java.net.Authenticator
27+
import java.net.InetSocketAddress
28+
import java.security.PublicKey
3329
import java.util.regex.Pattern
3430

3531
import org.apache.logging.log4j.kotlin.Logging
@@ -45,7 +41,10 @@ import org.eclipse.jgit.transport.CredentialsProvider
4541
import org.eclipse.jgit.transport.SshSessionFactory
4642
import org.eclipse.jgit.transport.TagOpt
4743
import org.eclipse.jgit.transport.URIish
48-
import org.eclipse.jgit.transport.ssh.jsch.JschConfigSessionFactory
44+
import org.eclipse.jgit.transport.sshd.DefaultProxyDataFactory
45+
import org.eclipse.jgit.transport.sshd.JGitKeyCache
46+
import org.eclipse.jgit.transport.sshd.ServerKeyDatabase
47+
import org.eclipse.jgit.transport.sshd.SshdSessionFactory
4948

5049
import org.ossreviewtoolkit.downloader.VersionControlSystem
5150
import org.ossreviewtoolkit.downloader.WorkingTree
@@ -73,30 +72,25 @@ class Git : VersionControlSystem(), CommandLineTool {
7372
// discrepancies in the way .netrc files are interpreted between JGit's and ORT's implementation.
7473
CredentialsProvider.setDefault(AuthenticatorCredentialsProvider)
7574

76-
val sessionFactory = object : JschConfigSessionFactory() {
77-
override fun configureJSch(jsch: JSch) {
78-
// Accept unknown hosts.
79-
JSch.setConfig("StrictHostKeyChecking", "no")
80-
81-
// Limit to "publickey" to avoid "keyboard-interactive" prompts.
82-
JSch.setConfig("PreferredAuthentications", "publickey")
83-
84-
try {
85-
// By default, JGit configures JSch to use identity files (named "identity", "id_rsa" or
86-
// "id_dsa") from the current user's ".ssh" directory only, also see
87-
// https://www.codeaffine.com/2014/12/09/jgit-authentication/. Additionally configure JSch to
88-
// connect to an SSH-Agent if available.
89-
if (SSHAgentConnector.isConnectorAvailable()) {
90-
val socketFactory = JNAUSocketFactory()
91-
val connector = SSHAgentConnector(socketFactory)
92-
jsch.identityRepository = RemoteIdentityRepository(connector)
93-
}
94-
} catch (e: AgentProxyException) {
95-
e.showStackTrace()
96-
97-
logger.error { "Could not create SSH Agent connector: ${e.collectMessages()}" }
98-
}
99-
}
75+
// Create a dummy key database that accepts any key from any (unknown) host.
76+
val dummyKeyDatabase = object : ServerKeyDatabase {
77+
override fun lookup(
78+
connectAddress: String,
79+
remoteAddress: InetSocketAddress,
80+
config: ServerKeyDatabase.Configuration
81+
) = emptyList<PublicKey>()
82+
83+
override fun accept(
84+
connectAddress: String,
85+
remoteAddress: InetSocketAddress,
86+
serverKey: PublicKey,
87+
config: ServerKeyDatabase.Configuration,
88+
provider: CredentialsProvider?
89+
) = true
90+
}
91+
92+
val sessionFactory = object : SshdSessionFactory(JGitKeyCache(), DefaultProxyDataFactory()) {
93+
override fun getServerKeyDatabase(homeDir: File, sshDir: File) = dummyKeyDatabase
10094
}
10195

10296
SshSessionFactory.setInstance(sessionFactory)

gradle/libs.versions.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ jackson = "2.13.4"
3434
jgit = "6.3.0.202209071007-r"
3535
jiraRestClient = "5.2.4"
3636
jruby = "9.3.9.0"
37-
jschAgentProxy = "0.0.9"
3837
jslt = "0.1.13"
3938
jsonSchemaValidator = "1.0.73"
4039
kotest = "5.5.3"
@@ -111,11 +110,10 @@ jacksonDatatypeJsr310 = { module = "com.fasterxml.jackson.datatype:jackson-datat
111110
jacksonModuleJaxbAnnotations = { module = "com.fasterxml.jackson.module:jackson-module-jaxb-annotations", version.ref = "jackson" }
112111
jacksonModuleKotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" }
113112
jgit = { module = "org.eclipse.jgit:org.eclipse.jgit", version.ref = "jgit" }
114-
jgitJsch = { module = "org.eclipse.jgit:org.eclipse.jgit.ssh.jsch", version.ref = "jgit" }
113+
jgitSshApacheAgent = { module = "org.eclipse.jgit:org.eclipse.jgit.ssh.apache.agent", version.ref = "jgit" }
115114
jiraRestClientApi = { module = "com.atlassian.jira:jira-rest-java-client-api", version.ref = "jiraRestClient" }
116115
jiraRestClientApp = { module = "com.atlassian.jira:jira-rest-java-client-app", version.ref = "jiraRestClient" }
117116
jruby = { module = "org.jruby:jruby-complete", version.ref = "jruby" }
118-
jschAgentProxy = { module = "com.jcraft:jsch.agentproxy.jsch", version.ref = "jschAgentProxy" }
119117
jslt = { module = "com.schibsted.spt.data:jslt", version.ref = "jslt" }
120118
jsonSchemaValidator = { module = "com.networknt:json-schema-validator", version.ref = "jsonSchemaValidator" }
121119
kotestAssertionsCore = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }

0 commit comments

Comments
 (0)