mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 18:28:59 +03:00
Implement keys migration
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
d56f53bb11
commit
ee7d4ed56c
4 changed files with 38 additions and 1 deletions
|
@ -99,6 +99,7 @@ public class PushUtils {
|
|||
}
|
||||
|
||||
private static int generateRsa2048KeyPair() {
|
||||
MainApp.migratePushKeys();
|
||||
String keyPath = MainApp.getAppContext().getFilesDir().getAbsolutePath() + File.separator + MainApp.getDataFolder() + File.separator
|
||||
+ KEYPAIR_FOLDER;
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ import android.content.pm.PackageInfo;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.StrictMode;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
|
@ -66,6 +65,7 @@ import com.owncloud.android.utils.FilesSyncHelper;
|
|||
import com.owncloud.android.utils.PermissionUtil;
|
||||
import com.owncloud.android.utils.ReceiversHelper;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -238,6 +238,31 @@ public class MainApp extends MultiDexApplication {
|
|||
}
|
||||
}
|
||||
|
||||
public static void migratePushKeys() {
|
||||
Context context = getAppContext();
|
||||
|
||||
if (!PreferenceManager.getKeysMigration(context)) {
|
||||
String oldKeyPath = getStoragePath() + File.separator + MainApp.getDataFolder() + File.separator + "nc-keypair";
|
||||
File oldPrivateKey = new File(oldKeyPath + File.separator + "push_key.priv");
|
||||
File oldPublicKey = new File(oldKeyPath + File.separator + "push_key.pub");
|
||||
|
||||
String keyPath = getAppContext().getFilesDir().getAbsolutePath() +
|
||||
File.separator + MainApp.getDataFolder() + File.separator + "nc-keypair";
|
||||
File privateKey = new File(keyPath + File.separator + "push_key.priv");
|
||||
File publicKey = new File(keyPath + File.separator + "push_key.pub");
|
||||
|
||||
if (oldPrivateKey.exists() && oldPublicKey.exists()) {
|
||||
if (oldPrivateKey.renameTo(privateKey) && oldPublicKey.renameTo(publicKey)) {
|
||||
PreferenceManager.setKeysMigration(context, true);
|
||||
} else {
|
||||
PreferenceManager.setKeysMigration(context, false);
|
||||
}
|
||||
} else {
|
||||
PreferenceManager.setKeysMigration(context, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void notificationChannels() {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O && getAppContext() != null) {
|
||||
Context context = getAppContext();
|
||||
|
|
|
@ -53,6 +53,7 @@ public abstract class PreferenceManager {
|
|||
private static final String PREF__INSTANT_VIDEO_UPLOAD_PATH_USE_SUBFOLDERS
|
||||
= "instant_video_upload_path_use_subfolders";
|
||||
private static final String PREF__LEGACY_CLEAN = "legacyClean";
|
||||
private static final String PREF__KEYS_MIGRATION = "keysMigration";
|
||||
private static final String PREF__AUTO_UPLOAD_UPDATE_PATH = "autoUploadPathUpdate";
|
||||
private static final String PREF__PUSH_TOKEN = "pushToken";
|
||||
private static final String PREF__AUTO_UPLOAD_SPLIT_OUT = "autoUploadEntriesSplitOut";
|
||||
|
@ -286,6 +287,11 @@ public abstract class PreferenceManager {
|
|||
return getDefaultSharedPreferences(context).getBoolean(PREF__LEGACY_CLEAN, false);
|
||||
}
|
||||
|
||||
public static boolean getKeysMigration(Context context) {
|
||||
return getDefaultSharedPreferences(context).getBoolean(PREF__KEYS_MIGRATION, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the auto upload paths flag last set.
|
||||
*
|
||||
|
@ -316,6 +322,10 @@ public abstract class PreferenceManager {
|
|||
saveBooleanPreference(context, PREF__LEGACY_CLEAN, legacyClean);
|
||||
}
|
||||
|
||||
public static void setKeysMigration(Context context, boolean keysMigration) {
|
||||
saveBooleanPreference(context, PREF__KEYS_MIGRATION, keysMigration);
|
||||
}
|
||||
|
||||
public static void setAutoUploadInit(Context context, boolean autoUploadInit) {
|
||||
saveBooleanPreference(context, PREF__AUTO_UPLOAD_INIT, autoUploadInit);
|
||||
}
|
||||
|
|
|
@ -99,6 +99,7 @@ public class PushUtils {
|
|||
}
|
||||
|
||||
private static int generateRsa2048KeyPair() {
|
||||
MainApp.migratePushKeys();
|
||||
String keyPath = MainApp.getAppContext().getFilesDir().getAbsolutePath() + File.separator + MainApp.getDataFolder() + File.separator
|
||||
+ KEYPAIR_FOLDER;
|
||||
|
||||
|
|
Loading…
Reference in a new issue