gpt4 book ai didi

sftp - 尝试使用 Apache Mina 为 SFTP 测试服务器实现 PublicKey 身份验证。但是没有调用 Authenticate 方法

转载 作者:行者123 更新时间:2023-12-04 21:18:56 24 4
gpt4 key购买 nike

我正在使用 Apache Mina SSHD 来实现一个测试 SFTPServer。我已经能够为简单的密码身份验证工作,但是我无法为 PublicKey 身份验证配置东西。我实现了 PublickeyAuthenticator 接口(interface),如下所示,

public class SimpleKeyAuthenticator implements PublickeyAuthenticator {

@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
System.out.println("In authenticate");
return false;
}

}

我的服务器实现如下,
...
sshd = SshServer.setUpDefaultServer();


sshd.setPort(2222);
//sshd.setPort(config.getSFTPPort());

//sshd.setKeyPairProvider(new
sshd.setKeyPairProvider(new PEMGeneratorHostKeyProvider("hostkey.pem"));
//sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());

sshd.setPublickeyAuthenticator(new SimpleKeyAuthenticator());
sshd.setFileSystemFactory(new SimpleFileSystemFactory());

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

sshd.setCommandFactory(new ScpCommandFactory());

List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();

namedFactoryList.add(new SftpSubsystem.Factory());
sshd.setSubsystemFactories(namedFactoryList);

sshd.setSessionFactory(new SimpleSessionFactory(handler));
try {
sshd.start();
} catch (Exception e) {
e.printStackTrace();
}

但是,当我尝试使用我的 SFTP 客户端获取文件时,一切正常。我希望身份验证方法会失败,因为它总是返回 false。我尝试将 KeyPairProvider 设置为同时使用 PEMGeneratorHostKeyProvider 和 SimpleGeneratorHostKeyProvider。我还将 PublicKeyAuthenticator 设置为使用我的 SimpleKeyAuthenticator 类。请注意,当我查看控制台输出时,我从未看到“验证中”,所以我知道永远不会调用 Authenticate。有人可以指出我错过了什么吗?任何帮助表示赞赏。

问候,
标记

最佳答案

//下面的行将在没有任何验证的情况下进行客户端登录。

userAuthFactories.add(new UserAuthNone.Factory());

你应该像这样改变它:

userAuthFactories.add(new UserAuthPublicKey.Factory());

关于sftp - 尝试使用 Apache Mina 为 SFTP 测试服务器实现 PublicKey 身份验证。但是没有调用 Authenticate 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16288158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com