Skip to content

Commit d98d349

Browse files
Fix: ED25519 SSH keys not working (#1595)
* Push testing stuffs for #1289 SFTP ED25519 KEYS * remove: maverick-bc; use bc directly as workaround for now * refactor: sftp log file to use a non-hard-coded value. This commit removes a hard-coded file path for the log file, Using a `context` retrieved app data directory Path. Docs Ref: https://developer.android.com/reference/android/content/Context#getExternalFilesDir(java.lang.String) * Update Sftp.java --------- Co-authored-by: Rohit Kushvaha <oldisg131@gmail.com>
1 parent 3b7ee17 commit d98d349

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

build-extras.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
android {
2+
packagingOptions {
3+
pickFirst 'META-INF/versions/9/OSGI-INF/MANIFEST.MF'
4+
}
5+
}
6+
17
configurations {
28
all {
39
exclude module: 'commons-logging'
10+
exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'
11+
exclude group: 'org.bouncycastle', module: 'bcpkix-jdk15on'
12+
exclude group: 'org.bouncycastle', module: 'bcpkix-jdk18on'
13+
exclude group: 'org.bouncycastle', module: 'bcprov-jdk18on'
414
}
515
}

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"cordova-clipboard": {},
2626
"cordova-plugin-device": {},
2727
"cordova-plugin-file": {},
28-
"cordova-plugin-sftp": {},
2928
"cordova-plugin-server": {},
3029
"cordova-plugin-ftp": {},
3130
"cordova-plugin-sdcard": {},
@@ -37,7 +36,9 @@
3736
"cordova-plugin-buildinfo": {},
3837
"cordova-plugin-system": {},
3938
"cordova-plugin-browser": {},
40-
"com.foxdebug.acode.rk.exec.terminal": {}
39+
"com.foxdebug.acode.rk.exec.terminal": {},
40+
"com.foxdebug.acode.rk.exec.proot": {},
41+
"cordova-plugin-sftp": {}
4142
},
4243
"platforms": [
4344
"android"
@@ -62,6 +63,7 @@
6263
"@types/url-parse": "^1.4.11",
6364
"autoprefixer": "^10.4.21",
6465
"babel-loader": "^10.0.0",
66+
"com.foxdebug.acode.rk.exec.proot": "file:src/plugins/proot",
6567
"com.foxdebug.acode.rk.exec.terminal": "file:src/plugins/terminal",
6668
"cordova-android": "^14.0.1",
6769
"cordova-clipboard": "^1.3.0",

src/plugins/sftp/plugin.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@
2626

2727
<framework src="commons-io:commons-io:2.11.0" />
2828
<framework src="com.sshtools:maverick-synergy-client:3.1.2" />
29-
<framework src="com.sshtools:maverick-bc:3.1.2" />
29+
<!-- <framework src="com.sshtools:maverick-bc:3.1.2" />-->
30+
<framework src="org.bouncycastle:bcprov-jdk15to18:1.79" />
31+
<framework src="org.bouncycastle:bcpkix-jdk15to18:1.79" />
3032
</plugin>

src/plugins/sftp/src/com/foxdebug/sftp/Sftp.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@
3333
import java.net.URLEncoder;
3434
import java.nio.channels.UnresolvedAddressException;
3535
import java.nio.charset.StandardCharsets;
36+
import java.security.Security;
3637
import org.apache.cordova.CallbackContext;
3738
import org.apache.cordova.CordovaInterface;
3839
import org.apache.cordova.CordovaPlugin;
3940
import org.apache.cordova.CordovaWebView;
4041
import org.json.JSONArray;
4142
import org.json.JSONException;
4243
import org.json.JSONObject;
44+
import java.util.Arrays;
45+
import org.bouncycastle.jce.provider.BouncyCastleProvider;
4346

4447
public class Sftp extends CordovaPlugin {
4548

@@ -178,7 +181,23 @@ public void run() {
178181
ContentResolver contentResolver = context.getContentResolver();
179182
InputStream in = contentResolver.openInputStream(uri);
180183

181-
JCEProvider.enableBouncyCastle(true);
184+
// for `appDataDirectory`, Ref: https://developer.android.com/reference/android/content/Context#getExternalFilesDir(java.lang.String)
185+
// the absolute path to application-specific directory. May return *null* if shared storage is not currently available.
186+
File appDataDirectory = context.getExternalFilesDir(null);
187+
if (appDataDirectory != null) {
188+
com.sshtools.common.logger.Log.getDefaultContext().enableFile(com.sshtools.common.logger.Log.Level.DEBUG, new File(appDataDirectory,"synergy.log"));
189+
}
190+
// JCEProvider.enableBouncyCastle(false);
191+
192+
Log.i(TAG, "All Available Security Providers (Security.getProviders() : " + Arrays.toString(Security.getProviders()));
193+
Log.i(TAG, "All Available Security Providers for ED25519 (Security.getProviders(\"KeyPairGenerator.Ed25519\"\") : " + Arrays.toString(Security.getProviders("KeyPairGenerator.Ed25519")));
194+
Log.i(TAG, "BC Security Provider Name (`Security.getProvider(BouncyCastleProvider.PROVIDER_NAME)`) : " + Security.getProvider(BouncyCastleProvider.PROVIDER_NAME));
195+
Security.removeProvider("BC");
196+
Security.insertProviderAt(new BouncyCastleProvider(), 1);
197+
198+
Log.i(TAG, "(After Inserting BC) All Available Security Providers (Security.getProviders() : " + Arrays.toString(Security.getProviders()));
199+
Log.i(TAG, "(After Inserting BC) All Available Security Providers for ED25519 (Security.getProviders(\"KeyPairGenerator.Ed25519\"\") : " + Arrays.toString(Security.getProviders("KeyPairGenerator.Ed25519")));
200+
Log.i(TAG, "(After Inserting BC) BC Security Provider Name (`Security.getProvider(BouncyCastleProvider.PROVIDER_NAME)`) : " + Security.getProvider(BouncyCastleProvider.PROVIDER_NAME));
182201

183202
SshKeyPair keyPair = null;
184203
try {

0 commit comments

Comments
 (0)