Skip to content
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

Changes to encryption wrapper #28774

Merged
merged 1 commit into from
Aug 29, 2017
Merged

Changes to encryption wrapper #28774

merged 1 commit into from
Aug 29, 2017

Conversation

sharidas
Copy link
Contributor

Changes made to encryption wrapper so that we can
get the commands like transfer-ownership or recreate
masterkey work. This change doesn't alter the core
functionality of copy or fopen function. The arguments
passed to the function remains same as other wrappers.

Signed-off-by: Sujith H sharidasan@owncloud.com

Description

Changes made to the ecnryption warpper and view to get the transfer-ownership command recreate master key work. Basically there was a problem which caused to change the arguments passed to the routines like fopen or copy. With this change we don't have to alter them. But we use flags to control the code flow for the commands.

Related Issue

Motivation and Context

This change would prevent the modification to common routines which were made to arguments of functions like fopen or copy etc.

How Has This Been Tested?

  • Scratch installation of oC and create 2 users
  • Verified transfer ownership command works with and without encryption between two users.
  • Verified Recreate command for master key works on the same setup.

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.

@sharidas sharidas self-assigned this Aug 23, 2017
@sharidas sharidas added this to the development milestone Aug 23, 2017
Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

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

great progress, see comments

let's use the static approach

* If encryption is enabled and masterkey is the option selected
* kindly use the CustomView wrapper.
*/
/*if ($this->encryptionManager->isEnabled() &&
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove

@@ -86,6 +86,10 @@ class Encryption extends Wrapper {
/** @var ArrayCache */
private $arrayCache;

private $sourcePath;

private $decryptedFile = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

so if I understand correctly, this flag only affects write operations ?

If yes, call it $disableWriteEncryption instead and the methods setDisableWriteEncryption()

* Set the flag to true, so that the file would be
* in the decrypted state.
*/
public function setDecryptedFileFlag() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just pass the flag as argument, no need to write two methods...

* the storage's set value for decrypted file flag is called.
*/

public function setDecryptedFile() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer that the View doesn't know anything about encryption. Encryption is just like a plugin that inserts itself so it's not good that the core code like View relies on encryption specific things.

Let's make flag static in the Encryption class above instead and set it from outside. That should do for now.

$size, $unencryptedSize, $headerSize, $signed, $sourceFileOfRename);
$size, $unencryptedSize, $headerSize, $signed, $this->sourcePath[$path]);

if (isset($this->sourcePath[$path])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to call isset earlier, else line 478 is going to throw a warning when not set

Copy link
Contributor

Choose a reason for hiding this comment

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

@sharidas did you miss this comment ?

Copy link
Contributor Author

@sharidas sharidas Aug 23, 2017

Choose a reason for hiding this comment

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

No, I thought in a different way. wrap() expects either null or string from$this->sourcePath[$path]. So if $this->sourcePath[$path] not set then I set as null at https://github.com/owncloud/core/pull/28774/files#diff-938b56891f3079e628cfda1c331911b7R476 .
Else if its set then unset at line 484. Terrible idea?

} else {
$target = $this->fopen($targetInternalPath, 'w');
$this->sourcePath[$targetInternalPath] = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

use unset for maximum deletion

@sharidas sharidas force-pushed the encryption-wrapper-work branch from 7e04194 to db6b456 Compare August 23, 2017 11:15
@sharidas
Copy link
Contributor Author

  • Removed changes from View which points to encryption.
  • Removed the comment ( code comment )
  • Renamed the variable $decryptedFile to $disableWriteEncryption and also renamed the function associated with the operation to setDisableWriteEncryption(). Argument is passed to setDisableWriteEncryption() for operation set or unset.
  • [x]

* for write mode.
*/
if (self::$disableWriteEncryption && ($mode !== 'r')) {
return fopen($this->storage->getSourcePath($path), $mode);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is going to break horribly with external storage because you are doing a fopen directly on the filesystem.

Use $this->getWrapperStorage()->fopen() instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@PVince81 Updated in my latest PR. Thanks for pointing it out.

@sharidas sharidas force-pushed the encryption-wrapper-work branch 3 times, most recently from 533c1d7 to 313e91a Compare August 24, 2017 06:51
$this->uid, $encryptionModule, $this->storage, $this, $this->util, $this->fileHelper, $mode,
$size, $unencryptedSize, $headerSize, $signed, $sourceFileOfRename);

if (isset($this->sourcePath[$path])) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hope this looks better.

*
* @param $isDisabled bool
*/
public function setDisableWriteEncryption($isDisabled) {
Copy link
Contributor

Choose a reason for hiding this comment

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

function must be static

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@sharidas sharidas force-pushed the encryption-wrapper-work branch from 313e91a to e440f98 Compare August 24, 2017 09:26
@sharidas
Copy link
Contributor Author

sharidas commented Aug 24, 2017

  • Made the function setDisableWriteEncryption static.
  • Used a local variable to pass the $this->sourcePath[$path] if its set else null to -> wrap()
  • Removed the view code

@@ -86,6 +86,10 @@ class Encryption extends Wrapper {
/** @var ArrayCache */
private $arrayCache;

private $sourcePath;
Copy link
Contributor

Choose a reason for hiding this comment

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

PHPDoc comments please

Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

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

👍 add missing PHP doc then this is good to go

Changes made to encryption wrapper so that we can
get the commands like transfer-ownership or recreate
masterkey work. This change doesn't alter the core
functionality of copy or fopen function. The arguments
passed to the function remains same as other wrappers.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
@sharidas sharidas force-pushed the encryption-wrapper-work branch from e440f98 to e0a0851 Compare August 29, 2017 11:24
@PVince81 PVince81 merged commit d32b584 into master Aug 29, 2017
@PVince81 PVince81 deleted the encryption-wrapper-work branch August 29, 2017 15:24
@PVince81
Copy link
Contributor

@sharidas please backport to stable10

@sharidas
Copy link
Contributor Author

sharidas commented Nov 3, 2017

Backport of this PR: #28845

@lock
Copy link

lock bot commented Aug 2, 2019

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 2, 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.

3 participants