Skip to content

Bug: MySQLi Config "encrypt" values not being respected #7453

@DaneRainbird

Description

@DaneRainbird

PHP Version

8.2

CodeIgniter4 Version

4.3.2

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

No response

What happened?

While following the instructions for configuring a database connection, I have configured my env file to contain the following:

database.default.DBDriver = MySQLi
database.default.encrypt.ssl_ca = C:\xampp\perl\vendor\lib\Mozilla\CA\cacert.pem
database.default.encrypt.ssl_verify = true

However, it appears these are not being respected by the actual SSL connection, as seen in Database.php. Thus, checking in vendor/codeigniter4/framework/system/Database/MySQLi/Connection.php. it appears that the entire section for checking if is_array($this->encrypt) is skipped over due to not being an array.

I have "fixed" this by adding a simple line beforehand that manually sets the encrypt values:

$this->encrypt = [
    'ssl_key'    => '',
    'ssl_cert'   => '',
    'ssl_ca'     => 'C:\xampp\perl\vendor\lib\Mozilla\CA\cacert.pem',
    'ssl_capath' => '',
    'ssl_cipher' => '',
    'ssl_verify' => 'true'
];

Thus continuing the checks and ensuring I can make an encrypted connection.

Steps to Reproduce

  1. Set any of the encryption subvalues in your .env file, or in Database.php
  2. Go to vendor/codeigniter4/framework/system/Database/MySQLi/Connection.php
  3. Within the connection function, add a simple print_r($this->encrypt); and observe that it appears to be being interpreted as a boolean rather than a array.

Expected Output

The correct values to be passed to Database.php / Connection.php to allow for connecting to databases that enforce SSL connections.

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions