diff options
| author | Fabian Henneke <FabianHenneke@users.noreply.github.com> | 2020-09-04 11:16:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-04 14:46:05 +0530 |
| commit | 4214b7fbb4b42e187ce23b9a56df89b45df87ca6 (patch) | |
| tree | a96dd0ffda61b598aeeda3addd052f467eb74c3d /app/src/main/java/com/zeapo/pwdstore/Migrations.kt | |
| parent | e731943437861f2eeac4d8a442f512065be2a0e7 (diff) | |
| download | HardenedPass-4214b7fbb4b42e187ce23b9a56df89b45df87ca6.tar.gz HardenedPass-4214b7fbb4b42e187ce23b9a56df89b45df87ca6.zip | |
Add migration to new SshKey backend (#1076)
Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/Migrations.kt')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/Migrations.kt | 19 |
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) + } + } +} |
