use autovalue for CryptoInputParcel
This commit is contained in:
@@ -92,6 +92,7 @@ dependencies {
|
|||||||
provided "com.google.auto.value:auto-value:1.4.1"
|
provided "com.google.auto.value:auto-value:1.4.1"
|
||||||
apt "com.google.auto.value:auto-value:1.4.1"
|
apt "com.google.auto.value:auto-value:1.4.1"
|
||||||
apt "com.ryanharter.auto.value:auto-value-parcel:0.2.5"
|
apt "com.ryanharter.auto.value:auto-value-parcel:0.2.5"
|
||||||
|
compile 'com.ryanharter.auto.value:auto-value-parcel-adapter:0.2.5'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output of ./gradlew -q calculateChecksums
|
// Output of ./gradlew -q calculateChecksums
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ public class ImportKeysListCloudLoader
|
|||||||
mEntryList.clear();
|
mEntryList.clear();
|
||||||
GetKeyResult pendingResult = new GetKeyResult(null,
|
GetKeyResult pendingResult = new GetKeyResult(null,
|
||||||
RequiredInputParcel.createOrbotRequiredOperation(),
|
RequiredInputParcel.createOrbotRequiredOperation(),
|
||||||
new CryptoInputParcel());
|
CryptoInputParcel.createCryptoInputParcel());
|
||||||
mEntryListWrapper = new AsyncTaskResultWrapper<>(mEntryList, pendingResult);
|
mEntryListWrapper = new AsyncTaskResultWrapper<>(mEntryList, pendingResult);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
|
|||||||
outStream = mContext.getContentResolver().openOutputStream(backupInput.mOutputUri);
|
outStream = mContext.getContentResolver().openOutputStream(backupInput.mOutputUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
return signEncryptOperation.execute(inputParcel, new CryptoInputParcel(), inputData, outStream);
|
return signEncryptOperation.execute(inputParcel, CryptoInputParcel.createCryptoInputParcel(), inputData, outStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean exportKeysToStream(OperationLog log, long[] masterKeyIds, boolean exportSecret, OutputStream outStream) {
|
boolean exportKeysToStream(OperationLog log, long[] masterKeyIds, boolean exportSecret, OutputStream outStream) {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class BenchmarkOperation extends BaseOperation<BenchmarkInputParcel> {
|
|||||||
data.setSymmetricEncryptionAlgorithm(OpenKeychainSymmetricKeyAlgorithmTags.AES_128);
|
data.setSymmetricEncryptionAlgorithm(OpenKeychainSymmetricKeyAlgorithmTags.AES_128);
|
||||||
SignEncryptParcel input = new SignEncryptParcel(data.build());
|
SignEncryptParcel input = new SignEncryptParcel(data.build());
|
||||||
input.setBytes(buf);
|
input.setBytes(buf);
|
||||||
encryptResult = op.execute(input, new CryptoInputParcel());
|
encryptResult = op.execute(input, CryptoInputParcel.createCryptoInputParcel());
|
||||||
log.add(encryptResult, 1);
|
log.add(encryptResult, 1);
|
||||||
log.add(LogType.MSG_BENCH_ENC_TIME, 2,
|
log.add(LogType.MSG_BENCH_ENC_TIME, 2,
|
||||||
String.format("%.2f", encryptResult.getResults().get(0).mOperationTime / 1000.0));
|
String.format("%.2f", encryptResult.getResults().get(0).mOperationTime / 1000.0));
|
||||||
@@ -107,7 +107,7 @@ public class BenchmarkOperation extends BaseOperation<BenchmarkInputParcel> {
|
|||||||
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 input = new PgpDecryptVerifyInputParcel(encryptResult.getResultBytes());
|
||||||
input.setAllowSymmetricDecryption(true);
|
input.setAllowSymmetricDecryption(true);
|
||||||
decryptResult = op.execute(input, new CryptoInputParcel(passphrase));
|
decryptResult = op.execute(input, 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;
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ public class KeybaseVerificationOperation extends BaseOperation<KeybaseVerificat
|
|||||||
|
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(messageBytes);
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(messageBytes);
|
||||||
|
|
||||||
DecryptVerifyResult decryptVerifyResult = op.execute(input, new CryptoInputParcel());
|
DecryptVerifyResult decryptVerifyResult = op.execute(input, CryptoInputParcel.createCryptoInputParcel());
|
||||||
|
|
||||||
if (!decryptVerifyResult.success()) {
|
if (!decryptVerifyResult.success()) {
|
||||||
log.add(decryptVerifyResult, 1);
|
log.add(decryptVerifyResult, 1);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class RevokeOperation extends BaseReadWriteOperation<RevokeKeyringParcel>
|
|||||||
CryptoInputParcel cryptoInputParcel) {
|
CryptoInputParcel cryptoInputParcel) {
|
||||||
|
|
||||||
// we don't cache passphrases during revocation
|
// we don't cache passphrases during revocation
|
||||||
cryptoInputParcel.mCachePassphrase = false;
|
cryptoInputParcel = cryptoInputParcel.withNoCachePassphrase();
|
||||||
|
|
||||||
long masterKeyId = revokeKeyringParcel.mMasterKeyId;
|
long masterKeyId = revokeKeyringParcel.mMasterKeyId;
|
||||||
|
|
||||||
|
|||||||
@@ -69,10 +69,9 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.LogTyp
|
|||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||||
import org.sufficientlysecure.keychain.pgp.DecryptVerifySecurityProblem.DecryptVerifySecurityProblemBuilder;
|
import org.sufficientlysecure.keychain.pgp.DecryptVerifySecurityProblem.DecryptVerifySecurityProblemBuilder;
|
||||||
import org.sufficientlysecure.keychain.pgp.SecurityProblem.InsecureBitStrength;
|
import org.sufficientlysecure.keychain.pgp.SecurityProblem.EncryptionAlgorithmProblem;
|
||||||
import org.sufficientlysecure.keychain.pgp.SecurityProblem.KeySecurityProblem;
|
import org.sufficientlysecure.keychain.pgp.SecurityProblem.KeySecurityProblem;
|
||||||
import org.sufficientlysecure.keychain.pgp.SecurityProblem.MissingMdc;
|
import org.sufficientlysecure.keychain.pgp.SecurityProblem.MissingMdc;
|
||||||
import org.sufficientlysecure.keychain.pgp.SecurityProblem.EncryptionAlgorithmProblem;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||||
@@ -321,6 +320,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||||||
decryptionResultBuilder.setEncrypted(true);
|
decryptionResultBuilder.setEncrypted(true);
|
||||||
if (esResult.sessionKey != null && esResult.decryptedSessionKey != null) {
|
if (esResult.sessionKey != null && esResult.decryptedSessionKey != null) {
|
||||||
decryptionResultBuilder.setSessionKey(esResult.sessionKey, esResult.decryptedSessionKey);
|
decryptionResultBuilder.setSessionKey(esResult.sessionKey, esResult.decryptedSessionKey);
|
||||||
|
cryptoInput = cryptoInput.withCryptoData(esResult.sessionKey, esResult.decryptedSessionKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (esResult.encryptionKeySecurityProblem != null) {
|
if (esResult.encryptionKeySecurityProblem != null) {
|
||||||
@@ -820,7 +820,6 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||||||
result.encryptedData = encryptedDataAsymmetric;
|
result.encryptedData = encryptedDataAsymmetric;
|
||||||
|
|
||||||
Map<ByteBuffer, byte[]> cachedSessionKeys = decryptorFactory.getCachedSessionKeys();
|
Map<ByteBuffer, byte[]> cachedSessionKeys = decryptorFactory.getCachedSessionKeys();
|
||||||
cryptoInput.addCryptoData(cachedSessionKeys);
|
|
||||||
if (cachedSessionKeys.size() >= 1) {
|
if (cachedSessionKeys.size() >= 1) {
|
||||||
Entry<ByteBuffer, byte[]> entry = cachedSessionKeys.entrySet().iterator().next();
|
Entry<ByteBuffer, byte[]> entry = cachedSessionKeys.entrySet().iterator().next();
|
||||||
result.sessionKey = entry.getKey().array();
|
result.sessionKey = entry.getKey().array();
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ public class PgpKeyOperation {
|
|||||||
masterSecretKey.getEncoded(), new JcaKeyFingerprintCalculator());
|
masterSecretKey.getEncoded(), new JcaKeyFingerprintCalculator());
|
||||||
|
|
||||||
subProgressPush(50, 100);
|
subProgressPush(50, 100);
|
||||||
CryptoInputParcel cryptoInput = new CryptoInputParcel(creationTime, new Passphrase(""));
|
CryptoInputParcel cryptoInput = CryptoInputParcel.createCryptoInputParcel(creationTime, new Passphrase(""));
|
||||||
return internal(sKR, masterSecretKey, add.mFlags, add.mExpiry, cryptoInput, saveParcel, log, indent);
|
return internal(sKR, masterSecretKey, add.mFlags, add.mExpiry, cryptoInput, saveParcel, log, indent);
|
||||||
|
|
||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
* Copyright (C) 2014 Vincent Breitmoser <v.breitmoser@mugenguild.com>
|
* Copyright (C) 2017 Vincent Breitmoser <v.breitmoser@mugenguild.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -154,12 +154,12 @@ public class OpenPgpService extends Service {
|
|||||||
|
|
||||||
CryptoInputParcel inputParcel = CryptoInputParcelCacheService.getCryptoInputParcel(this, data);
|
CryptoInputParcel inputParcel = CryptoInputParcelCacheService.getCryptoInputParcel(this, data);
|
||||||
if (inputParcel == null) {
|
if (inputParcel == null) {
|
||||||
inputParcel = new CryptoInputParcel(new Date());
|
inputParcel = CryptoInputParcel.createCryptoInputParcel(new Date());
|
||||||
}
|
}
|
||||||
// override passphrase in input parcel if given by API call
|
// override passphrase in input parcel if given by API call
|
||||||
if (data.hasExtra(OpenPgpApi.EXTRA_PASSPHRASE)) {
|
if (data.hasExtra(OpenPgpApi.EXTRA_PASSPHRASE)) {
|
||||||
inputParcel.mPassphrase =
|
inputParcel = inputParcel.withPassphrase(
|
||||||
new Passphrase(data.getCharArrayExtra(OpenPgpApi.EXTRA_PASSPHRASE));
|
new Passphrase(data.getCharArrayExtra(OpenPgpApi.EXTRA_PASSPHRASE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute PGP operation!
|
// execute PGP operation!
|
||||||
@@ -265,11 +265,12 @@ public class OpenPgpService extends Service {
|
|||||||
|
|
||||||
CryptoInputParcel inputParcel = CryptoInputParcelCacheService.getCryptoInputParcel(this, data);
|
CryptoInputParcel inputParcel = CryptoInputParcelCacheService.getCryptoInputParcel(this, data);
|
||||||
if (inputParcel == null) {
|
if (inputParcel == null) {
|
||||||
inputParcel = new CryptoInputParcel(new Date());
|
inputParcel = CryptoInputParcel.createCryptoInputParcel(new Date());
|
||||||
}
|
}
|
||||||
// override passphrase in input parcel if given by API call
|
// override passphrase in input parcel if given by API call
|
||||||
if (data.hasExtra(OpenPgpApi.EXTRA_PASSPHRASE)) {
|
if (data.hasExtra(OpenPgpApi.EXTRA_PASSPHRASE)) {
|
||||||
inputParcel.mPassphrase = new Passphrase(data.getCharArrayExtra(OpenPgpApi.EXTRA_PASSPHRASE));
|
inputParcel = inputParcel.withPassphrase(
|
||||||
|
new Passphrase(data.getCharArrayExtra(OpenPgpApi.EXTRA_PASSPHRASE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this is not correct!
|
// TODO this is not correct!
|
||||||
@@ -352,17 +353,18 @@ public class OpenPgpService extends Service {
|
|||||||
|
|
||||||
CryptoInputParcel cryptoInput = CryptoInputParcelCacheService.getCryptoInputParcel(this, data);
|
CryptoInputParcel cryptoInput = CryptoInputParcelCacheService.getCryptoInputParcel(this, data);
|
||||||
if (cryptoInput == null) {
|
if (cryptoInput == null) {
|
||||||
cryptoInput = new CryptoInputParcel();
|
cryptoInput = CryptoInputParcel.createCryptoInputParcel();
|
||||||
}
|
}
|
||||||
// override passphrase in input parcel if given by API call
|
// override passphrase in input parcel if given by API call
|
||||||
if (data.hasExtra(OpenPgpApi.EXTRA_PASSPHRASE)) {
|
if (data.hasExtra(OpenPgpApi.EXTRA_PASSPHRASE)) {
|
||||||
cryptoInput.mPassphrase =
|
cryptoInput = cryptoInput.withPassphrase(
|
||||||
new Passphrase(data.getCharArrayExtra(OpenPgpApi.EXTRA_PASSPHRASE));
|
new Passphrase(data.getCharArrayExtra(OpenPgpApi.EXTRA_PASSPHRASE)));
|
||||||
}
|
}
|
||||||
if (data.hasExtra(OpenPgpApi.EXTRA_DECRYPTION_RESULT)) {
|
if (data.hasExtra(OpenPgpApi.EXTRA_DECRYPTION_RESULT)) {
|
||||||
OpenPgpDecryptionResult decryptionResult = data.getParcelableExtra(OpenPgpApi.EXTRA_DECRYPTION_RESULT);
|
OpenPgpDecryptionResult decryptionResult = data.getParcelableExtra(OpenPgpApi.EXTRA_DECRYPTION_RESULT);
|
||||||
if (decryptionResult != null && decryptionResult.hasDecryptedSessionKey()) {
|
if (decryptionResult != null && decryptionResult.hasDecryptedSessionKey()) {
|
||||||
cryptoInput.addCryptoData(decryptionResult.getSessionKey(), decryptionResult.getDecryptedSessionKey());
|
cryptoInput = cryptoInput.withCryptoData(
|
||||||
|
decryptionResult.getSessionKey(), decryptionResult.getDecryptedSessionKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
}
|
}
|
||||||
case ACTION_UPDATE_ALL: {
|
case ACTION_UPDATE_ALL: {
|
||||||
// does not check for screen on/off
|
// does not check for screen on/off
|
||||||
asyncKeyUpdate(this, new CryptoInputParcel(), startId);
|
asyncKeyUpdate(this, CryptoInputParcel.createCryptoInputParcel(), startId);
|
||||||
// we depend on handleUpdateResult to call stopSelf when it is no longer necessary
|
// we depend on handleUpdateResult to call stopSelf when it is no longer necessary
|
||||||
// for the intent to be redelivered
|
// for the intent to be redelivered
|
||||||
return START_REDELIVER_INTENT;
|
return START_REDELIVER_INTENT;
|
||||||
@@ -118,7 +118,7 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
case ACTION_IGNORE_TOR: {
|
case ACTION_IGNORE_TOR: {
|
||||||
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT);
|
manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT);
|
||||||
asyncKeyUpdate(this, new CryptoInputParcel(ParcelableProxy.getForNoProxy()),
|
asyncKeyUpdate(this, CryptoInputParcel.createCryptoInputParcel(ParcelableProxy.getForNoProxy()),
|
||||||
startId);
|
startId);
|
||||||
// we depend on handleUpdateResult to call stopSelf when it is no longer necessary
|
// we depend on handleUpdateResult to call stopSelf when it is no longer necessary
|
||||||
// for the intent to be redelivered
|
// for the intent to be redelivered
|
||||||
|
|||||||
@@ -19,181 +19,128 @@ package org.sufficientlysecure.keychain.service.input;
|
|||||||
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.support.annotation.CheckResult;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoValue;
|
||||||
|
import com.ryanharter.auto.value.parcel.ParcelAdapter;
|
||||||
|
import org.sufficientlysecure.keychain.util.ByteMapParcelAdapter;
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
|
||||||
/**
|
@AutoValue
|
||||||
* This is a base class for the input of crypto operations.
|
public abstract class CryptoInputParcel implements Parcelable {
|
||||||
*/
|
@Nullable
|
||||||
public class CryptoInputParcel implements Parcelable {
|
public abstract Date getSignatureTime();
|
||||||
|
@Nullable
|
||||||
|
public abstract Passphrase getPassphrase();
|
||||||
|
public abstract boolean isCachePassphrase();
|
||||||
|
|
||||||
private Date mSignatureTime;
|
public boolean hasPassphrase() {
|
||||||
private boolean mHasSignature;
|
return getPassphrase() != null;
|
||||||
|
}
|
||||||
|
|
||||||
public Passphrase mPassphrase;
|
|
||||||
// used to supply an explicit proxy to operations that require it
|
// used to supply an explicit proxy to operations that require it
|
||||||
// this is not final so it can be added to an existing CryptoInputParcel
|
// this is not final so it can be added to an existing CryptoInputParcel
|
||||||
// (e.g) CertifyOperation with upload might require both passphrase and orbot to be enabled
|
// (e.g) CertifyOperation with upload might require both passphrase and orbot to be enabled
|
||||||
private ParcelableProxy mParcelableProxy;
|
@Nullable
|
||||||
|
public abstract ParcelableProxy getParcelableProxy();
|
||||||
// specifies whether passphrases should be cached
|
|
||||||
public boolean mCachePassphrase = true;
|
|
||||||
|
|
||||||
// this map contains both decrypted session keys and signed hashes to be
|
// this map contains both decrypted session keys and signed hashes to be
|
||||||
// used in the crypto operation described by this parcel.
|
// used in the crypto operation described by this parcel.
|
||||||
private HashMap<ByteBuffer, byte[]> mCryptoData = new HashMap<>();
|
@ParcelAdapter(ByteMapParcelAdapter.class)
|
||||||
|
public abstract Map<ByteBuffer, byte[]> getCryptoData();
|
||||||
|
|
||||||
public CryptoInputParcel() {
|
|
||||||
mSignatureTime = null;
|
public static CryptoInputParcel createCryptoInputParcel() {
|
||||||
mPassphrase = null;
|
return new AutoValue_CryptoInputParcel(null, null, true, null, Collections.<ByteBuffer,byte[]>emptyMap());
|
||||||
mCachePassphrase = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CryptoInputParcel(Date signatureTime, Passphrase passphrase) {
|
public static CryptoInputParcel createCryptoInputParcel(Date signatureTime, Passphrase passphrase) {
|
||||||
mHasSignature = true;
|
if (signatureTime == null) {
|
||||||
mSignatureTime = signatureTime == null ? new Date() : signatureTime;
|
signatureTime = new Date();
|
||||||
mPassphrase = passphrase;
|
}
|
||||||
mCachePassphrase = true;
|
return new AutoValue_CryptoInputParcel(signatureTime, passphrase, true, null,
|
||||||
|
Collections.<ByteBuffer,byte[]>emptyMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CryptoInputParcel(Passphrase passphrase) {
|
public static CryptoInputParcel createCryptoInputParcel(Passphrase passphrase) {
|
||||||
mPassphrase = passphrase;
|
return new AutoValue_CryptoInputParcel(null, passphrase, true, null, Collections.<ByteBuffer,byte[]>emptyMap());
|
||||||
mCachePassphrase = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CryptoInputParcel(Date signatureTime) {
|
public static CryptoInputParcel createCryptoInputParcel(Date signatureTime) {
|
||||||
mHasSignature = true;
|
if (signatureTime == null) {
|
||||||
mSignatureTime = signatureTime == null ? new Date() : signatureTime;
|
signatureTime = new Date();
|
||||||
mPassphrase = null;
|
}
|
||||||
mCachePassphrase = true;
|
return new AutoValue_CryptoInputParcel(signatureTime, null, true, null,
|
||||||
|
Collections.<ByteBuffer,byte[]>emptyMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CryptoInputParcel(ParcelableProxy parcelableProxy) {
|
public static CryptoInputParcel createCryptoInputParcel(ParcelableProxy parcelableProxy) {
|
||||||
this();
|
return new AutoValue_CryptoInputParcel(null, null, true, parcelableProxy, new HashMap<ByteBuffer,byte[]>());
|
||||||
mParcelableProxy = parcelableProxy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CryptoInputParcel(Date signatureTime, boolean cachePassphrase) {
|
public static CryptoInputParcel createCryptoInputParcel(Date signatureTime, boolean cachePassphrase) {
|
||||||
mHasSignature = true;
|
if (signatureTime == null) {
|
||||||
mSignatureTime = signatureTime == null ? new Date() : signatureTime;
|
signatureTime = new Date();
|
||||||
mPassphrase = null;
|
}
|
||||||
mCachePassphrase = cachePassphrase;
|
return new AutoValue_CryptoInputParcel(signatureTime, null, cachePassphrase, null,
|
||||||
|
new HashMap<ByteBuffer,byte[]>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CryptoInputParcel(boolean cachePassphrase) {
|
public static CryptoInputParcel createCryptoInputParcel(boolean cachePassphrase) {
|
||||||
mCachePassphrase = cachePassphrase;
|
return new AutoValue_CryptoInputParcel(null, null, cachePassphrase, null, new HashMap<ByteBuffer,byte[]>());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CryptoInputParcel(Parcel source) {
|
// TODO get rid of this!
|
||||||
mHasSignature = source.readByte() != 0;
|
@CheckResult
|
||||||
if (mHasSignature) {
|
public CryptoInputParcel withCryptoData(byte[] hash, byte[] signedHash) {
|
||||||
mSignatureTime = new Date(source.readLong());
|
Map<ByteBuffer,byte[]> newCryptoData = new HashMap<>(getCryptoData());
|
||||||
}
|
newCryptoData.put(ByteBuffer.wrap(hash), signedHash);
|
||||||
mPassphrase = source.readParcelable(getClass().getClassLoader());
|
newCryptoData = Collections.unmodifiableMap(newCryptoData);
|
||||||
mParcelableProxy = source.readParcelable(getClass().getClassLoader());
|
|
||||||
mCachePassphrase = source.readByte() != 0;
|
|
||||||
|
|
||||||
{
|
return new AutoValue_CryptoInputParcel(getSignatureTime(), getPassphrase(), isCachePassphrase(),
|
||||||
int count = source.readInt();
|
getParcelableProxy(), newCryptoData);
|
||||||
mCryptoData = new HashMap<>(count);
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
byte[] key = source.createByteArray();
|
|
||||||
byte[] value = source.createByteArray();
|
|
||||||
mCryptoData.put(ByteBuffer.wrap(key), value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CheckResult
|
||||||
|
public CryptoInputParcel withCryptoData(Map<ByteBuffer, byte[]> cachedSessionKeys) {
|
||||||
|
Map<ByteBuffer,byte[]> newCryptoData = new HashMap<>(getCryptoData());
|
||||||
|
newCryptoData.putAll(cachedSessionKeys);
|
||||||
|
newCryptoData = Collections.unmodifiableMap(newCryptoData);
|
||||||
|
|
||||||
|
return new AutoValue_CryptoInputParcel(getSignatureTime(), getPassphrase(), isCachePassphrase(),
|
||||||
|
getParcelableProxy(), newCryptoData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
@CheckResult
|
||||||
return 0;
|
public CryptoInputParcel withPassphrase(Passphrase passphrase) {
|
||||||
|
return new AutoValue_CryptoInputParcel(getSignatureTime(), passphrase, isCachePassphrase(),
|
||||||
|
getParcelableProxy(), getCryptoData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@CheckResult
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public CryptoInputParcel withNoCachePassphrase() {
|
||||||
dest.writeByte((byte) (mHasSignature ? 1 : 0));
|
return new AutoValue_CryptoInputParcel(getSignatureTime(), getPassphrase(), false, getParcelableProxy(),
|
||||||
if (mHasSignature) {
|
getCryptoData());
|
||||||
dest.writeLong(mSignatureTime.getTime());
|
|
||||||
}
|
|
||||||
dest.writeParcelable(mPassphrase, 0);
|
|
||||||
dest.writeParcelable(mParcelableProxy, 0);
|
|
||||||
dest.writeByte((byte) (mCachePassphrase ? 1 : 0));
|
|
||||||
|
|
||||||
dest.writeInt(mCryptoData.size());
|
|
||||||
for (HashMap.Entry<ByteBuffer, byte[]> entry : mCryptoData.entrySet()) {
|
|
||||||
dest.writeByteArray(entry.getKey().array());
|
|
||||||
dest.writeByteArray(entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addParcelableProxy(ParcelableProxy parcelableProxy) {
|
@CheckResult
|
||||||
mParcelableProxy = parcelableProxy;
|
public CryptoInputParcel withSignatureTime(Date signatureTime) {
|
||||||
|
return new AutoValue_CryptoInputParcel(signatureTime, getPassphrase(), isCachePassphrase(),
|
||||||
|
getParcelableProxy(), getCryptoData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSignatureTime(Date signatureTime) {
|
@CheckResult
|
||||||
mSignatureTime = signatureTime;
|
public CryptoInputParcel withParcelableProxy(ParcelableProxy parcelableProxy) {
|
||||||
|
return new AutoValue_CryptoInputParcel(getSignatureTime(), getPassphrase(), isCachePassphrase(),
|
||||||
|
parcelableProxy, getCryptoData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCryptoData(byte[] hash, byte[] signedHash) {
|
|
||||||
mCryptoData.put(ByteBuffer.wrap(hash), signedHash);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addCryptoData(Map<ByteBuffer, byte[]> cachedSessionKeys) {
|
|
||||||
mCryptoData.putAll(cachedSessionKeys);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParcelableProxy getParcelableProxy() {
|
|
||||||
return mParcelableProxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<ByteBuffer, byte[]> getCryptoData() {
|
|
||||||
return mCryptoData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getSignatureTime() {
|
|
||||||
return mSignatureTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasPassphrase() {
|
|
||||||
return mPassphrase != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Passphrase getPassphrase() {
|
|
||||||
return mPassphrase;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Creator<CryptoInputParcel> CREATOR = new Creator<CryptoInputParcel>() {
|
|
||||||
public CryptoInputParcel createFromParcel(final Parcel source) {
|
|
||||||
return new CryptoInputParcel(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CryptoInputParcel[] newArray(final int size) {
|
|
||||||
return new CryptoInputParcel[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder b = new StringBuilder();
|
|
||||||
b.append("CryptoInput: { ");
|
|
||||||
b.append(mSignatureTime).append(" ");
|
|
||||||
if (mPassphrase != null) {
|
|
||||||
b.append("passphrase");
|
|
||||||
}
|
|
||||||
if (mCryptoData != null) {
|
|
||||||
b.append(mCryptoData.size());
|
|
||||||
b.append(" hashes ");
|
|
||||||
}
|
|
||||||
b.append("}");
|
|
||||||
return b.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -523,7 +523,8 @@ public class BackupCodeFragment extends CryptoOperationFragment<BackupKeyringPar
|
|||||||
|
|
||||||
// if we don't want to execute the actual operation outside of this activity, drop out here
|
// if we don't want to execute the actual operation outside of this activity, drop out here
|
||||||
if (!mExecuteBackupOperation) {
|
if (!mExecuteBackupOperation) {
|
||||||
((BackupActivity) getActivity()).handleBackupOperation(new CryptoInputParcel(passphrase));
|
((BackupActivity) getActivity()).handleBackupOperation(
|
||||||
|
CryptoInputParcel.createCryptoInputParcel(passphrase));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -531,7 +532,7 @@ public class BackupCodeFragment extends CryptoOperationFragment<BackupKeyringPar
|
|||||||
mCachedBackupUri = TemporaryFileProvider.createFile(activity, filename,
|
mCachedBackupUri = TemporaryFileProvider.createFile(activity, filename,
|
||||||
Constants.MIME_TYPE_ENCRYPTED_ALTERNATE);
|
Constants.MIME_TYPE_ENCRYPTED_ALTERNATE);
|
||||||
|
|
||||||
cryptoOperation(new CryptoInputParcel(passphrase));
|
cryptoOperation(CryptoInputParcel.createCryptoInputParcel(passphrase));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public class CertifyKeyFragment
|
|||||||
Notify.create(getActivity(), getString(R.string.select_key_to_certify),
|
Notify.create(getActivity(), getString(R.string.select_key_to_certify),
|
||||||
Notify.Style.ERROR).show();
|
Notify.Style.ERROR).show();
|
||||||
} else {
|
} else {
|
||||||
cryptoOperation(new CryptoInputParcel(new Date()));
|
cryptoOperation(CryptoInputParcel.createCryptoInputParcel(new Date()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -499,7 +499,7 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
|
|
||||||
|
|
||||||
mMoveToCardOpHelper = new CryptoOperationHelper<>(2, this, callback, R.string.progress_modify);
|
mMoveToCardOpHelper = new CryptoOperationHelper<>(2, this, callback, R.string.progress_modify);
|
||||||
mMoveToCardOpHelper.cryptoOperation(new CryptoInputParcel(new Date()));
|
mMoveToCardOpHelper.cryptoOperation(CryptoInputParcel.createCryptoInputParcel(new Date()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uploadKey(final EditKeyResult saveKeyResult) {
|
private void uploadKey(final EditKeyResult saveKeyResult) {
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ public class CreateSecurityTokenImportResetFragment
|
|||||||
Intent intent = new Intent(getActivity(), SecurityTokenOperationActivity.class);
|
Intent intent = new Intent(getActivity(), SecurityTokenOperationActivity.class);
|
||||||
RequiredInputParcel resetP = RequiredInputParcel.createSecurityTokenReset();
|
RequiredInputParcel resetP = RequiredInputParcel.createSecurityTokenReset();
|
||||||
intent.putExtra(SecurityTokenOperationActivity.EXTRA_REQUIRED_INPUT, resetP);
|
intent.putExtra(SecurityTokenOperationActivity.EXTRA_REQUIRED_INPUT, resetP);
|
||||||
intent.putExtra(SecurityTokenOperationActivity.EXTRA_CRYPTO_INPUT, new CryptoInputParcel());
|
intent.putExtra(SecurityTokenOperationActivity.EXTRA_CRYPTO_INPUT, CryptoInputParcel.createCryptoInputParcel());
|
||||||
startActivityForResult(intent, REQUEST_CODE_RESET);
|
startActivityForResult(intent, REQUEST_CODE_RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startRevocationOperation() {
|
private void startRevocationOperation() {
|
||||||
mRevokeOpHelper.cryptoOperation(new CryptoInputParcel(new Date(), false));
|
mRevokeOpHelper.cryptoOperation(CryptoInputParcel.createCryptoInputParcel(new Date(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startDeletionOperation() {
|
private void startDeletionOperation() {
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ public class EditKeyFragment extends QueueingCryptoOperationFragment<SaveKeyring
|
|||||||
if (mDataUri == null) {
|
if (mDataUri == null) {
|
||||||
returnKeyringParcel();
|
returnKeyringParcel();
|
||||||
} else {
|
} else {
|
||||||
cryptoOperation(new CryptoInputParcel(new Date()));
|
cryptoOperation(CryptoInputParcel.createCryptoInputParcel(new Date()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, new OnClickListener() {
|
}, new OnClickListener() {
|
||||||
|
|||||||
@@ -345,19 +345,19 @@ public class EncryptFilesFragment
|
|||||||
case R.id.encrypt_save: {
|
case R.id.encrypt_save: {
|
||||||
hideKeyboard();
|
hideKeyboard();
|
||||||
mAfterEncryptAction = AfterEncryptAction.SAVE;
|
mAfterEncryptAction = AfterEncryptAction.SAVE;
|
||||||
cryptoOperation(new CryptoInputParcel(new Date()));
|
cryptoOperation(CryptoInputParcel.createCryptoInputParcel(new Date()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case R.id.encrypt_share: {
|
case R.id.encrypt_share: {
|
||||||
hideKeyboard();
|
hideKeyboard();
|
||||||
mAfterEncryptAction = AfterEncryptAction.SHARE;
|
mAfterEncryptAction = AfterEncryptAction.SHARE;
|
||||||
cryptoOperation(new CryptoInputParcel(new Date()));
|
cryptoOperation(CryptoInputParcel.createCryptoInputParcel(new Date()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case R.id.encrypt_copy: {
|
case R.id.encrypt_copy: {
|
||||||
hideKeyboard();
|
hideKeyboard();
|
||||||
mAfterEncryptAction = AfterEncryptAction.COPY;
|
mAfterEncryptAction = AfterEncryptAction.COPY;
|
||||||
cryptoOperation(new CryptoInputParcel(new Date()));
|
cryptoOperation(CryptoInputParcel.createCryptoInputParcel(new Date()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case R.id.check_use_armor: {
|
case R.id.check_use_armor: {
|
||||||
@@ -733,7 +733,7 @@ public class EncryptFilesFragment
|
|||||||
mOutputUris.add(data.getData());
|
mOutputUris.add(data.getData());
|
||||||
// make sure this is correct at this point
|
// make sure this is correct at this point
|
||||||
mAfterEncryptAction = AfterEncryptAction.SAVE;
|
mAfterEncryptAction = AfterEncryptAction.SAVE;
|
||||||
cryptoOperation(new CryptoInputParcel(new Date()));
|
cryptoOperation(CryptoInputParcel.createCryptoInputParcel(new Date()));
|
||||||
} else if (resultCode == Activity.RESULT_CANCELED) {
|
} else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
onCryptoOperationCancelled();
|
onCryptoOperationCancelled();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,18 +181,18 @@ public class EncryptTextFragment
|
|||||||
case R.id.encrypt_copy: {
|
case R.id.encrypt_copy: {
|
||||||
hideKeyboard();
|
hideKeyboard();
|
||||||
mShareAfterEncrypt = false;
|
mShareAfterEncrypt = false;
|
||||||
cryptoOperation(new CryptoInputParcel(new Date()));
|
cryptoOperation(CryptoInputParcel.createCryptoInputParcel(new Date()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case R.id.encrypt_share: {
|
case R.id.encrypt_share: {
|
||||||
hideKeyboard();
|
hideKeyboard();
|
||||||
mShareAfterEncrypt = true;
|
mShareAfterEncrypt = true;
|
||||||
cryptoOperation(new CryptoInputParcel(new Date()));
|
cryptoOperation(CryptoInputParcel.createCryptoInputParcel(new Date()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case R.id.encrypt_paste: {
|
case R.id.encrypt_paste: {
|
||||||
hideKeyboard();
|
hideKeyboard();
|
||||||
cryptoOperation(new CryptoInputParcel(new Date()));
|
cryptoOperation(CryptoInputParcel.createCryptoInputParcel(new Date()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class OrbotRequiredDialogActivity extends FragmentActivity
|
|||||||
mCryptoInputParcel = getIntent().getParcelableExtra(EXTRA_CRYPTO_INPUT);
|
mCryptoInputParcel = getIntent().getParcelableExtra(EXTRA_CRYPTO_INPUT);
|
||||||
if (mCryptoInputParcel == null) {
|
if (mCryptoInputParcel == null) {
|
||||||
// compatibility with usages that don't use a CryptoInputParcel
|
// compatibility with usages that don't use a CryptoInputParcel
|
||||||
mCryptoInputParcel = new CryptoInputParcel();
|
mCryptoInputParcel = CryptoInputParcel.createCryptoInputParcel();
|
||||||
}
|
}
|
||||||
|
|
||||||
mMessenger = getIntent().getParcelableExtra(EXTRA_MESSENGER);
|
mMessenger = getIntent().getParcelableExtra(EXTRA_MESSENGER);
|
||||||
@@ -147,7 +147,7 @@ public class OrbotRequiredDialogActivity extends FragmentActivity
|
|||||||
public void onNeutralButton() {
|
public void onNeutralButton() {
|
||||||
sendMessage(MESSAGE_ORBOT_IGNORE);
|
sendMessage(MESSAGE_ORBOT_IGNORE);
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
mCryptoInputParcel.addParcelableProxy(ParcelableProxy.getForNoProxy());
|
mCryptoInputParcel = mCryptoInputParcel.withParcelableProxy(ParcelableProxy.getForNoProxy());
|
||||||
intent.putExtra(RESULT_CRYPTO_INPUT, mCryptoInputParcel);
|
intent.putExtra(RESULT_CRYPTO_INPUT, mCryptoInputParcel);
|
||||||
setResult(RESULT_OK, intent);
|
setResult(RESULT_OK, intent);
|
||||||
finish();
|
finish();
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
|
|
||||||
CryptoInputParcel cryptoInputParcel = getIntent().getParcelableExtra(EXTRA_CRYPTO_INPUT);
|
CryptoInputParcel cryptoInputParcel = getIntent().getParcelableExtra(EXTRA_CRYPTO_INPUT);
|
||||||
if (cryptoInputParcel == null) {
|
if (cryptoInputParcel == null) {
|
||||||
cryptoInputParcel = new CryptoInputParcel();
|
cryptoInputParcel = CryptoInputParcel.createCryptoInputParcel();
|
||||||
getIntent().putExtra(EXTRA_CRYPTO_INPUT, cryptoInputParcel);
|
getIntent().putExtra(EXTRA_CRYPTO_INPUT, cryptoInputParcel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
if (pubRing.getSecretKeyType(requiredInput.getSubKeyId()) == SecretKeyType.PASSPHRASE_EMPTY) {
|
if (pubRing.getSecretKeyType(requiredInput.getSubKeyId()) == SecretKeyType.PASSPHRASE_EMPTY) {
|
||||||
// also return passphrase back to activity
|
// also return passphrase back to activity
|
||||||
Intent returnIntent = new Intent();
|
Intent returnIntent = new Intent();
|
||||||
cryptoInputParcel.mPassphrase = new Passphrase("");
|
cryptoInputParcel = cryptoInputParcel.withPassphrase(new Passphrase(""));
|
||||||
returnIntent.putExtra(RESULT_CRYPTO_INPUT, cryptoInputParcel);
|
returnIntent.putExtra(RESULT_CRYPTO_INPUT, cryptoInputParcel);
|
||||||
setResult(RESULT_OK, returnIntent);
|
setResult(RESULT_OK, returnIntent);
|
||||||
finish();
|
finish();
|
||||||
@@ -539,7 +539,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
|
|
||||||
CryptoInputParcel inputParcel = getArguments().getParcelable(EXTRA_CRYPTO_INPUT);
|
CryptoInputParcel inputParcel = getArguments().getParcelable(EXTRA_CRYPTO_INPUT);
|
||||||
// noinspection ConstantConditions, we handle the non-null case in PassphraseDialogActivity.onCreate()
|
// noinspection ConstantConditions, we handle the non-null case in PassphraseDialogActivity.onCreate()
|
||||||
inputParcel.mPassphrase = passphrase;
|
inputParcel = inputParcel.withPassphrase(passphrase);
|
||||||
|
|
||||||
((PassphraseDialogActivity) getActivity()).handleResult(inputParcel);
|
((PassphraseDialogActivity) getActivity()).handleResult(inputParcel);
|
||||||
|
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity {
|
|||||||
for (int i = 0; i < mRequiredInput.mInputData.length; i++) {
|
for (int i = 0; i < mRequiredInput.mInputData.length; i++) {
|
||||||
byte[] encryptedSessionKey = mRequiredInput.mInputData[i];
|
byte[] encryptedSessionKey = mRequiredInput.mInputData[i];
|
||||||
byte[] decryptedSessionKey = mSecurityTokenHelper.decryptSessionKey(encryptedSessionKey, publicKeyRing.getPublicKey(tokenKeyId));
|
byte[] decryptedSessionKey = mSecurityTokenHelper.decryptSessionKey(encryptedSessionKey, publicKeyRing.getPublicKey(tokenKeyId));
|
||||||
mInputParcel.addCryptoData(encryptedSessionKey, decryptedSessionKey);
|
mInputParcel = mInputParcel.withCryptoData(encryptedSessionKey, decryptedSessionKey);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -218,13 +218,13 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity {
|
|||||||
throw new IOException(getString(R.string.error_wrong_security_token));
|
throw new IOException(getString(R.string.error_wrong_security_token));
|
||||||
}
|
}
|
||||||
|
|
||||||
mInputParcel.addSignatureTime(mRequiredInput.mSignatureTime);
|
mInputParcel = mInputParcel.withSignatureTime(mRequiredInput.mSignatureTime);
|
||||||
|
|
||||||
for (int i = 0; i < mRequiredInput.mInputData.length; i++) {
|
for (int i = 0; i < mRequiredInput.mInputData.length; i++) {
|
||||||
byte[] hash = mRequiredInput.mInputData[i];
|
byte[] hash = mRequiredInput.mInputData[i];
|
||||||
int algo = mRequiredInput.mSignAlgos[i];
|
int algo = mRequiredInput.mSignAlgos[i];
|
||||||
byte[] signedHash = mSecurityTokenHelper.calculateSignature(hash, algo);
|
byte[] signedHash = mSecurityTokenHelper.calculateSignature(hash, algo);
|
||||||
mInputParcel.addCryptoData(hash, signedHash);
|
mInputParcel = mInputParcel.withCryptoData(hash, signedHash);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity {
|
|||||||
mSecurityTokenHelper.changeKey(key, passphrase);
|
mSecurityTokenHelper.changeKey(key, passphrase);
|
||||||
|
|
||||||
// TODO: Is this really used anywhere?
|
// TODO: Is this really used anywhere?
|
||||||
mInputParcel.addCryptoData(subkeyBytes, tokenSerialNumber);
|
mInputParcel = mInputParcel.withCryptoData(subkeyBytes, tokenSerialNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
// change PINs afterwards
|
// change PINs afterwards
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void cryptoOperation() {
|
public void cryptoOperation() {
|
||||||
cryptoOperation(new CryptoInputParcel(new Date()));
|
cryptoOperation(CryptoInputParcel.createCryptoInputParcel(new Date()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onHandleResult(OperationResult result) {
|
public void onHandleResult(OperationResult result) {
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package org.sufficientlysecure.keychain.util;
|
||||||
|
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
|
||||||
|
import com.ryanharter.auto.value.parcel.TypeAdapter;
|
||||||
|
|
||||||
|
|
||||||
|
public class ByteMapParcelAdapter implements TypeAdapter<Map<ByteBuffer,byte[]>> {
|
||||||
|
@Override
|
||||||
|
public Map<ByteBuffer, byte[]> fromParcel(Parcel source) {
|
||||||
|
int count = source.readInt();
|
||||||
|
Map<ByteBuffer,byte[]> result = new HashMap<>(count);
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
byte[] key = source.createByteArray();
|
||||||
|
byte[] value = source.createByteArray();
|
||||||
|
result.put(ByteBuffer.wrap(key), value);
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableMap(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toParcel(Map<ByteBuffer, byte[]> value, Parcel dest) {
|
||||||
|
dest.writeInt(value.size());
|
||||||
|
for (Map.Entry<ByteBuffer, byte[]> entry : value.entrySet()) {
|
||||||
|
dest.writeByteArray(entry.getKey().array());
|
||||||
|
dest.writeByteArray(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -310,7 +310,7 @@ public class BackupOperationTest {
|
|||||||
|
|
||||||
BackupKeyringParcel parcel = new BackupKeyringParcel(
|
BackupKeyringParcel parcel = new BackupKeyringParcel(
|
||||||
new long[] { mStaticRing1.getMasterKeyId() }, false, true, true, fakeOutputUri);
|
new long[] { mStaticRing1.getMasterKeyId() }, false, true, true, fakeOutputUri);
|
||||||
CryptoInputParcel inputParcel = new CryptoInputParcel(passphrase);
|
CryptoInputParcel inputParcel = CryptoInputParcel.createCryptoInputParcel(passphrase);
|
||||||
ExportResult result = op.execute(parcel, inputParcel);
|
ExportResult result = op.execute(parcel, inputParcel);
|
||||||
|
|
||||||
verify(mockResolver).openOutputStream(fakePipedUri);
|
verify(mockResolver).openOutputStream(fakePipedUri);
|
||||||
@@ -330,19 +330,20 @@ public class BackupOperationTest {
|
|||||||
input.setAllowSymmetricDecryption(true);
|
input.setAllowSymmetricDecryption(true);
|
||||||
|
|
||||||
{
|
{
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel());
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel());
|
||||||
assertTrue("decryption must return pending without passphrase", result.isPending());
|
assertTrue("decryption must return pending without passphrase", result.isPending());
|
||||||
Assert.assertTrue("should contain pending passphrase log entry",
|
Assert.assertTrue("should contain pending passphrase log entry",
|
||||||
result.getLog().containsType(LogType.MSG_DC_PENDING_PASSPHRASE));
|
result.getLog().containsType(LogType.MSG_DC_PENDING_PASSPHRASE));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(new Passphrase("bad")));
|
DecryptVerifyResult result = op.execute(input,
|
||||||
|
CryptoInputParcel.createCryptoInputParcel(new Passphrase("bad")));
|
||||||
assertFalse("decryption must fail with bad passphrase", result.success());
|
assertFalse("decryption must fail with bad passphrase", result.success());
|
||||||
Assert.assertTrue("should contain bad passphrase log entry",
|
Assert.assertTrue("should contain bad passphrase log entry",
|
||||||
result.getLog().containsType(LogType.MSG_DC_ERROR_SYM_PASSPHRASE));
|
result.getLog().containsType(LogType.MSG_DC_ERROR_SYM_PASSPHRASE));
|
||||||
}
|
}
|
||||||
|
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(passphrase));
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(passphrase));
|
||||||
assertTrue("decryption must succeed with passphrase", result.success());
|
assertTrue("decryption must succeed with passphrase", result.success());
|
||||||
|
|
||||||
assertEquals("backup filename should be backup_keyid.pub.asc",
|
assertEquals("backup filename should be backup_keyid.pub.asc",
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ public class CertifyOperationTest {
|
|||||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||||
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(),
|
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(),
|
||||||
mStaticRing2.getPublicKey().getUnorderedUserIds(), null));
|
mStaticRing2.getPublicKey().getUnorderedUserIds(), null));
|
||||||
CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(), mKeyPhrase1));
|
CertifyResult result = op.execute(actions, CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
|
||||||
|
|
||||||
Assert.assertTrue("certification must succeed", result.success());
|
Assert.assertTrue("certification must succeed", result.success());
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ public class CertifyOperationTest {
|
|||||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||||
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(), null,
|
actions.add(new CertifyAction(mStaticRing2.getMasterKeyId(), null,
|
||||||
mStaticRing2.getPublicKey().getUnorderedUserAttributes()));
|
mStaticRing2.getPublicKey().getUnorderedUserAttributes()));
|
||||||
CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(), mKeyPhrase1));
|
CertifyResult result = op.execute(actions, CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
|
||||||
|
|
||||||
Assert.assertTrue("certification must succeed", result.success());
|
Assert.assertTrue("certification must succeed", result.success());
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ public class CertifyOperationTest {
|
|||||||
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
||||||
mStaticRing2.getPublicKey().getUnorderedUserIds(), null));
|
mStaticRing2.getPublicKey().getUnorderedUserIds(), null));
|
||||||
|
|
||||||
CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(), mKeyPhrase1));
|
CertifyResult result = op.execute(actions, CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
|
||||||
|
|
||||||
Assert.assertFalse("certification with itself must fail!", result.success());
|
Assert.assertFalse("certification with itself must fail!", result.success());
|
||||||
Assert.assertTrue("error msg must be about self certification",
|
Assert.assertTrue("error msg must be about self certification",
|
||||||
@@ -226,7 +226,7 @@ public class CertifyOperationTest {
|
|||||||
uids.add("nonexistent");
|
uids.add("nonexistent");
|
||||||
actions.add(new CertifyAction(1234L, uids, null));
|
actions.add(new CertifyAction(1234L, uids, null));
|
||||||
|
|
||||||
CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(),
|
CertifyResult result = op.execute(actions, CryptoInputParcel.createCryptoInputParcel(new Date(),
|
||||||
mKeyPhrase1));
|
mKeyPhrase1));
|
||||||
|
|
||||||
Assert.assertFalse("certification of nonexistent key must fail", result.success());
|
Assert.assertFalse("certification of nonexistent key must fail", result.success());
|
||||||
@@ -239,7 +239,7 @@ public class CertifyOperationTest {
|
|||||||
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
|
||||||
mStaticRing2.getPublicKey().getUnorderedUserIds(), null));
|
mStaticRing2.getPublicKey().getUnorderedUserIds(), null));
|
||||||
|
|
||||||
CertifyResult result = op.execute(actions, new CryptoInputParcel(new Date(),
|
CertifyResult result = op.execute(actions, CryptoInputParcel.createCryptoInputParcel(new Date(),
|
||||||
mKeyPhrase1));
|
mKeyPhrase1));
|
||||||
|
|
||||||
Assert.assertFalse("certification of nonexistent key must fail", result.success());
|
Assert.assertFalse("certification of nonexistent key must fail", result.success());
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ public class InputDataOperationTest {
|
|||||||
|
|
||||||
InputDataParcel input = new InputDataParcel(fakeInputUri, null);
|
InputDataParcel input = new InputDataParcel(fakeInputUri, null);
|
||||||
|
|
||||||
InputDataResult result = op.execute(input, new CryptoInputParcel());
|
InputDataResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel());
|
||||||
|
|
||||||
// must be successful, no verification, have two output URIs
|
// must be successful, no verification, have two output URIs
|
||||||
Assert.assertTrue(result.success());
|
Assert.assertTrue(result.success());
|
||||||
@@ -309,7 +309,7 @@ public class InputDataOperationTest {
|
|||||||
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
InputDataParcel input = new InputDataParcel(FAKE_CONTENT_INPUT_URI_1, null);
|
InputDataParcel input = new InputDataParcel(FAKE_CONTENT_INPUT_URI_1, null);
|
||||||
return op.execute(input, new CryptoInputParcel());
|
return op.execute(input, CryptoInputParcel.createCryptoInputParcel());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
PgpSecurityConstants.OpenKeychainSymmetricKeyAlgorithmTags.AES_128);
|
PgpSecurityConstants.OpenKeychainSymmetricKeyAlgorithmTags.AES_128);
|
||||||
|
|
||||||
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel(pgpData.build());
|
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel(pgpData.build());
|
||||||
PgpSignEncryptResult result = op.execute(b, new CryptoInputParcel(new Date()),
|
PgpSignEncryptResult result = op.execute(b, CryptoInputParcel.createCryptoInputParcel(new Date()),
|
||||||
data, out);
|
data, out);
|
||||||
|
|
||||||
Assert.assertTrue("encryption must succeed", result.success());
|
Assert.assertTrue("encryption must succeed", result.success());
|
||||||
@@ -203,7 +203,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
input.setAllowSymmetricDecryption(true);
|
input.setAllowSymmetricDecryption(true);
|
||||||
DecryptVerifyResult result = op.execute(
|
DecryptVerifyResult result = op.execute(
|
||||||
input, new CryptoInputParcel(mSymmetricPassphrase), data, out);
|
input, CryptoInputParcel.createCryptoInputParcel(mSymmetricPassphrase), data, out);
|
||||||
|
|
||||||
Assert.assertTrue("decryption must succeed", result.success());
|
Assert.assertTrue("decryption must succeed", result.success());
|
||||||
Assert.assertArrayEquals("decrypted ciphertext should equal plaintext",
|
Assert.assertArrayEquals("decrypted ciphertext should equal plaintext",
|
||||||
@@ -233,7 +233,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
input.setAllowSymmetricDecryption(true);
|
input.setAllowSymmetricDecryption(true);
|
||||||
DecryptVerifyResult result = op.execute(input,
|
DecryptVerifyResult result = op.execute(input,
|
||||||
new CryptoInputParcel(new Passphrase(new String(mSymmetricPassphrase.getCharArray()) + "x")),
|
CryptoInputParcel.createCryptoInputParcel(new Passphrase(new String(mSymmetricPassphrase.getCharArray()) + "x")),
|
||||||
data, out);
|
data, out);
|
||||||
|
|
||||||
Assert.assertFalse("decryption must fail", result.success());
|
Assert.assertFalse("decryption must fail", result.success());
|
||||||
@@ -255,7 +255,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
input.setAllowSymmetricDecryption(true);
|
input.setAllowSymmetricDecryption(true);
|
||||||
DecryptVerifyResult result = op.execute(input,
|
DecryptVerifyResult result = op.execute(input,
|
||||||
new CryptoInputParcel(), data, out);
|
CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
Assert.assertFalse("decryption must fail", result.success());
|
Assert.assertFalse("decryption must fail", result.success());
|
||||||
Assert.assertEquals("decrypted plaintext should be empty", 0, out.size());
|
Assert.assertEquals("decrypted plaintext should be empty", 0, out.size());
|
||||||
@@ -276,7 +276,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
input.setAllowSymmetricDecryption(false);
|
input.setAllowSymmetricDecryption(false);
|
||||||
DecryptVerifyResult result = op.execute(input,
|
DecryptVerifyResult result = op.execute(input,
|
||||||
new CryptoInputParcel(), data, out);
|
CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
Assert.assertFalse("decryption must fail", result.success());
|
Assert.assertFalse("decryption must fail", result.success());
|
||||||
Assert.assertEquals("decrypted plaintext should be empty", 0, out.size());
|
Assert.assertEquals("decrypted plaintext should be empty", 0, out.size());
|
||||||
@@ -312,7 +312,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(pgpData.build());
|
PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(pgpData.build());
|
||||||
|
|
||||||
PgpSignEncryptResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1), data, out);
|
PgpSignEncryptResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1), data, out);
|
||||||
Assert.assertTrue("signing must succeed", result.success());
|
Assert.assertTrue("signing must succeed", result.success());
|
||||||
|
|
||||||
ciphertext = out.toByteArray();
|
ciphertext = out.toByteArray();
|
||||||
@@ -326,7 +326,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), 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());
|
||||||
Assert.assertArrayEquals("verification text should equal plaintext",
|
Assert.assertArrayEquals("verification text should equal plaintext",
|
||||||
@@ -369,7 +369,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(pgpData.build());
|
PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(pgpData.build());
|
||||||
|
|
||||||
PgpSignEncryptResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1), data, out);
|
PgpSignEncryptResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1), data, out);
|
||||||
Assert.assertTrue("signing must succeed", result.success());
|
Assert.assertTrue("signing must succeed", result.success());
|
||||||
|
|
||||||
ciphertext = out.toByteArray();
|
ciphertext = out.toByteArray();
|
||||||
@@ -386,7 +386,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), 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());
|
||||||
|
|
||||||
@@ -429,7 +429,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(pgpData.build());
|
PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(pgpData.build());
|
||||||
|
|
||||||
PgpSignEncryptResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1), data, out);
|
PgpSignEncryptResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1), data, out);
|
||||||
Assert.assertTrue("signing must succeed", result.success());
|
Assert.assertTrue("signing must succeed", result.success());
|
||||||
|
|
||||||
detachedSignature = result.getDetachedSignature();
|
detachedSignature = result.getDetachedSignature();
|
||||||
@@ -444,7 +444,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
input.setDetachedSignature(detachedSignature);
|
input.setDetachedSignature(detachedSignature);
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), 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());
|
||||||
Assert.assertArrayEquals("verification text should equal plaintext (save for a newline)",
|
Assert.assertArrayEquals("verification text should equal plaintext (save for a newline)",
|
||||||
@@ -485,7 +485,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(pgpData.build());
|
PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(pgpData.build());
|
||||||
|
|
||||||
PgpSignEncryptResult result = op.execute(input, new CryptoInputParcel(new Date()),
|
PgpSignEncryptResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(new Date()),
|
||||||
data, out);
|
data, out);
|
||||||
Assert.assertTrue("encryption must succeed", result.success());
|
Assert.assertTrue("encryption must succeed", result.success());
|
||||||
|
|
||||||
@@ -500,7 +500,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(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());
|
||||||
Assert.assertArrayEquals("decrypted ciphertext with provided passphrase should equal plaintext",
|
Assert.assertArrayEquals("decrypted ciphertext with provided passphrase should equal plaintext",
|
||||||
@@ -529,7 +529,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
||||||
mKeyPhrase1, mStaticRing1.getMasterKeyId(), null);
|
mKeyPhrase1, mStaticRing1.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
CryptoInputParcel cryptoInput = result.getCachedCryptoInputParcel();
|
CryptoInputParcel cryptoInput = result.getCachedCryptoInputParcel();
|
||||||
Assert.assertEquals("must have one cached session key",
|
Assert.assertEquals("must have one cached session key",
|
||||||
@@ -553,7 +553,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
||||||
null, mStaticRing1.getMasterKeyId(), null);
|
null, mStaticRing1.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), 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());
|
||||||
Assert.assertTrue("decryption with no passphrase should return pending", result.isPending());
|
Assert.assertTrue("decryption with no passphrase should return pending", result.isPending());
|
||||||
@@ -588,7 +588,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(pgpData.build());
|
PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(pgpData.build());
|
||||||
|
|
||||||
PgpSignEncryptResult result = op.execute(input, new CryptoInputParcel(new Date()),
|
PgpSignEncryptResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(new Date()),
|
||||||
data, out);
|
data, out);
|
||||||
Assert.assertTrue("encryption must succeed", result.success());
|
Assert.assertTrue("encryption must succeed", result.success());
|
||||||
|
|
||||||
@@ -626,7 +626,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
parcel.mChangeSubKeys.add(new SubkeyChange(encKeyId1, true, false));
|
parcel.mChangeSubKeys.add(new SubkeyChange(encKeyId1, true, false));
|
||||||
UncachedKeyRing modified = PgpKeyOperationTest.applyModificationWithChecks(parcel, mStaticRing1,
|
UncachedKeyRing modified = PgpKeyOperationTest.applyModificationWithChecks(parcel, mStaticRing1,
|
||||||
new ArrayList<RawPacket>(), new ArrayList<RawPacket>(),
|
new ArrayList<RawPacket>(), new ArrayList<RawPacket>(),
|
||||||
new CryptoInputParcel(new Date(), mKeyPhrase1));
|
CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
|
||||||
|
|
||||||
KeyWritableRepository databaseInteractor =
|
KeyWritableRepository databaseInteractor =
|
||||||
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
||||||
@@ -635,7 +635,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(ciphertext);
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext);
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1));
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1));
|
||||||
|
|
||||||
Assert.assertTrue("decryption must succeed", result.success());
|
Assert.assertTrue("decryption must succeed", result.success());
|
||||||
Assert.assertTrue("decryption must have skipped first key",
|
Assert.assertTrue("decryption must have skipped first key",
|
||||||
@@ -649,7 +649,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
parcel.mChangeSubKeys.add(new SubkeyChange(encKeyId1, KeyFlags.CERTIFY_OTHER, null));
|
parcel.mChangeSubKeys.add(new SubkeyChange(encKeyId1, KeyFlags.CERTIFY_OTHER, null));
|
||||||
UncachedKeyRing modified = PgpKeyOperationTest.applyModificationWithChecks(parcel, mStaticRing1,
|
UncachedKeyRing modified = PgpKeyOperationTest.applyModificationWithChecks(parcel, mStaticRing1,
|
||||||
new ArrayList<RawPacket>(), new ArrayList<RawPacket>(),
|
new ArrayList<RawPacket>(), new ArrayList<RawPacket>(),
|
||||||
new CryptoInputParcel(new Date(), mKeyPhrase1));
|
CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
|
||||||
|
|
||||||
KeyWritableRepository databaseInteractor =
|
KeyWritableRepository databaseInteractor =
|
||||||
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
||||||
@@ -658,7 +658,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(ciphertext);
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext);
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1));
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1));
|
||||||
|
|
||||||
Assert.assertTrue("decryption must succeed", result.success());
|
Assert.assertTrue("decryption must succeed", result.success());
|
||||||
Assert.assertTrue("decryption must have skipped first key",
|
Assert.assertTrue("decryption must have skipped first key",
|
||||||
@@ -677,7 +677,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
parcel.mRevokeSubKeys.add(KeyringTestingHelper.getSubkeyId(mStaticRing1, 2));
|
parcel.mRevokeSubKeys.add(KeyringTestingHelper.getSubkeyId(mStaticRing1, 2));
|
||||||
UncachedKeyRing modified = PgpKeyOperationTest.applyModificationWithChecks(parcel, mStaticRing1,
|
UncachedKeyRing modified = PgpKeyOperationTest.applyModificationWithChecks(parcel, mStaticRing1,
|
||||||
new ArrayList<RawPacket>(), new ArrayList<RawPacket>(),
|
new ArrayList<RawPacket>(), new ArrayList<RawPacket>(),
|
||||||
new CryptoInputParcel(new Date(), mKeyPhrase1));
|
CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1));
|
||||||
|
|
||||||
KeyWritableRepository databaseInteractor =
|
KeyWritableRepository databaseInteractor =
|
||||||
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
||||||
@@ -701,7 +701,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(pgpData.build());
|
PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(pgpData.build());
|
||||||
|
|
||||||
PgpSignEncryptResult result = op.execute(input, new CryptoInputParcel(new Date()),
|
PgpSignEncryptResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(new Date()),
|
||||||
data, out);
|
data, out);
|
||||||
Assert.assertTrue("encryption must succeed", result.success());
|
Assert.assertTrue("encryption must succeed", result.success());
|
||||||
|
|
||||||
@@ -749,7 +749,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel(pgpData.build());
|
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel(pgpData.build());
|
||||||
|
|
||||||
PgpSignEncryptResult result = op.execute(b, new CryptoInputParcel(new Date()),
|
PgpSignEncryptResult result = op.execute(b, CryptoInputParcel.createCryptoInputParcel(new Date()),
|
||||||
data, out);
|
data, out);
|
||||||
Assert.assertTrue("encryption must succeed", result.success());
|
Assert.assertTrue("encryption must succeed", result.success());
|
||||||
|
|
||||||
@@ -765,7 +765,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
||||||
mKeyPhrase1, mStaticRing1.getMasterKeyId(), null);
|
mKeyPhrase1, mStaticRing1.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), 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());
|
||||||
Assert.assertArrayEquals("decrypted ciphertext with cached passphrase should equal plaintext",
|
Assert.assertArrayEquals("decrypted ciphertext with cached passphrase should equal plaintext",
|
||||||
@@ -795,7 +795,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
input.setAllowedKeyIds(allowed);
|
input.setAllowedKeyIds(allowed);
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), 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());
|
||||||
Assert.assertArrayEquals("decrypted ciphertext with cached passphrase should equal plaintext",
|
Assert.assertArrayEquals("decrypted ciphertext with cached passphrase should equal plaintext",
|
||||||
@@ -818,7 +818,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
input.setAllowedKeyIds(new HashSet<Long>());
|
input.setAllowedKeyIds(new HashSet<Long>());
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), 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());
|
||||||
Assert.assertEquals("decryption must fail with key disllowed status",
|
Assert.assertEquals("decryption must fail with key disllowed status",
|
||||||
@@ -840,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 = new PgpDecryptVerifyInputParcel();
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), 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());
|
||||||
Assert.assertArrayEquals("decrypted ciphertext with cached passphrase should equal plaintext",
|
Assert.assertArrayEquals("decrypted ciphertext with cached passphrase should equal plaintext",
|
||||||
@@ -881,7 +881,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel(pgpData.build());
|
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel(pgpData.build());
|
||||||
|
|
||||||
PgpSignEncryptResult result = op.execute(b,
|
PgpSignEncryptResult result = op.execute(b,
|
||||||
new CryptoInputParcel(new Date(), mKeyPhrase1), data, out);
|
CryptoInputParcel.createCryptoInputParcel(new Date(), mKeyPhrase1), data, out);
|
||||||
Assert.assertTrue("encryption must succeed", result.success());
|
Assert.assertTrue("encryption must succeed", result.success());
|
||||||
|
|
||||||
ciphertext = out.toByteArray();
|
ciphertext = out.toByteArray();
|
||||||
@@ -896,7 +896,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
||||||
mKeyPhrase1, mStaticRing1.getMasterKeyId(), null);
|
mKeyPhrase1, mStaticRing1.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), 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());
|
||||||
Assert.assertArrayEquals("decrypted ciphertext with cached passphrase should equal plaintext",
|
Assert.assertArrayEquals("decrypted ciphertext with cached passphrase should equal plaintext",
|
||||||
@@ -923,7 +923,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(
|
||||||
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
mKeyPhrase2, mStaticRing2.getMasterKeyId(), null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), 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());
|
||||||
Assert.assertArrayEquals("decrypted ciphertext with cached passphrase should equal plaintext",
|
Assert.assertArrayEquals("decrypted ciphertext with cached passphrase should equal plaintext",
|
||||||
@@ -965,7 +965,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel(pgpData.build());
|
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel(pgpData.build());
|
||||||
|
|
||||||
PgpSignEncryptResult result = op.execute(b, new CryptoInputParcel(new Date()),
|
PgpSignEncryptResult result = op.execute(b, CryptoInputParcel.createCryptoInputParcel(new Date()),
|
||||||
data, out);
|
data, out);
|
||||||
Assert.assertTrue("encryption must succeed", result.success());
|
Assert.assertTrue("encryption must succeed", result.success());
|
||||||
|
|
||||||
@@ -980,7 +980,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(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());
|
||||||
Assert.assertArrayEquals("decrypted ciphertext should equal plaintext bytes",
|
Assert.assertArrayEquals("decrypted ciphertext should equal plaintext bytes",
|
||||||
@@ -1008,7 +1008,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1), data, out);
|
||||||
|
|
||||||
|
|
||||||
Assert.assertTrue(result.success());
|
Assert.assertTrue(result.success());
|
||||||
@@ -1031,7 +1031,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(mKeyPhrase1), data, out);
|
||||||
|
|
||||||
|
|
||||||
Assert.assertTrue(result.success());
|
Assert.assertTrue(result.success());
|
||||||
@@ -1052,7 +1052,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
PgpDecryptVerifyOperation op = operationWithFakePassphraseCache(null, null, null);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(), data, out);
|
DecryptVerifyResult result = op.execute(input, CryptoInputParcel.createCryptoInputParcel(), data, out);
|
||||||
|
|
||||||
|
|
||||||
Assert.assertTrue(result.success());
|
Assert.assertTrue(result.success());
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public class PgpKeyOperationTest {
|
|||||||
// we sleep here for a second, to make sure all new certificates have different timestamps
|
// we sleep here for a second, to make sure all new certificates have different timestamps
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
|
|
||||||
cryptoInput = new CryptoInputParcel(new Date(), passphrase);
|
cryptoInput = CryptoInputParcel.createCryptoInputParcel(new Date(), passphrase);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +327,7 @@ public class PgpKeyOperationTest {
|
|||||||
parcel.mAddUserIds.add("allure");
|
parcel.mAddUserIds.add("allure");
|
||||||
|
|
||||||
assertModifyFailure("keyring modification with bad passphrase should fail",
|
assertModifyFailure("keyring modification with bad passphrase should fail",
|
||||||
ring, parcel, new CryptoInputParcel(badphrase), LogType.MSG_MF_UNLOCK_ERROR);
|
ring, parcel, CryptoInputParcel.createCryptoInputParcel(badphrase), LogType.MSG_MF_UNLOCK_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -685,7 +685,7 @@ public class PgpKeyOperationTest {
|
|||||||
parcel.mRevokeSubKeys.add(keyId);
|
parcel.mRevokeSubKeys.add(keyId);
|
||||||
|
|
||||||
modified = applyModificationWithChecks(parcel, ring, onlyA, onlyB,
|
modified = applyModificationWithChecks(parcel, ring, onlyA, onlyB,
|
||||||
new CryptoInputParcel(new Date(), passphrase));
|
CryptoInputParcel.createCryptoInputParcel(new Date(), passphrase));
|
||||||
|
|
||||||
Assert.assertEquals("no extra packets in original", 0, onlyA.size());
|
Assert.assertEquals("no extra packets in original", 0, onlyA.size());
|
||||||
Assert.assertEquals("exactly one extra packet in modified", 1, onlyB.size());
|
Assert.assertEquals("exactly one extra packet in modified", 1, onlyB.size());
|
||||||
@@ -805,7 +805,8 @@ public class PgpKeyOperationTest {
|
|||||||
{ // we should be able to change the stripped status of subkeys without passphrase
|
{ // we should be able to change the stripped status of subkeys without passphrase
|
||||||
parcel.reset();
|
parcel.reset();
|
||||||
parcel.mChangeSubKeys.add(new SubkeyChange(keyId, true, false));
|
parcel.mChangeSubKeys.add(new SubkeyChange(keyId, true, false));
|
||||||
modified = applyModificationWithChecks(parcel, ring, onlyA, onlyB, new CryptoInputParcel());
|
modified = applyModificationWithChecks(parcel, ring, onlyA, onlyB,
|
||||||
|
CryptoInputParcel.createCryptoInputParcel());
|
||||||
Assert.assertEquals("one extra packet in modified", 1, onlyB.size());
|
Assert.assertEquals("one extra packet in modified", 1, onlyB.size());
|
||||||
Packet p = new BCPGInputStream(new ByteArrayInputStream(onlyB.get(0).buf)).readPacket();
|
Packet p = new BCPGInputStream(new ByteArrayInputStream(onlyB.get(0).buf)).readPacket();
|
||||||
Assert.assertEquals("new packet should have GNU_DUMMY S2K type",
|
Assert.assertEquals("new packet should have GNU_DUMMY S2K type",
|
||||||
@@ -885,8 +886,8 @@ public class PgpKeyOperationTest {
|
|||||||
0x6a, 0x6f, 0x6c, 0x6f, 0x73, 0x77, 0x61, 0x67,
|
0x6a, 0x6f, 0x6c, 0x6f, 0x73, 0x77, 0x61, 0x67,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
};
|
};
|
||||||
CryptoInputParcel inputParcel = new CryptoInputParcel();
|
CryptoInputParcel inputParcel = CryptoInputParcel.createCryptoInputParcel();
|
||||||
inputParcel.addCryptoData(keyIdBytes, serial);
|
inputParcel = inputParcel.withCryptoData(keyIdBytes, serial);
|
||||||
|
|
||||||
modified = applyModificationWithChecks(parcelSecurityToken, ringSecurityToken, onlyA, onlyB, inputParcel);
|
modified = applyModificationWithChecks(parcelSecurityToken, ringSecurityToken, onlyA, onlyB, inputParcel);
|
||||||
Assert.assertEquals("one extra packet in modified", 1, onlyB.size());
|
Assert.assertEquals("one extra packet in modified", 1, onlyB.size());
|
||||||
@@ -1082,7 +1083,7 @@ public class PgpKeyOperationTest {
|
|||||||
// applying the same modification AGAIN should not add more certifications but drop those
|
// applying the same modification AGAIN should not add more certifications but drop those
|
||||||
// as duplicates
|
// as duplicates
|
||||||
modified = applyModificationWithChecks(parcel, modified, onlyA, onlyB,
|
modified = applyModificationWithChecks(parcel, modified, onlyA, onlyB,
|
||||||
new CryptoInputParcel(new Date(), passphrase), true, false);
|
CryptoInputParcel.createCryptoInputParcel(new Date(), passphrase), true, false);
|
||||||
|
|
||||||
Assert.assertEquals("duplicate modification: one extra packet in original", 1, onlyA.size());
|
Assert.assertEquals("duplicate modification: one extra packet in original", 1, onlyA.size());
|
||||||
Assert.assertEquals("duplicate modification: one extra packet in modified", 1, onlyB.size());
|
Assert.assertEquals("duplicate modification: one extra packet in modified", 1, onlyB.size());
|
||||||
@@ -1158,10 +1159,10 @@ public class PgpKeyOperationTest {
|
|||||||
|
|
||||||
// modify keyring, change to non-empty passphrase
|
// modify keyring, change to non-empty passphrase
|
||||||
Passphrase otherPassphrase = TestingUtils.genPassphrase(true);
|
Passphrase otherPassphrase = TestingUtils.genPassphrase(true);
|
||||||
CryptoInputParcel otherCryptoInput = new CryptoInputParcel(otherPassphrase);
|
CryptoInputParcel otherCryptoInput = CryptoInputParcel.createCryptoInputParcel(otherPassphrase);
|
||||||
parcel.setNewUnlock(new ChangeUnlockParcel(otherPassphrase));
|
parcel.setNewUnlock(new ChangeUnlockParcel(otherPassphrase));
|
||||||
modified = applyModificationWithChecks(parcel, modified, onlyA, onlyB,
|
modified = applyModificationWithChecks(parcel, modified, onlyA, onlyB,
|
||||||
new CryptoInputParcel(new Date(), new Passphrase()));
|
CryptoInputParcel.createCryptoInputParcel(new Date(), new Passphrase()));
|
||||||
|
|
||||||
Assert.assertEquals("exactly three packets should have been modified (the secret keys)",
|
Assert.assertEquals("exactly three packets should have been modified (the secret keys)",
|
||||||
3, onlyB.size());
|
3, onlyB.size());
|
||||||
@@ -1210,7 +1211,8 @@ public class PgpKeyOperationTest {
|
|||||||
|
|
||||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||||
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(modified.getEncoded(), 0);
|
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(modified.getEncoded(), 0);
|
||||||
PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(otherPassphrase2), parcel);
|
PgpEditKeyResult result = op.modifySecretKeyRing(secretRing,
|
||||||
|
CryptoInputParcel.createCryptoInputParcel(otherPassphrase2), parcel);
|
||||||
Assert.assertTrue("key modification must succeed", result.success());
|
Assert.assertTrue("key modification must succeed", result.success());
|
||||||
Assert.assertTrue("log must contain a failed passphrase change warning",
|
Assert.assertTrue("log must contain a failed passphrase change warning",
|
||||||
result.getLog().containsType(LogType.MSG_MF_PASSPHRASE_FAIL));
|
result.getLog().containsType(LogType.MSG_MF_PASSPHRASE_FAIL));
|
||||||
@@ -1225,7 +1227,8 @@ public class PgpKeyOperationTest {
|
|||||||
|
|
||||||
parcel.mAddUserIds.add("discord");
|
parcel.mAddUserIds.add("discord");
|
||||||
PgpKeyOperation op = new PgpKeyOperation(null);
|
PgpKeyOperation op = new PgpKeyOperation(null);
|
||||||
PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date()), parcel);
|
PgpEditKeyResult result = op.modifySecretKeyRing(secretRing,
|
||||||
|
CryptoInputParcel.createCryptoInputParcel(new Date()), parcel);
|
||||||
Assert.assertFalse("non-restricted operations should fail without passphrase", result.success());
|
Assert.assertFalse("non-restricted operations should fail without passphrase", result.success());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -549,7 +549,7 @@ public class UncachedKeyringCanonicalizeTest {
|
|||||||
CanonicalizedSecretKey masterSecretKey = canonicalized.getSecretKey();
|
CanonicalizedSecretKey masterSecretKey = canonicalized.getSecretKey();
|
||||||
masterSecretKey.unlock(new Passphrase());
|
masterSecretKey.unlock(new Passphrase());
|
||||||
PGPPublicKey masterPublicKey = masterSecretKey.getPublicKey();
|
PGPPublicKey masterPublicKey = masterSecretKey.getPublicKey();
|
||||||
CryptoInputParcel cryptoInput = new CryptoInputParcel(new Date());
|
CryptoInputParcel cryptoInput = CryptoInputParcel.createCryptoInputParcel(new Date());
|
||||||
PGPSignature cert = PgpKeyOperation.generateSubkeyBindingSignature(
|
PGPSignature cert = PgpKeyOperation.generateSubkeyBindingSignature(
|
||||||
PgpKeyOperation.getSignatureGenerator(masterSecretKey.getSecretKey(), cryptoInput),
|
PgpKeyOperation.getSignatureGenerator(masterSecretKey.getSecretKey(), cryptoInput),
|
||||||
cryptoInput.getSignatureTime(),
|
cryptoInput.getSignatureTime(),
|
||||||
|
|||||||
@@ -189,11 +189,13 @@ public class UncachedKeyringMergeTest {
|
|||||||
|
|
||||||
parcel.reset();
|
parcel.reset();
|
||||||
parcel.mAddUserIds.add("flim");
|
parcel.mAddUserIds.add("flim");
|
||||||
modifiedA = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing();
|
modifiedA = op.modifySecretKeyRing(secretRing,
|
||||||
|
CryptoInputParcel.createCryptoInputParcel(new Date(), new Passphrase()), parcel).getRing();
|
||||||
|
|
||||||
parcel.reset();
|
parcel.reset();
|
||||||
parcel.mAddUserIds.add("flam");
|
parcel.mAddUserIds.add("flam");
|
||||||
modifiedB = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing();
|
modifiedB = op.modifySecretKeyRing(secretRing,
|
||||||
|
CryptoInputParcel.createCryptoInputParcel(new Date(), new Passphrase()), parcel).getRing();
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // merge A into base
|
{ // merge A into base
|
||||||
@@ -230,8 +232,10 @@ public class UncachedKeyringMergeTest {
|
|||||||
parcel.reset();
|
parcel.reset();
|
||||||
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
|
||||||
Algorithm.ECDSA, 0, SaveKeyringParcel.Curve.NIST_P256, KeyFlags.SIGN_DATA, 0L));
|
Algorithm.ECDSA, 0, SaveKeyringParcel.Curve.NIST_P256, KeyFlags.SIGN_DATA, 0L));
|
||||||
modifiedA = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing();
|
modifiedA = op.modifySecretKeyRing(secretRing,
|
||||||
modifiedB = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing();
|
CryptoInputParcel.createCryptoInputParcel(new Date(), new Passphrase()), parcel).getRing();
|
||||||
|
modifiedB = op.modifySecretKeyRing(secretRing,
|
||||||
|
CryptoInputParcel.createCryptoInputParcel(new Date(), new Passphrase()), parcel).getRing();
|
||||||
|
|
||||||
subKeyIdA = KeyringTestingHelper.getSubkeyId(modifiedA, 2);
|
subKeyIdA = KeyringTestingHelper.getSubkeyId(modifiedA, 2);
|
||||||
subKeyIdB = KeyringTestingHelper.getSubkeyId(modifiedB, 2);
|
subKeyIdB = KeyringTestingHelper.getSubkeyId(modifiedB, 2);
|
||||||
@@ -272,7 +276,8 @@ public class UncachedKeyringMergeTest {
|
|||||||
parcel.mRevokeSubKeys.add(KeyringTestingHelper.getSubkeyId(ringA, 1));
|
parcel.mRevokeSubKeys.add(KeyringTestingHelper.getSubkeyId(ringA, 1));
|
||||||
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(
|
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(
|
||||||
ringA.getEncoded(), 0);
|
ringA.getEncoded(), 0);
|
||||||
modified = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing();
|
modified = op.modifySecretKeyRing(secretRing,
|
||||||
|
CryptoInputParcel.createCryptoInputParcel(new Date(), new Passphrase()), parcel).getRing();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -371,7 +376,8 @@ public class UncachedKeyringMergeTest {
|
|||||||
|
|
||||||
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(
|
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(
|
||||||
ringA.getEncoded(), 0);
|
ringA.getEncoded(), 0);
|
||||||
modified = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing();
|
modified = op.modifySecretKeyRing(secretRing,
|
||||||
|
CryptoInputParcel.createCryptoInputParcel(new Date(), new Passphrase()), parcel).getRing();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ public class InteropTest {
|
|||||||
|
|
||||||
PgpDecryptVerifyOperation op = makeOperation(base.toString(), pass, decrypt, verify);
|
PgpDecryptVerifyOperation op = makeOperation(base.toString(), pass, decrypt, verify);
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
|
||||||
CryptoInputParcel cip = new CryptoInputParcel(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");
|
||||||
String filename = config.getString("filename");
|
String filename = config.getString("filename");
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ public class KeychainExternalProviderTest {
|
|||||||
certifyActionsParcel.add(new CertifyAction(publicMasterKeyId, Collections.singletonList(userId), null));
|
certifyActionsParcel.add(new CertifyAction(publicMasterKeyId, Collections.singletonList(userId), null));
|
||||||
CertifyOperation op = new CertifyOperation(
|
CertifyOperation op = new CertifyOperation(
|
||||||
RuntimeEnvironment.application, databaseInteractor, new ProgressScaler(), null);
|
RuntimeEnvironment.application, databaseInteractor, new ProgressScaler(), null);
|
||||||
CertifyResult certifyResult = op.execute(certifyActionsParcel, new CryptoInputParcel());
|
CertifyResult certifyResult = op.execute(certifyActionsParcel, CryptoInputParcel.createCryptoInputParcel());
|
||||||
|
|
||||||
assertTrue(certifyResult.success());
|
assertTrue(certifyResult.success());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) 2013-2014 Philipp Jakubeit, Signe Rüsch, Dominik Schürmann
|
* Copyright (c) 2013-2014 Philipp Jakubeit, Signe Rüsch, Dominik Schürmann
|
||||||
|
* Copyright (c) 2017 Vincent Breitmoser
|
||||||
*
|
*
|
||||||
* Licensed under the Bouncy Castle License (MIT license). See LICENSE file for details.
|
* Licensed under the Bouncy Castle License (MIT license). See LICENSE file for details.
|
||||||
*/
|
*/
|
||||||
@@ -8,6 +9,8 @@ package org.bouncycastle.openpgp.operator.jcajce;
|
|||||||
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bouncycastle.jcajce.util.NamedJcaJceHelper;
|
import org.bouncycastle.jcajce.util.NamedJcaJceHelper;
|
||||||
@@ -19,25 +22,27 @@ import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
|
|||||||
public class CachingDataDecryptorFactory implements PublicKeyDataDecryptorFactory
|
public class CachingDataDecryptorFactory implements PublicKeyDataDecryptorFactory
|
||||||
{
|
{
|
||||||
private final PublicKeyDataDecryptorFactory mWrappedDecryptor;
|
private final PublicKeyDataDecryptorFactory mWrappedDecryptor;
|
||||||
private final Map<ByteBuffer, byte[]> mSessionKeyCache;
|
private final HashMap<ByteBuffer, byte[]> mSessionKeyCache;
|
||||||
|
|
||||||
private OperatorHelper mOperatorHelper;
|
private OperatorHelper mOperatorHelper;
|
||||||
|
|
||||||
public CachingDataDecryptorFactory(String providerName,
|
public CachingDataDecryptorFactory(String providerName, Map<ByteBuffer, byte[]> sessionKeyCache)
|
||||||
final Map<ByteBuffer,byte[]> sessionKeyCache)
|
|
||||||
{
|
{
|
||||||
mWrappedDecryptor = null;
|
this((PublicKeyDataDecryptorFactory) null, sessionKeyCache);
|
||||||
mSessionKeyCache = sessionKeyCache;
|
|
||||||
|
|
||||||
mOperatorHelper = new OperatorHelper(new NamedJcaJceHelper(providerName));
|
mOperatorHelper = new OperatorHelper(new NamedJcaJceHelper(providerName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CachingDataDecryptorFactory(PublicKeyDataDecryptorFactory wrapped,
|
public CachingDataDecryptorFactory(PublicKeyDataDecryptorFactory wrapped,
|
||||||
final Map<ByteBuffer,byte[]> sessionKeyCache)
|
Map<ByteBuffer, byte[]> sessionKeyCache)
|
||||||
{
|
{
|
||||||
mWrappedDecryptor = wrapped;
|
mSessionKeyCache = new HashMap<>();
|
||||||
mSessionKeyCache = sessionKeyCache;
|
if (sessionKeyCache != null)
|
||||||
|
{
|
||||||
|
mSessionKeyCache.putAll(sessionKeyCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
mWrappedDecryptor = wrapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCachedSessionData(PGPPublicKeyEncryptedData encData) throws PGPException {
|
public boolean hasCachedSessionData(PGPPublicKeyEncryptedData encData) throws PGPException {
|
||||||
@@ -46,7 +51,7 @@ public class CachingDataDecryptorFactory implements PublicKeyDataDecryptorFactor
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<ByteBuffer, byte[]> getCachedSessionKeys() {
|
public Map<ByteBuffer, byte[]> getCachedSessionKeys() {
|
||||||
return mSessionKeyCache;
|
return Collections.unmodifiableMap(mSessionKeyCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canDecrypt() {
|
public boolean canDecrypt() {
|
||||||
|
|||||||
Reference in New Issue
Block a user