From 2596faeaa38c4781501bc5147bb65cca214c7889 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Thu, 12 Nov 2026 22:57:00 +0100 Subject: [PATCH 1/2] Clarify the missing passphrase error of the OpenSSL cipher OpenSSL::generateKey() reported "Missing passphrase file" although the option value is used as the key itself and never read as a file, which leads users to pass file paths as keys. Co-Authored-By: Claude Opus 5.5 --- Tests/Cipher/OpenSSLTest.php | 16 ++++++++++++++++ docs/overview.md | 6 +++--- src/Cipher/OpenSSL.php | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Tests/Cipher/OpenSSLTest.php b/Tests/Cipher/OpenSSLTest.php index 91dba2b6..b1ca27a0 100644 --- a/Tests/Cipher/OpenSSLTest.php +++ b/Tests/Cipher/OpenSSLTest.php @@ -8,6 +8,7 @@ namespace Joomla\Crypt\Tests\Cipher; use Joomla\Crypt\Cipher\OpenSSL; +use Joomla\Crypt\Exception\InvalidKeyException; use Joomla\Crypt\Key; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -97,4 +98,19 @@ public function testGenerateKey() // Assert the key is of the correct type. $this->assertSame('openssl', $key->getType()); } + + /** + * @testdox Generating a key without a passphrase reports the missing option + */ + public function testGenerateKeyRequiresAPassphrase() + { + $cipher = new OpenSSL('1234567890123456', 'aes-128-cbc'); + + $this->expectException(InvalidKeyException::class); + $this->expectExceptionMessage( + "The 'passphrase' option is missing. Its value is used as the key itself, not as a file path." + ); + + $cipher->generateKey(); + } } diff --git a/docs/overview.md b/docs/overview.md index 7a7f3ce5..c5a35ac3 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -142,9 +142,9 @@ $stored = base64_encode($nonce) . ':' . base64_encode($cipher->encrypt($message, > stream reuse; the missing authentication means a modified ciphertext decrypts without complaint. > Use `Cipher\Crypto` instead. -If you are stuck with it, one more detail matters. The option is called `passphrase` and the docs -describe it as a passphrase file, but the value is never read as a file — it is handed to -`openssl_encrypt()` as the key material verbatim: +If you are stuck with it, one more detail matters. The option is called `passphrase`, and before 4.1 the +error for a missing one called it a "passphrase file", but the value is never read as a file — it is +handed to `openssl_encrypt()` as the key material verbatim: ```php $key = $cipher->generateKey(['passphrase' => '/path/to/secret.dat']); diff --git a/src/Cipher/OpenSSL.php b/src/Cipher/OpenSSL.php index 5aa4f7a0..63094ccb 100644 --- a/src/Cipher/OpenSSL.php +++ b/src/Cipher/OpenSSL.php @@ -124,7 +124,7 @@ public function generateKey(array $options = []) $passphrase = $options['passphrase'] ?? false; if ($passphrase === false) { - throw new InvalidKeyException('Missing passphrase file'); + throw new InvalidKeyException("The 'passphrase' option is missing. Its value is used as the key itself, not as a file path."); } return new Key('openssl', $passphrase, 'unused'); From be3f50495f88a2aff7aeb7ab873b056071b8280d Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Thu, 12 Nov 2026 23:01:48 +0100 Subject: [PATCH 2/2] Move the passphrase test away from the end of the test class Avoids a merge conflict with the OpenSSL deprecation PR, which also adds a test at the end of the class. Co-Authored-By: Claude Opus 5.5 --- Tests/Cipher/OpenSSLTest.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Tests/Cipher/OpenSSLTest.php b/Tests/Cipher/OpenSSLTest.php index b1ca27a0..0fc03993 100644 --- a/Tests/Cipher/OpenSSLTest.php +++ b/Tests/Cipher/OpenSSLTest.php @@ -75,6 +75,21 @@ public function testDataEncryptionAndDecryption($data) $this->assertSame($data, $decrypted); } + /** + * @testdox Generating a key without a passphrase reports the missing option + */ + public function testGenerateKeyRequiresAPassphrase() + { + $cipher = new OpenSSL('1234567890123456', 'aes-128-cbc'); + + $this->expectException(InvalidKeyException::class); + $this->expectExceptionMessage( + "The 'passphrase' option is missing. Its value is used as the key itself, not as a file path." + ); + + $cipher->generateKey(); + } + /** * @testdox Validates keys are correctly generated * @@ -98,19 +113,4 @@ public function testGenerateKey() // Assert the key is of the correct type. $this->assertSame('openssl', $key->getType()); } - - /** - * @testdox Generating a key without a passphrase reports the missing option - */ - public function testGenerateKeyRequiresAPassphrase() - { - $cipher = new OpenSSL('1234567890123456', 'aes-128-cbc'); - - $this->expectException(InvalidKeyException::class); - $this->expectExceptionMessage( - "The 'passphrase' option is missing. Its value is used as the key itself, not as a file path." - ); - - $cipher->generateKey(); - } }