]> hydra-www.ietfng.org Git - android-vcpass-oisafe/commitdiff
OI Safe: added cipher access table, corrected spelling error
authorrmceoin <rmceoin@72b678ce-9140-0410-bee8-679b907dd61a>
Wed, 28 Jan 2009 01:09:36 +0000 (01:09 +0000)
committerrmceoin <rmceoin@72b678ce-9140-0410-bee8-679b907dd61a>
Wed, 28 Jan 2009 01:09:36 +0000 (01:09 +0000)
git-svn-id: http://openintents.googlecode.com/svn/trunk/Safe@1866 72b678ce-9140-0410-bee8-679b907dd61a

res/values/strings.xml
src/org/openintents/safe/DBHelper.java

index 61abaf471fd45860aef993f66687db47179eb51e..332e26ad0957bc57f41a3114b2cb0e8f0ee2b3bc 100644 (file)
        <string name="package_access">Package access</string>\r
        <string name="not_found">not found</string>\r
        <string name="dialog_title_first_time_warning">New master key</string>\r
-       <string name="dialog_summary_first_time_warning">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.</string>\r
+       <string name="dialog_summary_first_time_warning">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.</string>\r
 </resources>
index 276e833870751a2e3561b733df1bc5b239ce6c2a..3ead13a1952cadf367bad11bf1267b96a4a4c689 100644 (file)
@@ -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.
         *