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 2016/05/25 08:13:50 UTC

[1/2] camel git commit: camel-sftp: Permanently added 'X' (RSA) to the list of known hosts.

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 <ju...@laureate.net>
Authored: Sun May 22 21:35:02 2016 -0400
Committer: Claus Ibsen <da...@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();


[2/2] camel git commit: CAMEL-8282: Polished. This closes #993.

Posted by da...@apache.org.
CAMEL-8282: Polished. This closes #993.


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

Branch: refs/heads/master
Commit: 7d2580b571fa8a77e529d8019462717efe3de7ef
Parents: 924d350
Author: Claus Ibsen <da...@apache.org>
Authored: Wed May 25 10:12:15 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed May 25 10:13:42 2016 +0200

----------------------------------------------------------------------
 .../component/file/remote/SftpConfiguration.java    |  6 ++++--
 .../camel/component/file/remote/SftpOperations.java |  2 +-
 .../file/remote/sftp/SftpServerTestSupport.java     | 16 ++++++++--------
 3 files changed, 13 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7d2580b5/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 e6f785b..4b5bbd3 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,7 +33,7 @@ public class SftpConfiguration extends RemoteFileConfiguration {
 
     @UriParam(label = "security")
     private String knownHostsFile;
-    @UriParam(defaultValue = "true")
+    @UriParam(label = "security", defaultValue = "true")
     private boolean useUserKnownHostsFile = true;
     @UriParam(label = "security")
     private String knownHostsUri;
@@ -102,11 +102,13 @@ public class SftpConfiguration extends RemoteFileConfiguration {
         return useUserKnownHostsFile;
     }
 
+    /**
+     * If knownHostFile has not been explicit configured then use the host file from System.getProperty(user.home)/.ssh/known_hosts
+     */
     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/7d2580b5/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 0673f2c..4247997 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
@@ -279,7 +279,7 @@ public class SftpOperations implements RemoteFileOperations<ChannelSftp.LsEntry>
         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);
+            LOG.info("Known host file not configured, using user known host file: {}", knownHostsFile);
         }
         jsch.setKnownHosts(ObjectHelper.isEmpty(knownHostsFile) ? null : knownHostsFile);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/7d2580b5/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 b6c5973..1e323ac 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
@@ -51,17 +51,17 @@ public class SftpServerTestSupport extends BaseServerTestSupport {
         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";
+        String simulatedUserSsh = "target/user-home/.ssh";
         deleteDirectory(simulatedUserHome);
-		createDirectory(simulatedUserHome);
-		createDirectory(simulatedUserSsh);
-		
-		FileUtils.copyInputStreamToFile(getClass().getClassLoader().getResourceAsStream("known_hosts"), new File(simulatedUserSsh+"/known_hosts"));
-        
+        createDirectory(simulatedUserHome);
+        createDirectory(simulatedUserSsh);
+
+        FileUtils.copyInputStreamToFile(getClass().getClassLoader().getResourceAsStream("known_hosts"), new File(simulatedUserSsh + "/known_hosts"));
+
         super.setUp();
 
         setUpServer();