You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/06/24 09:47:37 UTC

[2/2] git commit: CAMEL-6477: sftp component supports loading keyfile from classpath. Thanks to Stephan Siano for the patch.

CAMEL-6477: sftp component supports loading keyfile from classpath. Thanks to Stephan Siano for the patch.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/efb65fc6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/efb65fc6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/efb65fc6

Branch: refs/heads/camel-2.11.x
Commit: efb65fc6baf75fde127107faedde71905f841188
Parents: adba465
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jun 24 09:46:26 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jun 24 09:47:17 2013 +0200

----------------------------------------------------------------------
 .../file/remote/SftpConfiguration.java          | 48 ++++++++++-
 .../component/file/remote/SftpOperations.java   | 57 ++++++++++++-
 .../file/remote/sftp/SftpKeyConsumeTest.java    | 85 ++++++++++++++++++++
 .../remote/sftp/SftpKeyFileConsumeTest.java     | 59 ++++++++++++++
 .../SftpKeyUriConsumeFromClasspathTest.java     | 59 ++++++++++++++
 .../file/remote/sftp/SftpKeyUriConsumeTest.java | 59 ++++++++++++++
 .../file/remote/sftp/SftpServerTestSupport.java | 11 +++
 components/camel-ftp/src/test/resources/id_rsa  | 30 +++++++
 .../camel-ftp/src/test/resources/id_rsa.pub     |  1 +
 .../camel-ftp/src/test/resources/known_hosts    |  1 +
 10 files changed, 403 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/efb65fc6/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java
