@@ -92,7 +92,7 @@ |
||
| 92 | 92 | |
| 93 | 93 | // rawKey is locked and become instance of \Defuse\Crypto\Key. |
| 94 | 94 | $this->rawKey = $this->getRawKey() |
| 95 | - ->unlockKey($this->getSecret()); |
|
| 95 | + ->unlockKey($this->getSecret()); |
|
| 96 | 96 | |
| 97 | 97 | return $this; |
| 98 | 98 | } |
@@ -99,7 +99,7 @@ |
||
| 99 | 99 | * @var FormatterHelper |
| 100 | 100 | */ |
| 101 | 101 | $formatter = $this->getHelperSet() |
| 102 | - ->get('formatter'); |
|
| 102 | + ->get('formatter'); |
|
| 103 | 103 | |
| 104 | 104 | $output->writeln(array( |
| 105 | 105 | '', |
@@ -26,13 +26,13 @@ |
||
| 26 | 26 | protected function configure() |
| 27 | 27 | { |
| 28 | 28 | $this->setName('mes:crypto:generate-secret') |
| 29 | - ->setDescription('Generates an authentication secret') |
|
| 30 | - ->setHelp(<<<'EOF' |
|
| 29 | + ->setDescription('Generates an authentication secret') |
|
| 30 | + ->setHelp(<<<'EOF' |
|
| 31 | 31 | The <info>%command.name%</info> generates an authentication secret. |
| 32 | 32 | |
| 33 | 33 | <info>%command.full_name%</info> |
| 34 | 34 | EOF |
| 35 | - ); |
|
| 35 | + ); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | $random = \bin2hex(random_bytes(20)); |
| 77 | 77 | $this->symfonyStyle->newLine(); |
| 78 | 78 | $question = new Question($this->getQuestion('Insert your authentication secret or use this one randomly generated', $random), $random); |
| 79 | - $question->setValidator(function ($secret) { |
|
| 79 | + $question->setValidator(function($secret) { |
|
| 80 | 80 | if (!ctype_print($secret)) { |
| 81 | 81 | throw new \RuntimeException(sprintf('The authentication secret is not printable', $secret)); |
| 82 | 82 | } |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | $dh->start(spl_object_hash($process), "Find {$options['dir']}", 'START'), |
| 207 | 207 | )); |
| 208 | 208 | |
| 209 | - $process->run(function ($type, $buffer) use ($process, $output, $dh) { |
|
| 209 | + $process->run(function($type, $buffer) use ($process, $output, $dh) { |
|
| 210 | 210 | $output->writeln($dh->progress(spl_object_hash($process), $buffer, Process::ERR === $type)); |
| 211 | 211 | }); |
| 212 | 212 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | parent::initialize($input, $output); |
| 42 | 42 | |
| 43 | 43 | $this->helper = $this->getHelperSet() |
| 44 | - ->get('question'); |
|
| 44 | + ->get('question'); |
|
| 45 | 45 | |
| 46 | 46 | $this->symfonyStyle = $this->getStyle($input, $output); |
| 47 | 47 | } |
@@ -49,9 +49,9 @@ discard block |
||
| 49 | 49 | protected function configure() |
| 50 | 50 | { |
| 51 | 51 | $this->setName('mes:crypto:generate-key') |
| 52 | - ->setDefinition($this->createDefinition()) |
|
| 53 | - ->setDescription('Generates an encoded key with or without authentication secret') |
|
| 54 | - ->setHelp(<<<'EOF' |
|
| 52 | + ->setDefinition($this->createDefinition()) |
|
| 53 | + ->setDescription('Generates an encoded key with or without authentication secret') |
|
| 54 | + ->setHelp(<<<'EOF' |
|
| 55 | 55 | The <info>%command.name%</info> generates an encoded key with or without authentication secret and optionally it saves the printable key and the secret in a ini format .crypto file. |
| 56 | 56 | |
| 57 | 57 | <info>%command.full_name%</info> |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | <info>%command.full_name%</info> --dir /path/to/dir/key.crypto |
| 62 | 62 | EOF |
| 63 | - ); |
|
| 63 | + ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | protected function interact(InputInterface $input, OutputInterface $output) |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | $this->writeSection($output, 'Generating key'.($secret ? ' with authentication secret' : '').($dir ? " in $dir" : '')); |
| 134 | 134 | |
| 135 | 135 | $encodedKey = $keyGenerator->generate($secret) |
| 136 | - ->getEncoded(); |
|
| 136 | + ->getEncoded(); |
|
| 137 | 137 | |
| 138 | 138 | $this->log($logger, "The encoded key has been generated with the following sequence:\n{$encodedKey}\n", LogLevel::INFO); |
| 139 | 139 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * @var DebugFormatterHelper |
| 198 | 198 | */ |
| 199 | 199 | $dh = $this->getHelperSet() |
| 200 | - ->get('debug_formatter'); |
|
| 200 | + ->get('debug_formatter'); |
|
| 201 | 201 | |
| 202 | 202 | $process = new Process("ls -la {$options['dir']} | grep \".crypto\""); |
| 203 | 203 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $rootNode = $treeBuilder->root('mes_crypto'); |
| 32 | 32 | |
| 33 | 33 | $rootNode |
| 34 | - ->children() |
|
| 34 | + ->children() |
|
| 35 | 35 | ->arrayNode('key') |
| 36 | 36 | ->addDefaultsIfNotSet() |
| 37 | 37 | ->children() |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | ->info('your_encryption_service_id. Default: Mes Encryption.') |
| 99 | 99 | ->defaultNull() |
| 100 | 100 | ->end() |
| 101 | - ->end() |
|
| 101 | + ->end() |
|
| 102 | 102 | ; |
| 103 | 103 | |
| 104 | 104 | return $treeBuilder; |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | ->info('Encoded key or path to .crypto file. If key is null, it generates a different random key for each request.') |
| 42 | 42 | ->beforeNormalization() |
| 43 | 43 | ->ifString() |
| 44 | - ->then(function ($v) { |
|
| 44 | + ->then(function($v) { |
|
| 45 | 45 | if (is_file($v) && is_readable($v)) { |
| 46 | 46 | return array('path' => $v); |
| 47 | 47 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | ->end() |
| 52 | 52 | ->validate() |
| 53 | 53 | ->ifArray() |
| 54 | - ->then(function ($v) { |
|
| 54 | + ->then(function($v) { |
|
| 55 | 55 | $path = $v['path']; |
| 56 | 56 | $key = $v['key']; |
| 57 | 57 | |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | $this->keyStorage->setKey($key); |
| 35 | 35 | |
| 36 | 36 | $this->assertInstanceOf('Defuse\Crypto\KeyProtectedByPassword', $this->keyStorage->getKey() |
| 37 | - ->getRawKey()); |
|
| 37 | + ->getRawKey()); |
|
| 38 | 38 | $this->assertSame($secret, $this->keyStorage->getKey() |
| 39 | 39 | ->getSecret()); |
| 40 | 40 | } |
@@ -49,6 +49,6 @@ |
||
| 49 | 49 | private function unlockKey(Key $key) |
| 50 | 50 | { |
| 51 | 51 | return $key->unlock() |
| 52 | - ->getRawKey(); |
|
| 52 | + ->getRawKey(); |
|
| 53 | 53 | } |
| 54 | 54 | } |
@@ -129,23 +129,23 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | // Reads encoded key from configuration file if key is not external. |
| 131 | 131 | $rawKeyDefinition->setClass($defuseKey) |
| 132 | - ->setFactory(array( |
|
| 133 | - $defuseKey, |
|
| 134 | - 'loadFromAsciiSafeString', |
|
| 135 | - )); |
|
| 132 | + ->setFactory(array( |
|
| 133 | + $defuseKey, |
|
| 134 | + 'loadFromAsciiSafeString', |
|
| 135 | + )); |
|
| 136 | 136 | $rawKeyDefinition->setArguments(array( |
| 137 | 137 | $keyIsExternal ? $loadKey : $key, |
| 138 | 138 | )); |
| 139 | 139 | } else { |
| 140 | 140 | $rawKeyDefinition->setClass($defuseKey) |
| 141 | - ->setArguments($secretExists ? array($secretIsExternal ? $loadSecret : $secret) : array()) |
|
| 142 | - ->setFactory($secretExists ? array( |
|
| 143 | - 'Defuse\Crypto\KeyProtectedByPassword', |
|
| 144 | - 'createRandomPasswordProtectedKey', |
|
| 145 | - ) : array( |
|
| 146 | - 'Defuse\Crypto\Key', |
|
| 147 | - 'createNewRandomKey', |
|
| 148 | - )); |
|
| 141 | + ->setArguments($secretExists ? array($secretIsExternal ? $loadSecret : $secret) : array()) |
|
| 142 | + ->setFactory($secretExists ? array( |
|
| 143 | + 'Defuse\Crypto\KeyProtectedByPassword', |
|
| 144 | + 'createRandomPasswordProtectedKey', |
|
| 145 | + ) : array( |
|
| 146 | + 'Defuse\Crypto\Key', |
|
| 147 | + 'createNewRandomKey', |
|
| 148 | + )); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | if ($createRandomKey || (!$createRandomKey && !$keyIsExternal)) { |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | $container->setDefinition('mes_crypto.raw_key', $rawKeyDefinition) |
| 156 | - ->setPublic(false); |
|
| 156 | + ->setPublic(false); |
|
| 157 | 157 | |
| 158 | 158 | // Key |
| 159 | 159 | $keyDefinition = new Definition('Mes\Security\CryptoBundle\Model\Key', array( |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | 'create', |
| 166 | 166 | )); |
| 167 | 167 | $container->setDefinition('mes_crypto.key', $keyDefinition) |
| 168 | - ->setPublic(false); |
|
| 168 | + ->setPublic(false); |
|
| 169 | 169 | |
| 170 | 170 | $keyManagerDefinition = $container->getDefinition('mes_crypto.key_manager_wrapper'); |
| 171 | 171 | |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | private function setCryptoLoaderResource(ContainerBuilder $container, $resource) |
| 201 | 201 | { |
| 202 | 202 | $container->getDefinition('mes_crypto.crypto_loader') |
| 203 | - ->replaceArgument(0, $resource); |
|
| 203 | + ->replaceArgument(0, $resource); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | { |
| 95 | 95 | $this->encryption->expects($this->once()) |
| 96 | 96 | ->method('encryptFile') |
| 97 | - ->will($this->returnCallback(function ($input, $output) { |
|
| 97 | + ->will($this->returnCallback(function($input, $output) { |
|
| 98 | 98 | $fs = new Filesystem(); |
| 99 | 99 | $fs->dumpFile($output, ''); |
| 100 | 100 | })); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | $this->encryption->expects($this->once()) |
| 112 | 112 | ->method('decryptFile') |
| 113 | - ->will($this->returnCallback(function ($input, $output) { |
|
| 113 | + ->will($this->returnCallback(function($input, $output) { |
|
| 114 | 114 | $fs = new Filesystem(); |
| 115 | 115 | $fs->dumpFile($output, 'Plain text'); |
| 116 | 116 | })); |
@@ -36,13 +36,13 @@ discard block |
||
| 36 | 36 | public function testEncryptEncryptsPlaintext() |
| 37 | 37 | { |
| 38 | 38 | $this->encryption->expects($this->once()) |
| 39 | - ->method('encrypt') |
|
| 40 | - ->with('The quick brown fox jumps over the lazy dog', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
|
| 39 | + ->method('encrypt') |
|
| 40 | + ->with('The quick brown fox jumps over the lazy dog', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
|
| 41 | 41 | ->getMock()) |
| 42 | - ->will($this->returnValue('ThisIsACipherText')); |
|
| 42 | + ->will($this->returnValue('ThisIsACipherText')); |
|
| 43 | 43 | |
| 44 | 44 | $ciphertext = $this->wrapper->encrypt('The quick brown fox jumps over the lazy dog', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
| 45 | - ->getMock()); |
|
| 45 | + ->getMock()); |
|
| 46 | 46 | |
| 47 | 47 | $this->assertTrue(ctype_print($ciphertext), 'is printable'); |
| 48 | 48 | } |
@@ -54,10 +54,10 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | try { |
| 56 | 56 | $this->encryption->expects($this->once()) |
| 57 | - ->method('encrypt') |
|
| 58 | - ->with('The quick brown fox jumps over the lazy dog', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
|
| 57 | + ->method('encrypt') |
|
| 58 | + ->with('The quick brown fox jumps over the lazy dog', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
|
| 59 | 59 | ->getMock()) |
| 60 | - ->will($this->throwException(new EnvironmentIsBrokenException())); |
|
| 60 | + ->will($this->throwException(new EnvironmentIsBrokenException())); |
|
| 61 | 61 | } catch (EnvironmentIsBrokenException $e) { |
| 62 | 62 | $this->throwException(new CryptoException()); |
| 63 | 63 | } |
@@ -69,13 +69,13 @@ discard block |
||
| 69 | 69 | public function testDecryptDecryptsCiphertext() |
| 70 | 70 | { |
| 71 | 71 | $this->encryption->expects($this->once()) |
| 72 | - ->method('decrypt') |
|
| 73 | - ->with('ThisIsACipherText', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
|
| 74 | - ->getMock()) |
|
| 75 | - ->will($this->returnValue('The quick brown fox jumps over the lazy dog')); |
|
| 72 | + ->method('decrypt') |
|
| 73 | + ->with('ThisIsACipherText', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
|
| 74 | + ->getMock()) |
|
| 75 | + ->will($this->returnValue('The quick brown fox jumps over the lazy dog')); |
|
| 76 | 76 | |
| 77 | 77 | $decryptedText = $this->wrapper->decrypt('ThisIsACipherText', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
| 78 | - ->getMock()); |
|
| 78 | + ->getMock()); |
|
| 79 | 79 | |
| 80 | 80 | $this->assertSame('The quick brown fox jumps over the lazy dog', $decryptedText); |
| 81 | 81 | } |
@@ -87,29 +87,29 @@ discard block |
||
| 87 | 87 | { |
| 88 | 88 | try { |
| 89 | 89 | $this->encryption->expects($this->once()) |
| 90 | - ->method('decrypt') |
|
| 91 | - ->with('ThisIsACipherText', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
|
| 92 | - ->getMock()) |
|
| 93 | - ->will($this->throwException(new BaseCryptoException())); |
|
| 90 | + ->method('decrypt') |
|
| 91 | + ->with('ThisIsACipherText', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
|
| 92 | + ->getMock()) |
|
| 93 | + ->will($this->throwException(new BaseCryptoException())); |
|
| 94 | 94 | } catch (BaseCryptoException $e) { |
| 95 | 95 | $this->throwException(new CryptoException()); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | $this->wrapper->decrypt('ThisIsACipherText', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
| 99 | - ->getMock()); |
|
| 99 | + ->getMock()); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public function testEncryptFileEncryptsFile() |
| 103 | 103 | { |
| 104 | 104 | $this->encryption->expects($this->once()) |
| 105 | - ->method('encryptFile') |
|
| 106 | - ->will($this->returnCallback(function ($input, $output) { |
|
| 107 | - $fs = new Filesystem(); |
|
| 108 | - $fs->dumpFile($output, ''); |
|
| 109 | - })); |
|
| 105 | + ->method('encryptFile') |
|
| 106 | + ->will($this->returnCallback(function ($input, $output) { |
|
| 107 | + $fs = new Filesystem(); |
|
| 108 | + $fs->dumpFile($output, ''); |
|
| 109 | + })); |
|
| 110 | 110 | |
| 111 | 111 | $this->wrapper->encryptFile(__DIR__.'/file.txt', __DIR__.'/file.crypto', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
| 112 | - ->getMock()); |
|
| 112 | + ->getMock()); |
|
| 113 | 113 | |
| 114 | 114 | $this->assertFileExists(__DIR__.'/file.crypto'); |
| 115 | 115 | |
@@ -119,14 +119,14 @@ discard block |
||
| 119 | 119 | public function testDecryptFileDecryptsEncryptedFile() |
| 120 | 120 | { |
| 121 | 121 | $this->encryption->expects($this->once()) |
| 122 | - ->method('decryptFile') |
|
| 123 | - ->will($this->returnCallback(function ($input, $output) { |
|
| 124 | - $fs = new Filesystem(); |
|
| 125 | - $fs->dumpFile($output, 'Plain text'); |
|
| 126 | - })); |
|
| 122 | + ->method('decryptFile') |
|
| 123 | + ->will($this->returnCallback(function ($input, $output) { |
|
| 124 | + $fs = new Filesystem(); |
|
| 125 | + $fs->dumpFile($output, 'Plain text'); |
|
| 126 | + })); |
|
| 127 | 127 | |
| 128 | 128 | $this->wrapper->decryptFile(__DIR__.'/file.crypto', __DIR__.'/file.txt', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
| 129 | - ->getMock()); |
|
| 129 | + ->getMock()); |
|
| 130 | 130 | |
| 131 | 131 | $this->assertFileExists(__DIR__.'/file.txt'); |
| 132 | 132 | $this->assertContains('Plain text', file_get_contents(__DIR__.'/file.txt')); |
@@ -141,14 +141,14 @@ discard block |
||
| 141 | 141 | { |
| 142 | 142 | try { |
| 143 | 143 | $this->encryption->expects($this->once()) |
| 144 | - ->method('encryptFile') |
|
| 145 | - ->will($this->throwException(new BaseCryptoException())); |
|
| 144 | + ->method('encryptFile') |
|
| 145 | + ->will($this->throwException(new BaseCryptoException())); |
|
| 146 | 146 | } catch (BaseCryptoException $e) { |
| 147 | 147 | $this->throwException(new CryptoException()); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | $this->wrapper->encryptFile(__DIR__.'/file.txt', __DIR__.'/file.crypto', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
| 151 | - ->getMock()); |
|
| 151 | + ->getMock()); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -158,20 +158,20 @@ discard block |
||
| 158 | 158 | { |
| 159 | 159 | try { |
| 160 | 160 | $this->encryption->expects($this->once()) |
| 161 | - ->method('decryptFile') |
|
| 162 | - ->will($this->throwException(new BaseCryptoException())); |
|
| 161 | + ->method('decryptFile') |
|
| 162 | + ->will($this->throwException(new BaseCryptoException())); |
|
| 163 | 163 | } catch (BaseCryptoException $e) { |
| 164 | 164 | $this->throwException(new CryptoException()); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $this->wrapper->decryptFile(__DIR__.'/file.crypto', __DIR__.'/file.txt', $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface') |
| 168 | - ->getMock()); |
|
| 168 | + ->getMock()); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | protected function setUp() |
| 172 | 172 | { |
| 173 | 173 | $this->encryption = $this->getMockBuilder('Mes\Security\CryptoBundle\EncryptionInterface') |
| 174 | - ->getMock(); |
|
| 174 | + ->getMock(); |
|
| 175 | 175 | $this->wrapper = new EncryptionWrapper($this->encryption); |
| 176 | 176 | } |
| 177 | 177 | |