From f0e159a372174db4d0939f8f747a05b62d9b068d Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 14 Sep 2014 00:33:19 +0200 Subject: add SignEncryptResult parcel (probably break stuff) --- .../keychain/remote/OpenPgpService.java | 81 ++++++++++++---------- 1 file changed, 44 insertions(+), 37 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index 205395dbf..29f888a82 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -45,6 +45,8 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.remote.ui.RemoteServiceActivity; import org.sufficientlysecure.keychain.service.PassphraseCacheService; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogEntryParcel; +import org.sufficientlysecure.keychain.service.results.SignEncryptResult; import org.sufficientlysecure.keychain.ui.ImportKeysActivity; import org.sufficientlysecure.keychain.ui.ViewKeyActivity; import org.sufficientlysecure.keychain.util.InputData; @@ -269,25 +271,28 @@ public class OpenPgpService extends RemoteService { // TODO: currently always assume cleartext input, no sign-only of binary currently! builder.setCleartextInput(true); - try { - builder.build().execute(); - - // throw exceptions upwards to client with meaningful messages - } catch (PgpSignEncrypt.KeyExtractionException e) { - throw new Exception(getString(R.string.error_could_not_extract_private_key)); - } catch (PgpSignEncrypt.NoPassphraseException e) { - throw new Exception(getString(R.string.error_no_signature_passphrase)); - } catch (PgpSignEncrypt.WrongPassphraseException e) { - throw new Exception(getString(R.string.error_wrong_passphrase)); - } catch (PgpSignEncrypt.NoSigningKeyException e) { - throw new Exception(getString(R.string.error_no_signature_key)); - } catch (PgpSignEncrypt.NeedNfcDataException e) { - // return PendingIntent to execute NFC activity - // pass through the signature creation timestamp to be used again on second execution - // of PgpSignEncrypt when we have the signed hash! - data.putExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, e.mCreationTimestamp.getTime()); - return getNfcSignIntent(data, passphrase, e.mHashToSign, e.mHashAlgo); + // execute PGP operation! + SignEncryptResult result = builder.build().execute(); + + if (result.isPending()) { + switch (result.getResult()) { + case SignEncryptResult.RESULT_PENDING_NFC: + // return PendingIntent to execute NFC activity + // pass through the signature creation timestamp to be used again on second execution + // of PgpSignEncrypt when we have the signed hash! + data.putExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, result.getNfcTimestamp().getTime()); + return getNfcSignIntent(data, passphrase, result.getNfcHash(), result.getNfcAlgo()); + + default: + throw new Exception("Encountered unhandled pending state - please file a bug report!"); + } } + + if (!result.success()) { + LogEntryParcel errorMsg = result.getLog().getLast(); + throw new Exception(getString(errorMsg.mType.getMsgId())); + } + } finally { is.close(); os.close(); @@ -379,26 +384,28 @@ public class OpenPgpService extends RemoteService { .setNfcState(nfcSignedHash, nfcCreationDate); } - try { - // execute PGP operation! - builder.build().execute(); - - // throw exceptions upwards to client with meaningful messages - } catch (PgpSignEncrypt.KeyExtractionException e) { - throw new Exception(getString(R.string.error_could_not_extract_private_key)); - } catch (PgpSignEncrypt.NoPassphraseException e) { - throw new Exception(getString(R.string.error_no_signature_passphrase)); - } catch (PgpSignEncrypt.WrongPassphraseException e) { - throw new Exception(getString(R.string.error_wrong_passphrase)); - } catch (PgpSignEncrypt.NoSigningKeyException e) { - throw new Exception(getString(R.string.error_no_signature_key)); - } catch (PgpSignEncrypt.NeedNfcDataException e) { - // return PendingIntent to execute NFC activity - // pass through the signature creation timestamp to be used again on second execution - // of PgpSignEncrypt when we have the signed hash! - data.putExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, e.mCreationTimestamp.getTime()); - return getNfcSignIntent(data, passphrase, e.mHashToSign, e.mHashAlgo); + // execute PGP operation! + SignEncryptResult result = builder.build().execute(); + + if (result.isPending()) { + switch (result.getResult()) { + case SignEncryptResult.RESULT_PENDING_NFC: + // return PendingIntent to execute NFC activity + // pass through the signature creation timestamp to be used again on second execution + // of PgpSignEncrypt when we have the signed hash! + data.putExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, result.getNfcTimestamp().getTime()); + return getNfcSignIntent(data, passphrase, result.getNfcHash(), result.getNfcAlgo()); + + default: + throw new Exception("Encountered unhandled pending state - please file a bug report!"); + } } + + if (!result.success()) { + LogEntryParcel errorMsg = result.getLog().getLast(); + throw new Exception(getString(errorMsg.mType.getMsgId())); + } + } finally { is.close(); os.close(); -- cgit v1.2.3