aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-09-13 17:54:10 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-09-13 17:54:10 +0200
commit4c636a1471ac1013574a3d1446549a652c690b47 (patch)
tree516558a2ef69a535cca365d2478367eb0326cee9 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service
parent19252380f198555a6650654ab5e2e35905b40203 (diff)
downloadopen-keychain-4c636a1471ac1013574a3d1446549a652c690b47.tar.gz
open-keychain-4c636a1471ac1013574a3d1446549a652c690b47.tar.bz2
open-keychain-4c636a1471ac1013574a3d1446549a652c690b47.zip
introduce OperationResultParcel for PgpDecryptVerify operations (WIP)
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java54
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java113
2 files changed, 128 insertions, 39 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
index 92917fa51..2366e0237 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
@@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
-import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult;
+import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult;
import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpImportExport;
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
@@ -337,28 +337,21 @@ public class KeychainIntentService extends IntentService implements Progressable
Bundle resultData = new Bundle();
+ /* TODO find passphrase from cache, if not provided
+ return PassphraseCacheService.getCachedPassphrase(
+ KeychainIntentService.this, masterKeyId);
+ */
+
// verifyText and decrypt returning additional resultData values for the
// verification of signatures
PgpDecryptVerify.Builder builder = new PgpDecryptVerify.Builder(
- new ProviderHelper(this),
- new PgpDecryptVerify.PassphraseCache() {
- @Override
- public String getCachedPassphrase(long masterKeyId) throws PgpDecryptVerify.NoSecretKeyException {
- try {
- return PassphraseCacheService.getCachedPassphrase(
- KeychainIntentService.this, masterKeyId);
- } catch (PassphraseCacheService.KeyNotFoundException e) {
- throw new PgpDecryptVerify.NoSecretKeyException();
- }
- }
- },
- inputData, outStream
+ new ProviderHelper(this), inputData, outStream
);
builder.setProgressable(this)
.setAllowSymmetricDecryption(true)
.setPassphrase(passphrase);
- PgpDecryptVerifyResult decryptVerifyResult = builder.build().execute();
+ DecryptVerifyResult decryptVerifyResult = builder.build().execute();
outStream.close();
@@ -385,29 +378,22 @@ public class KeychainIntentService extends IntentService implements Progressable
Bundle resultData = new Bundle();
+ /* TODO find passphrase from cache, if not provided
+ return PassphraseCacheService.getCachedPassphrase(
+ KeychainIntentService.this, masterKeyId);
+ */
+
// verifyText and decrypt returning additional resultData values for the
// verification of signatures
PgpDecryptVerify.Builder builder = new PgpDecryptVerify.Builder(
- new ProviderHelper(this),
- new PgpDecryptVerify.PassphraseCache() {
- @Override
- public String getCachedPassphrase(long masterKeyId) throws PgpDecryptVerify.NoSecretKeyException {
- try {
- return PassphraseCacheService.getCachedPassphrase(
- KeychainIntentService.this, masterKeyId);
- } catch (PassphraseCacheService.KeyNotFoundException e) {
- throw new PgpDecryptVerify.NoSecretKeyException();
- }
- }
- },
- inputData, null
+ new ProviderHelper(this), inputData, null
);
builder.setProgressable(this)
.setAllowSymmetricDecryption(true)
.setPassphrase(passphrase)
.setDecryptMetadataOnly(true);
- PgpDecryptVerifyResult decryptVerifyResult = builder.build().execute();
+ DecryptVerifyResult decryptVerifyResult = builder.build().execute();
resultData.putParcelable(RESULT_DECRYPT_VERIFY_RESULT, decryptVerifyResult);
@@ -785,16 +771,6 @@ public class KeychainIntentService extends IntentService implements Progressable
message = getString(R.string.error_no_signature_passphrase);
} else if (e instanceof PgpSignEncrypt.NoSigningKeyException) {
message = getString(R.string.error_no_signature_key);
- } else if (e instanceof PgpDecryptVerify.InvalidDataException) {
- message = getString(R.string.error_invalid_data);
- } else if (e instanceof PgpDecryptVerify.KeyExtractionException) {
- message = getString(R.string.error_could_not_extract_private_key);
- } else if (e instanceof PgpDecryptVerify.WrongPassphraseException) {
- message = getString(R.string.error_wrong_passphrase);
- } else if (e instanceof PgpDecryptVerify.NoSecretKeyException) {
- message = getString(R.string.error_no_secret_key_found);
- } else if (e instanceof PgpDecryptVerify.IntegrityCheckFailedException) {
- message = getString(R.string.error_integrity_check_failed);
} else {
message = e.getMessage();
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java
new file mode 100644
index 000000000..909f9f9be
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.sufficientlysecure.keychain.service.results;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import org.openintents.openpgp.OpenPgpMetadata;
+import org.openintents.openpgp.OpenPgpSignatureResult;
+
+public class DecryptVerifyResult extends OperationResultParcel {
+
+ // the fourth bit indicates a "data pending" result!
+ public static final int RESULT_PENDING = 8;
+
+ // fifth to sixth bit in addition indicate specific type of pending
+ public static final int RESULT_PENDING_ASYM_PASSPHRASE = RESULT_PENDING +16;
+ public static final int RESULT_PENDING_SYM_PASSPHRASE = RESULT_PENDING +32;
+ public static final int RESULT_PENDING_NFC = RESULT_PENDING +48;
+
+ long mKeyIdPassphraseNeeded;
+ byte[] mSessionKey;
+
+ OpenPgpSignatureResult mSignatureResult;
+ OpenPgpMetadata mDecryptMetadata;
+
+ public long getKeyIdPassphraseNeeded() {
+ return mKeyIdPassphraseNeeded;
+ }
+
+ public void setKeyIdPassphraseNeeded(long keyIdPassphraseNeeded) {
+ mKeyIdPassphraseNeeded = keyIdPassphraseNeeded;
+ }
+
+ public void setNfcEncryptedSessionKey(byte[] sessionKey) {
+ mSessionKey = sessionKey;
+ }
+
+ public OpenPgpSignatureResult getSignatureResult() {
+ return mSignatureResult;
+ }
+
+ public void setSignatureResult(OpenPgpSignatureResult signatureResult) {
+ mSignatureResult = signatureResult;
+ }
+
+ public OpenPgpMetadata getDecryptMetadata() {
+ return mDecryptMetadata;
+ }
+
+ public void setDecryptMetadata(OpenPgpMetadata decryptMetadata) {
+ mDecryptMetadata = decryptMetadata;
+ }
+
+ public boolean isPending() {
+ return (mResult & RESULT_PENDING) != 0;
+ }
+
+ public DecryptVerifyResult(int result, OperationLog log) {
+ super(result, log);
+ }
+
+ public DecryptVerifyResult(Parcel source) {
+ super(source);
+ mKeyIdPassphraseNeeded = source.readLong();
+ mSignatureResult = source.readParcelable(OpenPgpSignatureResult.class.getClassLoader());
+ mDecryptMetadata = source.readParcelable(OpenPgpMetadata.class.getClassLoader());
+ mSessionKey = source.readInt() != 0 ? source.createByteArray() : null;
+ }
+
+ public int describeContents() {
+ return 0;
+ }
+
+ public void writeToParcel(Parcel dest, int flags) {
+ super.writeToParcel(dest, flags);
+ dest.writeLong(mKeyIdPassphraseNeeded);
+ dest.writeParcelable(mSignatureResult, 0);
+ dest.writeParcelable(mDecryptMetadata, 0);
+ if (mSessionKey != null) {
+ dest.writeInt(1);
+ dest.writeByteArray(mSessionKey);
+ } else {
+ dest.writeInt(0);
+ }
+ }
+
+ public static final Creator<DecryptVerifyResult> CREATOR = new Creator<DecryptVerifyResult>() {
+ public DecryptVerifyResult createFromParcel(final Parcel source) {
+ return new DecryptVerifyResult(source);
+ }
+
+ public DecryptVerifyResult[] newArray(final int size) {
+ return new DecryptVerifyResult[size];
+ }
+ };
+
+}