-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Extend encryption:fix-encrypted-version to also detect encrypted files with 0 #31874
Comments
I like this feature. I had the problem that I executed the decrypt-all command but for some reason not all files were decrypted. Such a feature would help to repair in such a case |
Steps to recreate:
After the fix running |
I am not sure if I got this correctly: I am unable to get the file after setting encrypted to 0, but when looking at apps/encryption/lib/Command/FixEncryptedVersion.php it does not seem to specifically check that encrypted is not 0, it tries an fread:
And this fread returns true in my case so it says the file is OK. (even if failing to display in Files UI) How can I test |
a lot of magic is happening in the Encryption storage and stream wrappers. I don't remember exactly whether it's checking the header on fopen or on the first fread. |
Also note: in the PHP $cacheEntry it is likely that the attribute key is "encryptedVersion" for the number and "encrypted" for the bool. See https://github.com/nextcloud/server/blob/master/lib/private/Files/Cache/Cache.php#L457 |
Now thinking, I think the encryption check for the web UI is done at a higher level to prevent people to download the raw encrypted file, which would be bad especially when done automatically through the desktop client. The PHP level's fopen/fread will simply ignore the encrypted header if the flag is not set. |
There is actually nothing preventing downloading the raw encrypted file from what I can see, if I set encrypted to 0 in the DB I can download it, it just does not show as an image because it is encrypted. If I alter the fix command to test encryption first it works. So I can add a flag that does this. I think I found a solution by using stat and checking for hasHeader: https://github.com/nextcloud/server/blob/master/lib/private/Files/Storage/Wrapper/Encryption.php#L871 |
How to use GitHub
Is your feature request related to a problem? Please describe.
In some setups, it can happen that encrypted files exist or have been recovered from backup.
When running occ files:scan on those files, the "encrypted" column will still say "0" which means unencrypted as the scan command is not able to detect if files are encrypted.
So those files are not accessible nor downloadable.
Describe the solution you'd like
Extend the
occ encryption:fix-encrypted-version
to also attempt to detect encrypted files that have the column set to 0.The detection can attempt to set the value to "1" or higher as per its current algorithm and detect if decryption worked.
If decryption worked, it must adjust the value in the database.
There is already logic in place that does this for already encrypted files, so the extension should be a matter of including "0" in the files to be searched.
To avoid potential unwanted side effects, the option to include "0" in the search should be optional. So the user will need to add an option like
--detect-encrypted
(find better wording)Additional context
This is with master key encryption.
The text was updated successfully, but these errors were encountered: