Открытый ключ RSA, отправленный SSHD-сервером Apache, отличается от исходного - PullRequest
0 голосов
/ 08 апреля 2019

Я настраиваю SFTP-клиента с помощью Spring Integration.В моих интеграционных тестах я хочу, чтобы этот клиент подключался к встроенному SFTP-серверу, который я реализовал с использованием Apache SSHD.Важно, чтобы клиент проверял подлинность сервера.Теперь, когда проверка открытого ключа сервера завершается неудачно на стороне клиента:

[13:58:29]2019-04-08 11:58:29.363  INFO 93631 --- [ask-scheduler-1] o.s.i.s.s.DefaultSftpSessionFactory      : WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
[13:58:29]IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
[13:58:29]Someone could be eavesdropping on you right now (man-in-the-middle attack)!
[13:58:29]It is also possible that the RSA host key has just been changed.
[13:58:29]The fingerprint for the RSA key sent by the remote host [localhost]:30302 is
[13:58:29]2a:d7:91:85:e3:53:ab:aa:cd:74:5f:a2:c9:c9:8b:e7.
[13:58:29]Please contact your system administrator.
[13:58:29]Add correct host key in known_hosts to get rid of this message.
[13:58:29]Do you want to delete the old key and insert the new key?
[13:58:29]2019-04-08 11:58:29.363  INFO 93631 --- [ask-scheduler-1] com.jcraft.jsch                          : Disconnecting from localhost port 30302
[13:58:29]2019-04-08 11:58:29.408 ERROR 93631 --- [ask-scheduler-1] o.s.integration.handler.LoggingHandler   : org.springframework.messaging.MessagingException: Problem occurred while synchronizing remote to local directory; nested exception is org.springframework.messaging.MessagingException: Failed to obtain pooled item; nested exception is java.lang.IllegalStateException: failed to create SFTP Session
[13:58:29]  at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:331)
[...]
[13:58:29]  ... 28 more
[13:58:29]Caused by: com.jcraft.jsch.JSchException: HostKey has been changed: [localhost]:30302
[13:58:29]  at com.jcraft.jsch.Session.checkHost(Session.java:775)
[13:58:29]  at com.jcraft.jsch.Session.connect(Session.java:345)
[13:58:29]  at com.jcraft.jsch.Session.connect(Session.java:183)
[13:58:29]  at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:366)
[13:58:29]  ... 28 more

Я ожидаю, что проверка открытого ключа пройдет, так как я сам сгенерировал пару ключей:

$ ssh-keygen -t rsa sftpServer

На моем SSHD (SFTP) сервере я интегрирую закрытый ключ:

SshServer server = ServerBuilder.builder().interactiveAuthenticator(null).build();
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new ClassPathResource("META-INF/keys/sftpServer").getFile().toPath()));

Я не подозреваю, что клиент неисправен , так как я могу подключиться к автономномуЭкземпляр SFTP-сервера (т.е. Rebex Tiny SFTP-сервер).Там работает взаимная аутентификация.

При отладке в com.jcraft.jsch.Session#checkHost я вижу, что когда сервер передает свой открытый ключ, он уже отличается от того, который я хранил в своем клиенте.По крайней мере, показатель e отличается, как я вижу в байтовом массиве.

Как это может быть?Я понимаю, что сервер выводит открытый ключ из закрытого ключа.Нужно ли мне другое расширение JCE Java Cryptography, например Bouncycastle?

...