From c4340b2379199e26fc3301527b797c9bf7c79c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sat, 1 Feb 2014 16:34:42 +0100 Subject: [PATCH] No bouncy castle objects in key view --- .../keychain/Constants.java | 3 ++ .../keychain/provider/KeychainProvider.java | 5 ++- .../keychain/provider/ProviderHelper.java | 2 +- .../keychain/ui/ImportKeysActivity.java | 4 +- .../keychain/ui/ImportKeysQrCodeFragment.java | 2 +- .../keychain/ui/ViewKeyActivity.java | 41 +++++++------------ .../ui/dialog/ShareQrCodeDialogFragment.java | 4 +- 7 files changed, 25 insertions(+), 36 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/Constants.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/Constants.java index 74b407cd4..c1809e4e1 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/Constants.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/Constants.java @@ -31,6 +31,9 @@ public final class Constants { // as defined in http://tools.ietf.org/html/rfc3156, section 7 public static final String NFC_MIME = "application/pgp-keys"; + // used by QR Codes (Guardian Project, Monkeysphere compatiblity) + public static final String FINGERPRINT_SCHEME = "openpgp4fpr"; + // Not BC due to the use of Spongy Castle for Android public static final String SC = BouncyCastleProvider.PROVIDER_NAME; public static final String BOUNCY_CASTLE_PROVIDER_NAME = SC; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java index 62fcf4f84..cd3007353 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java @@ -346,7 +346,7 @@ public class KeychainProvider extends ContentProvider { } /** - * Set result of query to specific columns, don't show blob column for external content provider + * Set result of query to specific columns, don't show blob column * * @return */ @@ -367,7 +367,7 @@ public class KeychainProvider extends ContentProvider { } /** - * Set result of query to specific columns, don't show blob column for external content provider + * Set result of query to specific columns, don't show blob column * * @return */ @@ -388,6 +388,7 @@ public class KeychainProvider extends ContentProvider { projectionMap.put(KeysColumns.KEY_RING_ROW_ID, KeysColumns.KEY_RING_ROW_ID); projectionMap.put(KeysColumns.KEY_DATA, KeysColumns.KEY_DATA); projectionMap.put(KeysColumns.RANK, KeysColumns.RANK); + projectionMap.put(KeysColumns.FINGERPRINT, KeysColumns.FINGERPRINT); return projectionMap; } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index a1d7ad511..5e902d344 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -488,7 +488,7 @@ public class ProviderHelper { String[] projection = new String[]{KeyRings.MASTER_KEY_ID}; Cursor cursor = context.getContentResolver().query(queryUri, projection, null, null, null); - long masterKeyId = -1; + long masterKeyId = 0; try { if (cursor != null && cursor.moveToFirst()) { int masterKeyIdCol = cursor.getColumnIndexOrThrow(KeyRings.MASTER_KEY_ID); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index cccbcfa14..26ebc8e79 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -73,8 +73,6 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi // only used by ACTION_IMPORT_KEY_FROM_KEYSERVER public static final String EXTRA_QUERY = "query"; - public static final String FINGERPRINT_SCHEME = "openpgp4fpr"; - protected boolean mDeleteAfterImport = false; // view @@ -135,7 +133,7 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi /** * Scanning a fingerprint directly with Barcode Scanner */ - if (scheme != null && scheme.toLowerCase(Locale.ENGLISH).equals(FINGERPRINT_SCHEME)) { + if (scheme != null && scheme.toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) { getSupportActionBar().setSelectedNavigationItem(0); loadFragment(ImportKeysQrCodeFragment.class, null, mNavigationStrings[0]); loadFromFingerprintUri(dataUri); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java index 9d7d16a42..e714c231d 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java @@ -102,7 +102,7 @@ public class ImportKeysQrCodeFragment extends Fragment { Log.d(Constants.TAG, "scanResult content: " + scanResult.getContents()); // look if it's fingerprint only - if (scanResult.getContents().toLowerCase(Locale.ENGLISH).startsWith(ImportKeysActivity.FINGERPRINT_SCHEME)) { + if (scanResult.getContents().toLowerCase(Locale.ENGLISH).startsWith(Constants.FINGERPRINT_SCHEME)) { importFingerprint(Uri.parse(scanResult.getContents())); return; } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 8bb93e32a..638036701 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -21,8 +21,6 @@ package org.sufficientlysecure.keychain.ui; import java.util.ArrayList; import java.util.Date; -import org.spongycastle.openpgp.PGPPublicKey; -import org.spongycastle.openpgp.PGPPublicKeyRing; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.R; @@ -198,12 +196,9 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements @Override public void onClick(View v) { - // TODO: don't get object here!!! solve this differently! - PGPPublicKeyRing ring = (PGPPublicKeyRing) ProviderHelper.getPGPKeyRing( - ViewKeyActivity.this, mDataUri); - PGPPublicKey publicKey = ring.getPublicKey(); + long keyId = ProviderHelper.getMasterKeyId(ViewKeyActivity.this, mDataUri); - long[] encryptionKeyIds = new long[]{publicKey.getKeyID()}; + long[] encryptionKeyIds = new long[]{keyId}; Intent intent = new Intent(ViewKeyActivity.this, EncryptActivity.class); intent.setAction(EncryptActivity.ACTION_ENCRYPT); intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds); @@ -248,7 +243,7 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements static final String[] KEYS_PROJECTION = new String[]{Keys._ID, Keys.KEY_ID, Keys.IS_MASTER_KEY, Keys.ALGORITHM, Keys.KEY_SIZE, Keys.CAN_CERTIFY, Keys.CAN_SIGN, - Keys.CAN_ENCRYPT, Keys.CREATION, Keys.EXPIRY}; + Keys.CAN_ENCRYPT, Keys.CREATION, Keys.EXPIRY, Keys.FINGERPRINT}; static final String KEYS_SORT_ORDER = Keys.RANK + " ASC"; static final int KEYS_INDEX_ID = 0; static final int KEYS_INDEX_KEY_ID = 1; @@ -260,6 +255,7 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements static final int KEYS_INDEX_CAN_ENCRYPT = 7; static final int KEYS_INDEX_CREATION = 8; static final int KEYS_INDEX_EXPIRY = 9; + static final int KEYS_INDEX_FINGERPRINT = 10; public Loader onCreateLoader(int id, Bundle args) { switch (id) { @@ -348,13 +344,15 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements data.getInt(KEYS_INDEX_ALGORITHM), data.getInt(KEYS_INDEX_KEY_SIZE)); mAlgorithm.setText(algorithmStr); - // TODO: Can this be done better? fingerprint in db? - String fingerprint = PgpKeyHelper.getFingerPrint(this, keyId); + byte[] fingerprintBlob = data.getBlob(KEYS_INDEX_FINGERPRINT); + if (fingerprintBlob == null) { + // FALLBACK for old databases + fingerprintBlob = ProviderHelper.getFingerprint(this, mDataUri); + } + String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, true); fingerprint = fingerprint.replace(" ", "\n"); - mFingerprint.setText(fingerprint); - // TODO: get image with getUserAttributes() on key and then - // PGPUserAttributeSubpacketVector + mFingerprint.setText(fingerprint); } mKeysAdapter.swapCursor(data); @@ -392,13 +390,8 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements } private void updateFromKeyserver(Uri dataUri) { - long updateKeyId = 0; - PGPPublicKeyRing updateRing = (PGPPublicKeyRing) ProviderHelper - .getPGPKeyRing(this, dataUri); + long updateKeyId = ProviderHelper.getMasterKeyId(ViewKeyActivity.this, mDataUri); - if (updateRing != null) { - updateKeyId = PgpKeyHelper.getMasterKey(updateRing).getKeyID(); - } if (updateKeyId == 0) { Log.e(Constants.TAG, "this shouldn't happen. KeyId == 0!"); return; @@ -421,14 +414,10 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements private void shareKey(Uri dataUri, boolean fingerprintOnly) { String content = null; if (fingerprintOnly) { - long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri); + byte[] fingerprintBlob = ProviderHelper.getFingerprint(this, dataUri); + String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, false); - // TODO: dublicated in ShareQrCodeDialog - content = "openpgp4fpr:"; - - String fingerprint = PgpKeyHelper.convertKeyToHex(masterKeyId); - - content = content + fingerprint; + content = Constants.FINGERPRINT_SCHEME + fingerprint; } else { // get public keyring as ascii armored string long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java index 48ed5310b..833f9714d 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java @@ -90,13 +90,11 @@ public class ShareQrCodeDialogFragment extends SherlockDialogFragment { String content = null; if (mFingerprintOnly) { - content = "openpgp4fpr:"; - byte[] fingerprintBlob = ProviderHelper.getFingerprint(getActivity(), dataUri); String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, false); mText.setText(getString(R.string.share_qr_code_dialog_fingerprint_text) + " " + fingerprint); - content = content + fingerprint; + content = Constants.FINGERPRINT_SCHEME + fingerprint; Log.d(Constants.TAG, "content: " + content);