Commit 526d500a authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Upgrade sshd-core to version 0.14

parent 55a98ef6
......@@ -44,7 +44,6 @@ android {
pickFirst "META-INF/BCKEY.SF"
pickFirst "META-INF/BCKEY.DSA"
pickFirst "META-INF/INDEX.LIST"
pickFirst "META-INF/io.netty.versions.properties"
}
lintOptions {
abortOnError false
......@@ -75,7 +74,7 @@ dependencies {
implementation 'com.android.support:design:27.1.1'
implementation 'com.jakewharton:disklrucache:2.0.2' //For caching album art bitmaps
implementation 'org.apache.sshd:sshd-core:0.8.0' //0.9 seems to fail on Android 6 and 1.+ requires java.nio.file, which doesn't exist in Android
implementation 'org.apache.sshd:sshd-core:0.14.0' //Newer version requires java.nio.file, which isn't available until Android 8+
implementation 'com.madgag.spongycastle:bcpkix-jdk15on:1.58.0.0' //For SSL certificate generation
......
......@@ -51,9 +51,14 @@ public class SftpPlugin extends Plugin {
@Override
public boolean onCreate() {
server.init(context, device);
permissionExplanation = R.string.sftp_permission_explanation;
return true;
try {
server.init(context, device);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
@Override
......
......@@ -27,17 +27,17 @@ import android.util.Log;
import org.apache.sshd.SshServer;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.Session;
import org.apache.sshd.common.file.FileSystemFactory;
import org.apache.sshd.common.file.FileSystemView;
import org.apache.sshd.common.file.SshFile;
import org.apache.sshd.common.file.nativefs.NativeFileSystemView;
import org.apache.sshd.common.file.nativefs.NativeSshFile;
import org.apache.sshd.common.keyprovider.AbstractKeyPairProvider;
import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.FileSystemFactory;
import org.apache.sshd.server.FileSystemView;
import org.apache.sshd.server.PasswordAuthenticator;
import org.apache.sshd.server.PublickeyAuthenticator;
import org.apache.sshd.server.SshFile;
import org.apache.sshd.server.command.ScpCommandFactory;
import org.apache.sshd.server.filesystem.NativeFileSystemView;
import org.apache.sshd.server.filesystem.NativeSshFile;
import org.apache.sshd.server.kex.DHG1;
import org.apache.sshd.server.kex.DHG14;
import org.apache.sshd.server.session.ServerSession;
......@@ -84,32 +84,27 @@ class SimpleSftpServer {
private final SshServer sshd = SshServer.setUpDefaultServer();
public void init(Context context, Device device) {
public void init(Context context, Device device) throws Exception {
sshd.setKeyExchangeFactories(Arrays.asList(
new DHG14.Factory(),
new DHG1.Factory()));
//Reuse this device keys for the ssh connection as well
KeyPair[] keyPairList = new KeyPair[1];
try {
PrivateKey privateKey = RsaHelper.getPrivateKey(context);
PublicKey publicKey = RsaHelper.getPublicKey(context);
keyPairList[0] = new KeyPair(publicKey, privateKey);
} catch (Exception e) {
Log.e("SimpleSftpServer", "Can't load device keys");
throw new RuntimeException("BLA");
}
final KeyPair keyPair;
PrivateKey privateKey = RsaHelper.getPrivateKey(context);
PublicKey publicKey = RsaHelper.getPublicKey(context);
keyPair = new KeyPair(publicKey, privateKey);
sshd.setKeyPairProvider(new AbstractKeyPairProvider() {
@Override
protected KeyPair[] loadKeys() {
return keyPairList;
public Iterable<KeyPair> loadKeys() {
return Collections.singletonList(keyPair);
}
});
sshd.setFileSystemFactory(new AndroidFileSystemFactory(context));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setSubsystemFactories(Collections.singletonList((NamedFactory<Command>) new SftpSubsystem.Factory()));
sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystem.Factory()));
if (device.publicKey != null) {
keyAuth.deviceKey = device.publicKey;
......@@ -222,7 +217,7 @@ class SimpleSftpServer {
@Override
protected SshFile getFile(final String dir, final String file) {
File fileObj = new File(dir, file);
return new AndroidSshFile(fileObj, userName, context);
return new AndroidSshFile(this, fileObj, userName, context);
}
}
......@@ -231,8 +226,8 @@ class SimpleSftpServer {
final private Context context;
final private File file;
public AndroidSshFile(final File file, final String userName, Context context) {
super(file.getAbsolutePath(), file, userName);
public AndroidSshFile(final AndroidFileSystemView view, final File file, final String userName, Context context) {
super(view, file.getAbsolutePath(), file, userName);
this.context = context;
this.file = file;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment