Jannik Schmeier created CAMEL-22472:
---------------------------------------

             Summary: camel-sftp - private key and known hosts can't be 
specified via String argument
                 Key: CAMEL-22472
                 URL: https://issues.apache.org/jira/browse/CAMEL-22472
             Project: Camel
          Issue Type: Bug
          Components: camel-sftp
    Affects Versions: 4.14.0
            Reporter: Jannik Schmeier


After upgrading camel to 4.14.0 from 4.12.0 I have noticed that my camel sftp 
routes are having issues.

I am using endpoint builder kind of like this:


{code:java}
SftpEndpointConsumerBuilder builder = sftp(uri)
        .privateKey("my+private+key")
        .privateKeyPassphrase("my private key passphrase")
        .knownHosts("<host,ip> <type> ABC+123/ABC"); {code}
 

 

1. known hosts specified as String are causing Base64 exceptions:

 
{noformat}
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot 
connect to sftp://<user>@<host>:<port>      at 
org.apache.camel.component.file.remote.SftpOperations.connect(SftpOperations.java:143)
       at 
org.apache.camel.component.file.remote.RemoteFileConsumer.connectIfNecessary(RemoteFileConsumer.java:249)
    at 
org.apache.camel.component.file.remote.SftpConsumer.doStart(SftpConsumer.java:71)
    at org.apache.camel.support.service.BaseService.start(BaseService.java:123) 
    at 
org.apache.camel.support.service.ServiceHelper.startService(ServiceHelper.java:127)
  at 
org.apache.camel.impl.engine.AbstractCamelContext.startService(AbstractCamelContext.java:3457)
       at 
org.apache.camel.impl.engine.InternalRouteStartupManager.doStartOrResumeRouteConsumers(InternalRouteStartupManager.java:430)
 at 
org.apache.camel.impl.engine.InternalRouteStartupManager.doStartRouteConsumers(InternalRouteStartupManager.java:346)
 at 
org.apache.camel.impl.engine.InternalRouteStartupManager.safelyStartRouteServices(InternalRouteStartupManager.java:222)
      at 
org.apache.camel.impl.engine.InternalRouteStartupManager.safelyStartRouteServices(InternalRouteStartupManager.java:255)
      at 
org.apache.camel.impl.engine.AbstractCamelContext.startRouteService(AbstractCamelContext.java:3506)
  at 
org.apache.camel.impl.engine.AbstractCamelContext.startRoute(AbstractCamelContext.java:1181)
 at 
org.apache.camel.impl.engine.AbstractCamelContext.startRoute(AbstractCamelContext.java:1170)
 at 
org.apache.camel.impl.engine.InternalRouteController.startRoute(InternalRouteController.java:126)
    at 
org.apache.camel.impl.engine.DefaultRouteController.startRoute(DefaultRouteController.java:133)
      ...Caused by: com.jcraft.jsch.JSchException: fromBase64: invalid base64 
data    at com.jcraft.jsch.Util.fromBase64(Util.java:77)        at 
com.jcraft.jsch.KnownHosts.setKnownHosts(KnownHosts.java:257)        at 
com.jcraft.jsch.JSch.setKnownHosts(JSch.java:422)    at 
org.apache.camel.component.file.remote.SftpOperations.createSession(SftpOperations.java:311)
 at 
org.apache.camel.component.file.remote.SftpOperations.tryConnect(SftpOperations.java:165)
    at 
org.apache.camel.support.task.BlockingTask.lambda$run$0(BlockingTask.java:45)   
     at 
org.apache.camel.support.task.ForegroundTask.doRun(ForegroundTask.java:143)  at 
org.apache.camel.support.task.ForegroundTask.run(ForegroundTask.java:108)    at 
org.apache.camel.support.task.BlockingTask.run(BlockingTask.java:45) at 
org.apache.camel.component.file.remote.SftpOperations.connect(SftpOperations.java:141)
       ... 33 common frames omittedCaused by: 
java.lang.ArrayIndexOutOfBoundsException: Index 26 out of bounds for length 26  
 at com.jcraft.jsch.Util.fromBase64(Util.java:61)        ... 42 common frames 
omitted{noformat}
If I convert my known hosts string into a byte array it works.

 

 

2. Private key specified as string causes OOM
{noformat}
java.lang.OutOfMemoryError: Java heap space
        at com.jcraft.jsch.KeyPairRSA.parse(KeyPairRSA.java:350)
        at com.jcraft.jsch.KeyPair.decrypt(KeyPair.java:943)
        at com.jcraft.jsch.IdentityFile.setPassphrase(IdentityFile.java:59)
        at com.jcraft.jsch.JSch.addIdentity(JSch.java:528)
        at com.jcraft.jsch.JSch.addIdentity(JSch.java:511)
        at 
org.apache.camel.component.file.remote.SftpOperations.createSession(SftpOperations.java:257)
        at 
org.apache.camel.component.file.remote.SftpOperations.tryConnect(SftpOperations.java:165)
        at 
org.apache.camel.component.file.remote.SftpOperations$$Lambda/0x00007f2480edb398.test(Unknown
 Source)
        at 
org.apache.camel.support.task.BlockingTask.lambda$run$0(BlockingTask.java:45)
        at 
org.apache.camel.support.task.BlockingTask$$Lambda/0x00007f2480edb5f0.getAsBoolean(Unknown
 Source)
        at 
org.apache.camel.support.task.ForegroundTask.doRun(ForegroundTask.java:143)
        at 
org.apache.camel.support.task.ForegroundTask.run(ForegroundTask.java:108)
        at org.apache.camel.support.task.BlockingTask.run(BlockingTask.java:45)
        at 
org.apache.camel.component.file.remote.SftpOperations.connect(SftpOperations.java:141)
        at 
org.apache.camel.component.file.remote.RemoteFileConsumer.connectIfNecessary(RemoteFileConsumer.java:249)
        at 
org.apache.camel.component.file.remote.RemoteFileConsumer.prePollCheck(RemoteFileConsumer.java:79)
        at 
org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:134)
        at 
org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:113)
        at 
org.apache.camel.support.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:208)
        at 
org.apache.camel.support.ScheduledPollConsumer.run(ScheduledPollConsumer.java:119)
        at 
java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
        at 
java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:358)
        at 
java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
        at 
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at 
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at 
org.apache.camel.impl.engine.MDCThreadFactoryListener.lambda$newThreadFactory$0(MDCThreadFactoryListener.java:53)
        at 
org.apache.camel.impl.engine.MDCThreadFactoryListener$$Lambda/0x00007f2480ee68c0.run(Unknown
 Source)
        at java.base/java.lang.Thread.runWith(Thread.java:1596)
        at java.base/java.lang.Thread.run(Thread.java:1583){noformat}
Again, If I convert my private key string into a byte array it works.

 

I have debugged a bit and it seems like camel is removing the '+' characters 
from the base64 data in the private key and in the known hosts before passing 
them into JSch, causing these errors. If I use the byte array it keeps them.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to