aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/Migrations.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/Migrations.kt')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/Migrations.kt19
1 files changed, 19 insertions, 0 deletions
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)
+ }
+ }
+}