Skip to content

Fix recreate masterkey issue when decryptall command used - #29731

Merged
PVince81 merged 1 commit into
masterfrom
encryption-fix
Dec 1, 2017
Merged

PVince81 merged 1 commit into
masterfrom
encryption-fix

Conversation

@sharidas

Copy link
Copy Markdown
Contributor

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 disableWriteEncryption still 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?

  1. Create user admin and login
  2. Run decrypt-all command from the command line
  3. Run recreate masterkey command from the command line the files should remain encrypted.
    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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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]>
@sharidas sharidas self-assigned this Nov 30, 2017
@PVince81 PVince81 added this to the QA milestone Nov 30, 2017
@PVince81

PVince81 commented Nov 30, 2017 •

Copy link
Copy Markdown
Contributor

Why would it throw an exception in something that looks like a normal operation ?

@codecov

codecov Bot commented Dec 1, 2017

Copy link
Copy Markdown

Codecov Report

Merging #29731 into master will decrease coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
lib/private/Files/Storage/Wrapper/Encryption.php 67.65% <0%> (-0.17%) 154 <0> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 85fefcf...2fbfd84. Read the comment docs.

@sharidas

sharidas commented Dec 1, 2017

Copy link
Copy Markdown
Contributor Author

Why would it throw an exception in something that looks like a normal operation ?

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 true. And this was causing the mess.

@sharidas

sharidas commented Dec 1, 2017

Copy link
Copy Markdown
Contributor Author

Not sure if it would be a good idea to introduce a method get value of disableWriteEncryption, to please the tests!! Any suggestions?

@PVince81 PVince81 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 code is fine then for now, please backport

@PVince81
PVince81 merged commit 0e72e3c into master Dec 1, 2017
@PVince81
PVince81 deleted the encryption-fix branch December 1, 2017 08:32
@sharidas

sharidas commented Dec 1, 2017

Copy link
Copy Markdown
Contributor Author

Backport PR: #29735

@davitol

davitol commented Dec 1, 2017

Copy link
Copy Markdown
Contributor

@sharidas WFM, solves #29726

I have also seen that after running sudo -u www-data ./occ encryption:recreate-master-key

an error appears in the webUI if you try to create a new file:

screen shot 2017-12-01 at 09 53 17

It gets solved when you logout and login again

@lock

lock Bot commented Aug 1, 2019

Copy link
Copy Markdown

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.

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants