Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Fix for the issue #3541 - salt size for Encrypt/Decrypt Filter #3550

Closed
wants to merge 6 commits into from

Conversation

ezimuel
Copy link
Contributor

@ezimuel ezimuel commented Jan 24, 2013

This PR fix the issue #3541. In the BlockCipher used by Encrypt/Decrypt Filter the salt (vector) value has been resize to the correct value during the authentication , according to the encryption algorithm.
This PR is a replacement of the pull #3547.

More changes have been introduced, see comments below.

@Maks3w
Copy link
Member

Maks3w commented Jan 24, 2013

There is a CS issue in the Mcrypt class

Also I think that all the issue must be fixed inside of Mcrypt class without to truncate the salt value outside. Maybe throw an exception on setSalt if salt length is more than saltSize. Optionally add an argument to setSalt for auto truncate the value

@ghost ghost assigned Maks3w Jan 24, 2013
@radnan
Copy link
Contributor

radnan commented Jan 24, 2013

@Maks3w unfortunately you can't do that since different algorithms have different salt sizes and you can change/set the algorithm after setting the salt but before calling encrypt.

@Maks3w
Copy link
Member

Maks3w commented Jan 24, 2013

Then we could add something like getCorrectSalt in Mcrypt class

@ezimuel
Copy link
Contributor Author

ezimuel commented Jan 25, 2013

@Maks3w you cannot truncate the salt during the setSalt in Mcrypt because if you change the encryption algorithm using the setAlgorithm() you will need a different salt size. Also the auto truncate argument to the setSalt is not a good idea, it will confuse people.
Maybe, it would be better to change the getSalt() in Mcrypt, truncating the output according to the actual encryption algorithm. I will try this approach and let you know. I'm also fixing the CS issue.

@Maks3w
Copy link
Member

Maks3w commented Jan 25, 2013

Thank you @ezimuel, we could change getSalt for return algorithm specific salt and getOriginalSalt for return the original value

$this->mcrypt->setKey($this->key);
$this->mcrypt->setPadding(new PKCS7());
foreach ($this->mcrypt->getSupportedAlgorithms() as $algo) {
foreach ($this->mcrypt->getSupportedModes() as $mode) {
$this->mcrypt->setAlgorithm($algo);
$this->mcrypt->setMode($mode);
$this->mcrypt->setSalt($this->salt);
Copy link
Member

Choose a reason for hiding this comment

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

I think that this should be undo too for to have a test with the same salt stored in the object and different algos.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's true.

@ezimuel
Copy link
Contributor Author

ezimuel commented Jan 25, 2013

I changed the get/setSalt in Mcrypt and BlockCipher managing the correct size for the salt according to the encryption algorithm. Only getSalt() truncate the size. As suggested by @Maks3w I added a getOriginalSalt() to retrieve the original salt value.

Moreover, I refactored the implementation of the Zend\Filter\Encrypt and Decrypt adding a setKey() and removing the default key 'ZendFramework'. In this way you must specify a key in order to use it. You can omit to initialize the Vector because we are using the BlockCipher as default adapter and it will generate a random Vector (salt) by default.

This last changed solve finally the issue #3541. I'm going to change also the documentation of Zend\Filter\Encrypt and Zend\Filter\Decrypt.

@Freeaqingme
Copy link
Member

@ezimuel You're requesting this PR to be merged against the master branch. I'm however seeing some (minor) BC changes and perhaps new functionality. Is this because it is considered a security issue?

@@ -247,13 +250,19 @@ public function setKey($key)
*/
public function getKey()
{
return $this->key;
if (strlen($this->key) < $this->getKeySize()) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that check this in set and get is redundant. We the check in the setter is enough

@ezimuel
Copy link
Contributor Author

ezimuel commented Jan 25, 2013

@Freeaqingme Yes, the changes in Zend\Filter\Encrypt and Decrypt are for security issue. The only new features are the setKey() in Zend\Filter\Encrypt and Decrypt and the getOriginalSalt() in BlockCipher and Mcrypt.

weierophinney added a commit that referenced this pull request Jan 25, 2013
weierophinney added a commit to zendframework/zend-crypt that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-crypt that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-filter that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-filter that referenced this pull request May 15, 2015
ezimuel added a commit to zendframework/zend-filter that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants