Skip to content

Commit 9a20437

Browse files
bug #34275 [FrameworkBundle] allow using secrets when the sodium ext is missing (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [FrameworkBundle] allow using secrets when the sodium ext is missing | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - When all secrets are defined as env vars, there is no need for the sodium vault, yet it chokes on instantiation currently. Commits ------- 326284a [FrameworkBundle] allow using secrets when the sodium ext is missing
2 parents ba07cda + 326284a commit 9a20437

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ class SodiumVault extends AbstractVault
3030
*/
3131
public function __construct(string $secretsDir, $decryptionKey = null)
3232
{
33-
if (!\function_exists('sodium_crypto_box_seal')) {
34-
throw new \LogicException('The "sodium" PHP extension is required to deal with secrets. Alternatively, try running "composer require paragonie/sodium_compat" if you cannot enable the extension."');
35-
}
36-
3733
if (null !== $decryptionKey && !\is_string($decryptionKey) && !(\is_object($decryptionKey) && method_exists($decryptionKey, '__toString'))) {
3834
throw new \TypeError(sprintf('Decryption key should be a string or an object that implements the __toString() method, %s given.', \gettype($decryptionKey)));
3935
}
@@ -107,16 +103,22 @@ public function reveal(string $name): ?string
107103
return null;
108104
}
109105

106+
if (!\function_exists('sodium_crypto_box_seal')) {
107+
$this->lastMessage = sprintf('Secret "%s" cannot be revealed as the "sodium" PHP extension missing. Try running "composer require paragonie/sodium_compat" if you cannot enable the extension."', $name);
108+
109+
return null;
110+
}
111+
110112
$this->loadKeys();
111113

112114
if ('' === $this->decryptionKey) {
113-
$this->lastMessage = sprintf('Secrets cannot be revealed as no decryption key was found in "%s".', $this->getPrettyPath(\dirname($this->pathPrefix).\DIRECTORY_SEPARATOR));
115+
$this->lastMessage = sprintf('Secret "%s" cannot be revealed as no decryption key was found in "%s".', $name, $this->getPrettyPath(\dirname($this->pathPrefix).\DIRECTORY_SEPARATOR));
114116

115117
return null;
116118
}
117119

118120
if (false === $value = sodium_crypto_box_seal_open(include $file, $this->decryptionKey)) {
119-
$this->lastMessage = sprintf('Secrets cannot be revealed as the wrong decryption key was provided for "%s".', $this->getPrettyPath(\dirname($this->pathPrefix).\DIRECTORY_SEPARATOR));
121+
$this->lastMessage = sprintf('Secret "%s" cannot be revealed as the wrong decryption key was provided for "%s".', $name, $this->getPrettyPath(\dirname($this->pathPrefix).\DIRECTORY_SEPARATOR));
120122

121123
return null;
122124
}
@@ -167,6 +169,10 @@ public function list(bool $reveal = false): array
167169

168170
private function loadKeys(): void
169171
{
172+
if (!\function_exists('sodium_crypto_box_seal')) {
173+
throw new \LogicException('The "sodium" PHP extension is required to deal with secrets. Alternatively, try running "composer require paragonie/sodium_compat" if you cannot enable the extension."');
174+
}
175+
170176
if (null !== $this->encryptionKey || '' !== $this->decryptionKey = (string) $this->decryptionKey) {
171177
return;
172178
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy