【问题标题】:JSch is unable to find the private key using addIdentity when using HTTP URL使用 HTTP URL 时,JSch 无法使用 addIdentity 找到私钥
【发布时间】:2019-07-10 16:25:47
【问题描述】:

我一直在使用 JSch 与 OpenSSH 服务器建立 SFTP 连接,在此过程中,当我尝试以 URI 的形式将私钥添加为身份时,无法识别私钥。

当我尝试从浏览器运行 URL 时,它运行正常。

我已经尝试了所有使用转义字符的方法,但没有奏效。

Session session = null;
ChannelSftp channelSftp = null;

log.info(file.getOriginalFilename());
log.info(privatekey);
JSch jsch = new JSch();
jsch.addIdentity(this.privatekey);
log.info("identity added ");
session = jsch.getSession(username,hostname,portno);
log.info("Session Created");
session.setPassword(password);

Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setTimeout(60000);
session.connect();
log.info("session connected.....");
channelSftp = (ChannelSftp) session.openChannel("sftp");
log.info("Channel Opened.....");
log.info(channelSftp.toString());

channelSftp.setInputStream(System.in);
channelSftp.setOutputStream(System.out);
channelSftp.connect();
log.info("Channel connected.....");
//channelSftp.cd(destination);
log.info(file.getOriginalFilename());
channelSftp.put(file.getInputStream(), file.getOriginalFilename(), ChannelSftp.OVERWRITE);
channelSftp.put(file.getInputStream(),file.getOriginalFilename());


channelSftp.disconnect();
session.disconnect();

我希望必须使用 add identity 添加密钥,但不幸的是我收到以下错误

[https-jsse-nio-10443-exec-10] c.d.a.l.r.s.BlkCounterpartyServiceImpl:遇到的错误是:com.jcraft.jsch.JSchException:java.io.FileNotFoundException:http://staging.fileserver.com/properties/xyz/ xyz/xyz.ppk(没有这样的文件或目录)。

该文件位于此位置http://staging.fileserver.com/properties/xyz/xyz/xyz.ppk

【问题讨论】:

    标签: java ssh jsch private-key


    【解决方案1】:

    JSch.addIdentity method 的文档说:

    prvkey - 私钥文件的文件名。 ...

    “文件名” = 本地文件名的路径,而不是HTTP URL

    如果您想从 HTTP 服务器下载文件(从安全角度来看这是一个糟糕的想法),您必须对其进行编码。

    【讨论】:

    • 感谢您的回复.. 有没有办法利用翻译 URI /URL 来添加到 addIdentity ?
    • 你为什么要这样做?你的用例是什么?您是否意识到通过未加密的通道下载私钥是一件非常糟糕的事情?
    猜你喜欢
    • 2015-12-10
    • 2019-04-07
    • 1970-01-01
    • 2018-11-24
    • 2018-10-12
    • 1970-01-01
    • 2013-02-26
    • 2015-04-11
    • 1970-01-01
    相关资源
    最近更新 更多