index 77dec8c..b3432fb 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java
@@ -25,8 +25,12 @@ public class SftpConfiguration extends RemoteFileConfiguration {
 
     public static final int DEFAULT_SFTP_PORT = 22;
     private String knownHostsFile;
+    private String knownHostsUri;
+    private byte[] knownHosts;
     private String privateKeyFile;
-    private String privateKeyFilePassphrase;
+    private String privateKeyUri;
+    private byte[] privateKey;
+    private String privateKeyPassphrase;
     private String strictHostKeyChecking = "no";
     private int serverAliveInterval;
     private int serverAliveCountMax = 1;
@@ -57,6 +61,22 @@ public class SftpConfiguration extends RemoteFileConfiguration {
         this.knownHostsFile = knownHostsFile;
     }
 
+    public String getKnownHostsUri() {
+        return knownHostsUri;
+    }
+
+    public void setKnownHostsUri(String knownHostsUri) {
+        this.knownHostsUri = knownHostsUri;
+    }
+
+    public byte[] getKnownHosts() {
+        return knownHosts;
+    }
+
+    public void setKnownHosts(byte[] knownHosts) {
+        this.knownHosts = knownHosts;
+    }
+
     public String getPrivateKeyFile() {
         return privateKeyFile;
     }
@@ -65,12 +85,32 @@ public class SftpConfiguration extends RemoteFileConfiguration {
         this.privateKeyFile = privateKeyFile;
     }
 
-    public String getPrivateKeyFilePassphrase() {
-        return privateKeyFilePassphrase;
+    public String getPrivateKeyUri() {
+        return privateKeyUri;
+    }
+
+    public void setPrivateKeyUri(String privateKeyUri) {
+        this.privateKeyUri = privateKeyUri;
+    }
+
+    public byte[] getPrivateKey() {
+        return privateKey;
+    }
+
+    public void setPrivateKey(byte[] privateKey) {
+        this.privateKey = privateKey;
+    }
+
+    public String getPrivateKeyPassphrase() {
+        return privateKeyPassphrase;
+    }
+
+    public void setPrivateKeyPassphrase(String privateKeyFilePassphrase) {
+        this.privateKeyPassphrase = privateKeyFilePassphrase;
     }
 
     public void setPrivateKeyFilePassphrase(String privateKeyFilePassphrase) {
-        this.privateKeyFilePassphrase = privateKeyFilePassphrase;
+        this.privateKeyPassphrase = privateKeyFilePassphrase;
     }
 
     public String getStrictHostKeyChecking() {

http://git-wip-us.apache.org/repos/asf/camel/blob/efb65fc6/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
index 4603320..a7ad773 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
@@ -23,6 +23,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.List;
@@ -36,6 +37,7 @@ import com.jcraft.jsch.Session;
 import com.jcraft.jsch.SftpException;
 import com.jcraft.jsch.UIKeyboardInteractive;
 import com.jcraft.jsch.UserInfo;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.component.file.FileComponent;
@@ -46,6 +48,7 @@ import org.apache.camel.component.file.GenericFileOperationFailedException;
 import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ResourceHelper;
 
 import org.apache.camel.util.StopWatch;
 import org.apache.camel.util.TimeUtils;
@@ -157,21 +160,69 @@ public class SftpOperations implements RemoteFileOperations<ChannelSftp.LsEntry>
             ciphers.put("cipher.c2s", sftpConfig.getCiphers());
             JSch.setConfig(ciphers);
         }
-        
+
         if (isNotEmpty(sftpConfig.getPrivateKeyFile())) {
             LOG.debug("Using private keyfile: {}", sftpConfig.getPrivateKeyFile());
-            if (isNotEmpty(sftpConfig.getPrivateKeyFilePassphrase())) {
-                jsch.addIdentity(sftpConfig.getPrivateKeyFile(), sftpConfig.getPrivateKeyFilePassphrase());
+            if (isNotEmpty(sftpConfig.getPrivateKeyPassphrase())) {
+                jsch.addIdentity(sftpConfig.getPrivateKeyFile(), sftpConfig.getPrivateKeyPassphrase());
             } else {
                 jsch.addIdentity(sftpConfig.getPrivateKeyFile());
             }
         }
 
+        if (sftpConfig.getPrivateKey() != null) {
+            LOG.debug("Using private key information from byte array");
+            byte[] passphrase = null;
+            if (isNotEmpty(sftpConfig.getPrivateKeyPassphrase())) {
+                try {
+                    passphrase = sftpConfig.getPrivateKeyPassphrase().getBytes("UTF-8");
+                } catch (UnsupportedEncodingException e) {
+                    throw new JSchException("Cannot transform passphrase to byte[]", e);
+                }
+            }
+            jsch.addIdentity("ID", sftpConfig.getPrivateKey(), null, passphrase);
+        }
+
+        if (sftpConfig.getPrivateKeyUri() != null) {
+            LOG.debug("Using private key uri : {}", sftpConfig.getPrivateKeyUri());
+            byte[] passphrase = null;
+            if (isNotEmpty(sftpConfig.getPrivateKeyPassphrase())) {
+                try {
+                    passphrase = sftpConfig.getPrivateKeyPassphrase().getBytes("UTF-8");
+                } catch (UnsupportedEncodingException e) {
+                    throw new JSchException("Cannot transform passphrase to byte[]", e);
+                }
+            }
+            try {
+                InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(endpoint.getCamelContext().getClassResolver(), sftpConfig.getPrivateKeyUri());
+                ByteArrayOutputStream bos = new ByteArrayOutputStream();
+                IOHelper.copyAndCloseInput(is, bos);
+                jsch.addIdentity("ID", bos.toByteArray(), null, passphrase);
+            } catch (IOException e) {
+                throw new JSchException("Cannot read resource: " + sftpConfig.getPrivateKeyUri(), e);
+            }
+        }
+
         if (isNotEmpty(sftpConfig.getKnownHostsFile())) {
             LOG.debug("Using knownhosts file: {}", sftpConfig.getKnownHostsFile());
             jsch.setKnownHosts(sftpConfig.getKnownHostsFile());
         }
 
+        if (isNotEmpty(sftpConfig.getKnownHostsUri())) {
+            LOG.debug("Using knownhosts uri: {}", sftpConfig.getKnownHostsUri());
+            try {
+                InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(endpoint.getCamelContext().getClassResolver(), sftpConfig.getKnownHostsUri());
+                jsch.setKnownHosts(is);
+            } catch (IOException e) {
+                throw new JSchException("Cannot read resource: " + sftpConfig.getKnownHostsUri(), e);
+            }
+        }
+
+        if (sftpConfig.getKnownHosts() != null) {
+            LOG.debug("Using knownhosts information from byte array");
+            jsch.setKnownHosts(new ByteArrayInputStream(sftpConfig.getKnownHosts()));
+        }
+
         final Session session = jsch.getSession(configuration.getUsername(), configuration.getHost(), configuration.getPort());
 
         if (isNotEmpty(sftpConfig.getStrictHostKeyChecking())) {

http://git-wip-us.apache.org/repos/asf/camel/blob/efb65fc6/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyConsumeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyConsumeTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyConsumeTest.java
new file mode 100644
index 0000000..c830582
--- /dev/null
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyConsumeTest.java
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.remote.sftp;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.util.IOHelper;
+import org.junit.Test;
+
+public class SftpKeyConsumeTest extends SftpServerTestSupport {
+
+    @Test
+    public void testSftpSimpleConsume() throws Exception {
+        if (!canTest()) {
+            return;
+        }
+
+        String expected = "Hello World";
+
+        // create file using regular file
+        template.sendBodyAndHeader("file://" + FTP_ROOT_DIR, expected, Exchange.FILE_NAME, "hello.txt");
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt");
+        mock.expectedBodiesReceived(expected);
+
+        context.startRoute("foo");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    private byte[] getBytesFromFile(String filename) throws IOException {
+        InputStream input;
+        input = new FileInputStream(new File(filename));
+        ByteArrayOutputStream output = new ByteArrayOutputStream();
+        IOHelper.copyAndCloseInput(input, output);
+        return output.toByteArray();
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+
+        registry.bind("privateKey", getBytesFromFile("./src/test/resources/id_rsa"));
+        registry.bind("knownHosts", getBytesFromFile("./src/test/resources/known_hosts"));
+
+        return registry;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR
+                        + "?username=admin&knownHosts=#knownHosts&privateKey=#privateKey&privateKeyPassphrase=secret&delay=10s&strictHostKeyChecking=yes&disconnect=true")
+                    .routeId("foo").noAutoStartup()
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/efb65fc6/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyFileConsumeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyFileConsumeTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyFileConsumeTest.java
new file mode 100644
index 0000000..c2c4412
--- /dev/null
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyFileConsumeTest.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.remote.sftp;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+public class SftpKeyFileConsumeTest extends SftpServerTestSupport {
+
+    @Test
+    public void testSftpSimpleConsume() throws Exception {
+        if (!canTest()) {
+            return;
+        }
+
+        String expected = "Hello World";
+
+        // create file using regular file
+        template.sendBodyAndHeader("file://" + FTP_ROOT_DIR, expected, Exchange.FILE_NAME, "hello.txt");
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt");
+        mock.expectedBodiesReceived(expected);
+
+        context.startRoute("foo");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR
+                    + "?username=admin&knownHostsFile=./src/test/resources/known_hosts&privateKeyFile=./src/test/resources/id_rsa&privateKeyFilePassphrase=secret&delay=10s&disconnect=true")
+                    .routeId("foo").noAutoStartup()
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/efb65fc6/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyUriConsumeFromClasspathTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyUriConsumeFromClasspathTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyUriConsumeFromClasspathTest.java
new file mode 100644
index 0000000..2a6dab7
--- /dev/null
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyUriConsumeFromClasspathTest.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.remote.sftp;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+public class SftpKeyUriConsumeFromClasspathTest extends SftpServerTestSupport {
+
+    @Test
+    public void testSftpSimpleConsume() throws Exception {
+        if (!canTest()) {
+            return;
+        }
+
+        String expected = "Hello World";
+
+        // create file using regular file
+        template.sendBodyAndHeader("file://" + FTP_ROOT_DIR, expected, Exchange.FILE_NAME, "hello.txt");
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt");
+        mock.expectedBodiesReceived(expected);
+
+        context.startRoute("foo");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR
+                        + "?username=admin&knownHostsUri=known_hosts&privateKeyUri=id_rsa&privateKeyPassphrase=secret&delay=10s&disconnect=true")
+                    .routeId("foo").noAutoStartup()
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/efb65fc6/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyUriConsumeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyUriConsumeTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyUriConsumeTest.java
new file mode 100644
index 0000000..f99ce5f
--- /dev/null
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpKeyUriConsumeTest.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.remote.sftp;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+public class SftpKeyUriConsumeTest extends SftpServerTestSupport {
+
+    @Test
+    public void testSftpSimpleConsume() throws Exception {
+        if (!canTest()) {
+            return;
+        }
+
+        String expected = "Hello World";
+
+        // create file using regular file
+        template.sendBodyAndHeader("file://" + FTP_ROOT_DIR, expected, Exchange.FILE_NAME, "hello.txt");
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt");
+        mock.expectedBodiesReceived(expected);
+
+        context.startRoute("foo");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR
+                        + "?username=admin&knownHostsUri=file:./src/test/resources/known_hosts&privateKeyUri=file:./src/test/resources/id_rsa&privateKeyPassphrase=secret&delay=10s&disconnect=true")
+                    .routeId("foo").noAutoStartup()
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/efb65fc6/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java
index 9653d07..46e7b0b 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote.sftp;
 
 import java.security.NoSuchAlgorithmException;
+import java.security.PublicKey;
 import java.util.Arrays;
 
 import org.apache.camel.component.file.remote.BaseServerTestSupport;
@@ -25,7 +26,9 @@ import org.apache.sshd.SshServer;
 import org.apache.sshd.common.NamedFactory;
 import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
 import org.apache.sshd.server.Command;
+import org.apache.sshd.server.PublickeyAuthenticator;
 import org.apache.sshd.server.command.ScpCommandFactory;
+import org.apache.sshd.server.session.ServerSession;
 import org.apache.sshd.server.sftp.SftpSubsystem;
 import org.junit.After;
 import org.junit.Before;
@@ -54,6 +57,14 @@ public class SftpServerTestSupport extends BaseServerTestSupport {
             sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
             sshd.setCommandFactory(new ScpCommandFactory());
             sshd.setPasswordAuthenticator(new MyPasswordAuthenticator());
+            PublickeyAuthenticator publickeyAuthenticator = new PublickeyAuthenticator() {
+                // consider all keys as authorized for all users
+                @Override
+                public boolean authenticate(String username, PublicKey key, ServerSession session) {
+                    return true;
+                }
+            };
+            sshd.setPublickeyAuthenticator(publickeyAuthenticator);
             sshd.start();
         } catch (Exception e) {
             // ignore if algorithm is not on the OS

http://git-wip-us.apache.org/repos/asf/camel/blob/efb65fc6/components/camel-ftp/src/test/resources/id_rsa
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/resources/id_rsa b/components/camel-ftp/src/test/resources/id_rsa
new file mode 100644
index 0000000..a740e42
--- /dev/null
+++ b/components/camel-ftp/src/test/resources/id_rsa
@@ -0,0 +1,30 @@
+-----BEGIN RSA PRIVATE KEY-----
+Proc-Type: 4,ENCRYPTED
+DEK-Info: AES-128-CBC,95EC5EAA48687FE66BEDC8FC3D978209
+
+x4yeodnaPw0hyP5mX8hW681RZhKLQkUZ3YEgfDSkUTdC3Pm6HNnFoTitJiV4J5cz
+O9EATykxe0mBUsmk04oDmD52YbkwJ2D44Gddkh1C+rGa9fgbo52NGiiIXPGuyTR9
+rEPsOwGcWI7K5kSa6oD0QsOGvfn/7a6Gt6sZTe/p4IQKWtbpHyD2qJkDBLmnMVK5
+qAfqFCGiPGhbX3TUBqXUC7GY0fKv9SK4XV90SMsfwO1IOK5FofM7EJ6NbR18/w7P
+npK0Oldiv/lIx9wbJOHYawpYn/+MEas2GlS53VzREsyqSv3jj3srrUH10AjA/lZB
+Wy7uWIEEAplLG2pGLmLobyPnitSLEe8N+wk+91QLK4lN3dPmWnVm8xWVXNuVxfzG
+MZZ9B3+r4G96wAjViDYltHRsumjhqQjyBzSOwlmE/Uag88CHQyiIKBWfhnLy0JRi
+ceml5QFtt//zxtypd9p/wUv0+Z2xgwjH82+Vp5aL0vmd41W+pfOAyPJlB3O69X5a
+o4htRVAvYW7hGnTkPKabYV0PeQUwsQx6C4vNvUJR859RXxrUPoFvu/AhEMI8eetU
+mahGCtFxd82kX7TYY+70RBNfj/X4rpPLNEJh5FOH1D/rJoM+94V1LKpLi3AnNRHI
+4x5GyOVkQ5shQ93Ao+zfkGy/VSU/kPall/U0HzxFXvZFylfSWB9hsCNx2IWR9a5p
+XECRl+QKVZDSx/jbJ4WgpiM3ea37pfU0UqcgbSj7kcfOWvezk6/8LQyi6ivt5S/0
+htBWQR6/Tq9BWLKsFb6qqXatBbyP0cvLJmh761SYo5OMor3z4e+7LOww9SQH9ops
+KSR0iMftV36FlhvpasmuIxblFKMqZ04E3ItW5UClQNIXUseSMEa0RZnJqFogqhj7
+ebZ63maynjLIR457aFd26tbXNw14ERorBujWVw5nGhIbTlyc8zfuGflcDvTlq8Vq
+HPkPzXAPiM18S/uHd3Gc2DA3zreT21aa09QBdDUv7vs3bZUD+qGGtpHfg8JKzc9/
+KkJneo7yU7IwfR1acbVgnjapyUH6Ufy7dZWXNEyXJYf6svNpPMqx/NxSm+fz72JP
+GK4Bszng+4jfwxA2p6/A2Z7ndhpGxlfgLavNIb813mBTgkGbnPPEPr+RgRyE6sSE
+slogJXFL0wBeuqbKdofYmMRQCKI00FkNsfFip8tcMV5QgqwCBb7Q2U2ELdhWwXJq
+hy8a8f1Tbr9khJT0AgUcWny0sMdXtTNHy+ZiHlRFvAQGMJt0vxuVIT64VmdUXSlQ
+6Hza5yijC9pYxuOmwfKdjyukiwqOOaAWQQJHOwQOBwR6UCNM8FRl9O2w0hJ1/ZaU
+liNlbLttMZKfVH3xhV6I9Uh4uFPeS2kwsJlXvjZJJgC7X8hvqRSt8/3dZHtwmPsp
+tn/rDy4yL5slUsK38swzM5qsCAHT5LcoxMudkCUXwQB3qb+ehApTblvrlu6xv6/+
+unvHfPO9UhsOvnS3g8HP57RAIBN4Mik8e5CQ8xVcDwnEXx7pIahoOirirJey0xfo
+puoV5qrm997MBIgIuQ5svpnyUdPWDiTCvOnMDlZblyX9vbXWTYHLklC+jBztFaIF
+-----END RSA PRIVATE KEY-----

http://git-wip-us.apache.org/repos/asf/camel/blob/efb65fc6/components/camel-ftp/src/test/resources/id_rsa.pub
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/resources/id_rsa.pub b/components/camel-ftp/src/test/resources/id_rsa.pub
new file mode 100644
index 0000000..cbb725d
--- /dev/null
+++ b/components/camel-ftp/src/test/resources/id_rsa.pub
@@ -0,0 +1 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDpbhzkWvgJXsmO3XPadHYCo6Y9fK7KtUH9j4vqU5R1zkR93n0WUZAj8mitcpHDpRh2JSUMSY4MC90V5jzrlQaRfQMdF9g4t8NsIEDjJLIZiW6c2hzq1Di6u3hu6FUv2gEOd5jTP7DsAgm7Nl2xHb9nP6xOO7e7lOMZzesX4QeTDfBjwrWoUGl9vSRspVrp+/2NYPmTe6ENVLRuDHNbDW9baDuCKzOIaB7y1icEoDKLN3gu1MvpkVfIPbeg5C4Mc5G6g7bfaYvga58mR4Q2h+9C1TFgwHV54LuDl0niytOdJJNUeHp1gF28w5LPurBAXb7RlSSgbTjh6YKPOqnXomtp user@localhost

http://git-wip-us.apache.org/repos/asf/camel/blob/efb65fc6/components/camel-ftp/src/test/resources/known_hosts
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/resources/known_hosts b/components/camel-ftp/src/test/resources/known_hosts
new file mode 100644
index 0000000..b2026cb
--- /dev/null
+++ b/components/camel-ftp/src/test/resources/known_hosts
@@ -0,0 +1 @@
+[localhost]:21000 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDdfIWeSV4o68dRrKSzFd/Bk51E65UTmmSrmW0O1ohtzi6HzsDPjXgCtlTt3FqTcfFfI92IlTr4JWqC9UK1QT1ZTeng0MkPQmv68hDANHbt5CpETZHjW5q4OOgWhVvj5IyOC2NZHtKlJBkdsMAa15ouOOJLzBvAvbqOR/yUROsEiQ==