Author: janstey
Date: Thu Aug 25 17:28:04 2011
New Revision: 1161654
URL: http://svn.apache.org/viewvc?rev=1161654&view=rev
Log:
CAMEL-4382 - add support to set the cipher used for SFTP
Added:
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSetCipherTest.java
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java?rev=1161654&r1=1161653&r2=1161654&view=diff
==============================================================================
---
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java
(original)
+++
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java
Thu Aug 25 17:28:04 2011
@@ -31,6 +31,9 @@ public class SftpConfiguration extends R
private int serverAliveInterval;
private int serverAliveCountMax = 1;
private String chmod;
+ // comma separated list of ciphers.
+ // null means default jsch list will be used
+ private String ciphers;
public SftpConfiguration() {
setProtocol("sftp");
@@ -101,4 +104,12 @@ public class SftpConfiguration extends R
return chmod;
}
+ public void setCiphers(String ciphers) {
+ this.ciphers = ciphers;
+ }
+
+ public String getCiphers() {
+ return ciphers;
+ }
+
}
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java?rev=1161654&r1=1161653&r2=1161654&view=diff
==============================================================================
---
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
(original)
+++
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
Thu Aug 25 17:28:04 2011
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
+import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
@@ -137,6 +138,16 @@ public class SftpOperations implements R
SftpConfiguration sftpConfig = (SftpConfiguration) configuration;
+ if (isNotEmpty(sftpConfig.getCiphers())) {
+ LOG.debug("Using ciphers: " + sftpConfig.getCiphers());
+ Hashtable<String,String> ciphers = new Hashtable<String, String>();
+
+ ciphers.put("cipher.s2c", sftpConfig.getCiphers());
+ ciphers.put("cipher.c2s", sftpConfig.getCiphers());
+
+ JSch.setConfig(ciphers);
+ }
+
if (isNotEmpty(sftpConfig.getPrivateKeyFile())) {
LOG.debug("Using private keyfile: " +
sftpConfig.getPrivateKeyFile());
if (isNotEmpty(sftpConfig.getPrivateKeyFilePassphrase())) {
@@ -160,7 +171,7 @@ public class SftpOperations implements R
session.setServerAliveInterval(sftpConfig.getServerAliveInterval());
session.setServerAliveCountMax(sftpConfig.getServerAliveCountMax());
-
+
// set user information
session.setUserInfo(new UserInfo() {
public String getPassphrase() {
Added:
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSetCipherTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSetCipherTest.java?rev=1161654&view=auto
==============================================================================
---
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSetCipherTest.java
(added)
+++
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSetCipherTest.java
Thu Aug 25 17:28:04 2011
@@ -0,0 +1,57 @@
+/**
+ * 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.File;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.file.remote.SftpEndpoint;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+@Ignore("Disabled due CI servers fails on full build running with these tests")
+public class SftpSetCipherTest extends SftpServerTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Test
+ public void testSftpSetCipherName() throws Exception {
+ if (!canTest()) {
+ return;
+ }
+
+ String cipher = "blowfish-cbc";
+ String uri = "sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR +
"?username=admin&password=admin&ciphers=" + cipher ;
+ template.sendBodyAndHeader(uri , "Hello World", Exchange.FILE_NAME,
"hello.txt");
+
+ // test setting the cipher doesn't interfere with message payload
+ File file = new File(FTP_ROOT_DIR + "/hello.txt").getAbsoluteFile();
+ assertTrue("File should exist: " + file, file.exists());
+ assertEquals("Hello World",
context.getTypeConverter().convertTo(String.class, file));
+
+ // did we actually set the correct cipher?
+ SftpEndpoint endpoint = context.getEndpoint(uri, SftpEndpoint.class);
+ assertEquals(cipher, endpoint.getConfiguration().getCiphers());
+ }
+
+}