-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix subfolders in encrypted folders #17608
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
Draft
daniele-verducci
wants to merge
5
commits into
master
Choose a base branch
from
fix/internal-105265
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+18
−16
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e611738
Fix subfolders in encrypted folders
daniele-verducci eef7e94
Better fix subfolders in encrypted folders (using existing metadata r…
daniele-verducci 8bc21c7
Proposal to fix metadata key check
daniele-verducci 6160ea2
Revert "Updated android-library"
daniele-verducci d374ffa
Rebased
daniele-verducci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ import com.owncloud.android.datamodel.ArbitraryDataProvider | |
| import com.owncloud.android.datamodel.FileDataStorageManager | ||
| import com.owncloud.android.datamodel.OCFile | ||
| import com.owncloud.android.datamodel.e2e.v1.encrypted.EncryptedFolderMetadataFileV1 | ||
| import com.owncloud.android.datamodel.e2e.v2.encrypted.EncryptedFolderMetadataFile | ||
| import com.owncloud.android.lib.common.OwnCloudClient | ||
| import com.owncloud.android.lib.common.OwnCloudClientFactory | ||
| import com.owncloud.android.lib.common.utils.Log_OC | ||
| import com.owncloud.android.lib.resources.e2ee.GetMetadataRemoteOperation | ||
|
|
@@ -25,6 +25,7 @@ import com.owncloud.android.operations.GetCapabilitiesOperation | |
| import com.owncloud.android.ui.dialog.setupEncryption.CertificateValidator | ||
| import com.owncloud.android.ui.dialog.setupEncryption.model.DownloadKeyResult | ||
| import com.owncloud.android.utils.EncryptionUtils | ||
| import com.owncloud.android.utils.EncryptionUtilsV2 | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.withContext | ||
| import org.apache.commons.httpclient.HttpStatus | ||
|
|
@@ -102,24 +103,27 @@ class E2EEKeyInspector @Inject constructor( | |
| val metadata = metadataResult.resultData | ||
|
|
||
| return@withContext if (E2EVersionHelper.isV2Plus(capability)) { | ||
| decryptsMetadataV2(metadata.metadata, privateKey, client.userId) | ||
| decryptsMetadataV2(folder, privateKey, client) | ||
| } else { | ||
| decryptsMetadataV1(metadata.metadata, privateKey, folder.localId) | ||
| } | ||
| } | ||
|
|
||
| private fun decryptsMetadataV2(serializedMetadata: String, privateKey: String, userId: String): Boolean { | ||
| val metadataFile = EncryptionUtils.deserializeJSON( | ||
| serializedMetadata, | ||
| object : TypeToken<EncryptedFolderMetadataFile>() {} | ||
| ) | ||
|
|
||
| val user = metadataFile.users.find { it.userId == userId } | ||
| ?: throw IllegalStateException("cannot find current user in metadata") | ||
| private fun decryptsMetadataV2(ocFile: OCFile, privateKey: String, client: OwnCloudClient): Boolean { | ||
| val userId = client.userId | ||
|
|
||
| return try { | ||
| EncryptionUtils.decryptStringAsymmetricV2(user.encryptedMetadataKey, privateKey) | ||
| true | ||
| val metadataKey = EncryptionUtilsV2().retrieveTopMostMetadataKey( | ||
|
Collaborator
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. I saw this comment in the master. @tobiasKaminsky I think using
|
||
| ocFile, | ||
| storageManager, | ||
| client, | ||
| userId, | ||
| privateKey, | ||
| accountManager.user, | ||
| context, | ||
| arbitraryDataProvider | ||
| ) | ||
| !metadataKey.isEmpty() | ||
| } catch (e: Exception) { | ||
| Log_OC.w(TAG, "user tried to decrypt folder's metadata with different private key: $e") | ||
| false | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Previously
GetMetadataRemoteOperationwas already given the metadata why now we need toretrieveTopMostMetadataand also eventually calldecryptFolderMetadataFile?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.
GetMetadataRemoteOperation retrieves the metadata for the current folder, but I saw with the debugger that the users array is present only if the folder is the root encrypted folder. If we are in a subfolder, it's not. I think this isn't a server bug because it's working in the web version (checked the calls and the answer is the same, just in XML instead of JSON, so they must be keeping the root encrypted folder's key and using it for the subfolders, I believe)