I am using Apache Mina SSHD to implement a test SFTPServer. I have been able to get things working for simple Password authentication, however I am not able to configure things for PublicKey Authentication. I have a implemented the PublickeyAuthenticator interface as follows,
public class SimpleKeyAuthenticator implements PublickeyAuthenticator {
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
System.out.println("In authenticate");
return false;
}
}
My server implementation is as follows,
...
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();
}
However when I try to get a file using my SFTP client everything works. I would expect the authenticate method to fail given that it always returns false. I have tried setting the KeyPairProvider to use both the PEMGeneratorHostKeyProvider and the SimpleGeneratorHostKeyProvider. I have also set the PublicKeyAuthenticator to use my SimpleKeyAuthenticator class. Note, when I look at the console output I never see 'In authenticate' so I know that Authenticate is never being called. Could someone please point me to what I have missed? Any help is appreciated.
Regards, Mark
// below line will make client login without any validation.
userAuthFactories.add(new UserAuthNone.Factory());
You should change it like this:
userAuthFactories.add(new UserAuthPublicKey.Factory());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With