diff --git a/config/config.sample.php b/config/config.sample.php index 498a2000eb3f9..43dc7efaa6f00 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -2035,6 +2035,17 @@ */ 'mysql.collation' => null, +/** + * PostgreSQL SSL connection +*/ +'pgsql_ssl' => [ + 'mode' => '', + 'cert' => '', + 'rootcert' => '', + 'key' => '', + 'crl' => '', +], + /** * Database types that are supported for installation. * diff --git a/lib/private/DB/ConnectionFactory.php b/lib/private/DB/ConnectionFactory.php index d9b80b81992bb..2429eeb142fa3 100644 --- a/lib/private/DB/ConnectionFactory.php +++ b/lib/private/DB/ConnectionFactory.php @@ -198,6 +198,17 @@ public function createConnectionParams(string $configPrefix = '', array $additio 'tablePrefix' => $connectionParams['tablePrefix'] ]; + if ($type === 'pgsql') { + $pgsqlSsl = $this->config->getValue('pgsql_ssl', false); + if (is_array($pgsqlSsl)) { + $connectionParams['sslmode'] = $pgsqlSsl['mode'] ?? ''; + $connectionParams['sslrootcert'] = $pgsqlSsl['rootcert'] ?? ''; + $connectionParams['sslcert'] = $pgsqlSsl['cert'] ?? ''; + $connectionParams['sslkey'] = $pgsqlSsl['key'] ?? ''; + $connectionParams['sslcrl'] = $pgsqlSsl['crl'] ?? ''; + } + } + if ($type === 'mysql' && $this->config->getValue('mysql.utf8mb4', false)) { $connectionParams['defaultTableOptions'] = [ 'collate' => 'utf8mb4_bin', diff --git a/tests/lib/DB/ConnectionFactoryTest.php b/tests/lib/DB/ConnectionFactoryTest.php index 23bde34a8fb2d..a9fd5656b32b1 100644 --- a/tests/lib/DB/ConnectionFactoryTest.php +++ b/tests/lib/DB/ConnectionFactoryTest.php @@ -39,4 +39,33 @@ public function testSplitHostFromPortAndSocket($host, array $expected): void { $this->assertEquals($expected, self::invokePrivate($factory, 'splitHostFromPortAndSocket', [$host])); } + + public function testPgsqlSslConnection(): void { + /** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject $config */ + $config = $this->createMock(SystemConfig::class); + $config->method('getValue') + ->willReturnCallback(function ($key, $default) { + return match ($key) { + 'dbtype' => 'pgsql', + 'pgsql_ssl' => [ + 'mode' => 'verify-full', + 'cert' => 'client.crt', + 'key' => 'client.key', + 'crl' => 'client.crl', + 'rootcert' => 'rootCA.crt', + ], + default => $default, + }; + }); + $factory = new ConnectionFactory($config); + + $params = $factory->createConnectionParams(); + + $this->assertEquals('pdo_pgsql', $params['driver']); + $this->assertEquals('verify-full', $params['sslmode']); + $this->assertEquals('rootCA.crt', $params['sslrootcert']); + $this->assertEquals('client.crt', $params['sslcert']); + $this->assertEquals('client.key', $params['sslkey']); + $this->assertEquals('client.crl', $params['sslcrl']); + } }