aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyYubiKeyImportFragment.java10
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java84
2 files changed, 53 insertions, 41 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyYubiKeyImportFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyYubiKeyImportFragment.java
index 4c7d1dfbd..f8d79d33b 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyYubiKeyImportFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyYubiKeyImportFragment.java
@@ -193,13 +193,19 @@ public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListe
ImportKeyResult result =
returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT);
- if (!result.success()) {
+ long[] masterKeyIds = result.getImportedMasterKeyIds();
+
+ // TODO handle masterKeyIds.length != 1...? sorta outlandish scenario
+
+ if (!result.success() || masterKeyIds.length == 0) {
result.createNotify(getActivity()).show();
return;
}
Intent intent = new Intent(getActivity(), ViewKeyActivity.class);
- intent.setData(KeyRings.buildGenericKeyRingUri(mNfcMasterKeyId));
+ // use the imported masterKeyId, not the one from the yubikey, because
+ // that one might* just have been a subkey of the imported key
+ intent.setData(KeyRings.buildGenericKeyRingUri(masterKeyIds[0]));
intent.putExtra(ViewKeyActivity.EXTRA_DISPLAY_RESULT, result);
intent.putExtra(ViewKeyActivity.EXTRA_NFC_AID, mNfcAid);
intent.putExtra(ViewKeyActivity.EXTRA_NFC_USER_ID, mNfcUserId);
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 7d57538b6..8c1d23d68 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
@@ -535,49 +535,54 @@ public class ViewKeyActivity extends BaseNfcActivity implements
final String nfcUserId = nfcGetUserId();
final byte[] nfcAid = nfcGetAid();
- String fp = KeyFormattingUtils.convertFingerprintToHex(nfcFingerprints);
- final long masterKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(nfcFingerprints);
-
- if (!mFingerprint.equals(fp)) {
- try {
- CachedPublicKeyRing ring = mProviderHelper.getCachedPublicKeyRing(masterKeyId);
- ring.getMasterKeyId();
-
- Notify.create(this, R.string.snack_yubi_other, Notify.LENGTH_LONG,
- Style.WARN, new ActionListener() {
- @Override
- public void onAction() {
- Intent intent = new Intent(
- ViewKeyActivity.this, ViewKeyActivity.class);
- intent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId));
- intent.putExtra(ViewKeyActivity.EXTRA_NFC_AID, nfcAid);
- intent.putExtra(ViewKeyActivity.EXTRA_NFC_USER_ID, nfcUserId);
- intent.putExtra(ViewKeyActivity.EXTRA_NFC_FINGERPRINTS, nfcFingerprints);
- startActivity(intent);
- finish();
- }
- }, R.string.snack_yubikey_view).show();
- return;
+ long yubiKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(nfcFingerprints);
+
+ try {
- } catch (PgpKeyNotFoundException e) {
- Notify.create(this, R.string.snack_yubi_other, Notify.LENGTH_LONG,
- Style.WARN, new ActionListener() {
- @Override
- public void onAction() {
- Intent intent = new Intent(
- ViewKeyActivity.this, CreateKeyActivity.class);
- intent.putExtra(ViewKeyActivity.EXTRA_NFC_AID, nfcAid);
- intent.putExtra(ViewKeyActivity.EXTRA_NFC_USER_ID, nfcUserId);
- intent.putExtra(ViewKeyActivity.EXTRA_NFC_FINGERPRINTS, nfcFingerprints);
- startActivity(intent);
- finish();
- }
- }, R.string.snack_yubikey_import).show();
+ // if the yubikey matches a subkey in any key
+ CachedPublicKeyRing ring = mProviderHelper.getCachedPublicKeyRing(
+ KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(yubiKeyId));
+ byte[] candidateFp = ring.getFingerprint();
+
+ // if the master key of that key matches this one, just show the yubikey dialog
+ if (KeyFormattingUtils.convertFingerprintToHex(candidateFp).equals(mFingerprint)) {
+ showYubiKeyFragment(nfcFingerprints, nfcUserId, nfcAid);
return;
}
- }
- showYubiKeyFragment(nfcFingerprints, nfcUserId, nfcAid);
+ // otherwise, offer to go to that key
+ final long masterKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(candidateFp);
+ Notify.create(this, R.string.snack_yubi_other, Notify.LENGTH_LONG,
+ Style.WARN, new ActionListener() {
+ @Override
+ public void onAction() {
+ Intent intent = new Intent(
+ ViewKeyActivity.this, ViewKeyActivity.class);
+ intent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId));
+ intent.putExtra(ViewKeyActivity.EXTRA_NFC_AID, nfcAid);
+ intent.putExtra(ViewKeyActivity.EXTRA_NFC_USER_ID, nfcUserId);
+ intent.putExtra(ViewKeyActivity.EXTRA_NFC_FINGERPRINTS, nfcFingerprints);
+ startActivity(intent);
+ finish();
+ }
+ }, R.string.snack_yubikey_view).show();
+
+ // and if it's not found, offer import
+ } catch (PgpKeyNotFoundException e) {
+ Notify.create(this, R.string.snack_yubi_other, Notify.LENGTH_LONG,
+ Style.WARN, new ActionListener() {
+ @Override
+ public void onAction() {
+ Intent intent = new Intent(
+ ViewKeyActivity.this, CreateKeyActivity.class);
+ intent.putExtra(ViewKeyActivity.EXTRA_NFC_AID, nfcAid);
+ intent.putExtra(ViewKeyActivity.EXTRA_NFC_USER_ID, nfcUserId);
+ intent.putExtra(ViewKeyActivity.EXTRA_NFC_FINGERPRINTS, nfcFingerprints);
+ startActivity(intent);
+ finish();
+ }
+ }, R.string.snack_yubikey_import).show();
+ }
}
@@ -794,6 +799,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements
// old cursor once we return.)
switch (loader.getId()) {
case LOADER_ID_UNIFIED: {
+
if (data.moveToFirst()) {
// get name, email, and comment from USER_ID
KeyRing.UserId mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID));
55 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525