use autovalue for PgpDecryptVerifyInputParcel
This commit is contained in:
parent
76e9f6b229
commit
79af393847
|
@ -103,9 +103,10 @@ public class BenchmarkOperation extends BaseOperation<BenchmarkInputParcel> {
|
||||||
PgpDecryptVerifyOperation op =
|
PgpDecryptVerifyOperation op =
|
||||||
new PgpDecryptVerifyOperation(mContext, mKeyRepository,
|
new PgpDecryptVerifyOperation(mContext, mKeyRepository,
|
||||||
new ProgressScaler(mProgressable, 50 +i*(50/numRepeats), 50 +(i+1)*(50/numRepeats), 100));
|
new ProgressScaler(mProgressable, 50 +i*(50/numRepeats), 50 +(i+1)*(50/numRepeats), 100));
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(encryptResult.getResultBytes());
|
PgpDecryptVerifyInputParcel.Builder builder = PgpDecryptVerifyInputParcel.builder()
|
||||||
input.setAllowSymmetricDecryption(true);
|
.setInputBytes(encryptResult.getResultBytes())
|
||||||
decryptResult = op.execute(input, CryptoInputParcel.createCryptoInputParcel(passphrase));
|
.setAllowSymmetricDecryption(true);
|
||||||
|
decryptResult = op.execute(builder.build(), CryptoInputParcel.createCryptoInputParcel(passphrase));
|
||||||
log.add(decryptResult, 1);
|
log.add(decryptResult, 1);
|
||||||
log.add(LogType.MSG_BENCH_DEC_TIME, 2, String.format("%.2f", decryptResult.mOperationTime / 1000.0));
|
log.add(LogType.MSG_BENCH_DEC_TIME, 2, String.format("%.2f", decryptResult.mOperationTime / 1000.0));
|
||||||
totalTime += decryptResult.mOperationTime;
|
totalTime += decryptResult.mOperationTime;
|
||||||
|
|
|
@ -103,10 +103,12 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
|
||||||
PgpDecryptVerifyOperation op =
|
PgpDecryptVerifyOperation op =
|
||||||
new PgpDecryptVerifyOperation(mContext, mKeyRepository, mProgressable);
|
new PgpDecryptVerifyOperation(mContext, mKeyRepository, mProgressable);
|
||||||
|
|
||||||
decryptInput.setInputUri(input.getInputUri());
|
|
||||||
|
|
||||||
currentInputUri = TemporaryFileProvider.createFile(mContext);
|
currentInputUri = TemporaryFileProvider.createFile(mContext);
|
||||||
decryptInput.setOutputUri(currentInputUri);
|
|
||||||
|
decryptInput = decryptInput.toBuilder()
|
||||||
|
.setInputUri(input.getInputUri())
|
||||||
|
.setOutputUri(currentInputUri)
|
||||||
|
.build();
|
||||||
|
|
||||||
decryptResult = op.execute(decryptInput, cryptoInput);
|
decryptResult = op.execute(decryptInput, cryptoInput);
|
||||||
if (decryptResult.isPending()) {
|
if (decryptResult.isPending()) {
|
||||||
|
@ -264,9 +266,10 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
|
||||||
}
|
}
|
||||||
detachedSig.close();
|
detachedSig.close();
|
||||||
|
|
||||||
PgpDecryptVerifyInputParcel decryptInput = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel decryptInput = PgpDecryptVerifyInputParcel.builder()
|
||||||
decryptInput.setInputUri(uncheckedSignedDataUri);
|
.setInputUri(uncheckedSignedDataUri)
|
||||||
decryptInput.setDetachedSignature(detachedSig.toByteArray());
|
.setDetachedSignature(detachedSig.toByteArray())
|
||||||
|
.build();
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op =
|
PgpDecryptVerifyOperation op =
|
||||||
new PgpDecryptVerifyOperation(mContext, mKeyRepository, mProgressable);
|
new PgpDecryptVerifyOperation(mContext, mKeyRepository, mProgressable);
|
||||||
|
|
|
@ -152,7 +152,9 @@ public class KeybaseVerificationOperation extends BaseOperation<KeybaseVerificat
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(mContext, mKeyRepository, mProgressable);
|
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(mContext, mKeyRepository, mProgressable);
|
||||||
|
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(messageBytes);
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
|
||||||
|
.setInputBytes(messageBytes)
|
||||||
|
.build();
|
||||||
|
|
||||||
DecryptVerifyResult decryptVerifyResult = op.execute(input, CryptoInputParcel.createCryptoInputParcel());
|
DecryptVerifyResult decryptVerifyResult = op.execute(input, CryptoInputParcel.createCryptoInputParcel());
|
||||||
|
|
||||||
|
|
|
@ -19,152 +19,69 @@
|
||||||
package org.sufficientlysecure.keychain.pgp;
|
package org.sufficientlysecure.keychain.pgp;
|
||||||
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
public class PgpDecryptVerifyInputParcel implements Parcelable {
|
import com.google.auto.value.AutoValue;
|
||||||
|
|
||||||
private Uri mInputUri;
|
|
||||||
private Uri mOutputUri;
|
|
||||||
private byte[] mInputBytes;
|
|
||||||
|
|
||||||
private boolean mAllowSymmetricDecryption;
|
@AutoValue
|
||||||
private HashSet<Long> mAllowedKeyIds;
|
public abstract class PgpDecryptVerifyInputParcel implements Parcelable {
|
||||||
private boolean mDecryptMetadataOnly;
|
@Nullable
|
||||||
private byte[] mDetachedSignature;
|
@SuppressWarnings("mutable")
|
||||||
private String mRequiredSignerFingerprint;
|
abstract byte[] getInputBytes();
|
||||||
private String mSenderAddress;
|
|
||||||
|
|
||||||
public PgpDecryptVerifyInputParcel() {
|
@Nullable
|
||||||
|
abstract Uri getInputUri();
|
||||||
|
@Nullable
|
||||||
|
abstract Uri getOutputUri();
|
||||||
|
|
||||||
|
abstract boolean isAllowSymmetricDecryption();
|
||||||
|
abstract boolean isDecryptMetadataOnly();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
abstract List<Long> getAllowedKeyIds();
|
||||||
|
@Nullable
|
||||||
|
@SuppressWarnings("mutable")
|
||||||
|
abstract byte[] getDetachedSignature();
|
||||||
|
@Nullable
|
||||||
|
abstract String getSenderAddress();
|
||||||
|
|
||||||
|
public abstract Builder toBuilder();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_PgpDecryptVerifyInputParcel.Builder()
|
||||||
|
.setAllowSymmetricDecryption(false)
|
||||||
|
.setDecryptMetadataOnly(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PgpDecryptVerifyInputParcel(Uri inputUri, Uri outputUri) {
|
@AutoValue.Builder
|
||||||
mInputUri = inputUri;
|
public abstract static class Builder {
|
||||||
mOutputUri = outputUri;
|
public abstract Builder setInputBytes(byte[] inputBytes);
|
||||||
}
|
public abstract Builder setInputUri(Uri inputUri);
|
||||||
|
public abstract Builder setOutputUri(Uri outputUri);
|
||||||
|
|
||||||
public PgpDecryptVerifyInputParcel(byte[] inputBytes) {
|
public abstract Builder setAllowSymmetricDecryption(boolean allowSymmetricDecryption);
|
||||||
mInputBytes = inputBytes;
|
public abstract Builder setDecryptMetadataOnly(boolean decryptMetadataOnly);
|
||||||
}
|
public abstract Builder setDetachedSignature(byte[] detachedSignature);
|
||||||
|
public abstract Builder setSenderAddress(String senderAddress);
|
||||||
|
|
||||||
PgpDecryptVerifyInputParcel(Parcel source) {
|
public abstract Builder setAllowedKeyIds(List<Long> allowedKeyIds);
|
||||||
// we do all of those here, so the PgpSignEncryptInput class doesn't have to be parcelable
|
abstract List<Long> getAllowedKeyIds();
|
||||||
mInputUri = source.readParcelable(getClass().getClassLoader());
|
|
||||||
mOutputUri = source.readParcelable(getClass().getClassLoader());
|
|
||||||
mInputBytes = source.createByteArray();
|
|
||||||
|
|
||||||
mAllowSymmetricDecryption = source.readInt() != 0;
|
abstract PgpDecryptVerifyInputParcel autoBuild();
|
||||||
mAllowedKeyIds = (HashSet<Long>) source.readSerializable();
|
public PgpDecryptVerifyInputParcel build() {
|
||||||
mDecryptMetadataOnly = source.readInt() != 0;
|
List<Long> allowedKeyIds = getAllowedKeyIds();
|
||||||
mDetachedSignature = source.createByteArray();
|
if (allowedKeyIds != null) {
|
||||||
mRequiredSignerFingerprint = source.readString();
|
setAllowedKeyIds(Collections.unmodifiableList(allowedKeyIds));
|
||||||
}
|
}
|
||||||
|
return autoBuild();
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
dest.writeParcelable(mInputUri, 0);
|
|
||||||
dest.writeParcelable(mOutputUri, 0);
|
|
||||||
dest.writeByteArray(mInputBytes);
|
|
||||||
|
|
||||||
dest.writeInt(mAllowSymmetricDecryption ? 1 : 0);
|
|
||||||
dest.writeSerializable(mAllowedKeyIds);
|
|
||||||
dest.writeInt(mDecryptMetadataOnly ? 1 : 0);
|
|
||||||
dest.writeByteArray(mDetachedSignature);
|
|
||||||
dest.writeString(mRequiredSignerFingerprint);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] getInputBytes() {
|
|
||||||
return mInputBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PgpDecryptVerifyInputParcel setInputUri(Uri uri) {
|
|
||||||
mInputUri = uri;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uri getInputUri() {
|
|
||||||
return mInputUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PgpDecryptVerifyInputParcel setOutputUri(Uri uri) {
|
|
||||||
mOutputUri = uri;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uri getOutputUri() {
|
|
||||||
return mOutputUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isAllowSymmetricDecryption() {
|
|
||||||
return mAllowSymmetricDecryption;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PgpDecryptVerifyInputParcel setAllowSymmetricDecryption(boolean allowSymmetricDecryption) {
|
|
||||||
mAllowSymmetricDecryption = allowSymmetricDecryption;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
HashSet<Long> getAllowedKeyIds() {
|
|
||||||
return mAllowedKeyIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PgpDecryptVerifyInputParcel setAllowedKeyIds(HashSet<Long> allowedKeyIds) {
|
|
||||||
mAllowedKeyIds = allowedKeyIds;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isDecryptMetadataOnly() {
|
|
||||||
return mDecryptMetadataOnly;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PgpDecryptVerifyInputParcel setDecryptMetadataOnly(boolean decryptMetadataOnly) {
|
|
||||||
mDecryptMetadataOnly = decryptMetadataOnly;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] getDetachedSignature() {
|
|
||||||
return mDetachedSignature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PgpDecryptVerifyInputParcel setDetachedSignature(byte[] detachedSignature) {
|
|
||||||
mDetachedSignature = detachedSignature;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PgpDecryptVerifyInputParcel setSenderAddress(String senderAddress) {
|
|
||||||
mSenderAddress = senderAddress;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSenderAddress() {
|
|
||||||
return mSenderAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getRequiredSignerFingerprint() {
|
|
||||||
return mRequiredSignerFingerprint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PgpDecryptVerifyInputParcel setRequiredSignerFingerprint(String requiredSignerFingerprint) {
|
|
||||||
mRequiredSignerFingerprint = requiredSignerFingerprint;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Creator<PgpDecryptVerifyInputParcel> CREATOR = new Creator<PgpDecryptVerifyInputParcel>() {
|
|
||||||
public PgpDecryptVerifyInputParcel createFromParcel(final Parcel source) {
|
|
||||||
return new PgpDecryptVerifyInputParcel(source);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public PgpDecryptVerifyInputParcel[] newArray(final int size) {
|
|
||||||
return new PgpDecryptVerifyInputParcel[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.sufficientlysecure.keychain.remote;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -367,12 +368,13 @@ public class OpenPgpService extends Service {
|
||||||
|
|
||||||
// allow only private keys associated with accounts of this app
|
// allow only private keys associated with accounts of this app
|
||||||
// no support for symmetric encryption
|
// no support for symmetric encryption
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel()
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
|
||||||
.setAllowSymmetricDecryption(false)
|
.setAllowSymmetricDecryption(false)
|
||||||
.setAllowedKeyIds(getAllowedKeyIds())
|
.setAllowedKeyIds(new ArrayList<>(getAllowedKeyIds()))
|
||||||
.setDecryptMetadataOnly(decryptMetadataOnly)
|
.setDecryptMetadataOnly(decryptMetadataOnly)
|
||||||
.setDetachedSignature(detachedSignature)
|
.setDetachedSignature(detachedSignature)
|
||||||
.setSenderAddress(senderAddress);
|
.setSenderAddress(senderAddress)
|
||||||
|
.build();
|
||||||
|
|
||||||
DecryptVerifyResult pgpResult = op.execute(input, cryptoInput, inputData, outputStream);
|
DecryptVerifyResult pgpResult = op.execute(input, cryptoInput, inputData, outputStream);
|
||||||
|
|
||||||
|
|
|
@ -637,9 +637,9 @@ public class DecryptListFragment
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
PgpDecryptVerifyInputParcel decryptInput = new PgpDecryptVerifyInputParcel()
|
PgpDecryptVerifyInputParcel.Builder decryptInput = PgpDecryptVerifyInputParcel.builder()
|
||||||
.setAllowSymmetricDecryption(true);
|
.setAllowSymmetricDecryption(true);
|
||||||
return InputDataParcel.createInputDataParcel(mCurrentInputUri, decryptInput);
|
return InputDataParcel.createInputDataParcel(mCurrentInputUri, decryptInput.build());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -327,8 +327,10 @@ public class BackupOperationTest {
|
||||||
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
||||||
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(outStream.toByteArray());
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
|
||||||
input.setAllowSymmetricDecryption(true);
|
.setAllowSymmetricDecryption(true)
|
||||||
|
.setInputBytes(outStream.toByteArray())
|
||||||
|
.build();
|
||||||
|
|
||||||
{
|
{
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel());
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel());
|
||||||
|
|
|
@ -25,7 +25,6 @@ import java.io.PrintStream;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.apache.tools.ant.util.StringUtils;
|
import org.apache.tools.ant.util.StringUtils;
|
||||||
|
@ -199,8 +198,9 @@ public class PgpEncryptDecryptTest {
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
||||||
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
|
||||||
input.setAllowSymmetricDecryption(true);
|
.setAllowSymmetricDecryption(true)
|
||||||
|
.build();
|
||||||
DecryptVerifyResult result = op.execute(
|
DecryptVerifyResult result = op.execute(
|
||||||
input, CryptoInputParcel.createCryptoInputParcel(mSymmetricPassphrase), data, out);
|
input, CryptoInputParcel.createCryptoInputParcel(mSymmetricPassphrase), data, out);
|
||||||
|
|
||||||
|
@ -229,8 +229,9 @@ public class PgpEncryptDecryptTest {
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
||||||
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
|
||||||
input.setAllowSymmetricDecryption(true);
|
.setAllowSymmetricDecryption(true)
|
||||||
|
.build();
|
||||||
DecryptVerifyResult result = op.execute(input,
|
DecryptVerifyResult result = op.execute(input,
|
||||||
CryptoInputParcel.createCryptoInputParcel(new Passphrase(new String(mSymmetricPassphrase.getCharArray()) + "x")),
|
CryptoInputParcel.createCryptoInputParcel(new Passphrase(new String(mSymmetricPassphrase.getCharArray()) + "x")),
|
||||||
data, out);
|
data, out);
|
||||||
|
@ -251,8 +252,9 @@ public class PgpEncryptDecryptTest {
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
||||||
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
|
||||||
input.setAllowSymmetricDecryption(true);
|
.setAllowSymmetricDecryption(true)
|
||||||
|
.build();
|
||||||
DecryptVerifyResult result = op.execute(input,
|
DecryptVerifyResult result = op.execute(input,
|
||||||
CryptoInputParcel.createCryptoInputParcel(), data, out);
|
CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
|
@ -272,8 +274,7 @@ public class PgpEncryptDecryptTest {
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
||||||
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
input.setAllowSymmetricDecryption(false);
|
|
||||||
DecryptVerifyResult result = op.execute(input,
|
DecryptVerifyResult result = op.execute(input,
|
||||||
CryptoInputParcel.createCryptoInputParcel(), data, out);
|
CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
|
@ -323,7 +324,7 @@ public class PgpEncryptDecryptTest {
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
Assert.assertTrue("verification must succeed", result.success());
|
Assert.assertTrue("verification must succeed", result.success());
|
||||||
|
@ -382,7 +383,7 @@ public class PgpEncryptDecryptTest {
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
Assert.assertTrue("verification must succeed", result.success());
|
Assert.assertTrue("verification must succeed", result.success());
|
||||||
|
@ -438,8 +439,9 @@ public class PgpEncryptDecryptTest {
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
|
||||||
input.setDetachedSignature(detachedSignature);
|
.setDetachedSignature(detachedSignature)
|
||||||
|
.build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
Assert.assertTrue("verification must succeed", result.success());
|
Assert.assertTrue("verification must succeed", result.success());
|
||||||
|
@ -494,7 +496,7 @@ public class PgpEncryptDecryptTest {
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1), data, out);
|
||||||
|
|
||||||
Assert.assertTrue("decryption with provided passphrase must succeed", result.success());
|
Assert.assertTrue("decryption with provided passphrase must succeed", result.success());
|
||||||
|
@ -523,7 +525,7 @@ public class PgpEncryptDecryptTest {
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
||||||
mKeyPhrase1, mStaticRing1.getMasterKeyId(), null);
|
mKeyPhrase1, mStaticRing1.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
CryptoInputParcel cryptoInput = result.getCachedCryptoInputParcel();
|
CryptoInputParcel cryptoInput = result.getCachedCryptoInputParcel();
|
||||||
|
@ -547,7 +549,7 @@ public class PgpEncryptDecryptTest {
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
||||||
null, mStaticRing1.getMasterKeyId(), null);
|
null, mStaticRing1.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
Assert.assertFalse("decryption with no passphrase must return pending", result.success());
|
Assert.assertFalse("decryption with no passphrase must return pending", result.success());
|
||||||
|
@ -628,7 +630,9 @@ public class PgpEncryptDecryptTest {
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
||||||
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext);
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
|
||||||
|
.setInputBytes(ciphertext)
|
||||||
|
.build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1));
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1));
|
||||||
|
|
||||||
Assert.assertTrue("decryption must succeed", result.success());
|
Assert.assertTrue("decryption must succeed", result.success());
|
||||||
|
@ -651,7 +655,9 @@ public class PgpEncryptDecryptTest {
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
||||||
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext);
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
|
||||||
|
.setInputBytes(ciphertext)
|
||||||
|
.build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1));
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1));
|
||||||
|
|
||||||
Assert.assertTrue("decryption must succeed", result.success());
|
Assert.assertTrue("decryption must succeed", result.success());
|
||||||
|
@ -757,7 +763,7 @@ public class PgpEncryptDecryptTest {
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
||||||
mKeyPhrase1, mStaticRing1.getMasterKeyId(), null);
|
mKeyPhrase1, mStaticRing1.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
Assert.assertTrue("decryption with cached passphrase must succeed for the first key", result.success());
|
Assert.assertTrue("decryption with cached passphrase must succeed for the first key", result.success());
|
||||||
|
@ -780,14 +786,15 @@ public class PgpEncryptDecryptTest {
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
// allow only the second to decrypt
|
// allow only the second to decrypt
|
||||||
HashSet<Long> allowed = new HashSet<>();
|
ArrayList<Long> allowed = new ArrayList<>();
|
||||||
allowed.add(mStaticRing2.getMasterKeyId());
|
allowed.add(mStaticRing2.getMasterKeyId());
|
||||||
|
|
||||||
// provide passphrase for the second, and check that the first is never asked for!
|
// provide passphrase for the second, and check that the first is never asked for!
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
||||||
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
|
||||||
input.setAllowedKeyIds(allowed);
|
.setAllowedKeyIds(allowed)
|
||||||
|
.build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
Assert.assertTrue("decryption with cached passphrase must succeed for allowed key", result.success());
|
Assert.assertTrue("decryption with cached passphrase must succeed for allowed key", result.success());
|
||||||
|
@ -809,8 +816,9 @@ public class PgpEncryptDecryptTest {
|
||||||
// provide passphrase for the second, and check that the first is never asked for!
|
// provide passphrase for the second, and check that the first is never asked for!
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
||||||
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder()
|
||||||
input.setAllowedKeyIds(new HashSet<Long>());
|
.setAllowedKeyIds(new ArrayList<Long>())
|
||||||
|
.build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
Assert.assertFalse("decryption must fail if no key allowed", result.success());
|
Assert.assertFalse("decryption must fail if no key allowed", result.success());
|
||||||
|
@ -832,7 +840,7 @@ public class PgpEncryptDecryptTest {
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
||||||
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
Assert.assertTrue("decryption with cached passphrase must succeed", result.success());
|
Assert.assertTrue("decryption with cached passphrase must succeed", result.success());
|
||||||
|
@ -886,7 +894,7 @@ public class PgpEncryptDecryptTest {
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
||||||
mKeyPhrase1, mStaticRing1.getMasterKeyId(), null);
|
mKeyPhrase1, mStaticRing1.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
Assert.assertTrue("decryption with cached passphrase must succeed for the first key", result.success());
|
Assert.assertTrue("decryption with cached passphrase must succeed for the first key", result.success());
|
||||||
|
@ -913,7 +921,7 @@ public class PgpEncryptDecryptTest {
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
||||||
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
Assert.assertTrue("decryption with cached passphrase must succeed", result.success());
|
Assert.assertTrue("decryption with cached passphrase must succeed", result.success());
|
||||||
|
@ -968,7 +976,7 @@ public class PgpEncryptDecryptTest {
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1), data, out);
|
||||||
|
|
||||||
Assert.assertTrue("decryption with provided passphrase must succeed", result.success());
|
Assert.assertTrue("decryption with provided passphrase must succeed", result.success());
|
||||||
|
@ -996,7 +1004,7 @@ public class PgpEncryptDecryptTest {
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1), data, out);
|
||||||
|
|
||||||
|
|
||||||
|
@ -1019,7 +1027,7 @@ public class PgpEncryptDecryptTest {
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1), data, out);
|
||||||
|
|
||||||
|
|
||||||
|
@ -1040,7 +1048,7 @@ public class PgpEncryptDecryptTest {
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ public class InteropTest {
|
||||||
Passphrase pass = new Passphrase(config.getString("passphrase"));
|
Passphrase pass = new Passphrase(config.getString("passphrase"));
|
||||||
|
|
||||||
PgpDecryptVerifyOperation op = makeOperation(base.toString(), pass, decrypt, verify);
|
PgpDecryptVerifyOperation op = makeOperation(base.toString(), pass, decrypt, verify);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = PgpDecryptVerifyInputParcel.builder().build();
|
||||||
CryptoInputParcel cip = CryptoInputParcel.createCryptoInputParcel(pass);
|
CryptoInputParcel cip = CryptoInputParcel.createCryptoInputParcel(pass);
|
||||||
DecryptVerifyResult result = op.execute(input, cip, data, out);
|
DecryptVerifyResult result = op.execute(input, cip, data, out);
|
||||||
byte[] plaintext = config.getString("textcontent").getBytes("utf-8");
|
byte[] plaintext = config.getString("textcontent").getBytes("utf-8");
|
||||||
|
|
Loading…
Reference in a new issue