remove "export to file" code path from export operation
This commit is contained in:
@@ -18,11 +18,10 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.operations;
|
package org.sufficientlysecure.keychain.operations;
|
||||||
|
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
@@ -55,7 +54,6 @@ import org.sufficientlysecure.keychain.service.ExportKeyringParcel;
|
|||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||||
@@ -82,11 +80,6 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
|
|||||||
super(context, providerHelper, progressable, cancelled);
|
super(context, providerHelper, progressable, cancelled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExportResult uploadKeyRingToServer(HkpKeyserver server, CanonicalizedPublicKeyRing keyring,
|
|
||||||
Proxy proxy) {
|
|
||||||
return uploadKeyRingToServer(server, keyring.getUncachedKeyRing(), proxy);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExportResult uploadKeyRingToServer(HkpKeyserver server, UncachedKeyRing keyring, Proxy proxy) {
|
public ExportResult uploadKeyRingToServer(HkpKeyserver server, UncachedKeyRing keyring, Proxy proxy) {
|
||||||
mProgressable.setProgress(R.string.progress_uploading, 0, 1);
|
mProgressable.setProgress(R.string.progress_uploading, 0, 1);
|
||||||
|
|
||||||
@@ -130,48 +123,6 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExportResult exportToFile(long[] masterKeyIds, boolean exportSecret, String outputFile) {
|
|
||||||
|
|
||||||
OperationLog log = new OperationLog();
|
|
||||||
if (masterKeyIds != null) {
|
|
||||||
log.add(LogType.MSG_EXPORT, 0, masterKeyIds.length);
|
|
||||||
} else {
|
|
||||||
log.add(LogType.MSG_EXPORT_ALL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// do we have a file name?
|
|
||||||
if (outputFile == null) {
|
|
||||||
log.add(LogType.MSG_EXPORT_ERROR_NO_FILE, 1);
|
|
||||||
return new ExportResult(ExportResult.RESULT_ERROR, log);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.add(LogType.MSG_EXPORT_FILE_NAME, 1, outputFile);
|
|
||||||
|
|
||||||
// check if storage is ready
|
|
||||||
if (!FileHelper.isStorageMounted(outputFile)) {
|
|
||||||
log.add(LogType.MSG_EXPORT_ERROR_STORAGE, 1);
|
|
||||||
return new ExportResult(ExportResult.RESULT_ERROR, log);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
OutputStream outStream = new FileOutputStream(outputFile);
|
|
||||||
try {
|
|
||||||
ExportResult result = exportKeyRings(log, masterKeyIds, exportSecret, outStream);
|
|
||||||
if (result.cancelled()) {
|
|
||||||
//noinspection ResultOfMethodCallIgnored
|
|
||||||
new File(outputFile).delete();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
} finally {
|
|
||||||
outStream.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.add(LogType.MSG_EXPORT_ERROR_FOPEN, 1);
|
|
||||||
return new ExportResult(ExportResult.RESULT_ERROR, log);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExportResult exportToUri(long[] masterKeyIds, boolean exportSecret, Uri outputUri) {
|
public ExportResult exportToUri(long[] masterKeyIds, boolean exportSecret, Uri outputUri) {
|
||||||
|
|
||||||
OperationLog log = new OperationLog();
|
OperationLog log = new OperationLog();
|
||||||
@@ -188,8 +139,7 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OutputStream outStream = mProviderHelper.getContentResolver().openOutputStream
|
OutputStream outStream = mProviderHelper.getContentResolver().openOutputStream(outputUri);
|
||||||
(outputUri);
|
|
||||||
return exportKeyRings(log, masterKeyIds, exportSecret, outStream);
|
return exportKeyRings(log, masterKeyIds, exportSecret, outStream);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
log.add(LogType.MSG_EXPORT_ERROR_URI_OPEN, 1);
|
log.add(LogType.MSG_EXPORT_ERROR_URI_OPEN, 1);
|
||||||
@@ -359,23 +309,17 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
|
|||||||
CanonicalizedPublicKeyRing keyring
|
CanonicalizedPublicKeyRing keyring
|
||||||
= mProviderHelper.getCanonicalizedPublicKeyRing(
|
= mProviderHelper.getCanonicalizedPublicKeyRing(
|
||||||
exportInput.mCanonicalizedPublicKeyringUri);
|
exportInput.mCanonicalizedPublicKeyringUri);
|
||||||
return uploadKeyRingToServer(hkpKeyserver, keyring, proxy);
|
return uploadKeyRingToServer(hkpKeyserver, keyring.getUncachedKeyRing(), proxy);
|
||||||
} else {
|
} else {
|
||||||
return uploadKeyRingToServer(hkpKeyserver, exportInput.mUncachedKeyRing,
|
return uploadKeyRingToServer(hkpKeyserver, exportInput.mUncachedKeyRing, proxy);
|
||||||
proxy);
|
|
||||||
}
|
}
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
Log.e(Constants.TAG, "error uploading key", e);
|
Log.e(Constants.TAG, "error uploading key", e);
|
||||||
return new ExportResult(ExportResult.RESULT_ERROR, new OperationLog());
|
return new ExportResult(ExportResult.RESULT_ERROR, new OperationLog());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case EXPORT_FILE: {
|
|
||||||
return exportToFile(exportInput.mMasterKeyIds, exportInput.mExportSecret,
|
|
||||||
exportInput.mOutputFile);
|
|
||||||
}
|
|
||||||
case EXPORT_URI: {
|
case EXPORT_URI: {
|
||||||
return exportToUri(exportInput.mMasterKeyIds, exportInput.mExportSecret,
|
return exportToUri(exportInput.mMasterKeyIds, exportInput.mExportSecret, exportInput.mOutputUri);
|
||||||
exportInput.mOutputUri);
|
|
||||||
}
|
}
|
||||||
default: { // can never happen, all enum types must be handled above
|
default: { // can never happen, all enum types must be handled above
|
||||||
throw new AssertionError("must not happen, this is a bug!");
|
throw new AssertionError("must not happen, this is a bug!");
|
||||||
|
|||||||
@@ -763,16 +763,12 @@ public abstract class OperationResult implements Parcelable {
|
|||||||
MSG_IMPORT_SUCCESS (LogLevel.OK, R.string.msg_import_success),
|
MSG_IMPORT_SUCCESS (LogLevel.OK, R.string.msg_import_success),
|
||||||
|
|
||||||
MSG_EXPORT (LogLevel.START, R.plurals.msg_export),
|
MSG_EXPORT (LogLevel.START, R.plurals.msg_export),
|
||||||
MSG_EXPORT_FILE_NAME (LogLevel.INFO, R.string.msg_export_file_name),
|
|
||||||
MSG_EXPORT_UPLOAD_PUBLIC (LogLevel.START, R.string.msg_export_upload_public),
|
MSG_EXPORT_UPLOAD_PUBLIC (LogLevel.START, R.string.msg_export_upload_public),
|
||||||
MSG_EXPORT_PUBLIC (LogLevel.DEBUG, R.string.msg_export_public),
|
MSG_EXPORT_PUBLIC (LogLevel.DEBUG, R.string.msg_export_public),
|
||||||
MSG_EXPORT_SECRET (LogLevel.DEBUG, R.string.msg_export_secret),
|
MSG_EXPORT_SECRET (LogLevel.DEBUG, R.string.msg_export_secret),
|
||||||
MSG_EXPORT_ALL (LogLevel.START, R.string.msg_export_all),
|
MSG_EXPORT_ALL (LogLevel.START, R.string.msg_export_all),
|
||||||
MSG_EXPORT_ERROR_NO_FILE (LogLevel.ERROR, R.string.msg_export_error_no_file),
|
|
||||||
MSG_EXPORT_ERROR_FOPEN (LogLevel.ERROR, R.string.msg_export_error_fopen),
|
|
||||||
MSG_EXPORT_ERROR_NO_URI (LogLevel.ERROR, R.string.msg_export_error_no_uri),
|
MSG_EXPORT_ERROR_NO_URI (LogLevel.ERROR, R.string.msg_export_error_no_uri),
|
||||||
MSG_EXPORT_ERROR_URI_OPEN (LogLevel.ERROR, R.string.msg_export_error_uri_open),
|
MSG_EXPORT_ERROR_URI_OPEN (LogLevel.ERROR, R.string.msg_export_error_uri_open),
|
||||||
MSG_EXPORT_ERROR_STORAGE (LogLevel.ERROR, R.string.msg_export_error_storage),
|
|
||||||
MSG_EXPORT_ERROR_DB (LogLevel.ERROR, R.string.msg_export_error_db),
|
MSG_EXPORT_ERROR_DB (LogLevel.ERROR, R.string.msg_export_error_db),
|
||||||
MSG_EXPORT_ERROR_IO (LogLevel.ERROR, R.string.msg_export_error_io),
|
MSG_EXPORT_ERROR_IO (LogLevel.ERROR, R.string.msg_export_error_io),
|
||||||
MSG_EXPORT_ERROR_KEY (LogLevel.ERROR, R.string.msg_export_error_key),
|
MSG_EXPORT_ERROR_KEY (LogLevel.ERROR, R.string.msg_export_error_key),
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ public class ExportKeyringParcel implements Parcelable {
|
|||||||
|
|
||||||
public enum ExportType {
|
public enum ExportType {
|
||||||
UPLOAD_KEYSERVER,
|
UPLOAD_KEYSERVER,
|
||||||
EXPORT_FILE,
|
|
||||||
EXPORT_URI
|
EXPORT_URI
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,13 +53,6 @@ public class ExportKeyringParcel implements Parcelable {
|
|||||||
mUncachedKeyRing = uncachedKeyRing;
|
mUncachedKeyRing = uncachedKeyRing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExportKeyringParcel(long[] masterKeyIds, boolean exportSecret, String outputFile) {
|
|
||||||
mExportType = ExportType.EXPORT_FILE;
|
|
||||||
mMasterKeyIds = masterKeyIds;
|
|
||||||
mExportSecret = exportSecret;
|
|
||||||
mOutputFile = outputFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unused") // TODO: is it used?
|
@SuppressWarnings("unused") // TODO: is it used?
|
||||||
public ExportKeyringParcel(long[] masterKeyIds, boolean exportSecret, Uri outputUri) {
|
public ExportKeyringParcel(long[] masterKeyIds, boolean exportSecret, Uri outputUri) {
|
||||||
mExportType = ExportType.EXPORT_URI;
|
mExportType = ExportType.EXPORT_URI;
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public class ExportHelper
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExportKeyringParcel createOperationInput() {
|
public ExportKeyringParcel createOperationInput() {
|
||||||
return new ExportKeyringParcel(mMasterKeyIds, mExportSecret, mExportFile.getAbsolutePath());
|
return new ExportKeyringParcel(mMasterKeyIds, mExportSecret, Uri.fromFile(mExportFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user