Show warning when trying to access an encrypted folder, when not yet setup

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2022-11-01 10:19:15 +01:00
parent 12f04c8335
commit 6f826bbd8d
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
4 changed files with 34 additions and 21 deletions

View file

@ -35,7 +35,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources.NotFoundException;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@ -86,6 +85,7 @@ import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
import com.owncloud.android.ui.dialog.MultipleAccountsDialog;
import com.owncloud.android.ui.dialog.SortingOrderDialogFragment;
import com.owncloud.android.ui.fragment.TaskRetainerFragment;
import com.owncloud.android.ui.helpers.FileOperationsHelper;
import com.owncloud.android.ui.helpers.UriUploader;
import com.owncloud.android.utils.DataHolderUtil;
import com.owncloud.android.utils.DisplayUtils;
@ -647,7 +647,15 @@ public class ReceiveExternalFilesActivity extends FileActivity
if (files.size() < position) {
throw new IndexOutOfBoundsException("Incorrect item selected");
}
if (files.get(position).isFolder()) {
OCFile ocFile = files.get(position);
if (ocFile.isFolder()) {
if (ocFile.isEncrypted() &&
!FileOperationsHelper.isEndToEndEncryptionSetup(this, getUser().orElseThrow(IllegalAccessError::new))) {
DisplayUtils.showSnackMessage(this, R.string.e2e_not_yet_setup);
return;
}
OCFile folderToEnter = files.get(position);
startSyncFolderOperation(folderToEnter);
mParents.push(folderToEnter.getFileName());

View file

@ -964,31 +964,17 @@ public class OCFileListFragment extends ExtendedListFragment implements
return;
}
// check if keys are stored
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(
getContext().getContentResolver());
String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY);
String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY);
if (publicKey.isEmpty() || privateKey.isEmpty()) {
Log_OC.d(TAG, "no public key for " + user.getAccountName());
SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user,
position);
dialog.setTargetFragment(this, SetupEncryptionDialogFragment.SETUP_ENCRYPTION_REQUEST_CODE);
dialog.show(getFragmentManager(), SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG);
} else {
if (FileOperationsHelper.isEndToEndEncryptionSetup(requireContext(), user)) {
// update state and view of this fragment
searchFragment = false;
mHideFab = false;
if (mContainerActivity instanceof FolderPickerActivity &&
((FolderPickerActivity) mContainerActivity)
.isDoNotEnterEncryptedFolder()) {
((FolderPickerActivity) mContainerActivity)
.isDoNotEnterEncryptedFolder()) {
Snackbar.make(getRecyclerView(),
R.string.copy_move_to_encrypted_folder_not_supported,
Snackbar.LENGTH_LONG).show();
R.string.copy_move_to_encrypted_folder_not_supported,
Snackbar.LENGTH_LONG).show();
} else {
listDirectory(file, MainApp.isOnlyOnDevice(), false);
// then, notify parent activity to let it update its state and view
@ -996,6 +982,13 @@ public class OCFileListFragment extends ExtendedListFragment implements
// save index and top position
saveIndexAndTopPosition(position);
}
} else {
Log_OC.d(TAG, "no public key for " + user.getAccountName());
SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user,
position);
dialog.setTargetFragment(this, SetupEncryptionDialogFragment.SETUP_ENCRYPTION_REQUEST_CODE);
dialog.show(getFragmentManager(), SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG);
}
} else {
// update state and view of this fragment

View file

@ -53,6 +53,7 @@ import com.nextcloud.client.network.ConnectivityService;
import com.nextcloud.java.util.Optional;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.FileMenuFilter;
@ -82,6 +83,7 @@ import com.owncloud.android.ui.events.FavoriteEvent;
import com.owncloud.android.ui.events.FileLockEvent;
import com.owncloud.android.ui.events.SyncEventFinished;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.EncryptionUtils;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.PermissionUtil;
import com.owncloud.android.utils.UriUtils;
@ -1116,4 +1118,13 @@ public class FileOperationsHelper {
return stat.getBlockSizeLong() * stat.getAvailableBlocksLong();
}
public static boolean isEndToEndEncryptionSetup(Context context, User user) {
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY);
String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY);
return !publicKey.isEmpty() && !privateKey.isEmpty();
}
}

View file

@ -1052,4 +1052,5 @@
<string name="icon_for_empty_list">Icon for empty list</string>
<string name="no_items">No items</string>
<string name="check_back_later_or_reload">Check back later or reload.</string>
<string name="e2e_not_yet_setup">E2E not yet setup</string>
</resources>