-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
INT-4243: Upgrade to sshd 1.4 #2090
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2014-2016 the original author or authors. | ||
* Copyright 2014-2017 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -25,23 +25,25 @@ | |
import java.io.InputStream; | ||
import java.math.BigInteger; | ||
import java.nio.ByteBuffer; | ||
import java.nio.file.Paths; | ||
import java.security.KeyFactory; | ||
import java.security.PublicKey; | ||
import java.security.spec.RSAPublicKeySpec; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
import org.apache.sshd.SshServer; | ||
import org.apache.sshd.common.NamedFactory; | ||
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory; | ||
import org.apache.sshd.common.util.Base64; | ||
import org.apache.sshd.server.Command; | ||
import org.apache.sshd.server.SshServer; | ||
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; | ||
import org.apache.sshd.server.sftp.SftpSubsystem; | ||
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory; | ||
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.util.Base64Utils; | ||
import org.springframework.util.StreamUtils; | ||
|
||
import com.jcraft.jsch.ChannelSftp.LsEntry; | ||
|
@@ -62,11 +64,11 @@ public void testUcPw() throws Exception { | |
try { | ||
server.setPasswordAuthenticator((arg0, arg1, arg2) -> true); | ||
server.setPort(0); | ||
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser")); | ||
server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystem.Factory())); | ||
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser"))); | ||
server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystemFactory())); | ||
final String pathname = System.getProperty("java.io.tmpdir") + File.separator + "sftptest" + File.separator; | ||
new File(pathname).mkdirs(); | ||
server.setFileSystemFactory(new VirtualFileSystemFactory(pathname)); | ||
server.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(pathname))); | ||
server.start(); | ||
|
||
DefaultSftpSessionFactory f = new DefaultSftpSessionFactory(); | ||
|
@@ -100,11 +102,11 @@ private void testKeyExchange(String pubKey, String privKey, String passphrase) | |
try { | ||
server.setPublickeyAuthenticator((username, key, session) -> key.equals(allowedKey)); | ||
server.setPort(0); | ||
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser")); | ||
server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystem.Factory())); | ||
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser"))); | ||
server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystemFactory())); | ||
final String pathname = System.getProperty("java.io.tmpdir") + File.separator + "sftptest" + File.separator; | ||
new File(pathname).mkdirs(); | ||
server.setFileSystemFactory(new VirtualFileSystemFactory(pathname)); | ||
server.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(pathname))); | ||
server.start(); | ||
|
||
DefaultSftpSessionFactory f = new DefaultSftpSessionFactory(); | ||
|
@@ -125,7 +127,12 @@ private void testKeyExchange(String pubKey, String privKey, String passphrase) | |
|
||
private PublicKey decodePublicKey(String key) throws Exception { | ||
InputStream stream = new ClassPathResource(key).getInputStream(); | ||
byte[] decodeBuffer = Base64.decodeBase64(StreamUtils.copyToByteArray(stream)); | ||
byte[] keyBytes = StreamUtils.copyToByteArray(stream); | ||
// strip any newline chars | ||
while (keyBytes[keyBytes.length - 1] == 0x0a || keyBytes[keyBytes.length - 1] == 0x0c) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any ideas why that failed sporadically? Merging BTW There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment on the JIRA - problem is unrelated but we should do the upgrade anyway. |
||
keyBytes = Arrays.copyOf(keyBytes, keyBytes.length - 1); | ||
} | ||
byte[] decodeBuffer = Base64Utils.decode(keyBytes); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm... Fails for me on Windows like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, my mistake should be 0x0d not ox0c |
||
ByteBuffer bb = ByteBuffer.wrap(decodeBuffer); | ||
int len = bb.getInt(); | ||
byte[] type = new byte[len]; | ||
|
@@ -157,7 +164,7 @@ protected void doTest(SshServer server, Session<LsEntry> session) throws IOExcep | |
} | ||
session.write(new ByteArrayInputStream("foo".getBytes()), "bar"); | ||
list = session.list("."); | ||
assertEquals("bar", list[0].getFilename()); | ||
assertEquals("bar", list[1].getFilename()); | ||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
session.read("bar", outputStream); | ||
assertEquals("foo", new String(outputStream.toByteArray())); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
remoteTemporaryFolder.getRoot().toPath()
doesn't work for you?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok; fine