working version of DecryptVerifyResult

This commit is contained in:
Vincent Breitmoser
2014-09-13 19:30:10 +02:00
parent 4c636a1471
commit dbbefe2f41
6 changed files with 112 additions and 63 deletions

View File

@@ -337,15 +337,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), inputData, outStream
new ProviderHelper(this),
new PgpDecryptVerify.PassphraseCache() {
@Override
public String getCachedPassphrase(long masterKeyId) {
try {
return PassphraseCacheService.getCachedPassphrase(
KeychainIntentService.this, masterKeyId);
} catch (PassphraseCacheService.KeyNotFoundException e) {
return null;
}
}
},
inputData, outStream
);
builder.setProgressable(this)
.setAllowSymmetricDecryption(true)
@@ -378,15 +385,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), inputData, null
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
);
builder.setProgressable(this)
.setAllowSymmetricDecryption(true)

View File

@@ -18,7 +18,6 @@
package org.sufficientlysecure.keychain.service.results;
import android.os.Parcel;
import android.os.Parcelable;
import org.openintents.openpgp.OpenPgpMetadata;
import org.openintents.openpgp.OpenPgpSignatureResult;
@@ -34,7 +33,7 @@ public class DecryptVerifyResult extends OperationResultParcel {
public static final int RESULT_PENDING_NFC = RESULT_PENDING +48;
long mKeyIdPassphraseNeeded;
byte[] mSessionKey;
byte[] mNfcSessionKey;
OpenPgpSignatureResult mSignatureResult;
OpenPgpMetadata mDecryptMetadata;
@@ -48,7 +47,11 @@ public class DecryptVerifyResult extends OperationResultParcel {
}
public void setNfcEncryptedSessionKey(byte[] sessionKey) {
mSessionKey = sessionKey;
mNfcSessionKey = sessionKey;
}
public byte[] getNfcEncryptedSessionKey() {
return mNfcSessionKey;
}
public OpenPgpSignatureResult getSignatureResult() {
@@ -80,7 +83,7 @@ public class DecryptVerifyResult extends OperationResultParcel {
mKeyIdPassphraseNeeded = source.readLong();
mSignatureResult = source.readParcelable(OpenPgpSignatureResult.class.getClassLoader());
mDecryptMetadata = source.readParcelable(OpenPgpMetadata.class.getClassLoader());
mSessionKey = source.readInt() != 0 ? source.createByteArray() : null;
mNfcSessionKey = source.readInt() != 0 ? source.createByteArray() : null;
}
public int describeContents() {
@@ -92,9 +95,9 @@ public class DecryptVerifyResult extends OperationResultParcel {
dest.writeLong(mKeyIdPassphraseNeeded);
dest.writeParcelable(mSignatureResult, 0);
dest.writeParcelable(mDecryptMetadata, 0);
if (mSessionKey != null) {
if (mNfcSessionKey != null) {
dest.writeInt(1);
dest.writeByteArray(mSessionKey);
dest.writeByteArray(mNfcSessionKey);
} else {
dest.writeInt(0);
}