]> git.joonet.de Git - adminer.git/commitdiff
Support connecting to MySQL via SSL
authorJakub Vrana <jakub@vrana.cz>
Wed, 7 Feb 2018 11:13:58 +0000 (12:13 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 7 Feb 2018 11:13:58 +0000 (12:13 +0100)
adminer/drivers/mysql.inc.php
adminer/include/adminer.inc.php
adminer/include/pdo.inc.php
changes.txt
editor/include/adminer.inc.php
plugins/login-ssl.php [new file with mode: 0644]
plugins/plugin.php

index 8fa8e3443be74b0227fd17f47378fccaaad46ecb..01ca386d2afa33af6291846dcd4eea9ab72fbe42 100644 (file)
@@ -14,15 +14,21 @@ if (!defined("DRIVER")) {
                        }
 
                        function connect($server = "", $username = "", $password = "", $database = null, $port = null, $socket = null) {
+                               global $adminer;
                                mysqli_report(MYSQLI_REPORT_OFF); // stays between requests, not required since PHP 5.3.4
                                list($host, $port) = explode(":", $server, 2); // part after : is used for port or socket
+                               $ssl = $adminer->connectSsl();
+                               if ($ssl) {
+                                       $this->ssl_set($ssl['key'], $ssl['cert'], $ssl['ca'], '', '');
+                               }
                                $return = @$this->real_connect(
                                        ($server != "" ? $host : ini_get("mysqli.default_host")),
                                        ($server . $username != "" ? $username : ini_get("mysqli.default_user")),
                                        ($server . $username . $password != "" ? $password : ini_get("mysqli.default_pw")),
                                        $database,
                                        (is_numeric($port) ? $port : ini_get("mysqli.default_port")),
-                                       (!is_numeric($port) ? $port : $socket)
+                                       (!is_numeric($port) ? $port : $socket),
+                                       ($ssl ? 64 : 0) // 64 - MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT (not available before PHP 5.6.16)
                                );
                                return $return;
                        }
@@ -223,7 +229,22 @@ if (!defined("DRIVER")) {
                        var $extension = "PDO_MySQL";
 
                        function connect($server, $username, $password) {
-                               $this->dsn("mysql:charset=utf8;host=" . str_replace(":", ";unix_socket=", preg_replace('~:(\\d)~', ';port=\\1', $server)), $username, $password);
+                               global $adminer;
+                               $options = array();
+                               $ssl = $adminer->connectSsl();
+                               if ($ssl) {
+                                       $options = array(
+                                               PDO::MYSQL_ATTR_SSL_KEY => $ssl['key'],
+                                               PDO::MYSQL_ATTR_SSL_CERT => $ssl['cert'],
+                                               PDO::MYSQL_ATTR_SSL_CA => $ssl['ca'],
+                                       );
+                               }
+                               $this->dsn(
+                                       "mysql:charset=utf8;host=" . str_replace(":", ";unix_socket=", preg_replace('~:(\\d)~', ';port=\\1', $server)),
+                                       $username,
+                                       $password,
+                                       $options
+                               );
                                return true;
                        }
 
index 44dae5c94b8f2b1b95b795d766e92b0c106daf11..78fc2a675319bf425889df7b906c433e50c396c4 100644 (file)
@@ -19,6 +19,12 @@ class Adminer {
                return array(SERVER, $_GET["username"], get_password());
        }
 
+       /** Get SSL connection options
+       * @return array array("key" => filename, "cert" => filename, "ca" => filename) or null
+       */
+       function connectSsl() {
+       }
+
        /** Get key used for permanent login
        * @param bool
        * @return string cryptic string which gets combined with password or false in case of an error
index 5aef6a5de0a88ff4d389e2dd8544970803d229e7..f5d2d34e3fe65a366ab4a23a7a3769a6dcaaab1b 100644 (file)
@@ -12,9 +12,9 @@ if (extension_loaded('pdo')) {
                        }
                }
                
-               function dsn($dsn, $username, $password) {
+               function dsn($dsn, $username, $password, $options = array()) {
                        try {
-                               parent::__construct($dsn, $username, $password);
+                               parent::__construct($dsn, $username, $password, $options);
                        } catch (Exception $ex) {
                                auth_error(h($ex->getMessage()));
                        }
index 87a03f322f66fab1f73430fad72df0ff8b4f894d..626b3dd17914a7aa8c34942b1bdc4c09c0f96d92 100644 (file)
@@ -6,6 +6,7 @@ PostgreSQL: Cast to string when searching using LIKE (bug #325)
 PostgreSQL: Don't treat interval type as number (bug #474)
 PostgreSQL: Fix condition for selecting no rows
 PostgreSQL: Support TRUNCATE+INSERT export
+Customization: Support connecting to MySQL via SSL
 
 Adminer 4.6.0 (released 2018-02-05):
 Fix counting selected rows after going back to select page
index d69667880d24e71b08dd3a90470e6f4c4f21f39e..e96c879ac6ff99eacce55c256451bfce8023d260 100644 (file)
@@ -13,6 +13,9 @@ class Adminer {
                return array(SERVER, $_GET["username"], get_password());
        }
 
+       function connectSsl() {
+       }
+
        function permanentLogin($create = false) {
                return password_file($create);
        }
diff --git a/plugins/login-ssl.php b/plugins/login-ssl.php
new file mode 100644 (file)
index 0000000..0114965
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+/** Connect to MySQL using SSL
+* @link https://www.adminer.org/plugins/#use
+* @author Jakub Vrana, https://www.vrana.cz/
+* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
+*/
+class AdminerLoginSsl {
+       /** @access protected */
+       var $ssl;
+       
+       /** 
+       * @param array array("key" => filename, "cert" => filename, "ca" => filename)
+       */
+       function __construct($ssl) {
+               $this->ssl = $ssl;
+       }
+       
+       function connectSsl() {
+               return $this->ssl;
+       }
+       
+}
index fec581e33fece647e57553c35d067c36b61a374d..de34a0140b6e6921a6aa3e313345e4bf493c45f0 100644 (file)
@@ -97,6 +97,11 @@ class AdminerPlugin extends Adminer {
                return $this->_applyPlugin(__FUNCTION__, $args);
        }
 
+       function connectSsl() {
+               $args = func_get_args();
+               return $this->_applyPlugin(__FUNCTION__, $args);
+       }
+
        function permanentLogin($create = false) {
                $args = func_get_args();
                return $this->_applyPlugin(__FUNCTION__, $args);