From 99f4c22c7283d993b7aece2fba140e1c98b1111f Mon Sep 17 00:00:00 2001 From: Peter Knut Date: Sun, 10 Nov 2024 21:57:12 +0100 Subject: [PATCH] MSSQL: Allow to set Encrypt and TrustServerCertificate with AdminerLoginSsl plugin (issue #5) https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/connection-string-syntax#use-trustservercertificate --- adminer/drivers/mssql.inc.php | 18 +++++++++++++++++- adminer/plugin.php | 12 ++++++------ plugins/login-ssl.php | 3 ++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/adminer/drivers/mssql.inc.php b/adminer/drivers/mssql.inc.php index f6990c13..8fa4f2f2 100644 --- a/adminer/drivers/mssql.inc.php +++ b/adminer/drivers/mssql.inc.php @@ -24,11 +24,26 @@ if (isset($_GET["mssql"])) { function connect($server, $username, $password) { global $adminer; + + $connection_info = [ + "UID" => $username, + "PWD" => $password, + "CharacterSet" => "UTF-8", + ]; + + $ssl = $adminer->connectSsl(); + if (isset($ssl["Encrypt"])) { + $connection_info["Encrypt"] = $ssl["Encrypt"]; + } + if (isset($ssl["TrustServerCertificate"])) { + $connection_info["TrustServerCertificate"] = $ssl["TrustServerCertificate"]; + } + $db = $adminer->database(); - $connection_info = array("UID" => $username, "PWD" => $password, "CharacterSet" => "UTF-8"); if ($db != "") { $connection_info["Database"] = $db; } + $this->_link = @sqlsrv_connect(preg_replace('~:~', ',', $server), $connection_info); if ($this->_link) { $info = sqlsrv_server_info($this->_link); @@ -36,6 +51,7 @@ if (isset($_GET["mssql"])) { } else { $this->_get_error(); } + return (bool) $this->_link; } diff --git a/adminer/plugin.php b/adminer/plugin.php index 3470d772..bfca5b19 100644 --- a/adminer/plugin.php +++ b/adminer/plugin.php @@ -2,15 +2,15 @@ function adminer_object() { // required to run any plugin include_once "../plugins/plugin.php"; - + // autoloader foreach (glob("../plugins/*.php") as $filename) { include_once $filename; } - + // enable extra drivers just by including them //~ include "../plugins/drivers/simpledb.php"; - + $plugins = array( // specify enabled plugins here new AdminerDatabaseHide(array('information_schema')), @@ -29,16 +29,16 @@ function adminer_object() { new AdminerTranslation, new AdminerForeignSystem, new AdminerEnumOption, - new AdminerTablesFilter, new AdminerEditForeign, + new AdminerLoginSsl(["TrustServerCertificate" => true]), ); - + /* It is possible to combine customization and plugins: class AdminerCustomization extends AdminerPlugin { } return new AdminerCustomization($plugins); */ - + return new AdminerPlugin($plugins); } diff --git a/plugins/login-ssl.php b/plugins/login-ssl.php index 7728826c..1da400cc 100644 --- a/plugins/login-ssl.php +++ b/plugins/login-ssl.php @@ -10,11 +10,12 @@ */ class AdminerLoginSsl { - private var $ssl; + private $ssl; /** * MySQL: ["key" => filename, "cert" => filename, "ca" => filename] * PostgresSQL: ["mode" => sslmode] (https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLMODE) + * MSSQL: ["Encrypt" => true, "TrustServerCertificate" => true] (https://learn.microsoft.com/en-us/sql/connect/php/connection-options) */ function __construct(array $ssl) {