Failed to use mTLS with PHP Session handler (redis mode)
Author: nusphereCreated Jan 20, 2022Updated Jun 5, 2026
Expected behaviour
Actual behaviour
I'm seeing this behaviour on
- OS: Ubuntu
- Redis: 6
- PHP: 7.4
- phpredis: 5.3
Steps to reproduce, backtrace or example script
When setup a local redis server (via Docker) with mTLS it is not possible to use the ssl stream setup for the php ini setup. I tested this behavior via PHPUnit.
/**
* This test is working with the mTLS setup
*/
public function testConnectionWithTLS(): void
{
$redis = new Redis();
$cert = __DIR__ . DIRECTORY_SEPARATOR . 'client-cert.pem';
$key = __DIR__ . DIRECTORY_SEPARATOR. 'client-key.pem';
$ca = __DIR__ . DIRECTORY_SEPARATOR. 'ca.pem';
$redis->connect('127.0.1.1', '6379', 0.0, null, 0, 0.0, [
'stream' => [
'local_cert' => $cert,
'local_pk' => $key,
'cafile' => $ca,
'verify_peer_name' => false,
]
]);
self::assertTrue($redis->ping());
}When testing the Session Handler, it seems there is no way to add stream settings for ssl/tls. i try to use https://github.com/phpredis/phpredis/issues/1782#issuecomment-688642159 - but this was only implemented for redis cluster.
it should be easy to implent into the normal redis version.
/**
* @runInSeparateProcess
* @return void
*/
public function testSessionHandlerWithTLSPath(): void
{
$cert = __DIR__ . DIRECTORY_SEPARATOR . 'client-cert.pem';
$key = __DIR__ . DIRECTORY_SEPARATOR. 'client-key.pem';
$ca = __DIR__ . DIRECTORY_SEPARATOR. 'ca.pem';
$savePath = "tls://127.0.1.1:6379".
"&stream[verify_peer_name]=0".
"&stream[local_cert]=file://{$cert}".
"&stream[local_pk]=file://{$key}".
"&stream[cafile]=file://{$ca}";
ini_set('session.save_handler', 'redis');
ini_set('session.save_path', $savePath);
session_start();
}
I've checked
- There is no similar issue from other users
- Issue isn't fixed in
developbranch
Source: phpredis/phpredis