Update apache sshd to 2.3.0
Also update the following dependencies: * eddsa to 0.3.0 * mina-core to 2.0.21 Change-Id: I9cfa46458c95adcb2c1ab8cf5cebde28b7971afc
This commit is contained in:
parent
350a451832
commit
757709ec82
34
WORKSPACE
34
WORKSPACE
@ -818,28 +818,36 @@ maven_jar(
|
||||
sha1 = "89bb3aa5b98b48e584eee2a7401b7682a46779b4",
|
||||
)
|
||||
|
||||
SSHD_VERS = "2.3.0"
|
||||
|
||||
maven_jar(
|
||||
name = "sshd",
|
||||
artifact = "org.apache.sshd:sshd-core:2.0.0",
|
||||
sha1 = "f4275079a2463cfd2bf1548a80e1683288a8e86b",
|
||||
artifact = "org.apache.sshd:sshd-core:" + SSHD_VERS,
|
||||
sha1 = "21aeea9deba96c9b81ea0935fa4fac61aa3cf646",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "eddsa",
|
||||
artifact = "net.i2p.crypto:eddsa:0.2.0",
|
||||
sha1 = "0856a92559c4daf744cb27c93cd8b7eb1f8c4780",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "mina-core",
|
||||
artifact = "org.apache.mina:mina-core:2.0.17",
|
||||
sha1 = "7e10ec974760436d931f3e58be507d1957bcc8db",
|
||||
name = "sshd-common",
|
||||
artifact = "org.apache.sshd:sshd-common:" + SSHD_VERS,
|
||||
sha1 = "8b6e3baaa0d35b547696965eef3e62477f5e74c9",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "sshd-mina",
|
||||
artifact = "org.apache.sshd:sshd-mina:2.0.0",
|
||||
sha1 = "50f2669312494f6c1996d8bd0d266c1fca7be6f6",
|
||||
artifact = "org.apache.sshd:sshd-mina:" + SSHD_VERS,
|
||||
sha1 = "55dc0830dfcbceba01f9460812ee454978a15fe8",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "eddsa",
|
||||
artifact = "net.i2p.crypto:eddsa:0.3.0",
|
||||
sha1 = "1901c8d4d8bffb7d79027686cfb91e704217c3e1",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "mina-core",
|
||||
artifact = "org.apache.mina:mina-core:2.0.21",
|
||||
sha1 = "e1a317689ecd438f54e863747e832f741ef8e092",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
|
@ -34,7 +34,7 @@ public class SshdModule extends AbstractModule {
|
||||
if (keys == null) {
|
||||
keys = new SimpleGeneratorHostKeyProvider();
|
||||
keys.setAlgorithm("RSA");
|
||||
keys.loadKeys();
|
||||
keys.loadKeys(null);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import com.google.gerrit.sshd.SshScope.Context;
|
||||
import com.google.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.apache.sshd.server.channel.ChannelSession;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
@ -47,7 +48,7 @@ public abstract class AbstractGitCommand extends BaseCommand {
|
||||
protected Project project;
|
||||
|
||||
@Override
|
||||
public void start(Environment env) {
|
||||
public void start(ChannelSession channel, Environment env) {
|
||||
Context ctx = context.subContext(newSession(), context.getCommandLine());
|
||||
final Context old = sshScope.set(ctx);
|
||||
try {
|
||||
|
@ -27,6 +27,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.apache.sshd.server.channel.ChannelSession;
|
||||
import org.apache.sshd.server.command.Command;
|
||||
|
||||
/** Command that executes some other command. */
|
||||
@ -47,9 +48,9 @@ public class AliasCommand extends BaseCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Environment env) throws IOException {
|
||||
public void start(ChannelSession channel, Environment env) throws IOException {
|
||||
try {
|
||||
begin(env);
|
||||
begin(channel, env);
|
||||
} catch (Failure e) {
|
||||
String msg = e.getMessage();
|
||||
if (!msg.endsWith("\n")) {
|
||||
@ -61,7 +62,7 @@ public class AliasCommand extends BaseCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private void begin(Environment env) throws IOException, Failure {
|
||||
private void begin(ChannelSession channel, Environment env) throws IOException, Failure {
|
||||
Map<String, CommandProvider> map = root.getMap();
|
||||
for (String name : chain(command)) {
|
||||
CommandProvider p = map.get(name);
|
||||
@ -90,15 +91,15 @@ public class AliasCommand extends BaseCommand {
|
||||
}
|
||||
provideStateTo(cmd);
|
||||
atomicCmd.set(cmd);
|
||||
cmd.start(env);
|
||||
cmd.start(channel, env);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
public void destroy(ChannelSession channel) {
|
||||
Command cmd = atomicCmd.getAndSet(null);
|
||||
if (cmd != null) {
|
||||
try {
|
||||
cmd.destroy();
|
||||
cmd.destroy(channel);
|
||||
} catch (Exception e) {
|
||||
Throwables.throwIfUnchecked(e);
|
||||
throw new RuntimeException(e);
|
||||
|
@ -57,6 +57,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import org.apache.sshd.common.SshException;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.apache.sshd.server.ExitCallback;
|
||||
import org.apache.sshd.server.channel.ChannelSession;
|
||||
import org.apache.sshd.server.command.Command;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
@ -182,7 +183,7 @@ public abstract class BaseCommand implements Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
public void destroy(ChannelSession channel) {
|
||||
Future<?> future = task.getAndSet(null);
|
||||
if (future != null && !future.isDone()) {
|
||||
future.cancel(true);
|
||||
@ -264,7 +265,8 @@ public abstract class BaseCommand implements Command {
|
||||
/**
|
||||
* Spawn a function into its own thread.
|
||||
*
|
||||
* <p>Typically this should be invoked within {@link Command#start(Environment)}, such as:
|
||||
* <p>Typically this should be invoked within {@link Command#start(ChannelSession, Environment)},
|
||||
* such as:
|
||||
*
|
||||
* <pre>
|
||||
* startThread(new CommandRunnable() {
|
||||
|
@ -40,6 +40,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.apache.sshd.server.ExitCallback;
|
||||
import org.apache.sshd.server.SessionAware;
|
||||
import org.apache.sshd.server.channel.ChannelSession;
|
||||
import org.apache.sshd.server.command.Command;
|
||||
import org.apache.sshd.server.command.CommandFactory;
|
||||
import org.apache.sshd.server.session.ServerSession;
|
||||
@ -91,13 +92,13 @@ class CommandFactoryProvider implements Provider<CommandFactory>, LifecycleListe
|
||||
|
||||
@Override
|
||||
public CommandFactory get() {
|
||||
return requestCommand -> {
|
||||
String c = requestCommand;
|
||||
return (channelSession, requestCommand) -> {
|
||||
String command = requestCommand;
|
||||
SshCreateCommandInterceptor interceptor = createCommandInterceptor.get();
|
||||
if (interceptor != null) {
|
||||
c = interceptor.intercept(c);
|
||||
command = interceptor.intercept(command);
|
||||
}
|
||||
return new Trampoline(c);
|
||||
return new Trampoline(command);
|
||||
};
|
||||
}
|
||||
|
||||
@ -148,7 +149,7 @@ class CommandFactoryProvider implements Provider<CommandFactory>, LifecycleListe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Environment env) throws IOException {
|
||||
public void start(ChannelSession channel, Environment env) throws IOException {
|
||||
this.env = env;
|
||||
final Context ctx = this.ctx;
|
||||
task.set(
|
||||
@ -157,7 +158,7 @@ class CommandFactoryProvider implements Provider<CommandFactory>, LifecycleListe
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
onStart();
|
||||
onStart(channel);
|
||||
} catch (Exception e) {
|
||||
logger.atWarning().withCause(e).log(
|
||||
"Cannot start command \"%s\" for user %s",
|
||||
@ -172,7 +173,7 @@ class CommandFactoryProvider implements Provider<CommandFactory>, LifecycleListe
|
||||
}));
|
||||
}
|
||||
|
||||
private void onStart() throws IOException {
|
||||
private void onStart(ChannelSession channel) throws IOException {
|
||||
synchronized (this) {
|
||||
final Context old = sshScope.set(ctx);
|
||||
try {
|
||||
@ -195,7 +196,7 @@ class CommandFactoryProvider implements Provider<CommandFactory>, LifecycleListe
|
||||
log(rc);
|
||||
}
|
||||
});
|
||||
cmd.start(env);
|
||||
cmd.start(channel, env);
|
||||
} finally {
|
||||
sshScope.set(old);
|
||||
}
|
||||
@ -225,20 +226,20 @@ class CommandFactoryProvider implements Provider<CommandFactory>, LifecycleListe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
public void destroy(ChannelSession channel) {
|
||||
Future<?> future = task.getAndSet(null);
|
||||
if (future != null) {
|
||||
future.cancel(true);
|
||||
destroyExecutor.execute(this::onDestroy);
|
||||
destroyExecutor.execute(() -> onDestroy(channel));
|
||||
}
|
||||
}
|
||||
|
||||
private void onDestroy() {
|
||||
private void onDestroy(ChannelSession channel) {
|
||||
synchronized (this) {
|
||||
if (cmd != null) {
|
||||
final Context old = sshScope.set(ctx);
|
||||
try {
|
||||
cmd.destroy();
|
||||
cmd.destroy(channel);
|
||||
log(BaseCommand.STATUS_CANCEL);
|
||||
} finally {
|
||||
ctx = null;
|
||||
|
@ -31,6 +31,7 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyPair;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Collection;
|
||||
@ -80,19 +81,24 @@ class DatabasePubKeyAuth implements PublickeyAuthenticator {
|
||||
}
|
||||
|
||||
private static Set<PublicKey> myHostKeys(KeyPairProvider p) {
|
||||
final Set<PublicKey> keys = new HashSet<>(6);
|
||||
addPublicKey(keys, p, KeyPairProvider.SSH_ED25519);
|
||||
addPublicKey(keys, p, KeyPairProvider.ECDSA_SHA2_NISTP256);
|
||||
addPublicKey(keys, p, KeyPairProvider.ECDSA_SHA2_NISTP384);
|
||||
addPublicKey(keys, p, KeyPairProvider.ECDSA_SHA2_NISTP521);
|
||||
addPublicKey(keys, p, KeyPairProvider.SSH_RSA);
|
||||
addPublicKey(keys, p, KeyPairProvider.SSH_DSS);
|
||||
Set<PublicKey> keys = new HashSet<>(6);
|
||||
try {
|
||||
addPublicKey(keys, p, KeyPairProvider.SSH_ED25519);
|
||||
addPublicKey(keys, p, KeyPairProvider.ECDSA_SHA2_NISTP256);
|
||||
addPublicKey(keys, p, KeyPairProvider.ECDSA_SHA2_NISTP384);
|
||||
addPublicKey(keys, p, KeyPairProvider.ECDSA_SHA2_NISTP521);
|
||||
addPublicKey(keys, p, KeyPairProvider.SSH_RSA);
|
||||
addPublicKey(keys, p, KeyPairProvider.SSH_DSS);
|
||||
} catch (IOException | GeneralSecurityException e) {
|
||||
throw new IllegalStateException("Cannot load SSHD host key", e);
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
private static void addPublicKey(
|
||||
final Collection<PublicKey> out, KeyPairProvider p, String type) {
|
||||
final KeyPair pair = p.loadKey(type);
|
||||
private static void addPublicKey(Collection<PublicKey> out, KeyPairProvider p, String type)
|
||||
throws IOException, GeneralSecurityException {
|
||||
KeyPair pair = p.loadKey(null, type);
|
||||
if (pair != null && pair.getPublic() != null) {
|
||||
out.add(pair.getPublic());
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.apache.sshd.server.channel.ChannelSession;
|
||||
import org.apache.sshd.server.command.Command;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
|
||||
@ -69,7 +70,7 @@ final class DispatchCommand extends BaseCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Environment env) throws IOException {
|
||||
public void start(ChannelSession channel, Environment env) throws IOException {
|
||||
try {
|
||||
parseCommandLine();
|
||||
if (Strings.isNullOrEmpty(commandName)) {
|
||||
@ -115,7 +116,7 @@ final class DispatchCommand extends BaseCommand {
|
||||
|
||||
provideStateTo(cmd);
|
||||
atomicCmd.set(cmd);
|
||||
cmd.start(env);
|
||||
cmd.start(channel, env);
|
||||
|
||||
} catch (UnloggedFailure e) {
|
||||
String msg = e.getMessage();
|
||||
@ -145,11 +146,11 @@ final class DispatchCommand extends BaseCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
public void destroy(ChannelSession channel) {
|
||||
Command cmd = atomicCmd.getAndSet(null);
|
||||
if (cmd != null) {
|
||||
try {
|
||||
cmd.destroy();
|
||||
cmd.destroy(channel);
|
||||
} catch (Exception e) {
|
||||
Throwables.throwIfUnchecked(e);
|
||||
throw new RuntimeException(e);
|
||||
|
@ -18,7 +18,6 @@ import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.ProvisionException;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
@ -44,21 +43,21 @@ class HostKeyProvider implements Provider<KeyPairProvider> {
|
||||
Path ecdsaKey_521 = site.ssh_ecdsa_521;
|
||||
Path ed25519Key = site.ssh_ed25519;
|
||||
|
||||
final List<File> stdKeys = new ArrayList<>(6);
|
||||
final List<Path> stdKeys = new ArrayList<>(6);
|
||||
if (Files.exists(rsaKey)) {
|
||||
stdKeys.add(rsaKey.toAbsolutePath().toFile());
|
||||
stdKeys.add(rsaKey);
|
||||
}
|
||||
if (Files.exists(ecdsaKey_256)) {
|
||||
stdKeys.add(ecdsaKey_256.toAbsolutePath().toFile());
|
||||
stdKeys.add(ecdsaKey_256);
|
||||
}
|
||||
if (Files.exists(ecdsaKey_384)) {
|
||||
stdKeys.add(ecdsaKey_384.toAbsolutePath().toFile());
|
||||
stdKeys.add(ecdsaKey_384);
|
||||
}
|
||||
if (Files.exists(ecdsaKey_521)) {
|
||||
stdKeys.add(ecdsaKey_521.toAbsolutePath().toFile());
|
||||
stdKeys.add(ecdsaKey_521);
|
||||
}
|
||||
if (Files.exists(ed25519Key)) {
|
||||
stdKeys.add(ed25519Key.toAbsolutePath().toFile());
|
||||
stdKeys.add(ed25519Key);
|
||||
}
|
||||
|
||||
if (Files.exists(objKey)) {
|
||||
@ -70,14 +69,14 @@ class HostKeyProvider implements Provider<KeyPairProvider> {
|
||||
// Both formats of host key exist, we don't know which format
|
||||
// should be authoritative. Complain and abort.
|
||||
//
|
||||
stdKeys.add(objKey.toAbsolutePath().toFile());
|
||||
stdKeys.add(objKey);
|
||||
throw new ProvisionException("Multiple host keys exist: " + stdKeys);
|
||||
}
|
||||
if (stdKeys.isEmpty()) {
|
||||
throw new ProvisionException("No SSH keys under " + site.etc_dir);
|
||||
}
|
||||
FileKeyPairProvider kp = new FileKeyPairProvider();
|
||||
kp.setFiles(stdKeys);
|
||||
kp.setPaths(stdKeys);
|
||||
return kp;
|
||||
}
|
||||
}
|
||||
|
@ -27,12 +27,13 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import org.apache.sshd.common.Factory;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.apache.sshd.server.ExitCallback;
|
||||
import org.apache.sshd.server.SessionAware;
|
||||
import org.apache.sshd.server.channel.ChannelSession;
|
||||
import org.apache.sshd.server.command.Command;
|
||||
import org.apache.sshd.server.session.ServerSession;
|
||||
import org.apache.sshd.server.shell.ShellFactory;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
|
||||
@ -42,7 +43,7 @@ import org.eclipse.jgit.util.SystemReader;
|
||||
* <p>This implementation is used to ensure clients who try to SSH directly to this server without
|
||||
* supplying a command will get a reasonable error message, but cannot continue further.
|
||||
*/
|
||||
class NoShell implements Factory<Command> {
|
||||
class NoShell implements ShellFactory {
|
||||
private final Provider<SendMessage> shell;
|
||||
|
||||
@Inject
|
||||
@ -51,7 +52,7 @@ class NoShell implements Factory<Command> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command create() {
|
||||
public Command createShell(ChannelSession channel) {
|
||||
return shell.get();
|
||||
}
|
||||
|
||||
@ -98,7 +99,7 @@ class NoShell implements Factory<Command> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Environment env) throws IOException {
|
||||
public void start(ChannelSession channel, Environment env) throws IOException {
|
||||
Context old = sshScope.set(context);
|
||||
String message;
|
||||
try {
|
||||
@ -116,7 +117,7 @@ class NoShell implements Factory<Command> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {}
|
||||
public void destroy(ChannelSession channel) {}
|
||||
}
|
||||
|
||||
static class MessageFactory {
|
||||
|
@ -27,6 +27,7 @@ import com.google.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.apache.sshd.server.channel.ChannelSession;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
@ -45,7 +46,7 @@ public abstract class SshCommand extends BaseCommand {
|
||||
protected PrintWriter stderr;
|
||||
|
||||
@Override
|
||||
public void start(Environment env) throws IOException {
|
||||
public void start(ChannelSession channel, Environment env) throws IOException {
|
||||
startThread(
|
||||
() -> {
|
||||
parseCommandLine();
|
||||
|
@ -51,6 +51,7 @@ import java.nio.file.PathMatcher;
|
||||
import java.nio.file.WatchService;
|
||||
import java.nio.file.attribute.UserPrincipalLookupService;
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.KeyPair;
|
||||
import java.security.PublicKey;
|
||||
@ -381,12 +382,12 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final List<PublicKey> keys = myHostKeys();
|
||||
final List<HostKey> r = new ArrayList<>();
|
||||
List<HostKey> r = new ArrayList<>();
|
||||
List<PublicKey> keys = myHostKeys();
|
||||
for (PublicKey pub : keys) {
|
||||
final Buffer buf = new ByteArrayBuffer();
|
||||
Buffer buf = new ByteArrayBuffer();
|
||||
buf.putRawPublicKey(pub);
|
||||
final byte[] keyBin = buf.getCompactData();
|
||||
byte[] keyBin = buf.getCompactData();
|
||||
|
||||
for (String addr : advertised) {
|
||||
try {
|
||||
@ -397,24 +398,29 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(r);
|
||||
}
|
||||
|
||||
private List<PublicKey> myHostKeys() {
|
||||
final KeyPairProvider p = getKeyPairProvider();
|
||||
final List<PublicKey> keys = new ArrayList<>(6);
|
||||
addPublicKey(keys, p, KeyPairProvider.SSH_ED25519);
|
||||
addPublicKey(keys, p, KeyPairProvider.ECDSA_SHA2_NISTP256);
|
||||
addPublicKey(keys, p, KeyPairProvider.ECDSA_SHA2_NISTP384);
|
||||
addPublicKey(keys, p, KeyPairProvider.ECDSA_SHA2_NISTP521);
|
||||
addPublicKey(keys, p, KeyPairProvider.SSH_RSA);
|
||||
addPublicKey(keys, p, KeyPairProvider.SSH_DSS);
|
||||
KeyPairProvider p = getKeyPairProvider();
|
||||
List<PublicKey> keys = new ArrayList<>(6);
|
||||
try {
|
||||
addPublicKey(keys, p, KeyPairProvider.SSH_ED25519);
|
||||
addPublicKey(keys, p, KeyPairProvider.ECDSA_SHA2_NISTP256);
|
||||
addPublicKey(keys, p, KeyPairProvider.ECDSA_SHA2_NISTP384);
|
||||
addPublicKey(keys, p, KeyPairProvider.ECDSA_SHA2_NISTP521);
|
||||
addPublicKey(keys, p, KeyPairProvider.SSH_RSA);
|
||||
addPublicKey(keys, p, KeyPairProvider.SSH_DSS);
|
||||
} catch (IOException | GeneralSecurityException e) {
|
||||
throw new IllegalStateException("Cannot load SSHD host key", e);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
private static void addPublicKey(
|
||||
final Collection<PublicKey> out, KeyPairProvider p, String type) {
|
||||
final KeyPair pair = p.loadKey(type);
|
||||
private static void addPublicKey(final Collection<PublicKey> out, KeyPairProvider p, String type)
|
||||
throws IOException, GeneralSecurityException {
|
||||
final KeyPair pair = p.loadKey(null, type);
|
||||
if (pair != null && pair.getPublic() != null) {
|
||||
out.add(pair.getPublic());
|
||||
}
|
||||
@ -514,14 +520,14 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void initCiphers(Config cfg) {
|
||||
final List<NamedFactory<Cipher>> a = BaseBuilder.setUpDefaultCiphers(true);
|
||||
List<NamedFactory<Cipher>> a = BaseBuilder.setUpDefaultCiphers(true);
|
||||
|
||||
for (Iterator<NamedFactory<Cipher>> i = a.iterator(); i.hasNext(); ) {
|
||||
final NamedFactory<Cipher> f = i.next();
|
||||
NamedFactory<Cipher> f = i.next();
|
||||
try {
|
||||
final Cipher c = f.create();
|
||||
final byte[] key = new byte[c.getBlockSize()];
|
||||
final byte[] iv = new byte[c.getIVSize()];
|
||||
Cipher c = f.create();
|
||||
byte[] key = new byte[c.getKdfSize()];
|
||||
byte[] iv = new byte[c.getIVSize()];
|
||||
c.init(Cipher.Mode.Encrypt, key, iv);
|
||||
} catch (InvalidKeyException e) {
|
||||
logger.atWarning().log(
|
||||
@ -614,7 +620,8 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
|
||||
}
|
||||
|
||||
private void initSignatures() {
|
||||
setSignatureFactories(BaseBuilder.setUpDefaultSignatures(true));
|
||||
setSignatureFactories(
|
||||
NamedFactory.setUpBuiltinFactories(false, ServerBuilder.DEFAULT_SIGNATURE_PREFERENCE));
|
||||
}
|
||||
|
||||
private void initCompression(boolean enableCompression) {
|
||||
|
@ -19,7 +19,7 @@ import com.google.gerrit.server.CurrentUser;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import org.apache.sshd.common.AttributeStore.AttributeKey;
|
||||
import org.apache.sshd.common.AttributeRepository.AttributeKey;
|
||||
|
||||
/** Global data related to an active SSH connection. */
|
||||
public class SshSession {
|
||||
|
@ -35,6 +35,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.apache.sshd.server.channel.ChannelSession;
|
||||
import org.apache.sshd.server.command.Command;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.Option;
|
||||
@ -90,7 +91,7 @@ public final class SuExec extends BaseCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Environment env) throws IOException {
|
||||
public void start(ChannelSession channel, Environment env) throws IOException {
|
||||
try {
|
||||
checkCanRunAs();
|
||||
parseCommandLine();
|
||||
@ -102,7 +103,7 @@ public final class SuExec extends BaseCommand {
|
||||
cmd.setArguments(args.toArray(new String[args.size()]));
|
||||
provideStateTo(cmd);
|
||||
atomicCmd.set(cmd);
|
||||
cmd.start(env);
|
||||
cmd.start(channel, env);
|
||||
} finally {
|
||||
sshScope.set(old);
|
||||
}
|
||||
@ -158,11 +159,11 @@ public final class SuExec extends BaseCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
public void destroy(ChannelSession channel) {
|
||||
Command cmd = atomicCmd.getAndSet(null);
|
||||
if (cmd != null) {
|
||||
try {
|
||||
cmd.destroy();
|
||||
cmd.destroy(channel);
|
||||
} catch (Exception e) {
|
||||
Throwables.throwIfUnchecked(e);
|
||||
throw new RuntimeException(e);
|
||||
|
@ -34,6 +34,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.apache.sshd.server.channel.ChannelSession;
|
||||
|
||||
final class ScpCommand extends BaseCommand {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
@ -81,7 +82,7 @@ final class ScpCommand extends BaseCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Environment env) {
|
||||
public void start(ChannelSession channel, Environment env) {
|
||||
startThread(this::runImp, AccessPath.SSH_COMMAND);
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@ import org.apache.sshd.common.io.IoAcceptor;
|
||||
import org.apache.sshd.common.io.IoSession;
|
||||
import org.apache.sshd.common.io.mina.MinaSession;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.apache.sshd.server.channel.ChannelSession;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
/** Show the current cache states. */
|
||||
@ -97,7 +98,7 @@ final class ShowCaches extends SshCommand {
|
||||
private int nw;
|
||||
|
||||
@Override
|
||||
public void start(Environment env) throws IOException {
|
||||
public void start(ChannelSession channel, Environment env) throws IOException {
|
||||
String s = env.getEnv().get(Environment.ENV_COLUMNS);
|
||||
if (s != null && !s.isEmpty()) {
|
||||
try {
|
||||
@ -106,7 +107,7 @@ final class ShowCaches extends SshCommand {
|
||||
columns = 80;
|
||||
}
|
||||
}
|
||||
super.start(env);
|
||||
super.start(channel, env);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,6 +44,7 @@ import org.apache.sshd.common.io.mina.MinaSession;
|
||||
import org.apache.sshd.common.io.nio2.Nio2Acceptor;
|
||||
import org.apache.sshd.common.session.helpers.AbstractSession;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.apache.sshd.server.channel.ChannelSession;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
/** Show the current SSH connections. */
|
||||
@ -71,7 +72,7 @@ final class ShowConnections extends SshCommand {
|
||||
private int columns = 80;
|
||||
|
||||
@Override
|
||||
public void start(Environment env) throws IOException {
|
||||
public void start(ChannelSession channel, Environment env) throws IOException {
|
||||
String s = env.getEnv().get(Environment.ENV_COLUMNS);
|
||||
if (s != null && !s.isEmpty()) {
|
||||
try {
|
||||
@ -80,7 +81,7 @@ final class ShowConnections extends SshCommand {
|
||||
columns = 80;
|
||||
}
|
||||
}
|
||||
super.start(env);
|
||||
super.start(channel, env);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,6 +40,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.apache.sshd.server.channel.ChannelSession;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
/** Display the current work queue. */
|
||||
@ -70,7 +71,7 @@ final class ShowQueue extends SshCommand {
|
||||
private int maxCommandWidth;
|
||||
|
||||
@Override
|
||||
public void start(Environment env) throws IOException {
|
||||
public void start(ChannelSession channel, Environment env) throws IOException {
|
||||
String s = env.getEnv().get(Environment.ENV_COLUMNS);
|
||||
if (s != null && !s.isEmpty()) {
|
||||
try {
|
||||
@ -79,7 +80,7 @@ final class ShowQueue extends SshCommand {
|
||||
columns = 80;
|
||||
}
|
||||
}
|
||||
super.start(env);
|
||||
super.start(channel, env);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,6 +41,7 @@ import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.apache.sshd.server.channel.ChannelSession;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
@RequiresCapability(GlobalCapability.STREAM_EVENTS)
|
||||
@ -105,7 +106,7 @@ public final class StreamEvents extends BaseCommand {
|
||||
private Future<?> task;
|
||||
|
||||
@Override
|
||||
public void start(Environment env) throws IOException {
|
||||
public void start(ChannelSession channel, Environment env) throws IOException {
|
||||
try {
|
||||
parseCommandLine();
|
||||
} catch (UnloggedFailure e) {
|
||||
@ -179,7 +180,7 @@ public final class StreamEvents extends BaseCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
public void destroy(ChannelSession channel) {
|
||||
removeEventListenerRegistration();
|
||||
|
||||
final boolean exit;
|
||||
|
@ -6,6 +6,7 @@ java_library(
|
||||
visibility = ["//visibility:public"],
|
||||
exports = [
|
||||
":eddsa",
|
||||
"@sshd-common//jar",
|
||||
"@sshd-mina//jar",
|
||||
"@sshd//jar",
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user