diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-07-15 21:14:53 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-07-15 21:14:53 +0200 |
commit | e4b113701cfd12b89a18365491b50f6508184bc2 (patch) | |
tree | 19672479027e592e23cba851f07a9fe79e3a33f7 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/NfcOperationActivity.java | |
parent | 4cef97be5f4cd75fac252c8d3c739990604000df (diff) | |
parent | 1dafd1b629102180d7e6cb7bb31d1959f1ff6665 (diff) | |
download | open-keychain-e4b113701cfd12b89a18365491b50f6508184bc2.tar.gz open-keychain-e4b113701cfd12b89a18365491b50f6508184bc2.tar.bz2 open-keychain-e4b113701cfd12b89a18365491b50f6508184bc2.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/NfcOperationActivity.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/NfcOperationActivity.java | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/NfcOperationActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/NfcOperationActivity.java index 8802cd621..1584b87ae 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/NfcOperationActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/NfcOperationActivity.java @@ -33,21 +33,25 @@ import org.sufficientlysecure.keychain.util.Preferences; import java.io.IOException; import java.nio.ByteBuffer; import java.util.Arrays; +import java.util.Date; /** * This class provides a communication interface to OpenPGP applications on ISO SmartCard compliant * NFC devices. * <p/> * For the full specs, see http://g10code.com/docs/openpgp-card-2.0.pdf + * NOTE: If no CryptoInputParcel is passed via EXTRA_CRYPTO_INPUT, the CryptoInputParcel is created + * internally and is NOT meant to be used by signing operations before adding signature time */ public class NfcOperationActivity extends BaseNfcActivity { public static final String EXTRA_REQUIRED_INPUT = "required_input"; + public static final String EXTRA_CRYPTO_INPUT = "crypto_input"; // passthrough for OpenPgpService public static final String EXTRA_SERVICE_INTENT = "data"; - public static final String RESULT_DATA = "result_data"; + public static final String RESULT_CRYPTO_INPUT = "result_data"; public ViewAnimator vAnimator; public TextView vErrorText; @@ -67,6 +71,15 @@ public class NfcOperationActivity extends BaseNfcActivity { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + mInputParcel = getIntent().getParcelableExtra(EXTRA_CRYPTO_INPUT); + + if (mInputParcel == null) { + // for compatibility when used from OpenPgpService + // (or any place other than CryptoOperationHelper) + // NOTE: This CryptoInputParcel cannot be used for signing without adding signature time + mInputParcel = new CryptoInputParcel(); + } + setTitle(R.string.nfc_text); vAnimator = (ViewAnimator) findViewById(R.id.view_animator); @@ -112,8 +125,6 @@ public class NfcOperationActivity extends BaseNfcActivity { @Override protected void doNfcInBackground() throws IOException { - mInputParcel = new CryptoInputParcel(mRequiredInput.mSignatureTime); - switch (mRequiredInput.mType) { case NFC_DECRYPT: { for (int i = 0; i < mRequiredInput.mInputData.length; i++) { @@ -124,6 +135,9 @@ public class NfcOperationActivity extends BaseNfcActivity { break; } case NFC_SIGN: { + if (mInputParcel.getSignatureTime() == null) { + mInputParcel.addSignatureTime(new Date()); + } for (int i = 0; i < mRequiredInput.mInputData.length; i++) { byte[] hash = mRequiredInput.mInputData[i]; int algo = mRequiredInput.mSignAlgos[i]; @@ -218,11 +232,16 @@ public class NfcOperationActivity extends BaseNfcActivity { @Override protected void onNfcPostExecute() throws IOException { if (mServiceIntent != null) { + // if we're triggered by OpenPgpService CryptoInputParcelCacheService.addCryptoInputParcel(this, mServiceIntent, mInputParcel); + mServiceIntent.putExtra(EXTRA_CRYPTO_INPUT, + getIntent().getParcelableExtra(EXTRA_CRYPTO_INPUT)); setResult(RESULT_OK, mServiceIntent); } else { Intent result = new Intent(); - result.putExtra(NfcOperationActivity.RESULT_DATA, mInputParcel); + result.putExtra(RESULT_CRYPTO_INPUT, mInputParcel); + // send back the CryptoInputParcel we receive, to conform with the pattern in + // CryptoOperationHelper setResult(RESULT_OK, result); } |