camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: camel-sftp: Permanently added 'X' (RSA) to the list of known hosts.
Date Wed, 25 May 2016 08:13:50 GMT
Repository: camel
Updated Branches:
  refs/heads/master 5d69fbe89 -> 7d2580b57


camel-sftp: Permanently added 'X' (RSA) to the list of known hosts.

This fixes the "Permanently added 'X' (RSA) to the list of known hosts."
warning message by using the users home.

This was fixed for ssh but not for sftp in CAMEL-8202

 * Updated sftp to use user's home .ssh/known_hosts file by default
 * 'Implemented' updateFileHeaders as log messages


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

Branch: refs/heads/master
Commit: 924d3501485e9d906ae615ecf1daa884261f8b89
Parents: 5d69fbe
Author: Justin Wrobel <justin.wrobel@laureate.net>
Authored: Sun May 22 21:35:02 2016 -0400
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed May 25 09:59:52 2016 +0200

----------------------------------------------------------------------
 .../file/remote/SftpConfiguration.java          | 11 ++++++++++
 .../component/file/remote/SftpOperations.java   |  7 +++++++
 .../file/remote/sftp/SftpServerTestSupport.java | 22 ++++++++++++++++++++
 3 files changed, 40 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/924d3501/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 9da9e81..e6f785b 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
@@ -33,6 +33,8 @@ public class SftpConfiguration extends RemoteFileConfiguration {
 
     @UriParam(label = "security")
     private String knownHostsFile;
+    @UriParam(defaultValue = "true")
+    private boolean useUserKnownHostsFile = true;
     @UriParam(label = "security")
     private String knownHostsUri;
     @UriParam(label = "security")
@@ -96,6 +98,15 @@ public class SftpConfiguration extends RemoteFileConfiguration {
         return knownHostsUri;
     }
 
+    public boolean isUseUserKnownHostsFile() {
+        return useUserKnownHostsFile;
+    }
+
+    public void setUseUserKnownHostsFile(boolean useUserKnownHostsFile) {
+        this.useUserKnownHostsFile = useUserKnownHostsFile;
+    }
+
+
     /**
      * Sets the known_hosts file (loaded from classpath by default), so that the SFTP endpoint
can do host key verification.
      */

http://git-wip-us.apache.org/repos/asf/camel/blob/924d3501/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 e9982a4..0673f2c 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
@@ -276,6 +276,13 @@ public class SftpOperations implements RemoteFileOperations<ChannelSftp.LsEntry>
             jsch.setKnownHosts(new ByteArrayInputStream(sftpConfig.getKnownHosts()));
         }
 
+        String knownHostsFile = sftpConfig.getKnownHostsFile();
+        if (knownHostsFile == null && sftpConfig.isUseUserKnownHostsFile()) {
+            knownHostsFile = System.getProperty("user.home") + "/.ssh/known_hosts";
+            LOG.info("Known host file not configured, using user known host file: " + knownHostsFile);
+        }
+        jsch.setKnownHosts(ObjectHelper.isEmpty(knownHostsFile) ? null : knownHostsFile);
+
         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/924d3501/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 76641d5..b6c5973 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
@@ -16,12 +16,14 @@
  */
 package org.apache.camel.component.file.remote.sftp;
 
+import java.io.File;
 import java.security.NoSuchAlgorithmException;
 import java.security.PublicKey;
 import java.util.Arrays;
 
 import org.apache.camel.component.file.remote.BaseServerTestSupport;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.io.FileUtils;
 import org.apache.sshd.SshServer;
 import org.apache.sshd.common.NamedFactory;
 import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
@@ -41,11 +43,25 @@ public class SftpServerTestSupport extends BaseServerTestSupport {
     protected static final String FTP_ROOT_DIR = "target/res/home";
     protected SshServer sshd;
     protected boolean canTest;
+    protected String oldUserHome;
 
     @Override
     @Before
     public void setUp() throws Exception {
         deleteDirectory(FTP_ROOT_DIR);
+
+        oldUserHome = System.getProperty("user.home");
+        
+        System.setProperty("user.home", "target/user-home");
+        
+        String simulatedUserHome = "target/user-home";
+        String simulatedUserSsh  = "target/user-home/.ssh";
+        deleteDirectory(simulatedUserHome);
+		createDirectory(simulatedUserHome);
+		createDirectory(simulatedUserSsh);
+		
+		FileUtils.copyInputStreamToFile(getClass().getClassLoader().getResourceAsStream("known_hosts"),
new File(simulatedUserSsh+"/known_hosts"));
+        
         super.setUp();
 
         setUpServer();
@@ -88,6 +104,12 @@ public class SftpServerTestSupport extends BaseServerTestSupport {
     @Override
     @After
     public void tearDown() throws Exception {
+        if (oldUserHome != null) {
+            System.setProperty("user.home", oldUserHome);
+        } else {
+            System.clearProperty("user.home");
+        }
+
         super.tearDown();
 
         tearDownServer();


Mime
View raw message