Merge branch 'master' of github.com:open-keychain/open-keychain
This commit is contained in:
@@ -0,0 +1,154 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
* Copyright (C) 2015 Vincent Breitmoser <v.breitmoser@mugenguild.com>
|
||||||
|
* Copyright (C) 2015 Adithya Abraham Philip <adithyaphilip@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.sufficientlysecure.keychain.operations;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import org.spongycastle.bcpg.HashAlgorithmTags;
|
||||||
|
import org.spongycastle.bcpg.S2K;
|
||||||
|
import org.spongycastle.bcpg.SymmetricKeyAlgorithmTags;
|
||||||
|
import org.spongycastle.openpgp.PGPException;
|
||||||
|
import org.spongycastle.openpgp.operator.PBEDataDecryptorFactory;
|
||||||
|
import org.spongycastle.openpgp.operator.PGPDigestCalculatorProvider;
|
||||||
|
import org.spongycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
|
||||||
|
import org.spongycastle.openpgp.operator.jcajce.JcePBEDataDecryptorFactoryBuilder;
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.BenchmarkResult;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
|
||||||
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
|
import org.sufficientlysecure.keychain.service.BenchmarkInputParcel;
|
||||||
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||||
|
|
||||||
|
|
||||||
|
public class BenchmarkOperation extends BaseOperation<BenchmarkInputParcel> {
|
||||||
|
|
||||||
|
public BenchmarkOperation(Context context, ProviderHelper providerHelper, Progressable
|
||||||
|
progressable) {
|
||||||
|
super(context, providerHelper, progressable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public BenchmarkResult execute(BenchmarkInputParcel consolidateInputParcel,
|
||||||
|
CryptoInputParcel cryptoInputParcel) {
|
||||||
|
OperationLog log = new OperationLog();
|
||||||
|
log.add(LogType.MSG_BENCH, 0);
|
||||||
|
|
||||||
|
// random data
|
||||||
|
byte[] buf = new byte[1024*1024*5];
|
||||||
|
new Random().nextBytes(buf);
|
||||||
|
|
||||||
|
Passphrase passphrase = new Passphrase("a");
|
||||||
|
|
||||||
|
int numRepeats = 5;
|
||||||
|
long totalTime = 0;
|
||||||
|
|
||||||
|
// encrypt
|
||||||
|
SignEncryptResult encryptResult;
|
||||||
|
int i = 0;
|
||||||
|
do {
|
||||||
|
SignEncryptOperation op =
|
||||||
|
new SignEncryptOperation(mContext, mProviderHelper,
|
||||||
|
new ProgressScaler(mProgressable, i*(50/numRepeats), (i+1)*(50/numRepeats), 100), mCancelled);
|
||||||
|
SignEncryptParcel input = new SignEncryptParcel();
|
||||||
|
input.setSymmetricPassphrase(passphrase);
|
||||||
|
input.setBytes(buf);
|
||||||
|
encryptResult = op.execute(input, new CryptoInputParcel());
|
||||||
|
log.add(encryptResult, 1);
|
||||||
|
log.add(LogType.MSG_BENCH_ENC_TIME, 2,
|
||||||
|
String.format("%.2f", encryptResult.getResults().get(0).mOperationTime / 1000.0));
|
||||||
|
totalTime += encryptResult.getResults().get(0).mOperationTime;
|
||||||
|
} while (++i < numRepeats);
|
||||||
|
|
||||||
|
long encryptionTime = totalTime / numRepeats;
|
||||||
|
totalTime = 0;
|
||||||
|
|
||||||
|
// decrypt
|
||||||
|
i = 0;
|
||||||
|
do {
|
||||||
|
DecryptVerifyResult decryptResult;
|
||||||
|
PgpDecryptVerifyOperation op =
|
||||||
|
new PgpDecryptVerifyOperation(mContext, mProviderHelper,
|
||||||
|
new ProgressScaler(mProgressable, 50 +i*(50/numRepeats), 50 +(i+1)*(50/numRepeats), 100));
|
||||||
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(encryptResult.getResultBytes());
|
||||||
|
input.setAllowSymmetricDecryption(true);
|
||||||
|
decryptResult = op.execute(input, new CryptoInputParcel(passphrase));
|
||||||
|
log.add(decryptResult, 1);
|
||||||
|
log.add(LogType.MSG_BENCH_DEC_TIME, 2, String.format("%.2f", decryptResult.mOperationTime / 1000.0));
|
||||||
|
totalTime += decryptResult.mOperationTime;
|
||||||
|
} while (++i < numRepeats);
|
||||||
|
|
||||||
|
long decryptionTime = totalTime / numRepeats;
|
||||||
|
totalTime = 0;
|
||||||
|
|
||||||
|
int iterationsFor100ms;
|
||||||
|
try {
|
||||||
|
PGPDigestCalculatorProvider digestCalcProvider = new JcaPGPDigestCalculatorProviderBuilder()
|
||||||
|
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build();
|
||||||
|
PBEDataDecryptorFactory decryptorFactory = new JcePBEDataDecryptorFactoryBuilder(
|
||||||
|
digestCalcProvider).setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(
|
||||||
|
"".toCharArray());
|
||||||
|
|
||||||
|
byte[] iv = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||||
|
int iterations = 0;
|
||||||
|
while (iterations < 255 && totalTime < 100) {
|
||||||
|
iterations += 1;
|
||||||
|
|
||||||
|
S2K s2k = new S2K(HashAlgorithmTags.SHA1, iv, iterations);
|
||||||
|
totalTime = System.currentTimeMillis();
|
||||||
|
decryptorFactory.makeKeyFromPassPhrase(SymmetricKeyAlgorithmTags.AES_128, s2k);
|
||||||
|
totalTime = System.currentTimeMillis() -totalTime;
|
||||||
|
|
||||||
|
if ((iterations % 10) == 0) {
|
||||||
|
log.add(LogType.MSG_BENCH_S2K_FOR_IT, 1, Integer.toString(iterations), Long.toString(totalTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
iterationsFor100ms = iterations;
|
||||||
|
|
||||||
|
} catch (PGPException e) {
|
||||||
|
Log.e(Constants.TAG, "internal error during benchmark", e);
|
||||||
|
log.add(LogType.MSG_INTERNAL_ERROR, 0);
|
||||||
|
return new BenchmarkResult(BenchmarkResult.RESULT_ERROR, log);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.add(LogType.MSG_BENCH_S2K_100MS_ITS, 1, Integer.toString(iterationsFor100ms));
|
||||||
|
log.add(LogType.MSG_BENCH_ENC_TIME_AVG, 1, String.format("%.2f", encryptionTime/1000.0));
|
||||||
|
log.add(LogType.MSG_BENCH_DEC_TIME_AVG, 1, String.format("%.2f", decryptionTime/1000.0));
|
||||||
|
|
||||||
|
log.add(LogType.MSG_BENCH_SUCCESS, 0);
|
||||||
|
return new BenchmarkResult(BenchmarkResult.RESULT_OK, log);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
* Copyright (C) 2014 Vincent Breitmoser <v.breitmoser@mugenguild.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.sufficientlysecure.keychain.operations.results;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
|
||||||
|
|
||||||
|
public class BenchmarkResult extends OperationResult {
|
||||||
|
|
||||||
|
public BenchmarkResult(int result, OperationLog log) {
|
||||||
|
super(result, log);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Construct from a parcel - trivial because we have no extra data. */
|
||||||
|
public BenchmarkResult(Parcel source) {
|
||||||
|
super(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
super.writeToParcel(dest, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Creator<BenchmarkResult> CREATOR = new Creator<BenchmarkResult>() {
|
||||||
|
public BenchmarkResult createFromParcel(final Parcel source) {
|
||||||
|
return new BenchmarkResult(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BenchmarkResult[] newArray(final int size) {
|
||||||
|
return new BenchmarkResult[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -39,6 +39,8 @@ public class DecryptVerifyResult extends InputPendingResult {
|
|||||||
|
|
||||||
byte[] mOutputBytes;
|
byte[] mOutputBytes;
|
||||||
|
|
||||||
|
public long mOperationTime;
|
||||||
|
|
||||||
public DecryptVerifyResult(int result, OperationLog log) {
|
public DecryptVerifyResult(int result, OperationLog log) {
|
||||||
super(result, log);
|
super(result, log);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -874,6 +874,16 @@ public abstract class OperationResult implements Parcelable {
|
|||||||
MSG_LV_FETCH_ERROR_IO (LogLevel.ERROR, R.string.msg_lv_fetch_error_io),
|
MSG_LV_FETCH_ERROR_IO (LogLevel.ERROR, R.string.msg_lv_fetch_error_io),
|
||||||
MSG_LV_FETCH_ERROR_FORMAT(LogLevel.ERROR, R.string.msg_lv_fetch_error_format),
|
MSG_LV_FETCH_ERROR_FORMAT(LogLevel.ERROR, R.string.msg_lv_fetch_error_format),
|
||||||
MSG_LV_FETCH_ERROR_NOTHING (LogLevel.ERROR, R.string.msg_lv_fetch_error_nothing),
|
MSG_LV_FETCH_ERROR_NOTHING (LogLevel.ERROR, R.string.msg_lv_fetch_error_nothing),
|
||||||
|
|
||||||
|
MSG_BENCH (LogLevel.START, R.string.msg_bench),
|
||||||
|
MSG_BENCH_ENC_TIME (LogLevel.DEBUG, R.string.msg_bench_enc_time),
|
||||||
|
MSG_BENCH_ENC_TIME_AVG (LogLevel.INFO, R.string.msg_bench_enc_time_avg),
|
||||||
|
MSG_BENCH_DEC_TIME (LogLevel.DEBUG, R.string.msg_bench_dec_time),
|
||||||
|
MSG_BENCH_DEC_TIME_AVG (LogLevel.INFO, R.string.msg_bench_enc_time_avg),
|
||||||
|
MSG_BENCH_S2K_FOR_IT (LogLevel.DEBUG, R.string.msg_bench_s2k_for_it),
|
||||||
|
MSG_BENCH_S2K_100MS_ITS (LogLevel.INFO, R.string.msg_bench_s2k_100ms_its),
|
||||||
|
MSG_BENCH_SUCCESS (LogLevel.OK, R.string.msg_bench_success),
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
public final int mMsgId;
|
public final int mMsgId;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
|||||||
public class PgpSignEncryptResult extends InputPendingResult {
|
public class PgpSignEncryptResult extends InputPendingResult {
|
||||||
|
|
||||||
byte[] mDetachedSignature;
|
byte[] mDetachedSignature;
|
||||||
|
public long mOperationTime;
|
||||||
|
|
||||||
public void setDetachedSignature(byte[] detachedSignature) {
|
public void setDetachedSignature(byte[] detachedSignature) {
|
||||||
mDetachedSignature = detachedSignature;
|
mDetachedSignature = detachedSignature;
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ public class SignEncryptResult extends InputPendingResult {
|
|||||||
return mResultBytes;
|
return mResultBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<PgpSignEncryptResult> getResults() {
|
||||||
|
return mResults;
|
||||||
|
}
|
||||||
|
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||||||
InputData inputData;
|
InputData inputData;
|
||||||
OutputStream outputStream;
|
OutputStream outputStream;
|
||||||
|
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
if (input.getInputBytes() != null) {
|
if (input.getInputBytes() != null) {
|
||||||
byte[] inputBytes = input.getInputBytes();
|
byte[] inputBytes = input.getInputBytes();
|
||||||
inputData = new InputData(new ByteArrayInputStream(inputBytes), inputBytes.length);
|
inputData = new InputData(new ByteArrayInputStream(inputBytes), inputBytes.length);
|
||||||
@@ -122,6 +124,8 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||||||
result.setOutputBytes(outputData);
|
result.setOutputBytes(outputData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.mOperationTime = System.currentTimeMillis() - startTime;
|
||||||
|
Log.d(Constants.TAG, "total time taken: " + String.format("%.2f", result.mOperationTime / 1000.0) + "s");
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -425,10 +429,12 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||||||
|
|
||||||
InputStream dataIn = literalData.getInputStream();
|
InputStream dataIn = literalData.getInputStream();
|
||||||
|
|
||||||
|
long opTime, startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
long alreadyWritten = 0;
|
long alreadyWritten = 0;
|
||||||
long wholeSize = 0; // TODO inputData.getSize() - inputData.getStreamPosition();
|
long wholeSize = 0; // TODO inputData.getSize() - inputData.getStreamPosition();
|
||||||
int length;
|
int length;
|
||||||
byte[] buffer = new byte[1 << 16];
|
byte[] buffer = new byte[8192];
|
||||||
byte[] firstBytes = new byte[48];
|
byte[] firstBytes = new byte[48];
|
||||||
while ((length = dataIn.read(buffer)) > 0) {
|
while ((length = dataIn.read(buffer)) > 0) {
|
||||||
// Log.d(Constants.TAG, "read bytes: " + length);
|
// Log.d(Constants.TAG, "read bytes: " + length);
|
||||||
@@ -456,6 +462,20 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (signatureChecker.isInitialized()) {
|
||||||
|
|
||||||
|
Object o = plainFact.nextObject();
|
||||||
|
boolean signatureCheckOk = signatureChecker.verifySignatureOnePass(o, log, indent + 1);
|
||||||
|
|
||||||
|
if (!signatureCheckOk) {
|
||||||
|
return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
opTime = System.currentTimeMillis()-startTime;
|
||||||
|
Log.d(Constants.TAG, "decrypt time taken: " + String.format("%.2f", opTime / 1000.0) + "s");
|
||||||
|
|
||||||
// special treatment to detect pgp mime types
|
// special treatment to detect pgp mime types
|
||||||
if (matchesPrefix(firstBytes, "-----BEGIN PGP PUBLIC KEY BLOCK-----")
|
if (matchesPrefix(firstBytes, "-----BEGIN PGP PUBLIC KEY BLOCK-----")
|
||||||
|| matchesPrefix(firstBytes, "-----BEGIN PGP PRIVATE KEY BLOCK-----")) {
|
|| matchesPrefix(firstBytes, "-----BEGIN PGP PRIVATE KEY BLOCK-----")) {
|
||||||
@@ -470,17 +490,6 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||||||
metadata = new OpenPgpMetadata(
|
metadata = new OpenPgpMetadata(
|
||||||
originalFilename, mimeType, literalData.getModificationTime().getTime(), alreadyWritten, charset);
|
originalFilename, mimeType, literalData.getModificationTime().getTime(), alreadyWritten, charset);
|
||||||
|
|
||||||
if (signatureChecker.isInitialized()) {
|
|
||||||
|
|
||||||
Object o = plainFact.nextObject();
|
|
||||||
boolean signatureCheckOk = signatureChecker.verifySignatureOnePass(o, log, indent + 1);
|
|
||||||
|
|
||||||
if (!signatureCheckOk) {
|
|
||||||
return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
indent -= 1;
|
indent -= 1;
|
||||||
|
|
||||||
if (esResult != null) {
|
if (esResult != null) {
|
||||||
@@ -513,6 +522,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||||||
result.setSignatureResult(signatureChecker.getSignatureResult());
|
result.setSignatureResult(signatureChecker.getSignatureResult());
|
||||||
result.setDecryptionResult(decryptionResultBuilder.build());
|
result.setDecryptionResult(decryptionResultBuilder.build());
|
||||||
result.setDecryptionMetadata(metadata);
|
result.setDecryptionMetadata(metadata);
|
||||||
|
result.mOperationTime = opTime;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
|||||||
@@ -321,6 +321,8 @@ public class PgpSignEncryptOperation extends BaseOperation {
|
|||||||
ArmoredOutputStream detachedArmorOut = null;
|
ArmoredOutputStream detachedArmorOut = null;
|
||||||
BCPGOutputStream detachedBcpgOut = null;
|
BCPGOutputStream detachedBcpgOut = null;
|
||||||
|
|
||||||
|
long opTime, startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (enableEncryption) {
|
if (enableEncryption) {
|
||||||
@@ -516,6 +518,10 @@ public class PgpSignEncryptOperation extends BaseOperation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opTime = System.currentTimeMillis() -startTime;
|
||||||
|
Log.d(Constants.TAG, "sign/encrypt time taken: " + String.format("%.2f",
|
||||||
|
opTime / 1000.0) + "s");
|
||||||
|
|
||||||
// closing outputs
|
// closing outputs
|
||||||
// NOTE: closing needs to be done in the correct order!
|
// NOTE: closing needs to be done in the correct order!
|
||||||
if (encryptionOut != null) {
|
if (encryptionOut != null) {
|
||||||
@@ -559,6 +565,7 @@ public class PgpSignEncryptOperation extends BaseOperation {
|
|||||||
|
|
||||||
log.add(LogType.MSG_PSE_OK, indent);
|
log.add(LogType.MSG_PSE_OK, indent);
|
||||||
PgpSignEncryptResult result = new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_OK, log);
|
PgpSignEncryptResult result = new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_OK, log);
|
||||||
|
result.mOperationTime = opTime;
|
||||||
if (detachedByteOut != null) {
|
if (detachedByteOut != null) {
|
||||||
try {
|
try {
|
||||||
detachedByteOut.flush();
|
detachedByteOut.flush();
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
* Copyright (C) 2015 Vincent Breitmoser <v.breitmoser@mugenguild.com>
|
||||||
|
* Copyright (C) 2015 Adithya Abraham Philip <adithyaphilip@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.sufficientlysecure.keychain.service;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
|
||||||
|
public class BenchmarkInputParcel implements Parcelable {
|
||||||
|
|
||||||
|
public BenchmarkInputParcel() {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected BenchmarkInputParcel(Parcel in) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<BenchmarkInputParcel> CREATOR = new Creator<BenchmarkInputParcel>() {
|
||||||
|
@Override
|
||||||
|
public BenchmarkInputParcel createFromParcel(Parcel in) {
|
||||||
|
return new BenchmarkInputParcel(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BenchmarkInputParcel[] newArray(int size) {
|
||||||
|
return new BenchmarkInputParcel[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ import android.os.RemoteException;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.operations.BaseOperation;
|
import org.sufficientlysecure.keychain.operations.BaseOperation;
|
||||||
|
import org.sufficientlysecure.keychain.operations.BenchmarkOperation;
|
||||||
import org.sufficientlysecure.keychain.operations.CertifyOperation;
|
import org.sufficientlysecure.keychain.operations.CertifyOperation;
|
||||||
import org.sufficientlysecure.keychain.operations.ConsolidateOperation;
|
import org.sufficientlysecure.keychain.operations.ConsolidateOperation;
|
||||||
import org.sufficientlysecure.keychain.operations.DeleteOperation;
|
import org.sufficientlysecure.keychain.operations.DeleteOperation;
|
||||||
@@ -135,6 +136,8 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
op = new KeybaseVerificationOperation(outerThis, new ProviderHelper(outerThis), outerThis);
|
op = new KeybaseVerificationOperation(outerThis, new ProviderHelper(outerThis), outerThis);
|
||||||
} else if (inputParcel instanceof InputDataParcel) {
|
} else if (inputParcel instanceof InputDataParcel) {
|
||||||
op = new InputDataOperation(outerThis, new ProviderHelper(outerThis), outerThis);
|
op = new InputDataOperation(outerThis, new ProviderHelper(outerThis), outerThis);
|
||||||
|
} else if (inputParcel instanceof BenchmarkInputParcel) {
|
||||||
|
op = new BenchmarkOperation(outerThis, new ProviderHelper(outerThis), outerThis);
|
||||||
} else {
|
} else {
|
||||||
throw new AssertionError("Unrecognized input parcel in KeychainService!");
|
throw new AssertionError("Unrecognized input parcel in KeychainService!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ import com.getbase.floatingactionbutton.FloatingActionsMenu;
|
|||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.BenchmarkResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.ConsolidateResult;
|
import org.sufficientlysecure.keychain.operations.results.ConsolidateResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
@@ -64,6 +65,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
|
|||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
|
import org.sufficientlysecure.keychain.service.BenchmarkInputParcel;
|
||||||
import org.sufficientlysecure.keychain.service.ConsolidateInputParcel;
|
import org.sufficientlysecure.keychain.service.ConsolidateInputParcel;
|
||||||
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter;
|
||||||
@@ -415,6 +417,7 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
|
|
||||||
if (Constants.DEBUG) {
|
if (Constants.DEBUG) {
|
||||||
menu.findItem(R.id.menu_key_list_debug_cons).setVisible(true);
|
menu.findItem(R.id.menu_key_list_debug_cons).setVisible(true);
|
||||||
|
menu.findItem(R.id.menu_key_list_debug_bench).setVisible(true);
|
||||||
menu.findItem(R.id.menu_key_list_debug_read).setVisible(true);
|
menu.findItem(R.id.menu_key_list_debug_read).setVisible(true);
|
||||||
menu.findItem(R.id.menu_key_list_debug_write).setVisible(true);
|
menu.findItem(R.id.menu_key_list_debug_write).setVisible(true);
|
||||||
menu.findItem(R.id.menu_key_list_debug_first_time).setVisible(true);
|
menu.findItem(R.id.menu_key_list_debug_first_time).setVisible(true);
|
||||||
@@ -498,6 +501,10 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
consolidate();
|
consolidate();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case R.id.menu_key_list_debug_bench:
|
||||||
|
benchmark();
|
||||||
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
@@ -638,6 +645,43 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
mConsolidateOpHelper.cryptoOperation();
|
mConsolidateOpHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void benchmark() {
|
||||||
|
|
||||||
|
CryptoOperationHelper.Callback<BenchmarkInputParcel, BenchmarkResult> callback
|
||||||
|
= new CryptoOperationHelper.Callback<BenchmarkInputParcel, BenchmarkResult>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BenchmarkInputParcel createOperationInput() {
|
||||||
|
return new BenchmarkInputParcel(); // we want to perform a full consolidate
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCryptoOperationSuccess(BenchmarkResult result) {
|
||||||
|
result.createNotify(getActivity()).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCryptoOperationCancelled() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCryptoOperationError(BenchmarkResult result) {
|
||||||
|
result.createNotify(getActivity()).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCryptoSetProgress(String msg, int progress, int max) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
CryptoOperationHelper opHelper =
|
||||||
|
new CryptoOperationHelper<>(2, this, callback, R.string.progress_importing);
|
||||||
|
|
||||||
|
opHelper.cryptoOperation();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (mImportOpHelper != null) {
|
if (mImportOpHelper != null) {
|
||||||
|
|||||||
@@ -25,6 +25,12 @@
|
|||||||
android:visible="false"
|
android:visible="false"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_key_list_debug_bench"
|
||||||
|
android:title="Debug / Benchmark"
|
||||||
|
android:visible="false"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_key_list_debug_read"
|
android:id="@+id/menu_key_list_debug_read"
|
||||||
android:title="Debug / DB restore"
|
android:title="Debug / DB restore"
|
||||||
|
|||||||
@@ -397,6 +397,7 @@
|
|||||||
<string name="progress_cancelling">"cancelling…"</string>
|
<string name="progress_cancelling">"cancelling…"</string>
|
||||||
<string name="progress_saving">"saving…"</string>
|
<string name="progress_saving">"saving…"</string>
|
||||||
<string name="progress_importing">"importing…"</string>
|
<string name="progress_importing">"importing…"</string>
|
||||||
|
<string name="progress_benchmarking">"benchmarking…"</string>
|
||||||
<string name="progress_revoking_uploading">"Revoking and uploading key…"</string>
|
<string name="progress_revoking_uploading">"Revoking and uploading key…"</string>
|
||||||
<string name="progress_updating">"Updating keys…"</string>
|
<string name="progress_updating">"Updating keys…"</string>
|
||||||
<string name="progress_exporting">"exporting…"</string>
|
<string name="progress_exporting">"exporting…"</string>
|
||||||
@@ -1363,6 +1364,15 @@
|
|||||||
<string name="msg_lv_fetch_error_format">"Format error!"</string>
|
<string name="msg_lv_fetch_error_format">"Format error!"</string>
|
||||||
<string name="msg_lv_fetch_error_nothing">"Resource not found!"</string>
|
<string name="msg_lv_fetch_error_nothing">"Resource not found!"</string>
|
||||||
|
|
||||||
|
<string name="msg_bench">"Benchmarking some operations…"</string>
|
||||||
|
<string name="msg_bench_enc_time">"Encryption time: %ss"</string>
|
||||||
|
<string name="msg_bench_enc_time_avg">"Average time to encrypt 5M: %ss"</string>
|
||||||
|
<string name="msg_bench_dec_time">"Decryption time: %ss"</string>
|
||||||
|
<string name="msg_bench_dec_time_avg">"Average time to decrypt 5M: %ss"</string>
|
||||||
|
<string name="msg_bench_s2k_100ms_its">"S2K Iteration Count for 100ms: %s"</string>
|
||||||
|
<string name="msg_bench_s2k_for_it">"Time for %1$s SHA1 S2K iterations: %2$sms"</string>
|
||||||
|
<string name="msg_bench_success">"Benchmarking complete!"</string>
|
||||||
|
|
||||||
<string name="msg_data">"Processing input data"</string>
|
<string name="msg_data">"Processing input data"</string>
|
||||||
<string name="msg_data_openpgp">"Attempting to process OpenPGP data"</string>
|
<string name="msg_data_openpgp">"Attempting to process OpenPGP data"</string>
|
||||||
<string name="msg_data_detached">"Encountered detached signature"</string>
|
<string name="msg_data_detached">"Encountered detached signature"</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user