From 4214b7fbb4b42e187ce23b9a56df89b45df87ca6 Mon Sep 17 00:00:00 2001 From: Fabian Henneke Date: Fri, 4 Sep 2020 11:16:05 +0200 Subject: Add migration to new SshKey backend (#1076) Co-authored-by: Harsh Shandilya --- app/src/main/java/com/zeapo/pwdstore/Migrations.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'app/src/main/java/com/zeapo/pwdstore/Migrations.kt') diff --git a/app/src/main/java/com/zeapo/pwdstore/Migrations.kt b/app/src/main/java/com/zeapo/pwdstore/Migrations.kt index 64220aed..1922814c 100644 --- a/app/src/main/java/com/zeapo/pwdstore/Migrations.kt +++ b/app/src/main/java/com/zeapo/pwdstore/Migrations.kt @@ -12,14 +12,17 @@ import com.github.ajalt.timberkt.e import com.github.ajalt.timberkt.i import com.zeapo.pwdstore.git.config.GitSettings import com.zeapo.pwdstore.git.config.Protocol +import com.zeapo.pwdstore.git.sshj.SshKey import com.zeapo.pwdstore.utils.PreferenceKeys import com.zeapo.pwdstore.utils.getString import com.zeapo.pwdstore.utils.sharedPrefs +import java.io.File import java.net.URI fun runMigrations(context: Context) { migrateToGitUrlBasedConfig(context) migrateToHideAll(context) + migrateToSshKey(context) } private fun migrateToGitUrlBasedConfig(context: Context) { @@ -94,3 +97,19 @@ private fun migrateToHideAll(context: Context) { putBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, isHidden) } } + +private fun migrateToSshKey(context: Context) { + val privateKeyFile = File(context.filesDir, ".ssh_key") + if (context.sharedPrefs.contains(PreferenceKeys.USE_GENERATED_KEY) && + !SshKey.exists && + privateKeyFile.exists()) { + // Currently uses a private key imported or generated with an old version of Password Store. + // Generated keys come with a public key which the user should still be able to view after + // the migration (not possible for regular imported keys), hence the special case. + val isGeneratedKey = context.sharedPrefs.getBoolean(PreferenceKeys.USE_GENERATED_KEY, false) + SshKey.useLegacyKey(isGeneratedKey) + context.sharedPrefs.edit { + remove(PreferenceKeys.USE_GENERATED_KEY) + } + } +} -- cgit v1.2.3