Repository navigation
Fix recreate masterkey issue when decryptall command used - #29731
Conversation
When decrypt-all command is used the files get decrypted. After this when user executes the recreate masterkey command, the variable disableWriteEncryption is set to true and never set to false. Though the decrypted files when tried decrypt again in the copy operation, throws exception, the value should be set to false. If not set to false, user files would never be re-encrypted with recreate masterkey. Signed-off-by: Sujith H <[email protected]>
|
Why would it throw an exception in something that looks like a normal operation ? |
Codecov Report
@@ Coverage Diff @@
## master #29731 +/- ##
============================================
- Coverage 62.52% 62.52% -0.01%
Complexity 17619 17619
============================================
Files 1045 1045
Lines 58071 58072 +1
============================================
Hits 36311 36311
- Misses 21760 21761 +1
Continue to review full report at Codecov.
|
The reason for exception is due to the fact that its trying to decrypt the file, which was already decrypted. The decrypt-all command decrypts all files in the oC and then re-enables the encryption modules. So far that's good. Now the problem comes when recreate masterkey is called. The recreate master key internally calls decrypt-all methods. To verify this error one more scenario would be to run decrypt-all again. Even I was expecting the case to be normal and why should it throw exception. The reason comes due to decrypting the decrypted file : https://github.com/owncloud/core/blob/master/lib/private/Encryption/DecryptAll.php#L278 this copy calls the fopen in read mode for the source file. And eventually during this call reaches fopen of Encryption wrapper https://github.com/owncloud/core/blob/master/lib/private/Files/Storage/Wrapper/Encryption.php#L407 which eventually leads the code flow to https://github.com/owncloud/core/blob/master/lib/private/Files/Storage/Wrapper/Encryption.php#L166. Which leads to call https://github.com/owncloud/core/blob/master/lib/private/Files/Storage/Wrapper/Encryption.php#L518 and eventually https://github.com/owncloud/core/blob/master/lib/private/Files/Storage/Wrapper/Encryption.php#L599. Since the file is already decrypted, the call to https://github.com/owncloud/encryption/blob/master/lib/Crypto/Crypt.php#L578 causes the exception. Hope this justification looks ok. When this exception happens, the other part is the variable in the patch is still |
|
Not sure if it would be a good idea to introduce a method get value of disableWriteEncryption, to please the tests!! Any suggestions? |
PVince81
left a comment
There was a problem hiding this comment.
👍 code is fine then for now, please backport
|
Backport PR: #29735 |
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |

When decrypt-all command is used the files get decrypted.
After this when user executes the recreate masterkey
command, the variable disableWriteEncryption is set to
true and never set to false. Though the decrypted files
when tried decrypt again in the copy operation, throws
exception, the value should be set to false. If not
set to false, user files would never be re-encrypted
with recreate masterkey.
Signed-off-by: Sujith H [email protected]
Description
This tries to solve the problem caused when user tries to recreate masterkey after executing decrypt-all command.
Related Issue
#29726
Motivation and Context
When user executes decrypt-all command the oC files are decrypted successfully. Now after this step if user tries to execute recreate masterkey command, then the user could see that decrypting already decrypted files throws exception and code flow reaches: https://github.com/owncloud/core/blob/master/lib/private/Files/Storage/Wrapper/Encryption.php#L795. As a result the value of the variable
disableWriteEncryptionstill remains false. This causes problem with fopen during re-encryption phase. So this change helps to reset the value to false.How Has This Been Tested?
This has also been tested in the same way mentioned in the issue : encryption:recreate-master-key does not encrypt a file if we have run before encryption:decrypt-all command #29726
Screenshots (if appropriate):
Types of changes
Checklist: