From 11d0f4510b70a0c2b14c2f28b2ab153749dad821 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 30 Sep 2014 02:03:17 +0200 Subject: [PATCH] pass key id for check from EncryptActivity to NfcActivity --- .../sufficientlysecure/keychain/pgp/PgpSignEncrypt.java | 4 +++- .../keychain/service/results/SignEncryptResult.java | 8 +++++++- .../sufficientlysecure/keychain/ui/EncryptActivity.java | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java index c7d6455ab..40e265253 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java @@ -569,7 +569,9 @@ public class PgpSignEncrypt { log.add(LogType.MSG_SE_PENDING_NFC, indent); SignEncryptResult result = new SignEncryptResult(SignEncryptResult.RESULT_PENDING_NFC, log); - result.setNfcData(e.hashToSign, e.hashAlgo, e.creationTimestamp, mSignaturePassphrase); + // Note that the checked key here is the master key, not the signing key + // (although these are always the same on Yubikeys) + result.setNfcData(mSignatureMasterKeyId, e.hashToSign, e.hashAlgo, e.creationTimestamp, mSignaturePassphrase); Log.d(Constants.TAG, "e.hashToSign"+ Hex.toHexString(e.hashToSign)); return result; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java index 0f3c93385..cded70b7f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java @@ -32,6 +32,7 @@ public class SignEncryptResult extends OperationResult { long mKeyIdPassphraseNeeded; + long mNfcKeyId; byte[] mNfcHash; int mNfcAlgo; Date mNfcTimestamp; @@ -45,13 +46,18 @@ public class SignEncryptResult extends OperationResult { mKeyIdPassphraseNeeded = keyIdPassphraseNeeded; } - public void setNfcData(byte[] nfcHash, int nfcAlgo, Date nfcTimestamp, String passphrase) { + public void setNfcData(long nfcKeyId, byte[] nfcHash, int nfcAlgo, Date nfcTimestamp, String passphrase) { + mNfcKeyId = nfcKeyId; mNfcHash = nfcHash; mNfcAlgo = nfcAlgo; mNfcTimestamp = nfcTimestamp; mNfcPassphrase = passphrase; } + public long getNfcKeyId() { + return mNfcKeyId; + } + public byte[] getNfcHash() { return mNfcHash; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java index 58bbcb4f5..5fc047911 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java @@ -30,13 +30,14 @@ public abstract class EncryptActivity extends DrawerActivity { startActivityForResult(intent, REQUEST_CODE_PASSPHRASE); } - protected void startNfcSign(String pin, byte[] hashToSign, int hashAlgo) { + protected void startNfcSign(long keyId, String pin, byte[] hashToSign, int hashAlgo) { // build PendingIntent for Yubikey NFC operations Intent intent = new Intent(this, NfcActivity.class); intent.setAction(NfcActivity.ACTION_SIGN_HASH); // pass params through to activity that it can be returned again later to repeat pgp operation intent.putExtra(NfcActivity.EXTRA_DATA, new Intent()); // not used, only relevant to OpenPgpService + intent.putExtra(NfcActivity.EXTRA_KEY_ID, keyId); intent.putExtra(NfcActivity.EXTRA_PIN, pin); intent.putExtra(NfcActivity.EXTRA_NFC_HASH_TO_SIGN, hashToSign); intent.putExtra(NfcActivity.EXTRA_NFC_HASH_ALGO, hashAlgo); @@ -102,7 +103,7 @@ public abstract class EncryptActivity extends DrawerActivity { SignEncryptResult.RESULT_PENDING_NFC) { mNfcTimestamp = pgpResult.getNfcTimestamp(); - startNfcSign(pgpResult.getNfcPassphrase(), pgpResult.getNfcHash(), pgpResult.getNfcAlgo()); + startNfcSign(pgpResult.getNfcKeyId(), pgpResult.getNfcPassphrase(), pgpResult.getNfcHash(), pgpResult.getNfcAlgo()); } else { throw new RuntimeException("Unhandled pending result!"); }