make unencrypted backup an explicit parameter
This commit is contained in:
@@ -20,7 +20,6 @@ package org.sufficientlysecure.keychain.operations;
|
||||
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@@ -113,23 +112,25 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
|
||||
log.add(LogType.MSG_BACKUP_ALL, 0);
|
||||
}
|
||||
|
||||
if (backupInput.mIsEncrypted && cryptoInput == null) {
|
||||
throw new IllegalStateException("Encrypted backup must supply cryptoInput parameter");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
boolean nonEncryptedOutput = cryptoInput == null;
|
||||
|
||||
Uri plainUri = null;
|
||||
OutputStream plainOut;
|
||||
if (nonEncryptedOutput && backupInput.mOutputUri == null) {
|
||||
plainOut = outputStream;
|
||||
} else if (nonEncryptedOutput) {
|
||||
plainOut = mContext.getContentResolver().openOutputStream(backupInput.mOutputUri);
|
||||
} else {
|
||||
if (backupInput.mIsEncrypted) {
|
||||
plainUri = TemporaryFileProvider.createFile(mContext);
|
||||
plainOut = mContext.getContentResolver().openOutputStream(plainUri);
|
||||
} else {
|
||||
if (backupInput.mOutputUri == null) {
|
||||
throw new IllegalArgumentException("Unencrypted export to output stream is not supported!");
|
||||
} else {
|
||||
plainOut = mContext.getContentResolver().openOutputStream(backupInput.mOutputUri);
|
||||
}
|
||||
}
|
||||
|
||||
int exportedDataSize;
|
||||
|
||||
{ // export key data, and possibly return if we don't encrypt
|
||||
DataOutputStream outStream = new DataOutputStream(new BufferedOutputStream(plainOut));
|
||||
|
||||
|
||||
@@ -757,7 +757,7 @@ public class OpenPgpService extends Service {
|
||||
// after user interaction with RemoteBackupActivity,
|
||||
// the backup code is cached in CryptoInputParcelCacheService, now we can proceed
|
||||
|
||||
BackupKeyringParcel input = new BackupKeyringParcel(masterKeyIds, backupSecret, null);
|
||||
BackupKeyringParcel input = new BackupKeyringParcel(masterKeyIds, backupSecret, true, null);
|
||||
BackupOperation op = new BackupOperation(this, mProviderHelper, null);
|
||||
ExportResult pgpResult = op.execute(input, inputParcel, outputStream);
|
||||
|
||||
|
||||
@@ -29,14 +29,16 @@ import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
public class BackupKeyringParcel implements Parcelable {
|
||||
public Uri mCanonicalizedPublicKeyringUri;
|
||||
|
||||
public boolean mExportSecret;
|
||||
public long mMasterKeyIds[];
|
||||
public Uri mOutputUri;
|
||||
public final boolean mExportSecret;
|
||||
public final boolean mIsEncrypted;
|
||||
public final long mMasterKeyIds[];
|
||||
public final Uri mOutputUri;
|
||||
|
||||
public BackupKeyringParcel(long[] masterKeyIds, boolean exportSecret, Uri outputUri) {
|
||||
public BackupKeyringParcel(long[] masterKeyIds, boolean exportSecret, boolean isEncrypted, Uri outputUri) {
|
||||
mMasterKeyIds = masterKeyIds;
|
||||
mExportSecret = exportSecret;
|
||||
mOutputUri = outputUri;
|
||||
mIsEncrypted = isEncrypted;
|
||||
}
|
||||
|
||||
protected BackupKeyringParcel(Parcel in) {
|
||||
@@ -44,6 +46,7 @@ public class BackupKeyringParcel implements Parcelable {
|
||||
mExportSecret = in.readByte() != 0x00;
|
||||
mOutputUri = (Uri) in.readValue(Uri.class.getClassLoader());
|
||||
mMasterKeyIds = in.createLongArray();
|
||||
mIsEncrypted = in.readInt() != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,6 +60,7 @@ public class BackupKeyringParcel implements Parcelable {
|
||||
dest.writeByte((byte) (mExportSecret ? 0x01 : 0x00));
|
||||
dest.writeValue(mOutputUri);
|
||||
dest.writeLongArray(mMasterKeyIds);
|
||||
dest.writeInt(mIsEncrypted ? 1 : 0);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<BackupKeyringParcel> CREATOR = new Parcelable.Creator<BackupKeyringParcel>() {
|
||||
|
||||
@@ -606,7 +606,7 @@ public class BackupCodeFragment extends CryptoOperationFragment<BackupKeyringPar
|
||||
@Nullable
|
||||
@Override
|
||||
public BackupKeyringParcel createOperationInput() {
|
||||
return new BackupKeyringParcel(mMasterKeyIds, mExportSecret, mCachedBackupUri);
|
||||
return new BackupKeyringParcel(mMasterKeyIds, mExportSecret, true, mCachedBackupUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user