Camel SFTP component - SSH private key URI works with privateKeyFile, doesn't work with privateKey

被刻印的时光 ゝ 提交于 2020-08-08 15:44:45

问题


I have a camel route that looks like the next one:

from("direct:download")
        .pollEnrich()
        .simple("sftp://my.host:22/folder/?username=foo&fileName=${header.CamelFileName}
        &privateKeyFile=src/main/resources/privateSSHKey")
        .to("file://state/downloaded");

The file src/main/resources/privateSSHKey is an RSA private key. That works without a problem : JSCH (library used by Camel for the SFTP endpoint) manages to connect and download the desired file.

The previous setup is ok while developing, because I can have the file with the key locally. However, for prod, we have other system in which I will be able to get a byte array with the content of the key. For that, I am changing the route to look like this:

from("direct:download")
        .pollEnrich()
        .simple("sftp://my.host:22/folder/?username=foo&fileName=${header.CamelFileName}
     &privateKey=" + URLEncoder.encode(new String(sshPrivateKey), "UTF-8"))
        .to("file://state/downloaded");

...being sshPrivateKey the byte array. Unfortunately, I always get "auth_cancel" from JSCH, and debugging I can see that this happens when trying to handshake with the SFTP server.

Am I missing something? I am pretty sure that encoding the sshPrivateKey byte[] is the way to go (JSCH was complaining about wrong key if I didn't do it), but I am not sure about what else I am missing?

来源:https://stackoverflow.com/questions/57495686/camel-sftp-component-ssh-private-key-uri-works-with-privatekeyfile-doesnt-wo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!