diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-09-20 20:36:37 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-09-20 20:36:37 +0200 |
commit | b06fe773cf043a97f216dc1073a9c428c4d2f2f8 (patch) | |
tree | 8c44bc51210a3f09aeefc5529ee2e09ce52a2c4e /OpenKeychain/src/main/java/org/sufficientlysecure/keychain | |
parent | da4a70c5137d37dab41d1ee65627f38ed78204e9 (diff) | |
download | open-keychain-b06fe773cf043a97f216dc1073a9c428c4d2f2f8.tar.gz open-keychain-b06fe773cf043a97f216dc1073a9c428c4d2f2f8.tar.bz2 open-keychain-b06fe773cf043a97f216dc1073a9c428c4d2f2f8.zip |
New key flags icons, subkey adapter redesign, support authanticate flag in database
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain')
6 files changed, 91 insertions, 29 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java index 9722ae5a2..33f51cbf9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java @@ -43,6 +43,7 @@ public class KeychainContract { String CAN_SIGN = "can_sign"; String CAN_ENCRYPT = "can_encrypt"; String CAN_CERTIFY = "can_certify"; + String CAN_AUTHENTICATE = "can_authenticate"; String IS_REVOKED = "is_revoked"; String HAS_SECRET = "has_secret"; @@ -114,6 +115,7 @@ public class KeychainContract { public static final String HAS_ENCRYPT = "has_encrypt"; public static final String HAS_SIGN = "has_sign"; public static final String HAS_CERTIFY = "has_certify"; + public static final String HAS_AUTHENTICATE = "has_authenticate"; public static final String PUBKEY_DATA = "pubkey_data"; public static final String PRIVKEY_DATA = "privkey_data"; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java index 4d62f67a9..3da288c86 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java @@ -54,7 +54,7 @@ import java.io.IOException; */ public class KeychainDatabase extends SQLiteOpenHelper { private static final String DATABASE_NAME = "openkeychain.db"; - private static final int DATABASE_VERSION = 4; + private static final int DATABASE_VERSION = 5; static Boolean apgHack = false; private Context mContext; @@ -96,6 +96,7 @@ public class KeychainDatabase extends SQLiteOpenHelper { + KeysColumns.CAN_CERTIFY + " BOOLEAN, " + KeysColumns.CAN_SIGN + " BOOLEAN, " + KeysColumns.CAN_ENCRYPT + " BOOLEAN, " + + KeysColumns.CAN_AUTHENTICATE + " BOOLEAN, " + KeysColumns.IS_REVOKED + " BOOLEAN, " + KeysColumns.HAS_SECRET + " BOOLEAN, " @@ -214,21 +215,28 @@ public class KeychainDatabase extends SQLiteOpenHelper { // add has_secret for all who are upgrading from a beta version try { db.execSQL("ALTER TABLE keys ADD COLUMN has_secret BOOLEAN"); - } catch(Exception e){ + } catch (Exception e){ // never mind, the column probably already existed } // fall through case 2: // ECC support try { - db.execSQL("ALTER TABLE keys ADD COLUMN " + KeysColumns.KEY_CURVE_OID + " TEXT"); - } catch(Exception e){ + db.execSQL("ALTER TABLE keys ADD COLUMN key_curve_oid TEXT"); + } catch (Exception e){ // never mind, the column probably already existed } // fall through case 3: // better s2k detection, we need consolidate // fall through + case 4: + try { + db.execSQL("ALTER TABLE keys ADD COLUMN can_authenticate BOOLEAN"); + } catch (Exception e){ + // never mind, the column probably already existed + } + // fall through } // always do consolidate after upgrade diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java index 3cd70df7f..4e63656ec 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java @@ -251,6 +251,7 @@ public class KeychainProvider extends ContentProvider { projectionMap.put(KeyRings.CAN_CERTIFY, Tables.KEYS + "." + Keys.CAN_CERTIFY); projectionMap.put(KeyRings.CAN_ENCRYPT, Tables.KEYS + "." + Keys.CAN_ENCRYPT); projectionMap.put(KeyRings.CAN_SIGN, Tables.KEYS + "." + Keys.CAN_SIGN); + projectionMap.put(KeyRings.CAN_AUTHENTICATE, Tables.KEYS + "." + Keys.CAN_AUTHENTICATE); projectionMap.put(KeyRings.CREATION, Tables.KEYS + "." + Keys.CREATION); projectionMap.put(KeyRings.EXPIRY, Tables.KEYS + "." + Keys.EXPIRY); projectionMap.put(KeyRings.ALGORITHM, Tables.KEYS + "." + Keys.ALGORITHM); @@ -333,6 +334,16 @@ public class KeychainProvider extends ContentProvider { + " AND ( kS." + Keys.EXPIRY + " IS NULL OR kS." + Keys.EXPIRY + " >= " + new Date().getTime() / 1000 + " )" + ")" : "") + + (plist.contains(KeyRings.HAS_AUTHENTICATE) ? + " LEFT JOIN " + Tables.KEYS + " AS kS ON (" + +"kS." + Keys.MASTER_KEY_ID + + " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID + + " AND kS." + Keys.IS_REVOKED + " = 0" + + " AND kS." + Keys.CAN_AUTHENTICATE + " = 1" + + " AND kS." + Keys.HAS_SECRET + " > 1" + + " AND ( kS." + Keys.EXPIRY + " IS NULL OR kS." + Keys.EXPIRY + + " >= " + new Date().getTime() / 1000 + " )" + + ")" : "") + (plist.contains(KeyRings.HAS_CERTIFY) ? " LEFT JOIN " + Tables.KEYS + " AS kC ON (" +"kC." + Keys.MASTER_KEY_ID @@ -424,6 +435,7 @@ public class KeychainProvider extends ContentProvider { projectionMap.put(Keys.CAN_CERTIFY, Keys.CAN_CERTIFY); projectionMap.put(Keys.CAN_ENCRYPT, Keys.CAN_ENCRYPT); projectionMap.put(Keys.CAN_SIGN, Keys.CAN_SIGN); + projectionMap.put(Keys.CAN_AUTHENTICATE, Keys.CAN_AUTHENTICATE); projectionMap.put(Keys.HAS_SECRET, Keys.HAS_SECRET); projectionMap.put(Keys.CREATION, Keys.CREATION); projectionMap.put(Keys.EXPIRY, Keys.EXPIRY); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index 8d790110d..3da685ff6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -356,10 +356,11 @@ public class ProviderHelper { values.put(Keys.ALGORITHM, key.getAlgorithm()); values.put(Keys.FINGERPRINT, key.getFingerprint()); - boolean c = key.canCertify(), e = key.canEncrypt(), s = key.canSign(); + boolean c = key.canCertify(), e = key.canEncrypt(), s = key.canSign(), a = key.canAuthenticate(); values.put(Keys.CAN_CERTIFY, c); values.put(Keys.CAN_ENCRYPT, e); values.put(Keys.CAN_SIGN, s); + values.put(Keys.CAN_AUTHENTICATE, a); values.put(Keys.IS_REVOKED, key.isRevoked()); if (masterKeyId == keyId) { if (c) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java index b377e2cc9..7bbd3eee3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java @@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui.adapter; import android.content.Context; import android.content.res.ColorStateList; import android.database.Cursor; +import android.graphics.PorterDuff; import android.graphics.Typeface; import android.support.v4.widget.CursorAdapter; import android.text.Spannable; @@ -62,6 +63,7 @@ public class SubkeysAdapter extends CursorAdapter { Keys.CAN_CERTIFY, Keys.CAN_ENCRYPT, Keys.CAN_SIGN, + Keys.CAN_AUTHENTICATE, Keys.IS_REVOKED, Keys.CREATION, Keys.EXPIRY, @@ -77,10 +79,11 @@ public class SubkeysAdapter extends CursorAdapter { private static final int INDEX_CAN_CERTIFY = 7; private static final int INDEX_CAN_ENCRYPT = 8; private static final int INDEX_CAN_SIGN = 9; - private static final int INDEX_IS_REVOKED = 10; - private static final int INDEX_CREATION = 11; - private static final int INDEX_EXPIRY = 12; - private static final int INDEX_FINGERPRINT = 13; + private static final int INDEX_CAN_AUTHENTICATE = 10; + private static final int INDEX_IS_REVOKED = 11; + private static final int INDEX_CREATION = 12; + private static final int INDEX_EXPIRY = 13; + private static final int INDEX_FINGERPRINT = 14; public SubkeysAdapter(Context context, Cursor c, int flags, SaveKeyringParcel saveKeyringParcel) { @@ -135,10 +138,11 @@ public class SubkeysAdapter extends CursorAdapter { TextView vKeyDetails = (TextView) view.findViewById(R.id.subkey_item_details); TextView vKeyExpiry = (TextView) view.findViewById(R.id.subkey_item_expiry); ImageView vCertifyIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_certify); - ImageView vEncryptIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_encrypt); ImageView vSignIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_sign); - ImageView vRevokedIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_revoked); + ImageView vEncryptIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_encrypt); + ImageView vAuthenticateIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_authenticate); ImageView vEditImage = (ImageView) view.findViewById(R.id.subkey_item_edit_image); + ImageView vStatus = (ImageView) view.findViewById(R.id.subkey_item_status); // not used: ImageView deleteImage = (ImageView) view.findViewById(R.id.subkey_item_delete_button); @@ -196,7 +200,7 @@ public class SubkeysAdapter extends CursorAdapter { vCertifyIcon.setVisibility(cursor.getInt(INDEX_CAN_CERTIFY) != 0 ? View.VISIBLE : View.GONE); vEncryptIcon.setVisibility(cursor.getInt(INDEX_CAN_ENCRYPT) != 0 ? View.VISIBLE : View.GONE); vSignIcon.setVisibility(cursor.getInt(INDEX_CAN_SIGN) != 0 ? View.VISIBLE : View.GONE); - // TODO: missing icon for authenticate + vAuthenticateIcon.setVisibility(cursor.getInt(INDEX_CAN_AUTHENTICATE) != 0 ? View.VISIBLE : View.GONE); boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0; @@ -245,22 +249,50 @@ public class SubkeysAdapter extends CursorAdapter { vKeyExpiry.setText(context.getString(R.string.label_expiry) + ": " + context.getString(R.string.none)); } - if (isRevoked) { - vRevokedIcon.setVisibility(View.VISIBLE); - } else { - vKeyId.setTextColor(mDefaultTextColor); - vKeyDetails.setTextColor(mDefaultTextColor); - vKeyExpiry.setTextColor(mDefaultTextColor); - - vRevokedIcon.setVisibility(View.GONE); - } - // if key is expired or revoked, strike through text boolean isInvalid = isRevoked || isExpired; if (isInvalid) { + vStatus.setVisibility(View.VISIBLE); + vKeyId.setText(FormattingUtils.strikeOutText(vKeyId.getText())); vKeyDetails.setText(FormattingUtils.strikeOutText(vKeyDetails.getText())); vKeyExpiry.setText(FormattingUtils.strikeOutText(vKeyExpiry.getText())); + + vCertifyIcon.setColorFilter( + mContext.getResources().getColor(R.color.bg_gray), + PorterDuff.Mode.SRC_IN); + vSignIcon.setColorFilter( + mContext.getResources().getColor(R.color.bg_gray), + PorterDuff.Mode.SRC_IN); + vEncryptIcon.setColorFilter( + mContext.getResources().getColor(R.color.bg_gray), + PorterDuff.Mode.SRC_IN); + vAuthenticateIcon.setColorFilter( + mContext.getResources().getColor(R.color.bg_gray), + PorterDuff.Mode.SRC_IN); + + if (isRevoked) { + vStatus.setImageResource(R.drawable.status_signature_revoked_cutout); + vStatus.setColorFilter( + mContext.getResources().getColor(R.color.bg_gray), + PorterDuff.Mode.SRC_IN); + } else if (isExpired) { + vStatus.setImageResource(R.drawable.status_signature_expired_cutout); + vStatus.setColorFilter( + mContext.getResources().getColor(R.color.bg_gray), + PorterDuff.Mode.SRC_IN); + } + } else { + vStatus.setVisibility(View.GONE); + + vKeyId.setTextColor(mDefaultTextColor); + vKeyDetails.setTextColor(mDefaultTextColor); + vKeyExpiry.setTextColor(mDefaultTextColor); + + vCertifyIcon.clearColorFilter(); + vSignIcon.clearColorFilter(); + vEncryptIcon.clearColorFilter(); + vAuthenticateIcon.clearColorFilter(); } vKeyId.setEnabled(!isInvalid); vKeyDetails.setEnabled(!isInvalid); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAddedAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAddedAdapter.java index 009e4c620..a98471122 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAddedAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAddedAdapter.java @@ -53,8 +53,9 @@ public class SubkeysAddedAdapter extends ArrayAdapter<SaveKeyringParcel.SubkeyAd public TextView vKeyDetails; public TextView vKeyExpiry; public ImageView vCertifyIcon; - public ImageView vEncryptIcon; public ImageView vSignIcon; + public ImageView vEncryptIcon; + public ImageView vAuthenticateIcon; public ImageButton vDelete; // also hold a reference to the model item public SaveKeyringParcel.SubkeyAdd mModel; @@ -69,16 +70,18 @@ public class SubkeysAddedAdapter extends ArrayAdapter<SaveKeyringParcel.SubkeyAd holder.vKeyDetails = (TextView) convertView.findViewById(R.id.subkey_item_details); holder.vKeyExpiry = (TextView) convertView.findViewById(R.id.subkey_item_expiry); holder.vCertifyIcon = (ImageView) convertView.findViewById(R.id.subkey_item_ic_certify); - holder.vEncryptIcon = (ImageView) convertView.findViewById(R.id.subkey_item_ic_encrypt); holder.vSignIcon = (ImageView) convertView.findViewById(R.id.subkey_item_ic_sign); + holder.vEncryptIcon = (ImageView) convertView.findViewById(R.id.subkey_item_ic_encrypt); + holder.vAuthenticateIcon = (ImageView) convertView.findViewById(R.id.subkey_item_ic_authenticate); + holder.vDelete = (ImageButton) convertView.findViewById(R.id.subkey_item_delete_button); holder.vDelete.setVisibility(View.VISIBLE); // always visible // not used: - ImageView editImage = (ImageView) convertView.findViewById(R.id.subkey_item_edit_image); - editImage.setVisibility(View.GONE); - ImageView revokedIcon = (ImageView) convertView.findViewById(R.id.subkey_item_ic_revoked); - revokedIcon.setVisibility(View.GONE); + ImageView vEdit = (ImageView) convertView.findViewById(R.id.subkey_item_edit_image); + vEdit.setVisibility(View.GONE); + ImageView vStatus = (ImageView) convertView.findViewById(R.id.subkey_item_status); + vStatus.setVisibility(View.GONE); convertView.setTag(holder); @@ -136,7 +139,11 @@ public class SubkeysAddedAdapter extends ArrayAdapter<SaveKeyringParcel.SubkeyAd } else { holder.vEncryptIcon.setVisibility(View.GONE); } - // TODO: missing icon for authenticate + if ((flags & KeyFlags.AUTHENTICATION) > 0) { + holder.vAuthenticateIcon.setVisibility(View.VISIBLE); + } else { + holder.vAuthenticateIcon.setVisibility(View.GONE); + } return convertView; } |