Skip to content

Commit 8e08bdb

Browse files
committed
wip
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent a22baed commit 8e08bdb

6 files changed

Lines changed: 20 additions & 16 deletions

File tree

app/src/main/java/com/owncloud/android/datamodel/OCFile.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646

4747
public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterface {
4848

49-
public final static long FIRST_E2EE_COUNTER = 1L;
5049
public final static String PERMISSION_CAN_RESHARE = "R";
5150
public final static String PERMISSION_SHARED = "S";
5251
public final static String PERMISSION_MOUNTED = "M";
@@ -1176,12 +1175,4 @@ public boolean hasValidParentId() {
11761175
return getParentId() != 0;
11771176
}
11781177
}
1179-
1180-
public static long getFirstE2EECounter(boolean useV2) {
1181-
if (useV2) {
1182-
return 1L;
1183-
} else {
1184-
return 0L;
1185-
}
1186-
}
11871178
}

app/src/main/java/com/owncloud/android/datamodel/e2e/v2/decrypted/DecryptedMetadata.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
*/
88
package com.owncloud.android.datamodel.e2e.v2.decrypted
99

10-
import com.owncloud.android.datamodel.OCFile
1110
import com.owncloud.android.utils.EncryptionUtils
1211

1312
data class DecryptedMetadata(
1413
val keyChecksums: MutableList<String> = mutableListOf(),
1514
val deleted: Boolean = false,
16-
var counter: Long = OCFile.getFirstE2EECounter(true),
15+
var counter: Long = EncryptionUtils.E2E_V2_INITIAL_COUNTER,
1716
val folders: MutableMap<String, String> = mutableMapOf(),
1817
val files: MutableMap<String, DecryptedFile> = mutableMapOf(),
1918
@Transient

app/src/main/java/com/owncloud/android/operations/CreateFolderOperation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private RemoteOperationResult encryptedCreateV1(OCFile parent, OwnCloudClient cl
137137

138138
try {
139139
// lock folder
140-
token = EncryptionUtils.lockFolder(parent, client, OCFile.getFirstE2EECounter(false));
140+
token = EncryptionUtils.lockFolder(parent, client, EncryptionUtils.E2E_V1_INITIAL_COUNTER);
141141

142142
// get metadata
143143
Pair<Boolean, DecryptedFolderMetadataFileV1> metadataPair = EncryptionUtils.retrieveMetadataV1(parent,
@@ -153,7 +153,7 @@ private RemoteOperationResult encryptedCreateV1(OCFile parent, OwnCloudClient cl
153153

154154
// check if filename already exists
155155
if (isFileExisting(metadata, filename)) {
156-
return new RemoteOperationResult(RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS);
156+
return new RemoteOperationResult<>(RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS);
157157
}
158158

159159
// generate new random file name, check if it exists in metadata
@@ -275,7 +275,7 @@ private RemoteOperationResult encryptedCreateV2(OCFile parent, OwnCloudClient cl
275275

276276
try {
277277
// lock folder
278-
token = EncryptionUtils.lockFolder(parent, client, OCFile.getFirstE2EECounter(true));
278+
token = EncryptionUtils.lockFolder(parent, client, EncryptionUtils.E2E_V2_INITIAL_COUNTER);
279279

280280
// get metadata
281281
EncryptionUtilsV2 encryptionUtilsV2 = new EncryptionUtilsV2();

app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface;
6565
import com.owncloud.android.ui.preview.PreviewTextFragment;
6666
import com.owncloud.android.utils.DisplayUtils;
67+
import com.owncloud.android.utils.EncryptionUtils;
6768
import com.owncloud.android.utils.FileSortOrder;
6869
import com.owncloud.android.utils.FileStorageUtils;
6970
import com.owncloud.android.utils.MimeTypeUtil;
@@ -298,7 +299,12 @@ public void updateFileEncryptionById(String fileId, boolean encrypted) {
298299
.ifPresent(file -> {
299300
file.setEncrypted(encrypted);
300301
final var isE2EEV2 = E2EVersionHelper.INSTANCE.isV2Plus(capability);
301-
file.setE2eCounter(OCFile.getFirstE2EECounter(isE2EEV2));
302+
long e2eCounter = EncryptionUtils.E2E_V1_INITIAL_COUNTER;
303+
if (isE2EEV2) {
304+
e2eCounter = EncryptionUtils.E2E_V2_INITIAL_COUNTER;
305+
}
306+
307+
file.setE2eCounter(e2eCounter);
302308
mStorageManager.saveFile(file);
303309
int position = getItemPosition(file);
304310
if (position != -1) {

app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1946,9 +1946,13 @@ private void encryptFolder(OCFile folder,
19461946
if (remoteOperationResult.isSuccess()) {
19471947
OCCapability ocCapability = mContainerActivity.getStorageManager().getCapability(user.getAccountName());
19481948
final var isE2EEV2 = E2EVersionHelper.INSTANCE.isV2Plus(ocCapability);
1949+
long e2eCounter = EncryptionUtils.E2E_V1_INITIAL_COUNTER;
1950+
if (isE2EEV2) {
1951+
e2eCounter = EncryptionUtils.E2E_V2_INITIAL_COUNTER;
1952+
}
19491953

19501954
// lock folder
1951-
String token = EncryptionUtils.lockFolder(folder, client, OCFile.getFirstE2EECounter(isE2EEV2));
1955+
String token = EncryptionUtils.lockFolder(folder, client, e2eCounter);
19521956

19531957
if (E2EVersionHelper.INSTANCE.isV2Plus(ocCapability)) {
19541958
// Update metadata

app/src/main/java/com/owncloud/android/utils/EncryptionUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ public final class EncryptionUtils {
129129
@VisibleForTesting
130130
public static final String MIGRATED_FOLDER_IDS = "MIGRATED_FOLDER_IDS";
131131

132+
public static final long E2E_V1_INITIAL_COUNTER = 0L;
133+
public static final long E2E_V2_INITIAL_COUNTER = 1L;
134+
135+
132136
private EncryptionUtils() {
133137
// utility class -> private constructor
134138
}

0 commit comments

Comments
 (0)