mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-21 05:11:45 -05:00
yubikey: don't assume signing key is masterKeyId in ViewKeyActivity
This commit is contained in:
parent
aa133574b0
commit
5b75b542e8
@ -193,13 +193,19 @@ public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListe
|
|||||||
ImportKeyResult result =
|
ImportKeyResult result =
|
||||||
returnData.getParcelable(DecryptVerifyResult.EXTRA_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();
|
result.createNotify(getActivity()).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent intent = new Intent(getActivity(), ViewKeyActivity.class);
|
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_DISPLAY_RESULT, result);
|
||||||
intent.putExtra(ViewKeyActivity.EXTRA_NFC_AID, mNfcAid);
|
intent.putExtra(ViewKeyActivity.EXTRA_NFC_AID, mNfcAid);
|
||||||
intent.putExtra(ViewKeyActivity.EXTRA_NFC_USER_ID, mNfcUserId);
|
intent.putExtra(ViewKeyActivity.EXTRA_NFC_USER_ID, mNfcUserId);
|
||||||
|
@ -546,14 +546,23 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
|||||||
final String nfcUserId = nfcGetUserId();
|
final String nfcUserId = nfcGetUserId();
|
||||||
final byte[] nfcAid = nfcGetAid();
|
final byte[] nfcAid = nfcGetAid();
|
||||||
|
|
||||||
String fp = KeyFormattingUtils.convertFingerprintToHex(nfcFingerprints);
|
long yubiKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(nfcFingerprints);
|
||||||
final long masterKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(nfcFingerprints);
|
|
||||||
|
|
||||||
if (!mFingerprint.equals(fp)) {
|
|
||||||
try {
|
try {
|
||||||
CachedPublicKeyRing ring = mProviderHelper.getCachedPublicKeyRing(masterKeyId);
|
|
||||||
ring.getMasterKeyId();
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise, offer to go to that key
|
||||||
|
final long masterKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(candidateFp);
|
||||||
Notify.create(this, R.string.snack_yubi_other, Notify.LENGTH_LONG,
|
Notify.create(this, R.string.snack_yubi_other, Notify.LENGTH_LONG,
|
||||||
Style.WARN, new ActionListener() {
|
Style.WARN, new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -568,8 +577,8 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}, R.string.snack_yubikey_view).show();
|
}, R.string.snack_yubikey_view).show();
|
||||||
return;
|
|
||||||
|
|
||||||
|
// and if it's not found, offer import
|
||||||
} catch (PgpKeyNotFoundException e) {
|
} catch (PgpKeyNotFoundException e) {
|
||||||
Notify.create(this, R.string.snack_yubi_other, Notify.LENGTH_LONG,
|
Notify.create(this, R.string.snack_yubi_other, Notify.LENGTH_LONG,
|
||||||
Style.WARN, new ActionListener() {
|
Style.WARN, new ActionListener() {
|
||||||
@ -584,11 +593,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}, R.string.snack_yubikey_import).show();
|
}, R.string.snack_yubikey_import).show();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
showYubiKeyFragment(nfcFingerprints, nfcUserId, nfcAid);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -820,7 +825,8 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
mMasterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
|
mMasterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
|
||||||
mFingerprint = KeyFormattingUtils.convertFingerprintToHex(data.getBlob(INDEX_FINGERPRINT));
|
mFingerprint = KeyFormattingUtils.convertFingerprintToHex(
|
||||||
|
data.getBlob(INDEX_FINGERPRINT));
|
||||||
|
|
||||||
mIsSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0;
|
mIsSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0;
|
||||||
mHasEncrypt = data.getInt(INDEX_HAS_ENCRYPT) != 0;
|
mHasEncrypt = data.getInt(INDEX_HAS_ENCRYPT) != 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user