Apache Mina SSHD setKeyPairProvider 保存生成的密钥 (Android)
Apache Mina SSHD setKeyPairProvider save generated keys (Android)
在 Apache Mina SSHD Github 文档 https://github.com/apache/mina-sshd#configuring-the-server-instance 中,我们可以看到部分 "KeyPairProvider".
在这部分我们可以看到
It's usually a good idea to save generated keys, so that if the SSHD
server is restarted, the same keys will be used to authenticate the
server and avoid the warning the clients might get if the host keys
are modified.
我的问题是如何保存生成的密钥因为每次我在终端中重启服务器时我都能看到消息
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
我需要进入 /.ssh/known_hosts 并删除生成的 IP 地址 "sha-rsa" 键。
我尝试了几种方法
1.) 方式
if(SecurityUtils.isBouncyCastleRegistered()){
PEMGeneratorHostKeyProvider hostKeyProvider = new PEMGeneratorHostKeyProvider(new File("myapp.pem").getAbsolutePath());
hostKeyProvider.setAlgorithm("RSA");
sshd.setKeyPairProvider(hostKeyProvider);
}else{
SimpleGeneratorHostKeyProvider hostKeyProvider = new SimpleGeneratorHostKeyProvider(new File("myapp.ser").getAbsolutePath());
hostKeyProvider.setAlgorithm("RSA");
sshd.setKeyPairProvider(hostKeyProvider);
}
2.) 方式
首先生成"keystore"文件。
keytool -genkey -keystore "app.keystore" -keyalg RSA
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("app.keystore", "RSA"));
3.) 方式
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
4.) 方式
首先生成"PEM"文件。
openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout
app.crt -out app.crt
openssl pkcs12 -export -in app.crt -out app.p12
openssl pkcs12 -in app.p12 -out app.pem
PEMGeneratorHostKeyProvider hostKeyProvider = new PEMGeneratorHostKeyProvider(new File("app.pem").getAbsolutePath());
hostKeyProvider.setAlgorithm("RSA");
或
PEMGeneratorHostKeyProvider hostKeyProvider = new PEMGeneratorHostKeyProvider("app.pem");
hostKeyProvider.setAlgorithm("RSA");
并放
sshd.setKeyPairProvider(hostKeyProvider);
我是这样做的:
import org.apache.sshd.common.util.security.bouncycastle.BouncyCastleGeneratorHostKeyProvider
...
server.setKeyPairProvider(new BouncyCastleGeneratorHostKeyProvider(Paths.get("ssh.pem")))
我不知道我是如何生成 pem 文件的..
在 Apache Mina SSHD Github 文档 https://github.com/apache/mina-sshd#configuring-the-server-instance 中,我们可以看到部分 "KeyPairProvider".
在这部分我们可以看到
It's usually a good idea to save generated keys, so that if the SSHD server is restarted, the same keys will be used to authenticate the server and avoid the warning the clients might get if the host keys are modified.
我的问题是如何保存生成的密钥因为每次我在终端中重启服务器时我都能看到消息
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
我需要进入 /.ssh/known_hosts 并删除生成的 IP 地址 "sha-rsa" 键。
我尝试了几种方法
1.) 方式
if(SecurityUtils.isBouncyCastleRegistered()){
PEMGeneratorHostKeyProvider hostKeyProvider = new PEMGeneratorHostKeyProvider(new File("myapp.pem").getAbsolutePath());
hostKeyProvider.setAlgorithm("RSA");
sshd.setKeyPairProvider(hostKeyProvider);
}else{
SimpleGeneratorHostKeyProvider hostKeyProvider = new SimpleGeneratorHostKeyProvider(new File("myapp.ser").getAbsolutePath());
hostKeyProvider.setAlgorithm("RSA");
sshd.setKeyPairProvider(hostKeyProvider);
}
2.) 方式
首先生成"keystore"文件。
keytool -genkey -keystore "app.keystore" -keyalg RSA
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("app.keystore", "RSA"));
3.) 方式
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
4.) 方式
首先生成"PEM"文件。
openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout app.crt -out app.crt
openssl pkcs12 -export -in app.crt -out app.p12
openssl pkcs12 -in app.p12 -out app.pem
PEMGeneratorHostKeyProvider hostKeyProvider = new PEMGeneratorHostKeyProvider(new File("app.pem").getAbsolutePath());
hostKeyProvider.setAlgorithm("RSA");
或
PEMGeneratorHostKeyProvider hostKeyProvider = new PEMGeneratorHostKeyProvider("app.pem");
hostKeyProvider.setAlgorithm("RSA");
并放
sshd.setKeyPairProvider(hostKeyProvider);
我是这样做的:
import org.apache.sshd.common.util.security.bouncycastle.BouncyCastleGeneratorHostKeyProvider
...
server.setKeyPairProvider(new BouncyCastleGeneratorHostKeyProvider(Paths.get("ssh.pem")))
我不知道我是如何生成 pem 文件的..