-
-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(e2ee): refresh during crud operations #17267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8c3780f
28e15a4
5293dbf
9428f0c
79607ed
23bc79d
933fbb3
9db26ae
8e9936b
978bc75
bc2a5ff
4bd9257
a8f9719
f24578c
2fe1406
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| /* | ||
| * Nextcloud - Android Client | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com> | ||
| * SPDX-FileCopyrightText: 2020-2023 Tobias Kaminsky <tobias@kaminsky.me> | ||
| * SPDX-FileCopyrightText: 2021 Chris Narkiewicz <hello@ezaquarii.com> | ||
| * SPDX-FileCopyrightText: 2017-2018 Andy Scherzinger <info@andy-scherzinger.de> | ||
|
|
@@ -601,7 +602,7 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare | |
| result = performE2EUpload(clientData); | ||
|
|
||
| if (result.isSuccess()) { | ||
| updateMetadataForE2E(object, e2eData, clientData, e2eFiles, arbitraryDataProvider, encryptionUtilsV2, isV1MetadataExists); | ||
| upsertMetadata(object, e2eData, clientData, e2eFiles, arbitraryDataProvider, encryptionUtilsV2, isV1MetadataExists); | ||
| } | ||
| } catch (FileNotFoundException e) { | ||
| Log_OC.e(TAG, mFile.getStoragePath() + " does not exist anymore"); | ||
|
|
@@ -613,13 +614,13 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare | |
| Log_OC.e(TAG, "UploadFileOperation exception: " + e.getLocalizedMessage()); | ||
| result = new RemoteOperationResult<>(e); | ||
| } finally { | ||
| result = cleanupE2EUpload(fileLock, channel, e2eFiles, result, object, client, token); | ||
| result = releaseLocksAndUnlockE2EFolder(fileLock, channel, e2eFiles, result, object, client, token); | ||
|
|
||
| // update upload status | ||
| uploadsStorageManager.updateDatabaseUploadResult(result, this); | ||
| } | ||
|
|
||
| completeE2EUpload(result, e2eFiles, client); | ||
| handleLocalBehaviourOrSaveConflictAndDeleteTemporalFile(result, e2eFiles, client); | ||
|
|
||
| return result; | ||
| } | ||
|
|
@@ -811,7 +812,10 @@ private E2EData getE2EData(Object object) throws InvalidAlgorithmParameterExcept | |
| return new E2EData(key, iv, encryptedFile, encryptedFileName); | ||
| } | ||
|
|
||
| private void updateMetadataForE2E(Object object, E2EData e2eData, E2EClientData clientData, E2EFiles e2eFiles, ArbitraryDataProvider arbitraryDataProvider, EncryptionUtilsV2 encryptionUtilsV2, boolean isV1MetadataExists) | ||
| /** | ||
| * Stores or updates metadata of the encrypted file along with e2ee counter. | ||
| */ | ||
| private void upsertMetadata(Object object, E2EData e2eData, E2EClientData clientData, E2EFiles e2eFiles, ArbitraryDataProvider arbitraryDataProvider, EncryptionUtilsV2 encryptionUtilsV2, boolean isV1MetadataExists) | ||
|
|
||
| throws InvalidAlgorithmParameterException, UploadException, NoSuchPaddingException, IllegalBlockSizeException, CertificateException, | ||
| NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { | ||
|
|
@@ -892,11 +896,7 @@ private void updateMetadataForV2(DecryptedFolderMetadataFile metadata, Encryptio | |
| e2eData.getIv(), | ||
| e2eData.getEncryptedFile().getAuthenticationTag(), | ||
| e2eData.getKey(), | ||
| metadata, | ||
| getStorageManager()); | ||
|
|
||
| parentFile.setE2eCounter(metadata.getMetadata().getCounter()); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be after |
||
| getStorageManager().saveFile(parentFile); | ||
| metadata); | ||
|
|
||
| // upload metadata | ||
| encryptionUtilsV2.serializeAndUploadMetadata(parentFile, | ||
|
|
@@ -909,7 +909,7 @@ private void updateMetadataForV2(DecryptedFolderMetadataFile metadata, Encryptio | |
| getStorageManager()); | ||
| } | ||
|
|
||
| private void completeE2EUpload(RemoteOperationResult result, E2EFiles e2eFiles, OwnCloudClient client) { | ||
| private void handleLocalBehaviourOrSaveConflictAndDeleteTemporalFile(RemoteOperationResult result, E2EFiles e2eFiles, OwnCloudClient client) { | ||
| if (result.isSuccess()) { | ||
| handleLocalBehaviour(e2eFiles.getTemporalFile(), e2eFiles.getExpectedFile(), e2eFiles.getOriginalFile(), client); | ||
| } else if (RemoteOperationResultExtensionsKt.isConflict(result.getCode())) { | ||
|
|
@@ -919,7 +919,7 @@ private void completeE2EUpload(RemoteOperationResult result, E2EFiles e2eFiles, | |
| e2eFiles.deleteTemporalFile(); | ||
| } | ||
|
|
||
| private RemoteOperationResult cleanupE2EUpload(FileLock fileLock, FileChannel channel, E2EFiles e2eFiles, RemoteOperationResult result, Object object, OwnCloudClient client, String token) { | ||
| private RemoteOperationResult releaseLocksAndUnlockE2EFolder(FileLock fileLock, FileChannel channel, E2EFiles e2eFiles, RemoteOperationResult result, Object object, OwnCloudClient client, String token) { | ||
| mUploadStarted.set(false); | ||
|
|
||
| if (fileLock != null) { | ||
|
|
@@ -989,6 +989,12 @@ private RemoteOperationResult cleanupE2EUpload(FileLock fileLock, FileChannel ch | |
| return Unit.INSTANCE; | ||
| }); | ||
| } | ||
|
|
||
| // only update local counter after unlock | ||
| if (object instanceof DecryptedFolderMetadataFile metadata) { | ||
| final var parentFile = e2eFiles.getParentFile(); | ||
| getStorageManager().updateE2EECounter(parentFile, metadata); | ||
| } | ||
| } | ||
|
|
||
| e2eFiles.deleteEncryptedTempFile(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| /* | ||
| * Nextcloud - Android Client | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com> | ||
| * SPDX-FileCopyrightText: 2023 Tobias Kaminsky <tobias@kaminsky.me> | ||
| * SPDX-FileCopyrightText: 2023 Nextcloud GmbH | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only | ||
|
|
@@ -12,7 +13,6 @@ import android.content.Context | |
| import androidx.annotation.VisibleForTesting | ||
| import com.google.gson.reflect.TypeToken | ||
| import com.nextcloud.client.account.User | ||
| import com.nextcloud.client.account.UserAccountManagerImpl | ||
| import com.nextcloud.utils.CmsSignatureVerifier | ||
| import com.nextcloud.utils.autoRename.AutoRename | ||
| import com.nextcloud.utils.e2ee.E2EVersionHelper | ||
|
|
@@ -474,8 +474,7 @@ class EncryptionUtilsV2 { | |
| initializationVector: ByteArray, | ||
| authenticationTag: String, | ||
| key: ByteArray, | ||
| metadataFile: DecryptedFolderMetadataFile, | ||
| fileDataStorageManager: FileDataStorageManager | ||
| metadataFile: DecryptedFolderMetadataFile | ||
| ): DecryptedFolderMetadataFile { | ||
| val decryptedFile = DecryptedFile( | ||
| ocFile.decryptedFileName, | ||
|
|
@@ -487,23 +486,17 @@ class EncryptionUtilsV2 { | |
|
|
||
| metadataFile.metadata.files[encryptedFileName] = decryptedFile | ||
| metadataFile.metadata.counter++ | ||
| ocFile.setE2eCounter(metadataFile.metadata.counter) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also aligns with other functions such as |
||
| fileDataStorageManager.saveFile(ocFile) | ||
|
|
||
| return metadataFile | ||
| } | ||
|
|
||
| fun addFolderToMetadata( | ||
| encryptedFileName: String, | ||
| fileName: String, | ||
| metadataFile: DecryptedFolderMetadataFile, | ||
| ocFile: OCFile, | ||
| fileDataStorageManager: FileDataStorageManager | ||
| metadataFile: DecryptedFolderMetadataFile | ||
| ): DecryptedFolderMetadataFile { | ||
| metadataFile.metadata.folders[encryptedFileName] = fileName | ||
| metadataFile.metadata.counter++ | ||
| ocFile.setE2eCounter(metadataFile.metadata.counter) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also aligns with other functions such as |
||
| fileDataStorageManager.saveFile(ocFile) | ||
|
|
||
| return metadataFile | ||
| } | ||
|
|
@@ -861,7 +854,9 @@ class EncryptionUtilsV2 { | |
| oldCounter: Long, | ||
| signature: String | ||
| ): Boolean { | ||
| if (decryptedFolderMetadataFile.metadata.counter < oldCounter) { | ||
| val metadataCounter = decryptedFolderMetadataFile.metadata.counter | ||
| if (metadataCounter < oldCounter) { | ||
| Log_OC.e(TAG, "old counter: $oldCounter, metadata counter $metadataCounter") | ||
| MainApp.showMessage(R.string.e2e_counter_too_old) | ||
| return false | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be after
serializeAndUploadMetadata