mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-22 12:21:15 +00:00
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:
parent
856495ab0d
commit
5af44fe8bb
2 changed files with 26 additions and 1 deletions
|
@ -109,8 +109,19 @@ public class Constants {
|
|||
/**
|
||||
* 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) {
|
||||
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) {
|
||||
|
|
|
@ -672,6 +672,10 @@ public class SyncthingService extends Service {
|
|||
new File(Constants.EXPORT_PATH, Constants.PRIVATE_KEY_FILE));
|
||||
Files.copy(Constants.getPublicKeyFile(this),
|
||||
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) {
|
||||
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 privateKey = new File(Constants.EXPORT_PATH, Constants.PRIVATE_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())
|
||||
return false;
|
||||
shutdown(State.INIT, () -> {
|
||||
|
@ -696,6 +702,14 @@ public class SyncthingService extends Service {
|
|||
} catch (IOException 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();
|
||||
});
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue