【问题标题】:"no matching host key type found" - Apache MINA SFTP server“找不到匹配的主机密钥类型” - Apache MINA SFTP 服务器
【发布时间】:2016-02-14 21:55:22
【问题描述】:

我希望使用 Apache MINA 在 Java 中设置 SFTP 服务器。

它似乎开始正常,但是当我尝试使用 OpenSSH 客户端连接到它时,我得到:

$ ssh localhost -p 2222
Unable to negotiate with ::1: no matching host key type found. Their offer: ssh-dss
$ ssh -V
OpenSSH_7.1p1, OpenSSL 1.0.2d 9 Jul 2015

Java 应用程序日志:

! java.lang.IllegalStateException: Unable to negotiate key exchange for server host key algorithms (client: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,ssh-rsa / server: ssh-dss)
! at org.apache.sshd.common.session.AbstractSession.negotiate(AbstractSession.java:1279) ~[sshd-core-1.0.0.jar:1.0.0]

我的 Maven 依赖项是:

<dependency>
    <groupId>org.apache.sshd</groupId>
    <artifactId>sshd-sftp</artifactId>
    <version>0.11.0</version>
</dependency>

<dependency>
    <groupId>org.apache.sshd</groupId>
    <artifactId>sshd-core</artifactId>
    <version>1.0.0</version>
</dependency>

我的应用启动代码如下(复制自https://stackoverflow.com/a/8974515/8261

import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.auth.UserAuth;
import org.apache.sshd.server.auth.UserAuthNoneFactory;
import org.apache.sshd.server.command.ScpCommandFactory;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.sftp.subsystem.SftpSubsystem;

private void startSftpServer() throws IOException {
    SshServer sshd = SshServer.setUpDefaultServer();
    sshd.setPort(2222);
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(
            new File("hostkey.ser")));

    List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
    userAuthFactories.add(new UserAuthNoneFactory());
    sshd.setUserAuthFactories(userAuthFactories);

    sshd.setCommandFactory(new ScpCommandFactory());

    List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
    namedFactoryList.add(new SftpSubsystem.Factory());
    sshd.setSubsystemFactories(namedFactoryList);

    sshd.start();
}

如何向服务器添加更现代的主机密钥算法?

【问题讨论】:

    标签: java sshd apache-mina


    【解决方案1】:

    这对我有用:

    更改 Maven pom.xml 以删除“sshd-sftp”,它现在是“sshd-core”的一部分:

    <dependency>
        <groupId>org.apache.sshd</groupId>
        <artifactId>sshd-core</artifactId>
        <version>1.0.0</version>
    </dependency>
    

    添加到“startSftpServer”:

        AbstractGeneratorHostKeyProvider hostKeyProvider =
                new SimpleGeneratorHostKeyProvider(SERVER_KEY_FILE.toPath());
    
        hostKeyProvider.setAlgorithm("RSA");
        sshd.setKeyPairProvider(hostKeyProvider);
    

    ...使用这个库似乎涉及很多猜测,这对于“安全”库来说似乎是阴暗的。

    【讨论】:

    • 谢谢,setAlgorithm(KeyUtils.RSA_ALGORITHM); 正是我试图让 SSHD 工作时所缺少的。如果有人收到“找不到匹配的主机密钥类型。他们的提议:ssh-dss”,请尝试将主机密钥算法设置为 RSA!
    • 还记得删除之前保存的所有SERVER_KEY_FILE
    • 对我来说,Java_161 抛出异常:java.security.InvalidKeyException:SHA-1 摘要算法的安全强度不够,这些行节省了时间:AbstractGeneratorHostKeyProvider hostKeyProvider = new SimpleGeneratorHostKeyProvider(Paths.get (“密钥库”)); hostKeyProvider.setAlgorithm(KeyUtils.DSS_ALGORITHM); hostKeyProvider.setKeySize(512);
    猜你喜欢
    • 2019-05-20
    • 1970-01-01
    • 2015-06-22
    • 2021-10-25
    • 1970-01-01
    • 2017-10-06
    • 2021-08-20
    • 2015-09-02
    • 1970-01-01
    相关资源
    最近更新 更多