5

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

Cydrick Trudel
  • 9,957
  • 8
  • 41
  • 63
Mark
  • 51
  • 1
  • 2

1 Answers1

2

// 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());

cza55007
  • 21
  • 3
  • "new UserAuthNone.Factory()" doesn't exist in this library anymore as of 2.3.0 and I have no idea why... has anyone used a recent version of this library for pubkey auth? The documentation is non-existent other than some dry javadocs – Alkanshel Apr 10 '20 at 03:51