MSSql SSL encrypted connection via ODBC/sqlsrv and TrustServerCertificate flag

Created on 6 June 2024, 22 days ago

PROBLEM

There is no option to choose if we trust or not to self signed certificates with encrypted connection with MSSQL server.

If your server is self signed you get an error from both sqlsrv and odbc drivers. It breaks all site.

SOLUTION 1 (easy and primitive, but works :) )

Use TrustServerCertificate flag with connection string. It is located in sqlsrv/src/Driver/Database/sqlsrv/Connection.php

$pdo = new \PDO($dsn."TrustServerCertificate = true", $connection_options['username'], $connection_options['password'], $connection_options['pdo']);

Patch included.

SOLUTION 2

Consider new variable in connections settings which will allow you to manage trustness of certificate
ex.:

$databases['external']['default'] = [
  'database' => 'my_database',
  'username' => 'my_user',
  'password' => 'my_password',
  'port' => '1433',
  'prefix' => '',
  'host' => 'my.special.host.of.mssql.server',
  'namespace' => 'Drupal\\sqlsrv\\Driver\\Database\sqlsrv',
  'autoload' => 'modules/contrib/sqlsrv/src/Driver/Database/sqlsrv',
  'driver' => 'sqlsrv',
  'TrustServerCertificate' => true
];

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡΅πŸ‡±Poland SebaZ

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024