Skip to content

Commit 629b2b5

Browse files
Add org.eclipse.jgit.ssh.jsch stable-5.13 fork (#1)
* Add org.eclipse.jgit.ssh.jsch stable-5.13 fork * Formatting --------- Co-authored-by: Tim te Beek <[email protected]>
1 parent 5cf3f1a commit 629b2b5

File tree

8 files changed

+1491
-0
lines changed

8 files changed

+1491
-0
lines changed

jgit-ssh-jsch/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fork of org.eclipse.jgit.ssh.jsch stable-5.13 with com.github.mwiede:jsch for support of id\_ecdsa, id\_ed25519 and id\_ed448 SSH key types.

jgit-ssh-jsch/build.gradle.kts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
plugins {
2+
id("org.openrewrite.build.language-library")
3+
}
4+
5+
dependencies {
6+
implementation(project(":jgit"))
7+
implementation("com.github.mwiede:jsch:0.2.17")
8+
compileOnly("org.slf4j:slf4j-api:1.7.36")
9+
}
10+
11+
java {
12+
toolchain {
13+
languageVersion.set(JavaLanguageVersion.of(8))
14+
}
15+
}
16+
17+
tasks.withType<JavaCompile>().configureEach {
18+
options.isFork = true
19+
options.release.set(null as? Int?) // remove `--release 8` set in `org.openrewrite.java-base`
20+
}
21+
22+
tasks.named("javadoc") {
23+
enabled = false
24+
}
25+
26+
tasks.named("licenseMain") {
27+
enabled = false
28+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2020, Michael Dardis <[email protected]> and others
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Distribution License v. 1.0 which is available at
6+
* https://www.eclipse.org/org/documents/edl-v10.php.
7+
*
8+
* SPDX-License-Identifier: BSD-3-Clause
9+
*/
10+
package org.openrewrite.jgit.internal.transport.jsch;
11+
12+
import org.openrewrite.jgit.nls.NLS;
13+
import org.openrewrite.jgit.nls.TranslationBundle;
14+
15+
/**
16+
* Externalized text messages for localization.
17+
*/
18+
public final class JSchText extends TranslationBundle {
19+
20+
/**
21+
* Get an instance of this translation bundle.
22+
*
23+
* @return an instance of this translation bundle
24+
*/
25+
public static JSchText get() {
26+
return NLS.getBundleFor(JSchText.class);
27+
}
28+
29+
// @formatter:off
30+
/***/ public String connectionFailed;
31+
/***/ public String sshUserNameError;
32+
/***/ public String transportSSHRetryInterrupt;
33+
/***/ public String unknownHost;
34+
35+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright (C) 2010, Google Inc. and others
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Distribution License v. 1.0 which is available at
6+
* https://www.eclipse.org/org/documents/edl-v10.php.
7+
*
8+
* SPDX-License-Identifier: BSD-3-Clause
9+
*/
10+
11+
//TODO(ms): move to org.openrewrite.jgit.ssh.jsch in 6.0
12+
package org.openrewrite.jgit.transport;
13+
14+
import java.util.ArrayList;
15+
import java.util.Arrays;
16+
import java.util.List;
17+
18+
import com.jcraft.jsch.Session;
19+
import com.jcraft.jsch.UIKeyboardInteractive;
20+
import com.jcraft.jsch.UserInfo;
21+
22+
/**
23+
* A JSch {@link com.jcraft.jsch.UserInfo} adapter for a
24+
* {@link org.openrewrite.jgit.transport.CredentialsProvider}.
25+
*/
26+
public class CredentialsProviderUserInfo implements UserInfo,
27+
UIKeyboardInteractive {
28+
private final URIish uri;
29+
30+
private final CredentialsProvider provider;
31+
32+
private String password;
33+
34+
private String passphrase;
35+
36+
/**
37+
* Wrap a CredentialsProvider to make it suitable for use with JSch.
38+
*
39+
* @param session
40+
* the JSch session this UserInfo will support authentication on.
41+
* @param credentialsProvider
42+
* the provider that will perform the authentication.
43+
*/
44+
public CredentialsProviderUserInfo(Session session,
45+
CredentialsProvider credentialsProvider) {
46+
this.uri = createURI(session);
47+
this.provider = credentialsProvider;
48+
}
49+
50+
private static URIish createURI(Session session) {
51+
URIish uri = new URIish();
52+
uri = uri.setScheme("ssh"); //$NON-NLS-1$
53+
uri = uri.setUser(session.getUserName());
54+
uri = uri.setHost(session.getHost());
55+
uri = uri.setPort(session.getPort());
56+
return uri;
57+
}
58+
59+
/** {@inheritDoc} */
60+
@Override
61+
public String getPassword() {
62+
return password;
63+
}
64+
65+
/** {@inheritDoc} */
66+
@Override
67+
public String getPassphrase() {
68+
return passphrase;
69+
}
70+
71+
/** {@inheritDoc} */
72+
@Override
73+
public boolean promptPassphrase(String msg) {
74+
CredentialItem.StringType v = newPrompt(msg);
75+
if (provider.get(uri, v)) {
76+
passphrase = v.getValue();
77+
return true;
78+
}
79+
passphrase = null;
80+
return false;
81+
}
82+
83+
/** {@inheritDoc} */
84+
@Override
85+
public boolean promptPassword(String msg) {
86+
CredentialItem.Password p = new CredentialItem.Password(msg);
87+
if (provider.get(uri, p)) {
88+
password = new String(p.getValue());
89+
return true;
90+
}
91+
password = null;
92+
return false;
93+
}
94+
95+
private CredentialItem.StringType newPrompt(String msg) {
96+
return new CredentialItem.StringType(msg, true);
97+
}
98+
99+
/** {@inheritDoc} */
100+
@Override
101+
public boolean promptYesNo(String msg) {
102+
CredentialItem.YesNoType v = new CredentialItem.YesNoType(msg);
103+
return provider.get(uri, v) && v.getValue();
104+
}
105+
106+
/** {@inheritDoc} */
107+
@Override
108+
public void showMessage(String msg) {
109+
provider.get(uri, new CredentialItem.InformationalMessage(msg));
110+
}
111+
112+
/** {@inheritDoc} */
113+
@Override
114+
public String[] promptKeyboardInteractive(String destination, String name,
115+
String instruction, String[] prompt, boolean[] echo) {
116+
CredentialItem.StringType[] v = new CredentialItem.StringType[prompt.length];
117+
for (int i = 0; i < prompt.length; i++)
118+
v[i] = new CredentialItem.StringType(prompt[i], !echo[i]);
119+
120+
List<CredentialItem> items = new ArrayList<>();
121+
if (instruction != null && instruction.length() > 0)
122+
items.add(new CredentialItem.InformationalMessage(instruction));
123+
items.addAll(Arrays.asList(v));
124+
125+
if (!provider.get(uri, items))
126+
return null; // cancel
127+
128+
String[] result = new String[v.length];
129+
for (int i = 0; i < v.length; i++)
130+
result[i] = v[i].getValue();
131+
return result;
132+
}
133+
}

0 commit comments

Comments
 (0)