export: externalize upload into its own operation
This commit is contained in:
@@ -17,15 +17,20 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.operations;
|
||||
|
||||
|
||||
import java.net.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
|
||||
import org.sufficientlysecure.keychain.operations.results.CertifyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.UploadResult;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
|
||||
@@ -48,10 +53,6 @@ import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
|
||||
import java.net.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* An operation which implements a high level user id certification operation.
|
||||
* <p/>
|
||||
@@ -205,11 +206,11 @@ public class CertifyOperation extends BaseOperation<CertifyActionsParcel> {
|
||||
|
||||
// these variables are used inside the following loop, but they need to be created only once
|
||||
HkpKeyserver keyServer = null;
|
||||
ExportOperation exportOperation = null;
|
||||
UploadOperation uploadOperation = null;
|
||||
Proxy proxy = null;
|
||||
if (parcel.keyServerUri != null) {
|
||||
keyServer = new HkpKeyserver(parcel.keyServerUri);
|
||||
exportOperation = new ExportOperation(mContext, mProviderHelper, mProgressable);
|
||||
uploadOperation = new UploadOperation(mContext, mProviderHelper, mProgressable);
|
||||
if (cryptoInput.getParcelableProxy() == null) {
|
||||
// explicit proxy not set
|
||||
if (!OrbotHelper.isOrbotInRequiredState(mContext)) {
|
||||
@@ -239,8 +240,8 @@ public class CertifyOperation extends BaseOperation<CertifyActionsParcel> {
|
||||
mProviderHelper.clearLog();
|
||||
SaveKeyringResult result = mProviderHelper.savePublicKeyRing(certifiedKey);
|
||||
|
||||
if (exportOperation != null) {
|
||||
ExportResult uploadResult = exportOperation.uploadKeyRingToServer(
|
||||
if (uploadOperation != null) {
|
||||
UploadResult uploadResult = uploadOperation.uploadKeyRingToServer(
|
||||
keyServer,
|
||||
certifiedKey,
|
||||
proxy);
|
||||
|
||||
@@ -20,30 +20,24 @@ package org.sufficientlysecure.keychain.operations;
|
||||
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Proxy;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.spongycastle.bcpg.ArmoredOutputStream;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
|
||||
import org.sufficientlysecure.keychain.keyimport.Keyserver.AddKeyException;
|
||||
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
@@ -52,11 +46,9 @@ import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.ExportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
|
||||
|
||||
/**
|
||||
* An operation class which implements high level export
|
||||
@@ -93,107 +85,24 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
|
||||
|
||||
@NonNull
|
||||
public ExportResult execute(ExportKeyringParcel exportInput, CryptoInputParcel cryptoInput) {
|
||||
switch (exportInput.mExportType) {
|
||||
case UPLOAD_KEYSERVER: {
|
||||
Proxy proxy;
|
||||
if (cryptoInput.getParcelableProxy() == null) {
|
||||
// explicit proxy not set
|
||||
if (!OrbotHelper.isOrbotInRequiredState(mContext)) {
|
||||
return new ExportResult(null,
|
||||
RequiredInputParcel.createOrbotRequiredOperation(), cryptoInput);
|
||||
}
|
||||
proxy = Preferences.getPreferences(mContext).getProxyPrefs()
|
||||
.parcelableProxy.getProxy();
|
||||
} else {
|
||||
proxy = cryptoInput.getParcelableProxy().getProxy();
|
||||
}
|
||||
|
||||
HkpKeyserver hkpKeyserver = new HkpKeyserver(exportInput.mKeyserver);
|
||||
try {
|
||||
if (exportInput.mCanonicalizedPublicKeyringUri != null) {
|
||||
CanonicalizedPublicKeyRing keyring
|
||||
= mProviderHelper.getCanonicalizedPublicKeyRing(
|
||||
exportInput.mCanonicalizedPublicKeyringUri);
|
||||
return uploadKeyRingToServer(hkpKeyserver, keyring.getUncachedKeyRing(), proxy);
|
||||
} else {
|
||||
return uploadKeyRingToServer(hkpKeyserver, exportInput.mUncachedKeyRing, proxy);
|
||||
}
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
Log.e(Constants.TAG, "error uploading key", e);
|
||||
return new ExportResult(ExportResult.RESULT_ERROR, new OperationLog());
|
||||
}
|
||||
}
|
||||
case EXPORT_URI: {
|
||||
return exportToUri(exportInput.mMasterKeyIds, exportInput.mExportSecret, exportInput.mOutputUri);
|
||||
}
|
||||
default: { // can never happen, all enum types must be handled above
|
||||
throw new AssertionError("must not happen, this is a bug!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ExportResult uploadKeyRingToServer(HkpKeyserver server, UncachedKeyRing keyring, Proxy proxy) {
|
||||
mProgressable.setProgress(R.string.progress_uploading, 0, 1);
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ArmoredOutputStream aos = null;
|
||||
OperationLog log = new OperationLog();
|
||||
log.add(LogType.MSG_EXPORT_UPLOAD_PUBLIC, 0, KeyFormattingUtils.convertKeyIdToHex(
|
||||
keyring.getPublicKey().getKeyId()
|
||||
));
|
||||
|
||||
try {
|
||||
aos = new ArmoredOutputStream(bos);
|
||||
keyring.encode(aos);
|
||||
aos.close();
|
||||
|
||||
String armoredKey = bos.toString("UTF-8");
|
||||
server.add(armoredKey, proxy);
|
||||
|
||||
log.add(LogType.MSG_EXPORT_UPLOAD_SUCCESS, 1);
|
||||
return new ExportResult(ExportResult.RESULT_OK, log);
|
||||
} catch (IOException e) {
|
||||
Log.e(Constants.TAG, "IOException", e);
|
||||
|
||||
log.add(LogType.MSG_EXPORT_ERROR_KEY, 1);
|
||||
return new ExportResult(ExportResult.RESULT_ERROR, log);
|
||||
} catch (AddKeyException e) {
|
||||
Log.e(Constants.TAG, "AddKeyException", e);
|
||||
|
||||
log.add(LogType.MSG_EXPORT_ERROR_UPLOAD, 1);
|
||||
return new ExportResult(ExportResult.RESULT_ERROR, log);
|
||||
} finally {
|
||||
mProgressable.setProgress(R.string.progress_uploading, 1, 1);
|
||||
try {
|
||||
if (aos != null) {
|
||||
aos.close();
|
||||
}
|
||||
bos.close();
|
||||
} catch (IOException e) {
|
||||
// this is just a finally thing, no matter if it doesn't work out.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ExportResult exportToUri(long[] masterKeyIds, boolean exportSecret, Uri outputUri) {
|
||||
|
||||
OperationLog log = new OperationLog();
|
||||
if (masterKeyIds != null) {
|
||||
log.add(LogType.MSG_EXPORT, 0, masterKeyIds.length);
|
||||
if (exportInput.mMasterKeyIds != null) {
|
||||
log.add(LogType.MSG_EXPORT, 0, exportInput.mMasterKeyIds.length);
|
||||
} else {
|
||||
log.add(LogType.MSG_EXPORT_ALL, 0);
|
||||
}
|
||||
|
||||
// do we have a file name?
|
||||
if (outputUri == null) {
|
||||
if (exportInput.mOutputUri == null) {
|
||||
log.add(LogType.MSG_EXPORT_ERROR_NO_URI, 1);
|
||||
return new ExportResult(ExportResult.RESULT_ERROR, log);
|
||||
}
|
||||
|
||||
try {
|
||||
OutputStream outStream = mProviderHelper.getContentResolver().openOutputStream(outputUri);
|
||||
OutputStream outStream = mProviderHelper.getContentResolver().openOutputStream(exportInput.mOutputUri);
|
||||
outStream = new BufferedOutputStream(outStream);
|
||||
return exportKeyRings(log, masterKeyIds, exportSecret, outStream);
|
||||
return exportKeyRings(log, exportInput.mMasterKeyIds, exportInput.mExportSecret, outStream);
|
||||
} catch (FileNotFoundException e) {
|
||||
log.add(LogType.MSG_EXPORT_ERROR_URI_OPEN, 1);
|
||||
return new ExportResult(ExportResult.RESULT_ERROR, log);
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
* Copyright (C) 2010-2014 Thialfihar <thi@thialfihar.org>
|
||||
* Copyright (C) 2015 Vincent Breitmoser <valodim@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;
|
||||
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Proxy;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.spongycastle.bcpg.ArmoredOutputStream;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
|
||||
import org.sufficientlysecure.keychain.keyimport.Keyserver.AddKeyException;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.operations.results.UploadResult;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.UploadKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
|
||||
|
||||
/**
|
||||
* An operation class which implements high level export operations.
|
||||
* This class receives a source and/or destination of keys as input and performs
|
||||
* all steps for this export.
|
||||
*
|
||||
* @see org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter#getSelectedEntries()
|
||||
* For the export operation, the input consists of a set of key ids and
|
||||
* either the name of a file or an output uri to write to.
|
||||
*/
|
||||
public class UploadOperation extends BaseOperation<UploadKeyringParcel> {
|
||||
|
||||
public UploadOperation(Context context, ProviderHelper providerHelper, Progressable
|
||||
progressable) {
|
||||
super(context, providerHelper, progressable);
|
||||
}
|
||||
|
||||
public UploadOperation(Context context, ProviderHelper providerHelper,
|
||||
Progressable progressable, AtomicBoolean cancelled) {
|
||||
super(context, providerHelper, progressable, cancelled);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public UploadResult execute(UploadKeyringParcel exportInput, CryptoInputParcel cryptoInput) {
|
||||
Proxy proxy;
|
||||
if (cryptoInput.getParcelableProxy() == null) {
|
||||
// explicit proxy not set
|
||||
if (!OrbotHelper.isOrbotInRequiredState(mContext)) {
|
||||
return new UploadResult(null, RequiredInputParcel.createOrbotRequiredOperation(), cryptoInput);
|
||||
}
|
||||
proxy = Preferences.getPreferences(mContext).getProxyPrefs().parcelableProxy.getProxy();
|
||||
} else {
|
||||
proxy = cryptoInput.getParcelableProxy().getProxy();
|
||||
}
|
||||
|
||||
HkpKeyserver hkpKeyserver = new HkpKeyserver(exportInput.mKeyserver);
|
||||
try {
|
||||
CanonicalizedPublicKeyRing keyring = mProviderHelper.getCanonicalizedPublicKeyRing(
|
||||
exportInput.mCanonicalizedPublicKeyringUri);
|
||||
return uploadKeyRingToServer(hkpKeyserver, keyring.getUncachedKeyRing(), proxy);
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
Log.e(Constants.TAG, "error uploading key", e);
|
||||
return new UploadResult(UploadResult.RESULT_ERROR, new OperationLog());
|
||||
}
|
||||
}
|
||||
|
||||
public UploadResult uploadKeyRingToServer(HkpKeyserver server, UncachedKeyRing keyring, Proxy proxy) {
|
||||
|
||||
mProgressable.setProgress(R.string.progress_uploading, 0, 1);
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ArmoredOutputStream aos = null;
|
||||
OperationLog log = new OperationLog();
|
||||
log.add(LogType.MSG_EXPORT_UPLOAD_PUBLIC, 0, KeyFormattingUtils.convertKeyIdToHex(
|
||||
keyring.getPublicKey().getKeyId()
|
||||
));
|
||||
|
||||
try {
|
||||
aos = new ArmoredOutputStream(bos);
|
||||
keyring.encode(aos);
|
||||
aos.close();
|
||||
|
||||
String armoredKey = bos.toString("UTF-8");
|
||||
server.add(armoredKey, proxy);
|
||||
|
||||
log.add(LogType.MSG_EXPORT_UPLOAD_SUCCESS, 1);
|
||||
return new UploadResult(UploadResult.RESULT_OK, log);
|
||||
} catch (IOException e) {
|
||||
Log.e(Constants.TAG, "IOException", e);
|
||||
|
||||
log.add(LogType.MSG_EXPORT_ERROR_KEY, 1);
|
||||
return new UploadResult(UploadResult.RESULT_ERROR, log);
|
||||
} catch (AddKeyException e) {
|
||||
Log.e(Constants.TAG, "AddKeyException", e);
|
||||
|
||||
log.add(LogType.MSG_EXPORT_ERROR_UPLOAD, 1);
|
||||
return new UploadResult(UploadResult.RESULT_ERROR, log);
|
||||
} finally {
|
||||
mProgressable.setProgress(R.string.progress_uploading, 1, 1);
|
||||
try {
|
||||
if (aos != null) {
|
||||
aos.close();
|
||||
}
|
||||
bos.close();
|
||||
} catch (IOException e) {
|
||||
// this is just a finally thing, no matter if it doesn't work out.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
|
||||
|
||||
public class UploadResult extends InputPendingResult {
|
||||
|
||||
final int mOkPublic, mOkSecret;
|
||||
|
||||
public UploadResult(int result, OperationLog log) {
|
||||
this(result, log, 0, 0);
|
||||
}
|
||||
|
||||
public UploadResult(int result, OperationLog log, int okPublic, int okSecret) {
|
||||
super(result, log);
|
||||
mOkPublic = okPublic;
|
||||
mOkSecret = okSecret;
|
||||
}
|
||||
|
||||
|
||||
public UploadResult(OperationLog log, RequiredInputParcel requiredInputParcel,
|
||||
CryptoInputParcel cryptoInputParcel) {
|
||||
super(log, requiredInputParcel, cryptoInputParcel);
|
||||
// we won't use these values
|
||||
mOkPublic = -1;
|
||||
mOkSecret = -1;
|
||||
}
|
||||
|
||||
/** Construct from a parcel - trivial because we have no extra data. */
|
||||
public UploadResult(Parcel source) {
|
||||
super(source);
|
||||
mOkPublic = source.readInt();
|
||||
mOkSecret = source.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeInt(mOkPublic);
|
||||
dest.writeInt(mOkSecret);
|
||||
}
|
||||
|
||||
public static Creator<UploadResult> CREATOR = new Creator<UploadResult>() {
|
||||
public UploadResult createFromParcel(final Parcel source) {
|
||||
return new UploadResult(source);
|
||||
}
|
||||
|
||||
public UploadResult[] newArray(final int size) {
|
||||
return new UploadResult[size];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -32,30 +32,15 @@ public class ExportKeyringParcel implements Parcelable {
|
||||
|
||||
public boolean mExportSecret;
|
||||
public long mMasterKeyIds[];
|
||||
public String mOutputFile;
|
||||
public Uri mOutputUri;
|
||||
public ExportType mExportType;
|
||||
|
||||
public enum ExportType {
|
||||
UPLOAD_KEYSERVER,
|
||||
EXPORT_URI
|
||||
}
|
||||
|
||||
public ExportKeyringParcel(String keyserver, Uri keyringUri) {
|
||||
mExportType = ExportType.UPLOAD_KEYSERVER;
|
||||
mKeyserver = keyserver;
|
||||
mCanonicalizedPublicKeyringUri = keyringUri;
|
||||
}
|
||||
|
||||
public ExportKeyringParcel(String keyserver, UncachedKeyRing uncachedKeyRing) {
|
||||
mExportType = ExportType.UPLOAD_KEYSERVER;
|
||||
mKeyserver = keyserver;
|
||||
mUncachedKeyRing = uncachedKeyRing;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused") // TODO: is it used?
|
||||
public ExportKeyringParcel(long[] masterKeyIds, boolean exportSecret, Uri outputUri) {
|
||||
mExportType = ExportType.EXPORT_URI;
|
||||
mMasterKeyIds = masterKeyIds;
|
||||
mExportSecret = exportSecret;
|
||||
mOutputUri = outputUri;
|
||||
@@ -66,9 +51,7 @@ public class ExportKeyringParcel implements Parcelable {
|
||||
mCanonicalizedPublicKeyringUri = (Uri) in.readValue(Uri.class.getClassLoader());
|
||||
mUncachedKeyRing = (UncachedKeyRing) in.readValue(UncachedKeyRing.class.getClassLoader());
|
||||
mExportSecret = in.readByte() != 0x00;
|
||||
mOutputFile = in.readString();
|
||||
mOutputUri = (Uri) in.readValue(Uri.class.getClassLoader());
|
||||
mExportType = (ExportType) in.readValue(ExportType.class.getClassLoader());
|
||||
mMasterKeyIds = in.createLongArray();
|
||||
}
|
||||
|
||||
@@ -83,9 +66,7 @@ public class ExportKeyringParcel implements Parcelable {
|
||||
dest.writeValue(mCanonicalizedPublicKeyringUri);
|
||||
dest.writeValue(mUncachedKeyRing);
|
||||
dest.writeByte((byte) (mExportSecret ? 0x01 : 0x00));
|
||||
dest.writeString(mOutputFile);
|
||||
dest.writeValue(mOutputUri);
|
||||
dest.writeValue(mExportType);
|
||||
dest.writeLongArray(mMasterKeyIds);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.sufficientlysecure.keychain.operations.InputDataOperation;
|
||||
import org.sufficientlysecure.keychain.operations.PromoteKeyOperation;
|
||||
import org.sufficientlysecure.keychain.operations.RevokeOperation;
|
||||
import org.sufficientlysecure.keychain.operations.SignEncryptOperation;
|
||||
import org.sufficientlysecure.keychain.operations.UploadOperation;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
|
||||
@@ -126,6 +127,8 @@ public class KeychainService extends Service implements Progressable {
|
||||
op = new ImportOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled);
|
||||
} else if (inputParcel instanceof ExportKeyringParcel) {
|
||||
op = new ExportOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled);
|
||||
} else if (inputParcel instanceof UploadKeyringParcel) {
|
||||
op = new UploadOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled);
|
||||
} else if (inputParcel instanceof ConsolidateInputParcel) {
|
||||
op = new ConsolidateOperation(outerThis, new ProviderHelper(outerThis), outerThis);
|
||||
} else if (inputParcel instanceof KeybaseVerificationParcel) {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
|
||||
public class UploadKeyringParcel implements Parcelable {
|
||||
public String mKeyserver;
|
||||
public Uri mCanonicalizedPublicKeyringUri;
|
||||
|
||||
public UploadKeyringParcel(String keyserver, Uri keyringUri) {
|
||||
mKeyserver = keyserver;
|
||||
mCanonicalizedPublicKeyringUri = keyringUri;
|
||||
}
|
||||
|
||||
protected UploadKeyringParcel(Parcel in) {
|
||||
mKeyserver = in.readString();
|
||||
mCanonicalizedPublicKeyringUri = (Uri) in.readValue(Uri.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(mKeyserver);
|
||||
dest.writeValue(mCanonicalizedPublicKeyringUri);
|
||||
}
|
||||
|
||||
public static final Creator<UploadKeyringParcel> CREATOR = new Creator<UploadKeyringParcel>() {
|
||||
@Override
|
||||
public UploadKeyringParcel createFromParcel(Parcel in) {
|
||||
return new UploadKeyringParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadKeyringParcel[] newArray(int size) {
|
||||
return new UploadKeyringParcel[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -37,17 +37,17 @@ import org.spongycastle.bcpg.sig.KeyFlags;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.UploadResult;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.ExportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.service.UploadKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
@@ -69,7 +69,7 @@ public class CreateKeyFinalFragment extends Fragment {
|
||||
|
||||
SaveKeyringParcel mSaveKeyringParcel;
|
||||
|
||||
private CryptoOperationHelper<ExportKeyringParcel, ExportResult> mUploadOpHelper;
|
||||
private CryptoOperationHelper<UploadKeyringParcel, UploadResult> mUploadOpHelper;
|
||||
private CryptoOperationHelper<SaveKeyringParcel, EditKeyResult> mCreateOpHelper;
|
||||
private CryptoOperationHelper<SaveKeyringParcel, EditKeyResult> mMoveToCardOpHelper;
|
||||
|
||||
@@ -411,16 +411,16 @@ public class CreateKeyFinalFragment extends Fragment {
|
||||
// upload to favorite keyserver
|
||||
final String keyserver = Preferences.getPreferences(activity).getPreferredKeyserver();
|
||||
|
||||
CryptoOperationHelper.Callback<ExportKeyringParcel, ExportResult> callback
|
||||
= new CryptoOperationHelper.Callback<ExportKeyringParcel, ExportResult>() {
|
||||
CryptoOperationHelper.Callback<UploadKeyringParcel, UploadResult> callback
|
||||
= new CryptoOperationHelper.Callback<UploadKeyringParcel, UploadResult>() {
|
||||
|
||||
@Override
|
||||
public ExportKeyringParcel createOperationInput() {
|
||||
return new ExportKeyringParcel(keyserver, blobUri);
|
||||
public UploadKeyringParcel createOperationInput() {
|
||||
return new UploadKeyringParcel(keyserver, blobUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationSuccess(ExportResult result) {
|
||||
public void onCryptoOperationSuccess(UploadResult result) {
|
||||
handleResult(result);
|
||||
}
|
||||
|
||||
@@ -430,11 +430,11 @@ public class CreateKeyFinalFragment extends Fragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationError(ExportResult result) {
|
||||
public void onCryptoOperationError(UploadResult result) {
|
||||
handleResult(result);
|
||||
}
|
||||
|
||||
public void handleResult(ExportResult result) {
|
||||
public void handleResult(UploadResult result) {
|
||||
saveKeyResult.getLog().add(result, 0);
|
||||
finishWithResult(saveKeyResult);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@@ -29,10 +30,10 @@ import android.widget.Spinner;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.UploadResult;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.service.ExportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.UploadKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
@@ -42,7 +43,7 @@ import org.sufficientlysecure.keychain.util.Preferences;
|
||||
* Sends the selected public key to a keyserver
|
||||
*/
|
||||
public class UploadKeyActivity extends BaseActivity
|
||||
implements CryptoOperationHelper.Callback<ExportKeyringParcel, ExportResult> {
|
||||
implements CryptoOperationHelper.Callback<UploadKeyringParcel, UploadResult> {
|
||||
private View mUploadButton;
|
||||
private Spinner mKeyServerSpinner;
|
||||
|
||||
@@ -51,7 +52,7 @@ public class UploadKeyActivity extends BaseActivity
|
||||
// CryptoOperationHelper.Callback vars
|
||||
private String mKeyserver;
|
||||
private Uri mUnifiedKeyringUri;
|
||||
private CryptoOperationHelper<ExportKeyringParcel, ExportResult> mUploadOpHelper;
|
||||
private CryptoOperationHelper<UploadKeyringParcel, UploadResult> mUploadOpHelper;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -107,7 +108,7 @@ public class UploadKeyActivity extends BaseActivity
|
||||
String server = (String) mKeyServerSpinner.getSelectedItem();
|
||||
mKeyserver = server;
|
||||
|
||||
mUploadOpHelper = new CryptoOperationHelper(1, this, this, R.string.progress_uploading);
|
||||
mUploadOpHelper = new CryptoOperationHelper<>(1, this, this, R.string.progress_uploading);
|
||||
mUploadOpHelper.cryptoOperation();
|
||||
}
|
||||
|
||||
@@ -125,12 +126,12 @@ public class UploadKeyActivity extends BaseActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExportKeyringParcel createOperationInput() {
|
||||
return new ExportKeyringParcel(mKeyserver, mUnifiedKeyringUri);
|
||||
public UploadKeyringParcel createOperationInput() {
|
||||
return new UploadKeyringParcel(mKeyserver, mUnifiedKeyringUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationSuccess(ExportResult result) {
|
||||
public void onCryptoOperationSuccess(UploadResult result) {
|
||||
result.createNotify(this).show();
|
||||
}
|
||||
|
||||
@@ -140,7 +141,7 @@ public class UploadKeyActivity extends BaseActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationError(ExportResult result) {
|
||||
public void onCryptoOperationError(UploadResult result) {
|
||||
result.createNotify(this).show();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user