INT-3200: SFTP: use byte[] for the PrivateKey
JIRA: https://jira.spring.io/browse/INT-3200 INT-3200: Remove reduntant test case INT-3200: remove trailing space
This commit is contained in:
@@ -25,6 +25,7 @@ import org.springframework.integration.file.remote.session.Session;
|
||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
import org.springframework.integration.file.remote.session.SharedSessionCapable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
@@ -42,6 +43,7 @@ import com.jcraft.jsch.UserInfo;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gunnar Hillert
|
||||
* @author Gary Russell
|
||||
* @author David Liu
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
@@ -367,12 +369,12 @@ public class DefaultSftpSessionFactory implements SessionFactory<LsEntry>, Share
|
||||
|
||||
// private key
|
||||
if (this.privateKey != null) {
|
||||
String privateKeyFilePath = this.privateKey.getFile().getAbsolutePath();
|
||||
byte[] keyByteArray = StreamUtils.copyToByteArray(this.privateKey.getInputStream());
|
||||
if (StringUtils.hasText(this.privateKeyPassphrase)) {
|
||||
this.jsch.addIdentity(privateKeyFilePath, this.privateKeyPassphrase);
|
||||
this.jsch.addIdentity(this.user, keyByteArray, null, this.privateKeyPassphrase.getBytes());
|
||||
}
|
||||
else {
|
||||
this.jsch.addIdentity(privateKeyFilePath);
|
||||
this.jsch.addIdentity(this.user, keyByteArray, null, null);
|
||||
}
|
||||
}
|
||||
com.jcraft.jsch.Session jschSession = this.jsch.getSession(this.user, this.host, this.port);
|
||||
|
||||
@@ -30,7 +30,6 @@ import java.security.PublicKey;
|
||||
import java.security.spec.RSAPublicKeySpec;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
import org.apache.sshd.SshServer;
|
||||
import org.apache.sshd.common.NamedFactory;
|
||||
import org.apache.sshd.common.file.FileSystemView;
|
||||
@@ -45,13 +44,17 @@ import org.apache.sshd.server.session.ServerSession;
|
||||
import org.apache.sshd.server.sftp.SftpSubsystem;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.integration.file.remote.session.Session;
|
||||
import org.springframework.integration.test.util.SocketUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
* @author David Liu
|
||||
* @since 4.1
|
||||
*
|
||||
*/
|
||||
@@ -150,7 +153,8 @@ public class SftpServerTests {
|
||||
f.setHost("localhost");
|
||||
f.setPort(port);
|
||||
f.setUser("user");
|
||||
f.setPrivateKey(new ClassPathResource("id_rsa"));
|
||||
InputStream stream = new ClassPathResource("id_rsa").getInputStream();
|
||||
f.setPrivateKey(new ByteArrayResource(StreamUtils.copyToByteArray(stream)));
|
||||
Session<LsEntry> session = f.getSession();
|
||||
doTest(server, session);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user