5

テスト SFTPServer を実装するために Apache Mina SSHD を使用しています。単純なパスワード認証では機能するようになりましたが、PublicKey 認証では設定できません。次のように PublickeyAuthenticator インターフェイスを実装しました。

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 を返すため、失敗することが予想されます。PEMGeneratorHostKeyProvider と SimpleGeneratorHostKeyProvider の両方を使用するように KeyPairProvider を設定しようとしました。また、SimpleKeyAuthenticator クラスを使用するように PublicKeyAuthenticator を設定しました。コンソール出力を見ると、「認証中」とは表示されないため、認証が呼び出されていないことがわかります。誰かが私が見逃したものを教えてもらえますか? どんな助けでも大歓迎です。

よろしく、マーク

4

1 に答える 1

2

// 以下の行は、検証なしでクライアントをログインさせます。

userAuthFactories.add(新しい UserAuthNone.Factory());

次のように変更する必要があります。

userAuthFactories.add(新しい UserAuthPublicKey.Factory());

于 2013-10-16T02:05:39.777 に答える