(bug 32774) Added config options and flags for SSL and compression in DB.
authorTyler Anthony Romeo <tylerromeo@gmail.com>
Wed, 15 Aug 2012 20:44:41 +0000 (16:44 -0400)
committerTyler Anthony Romeo <tylerromeo@gmail.com>
Thu, 16 Aug 2012 14:48:07 +0000 (10:48 -0400)
Added configuration options ($wgDBssl, $wgDBcompress) and related
connection flags (DBO_SSL, DBO_COMPRESS) to allow SSL/TLS and
compression on database connections. The flags are only observed if
the functionality is supported for that type of database (e.g.,
SQLite will ignore both flags as neither are supported).

Currently, only MySQL and PgSQL have support for at least one of
these flags in their PHP extensions. MySQL supports both flags and
PgSQL supports the SSL flag only.

Change-Id: I7b4d3ba82ccab0eed4a19e3b4e7bc0b4eb881262
Signed-off-by: Tyler Anthony Romeo <tylerromeo@gmail.com>
RELEASE-NOTES-1.20
includes/DefaultSettings.php
includes/Defines.php
includes/db/DatabaseMysql.php
includes/db/DatabasePostgres.php
includes/db/LBFactory.php

index 54554c9..2dea396 100644 (file)
@@ -25,6 +25,8 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * Removed f-prot support from $wgAntivirusSetup.
 * New variable $wgDBerrorLogTZ to provide dates in the error log in a
   different timezone than the wiki timezone set by $wgLocalTimezone.
+* New variables $wgDBssl and $wgDBcompress to enable SSL and compression for database
+  connections, if either are available for the selected DB type.
 
 === New features in 1.20 ===
 * Added TitleIsAlwaysKnown hook which gets called when determining if a page exists.
index a6244ed..1ccf5a9 100644 (file)
@@ -1308,6 +1308,10 @@ $wgDBuser = 'wikiuser';
 $wgDBpassword = '';
 /** Database type */
 $wgDBtype = 'mysql';
+/** Whether to use SSL in DB connection. */
+$wgDBssl = false;
+/** Whether to use compression in DB connection. */
+$wgDBcompress = false;
 
 /** Separate username for maintenance tasks. Leave as null to use the default. */
 $wgDBadminuser = null;
@@ -1393,6 +1397,8 @@ $wgSharedTables = array( 'user', 'user_properties' );
  *                  - DBO_IGNORE -- ignore errors (not useful in LocalSettings.php)
  *                  - DBO_NOBUFFER -- turn off buffering (not useful in LocalSettings.php)
  *                  - DBO_PERSISTENT -- enables persistent database connections
+ *                  - DBO_SSL -- uses SSL/TLS encryption in database connections, if available
+ *                  - DBO_COMPRESS -- uses internal compression in database connections, if available
  *
  *   - max lag:     (optional) Maximum replication lag before a slave will taken out of rotation
  *   - max threads: (optional) Maximum number of running threads
index 56218d6..55d9a7a 100644 (file)
@@ -44,6 +44,8 @@ define( 'DBO_DEFAULT', 16 );
 define( 'DBO_PERSISTENT', 32 );
 define( 'DBO_SYSDBA', 64 ); //for oracle maintenance
 define( 'DBO_DDLMODE', 128 ); // when using schema files: mostly for Oracle
+define( 'DBO_SSL', 256 );
+define( 'DBO_COMPRESS', 512 );
 /**@}*/
 
 /**@{
index e27d3db..4b34310 100644 (file)
@@ -83,6 +83,14 @@ class DatabaseMysql extends DatabaseBase {
                $this->mPassword = $password;
                $this->mDBname = $dbName;
 
+               $connFlags = 0;
+               if ( $this->mFlags & DBO_SSL ) {
+                       $connFlags |= MYSQL_CLIENT_SSL;
+               }
+               if ( $this->mFlags & DBO_COMPRESS ) {
+                       $connFlags |= MYSQL_CLIENT_COMPRESS;
+               }
+
                wfProfileIn("dbconnect-$server");
 
                # The kernel's default SYN retransmission period is far too slow for us,
@@ -100,10 +108,10 @@ class DatabaseMysql extends DatabaseBase {
                                usleep( 1000 );
                        }
                        if ( $this->mFlags & DBO_PERSISTENT ) {
-                               $this->mConn = mysql_pconnect( $realServer, $user, $password );
+                               $this->mConn = mysql_pconnect( $realServer, $user, $password, $connFlags );
                        } else {
                                # Create a new connection...
-                               $this->mConn = mysql_connect( $realServer, $user, $password, true );
+                               $this->mConn = mysql_connect( $realServer, $user, $password, true, $connFlags );
                        }
                        #if ( $this->mConn === false ) {
                                #$iplus = $i + 1;
index 3504892..8f8f5e8 100644 (file)
@@ -356,6 +356,10 @@ class DatabasePostgres extends DatabaseBase {
                if ( $port != false && $port != '' ) {
                        $connectVars['port'] = $port;
                }
+               if ( $this->mFlags & DBO_SSL ) {
+                       $connectVars['sslmode'] = 1;
+               }
+
                $this->connectString = $this->makeConnectionString( $connectVars, PGSQL_CONNECT_FORCE_NEW );
                $this->close();
                $this->installErrorHandler();
index aaca12c..e82c54b 100644 (file)
@@ -191,6 +191,16 @@ class LBFactory_Simple extends LBFactory {
                        $servers = $wgDBservers;
                } else {
                        global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype, $wgDebugDumpSql;
+                       global $wgDBssl, $wgDBcompress;
+
+                       $flags = ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT;
+                       if ( $wgDBssl ) {
+                               $flags |= DBO_SSL;
+                       }
+                       if ( $wgDBcompress ) {
+                               $flags |= DBO_COMPRESS;
+                       }
+
                        $servers = array(array(
                                'host' => $wgDBserver,
                                'user' => $wgDBuser,
@@ -198,7 +208,7 @@ class LBFactory_Simple extends LBFactory {
                                'dbname' => $wgDBname,
                                'type' => $wgDBtype,
                                'load' => 1,
-                               'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
+                               'flags' => $flags
                        ));
                }