diff options
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java index 5a5746d5..6442e909 100644 --- a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java +++ b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java @@ -44,6 +44,7 @@ import de.thedevstack.conversationsplus.entities.Conversation; import de.thedevstack.conversationsplus.entities.Message; import de.thedevstack.conversationsplus.entities.Roster; import de.thedevstack.conversationsplus.entities.ServiceDiscoveryResult; +import de.thedevstack.conversationsplus.utils.SimpleCryptoUtil; import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException; import de.thedevstack.conversationsplus.xmpp.jid.Jid; @@ -54,7 +55,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { private static final String DATABASE_NAME = "history"; private static final int DATABASE_VERSION = 25; private static final int C_TO_CPLUS_VERSION_OFFSET = 1000; - private static final int CPLUS_DATABASE_VERSION = 1; + private static final int CPLUS_DATABASE_VERSION = 2; private static final int CPLUS_DATABASE_VERSION_MULTIPLIER = 100; private static final int PHYSICAL_DATABASE_VERSION = DATABASE_VERSION + C_TO_CPLUS_VERSION_OFFSET + (CPLUS_DATABASE_VERSION * CPLUS_DATABASE_VERSION_MULTIPLIER); @@ -203,6 +204,19 @@ public class DatabaseBackend extends SQLiteOpenHelper { db.execSQL("INSERT INTO " + MessageDatabaseAccess.TABLE_NAME_ADDITIONAL_PARAMETERS + "(" + MessageDatabaseAccess.COLUMN_NAME_MSG_PARAMS_MSGUUID + ") " + " SELECT " + Message.UUID + " FROM " + Message.TABLENAME); } + if (newVersion == 2) { + Logging.d("db.upgrade.cplus", "Encrypt all passwords for the first time"); + Cursor cursor = db.rawQuery("SELECT " + Account.UUID + ", " + Account.PASSWORD + " FROM " + Account.TABLENAME, new String[0]); + while (cursor.moveToNext()) { + String uuid = CursorHelper.getString(cursor, Account.UUID); + String password = CursorHelper.getString(cursor, Account.PASSWORD); + String encryptedPassword = SimpleCryptoUtil.encrypt(Account.PW_SEED, password); + ContentValues values = new ContentValues(); + values.put(Account.PASSWORD, encryptedPassword); + db.update(Account.TABLENAME, values, Account.UUID + "=?", new String[] {uuid}); + } + cursor.close(); + } } } |