diff options
author | Adithya Abraham Philip <adithyaphilip@gmail.com> | 2015-02-28 21:57:49 +0530 |
---|---|---|
committer | Adithya Abraham Philip <adithyaphilip@gmail.com> | 2015-02-28 21:57:49 +0530 |
commit | 6a26ea908ef0b62e68fcee93f66807cb69c67c84 (patch) | |
tree | 64efe79d1437e1b769a7ae5c3c6725be7415660c /OpenKeychain/src/main/java/org | |
parent | 94114e35c2af9e264bfa6b3d458f6ceae77ab4f9 (diff) | |
parent | 0557e0680e3cdedc32f8ebe35105b772c7b3935b (diff) | |
download | open-keychain-6a26ea908ef0b62e68fcee93f66807cb69c67c84.tar.gz open-keychain-6a26ea908ef0b62e68fcee93f66807cb69c67c84.tar.bz2 open-keychain-6a26ea908ef0b62e68fcee93f66807cb69c67c84.zip |
Merge branch 'development' of https://github.com/open-keychain/open-keychain into development
Diffstat (limited to 'OpenKeychain/src/main/java/org')
4 files changed, 113 insertions, 37 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java index 4cb6c69e0..94eaa8171 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java @@ -57,6 +57,9 @@ public class ImportKeysProxyActivity extends FragmentActivity { public static final String ACTION_QR_CODE_API = OpenKeychainIntents.IMPORT_KEY_FROM_QR_CODE; public static final String ACTION_SCAN_WITH_RESULT = Constants.INTENT_PREFIX + "SCAN_QR_CODE_WITH_RESULT"; + public static final String ACTION_SCAN_IMPORT = Constants.INTENT_PREFIX + "SCAN_QR_CODE_IMPORT"; + + public static final String EXTRA_FINGERPRINT = "fingerprint"; boolean returnResult; @@ -78,10 +81,15 @@ public class ImportKeysProxyActivity extends FragmentActivity { // Scanning a fingerprint directly with Barcode Scanner, thus we already have scanned returnResult = false; - startCertify(dataUri); + processScannedContent(dataUri); + } else if (ACTION_SCAN_IMPORT.equals(action)) { + returnResult = false; + IntentIntegrator integrator = new IntentIntegrator(this); + integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES) + .setPrompt(getString(R.string.import_qr_code_text)) + .setResultDisplayDuration(0) + .initiateScan(); } else if (ACTION_SCAN_WITH_RESULT.equals(action)) { - // scan using xzing's Barcode Scanner and return result parcel in OpenKeychain - returnResult = true; IntentIntegrator integrator = new IntentIntegrator(this); integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES) @@ -113,16 +121,16 @@ public class ImportKeysProxyActivity extends FragmentActivity { if (requestCode == IntentIntegratorSupportV4.REQUEST_CODE) { IntentResult scanResult = IntentIntegratorSupportV4.parseActivityResult(requestCode, resultCode, data); - if (scanResult != null && scanResult.getFormatName() != null) { - String scannedContent = scanResult.getContents(); - Log.d(Constants.TAG, "scannedContent: " + scannedContent); - startCertify(Uri.parse(scanResult.getContents())); - } else { + if (scanResult == null || scanResult.getFormatName() == null) { Log.e(Constants.TAG, "scanResult or formatName null! Should not happen!"); finish(); + return; } + String scannedContent = scanResult.getContents(); + processScannedContent(scannedContent); + return; } // if a result has been returned, return it down to other activity @@ -134,6 +142,41 @@ public class ImportKeysProxyActivity extends FragmentActivity { } } + private void processScannedContent(String content) { + Uri uri = Uri.parse(content); + processScannedContent(uri); + } + + private void processScannedContent(Uri uri) { + + Log.d(Constants.TAG, "scanned: " + uri.toString()); + + String fingerprint = null; + + // example: openpgp4fpr:73EE2314F65FA92EC2390D3A718C070100012282 + if (uri.getScheme().toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) { + fingerprint = uri.getEncodedSchemeSpecificPart().toLowerCase(Locale.ENGLISH); + } + + if (fingerprint == null) { + SingletonResult result = new SingletonResult( + SingletonResult.RESULT_ERROR, OperationResult.LogType.MSG_WRONG_QR_CODE); + Intent intent = new Intent(); + intent.putExtra(SingletonResult.EXTRA_RESULT, result); + returnResult(intent); + return; + } + + if (returnResult) { + Intent result = new Intent(); + result.putExtra(EXTRA_FINGERPRINT, fingerprint); + setResult(RESULT_OK, result); + finish(); + } else { + importKeys(fingerprint); + } + } + public void returnResult(Intent data) { if (returnResult) { setResult(RESULT_OK, data); @@ -147,20 +190,6 @@ public class ImportKeysProxyActivity extends FragmentActivity { } } - public void startCertify(Uri dataUri) { - // example: openpgp4fpr:73EE2314F65FA92EC2390D3A718C070100012282 - if (dataUri.getScheme().equals(Constants.FINGERPRINT_SCHEME)) { - String fingerprint = dataUri.getEncodedSchemeSpecificPart().toLowerCase(Locale.ENGLISH); - importKeys(fingerprint); - } else { - SingletonResult result = new SingletonResult( - SingletonResult.RESULT_ERROR, OperationResult.LogType.MSG_WRONG_QR_CODE); - Intent intent = new Intent(); - intent.putExtra(SingletonResult.EXTRA_RESULT, result); - returnResult(intent); - } - } - public void importKeys(byte[] keyringData) { ParcelableKeyRing keyEntry = new ParcelableKeyRing(keyringData); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 496048582..b56da463a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -527,7 +527,7 @@ public class KeyListFragment extends LoaderFragment private void scanQrCode() { Intent scanQrCode = new Intent(getActivity(), ImportKeysProxyActivity.class); - scanQrCode.setAction(ImportKeysProxyActivity.ACTION_SCAN_WITH_RESULT); + scanQrCode.setAction(ImportKeysProxyActivity.ACTION_SCAN_IMPORT); startActivityForResult(scanQrCode, 0); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index f7d402c0b..3bc207419 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -88,6 +88,8 @@ import java.util.HashMap; public class ViewKeyActivity extends BaseActivity implements LoaderManager.LoaderCallbacks<Cursor> { + static final int REQUEST_QR_FINGERPRINT = 1; + ExportHelper mExportHelper; ProviderHelper mProviderHelper; @@ -122,6 +124,8 @@ public class ViewKeyActivity extends BaseActivity implements private boolean mIsRefreshing; private Animation mRotate, mRotateSpin; private View mRefresh; + private String mFingerprint; + private long mMasterKeyId; @Override protected void onCreate(Bundle savedInstanceState) { @@ -380,13 +384,24 @@ public class ViewKeyActivity extends BaseActivity implements private void scanQrCode() { Intent scanQrCode = new Intent(this, ImportKeysProxyActivity.class); scanQrCode.setAction(ImportKeysProxyActivity.ACTION_SCAN_WITH_RESULT); - startActivityForResult(scanQrCode, 0); + startActivityForResult(scanQrCode, REQUEST_QR_FINGERPRINT); } private void certifyFingeprint(Uri dataUri) { Intent intent = new Intent(this, CertifyFingerprintActivity.class); intent.setData(dataUri); + startCertifyIntent(intent); + } + + private void certifyImmediate() { + Intent intent = new Intent(this, CertifyKeyActivity.class); + intent.putExtra(CertifyKeyActivity.EXTRA_KEY_IDS, new long[]{ mMasterKeyId }); + + startCertifyIntent(intent); + } + + private void startCertifyIntent (Intent intent) { // Message is received after signing is done in KeychainIntentService KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this) { public void handleMessage(Message message) { @@ -456,7 +471,31 @@ public class ViewKeyActivity extends BaseActivity implements @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - // if a result has been returned, display a notify + if (requestCode == REQUEST_QR_FINGERPRINT && resultCode == Activity.RESULT_OK) { + + // If there is an EXTRA_RESULT, that's an error. Just show it. + if (data.hasExtra(OperationResult.EXTRA_RESULT)) { + OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT); + result.createNotify(this).show(); + return; + } + + String fp = data.getStringExtra(ImportKeysProxyActivity.EXTRA_FINGERPRINT); + if (fp == null) { + Notify.createNotify(this, "Error scanning fingerprint!", + Notify.LENGTH_LONG, Notify.Style.ERROR).show(); + return; + } + if (mFingerprint.equalsIgnoreCase(fp)) { + certifyImmediate(); + } else { + Notify.createNotify(this, "Fingerprints did not match!", + Notify.LENGTH_LONG, Notify.Style.ERROR).show(); + } + + return; + } + if (data != null && data.hasExtra(OperationResult.EXTRA_RESULT)) { OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT); result.createNotify(this).show(); @@ -764,7 +803,8 @@ public class ViewKeyActivity extends BaseActivity implements mName.setText(R.string.user_id_no_name); } - String fingerprint = KeyFormattingUtils.convertFingerprintToHex(data.getBlob(INDEX_FINGERPRINT)); + mMasterKeyId = data.getLong(INDEX_MASTER_KEY_ID); + mFingerprint = KeyFormattingUtils.convertFingerprintToHex(data.getBlob(INDEX_FINGERPRINT)); mIsSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0; mHasEncrypt = data.getInt(INDEX_HAS_ENCRYPT) != 0; @@ -826,8 +866,8 @@ public class ViewKeyActivity extends BaseActivity implements mStatusText.setText(R.string.view_key_my_key); mStatusImage.setVisibility(View.GONE); color = getResources().getColor(R.color.primary); - photoTask.execute(fingerprint); - loadQrCode(fingerprint); + photoTask.execute(mFingerprint); + loadQrCode(mFingerprint); mQrCodeLayout.setVisibility(View.VISIBLE); // and place leftOf qr code @@ -873,7 +913,7 @@ public class ViewKeyActivity extends BaseActivity implements KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, KeyFormattingUtils.STATE_VERIFIED, R.color.icons, true); color = getResources().getColor(R.color.primary); - photoTask.execute(fingerprint); + photoTask.execute(mFingerprint); mFab.setVisibility(View.GONE); } else { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java index 8686b605f..3bc29edb6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java @@ -100,18 +100,25 @@ public class Notify { return createNotify(activity, activity.getString(resId), duration, style, listener, resIdAction); } + public static Showable createNotify(Activity activity, String msg, int duration, Style style) { + return createNotify(activity, msg, duration, style, null, 0); + } + public static Showable createNotify(Activity activity, String msg, int duration, Style style, final ActionListener listener, int resIdAction) { final Snackbar bar = getSnackbar(activity) - .text(msg) - .actionLabel(resIdAction) - .actionListener(new ActionClickListener() { - @Override - public void onActionClicked(Snackbar snackbar) { - listener.onAction(); - } - }); + .text(msg); + + if (listener != null) { + bar.actionLabel(resIdAction); + bar.actionListener(new ActionClickListener() { + @Override + public void onActionClicked(Snackbar snackbar) { + listener.onAction(); + } + }); + } if (duration == LENGTH_INDEFINITE) { bar.duration(SnackbarDuration.LENGTH_INDEFINITE); |