Skip to content

Adding encryption decorator#107

Merged
Nyholm merged 15 commits into
php-cache:masterfrom
PrisisForks:add-encrypting-decorator
Nov 9, 2016
Merged

Adding encryption decorator#107
Nyholm merged 15 commits into
php-cache:masterfrom
PrisisForks:add-encrypting-decorator

Conversation

@prisis
Copy link
Copy Markdown
Contributor

@prisis prisis commented Nov 6, 2016

Question Answer
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #8
License MIT
Doc PR

Description

Adding a encryption decorator for psr6

TODO

  • Add tests
  • Add documentation
  • Updated Changelog.md
  • Rename package from encrypted to encryption

@prisis prisis changed the title Add encrypting decorator [WIP] Add encrypting decorator Nov 6, 2016
@prisis prisis changed the title [WIP] Add encrypting decorator [WIP] Adding encryption decorator Nov 6, 2016
Copy link
Copy Markdown
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Awesome. I like this! I just had some minor comments

Comment thread src/Encrypted/README.md Outdated

### Use

Read the [documentation on usage](http://www.php-cache.com/en/latest/tagging/).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Update link

Comment thread src/Encrypted/README.md Outdated

### Implement

Read the [documentation on implementation](http://www.php-cache.com/en/latest/implementing-cache-pools/tagging/).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Update link

Comment thread src/Encrypted/README.md Outdated
to tag related items, and then clear the cached data for that tag only. It is a part of the PHP Cache organisation. To read about
features like tagging and hierarchy support please read the shared documentation at [www.php-cache.com](http://www.php-cache.com).

*Note: Performance will be best with a driver such as memcached or redis, which automatically purges stale records.*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should be removed

Comment thread src/Encrypted/README.md Outdated

This repository has traits and interfaces that makes a PSR-6 cache implementation encrypted. Using tags allow you
to tag related items, and then clear the cached data for that tag only. It is a part of the PHP Cache organisation. To read about
features like tagging and hierarchy support please read the shared documentation at [www.php-cache.com](http://www.php-cache.com).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These rows should be updated/removed.

@prisis
Copy link
Copy Markdown
Contributor Author

prisis commented Nov 7, 2016

@Nyholm any idea why i cant get testSaveDeferredWhenChangingValues to pass?

@Nyholm
Copy link
Copy Markdown
Member

Nyholm commented Nov 7, 2016

Ill see.

@Nyholm
Copy link
Copy Markdown
Member

Nyholm commented Nov 7, 2016

The testSaveDeferredWhenChangingValues test makes sure that the raw value has not changed on the deferred queue before we do a save.

Since you encrypt the value you break the test. It is the test that is flawed though. I'll fix it.

@prisis
Copy link
Copy Markdown
Contributor Author

prisis commented Nov 7, 2016

Maybe i can find a workaround

Copy link
Copy Markdown
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

The issue with the deferred save has to do with the cloning. When we get an item from the deferred queue we clone it to make sure it wont be changed. https://github.com/php-cache/cache/blob/0.3/src/Adapter/Common/AbstractCachePool.php#L88

The issue is that we have a CacheItem with reference A and we put a EncryptedItemDecorator with reference B on the deferred queue. When we later call Pool::get we clone the EncryptedItemDecorator to a new place in memory and it gets reference C. Though, EncryptedItemDecorator (C) has still a reference to CacheItem (A).

The EncryptedItemDecorator should implement __clone() to propagate the clone function down to the CacheItem. Something like:

class EncryptedItemDecorator {
  // ...
  public function __clone() {
    $this->cacheItem = clone $this->cacheItem;
  }
}

Comment thread composer.json
"symfony/options-resolver": "^2.7 || ^3.0"
},
"require-dev": {
"defuse/php-encryption": "^2.0",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this the best encryption package for us?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is the best i know, you know a other one?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have no idea. =)

I trust that you have done some research to find a popular and robust package. And also one that you like.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If you like you can read https://paragonie.com/blog/2016/05/defuse-security-s-php-encryption-library-version-2-0-0-released and if @paragonie-scott recommend it, so it musst be really secure :D

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Aside from libsodium, you'll be hard-pressed to do better. @defuse really knocked it out of the park. :)

* with this source code in the file LICENSE.
*/

namespace Cache\Encryption;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should rename the folder to "Encryption". Right now all files are in a folder named "Encrypted"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

use Cache\Taggable\TaggableItemInterface;
use Defuse\Crypto\Crypto;
use Defuse\Crypto\Key;
use Psr\Cache\CacheItemInterface;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You miss

use Psr\Cache\CacheItemPoolInterface;

@Nyholm
Copy link
Copy Markdown
Member

Nyholm commented Nov 7, 2016

I think we can ignore them for now but this sure is an issue.. let's fix that before making our first tag.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Nov 7, 2016

Current coverage is 83.56% (diff: 89.61%)

Merging #107 into master will increase coverage by 0.46%

@@             master       #107   diff @@
==========================================
  Files            22         24     +2   
  Lines          1006       1083    +77   
  Methods         218        241    +23   
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits            836        905    +69   
- Misses          170        178     +8   
  Partials          0          0          

Powered by Codecov. Last update 55d7af5...74639aa

class EncryptedItemDecorator implements CacheItemInterface, HasExpirationDateInterface, TaggableItemInterface
{
/**
* @type CacheItemInterface
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IIRC these should all be var. I think type was removed from that spec

Copy link
Copy Markdown
Contributor Author

@prisis prisis Nov 8, 2016

Choose a reason for hiding this comment

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

we can fix it with styleci, we use it in all packages @type

}
],
"require": {
"php": "^5.5 || ^7.0",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i think ^5.5|^7.0 is the "right" way to do this now?

Also, should we continue supporting 5.5? @Nyholm

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lets support 5.5 if we have no reason to drop it.

The current syntax (at least the one in the docs) are dubble pipe.

"psr/cache": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0 || ^5.1",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

formatting is strange here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we use the same format in all phpunits

@cryptiklemur
Copy link
Copy Markdown
Member

Really like this!

@prisis
Copy link
Copy Markdown
Contributor Author

prisis commented Nov 8, 2016

So the last thing to do is add documentation

Copy link
Copy Markdown
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Is this ready for merge?

@prisis
Copy link
Copy Markdown
Contributor Author

prisis commented Nov 9, 2016

test are all green, only need to add docs for it

@Nyholm Nyholm merged commit 3e13831 into php-cache:master Nov 9, 2016
@prisis prisis deleted the add-encrypting-decorator branch November 9, 2016 21:33
@prisis prisis changed the title [WIP] Adding encryption decorator Adding encryption decorator Nov 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants