This repository has been archived by the owner on Jan 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from salesupply/develop
Dev to Master for 1.0 merge
- Loading branch information
Showing
13 changed files
with
488 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1 @@ | ||
# Composer files | ||
composer.phar | ||
vendor/ | ||
|
||
# Local configs | ||
config/autoload/*.local.php | ||
|
||
# Binary gettext files | ||
*.mo | ||
|
||
# Data | ||
data/logs/ | ||
data/cache/ | ||
data/sessions/ | ||
data/tmp/ | ||
temp/ | ||
|
||
#Doctrine 2 | ||
data/DoctrineORMModule/Proxy/ | ||
data/DoctrineORMModule/cache/ | ||
|
||
|
||
# Legacy ZF1 | ||
demos/ | ||
extras/documentation | ||
config/local.config.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace ZfDoctrineEncryptModule; | ||
|
||
use Doctrine\Common\Annotations\AnnotationReader; | ||
use ZfDoctrineEncryptModule\Adapter\HaliteAdapter; | ||
use ZfDoctrineEncryptModule\Factory\HaliteAdapterFactory; | ||
use ZfDoctrineEncryptModule\Factory\ZfDoctrineEncryptedServiceFactory; | ||
|
||
return [ | ||
'doctrine_factories' => [ | ||
'encryption' => ZfDoctrineEncryptedServiceFactory::class, | ||
], | ||
'doctrine' => [ | ||
'encryption' => [ | ||
'orm_default' => [ | ||
'adapter' => 'encryption_adapter', | ||
'reader' => AnnotationReader::class, | ||
], | ||
], | ||
'eventmanager' => [ | ||
'orm_default' => [ | ||
'subscribers' => [ | ||
'doctrine.encryption.orm_default', | ||
], | ||
], | ||
], | ||
], | ||
'service_manager' => [ | ||
'aliases' => [ | ||
'encryption_adapter' => HaliteAdapter::class, | ||
], | ||
'factories' => [ | ||
// Using aliases so someone else can use own adapter/factory | ||
HaliteAdapter::class => HaliteAdapterFactory::class | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace ZfDoctrineEncryptModule; | ||
|
||
return [ | ||
'doctrine' => [ | ||
'encryption' => [ | ||
'orm_default' => [ | ||
'key' => '', // Must be 32 characters - Halite requirement | ||
'salt' => '', // Must be 32 characters - Halite requirement | ||
], | ||
], | ||
], | ||
]; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace ZfDoctrineEncryptModule\Adapter; | ||
|
||
use DoctrineEncrypt\Encryptors\EncryptorInterface; | ||
use ParagonIE\Halite\Alerts\InvalidKey; | ||
use ParagonIE\Halite\HiddenString; | ||
use ParagonIE\Halite\Symmetric\Crypto; | ||
use ParagonIE\Halite\Symmetric\EncryptionKey; | ||
use ParagonIE\Halite\Util as CryptoUtil; | ||
|
||
class HaliteAdapter implements EncryptorInterface | ||
{ | ||
/** | ||
* @var EncryptionKey | ||
*/ | ||
private $key; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $salt; | ||
|
||
/** | ||
* HaliteAdapter constructor. | ||
* @param $key | ||
* @param $salt | ||
* @throws InvalidKey | ||
* @throws \ParagonIE\Halite\Alerts\CannotPerformOperation | ||
*/ | ||
public function __construct($key, $salt) | ||
{ | ||
if (CryptoUtil::safeStrlen($key) !== \Sodium\CRYPTO_STREAM_KEYBYTES) { | ||
|
||
throw new InvalidKey( | ||
'Encryption key used for ' . __CLASS__ . ' must be exactly ' . \Sodium\CRYPTO_STREAM_KEYBYTES . ' characters long' | ||
); | ||
} | ||
|
||
if (CryptoUtil::safeStrlen($salt) !== \Sodium\CRYPTO_STREAM_KEYBYTES) { | ||
|
||
throw new InvalidKey( | ||
'Salt used for ' . __CLASS__ . ' must be exactly ' . \Sodium\CRYPTO_STREAM_KEYBYTES . ' characters long' | ||
); | ||
} | ||
|
||
$this->setKey((new EncryptionKey((new HiddenString($key))))); | ||
$this->setSalt($salt); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function encrypt($data) | ||
{ | ||
return Crypto::encrypt(new HiddenString($this->getSalt() . $data), $this->getKey()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function decrypt($data) | ||
{ | ||
$decrypted = Crypto::decrypt($data, $this->getKey()); | ||
|
||
return str_replace($this->getSalt(), '', $decrypted); | ||
} | ||
|
||
/** | ||
* @return EncryptionKey | ||
*/ | ||
public function getKey(): EncryptionKey | ||
{ | ||
return $this->key; | ||
} | ||
|
||
/** | ||
* @param EncryptionKey $key | ||
* @return HaliteAdapter | ||
*/ | ||
public function setKey(EncryptionKey $key): HaliteAdapter | ||
{ | ||
$this->key = $key; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSalt(): string | ||
{ | ||
return $this->salt; | ||
} | ||
|
||
/** | ||
* @param string $salt | ||
* @return HaliteAdapter | ||
*/ | ||
public function setSalt(string $salt): HaliteAdapter | ||
{ | ||
$this->salt = $salt; | ||
return $this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
namespace ZfDoctrineEncryptModule\Exception; | ||
|
||
class OptionsNotFoundException extends \Exception | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace ZfDoctrineEncryptModule\Factory; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use Zend\ServiceManager\Factory\FactoryInterface; | ||
use ZfDoctrineEncryptModule\Adapter\HaliteAdapter; | ||
use ZfDoctrineEncryptModule\Exception\OptionsNotFoundException; | ||
|
||
class HaliteAdapterFactory implements FactoryInterface | ||
{ | ||
/** | ||
* @param ContainerInterface $container | ||
* @param string $requestedName | ||
* @param array|null $options | ||
* @return object|HaliteAdapter | ||
* @throws OptionsNotFoundException | ||
* @throws \ParagonIE\Halite\Alerts\CannotPerformOperation | ||
* @throws \ParagonIE\Halite\Alerts\InvalidKey | ||
*/ | ||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) | ||
{ | ||
if (!key_exists('key', $options) && !is_string($options['key'])) { | ||
|
||
throw new OptionsNotFoundException('Option "key" is required.'); | ||
} | ||
|
||
if (!key_exists('salt', $options) && !is_string($options['salt'])) { | ||
|
||
throw new OptionsNotFoundException('Option "salt" is required.'); | ||
} | ||
|
||
return new HaliteAdapter($options['key'], $options['salt']); | ||
} | ||
} |
Oops, something went wrong.