Renaming export strings to backup

This commit is contained in:
Dominik Schürmann
2015-10-15 23:40:35 +02:00
parent 491477cabf
commit 2db8346f37
17 changed files with 164 additions and 163 deletions

View File

@@ -61,8 +61,9 @@ public final class Constants {
public static final String FILE_EXTENSION_BACKUP_SECRET = ".sec.asc";
public static final String FILE_EXTENSION_BACKUP_PUBLIC = ".pub.asc";
public static final String FILE_ENCRYPTED_BACKUP_PREFIX = "backup_";
public static final String FILE_EXTENSION_ENCRYPTED_BACKUP_SECRET = ".sec.asc";
public static final String FILE_EXTENSION_ENCRYPTED_BACKUP_PUBLIC = ".pub.asc";
// actually it is ASCII Armor, so .asc would be more accurate, but Android displays a nice icon for .pgp files!
public static final String FILE_EXTENSION_ENCRYPTED_BACKUP_SECRET = ".sec.pgp";
public static final String FILE_EXTENSION_ENCRYPTED_BACKUP_PUBLIC = ".pub.pgp";
// used by QR Codes (Guardian Project, Monkeysphere compatiblity)
public static final String FINGERPRINT_SCHEME = "openpgp4fpr";

View File

@@ -63,13 +63,13 @@ import org.sufficientlysecure.keychain.util.Log;
/**
* An operation class which implements high level export
* An operation class which implements high level backup
* operations.
* This class receives a source and/or destination of keys as input and performs
* all steps for this export.
* all steps for this backup.
*
* @see org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter#getSelectedEntries()
* For the export operation, the input consists of a set of key ids and
* For the backup 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 BackupOperation extends BaseOperation<BackupKeyringParcel> {
@@ -96,21 +96,21 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
}
@NonNull
public ExportResult execute(@NonNull BackupKeyringParcel exportInput, @Nullable CryptoInputParcel cryptoInput) {
public ExportResult execute(@NonNull BackupKeyringParcel backupInput, @Nullable CryptoInputParcel cryptoInput) {
OperationLog log = new OperationLog();
if (exportInput.mMasterKeyIds != null) {
log.add(LogType.MSG_EXPORT, 0, exportInput.mMasterKeyIds.length);
if (backupInput.mMasterKeyIds != null) {
log.add(LogType.MSG_BACKUP, 0, backupInput.mMasterKeyIds.length);
} else {
log.add(LogType.MSG_EXPORT_ALL, 0);
log.add(LogType.MSG_BACKUP_ALL, 0);
}
try {
boolean nonEncryptedOutput = exportInput.mSymmetricPassphrase == null;
boolean nonEncryptedOutput = backupInput.mSymmetricPassphrase == null;
Uri exportOutputUri = nonEncryptedOutput
? exportInput.mOutputUri
Uri backupOutputUri = nonEncryptedOutput
? backupInput.mOutputUri
: TemporaryFileProvider.createFile(mContext);
int exportedDataSize;
@@ -118,21 +118,21 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
{ // export key data, and possibly return if we don't encrypt
DataOutputStream outStream = new DataOutputStream(new BufferedOutputStream(
mContext.getContentResolver().openOutputStream(exportOutputUri)));
mContext.getContentResolver().openOutputStream(backupOutputUri)));
boolean exportSuccess = exportKeysToStream(
log, exportInput.mMasterKeyIds, exportInput.mExportSecret, outStream);
boolean backupSuccess = exportKeysToStream(
log, backupInput.mMasterKeyIds, backupInput.mExportSecret, outStream);
exportedDataSize = outStream.size();
if (!exportSuccess) {
if (!backupSuccess) {
// if there was an error, it will be in the log so we just have to return
return new ExportResult(ExportResult.RESULT_ERROR, log);
}
if (nonEncryptedOutput) {
// log.add(LogType.MSG_EXPORT_NO_ENCRYPT, 1);
log.add(LogType.MSG_EXPORT_SUCCESS, 1);
log.add(LogType.MSG_BACKUP_SUCCESS, 1);
return new ExportResult(ExportResult.RESULT_OK, log);
}
}
@@ -140,23 +140,23 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
PgpSignEncryptOperation pseOp = new PgpSignEncryptOperation(mContext, mProviderHelper, mProgressable, mCancelled);
PgpSignEncryptInputParcel inputParcel = new PgpSignEncryptInputParcel();
inputParcel.setSymmetricPassphrase(exportInput.mSymmetricPassphrase);
inputParcel.setSymmetricPassphrase(backupInput.mSymmetricPassphrase);
inputParcel.setEnableAsciiArmorOutput(true);
inputParcel.setAddBackupHeader(true);
InputStream inStream = mContext.getContentResolver().openInputStream(exportOutputUri);
InputStream inStream = mContext.getContentResolver().openInputStream(backupOutputUri);
String filename;
if (exportInput.mMasterKeyIds != null && exportInput.mMasterKeyIds.length == 1) {
filename = Constants.FILE_BACKUP_PREFIX + KeyFormattingUtils.convertKeyIdToHex(exportInput.mMasterKeyIds[0]);
if (backupInput.mMasterKeyIds != null && backupInput.mMasterKeyIds.length == 1) {
filename = Constants.FILE_BACKUP_PREFIX + KeyFormattingUtils.convertKeyIdToHex(backupInput.mMasterKeyIds[0]);
} else {
filename = Constants.FILE_BACKUP_PREFIX + new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date());
}
filename += exportInput.mExportSecret ? Constants.FILE_EXTENSION_BACKUP_SECRET : Constants.FILE_EXTENSION_BACKUP_PUBLIC;
filename += backupInput.mExportSecret ? Constants.FILE_EXTENSION_BACKUP_SECRET : Constants.FILE_EXTENSION_BACKUP_PUBLIC;
InputData inputData = new InputData(inStream, exportedDataSize, filename);
OutputStream outStream = mContext.getContentResolver().openOutputStream(exportInput.mOutputUri);
OutputStream outStream = mContext.getContentResolver().openOutputStream(backupInput.mOutputUri);
outStream = new BufferedOutputStream(outStream);
PgpSignEncryptResult encryptResult = pseOp.execute(inputParcel, new CryptoInputParcel(), inputData, outStream);
@@ -167,11 +167,11 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
}
log.add(encryptResult, 1);
log.add(LogType.MSG_EXPORT_SUCCESS, 1);
log.add(LogType.MSG_BACKUP_SUCCESS, 1);
return new ExportResult(ExportResult.RESULT_OK, log);
} catch (FileNotFoundException e) {
log.add(LogType.MSG_EXPORT_ERROR_URI_OPEN, 1);
log.add(LogType.MSG_BACKUP_ERROR_URI_OPEN, 1);
return new ExportResult(ExportResult.RESULT_ERROR, log);
}
@@ -188,7 +188,7 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
Cursor cursor = queryForKeys(masterKeyIds);
if (cursor == null || !cursor.moveToFirst()) {
log.add(LogType.MSG_EXPORT_ERROR_DB, 1);
log.add(LogType.MSG_BACKUP_ERROR_DB, 1);
return false; // new ExportResult(ExportResult.RESULT_ERROR, log);
}
@@ -203,14 +203,14 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
while (!cursor.isAfterLast()) {
long keyId = cursor.getLong(INDEX_MASTER_KEY_ID);
log.add(LogType.MSG_EXPORT_PUBLIC, 1, KeyFormattingUtils.beautifyKeyId(keyId));
log.add(LogType.MSG_BACKUP_PUBLIC, 1, KeyFormattingUtils.beautifyKeyId(keyId));
if (writePublicKeyToStream(log, outStream, cursor)) {
okPublic += 1;
boolean hasSecret = cursor.getInt(INDEX_HAS_ANY_SECRET) > 0;
if (exportSecret && hasSecret) {
log.add(LogType.MSG_EXPORT_SECRET, 2, KeyFormattingUtils.beautifyKeyId(keyId));
log.add(LogType.MSG_BACKUP_SECRET, 2, KeyFormattingUtils.beautifyKeyId(keyId));
if (writeSecretKeyToStream(log, outStream, cursor)) {
okSecret += 1;
}
@@ -224,7 +224,7 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
updateProgress(R.string.progress_done, numKeys, numKeys);
} catch (IOException e) {
log.add(LogType.MSG_EXPORT_ERROR_IO, 1);
log.add(LogType.MSG_BACKUP_ERROR_IO, 1);
return false; // new ExportResult(ExportResult.RESULT_ERROR, log);
} finally {
// Make sure the stream is closed
@@ -252,7 +252,7 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
ring.encode(arOutStream);
} catch (PgpGeneralException e) {
log.add(LogType.MSG_EXPORT_ERROR_KEY, 2);
log.add(LogType.MSG_BACKUP_ERROR_KEY, 2);
} finally {
if (arOutStream != null) {
arOutStream.close();
@@ -273,7 +273,7 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
ring.encode(arOutStream);
} catch (PgpGeneralException e) {
log.add(LogType.MSG_EXPORT_ERROR_KEY, 2);
log.add(LogType.MSG_BACKUP_ERROR_KEY, 2);
} finally {
if (arOutStream != null) {
arOutStream.close();

View File

@@ -122,7 +122,7 @@ public class UploadOperation extends BaseOperation<UploadKeyringParcel> {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ArmoredOutputStream aos = null;
OperationLog log = new OperationLog();
log.add(LogType.MSG_EXPORT_UPLOAD_PUBLIC, 0, KeyFormattingUtils.convertKeyIdToHex(
log.add(LogType.MSG_BACKUP_UPLOAD_PUBLIC, 0, KeyFormattingUtils.convertKeyIdToHex(
keyring.getPublicKey().getKeyId()
));
@@ -134,17 +134,17 @@ public class UploadOperation extends BaseOperation<UploadKeyringParcel> {
String armoredKey = bos.toString("UTF-8");
server.add(armoredKey, proxy);
log.add(LogType.MSG_EXPORT_UPLOAD_SUCCESS, 1);
log.add(LogType.MSG_BACKUP_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);
log.add(LogType.MSG_BACKUP_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);
log.add(LogType.MSG_BACKUP_ERROR_UPLOAD, 1);
return new UploadResult(UploadResult.RESULT_ERROR, log);
} finally {
mProgressable.setProgress(R.string.progress_uploading, 1, 1);

View File

@@ -765,18 +765,18 @@ public abstract class OperationResult implements Parcelable {
MSG_IMPORT_PARTIAL (LogLevel.ERROR, R.string.msg_import_partial),
MSG_IMPORT_SUCCESS (LogLevel.OK, R.string.msg_import_success),
MSG_EXPORT (LogLevel.START, R.plurals.msg_export),
MSG_EXPORT_UPLOAD_PUBLIC (LogLevel.START, R.string.msg_export_upload_public),
MSG_EXPORT_PUBLIC (LogLevel.DEBUG, R.string.msg_export_public),
MSG_EXPORT_SECRET (LogLevel.DEBUG, R.string.msg_export_secret),
MSG_EXPORT_ALL (LogLevel.START, R.string.msg_export_all),
MSG_EXPORT_ERROR_URI_OPEN (LogLevel.ERROR, R.string.msg_export_error_uri_open),
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_KEY (LogLevel.ERROR, R.string.msg_export_error_key),
MSG_EXPORT_ERROR_UPLOAD (LogLevel.ERROR, R.string.msg_export_error_upload),
MSG_EXPORT_SUCCESS (LogLevel.OK, R.string.msg_export_success),
MSG_EXPORT_UPLOAD_SUCCESS (LogLevel.OK, R.string.msg_export_upload_success),
MSG_BACKUP(LogLevel.START, R.plurals.msg_backup),
MSG_BACKUP_UPLOAD_PUBLIC(LogLevel.START, R.string.msg_backup_upload_public),
MSG_BACKUP_PUBLIC(LogLevel.DEBUG, R.string.msg_backup_public),
MSG_BACKUP_SECRET(LogLevel.DEBUG, R.string.msg_backup_secret),
MSG_BACKUP_ALL(LogLevel.START, R.string.msg_backup_all),
MSG_BACKUP_ERROR_URI_OPEN(LogLevel.ERROR, R.string.msg_backup_error_uri_open),
MSG_BACKUP_ERROR_DB(LogLevel.ERROR, R.string.msg_backup_error_db),
MSG_BACKUP_ERROR_IO(LogLevel.ERROR, R.string.msg_backup_error_io),
MSG_BACKUP_ERROR_KEY(LogLevel.ERROR, R.string.msg_backup_error_key),
MSG_BACKUP_ERROR_UPLOAD(LogLevel.ERROR, R.string.msg_backup_error_upload),
MSG_BACKUP_SUCCESS(LogLevel.OK, R.string.msg_backup_success),
MSG_BACKUP_UPLOAD_SUCCESS(LogLevel.OK, R.string.msg_backup_upload_success),
MSG_CRT_UPLOAD_SUCCESS (LogLevel.OK, R.string.msg_crt_upload_success),