1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-29 07:41:17 +00:00

Add export/import support for HTTPS files (fixes #1986) (#2013)

Add support for exporting and importing HTTPS related files
(`https-cert.pem` and `https-key.pem`). It can be used to export/import
a self-signed certificate/custom HTTPS certificate to the Syncthing
instance on Android.

I couldn't launch the app in my IDE so I didn't test the changes. 

Closes #1986
This commit is contained in:
LBF38 2023-12-03 23:20:08 +01:00 committed by GitHub
parent 856495ab0d
commit 5af44fe8bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -109,8 +109,19 @@ public class Constants {
/** /**
* Name of the public HTTPS CA file in the data directory. * Name of the public HTTPS CA file in the data directory.
*/ */
static final String HTTPS_CERT_FILE = "https-cert.pem";
public static File getHttpsCertFile(Context context) { public static File getHttpsCertFile(Context context) {
return new File(context.getFilesDir(), "https-cert.pem"); return new File(context.getFilesDir(), HTTPS_CERT_FILE);
}
/**
* Key of the public HTTPS CA file in the data directory.
*/
static final String HTTPS_KEY_FILE = "https-key.pem";
public static File getHttpsKeyFile(Context context) {
return new File(context.getFilesDir(), HTTPS_KEY_FILE);
} }
static File getSyncthingBinary(Context context) { static File getSyncthingBinary(Context context) {

View file

@ -672,6 +672,10 @@ public class SyncthingService extends Service {
new File(Constants.EXPORT_PATH, Constants.PRIVATE_KEY_FILE)); new File(Constants.EXPORT_PATH, Constants.PRIVATE_KEY_FILE));
Files.copy(Constants.getPublicKeyFile(this), Files.copy(Constants.getPublicKeyFile(this),
new File(Constants.EXPORT_PATH, Constants.PUBLIC_KEY_FILE)); new File(Constants.EXPORT_PATH, Constants.PUBLIC_KEY_FILE));
Files.copy(Constants.getHttpsCertFile(this),
new File(Constants.EXPORT_PATH, Constants.HTTPS_CERT_FILE));
Files.copy(Constants.getHttpsKeyFile(this),
new File(Constants.EXPORT_PATH, Constants.HTTPS_KEY_FILE));
} catch (IOException e) { } catch (IOException e) {
Log.w(TAG, "Failed to export config", e); Log.w(TAG, "Failed to export config", e);
} }
@ -686,6 +690,8 @@ public class SyncthingService extends Service {
File config = new File(Constants.EXPORT_PATH, Constants.CONFIG_FILE); File config = new File(Constants.EXPORT_PATH, Constants.CONFIG_FILE);
File privateKey = new File(Constants.EXPORT_PATH, Constants.PRIVATE_KEY_FILE); File privateKey = new File(Constants.EXPORT_PATH, Constants.PRIVATE_KEY_FILE);
File publicKey = new File(Constants.EXPORT_PATH, Constants.PUBLIC_KEY_FILE); File publicKey = new File(Constants.EXPORT_PATH, Constants.PUBLIC_KEY_FILE);
File httpsCert = new File(Constants.EXPORT_PATH, Constants.HTTPS_CERT_FILE);
File httpsKey = new File(Constants.EXPORT_PATH, Constants.HTTPS_KEY_FILE);
if (!config.exists() || !privateKey.exists() || !publicKey.exists()) if (!config.exists() || !privateKey.exists() || !publicKey.exists())
return false; return false;
shutdown(State.INIT, () -> { shutdown(State.INIT, () -> {
@ -696,6 +702,14 @@ public class SyncthingService extends Service {
} catch (IOException e) { } catch (IOException e) {
Log.w(TAG, "Failed to import config", e); Log.w(TAG, "Failed to import config", e);
} }
if (httpsCert.exists() && httpsKey.exists()) {
try {
Files.copy(httpsCert, Constants.getHttpsCertFile(this));
Files.copy(httpsKey, Constants.getHttpsKeyFile(this));
} catch (IOException e) {
Log.w(TAG, "Failed to import HTTPS config files", e);
}
}
launchStartupTask(); launchStartupTask();
}); });
return true; return true;