added export and upload to KeychainNewService
This commit is contained in:
@@ -47,9 +47,10 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
||||
import org.sufficientlysecure.keychain.service.ExportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.ImportExportParcel;
|
||||
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
||||
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.FileHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
@@ -101,7 +102,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
* TODO rework uploadKeyRingToServer
|
||||
*
|
||||
*/
|
||||
public class ImportExportOperation extends BaseOperation<ImportKeyringParcel> {
|
||||
public class ImportExportOperation extends BaseOperation<ImportExportParcel> {
|
||||
|
||||
public ImportExportOperation(Context context, ProviderHelper providerHelper, Progressable progressable) {
|
||||
super(context, providerHelper, progressable);
|
||||
@@ -629,9 +630,44 @@ public class ImportExportOperation extends BaseOperation<ImportKeyringParcel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImportKeyResult execute(ImportKeyringParcel input, CryptoInputParcel cryptoInput) {
|
||||
|
||||
return importKeys(input.mKeyList, input.mKeyserver);
|
||||
public OperationResult execute(ImportExportParcel input, CryptoInputParcel cryptoInput) {
|
||||
if (input instanceof ExportKeyringParcel) {
|
||||
ExportKeyringParcel exportInput = (ExportKeyringParcel) input;
|
||||
switch (exportInput.mExportType) {
|
||||
case UPLOAD_KEYSERVER: {
|
||||
HkpKeyserver hkpKeyserver = new HkpKeyserver(exportInput.mKeyserver);
|
||||
try {
|
||||
CanonicalizedPublicKeyRing keyring
|
||||
= mProviderHelper.getCanonicalizedPublicKeyRing(
|
||||
exportInput.mCanonicalizedPublicKeyringUri);
|
||||
uploadKeyRingToServer(hkpKeyserver, keyring);
|
||||
// TODO: replace with proper log
|
||||
return new ExportResult(ExportResult.RESULT_OK, new OperationLog());
|
||||
} catch (Exception e) {
|
||||
// TODO: Implement better exception handling, replace with log
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EXPORT_FILE: {
|
||||
return exportToFile(exportInput.mMasterKeyIds, exportInput.mExportSecret,
|
||||
exportInput.mOutputFile);
|
||||
}
|
||||
case EXPORT_URI: {
|
||||
return exportToUri(exportInput.mMasterKeyIds, exportInput.mExportSecret,
|
||||
exportInput.mOutputUri);
|
||||
}
|
||||
default: {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (input instanceof ImportKeyringParcel) {
|
||||
ImportKeyringParcel importInput = (ImportKeyringParcel) input;
|
||||
return importKeys(importInput.mKeyList, importInput.mKeyserver);
|
||||
} else {
|
||||
throw new RuntimeException("Invalid input parcel at ImportExportOperation");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ImportKeyResult importKeys(ArrayList<ParcelableKeyRing> keyList, String keyServer) {
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package org.sufficientlysecure.keychain.service;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class ExportKeyringParcel extends ImportExportParcel implements Parcelable {
|
||||
public String mKeyserver;
|
||||
public Uri mCanonicalizedPublicKeyringUri;
|
||||
|
||||
public boolean mExportSecret;
|
||||
public long mMasterKeyIds[];
|
||||
public String mOutputFile;
|
||||
public Uri mOutputUri;
|
||||
public ExportType mExportType;
|
||||
|
||||
public enum ExportType {
|
||||
UPLOAD_KEYSERVER,
|
||||
EXPORT_FILE,
|
||||
EXPORT_URI
|
||||
}
|
||||
|
||||
public ExportKeyringParcel(String keyserver, Uri keyringUri) {
|
||||
mExportType = ExportType.UPLOAD_KEYSERVER;
|
||||
mKeyserver = keyserver;
|
||||
mCanonicalizedPublicKeyringUri = keyringUri;
|
||||
}
|
||||
|
||||
public ExportKeyringParcel(long[] masterKeyIds, boolean exportSecret, String outputFile) {
|
||||
mExportType = ExportType.EXPORT_FILE;
|
||||
mMasterKeyIds = masterKeyIds;
|
||||
mExportSecret = exportSecret;
|
||||
mOutputFile = outputFile;
|
||||
}
|
||||
|
||||
public ExportKeyringParcel(long[] masterKeyIds, boolean exportSecret, Uri outputUri) {
|
||||
mExportType = ExportType.EXPORT_URI;
|
||||
mMasterKeyIds = masterKeyIds;
|
||||
mExportSecret = exportSecret;
|
||||
mOutputUri = outputUri;
|
||||
}
|
||||
|
||||
protected ExportKeyringParcel(Parcel in) {
|
||||
mKeyserver = in.readString();
|
||||
mCanonicalizedPublicKeyringUri = (Uri) in.readValue(Uri.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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(mKeyserver);
|
||||
dest.writeValue(mCanonicalizedPublicKeyringUri);
|
||||
dest.writeByte((byte) (mExportSecret ? 0x01 : 0x00));
|
||||
dest.writeString(mOutputFile);
|
||||
dest.writeValue(mOutputUri);
|
||||
dest.writeValue(mExportType);
|
||||
dest.writeLongArray(mMasterKeyIds);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<ExportKeyringParcel> CREATOR = new Parcelable.Creator<ExportKeyringParcel>() {
|
||||
@Override
|
||||
public ExportKeyringParcel createFromParcel(Parcel in) {
|
||||
return new ExportKeyringParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExportKeyringParcel[] newArray(int size) {
|
||||
return new ExportKeyringParcel[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.sufficientlysecure.keychain.service;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* Empty class, simply serves as a base class for ImportKeyringParcel and ExportKeyringParcel
|
||||
*/
|
||||
public class ImportExportParcel implements Parcelable {
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ImportKeyringParcel implements Parcelable {
|
||||
public class ImportKeyringParcel extends ImportExportParcel {
|
||||
// if null, keys are expected to be read from a cache file in ImportExportOperations
|
||||
public ArrayList<ParcelableKeyRing> mKeyList;
|
||||
public String mKeyserver; // must be set if keys are to be imported from a keyserver
|
||||
|
||||
@@ -103,7 +103,8 @@ public class KeychainNewService extends Service implements Progressable {
|
||||
} else if (inputParcel instanceof CertifyAction) {
|
||||
op = new CertifyOperation(outerThis, new ProviderHelper(outerThis), outerThis,
|
||||
mActionCanceled);
|
||||
} else if (inputParcel instanceof ImportKeyringParcel){
|
||||
} else if (inputParcel instanceof ImportKeyringParcel
|
||||
|| inputParcel instanceof ExportKeyringParcel){
|
||||
op = new ImportExportOperation(outerThis, new ProviderHelper(outerThis),
|
||||
outerThis, mActionCanceled);
|
||||
} else {
|
||||
|
||||
@@ -91,11 +91,6 @@ public class KeychainService extends Service implements Progressable {
|
||||
|
||||
public static final String ACTION_PROMOTE_KEYRING = Constants.INTENT_PREFIX + "PROMOTE_KEYRING";
|
||||
|
||||
public static final String ACTION_IMPORT_KEYRING = Constants.INTENT_PREFIX + "IMPORT_KEYRING";
|
||||
public static final String ACTION_EXPORT_KEYRING = Constants.INTENT_PREFIX + "EXPORT_KEYRING";
|
||||
|
||||
public static final String ACTION_UPLOAD_KEYRING = Constants.INTENT_PREFIX + "UPLOAD_KEYRING";
|
||||
|
||||
public static final String ACTION_DELETE = Constants.INTENT_PREFIX + "DELETE";
|
||||
|
||||
public static final String ACTION_CONSOLIDATE = Constants.INTENT_PREFIX + "CONSOLIDATE";
|
||||
@@ -117,20 +112,6 @@ public class KeychainService extends Service implements Progressable {
|
||||
public static final String DELETE_KEY_LIST = "delete_list";
|
||||
public static final String DELETE_IS_SECRET = "delete_is_secret";
|
||||
|
||||
// import key
|
||||
public static final String IMPORT_KEY_LIST = "import_key_list";
|
||||
public static final String IMPORT_KEY_SERVER = "import_key_server";
|
||||
|
||||
// export key
|
||||
public static final String EXPORT_FILENAME = "export_filename";
|
||||
public static final String EXPORT_URI = "export_uri";
|
||||
public static final String EXPORT_SECRET = "export_secret";
|
||||
public static final String EXPORT_ALL = "export_all";
|
||||
public static final String EXPORT_KEY_RING_MASTER_KEY_ID = "export_key_ring_id";
|
||||
|
||||
// upload key
|
||||
public static final String UPLOAD_KEY_SERVER = "upload_key_server";
|
||||
|
||||
// promote key
|
||||
public static final String PROMOTE_MASTER_KEY_ID = "promote_master_key_id";
|
||||
public static final String PROMOTE_CARD_AID = "promote_card_aid";
|
||||
@@ -354,76 +335,6 @@ public class KeychainService extends Service implements Progressable {
|
||||
|
||||
break;
|
||||
}
|
||||
case ACTION_EXPORT_KEYRING: {
|
||||
|
||||
// Input
|
||||
boolean exportSecret = data.getBoolean(EXPORT_SECRET, false);
|
||||
String outputFile = data.getString(EXPORT_FILENAME);
|
||||
Uri outputUri = data.getParcelable(EXPORT_URI);
|
||||
|
||||
boolean exportAll = data.getBoolean(EXPORT_ALL);
|
||||
long[] masterKeyIds = exportAll ? null : data.getLongArray(EXPORT_KEY_RING_MASTER_KEY_ID);
|
||||
|
||||
// Operation
|
||||
ImportExportOperation importExportOperation = new ImportExportOperation(
|
||||
KeychainService.this, providerHelper, KeychainService.this);
|
||||
ExportResult result;
|
||||
if (outputFile != null) {
|
||||
result = importExportOperation.exportToFile(masterKeyIds, exportSecret, outputFile);
|
||||
} else {
|
||||
result = importExportOperation.exportToUri(masterKeyIds, exportSecret, outputUri);
|
||||
}
|
||||
|
||||
// Result
|
||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||
|
||||
break;
|
||||
}
|
||||
case ACTION_IMPORT_KEYRING: {
|
||||
|
||||
// Input
|
||||
String keyServer = data.getString(IMPORT_KEY_SERVER);
|
||||
ArrayList<ParcelableKeyRing> keyList = data.getParcelableArrayList(IMPORT_KEY_LIST);
|
||||
|
||||
ImportExportOperation importExportOperation = new ImportExportOperation(
|
||||
KeychainService.this,
|
||||
providerHelper, KeychainService.this, mActionCanceled);
|
||||
|
||||
ImportKeyringParcel inputParcel = new ImportKeyringParcel(keyList, keyServer);
|
||||
CryptoInputParcel cryptoInputParcel = new CryptoInputParcel();
|
||||
|
||||
ImportKeyResult result = importExportOperation.execute(inputParcel, cryptoInputParcel);
|
||||
|
||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||
|
||||
break;
|
||||
}
|
||||
case ACTION_UPLOAD_KEYRING: {
|
||||
try {
|
||||
|
||||
// Input
|
||||
String keyServer = data.getString(UPLOAD_KEY_SERVER);
|
||||
// and dataUri!
|
||||
|
||||
// Operation
|
||||
HkpKeyserver server = new HkpKeyserver(keyServer);
|
||||
|
||||
CanonicalizedPublicKeyRing keyring = providerHelper.getCanonicalizedPublicKeyRing(dataUri);
|
||||
ImportExportOperation importExportOperation = new ImportExportOperation(
|
||||
KeychainService.this, providerHelper, KeychainService.this);
|
||||
|
||||
try {
|
||||
importExportOperation.uploadKeyRingToServer(server, keyring);
|
||||
} catch (Keyserver.AddKeyException e) {
|
||||
throw new PgpGeneralException("Unable to export key to selected server");
|
||||
}
|
||||
|
||||
sendMessageToHandler(MessageStatus.OKAY);
|
||||
} catch (Exception e) {
|
||||
sendErrorToHandler(e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
@@ -35,15 +35,18 @@ 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.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.service.ExportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.KeychainService;
|
||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
|
||||
@@ -63,6 +66,8 @@ public class CreateKeyFinalFragment extends Fragment {
|
||||
|
||||
SaveKeyringParcel mSaveKeyringParcel;
|
||||
|
||||
private CryptoOperationHelper<ExportKeyringParcel, ExportResult> mOperationHelper;
|
||||
|
||||
public static CreateKeyFinalFragment newInstance() {
|
||||
CreateKeyFinalFragment frag = new CreateKeyFinalFragment();
|
||||
|
||||
@@ -134,6 +139,9 @@ public class CreateKeyFinalFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (mOperationHelper != null) {
|
||||
mOperationHelper.handleActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
switch (requestCode) {
|
||||
case REQUEST_EDIT_KEY: {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
@@ -249,58 +257,58 @@ public class CreateKeyFinalFragment extends Fragment {
|
||||
|
||||
// TODO move into EditKeyOperation
|
||||
private void uploadKey(final EditKeyResult saveKeyResult) {
|
||||
// Send all information needed to service to upload key in other thread
|
||||
final Intent intent = new Intent(getActivity(), KeychainService.class);
|
||||
|
||||
intent.setAction(KeychainService.ACTION_UPLOAD_KEYRING);
|
||||
|
||||
// set data uri as path to keyring
|
||||
Uri blobUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(
|
||||
final Uri blobUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(
|
||||
saveKeyResult.mMasterKeyId);
|
||||
intent.setData(blobUri);
|
||||
|
||||
// fill values for this action
|
||||
Bundle data = new Bundle();
|
||||
|
||||
// upload to favorite keyserver
|
||||
String keyserver = Preferences.getPreferences(getActivity()).getPreferredKeyserver();
|
||||
data.putString(KeychainService.UPLOAD_KEY_SERVER, keyserver);
|
||||
final String keyserver = Preferences.getPreferences(getActivity()).getPreferredKeyserver();
|
||||
|
||||
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
||||
CryptoOperationHelper.Callback<ExportKeyringParcel, ExportResult> callback
|
||||
= new CryptoOperationHelper.Callback<ExportKeyringParcel, ExportResult>() {
|
||||
|
||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
// handle messages by standard KeychainIntentServiceHandler first
|
||||
super.handleMessage(message);
|
||||
public ExportKeyringParcel createOperationInput() {
|
||||
return new ExportKeyringParcel(keyserver, blobUri);
|
||||
}
|
||||
|
||||
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
|
||||
// TODO: upload operation needs a result!
|
||||
// TODO: then combine these results
|
||||
//if (result.getResult() == OperationResultParcel.RESULT_OK) {
|
||||
//Notify.create(getActivity(), R.string.key_send_success,
|
||||
//Notify.Style.OK).show();
|
||||
@Override
|
||||
public void onCryptoOperationSuccess(ExportResult result) {
|
||||
// TODO: upload operation needs a result!
|
||||
// TODO: then combine these results (saveKeyResult and update op result)
|
||||
//if (result.getResult() == OperationResultParcel.RESULT_OK) {
|
||||
//Notify.create(getActivity(), R.string.key_send_success,
|
||||
//Notify.Style.OK).show();
|
||||
|
||||
Intent data = new Intent();
|
||||
data.putExtra(OperationResult.EXTRA_RESULT, saveKeyResult);
|
||||
getActivity().setResult(Activity.RESULT_OK, data);
|
||||
getActivity().finish();
|
||||
}
|
||||
Intent data = new Intent();
|
||||
data.putExtra(OperationResult.EXTRA_RESULT, saveKeyResult);
|
||||
getActivity().setResult(Activity.RESULT_OK, data);
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationCancelled() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationError(ExportResult result) {
|
||||
|
||||
// TODO: upload operation needs a result!
|
||||
// TODO: then combine these results (saveKeyResult and update op result)
|
||||
//if (result.getResult() == OperationResultParcel.RESULT_OK) {
|
||||
//Notify.create(getActivity(), R.string.key_send_success,
|
||||
//Notify.Style.OK).show();
|
||||
|
||||
Intent data = new Intent();
|
||||
data.putExtra(OperationResult.EXTRA_RESULT, saveKeyResult);
|
||||
getActivity().setResult(Activity.RESULT_OK, data);
|
||||
getActivity().finish();
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new Messenger for the communication back
|
||||
Messenger messenger = new Messenger(saveHandler);
|
||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||
|
||||
// show progress dialog
|
||||
saveHandler.showProgressDialog(
|
||||
getString(R.string.progress_uploading),
|
||||
ProgressDialog.STYLE_HORIZONTAL, false);
|
||||
|
||||
// start service with intent
|
||||
getActivity().startService(intent);
|
||||
|
||||
mOperationHelper = new CryptoOperationHelper<>(this, callback, R.string.progress_uploading);
|
||||
mOperationHelper.cryptoOperation();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,12 +17,9 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -33,23 +30,31 @@ import android.widget.Toast;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.service.ExportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.KeychainService;
|
||||
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
|
||||
/**
|
||||
* Sends the selected public key to a keyserver
|
||||
*/
|
||||
public class UploadKeyActivity extends BaseActivity {
|
||||
public class UploadKeyActivity extends BaseActivity
|
||||
implements CryptoOperationHelper.Callback<ExportKeyringParcel, ExportResult> {
|
||||
private View mUploadButton;
|
||||
private Spinner mKeyServerSpinner;
|
||||
|
||||
private Uri mDataUri;
|
||||
|
||||
// CryptoOperationHelper.Callback vars
|
||||
private String mKeyserver;
|
||||
private Uri mUnifiedKeyringUri;
|
||||
private CryptoOperationHelper<ExportKeyringParcel, ExportResult> mUploadOpHelper;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -89,51 +94,23 @@ public class UploadKeyActivity extends BaseActivity {
|
||||
setContentView(R.layout.upload_key_activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (mUploadOpHelper != null) {
|
||||
mUploadOpHelper.handleActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
private void uploadKey() {
|
||||
// Send all information needed to service to upload key in other thread
|
||||
Intent intent = new Intent(this, KeychainService.class);
|
||||
|
||||
intent.setAction(KeychainService.ACTION_UPLOAD_KEYRING);
|
||||
|
||||
// set data uri as path to keyring
|
||||
Uri blobUri = KeyRings.buildUnifiedKeyRingUri(mDataUri);
|
||||
intent.setData(blobUri);
|
||||
|
||||
// fill values for this action
|
||||
Bundle data = new Bundle();
|
||||
mUnifiedKeyringUri = blobUri;
|
||||
|
||||
String server = (String) mKeyServerSpinner.getSelectedItem();
|
||||
data.putString(KeychainService.UPLOAD_KEY_SERVER, server);
|
||||
mKeyserver = server;
|
||||
|
||||
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
||||
|
||||
// Message is received after uploading is done in KeychainService
|
||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(this) {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
// handle messages by standard KeychainIntentServiceHandler first
|
||||
super.handleMessage(message);
|
||||
|
||||
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
|
||||
|
||||
Toast.makeText(UploadKeyActivity.this, R.string.msg_crt_upload_success,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new Messenger for the communication back
|
||||
Messenger messenger = new Messenger(saveHandler);
|
||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||
|
||||
// show progress dialog
|
||||
saveHandler.showProgressDialog(
|
||||
getString(R.string.progress_uploading),
|
||||
ProgressDialog.STYLE_HORIZONTAL, false);
|
||||
|
||||
// start service with intent
|
||||
startService(intent);
|
||||
mUploadOpHelper = new CryptoOperationHelper(this, this, R.string.progress_uploading);
|
||||
mUploadOpHelper.cryptoOperation();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -148,4 +125,25 @@ public class UploadKeyActivity extends BaseActivity {
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExportKeyringParcel createOperationInput() {
|
||||
return new ExportKeyringParcel(mKeyserver, mUnifiedKeyringUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationSuccess(ExportResult result) {
|
||||
Toast.makeText(UploadKeyActivity.this, R.string.msg_crt_upload_success,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationCancelled() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationError(ExportResult result) {
|
||||
// TODO: Implement proper log for key upload then show error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,16 +27,23 @@ import android.support.v4.app.FragmentActivity;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
||||
import org.sufficientlysecure.keychain.service.ExportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.KeychainService;
|
||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ExportHelper {
|
||||
public class ExportHelper
|
||||
implements CryptoOperationHelper.Callback <ExportKeyringParcel, ExportResult> {
|
||||
protected File mExportFile;
|
||||
|
||||
FragmentActivity mActivity;
|
||||
|
||||
private CryptoOperationHelper<ExportKeyringParcel, ExportResult> mExportOpHelper;
|
||||
private boolean mExportSecret;
|
||||
private long[] mMasterKeyIds;
|
||||
|
||||
public ExportHelper(FragmentActivity activity) {
|
||||
super();
|
||||
this.mActivity = activity;
|
||||
@@ -71,60 +78,38 @@ public class ExportHelper {
|
||||
}, mActivity.getSupportFragmentManager() ,title, message, exportFile, checkMsg);
|
||||
}
|
||||
|
||||
// TODO: If ExportHelper requires pending data (see CryptoOPerationHelper), activities using
|
||||
// TODO: this class should be able to call mExportOpHelper.handleActivity
|
||||
|
||||
/**
|
||||
* Export keys
|
||||
*/
|
||||
public void exportKeys(long[] masterKeyIds, boolean exportSecret) {
|
||||
Log.d(Constants.TAG, "exportKeys started");
|
||||
mExportSecret = exportSecret;
|
||||
mMasterKeyIds = masterKeyIds; // if masterKeyIds is null it means export all
|
||||
|
||||
// Send all information needed to service to export key in other thread
|
||||
final Intent intent = new Intent(mActivity, KeychainService.class);
|
||||
|
||||
intent.setAction(KeychainService.ACTION_EXPORT_KEYRING);
|
||||
|
||||
// fill values for this action
|
||||
Bundle data = new Bundle();
|
||||
|
||||
data.putString(KeychainService.EXPORT_FILENAME, mExportFile.getAbsolutePath());
|
||||
data.putBoolean(KeychainService.EXPORT_SECRET, exportSecret);
|
||||
|
||||
if (masterKeyIds == null) {
|
||||
data.putBoolean(KeychainService.EXPORT_ALL, true);
|
||||
} else {
|
||||
data.putLongArray(KeychainService.EXPORT_KEY_RING_MASTER_KEY_ID, masterKeyIds);
|
||||
}
|
||||
|
||||
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
||||
|
||||
// Message is received after exporting is done in KeychainService
|
||||
ServiceProgressHandler exportHandler = new ServiceProgressHandler(mActivity) {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
// handle messages by standard KeychainIntentServiceHandler first
|
||||
super.handleMessage(message);
|
||||
|
||||
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
|
||||
// get returned data bundle
|
||||
Bundle data = message.getData();
|
||||
|
||||
ExportResult result = data.getParcelable(ExportResult.EXTRA_RESULT);
|
||||
result.createNotify(mActivity).show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new Messenger for the communication back
|
||||
Messenger messenger = new Messenger(exportHandler);
|
||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||
|
||||
// show progress dialog
|
||||
exportHandler.showProgressDialog(
|
||||
mActivity.getString(R.string.progress_exporting),
|
||||
ProgressDialog.STYLE_HORIZONTAL, false
|
||||
);
|
||||
|
||||
// start service with intent
|
||||
mActivity.startService(intent);
|
||||
mExportOpHelper = new CryptoOperationHelper(mActivity, this, R.string.progress_exporting);
|
||||
mExportOpHelper.cryptoOperation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExportKeyringParcel createOperationInput() {
|
||||
return new ExportKeyringParcel(mMasterKeyIds, mExportSecret, mExportFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationSuccess(ExportResult result) {
|
||||
result.createNotify(mActivity).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationCancelled() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationError(ExportResult result) {
|
||||
result.createNotify(mActivity).show();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user