From: rmceoin Date: Wed, 28 Jan 2009 01:09:36 +0000 (+0000) Subject: OI Safe: added cipher access table, corrected spelling error X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=3bc80ba43fce39612f226dcc8e2b5e894b23b66e;p=android-vcpass-oisafe OI Safe: added cipher access table, corrected spelling error git-svn-id: http://openintents.googlecode.com/svn/trunk/Safe@1866 72b678ce-9140-0410-bee8-679b907dd61a --- diff --git a/res/values/strings.xml b/res/values/strings.xml index 61abaf4..332e26a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -154,5 +154,5 @@ Package access not found New master key - A new random master key has been created. Use menu > backup and store this key in a safe place. Without this key you may loose encrypted data. + A new random master key has been created. Use menu > backup and store this key in a safe place. Without this key you may lose encrypted data. diff --git a/src/org/openintents/safe/DBHelper.java b/src/org/openintents/safe/DBHelper.java index 276e833..3ead13a 100644 --- a/src/org/openintents/safe/DBHelper.java +++ b/src/org/openintents/safe/DBHelper.java @@ -46,6 +46,7 @@ public class DBHelper { private static final String TABLE_MASTER_KEY = "master_key"; private static final String TABLE_SALT = "salt"; private static final String TABLE_PACKAGE_ACCESS = "package_access"; + private static final String TABLE_CIPHER_ACCESS = "cipher_access"; private static final int DATABASE_VERSION = 4; private static String TAG = "DBHelper"; Context myCtx; @@ -94,6 +95,16 @@ public class DBHelper { "create table " + TABLE_SALT + " (" + "salt text not null);"; + private static final String CIPHER_ACCESS_CREATE = + "create table " + TABLE_CIPHER_ACCESS + " (" + + "id integer primary key autoincrement, " + + "packagename text not null, " + + "expires integer not null, " + + "dateadded text not null);"; + + private static final String CIPHER_ACCESS_DROP = + "drop table " + TABLE_CIPHER_ACCESS + ";"; + private SQLiteDatabase db; private static boolean needsPrePopulation=false; private static boolean needsUpgrade=false; @@ -152,6 +163,7 @@ public class DBHelper { db.execSQL(PASSWORDS_CREATE); db.execSQL(PACKAGE_ACCESS_CREATE); + db.execSQL(CIPHER_ACCESS_CREATE); db.execSQL(MASTER_KEY_CREATE); db.execSQL(SALT_CREATE); } catch (SQLException e) @@ -731,6 +743,55 @@ public class DBHelper { Log.d(TAG,"SQLite exception: " + e.getLocalizedMessage()); } } + +//////////Cipher Access Functions //////////////// + + /** + * Add a package to the list of packages allowed to use the encrypt/decrypt + * cipher services. + * + * @param packageToAdd + * @param expiration set to 0 if no expiration, otherwise epoch time + */ + public void addCipherAccess (String packageToAdd, long expiration) { + ContentValues initialValues = new ContentValues (); + initialValues.put("packagename", packageToAdd); + initialValues.put("expires", expiration); + DateFormat dateFormatter = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, + DateFormat.FULL); + Date today = new Date(); + String dateOut = dateFormatter.format(today); + initialValues.put("dateadded", dateOut); + try { + db.insert(TABLE_CIPHER_ACCESS, null, initialValues); + } catch (SQLException e) { + Log.d(TAG,"SQLite exception: " + e.getLocalizedMessage()); + } + } + + /** + * Fetch the cipher access for a package. This determines if the package + * is allowed to use encrypt/decrypt services. + * + * @param packageName + * @return -1 if not found, 0 if no expiration, otherwise epoch date of expiration + */ + public long fetchCipherAccess(String packageName) { + long expires=-1; // default to not found + try { + Cursor c = db.query(true, TABLE_CIPHER_ACCESS, new String[] {"expires"}, + "packagename="+packageName, null, null, null, null,null); + if(c.getCount() > 0) { + c.moveToFirst(); + expires=c.getLong(0); + } + c.close(); + } catch (SQLException e) + { + Log.d(TAG,"SQLite exception: " + e.getLocalizedMessage()); + } + return expires; + } /** * Begin a transaction on an open database. *