added revocation and creation/expire time info to key table, use both for public and secret key selection
This commit is contained in:
@@ -69,20 +69,6 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="fill_parent"/>
|
android:layout_height="fill_parent"/>
|
||||||
|
|
||||||
<!-- <TextView
|
|
||||||
android:id="@+id/creation"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:text="31.12.2009"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/expiry"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:text="31.12.2010"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"/> -->
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/status"
|
android:id="@+id/status"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
|||||||
@@ -62,20 +62,6 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="fill_parent"/>
|
android:layout_height="fill_parent"/>
|
||||||
|
|
||||||
<!-- <TextView
|
|
||||||
android:id="@+id/creation"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:text="31.12.2009"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/expiry"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:text="31.12.2010"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"/> -->
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/status"
|
android:id="@+id/status"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
|||||||
@@ -88,11 +88,9 @@ import org.thialfihar.android.apg.ui.widget.UserIdEditor;
|
|||||||
import org.thialfihar.android.apg.utils.IterableIterator;
|
import org.thialfihar.android.apg.utils.IterableIterator;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -318,7 +316,6 @@ public class Apg {
|
|||||||
secretKey = (PGPSecretKey) it.next();
|
secretKey = (PGPSecretKey) it.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return secretKey;
|
return secretKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,6 +451,7 @@ public class Apg {
|
|||||||
hashedPacketsGen.setPreferredHashAlgorithms(true, PREFERRED_HASH_ALGORITHMS);
|
hashedPacketsGen.setPreferredHashAlgorithms(true, PREFERRED_HASH_ALGORITHMS);
|
||||||
hashedPacketsGen.setPreferredCompressionAlgorithms(true, PREFERRED_COMPRESSION_ALGORITHMS);
|
hashedPacketsGen.setPreferredCompressionAlgorithms(true, PREFERRED_COMPRESSION_ALGORITHMS);
|
||||||
|
|
||||||
|
// TODO: this doesn't work quite right yet
|
||||||
if (keyEditor.getExpiryDate() != null) {
|
if (keyEditor.getExpiryDate() != null) {
|
||||||
GregorianCalendar creationDate = new GregorianCalendar();
|
GregorianCalendar creationDate = new GregorianCalendar();
|
||||||
creationDate.setTime(getCreationDate(masterKey));
|
creationDate.setTime(getCreationDate(masterKey));
|
||||||
@@ -505,6 +503,7 @@ public class Apg {
|
|||||||
}
|
}
|
||||||
hashedPacketsGen.setKeyFlags(true, keyFlags);
|
hashedPacketsGen.setKeyFlags(true, keyFlags);
|
||||||
|
|
||||||
|
// TODO: this doesn't work quite right yet
|
||||||
if (keyEditor.getExpiryDate() != null) {
|
if (keyEditor.getExpiryDate() != null) {
|
||||||
GregorianCalendar creationDate = new GregorianCalendar();
|
GregorianCalendar creationDate = new GregorianCalendar();
|
||||||
creationDate.setTime(getCreationDate(masterKey));
|
creationDate.setTime(getCreationDate(masterKey));
|
||||||
@@ -530,36 +529,6 @@ public class Apg {
|
|||||||
progress.setProgress(R.string.progress_done, 100, 100);
|
progress.setProgress(R.string.progress_done, 100, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int saveKeyRing(Activity context, PGPPublicKeyRing keyRing) {
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
|
|
||||||
PGPPublicKey masterKey = getMasterKey(keyRing);
|
|
||||||
if (masterKey == null) {
|
|
||||||
return Id.return_value.no_master_key;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
keyRing.encode(out);
|
|
||||||
out.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
return Id.return_value.error;
|
|
||||||
}
|
|
||||||
|
|
||||||
values.put(PublicKeys.KEY_ID, masterKey.getKeyID());
|
|
||||||
values.put(PublicKeys.KEY_DATA, out.toByteArray());
|
|
||||||
|
|
||||||
Uri uri = Uri.withAppendedPath(PublicKeys.CONTENT_URI_BY_KEY_ID, "" + masterKey.getKeyID());
|
|
||||||
Cursor cursor = context.managedQuery(uri, PUBLIC_KEY_PROJECTION, null, null, null);
|
|
||||||
if (cursor != null && cursor.getCount() > 0) {
|
|
||||||
context.getContentResolver().update(uri, values, null, null);
|
|
||||||
return Id.return_value.updated;
|
|
||||||
} else {
|
|
||||||
context.getContentResolver().insert(PublicKeys.CONTENT_URI, values);
|
|
||||||
return Id.return_value.ok;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Bundle importKeyRings(Activity context, int type, String filename,
|
public static Bundle importKeyRings(Activity context, int type, String filename,
|
||||||
ProgressDialogUpdater progress)
|
ProgressDialogUpdater progress)
|
||||||
throws GeneralException, FileNotFoundException, PGPException, IOException {
|
throws GeneralException, FileNotFoundException, PGPException, IOException {
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.thialfihar.android.apg;
|
package org.thialfihar.android.apg;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import org.thialfihar.android.apg.provider.KeyRings;
|
import org.thialfihar.android.apg.provider.KeyRings;
|
||||||
import org.thialfihar.android.apg.provider.Keys;
|
import org.thialfihar.android.apg.provider.Keys;
|
||||||
import org.thialfihar.android.apg.provider.UserIds;
|
import org.thialfihar.android.apg.provider.UserIds;
|
||||||
@@ -41,6 +43,7 @@ public class SelectPublicKeyListAdapter extends BaseAdapter {
|
|||||||
mParent = parent;
|
mParent = parent;
|
||||||
mDatabase = Apg.getDatabase().db();
|
mDatabase = Apg.getDatabase().db();
|
||||||
mInflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
mInflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
long now = new Date().getTime() / 1000;
|
||||||
mCursor = mDatabase.query(
|
mCursor = mDatabase.query(
|
||||||
KeyRings.TABLE_NAME + " INNER JOIN " + Keys.TABLE_NAME + " ON " +
|
KeyRings.TABLE_NAME + " INNER JOIN " + Keys.TABLE_NAME + " ON " +
|
||||||
"(" + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " +
|
"(" + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " +
|
||||||
@@ -58,7 +61,16 @@ public class SelectPublicKeyListAdapter extends BaseAdapter {
|
|||||||
"(SELECT COUNT(tmp." + Keys._ID + ") FROM " + Keys.TABLE_NAME + " AS tmp WHERE " +
|
"(SELECT COUNT(tmp." + Keys._ID + ") FROM " + Keys.TABLE_NAME + " AS tmp WHERE " +
|
||||||
"tmp." + Keys.KEY_RING_ID + " = " +
|
"tmp." + Keys.KEY_RING_ID + " = " +
|
||||||
KeyRings.TABLE_NAME + "." + KeyRings._ID + " AND " +
|
KeyRings.TABLE_NAME + "." + KeyRings._ID + " AND " +
|
||||||
|
"tmp." + Keys.IS_REVOKED + " = '0' AND " +
|
||||||
"tmp." + Keys.CAN_ENCRYPT + " = '1')", // 3
|
"tmp." + Keys.CAN_ENCRYPT + " = '1')", // 3
|
||||||
|
"(SELECT COUNT(tmp." + Keys._ID + ") FROM " + Keys.TABLE_NAME + " AS tmp WHERE " +
|
||||||
|
"tmp." + Keys.KEY_RING_ID + " = " +
|
||||||
|
KeyRings.TABLE_NAME + "." + KeyRings._ID + " AND " +
|
||||||
|
"tmp." + Keys.IS_REVOKED + " = '0' AND " +
|
||||||
|
"tmp." + Keys.CAN_ENCRYPT + " = '1' AND " +
|
||||||
|
"tmp." + Keys.CREATION + " <= '" + now + "' AND " +
|
||||||
|
"(tmp." + Keys.EXPIRY + " IS NULL OR " +
|
||||||
|
"tmp." + Keys.EXPIRY + " >= '" + now + "'))", // 4
|
||||||
},
|
},
|
||||||
KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?",
|
KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?",
|
||||||
new String[] { "" + Id.database.type_public },
|
new String[] { "" + Id.database.type_public },
|
||||||
@@ -75,7 +87,7 @@ public class SelectPublicKeyListAdapter extends BaseAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int position) {
|
public boolean isEnabled(int position) {
|
||||||
mCursor.moveToPosition(position);
|
mCursor.moveToPosition(position);
|
||||||
return mCursor.getInt(3) > 0; // CAN_ENCRYPT
|
return mCursor.getInt(4) > 0; // valid CAN_ENCRYPT
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -112,10 +124,6 @@ public class SelectPublicKeyListAdapter extends BaseAdapter {
|
|||||||
mainUserIdRest.setText("");
|
mainUserIdRest.setText("");
|
||||||
TextView keyId = (TextView) view.findViewById(R.id.keyId);
|
TextView keyId = (TextView) view.findViewById(R.id.keyId);
|
||||||
keyId.setText(R.string.noKey);
|
keyId.setText(R.string.noKey);
|
||||||
/*TextView creation = (TextView) view.findViewById(R.id.creation);
|
|
||||||
creation.setText(R.string.noDate);
|
|
||||||
TextView expiry = (TextView) view.findViewById(R.id.expiry);
|
|
||||||
expiry.setText(R.string.noExpiry);*/
|
|
||||||
TextView status = (TextView) view.findViewById(R.id.status);
|
TextView status = (TextView) view.findViewById(R.id.status);
|
||||||
status.setText(R.string.unknownStatus);
|
status.setText(R.string.unknownStatus);
|
||||||
|
|
||||||
@@ -136,34 +144,16 @@ public class SelectPublicKeyListAdapter extends BaseAdapter {
|
|||||||
mainUserIdRest.setVisibility(View.GONE);
|
mainUserIdRest.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: must get this functionality in again
|
|
||||||
/*PGPPublicKey timespanKey = key;
|
|
||||||
if (usableKeys.size() > 0) {
|
|
||||||
timespanKey = usableKeys.get(0);
|
|
||||||
status.setText(R.string.canEncrypt);
|
|
||||||
} else if (encryptKeys.size() > 0) {
|
|
||||||
timespanKey = encryptKeys.get(0);
|
|
||||||
Date now = new Date();
|
|
||||||
if (now.compareTo(Apg.getCreationDate(timespanKey)) > 0) {
|
|
||||||
status.setText(R.string.notValid);
|
|
||||||
} else {
|
|
||||||
status.setText(R.string.expired);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
status.setText(R.string.noKey);
|
|
||||||
}*/
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
status.setText(R.string.canEncrypt);
|
status.setText(R.string.canEncrypt);
|
||||||
|
} else {
|
||||||
|
if (mCursor.getInt(3) > 0) {
|
||||||
|
// has some CAN_ENCRYPT keys, but col(4) = 0, so must be revoked or expired
|
||||||
|
status.setText(R.string.expired);
|
||||||
} else {
|
} else {
|
||||||
status.setText(R.string.noKey);
|
status.setText(R.string.noKey);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/*
|
|
||||||
creation.setText(DateFormat.getDateInstance().format(Apg.getCreationDate(timespanKey)));
|
|
||||||
Date expiryDate = Apg.getExpiryDate(timespanKey);
|
|
||||||
if (expiryDate != null) {
|
|
||||||
expiry.setText(DateFormat.getDateInstance().format(expiryDate));
|
|
||||||
}*/
|
|
||||||
|
|
||||||
status.setText(status.getText() + " ");
|
status.setText(status.getText() + " ");
|
||||||
|
|
||||||
@@ -175,8 +165,6 @@ public class SelectPublicKeyListAdapter extends BaseAdapter {
|
|||||||
mainUserId.setEnabled(enabled);
|
mainUserId.setEnabled(enabled);
|
||||||
mainUserIdRest.setEnabled(enabled);
|
mainUserIdRest.setEnabled(enabled);
|
||||||
keyId.setEnabled(enabled);
|
keyId.setEnabled(enabled);
|
||||||
/*creation.setEnabled(enabled);
|
|
||||||
expiry.setEnabled(enabled);*/
|
|
||||||
selected.setEnabled(enabled);
|
selected.setEnabled(enabled);
|
||||||
status.setEnabled(enabled);
|
status.setEnabled(enabled);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.thialfihar.android.apg;
|
package org.thialfihar.android.apg;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import org.thialfihar.android.apg.provider.KeyRings;
|
import org.thialfihar.android.apg.provider.KeyRings;
|
||||||
import org.thialfihar.android.apg.provider.Keys;
|
import org.thialfihar.android.apg.provider.Keys;
|
||||||
import org.thialfihar.android.apg.provider.UserIds;
|
import org.thialfihar.android.apg.provider.UserIds;
|
||||||
@@ -24,6 +26,7 @@ public class SelectSecretKeyListAdapter extends BaseAdapter {
|
|||||||
mParent = parent;
|
mParent = parent;
|
||||||
mDatabase = Apg.getDatabase().db();
|
mDatabase = Apg.getDatabase().db();
|
||||||
mInflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
mInflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
long now = new Date().getTime() / 1000;
|
||||||
mCursor = mDatabase.query(
|
mCursor = mDatabase.query(
|
||||||
KeyRings.TABLE_NAME + " INNER JOIN " + Keys.TABLE_NAME + " ON " +
|
KeyRings.TABLE_NAME + " INNER JOIN " + Keys.TABLE_NAME + " ON " +
|
||||||
"(" + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " +
|
"(" + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " +
|
||||||
@@ -41,7 +44,16 @@ public class SelectSecretKeyListAdapter extends BaseAdapter {
|
|||||||
"(SELECT COUNT(tmp." + Keys._ID + ") FROM " + Keys.TABLE_NAME + " AS tmp WHERE " +
|
"(SELECT COUNT(tmp." + Keys._ID + ") FROM " + Keys.TABLE_NAME + " AS tmp WHERE " +
|
||||||
"tmp." + Keys.KEY_RING_ID + " = " +
|
"tmp." + Keys.KEY_RING_ID + " = " +
|
||||||
KeyRings.TABLE_NAME + "." + KeyRings._ID + " AND " +
|
KeyRings.TABLE_NAME + "." + KeyRings._ID + " AND " +
|
||||||
"tmp." + Keys.CAN_SIGN + " = '1')", // 3
|
"tmp." + Keys.IS_REVOKED + " = '0' AND " +
|
||||||
|
"tmp." + Keys.CAN_SIGN + " = '1')", // 3,
|
||||||
|
"(SELECT COUNT(tmp." + Keys._ID + ") FROM " + Keys.TABLE_NAME + " AS tmp WHERE " +
|
||||||
|
"tmp." + Keys.KEY_RING_ID + " = " +
|
||||||
|
KeyRings.TABLE_NAME + "." + KeyRings._ID + " AND " +
|
||||||
|
"tmp." + Keys.IS_REVOKED + " = '0' AND " +
|
||||||
|
"tmp." + Keys.CAN_SIGN + " = '1' AND " +
|
||||||
|
"tmp." + Keys.CREATION + " <= '" + now + "' AND " +
|
||||||
|
"(tmp." + Keys.EXPIRY + " IS NULL OR " +
|
||||||
|
"tmp." + Keys.EXPIRY + " >= '" + now + "'))", // 4
|
||||||
},
|
},
|
||||||
KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?",
|
KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?",
|
||||||
new String[] { "" + Id.database.type_secret },
|
new String[] { "" + Id.database.type_secret },
|
||||||
@@ -58,7 +70,7 @@ public class SelectSecretKeyListAdapter extends BaseAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int position) {
|
public boolean isEnabled(int position) {
|
||||||
mCursor.moveToPosition(position);
|
mCursor.moveToPosition(position);
|
||||||
return mCursor.getInt(3) > 0; // CAN_SIGN
|
return mCursor.getInt(4) > 0; // valid CAN_SIGN
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -95,10 +107,6 @@ public class SelectSecretKeyListAdapter extends BaseAdapter {
|
|||||||
mainUserIdRest.setText("");
|
mainUserIdRest.setText("");
|
||||||
TextView keyId = (TextView) view.findViewById(R.id.keyId);
|
TextView keyId = (TextView) view.findViewById(R.id.keyId);
|
||||||
keyId.setText(R.string.noKey);
|
keyId.setText(R.string.noKey);
|
||||||
/*TextView creation = (TextView) view.findViewById(R.id.creation);
|
|
||||||
creation.setText(R.string.noDate);
|
|
||||||
TextView expiry = (TextView) view.findViewById(R.id.expiry);
|
|
||||||
expiry.setText(R.string.noExpiry);*/
|
|
||||||
TextView status = (TextView) view.findViewById(R.id.status);
|
TextView status = (TextView) view.findViewById(R.id.status);
|
||||||
status.setText(R.string.unknownStatus);
|
status.setText(R.string.unknownStatus);
|
||||||
|
|
||||||
@@ -119,34 +127,16 @@ public class SelectSecretKeyListAdapter extends BaseAdapter {
|
|||||||
mainUserIdRest.setVisibility(View.GONE);
|
mainUserIdRest.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: must get this functionality in again
|
|
||||||
/*PGPSecretKey timespanKey = key;
|
|
||||||
if (usableKeys.size() > 0) {
|
|
||||||
timespanKey = usableKeys.get(0);
|
|
||||||
status.setText(R.string.canSign);
|
|
||||||
} else if (signingKeys.size() > 0) {
|
|
||||||
timespanKey = signingKeys.get(0);
|
|
||||||
Date now = new Date();
|
|
||||||
if (now.compareTo(Apg.getCreationDate(timespanKey)) > 0) {
|
|
||||||
status.setText(R.string.notValid);
|
|
||||||
} else {
|
|
||||||
status.setText(R.string.expired);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
status.setText(R.string.noKey);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
status.setText(R.string.canSign);
|
status.setText(R.string.canSign);
|
||||||
|
} else {
|
||||||
|
if (mCursor.getInt(3) > 0) {
|
||||||
|
// has some CAN_SIGN keys, but col(4) = 0, so must be revoked or expired
|
||||||
|
status.setText(R.string.expired);
|
||||||
} else {
|
} else {
|
||||||
status.setText(R.string.noKey);
|
status.setText(R.string.noKey);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/*creation.setText(DateFormat.getDateInstance().format(Apg.getCreationDate(timespanKey)));
|
|
||||||
Date expiryDate = Apg.getExpiryDate(timespanKey);
|
|
||||||
if (expiryDate != null) {
|
|
||||||
expiry.setText(DateFormat.getDateInstance().format(expiryDate));
|
|
||||||
}*/
|
|
||||||
|
|
||||||
status.setText(status.getText() + " ");
|
status.setText(status.getText() + " ");
|
||||||
|
|
||||||
@@ -154,8 +144,6 @@ public class SelectSecretKeyListAdapter extends BaseAdapter {
|
|||||||
mainUserId.setEnabled(enabled);
|
mainUserId.setEnabled(enabled);
|
||||||
mainUserIdRest.setEnabled(enabled);
|
mainUserIdRest.setEnabled(enabled);
|
||||||
keyId.setEnabled(enabled);
|
keyId.setEnabled(enabled);
|
||||||
/*creation.setEnabled(enabled);
|
|
||||||
expiry.setEnabled(enabled);*/
|
|
||||||
status.setEnabled(enabled);
|
status.setEnabled(enabled);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ package org.thialfihar.android.apg.provider;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.thialfihar.android.apg.Apg;
|
||||||
|
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
@@ -82,7 +84,9 @@ public class DataProvider extends ContentProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreate() {
|
public boolean onCreate() {
|
||||||
mdbHelper = new Database(getContext());
|
//mdbHelper = new Database(getContext());
|
||||||
|
Apg.initialize(getContext());
|
||||||
|
mdbHelper = Apg.getDatabase();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.thialfihar.android.apg.provider;
|
package org.thialfihar.android.apg.provider;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
@@ -58,6 +59,9 @@ public class Database extends SQLiteOpenHelper {
|
|||||||
sKeysProjection.put(Keys.KEY_SIZE, Keys.KEY_SIZE);
|
sKeysProjection.put(Keys.KEY_SIZE, Keys.KEY_SIZE);
|
||||||
sKeysProjection.put(Keys.CAN_SIGN, Keys.CAN_SIGN);
|
sKeysProjection.put(Keys.CAN_SIGN, Keys.CAN_SIGN);
|
||||||
sKeysProjection.put(Keys.CAN_ENCRYPT, Keys.CAN_ENCRYPT);
|
sKeysProjection.put(Keys.CAN_ENCRYPT, Keys.CAN_ENCRYPT);
|
||||||
|
sKeysProjection.put(Keys.IS_REVOKED, Keys.IS_REVOKED);
|
||||||
|
sKeysProjection.put(Keys.CREATION, Keys.CREATION);
|
||||||
|
sKeysProjection.put(Keys.EXPIRY, Keys.EXPIRY);
|
||||||
sKeysProjection.put(Keys.KEY_DATA, Keys.KEY_DATA);
|
sKeysProjection.put(Keys.KEY_DATA, Keys.KEY_DATA);
|
||||||
sKeysProjection.put(Keys.RANK, Keys.RANK);
|
sKeysProjection.put(Keys.RANK, Keys.RANK);
|
||||||
|
|
||||||
@@ -70,9 +74,9 @@ public class Database extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
public Database(Context context) {
|
public Database(Context context) {
|
||||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
mDb = getWritableDatabase();
|
|
||||||
// force upgrade to test things
|
// force upgrade to test things
|
||||||
//onUpgrade(getWritableDatabase(), 1, 2);
|
//onUpgrade(getWritableDatabase(), 1, 2);
|
||||||
|
mDb = getWritableDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,6 +103,9 @@ public class Database extends SQLiteOpenHelper {
|
|||||||
Keys.KEY_SIZE + " " + Keys.KEY_SIZE_type + ", " +
|
Keys.KEY_SIZE + " " + Keys.KEY_SIZE_type + ", " +
|
||||||
Keys.CAN_SIGN + " " + Keys.CAN_SIGN_type + ", " +
|
Keys.CAN_SIGN + " " + Keys.CAN_SIGN_type + ", " +
|
||||||
Keys.CAN_ENCRYPT + " " + Keys.CAN_ENCRYPT_type + ", " +
|
Keys.CAN_ENCRYPT + " " + Keys.CAN_ENCRYPT_type + ", " +
|
||||||
|
Keys.IS_REVOKED + " " + Keys.IS_REVOKED_type + ", " +
|
||||||
|
Keys.CREATION + " " + Keys.CREATION_type + ", " +
|
||||||
|
Keys.EXPIRY + " " + Keys.EXPIRY_type + ", " +
|
||||||
Keys.KEY_RING_ID + " " + Keys.KEY_RING_ID_type + ", " +
|
Keys.KEY_RING_ID + " " + Keys.KEY_RING_ID_type + ", " +
|
||||||
Keys.KEY_DATA + " " + Keys.KEY_DATA_type +
|
Keys.KEY_DATA + " " + Keys.KEY_DATA_type +
|
||||||
Keys.RANK + " " + Keys.RANK_type + ");");
|
Keys.RANK + " " + Keys.RANK_type + ");");
|
||||||
@@ -140,6 +147,9 @@ public class Database extends SQLiteOpenHelper {
|
|||||||
Keys.KEY_SIZE + " " + Keys.KEY_SIZE_type + ", " +
|
Keys.KEY_SIZE + " " + Keys.KEY_SIZE_type + ", " +
|
||||||
Keys.CAN_SIGN + " " + Keys.CAN_SIGN_type + ", " +
|
Keys.CAN_SIGN + " " + Keys.CAN_SIGN_type + ", " +
|
||||||
Keys.CAN_ENCRYPT + " " + Keys.CAN_ENCRYPT_type + ", " +
|
Keys.CAN_ENCRYPT + " " + Keys.CAN_ENCRYPT_type + ", " +
|
||||||
|
Keys.IS_REVOKED + " " + Keys.IS_REVOKED_type + ", " +
|
||||||
|
Keys.CREATION + " " + Keys.CREATION_type + ", " +
|
||||||
|
Keys.EXPIRY + " " + Keys.EXPIRY_type + ", " +
|
||||||
Keys.KEY_RING_ID + " " + Keys.KEY_RING_ID_type + ", " +
|
Keys.KEY_RING_ID + " " + Keys.KEY_RING_ID_type + ", " +
|
||||||
Keys.KEY_DATA + " " + Keys.KEY_DATA_type +
|
Keys.KEY_DATA + " " + Keys.KEY_DATA_type +
|
||||||
Keys.RANK + " " + Keys.RANK_type + ");");
|
Keys.RANK + " " + Keys.RANK_type + ");");
|
||||||
@@ -239,6 +249,7 @@ public class Database extends SQLiteOpenHelper {
|
|||||||
Keys._ID + " NOT IN (" + seenIdsStr + ")",
|
Keys._ID + " NOT IN (" + seenIdsStr + ")",
|
||||||
new String[] { "" + rowId });
|
new String[] { "" + rowId });
|
||||||
|
|
||||||
|
mDb.setTransactionSuccessful();
|
||||||
mDb.endTransaction();
|
mDb.endTransaction();
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
@@ -279,6 +290,7 @@ public class Database extends SQLiteOpenHelper {
|
|||||||
Keys._ID + " NOT IN (" + seenIdsStr + ")",
|
Keys._ID + " NOT IN (" + seenIdsStr + ")",
|
||||||
new String[] { "" + rowId });
|
new String[] { "" + rowId });
|
||||||
|
|
||||||
|
mDb.setTransactionSuccessful();
|
||||||
mDb.endTransaction();
|
mDb.endTransaction();
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
@@ -294,6 +306,12 @@ public class Database extends SQLiteOpenHelper {
|
|||||||
values.put(Keys.KEY_SIZE, key.getBitStrength());
|
values.put(Keys.KEY_SIZE, key.getBitStrength());
|
||||||
values.put(Keys.CAN_SIGN, Apg.isSigningKey(key));
|
values.put(Keys.CAN_SIGN, Apg.isSigningKey(key));
|
||||||
values.put(Keys.CAN_ENCRYPT, Apg.isEncryptionKey(key));
|
values.put(Keys.CAN_ENCRYPT, Apg.isEncryptionKey(key));
|
||||||
|
values.put(Keys.IS_REVOKED, key.isRevoked());
|
||||||
|
values.put(Keys.CREATION, Apg.getCreationDate(key).getTime() / 1000);
|
||||||
|
Date expiryDate = Apg.getExpiryDate(key);
|
||||||
|
if (expiryDate != null) {
|
||||||
|
values.put(Keys.EXPIRY, expiryDate.getTime() / 1000);
|
||||||
|
}
|
||||||
values.put(Keys.KEY_RING_ID, keyRingId);
|
values.put(Keys.KEY_RING_ID, keyRingId);
|
||||||
values.put(Keys.KEY_DATA, key.getEncoded());
|
values.put(Keys.KEY_DATA, key.getEncoded());
|
||||||
values.put(Keys.RANK, rank);
|
values.put(Keys.RANK, rank);
|
||||||
@@ -337,6 +355,12 @@ public class Database extends SQLiteOpenHelper {
|
|||||||
values.put(Keys.KEY_SIZE, key.getPublicKey().getBitStrength());
|
values.put(Keys.KEY_SIZE, key.getPublicKey().getBitStrength());
|
||||||
values.put(Keys.CAN_SIGN, Apg.isSigningKey(key));
|
values.put(Keys.CAN_SIGN, Apg.isSigningKey(key));
|
||||||
values.put(Keys.CAN_ENCRYPT, Apg.isEncryptionKey(key));
|
values.put(Keys.CAN_ENCRYPT, Apg.isEncryptionKey(key));
|
||||||
|
values.put(Keys.IS_REVOKED, key.getPublicKey().isRevoked());
|
||||||
|
values.put(Keys.CREATION, Apg.getCreationDate(key).getTime() / 1000);
|
||||||
|
Date expiryDate = Apg.getExpiryDate(key);
|
||||||
|
if (expiryDate != null) {
|
||||||
|
values.put(Keys.EXPIRY, expiryDate.getTime() / 1000);
|
||||||
|
}
|
||||||
values.put(Keys.KEY_RING_ID, keyRingId);
|
values.put(Keys.KEY_RING_ID, keyRingId);
|
||||||
values.put(Keys.KEY_DATA, key.getEncoded());
|
values.put(Keys.KEY_DATA, key.getEncoded());
|
||||||
values.put(Keys.RANK, rank);
|
values.put(Keys.RANK, rank);
|
||||||
@@ -539,6 +563,7 @@ public class Database extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
c.close();
|
c.close();
|
||||||
|
|
||||||
|
mDb.setTransactionSuccessful();
|
||||||
mDb.endTransaction();
|
mDb.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,12 @@ public class Keys implements BaseColumns {
|
|||||||
public static final String CAN_SIGN_type = "INTEGER";
|
public static final String CAN_SIGN_type = "INTEGER";
|
||||||
public static final String CAN_ENCRYPT = "c_can_encrypt";
|
public static final String CAN_ENCRYPT = "c_can_encrypt";
|
||||||
public static final String CAN_ENCRYPT_type = "INTEGER";
|
public static final String CAN_ENCRYPT_type = "INTEGER";
|
||||||
|
public static final String IS_REVOKED = "c_is_revoked";
|
||||||
|
public static final String IS_REVOKED_type = "INTEGER";
|
||||||
|
public static final String CREATION = "c_creation";
|
||||||
|
public static final String CREATION_type = "INTEGER";
|
||||||
|
public static final String EXPIRY = "c_expiry";
|
||||||
|
public static final String EXPIRY_type = "INTEGER";
|
||||||
public static final String KEY_RING_ID = "c_key_ring_id";
|
public static final String KEY_RING_ID = "c_key_ring_id";
|
||||||
public static final String KEY_RING_ID_type = "INTEGER";
|
public static final String KEY_RING_ID_type = "INTEGER";
|
||||||
public static final String KEY_DATA = "c_key_data";
|
public static final String KEY_DATA = "c_key_data";
|
||||||
|
|||||||
Reference in New Issue
Block a user