No bouncy castle objects in key view

This commit is contained in:
Dominik Schürmann 2014-02-01 16:34:42 +01:00
parent 5359205b50
commit c4340b2379
7 changed files with 25 additions and 36 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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<Cursor> 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);

View File

@ -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);