Reverted database encryption due to malfunction of SQLCipher library

This commit is contained in:
Juan Miguel Boyero Corral 2012-11-09 22:13:30 +01:00
parent 9d0bc554bb
commit d4f560d2a6
15 changed files with 56 additions and 49 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -8,5 +8,5 @@
# project structure.
# Project target.
target=android-15
target=android-16
android.library=false

View File

@ -29,7 +29,8 @@ package com.android.dataframework;
import android.content.Context;
import android.database.Cursor;
import net.sqlcipher.database.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase;
//import net.sqlcipher.database.SQLiteDatabase;
import com.android.dataframework.core.DataFrameworkCore;
import com.android.dataframework.core.Table;
@ -51,10 +52,12 @@ public class DataFramework {
private DataFrameworkCore mCore;
public void open(Context context, String namePackage, String password) throws XmlPullParserException, IOException
//public void open(Context context, String namePackage, String password) throws XmlPullParserException, IOException
public void open(Context context, String namePackage) throws XmlPullParserException, IOException
{
if (mOpenInstances == 0){
mCore.open(context, namePackage, mTables, password);
//mCore.open(context, namePackage, mTables, password);
mCore.open(context, namePackage, mTables);
}
mOpenInstances++;
}

View File

@ -30,8 +30,10 @@ package com.android.dataframework.core;
import android.content.Context;
import android.content.res.XmlResourceParser;
import android.database.Cursor;
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
//import net.sqlcipher.database.SQLiteDatabase;
//import net.sqlcipher.database.SQLiteOpenHelper;
import android.util.Log;
import com.android.dataframework.DataFramework;
import com.android.dataframework.Entity;
@ -149,7 +151,8 @@ public class DataFrameworkCore {
* @param idInitialValues recurso XML con los registros a generar en la primera carga
*
*/
public void open(Context context, String namePackage, ArrayList<Table> tables, String password) throws XmlPullParserException, IOException {
//public void open(Context context, String namePackage, ArrayList<Table> tables, String password) throws XmlPullParserException, IOException {
public void open(Context context, String namePackage, ArrayList<Table> tables) throws XmlPullParserException, IOException {
try {
// Solo en el caso de que no est<EFBFBD>n cargadas las tablas, leemos el XML
if (tables.size() == 0)
@ -231,7 +234,8 @@ public class DataFrameworkCore {
mSaveInitialValues = false;
mDbHelper = new DatabaseHelper();
mDb = mDbHelper.getWritableDatabase(password);
mDb = mDbHelper.getWritableDatabase();
//mDb = mDbHelper.getWritableDatabase(password);
//mDb = SQLiteDatabase.openDatabase(mCtx.getDatabasePath(mDataBaseName).getPath(), password, null, SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
if (mSaveInitialValues)

View File

@ -86,7 +86,7 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
/**
* Database passphrase
*/
private String DBKey;
//private String DBKey;
/**
* Last application version preference name.
*/
@ -138,7 +138,7 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
/**
* Database passphrase preference name.
*/
private static final String DBKEYPREF = "DBKeyPref";
//private static final String DBKEYPREF = "DBKeyPref";
/**
* User ID preference
*/
@ -277,20 +277,20 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
* Gets the database passphrase
* @return The database passphrase
*/
public String getDBKey() {
/*public String getDBKey() {
return DBKey;
}
}*/
/**
* Sets the database passphrase
* @param key The database passphrase
*/
public void setDBKey(String key) {
/*public void setDBKey(String key) {
DBKey = key;
editor = prefs.edit();
editor.putString(DBKEYPREF, DBKey);
editor.commit();
}
}*/
/**
* Generates the stars sequence to be showed on password field
@ -355,7 +355,7 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
lastVersion = prefs.getInt(LASTVERSIONPREF, 0);
lastCourseSelected = prefs.getInt(LASTCOURSESELECTEDPREF, 0);
rollcallCourseSelected = prefs.getLong(ROLLCALLCOURSESELECTEDPREF, -1);
DBKey = prefs.getString(DBKEYPREF, "");
//DBKey = prefs.getString(DBKEYPREF, "");
}
/* (non-Javadoc)
@ -589,7 +589,7 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
editor.putInt(LASTVERSIONPREF, lastVersion);
editor.putInt(LASTCOURSESELECTEDPREF, lastCourseSelected);
editor.putLong(ROLLCALLCOURSESELECTEDPREF, rollcallCourseSelected);
editor.putString(DBKEYPREF, DBKey);
//editor.putString(DBKEYPREF, DBKey);
editor.commit();
}
}

View File

@ -312,7 +312,7 @@ public class SWADMain extends MenuExpandableListActivity {
//If this is an upgrade, show upgrade dialog
} else if(lastVersion < currentVersion) {
showUpgradeDialog();
//showUpgradeDialog();
dbHelper.upgradeDB(this);
//prefs.upgradeCredentials();

View File

@ -32,8 +32,10 @@ import org.xmlpull.v1.XmlPullParserException;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteStatement;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
//import net.sqlcipher.database.SQLiteDatabase;
//import net.sqlcipher.database.SQLiteStatement;
import android.os.Environment;
import android.util.Log;
@ -41,7 +43,6 @@ import com.android.dataframework.DataFramework;
import com.android.dataframework.Entity;
import es.ugr.swad.swadroid.Global;
import es.ugr.swad.swadroid.Preferences;
/**
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
@ -60,15 +61,15 @@ public class DataBaseHelper {
/**
* Application preferences
*/
private Preferences prefs = new Preferences();
//private Preferences prefs = new Preferences();
/**
* Database passphrase
*/
private String DBKey;
//private String DBKey;
/**
* Database passphrase length
*/
private int DB_KEY_LENGTH = 128;
//private int DB_KEY_LENGTH = 128;
/**
* Constructor
@ -76,26 +77,27 @@ public class DataBaseHelper {
*/
public DataBaseHelper(Context ctx) {
mCtx = ctx;
prefs.getPreferences(mCtx);
DBKey = prefs.getDBKey();
//prefs.getPreferences(mCtx);
//DBKey = prefs.getDBKey();
db = DataFramework.getInstance();
//Initialize SQLCipher libraries
SQLiteDatabase.loadLibs(mCtx);
//SQLiteDatabase.loadLibs(mCtx);
//If the passphrase is empty, generate a random passphrase and recreate database
if(DBKey.equals("")) {
/*if(DBKey.equals("")) {
DBKey = Global.randomString(DB_KEY_LENGTH);
prefs.setDBKey(DBKey);
mCtx.deleteDatabase("swadroid_db");
mCtx.deleteDatabase("swadroid_db");*/
//SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(mCtx.getDatabasePath("swadroid_db_crypt"), DBKey, null);
//database.close();
}
/*}
Log.d("DataBaseHelper", "DBKey=" + DBKey);
Log.d("DataBaseHelper", "DBKey=" + DBKey);*/
try {
db.open(mCtx, mCtx.getPackageName(), DBKey);
//db.open(mCtx, mCtx.getPackageName(), DBKey);
db.open(mCtx, mCtx.getPackageName());
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
@ -921,9 +923,7 @@ public class DataBaseHelper {
insertEntity(Global.DB_TABLE_GROUPS,g,rows.get(0));
}
//update all the relationship
Entity ent;
//update all the relationship
long groupCode = g.getId();
rows = db.getEntityList(Global.DB_TABLE_GROUPS_COURSES,"grpCod =" + groupCode);
Course course = (Course) getRow(Global.DB_TABLE_COURSES,"id",String.valueOf(courseCode));
@ -1776,12 +1776,12 @@ public class DataBaseHelper {
*
* */
/* From version 11 to 12
* changes on courses table:
* - old field name is erased
* The rest of the changes are only new fields and they are added automatic by Dataframework. */
/*Cursor dbCursor = db.getDB().query(Global.DB_TABLE_COURSES, null, null, null, null, null, null);
Cursor dbCursor = db.getDB().query(Global.DB_TABLE_COURSES, null, null, null, null, null, null);
String[] columnNames = dbCursor.getColumnNames();
boolean found = false;
int i = 0;
@ -1808,13 +1808,13 @@ public class DataBaseHelper {
+ " shortName text, fullName text); ");
db.getDB().execSQL(
"INSERT INTO " + Global.DB_TABLE_COURSES + " SELECT _id, id, userRole, shortName, fullName "
+ " FROM __"+ Global.DB_TABLE_COURSES + ";");
+ " FROM __"+ Global.DB_TABLE_COURSES + ";");*/
}
dbCursor = db.getDB().query(Global.DB_TABLE_COURSES, null, null, null, null, null, null);
columnNames = dbCursor.getColumnNames();
/* version 12 - 13
* changes on groups table:
* - old field groupCode is now id
@ -1822,7 +1822,7 @@ public class DataBaseHelper {
* - old field groupTypeName is erased
* The rest of the changes are only new fields and they are added automatic by Dataframework.
* */
/*dbCursor = db.getDB().query(Global.DB_TABLE_GROUPS, null, null, null, null, null, null);
dbCursor = db.getDB().query(Global.DB_TABLE_GROUPS, null, null, null, null, null, null);
columnNames = dbCursor.getColumnNames();
found = false;
i = 0;
@ -1848,11 +1848,11 @@ public class DataBaseHelper {
db.getDB().execSQL("INSERT INTO " + Global.DB_TABLE_GROUPS + " SELECT _id, id, groupName, maxStudents, "
+ "students, open, fileZones, member FROM __"+ Global.DB_TABLE_GROUPS + ";");
db.getDB().execSQL( "DROP TABLE __" + Global.DB_TABLE_GROUPS + ";");*/
/*}
}
dbCursor = db.getDB().query(Global.DB_TABLE_GROUPS, null, null, null, null, null, null);
columnNames = dbCursor.getColumnNames();
/*db.getDB().execSQL("CREATE TEMPORARY TABLE __"
+ Global.DB_TABLE_NOTIFICATIONS
+ " (_id INTEGER PRIMARY KEY AUTOINanCREMENT, id INTEGER, eventType TEXT, eventTime TEXT,"
@ -1887,7 +1887,7 @@ public class DataBaseHelper {
+ "userSurname1, userSurname2, userFirstname, location, summary, status, content FROM __"
+ Global.DB_TABLE_NOTIFICATIONS + ";"
+ "DROP TABLE __" + Global.DB_TABLE_NOTIFICATIONS + ";");*/
compactDB();
}
}

View File

@ -316,11 +316,11 @@ public class Test extends Model {
s = buff.toString().trim();
//Remove accents
s = s.replace('', 'a');
s = s.replace('Ž', 'e');
s = s.replace('', 'i');
s = s.replace('', 'o');
s = s.replace('œ', 'u');
s = s.replace('á', 'a');
s = s.replace('é', 'e');
s = s.replace('í', 'i');
s = s.replace('ó', 'o');
s = s.replace('ú', 'u');
return s;
}