繁体   English   中英

在内存/嵌入式 SFTP 服务器中使用 Java 中的私钥身份验证进行测试

[英]In memory/embedded SFTP server for test with private key authentication in Java

场景是我需要为执行 SFTP 文件传输的应用程序编写测试,并且我需要一个具有私钥身份验证实现的内存/嵌入式 SFTP 服务器,以便我可以测试文件传输是否与嵌入式/内存服务器一起正常运行私钥 (.pem) 文件身份验证。

我已经深入了解了互联网,最接近的是Apache Mina Server,如this SO question中所述

目前我使用的用户名和密码身份验证如下:

SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(22999);

sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {

    public boolean authenticate(String username, String password,
                                ServerSession session) {
        // TODO Auto-generated method stub
        return true;
    }
});

我试图找到一种实现私钥身份验证的方法,但似乎只有一个身份验证器,但它是一个公钥身份验证器,如下所示:

public void setPublickeyAuthenticator(PublickeyAuthenticator publickeyAuthenticator) {
    this.publickeyAuthenticator = publickeyAuthenticator;
}

有没有办法用 Apache Mina 实现私钥身份验证器? 或者,如果不可能,还有其他模拟 SFTP 服务器可以用于我的测试场景吗?

您实际上是在寻找公钥验证器

客户端/用户使用其公钥进行身份验证。 服务器永远不会看到私钥。


因此,您实现了PublickeyAuthenticator接口以检查authenticate方法PublicKey key参数是否与您在客户端中用于进行身份验证的密钥对的公共部分匹配。

您可以从使用OpenSSH .ssh/authorized_keys类的配置文件的AuthorizedKeysAuthenticator实现开始。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM