diff options
author | Kevin T. Berstene <kberstene@gmail.com> | 2019-04-01 14:30:43 -0400 |
---|---|---|
committer | Kevin T. Berstene <kberstene@gmail.com> | 2019-04-01 14:30:43 -0400 |
commit | 0e5c95e5cb6f7db5cc1c3ae711f622378d8ef786 (patch) | |
tree | 252846940f1e75a34b8da511d1975c68fa00c1f1 /app/src/main/java/github/daneren2005/dsub/activity | |
parent | 2b26df335ccff17e3970ac94f4c0abfbd6898a47 (diff) | |
download | dsub-0e5c95e5cb6f7db5cc1c3ae711f622378d8ef786.tar.gz dsub-0e5c95e5cb6f7db5cc1c3ae711f622378d8ef786.tar.bz2 dsub-0e5c95e5cb6f7db5cc1c3ae711f622378d8ef786.zip |
Added password encryption for SDK 23 and higher
Diffstat (limited to 'app/src/main/java/github/daneren2005/dsub/activity')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index 803e6f72..a698f530 100644 --- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -27,6 +27,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.TypedArray; +import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; import android.provider.MediaStore; @@ -74,6 +75,7 @@ import github.daneren2005.dsub.updates.Updater; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.DrawableTint; import github.daneren2005.dsub.util.FileUtil; +import github.daneren2005.dsub.util.KeyStoreUtil; import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.UserUtil; import github.daneren2005.dsub.util.Util; @@ -691,6 +693,15 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo } private void loadSession() { + if (Build.VERSION.SDK_INT >= 23) { + try { + KeyStoreUtil.loadKeyStore(); + } catch (Exception e) { + Log.w(TAG, "Error loading keystore"); + Log.w(TAG, Log.getStackTraceString(e)); + } + } + loadSettings(); if(!Util.isOffline(this) && ServerInfo.canBookmark(this)) { loadBookmarks(); @@ -730,7 +741,22 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo editor.putString(Constants.PREFERENCES_KEY_SERVER_NAME + 1, "Demo Server"); editor.putString(Constants.PREFERENCES_KEY_SERVER_URL + 1, "http://demo.subsonic.org"); editor.putString(Constants.PREFERENCES_KEY_USERNAME + 1, "guest2"); - editor.putString(Constants.PREFERENCES_KEY_PASSWORD + 1, "guest"); + if (Build.VERSION.SDK_INT < 23) { + editor.putString(Constants.PREFERENCES_KEY_PASSWORD + 1, "guest"); + } else { + // Attempt to encrypt password + String encryptedDefaultPassword = KeyStoreUtil.encrypt("guest"); + + if (encryptedDefaultPassword != null) { + // If encryption succeeds, store encrypted password and flag password as encrypted + editor.putString(Constants.PREFERENCES_KEY_PASSWORD + 1, encryptedDefaultPassword); + editor.putBoolean(Constants.PREFERENCES_KEY_ENCRYPTED_PASSWORD + 1, true); + } else { + // Fall back to plaintext if Keystore is having issue + editor = editor.putString(Constants.PREFERENCES_KEY_PASSWORD + 1, "guest"); + editor.putBoolean(Constants.PREFERENCES_KEY_ENCRYPTED_PASSWORD + 1, false); + } + } editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); editor.commit(); } |