aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-09-14 00:33:19 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-09-14 00:33:30 +0200
commitf0e159a372174db4d0939f8f747a05b62d9b068d (patch)
tree00eb8eb73e04c39d37cac8d15bfc6f4ef08f4206 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java
parent6156600e42407a6a810f3f8b294197de47095f74 (diff)
downloadopen-keychain-f0e159a372174db4d0939f8f747a05b62d9b068d.tar.gz
open-keychain-f0e159a372174db4d0939f8f747a05b62d9b068d.tar.bz2
open-keychain-f0e159a372174db4d0939f8f747a05b62d9b068d.zip
add SignEncryptResult parcel (probably break stuff)
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java81
1 files changed, 44 insertions, 37 deletions
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();