сейчас пытаюсь настроить простой (начальная точка) ssh-сервер с apache mina внутри приложения Quarkus.
Мой текущий код выглядит следующим образом (да, ведение журнала на данный момент специально):
Код: Выделить всё
public void start() throws IOException {
if (sshConfig.disable()) {
return;
}
if (sshd != null) {
return;
}
sshd = org.apache.sshd.server.SshServer.setUpDefaultServer();
sshd.setPort(sshConfig.port());
sshd.setHost(sshConfig.listenAddress());
// If the host key does not exist yet, it will be auto-created
final File hostKey = new File(sshConfig.privateHostKey());
SimpleGeneratorHostKeyProvider hostKeyProvider = new SimpleGeneratorHostKeyProvider(hostKey.toPath());
hostKeyProvider.setAlgorithm(KeyUtils.RSA_ALGORITHM);
if (!hostKey.exists()) {
final List hostKeys = hostKeyProvider.loadKeys(null);
if (!hostKeys.isEmpty()) {
Files.writeString(
new File(sshConfig.privateHostKey()).toPath(),
hostKeys.getFirst().getPrivate().toString()
);
Files.writeString(
new File(sshConfig.publicHostKey()).toPath(),
hostKeys.getFirst().getPublic().toString()
);
}
}
sshd.setKeyPairProvider(hostKeyProvider);
sshd.setHostKeyCertificateProvider(new FileHostKeyCertificateProvider(hostKey.toPath()));
sshd.setFileSystemFactory(NativeFileSystemFactory.INSTANCE);
sshd.setShellFactory(channel -> {
System.out.println("ShellFactory: " + channel);
return new InteractiveProcessShellFactory().createShell(channel);
});
sshd.setPasswordAuthenticator(new LoggingPasswordAuthenticator());
sshd.setKeyboardInteractiveAuthenticator(new LoggingKeyboardInteractiveAuthenticator());
sshd.setPublickeyAuthenticator(new LoggingPublicKeyAuthenticator());
sshd.setGSSAuthenticator(null);
sshd.setHostBasedAuthenticator((session, username, clientHostKey, clientHostName, clientUsername, certificates) -> {
System.out.println("Username: " + username);
System.out.println("ClientHostKey: " + clientHostKey);
System.out.println("ClientHostName: " + clientHostName);
System.out.println("ClientUsername: " + clientUsername);
return true;
});
sshd.setSubsystemFactories(List.of(
new SftpSubsystemFactory()
));
sshd.setCommandFactory((channel, command) -> {
System.out.println("Command: " + command);
return new UnknownCommand(command);
});
// sshd.setSessionFactory(new NoStrictKexSessionFactory(sshd));
sshd.start();
}
Код: Выделить всё
org.apache.sshd
sshd-core
2.14.0
org.apache.sshd
sshd-git
2.14.0
org.apache.sshd
sshd-sftp
2.14.0
Код: Выделить всё
2024-10-27 21:34:02,297 INFO [org.apa.ssh.com.uti.sec.bou.BouncyCastleSecurityProviderRegistrar] (Quarkus Main Thread) getOrCreateProvider(BC) created instance of org.bouncycastle.jce.provider.BouncyCastleProvider
2024-10-27 21:34:02,299 DEBUG [org.apa.ssh.com.uti.sec.SecurityUtils] (Quarkus Main Thread) register(EdDSA) not registered - enabled=true, supported=false
2024-10-27 21:34:02,322 INFO [org.apa.ssh.com.io.DefaultIoServiceFactoryFactory] (Quarkus Main Thread) No detected/configured IoServiceFactoryFactory; using Nio2ServiceFactoryFactory
2024-10-27 21:34:02,326 DEBUG [org.apa.ssh.ser.SshServer] (Quarkus Main Thread) start() - resolve bind host=127.0.0.1
2024-10-27 21:34:02,326 DEBUG [org.apa.ssh.com.io.nio.Nio2Acceptor] (Quarkus Main Thread) bind(/127.0.0.1:2222) binding to address
2024-10-27 21:34:02,328 DEBUG [org.apa.ssh.com.io.nio.Nio2Acceptor] (Quarkus Main Thread) setOption(SO_REUSEADDR)[true] from property=Property[socket-reuseaddr](Boolean]
2024-10-27 21:34:02,328 DEBUG [org.apa.ssh.com.io.nio.Nio2Acceptor] (Quarkus Main Thread) bind(/127.0.0.1:2222) bound to /127.0.0.1:2222
2024-10-27 21:34:02,367 INFO [io.quarkus] (Quarkus Main Thread) git-server 1.0.0-SNAPSHOT on JVM (powered by Quarkus 3.15.1) started in 1.022s. Listening on: http://localhost:8080
2024-10-27 21:34:02,367 INFO [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2024-10-27 21:34:02,367 INFO [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, config-yaml, rest, rest-jackson, smallrye-context-propagation, vertx]
2024-10-27 21:34:04,362 DEBUG [org.apa.ssh.com.io.nio.Nio2Acceptor] (sshd-SshServer[2fa1216](port=2222)-nio2-thread-1) setOption(SO_REUSEADDR)[true] from property=Property[socket-reuseaddr](Boolean]
2024-10-27 21:34:04,364 DEBUG [org.apa.ssh.com.io.nio.Nio2Session] (sshd-SshServer[2fa1216](port=2222)-nio2-thread-1) Creating IoSession on /127.0.0.1:2222 from /127.0.0.1:55728 via /127.0.0.1:2222
Код: Выделить всё
ssh -vvvv -i keyFile -p 2222 [email protected]
Код: Выделить всё
OpenSSH_9.6p1 Ubuntu-3ubuntu13.5, OpenSSL 3.0.13 30 Jan 2024
debug1: Reading configuration data /home/USER/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolve_canonicalize: hostname 127.0.0.1 is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/USER/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/USER/.ssh/known_hosts2'
debug3: channel_clear_timeouts: clearing
debug3: ssh_connect_direct: entering
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 2222.
debug3: set_sock_tos: set socket 3 IP_TOS 0x10
debug1: Connection established.
debug1: identity file keyFile type 0
debug1: identity file keyFile-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.5
kex_exchange_identification: read: Connection reset by peer
Connection reset by 127.0.0.1 port 2222

Пробовал скопировать тестовый код из https://github.com/apache/mina-sshd/blo ... s.java#L86 и много изменено на основе этого кода.
- Пробовал serverBuilder со всеми перестановками параметров.
- Пытался настроить сервер по умолчанию и изменить параметры после этого
- Пытался установить приветственный баннер (поскольку обычно случаются ошибки kex_identification, когда не отправляется номер версии или возникают ошибки рукопожатия)
- Пытался настроить NoStrictKexSession с https://github.com/apache/mina-sshd/blo ... s/howto.md
- Пыталась войти в систему с именем пользователя/паролем, открытым ключом RSA, общедоступным ed25519 key
- Пыталась сгенерировать разные ключи хоста.
- Пыталась настроить ключи хоста, сгенерированные вручную.
С уважением
Только что пришел на мой взгляд: может быть, Quarkus перехватывает все вызовы на любой порт? Не знаю, как, поскольку Quarkus не имеет привилегий на открытый сокет Mina, но, возможно, это возможное направление? Если да, то как сказать Кваркусу не делать этого?
Подробнее здесь: https://stackoverflow.com/questions/791 ... et-by-peer