Apache Mina SSHd默认使用ssh2协议。如果需要使用ssh1协议,可以在SSH服务器配置中进行设置:
SshServer sshd = SshServer.setUpDefaultServer();
sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshServer.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-l" }));
sshd.setPort(22);
sshd.setKeyExchangeFactories(Arrays.>asList(new DHG1.Factory(), new DHG14.Factory()));
sshd.setCipherFactories(Arrays.>asList(
// SSH2 Ciphers
new AES128CBC.Factory(), new AES192CBC.Factory(), new AES256CBC.Factory(),
new BlowfishCBC.Factory(),
// SSH1 Ciphers
new BlowfishCBC.Factory(),
new DESedeCBC.Factory(),
new RC4.Factory()
));
sshd.setMacFactories(Arrays.>asList(
// SSH2 MACs
new HMACMD5.Factory(), new HMACMD256.Factory(), new HMACSHA1.Factory(),
new HMACSHA196.Factory(), new HMACSHA256.Factory(),
// SSH1 MACs
new HMACMD5.Factory(), new HMACSHA1.Factory()
));
sshd.start();
在以上示例中,可以看到在ssh服务器的密钥交换、加密和MAC工厂列表中都包含了ssh1和ssh2协议支持的加密和MAC算法。这样,如果客户端使用ssh1协议连接,则可以成功认证和交换密钥。