Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible undefined constant exception when using ssl_no_verify #18481

Closed
e0001ed9 opened this issue Dec 10, 2021 · 4 comments · Fixed by #18491
Closed

Fix possible undefined constant exception when using ssl_no_verify #18481

e0001ed9 opened this issue Dec 10, 2021 · 4 comments · Fixed by #18491
Assignees
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Milestone

Comments

@e0001ed9
Copy link

I recently tried upgrading from Matomo 4.5.0 to 4.6.1 (via the docker apache image), and discovered I was no longer able to connect to the UI due to 500s.

Upon enabling debug logging, I discovered numerous errors like the following:

ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] Uncaught exception: Error: Undefined constant "SSL_NO_VERIFY" in /var/www/html/libs/Zend/Db/Adapter/Mysqli.php:320
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] Stack trace:
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #0 /var/www/html/libs/Zend/Db/Adapter/Mysqli.php(320): constant('SSL_NO_VERIFY')
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #1 /var/www/html/core/Db/Adapter/Mysqli.php(81): Zend_Db_Adapter_Mysqli->_connect()
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #2 /var/www/html/libs/Zend/Db/Adapter/Abstract.php(315): Piwik\Db\Adapter\Mysqli->_connect()
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #3 /var/www/html/core/Db/Adapter.php(53): Zend_Db_Adapter_Abstract->getConnection()
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #4 /var/www/html/core/Db.php(156): Piwik\Db\Adapter::factory('MYSQLI', Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #5 /var/www/html/core/Db.php(55): Piwik\Db::createDatabaseObject()
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #6 /var/www/html/core/Db.php(301): Piwik\Db::get()
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #7 /var/www/html/core/Option.php(288): Piwik\Db::fetchAll('SELECT option_v...')
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #8 /var/www/html/core/Option.php(178): Piwik\Option->autoload()
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #9 /var/www/html/core/Option.php(48): Piwik\Option->getValue('marketplace_lic...')
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #10 /var/www/html/plugins/Marketplace/LicenseKey.php(17): Piwik\Option::get('marketplace_lic...')
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #11 /var/www/html/plugins/Marketplace/config/config.php(26): Piwik\Plugins\Marketplace\LicenseKey->get()
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #12 [internal function]: DI\Definition\Source\DefinitionFile->{closure}(Object(DI\Container))
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #13 /var/www/html/vendor/php-di/invoker/src/Invoker.php(82): call_user_func_array(Object(Closure), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #14 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/FactoryResolver.php(80): Invoker\Invoker->call(Object(Closure), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #15 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ResolverDispatcher.php(71): DI\Definition\Resolver\FactoryResolver->resolve(Object(DI\Definition\FactoryDefinition), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #16 /var/www/html/vendor/php-di/php-di/src/Container.php(390): DI\Definition\Resolver\ResolverDispatcher->resolve(Object(DI\Definition\FactoryDefinition), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #17 /var/www/html/vendor/php-di/php-di/src/Container.php(139): DI\Container->resolveDefinition(Object(DI\Definition\FactoryDefinition))
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #18 /var/www/html/vendor/php-di/php-di/src/Definition/Reference.php(53): DI\Container->get('Piwik\\Plugins\\M...')
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #19 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ResolverDispatcher.php(66): DI\Definition\Reference->resolve(Object(DI\Container))
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #20 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ParameterResolver.php(78): DI\Definition\Resolver\ResolverDispatcher->resolve(Object(DI\Definition\Reference))
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #21 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ObjectCreator.php(138): DI\Definition\Resolver\ParameterResolver->resolveParameters(Object(DI\Definition\ObjectDefinition\MethodInjection), Object(ReflectionMethod), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #22 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ObjectCreator.php(71): DI\Definition\Resolver\ObjectCreator->createInstance(Object(DI\Definition\ObjectDefinition), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #23 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ResolverDispatcher.php(71): DI\Definition\Resolver\ObjectCreator->resolve(Object(DI\Definition\ObjectDefinition), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #24 /var/www/html/vendor/php-di/php-di/src/Container.php(390): DI\Definition\Resolver\ResolverDispatcher->resolve(Object(DI\Definition\ObjectDefinition), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #25 /var/www/html/vendor/php-di/php-di/src/Container.php(139): DI\Container->resolveDefinition(Object(DI\Definition\ObjectDefinition))
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #26 /var/www/html/core/Container/StaticContainer.php(81): DI\Container->get('Piwik\\Plugins\\M...')
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #27 /var/www/html/plugins/CorePluginsAdmin/PluginInstaller.php(49): Piwik\Container\StaticContainer::get('Piwik\\Plugins\\M...')
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #28 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ObjectCreator.php(143): Piwik\Plugins\CorePluginsAdmin\PluginInstaller->__construct(NULL)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #29 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ObjectCreator.php(71): DI\Definition\Resolver\ObjectCreator->createInstance(Object(DI\Definition\ObjectDefinition), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #30 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ResolverDispatcher.php(71): DI\Definition\Resolver\ObjectCreator->resolve(Object(DI\Definition\ObjectDefinition), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #31 /var/www/html/vendor/php-di/php-di/src/Container.php(390): DI\Definition\Resolver\ResolverDispatcher->resolve(Object(DI\Definition\ObjectDefinition), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #32 /var/www/html/vendor/php-di/php-di/src/Container.php(139): DI\Container->resolveDefinition(Object(DI\Definition\ObjectDefinition))
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #33 /var/www/html/vendor/php-di/php-di/src/Definition/Reference.php(53): DI\Container->get('Piwik\\Plugins\\C...')
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #34 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ResolverDispatcher.php(66): DI\Definition\Reference->resolve(Object(DI\Container))
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #35 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ParameterResolver.php(78): DI\Definition\Resolver\ResolverDispatcher->resolve(Object(DI\Definition\Reference))
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #36 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ObjectCreator.php(138): DI\Definition\Resolver\ParameterResolver->resolveParameters(Object(DI\Definition\ObjectDefinition\MethodInjection), Object(ReflectionMethod), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #37 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ObjectCreator.php(71): DI\Definition\Resolver\ObjectCreator->createInstance(Object(DI\Definition\ObjectDefinition), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #38 /var/www/html/vendor/php-di/php-di/src/Definition/Resolver/ResolverDispatcher.php(71): DI\Definition\Resolver\ObjectCreator->resolve(Object(DI\Definition\ObjectDefinition), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #39 /var/www/html/vendor/php-di/php-di/src/Container.php(390): DI\Definition\Resolver\ResolverDispatcher->resolve(Object(DI\Definition\ObjectDefinition), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #40 /var/www/html/vendor/php-di/php-di/src/Container.php(199): DI\Container->resolveDefinition(Object(DI\Definition\ObjectDefinition), Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #41 /var/www/html/core/Http/ControllerResolver.php(75): DI\Container->make('Piwik\\Plugins\\C...')
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #42 /var/www/html/core/Http/ControllerResolver.php(49): Piwik\Http\ControllerResolver->createPluginController('CorePluginsAdmi...', 'safemode')
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #43 /var/www/html/core/FrontController.php(604): Piwik\Http\ControllerResolver->getController('CorePluginsAdmi...', 'safemode', Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #44 /var/www/html/core/FrontController.php(168): Piwik\FrontController->doDispatch('CorePluginsAdmi...', 'safemode', Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #45 /var/www/html/core/FrontController.php(99): Piwik\FrontController->dispatch('CorePluginsAdmi...', 'safemode', Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #46 /var/www/html/core/FrontController.php(139): Piwik\FrontController::generateSafeModeOutputFromError(Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #47 /var/www/html/core/FrontController.php(189): Piwik\FrontController::generateSafeModeOutputFromException(Object(Error))
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #48 /var/www/html/core/FrontController.php(99): Piwik\FrontController->dispatch('CorePluginsAdmi...', 'safemode', Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #49 /var/www/html/core/FrontController.php(139): Piwik\FrontController::generateSafeModeOutputFromError(Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #50 /var/www/html/core/FrontController.php(189): Piwik\FrontController::generateSafeModeOutputFromException(Object(Error))
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #51 /var/www/html/core/FrontController.php(99): Piwik\FrontController->dispatch('CorePluginsAdmi...', 'safemode', Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #52 /var/www/html/core/FrontController.php(139): Piwik\FrontController::generateSafeModeOutputFromError(Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #53 /var/www/html/core/FrontController.php(189): Piwik\FrontController::generateSafeModeOutputFromException(Object(Error))
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #54 /var/www/html/core/FrontController.php(99): Piwik\FrontController->dispatch('CorePluginsAdmi...', 'safemode', Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #55 /var/www/html/core/FrontController.php(274): Piwik\FrontController::generateSafeModeOutputFromError(Array)
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #56 [internal function]: Piwik\FrontController::triggerSafeModeWhenError()
ERROR Piwik\FrontController[2021-12-10 02:51:54 UTC] [857fb] #57 {main}

I am using Matomo with Google's Cloud SQL, which provides self-signed certificates, so I think I have to use ssl_no_verify = 1 (though I'd love not to use that setting if anyone knows a workaround). Removing this setting, as expected, led to Matomo not being able to connect to the database due to certificate verification issues.

Expected Behavior

I expected Matomo to continue to connect successfully to the database with SSL enabled, but verification disabled.

Current Behavior

Matomo is unable to connect to the database and returns 500.

Possible Solution

I noticed that both PHP and Zend received major upgrades between the two docker images for 4.5.0 and 4.6.1. Perhaps this led to incompatibilities?

4.5.0

➜  ~ docker run -ti matomo:4.5.0-apache bash -c 'uname -a && php -v'
Linux f98aac68bbec 5.11.0-41-generic #45~20.04.1-Ubuntu SMP Wed Nov 10 10:20:10 UTC 2021 x86_64 GNU/Linux
PHP 7.4.26 (cli) (built: Dec  2 2021 14:25:17) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.26, Copyright (c), by Zend Technologies

4.6.1

➜  ~ docker run -ti matomo:4.6.1-apache bash -c 'uname -a && php -v'
Linux fe5285d4b0d8 5.11.0-41-generic #45~20.04.1-Ubuntu SMP Wed Nov 10 10:20:10 UTC 2021 x86_64 GNU/Linux
PHP 8.0.13 (cli) (built: Dec  2 2021 13:29:44) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.13, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.13, Copyright (c), by Zend Technologies

Steps to Reproduce (for Bugs)

  1. Run the docker 4.6.1-apache image
  2. Configure it to connect to a database with a self-signed certificate, but with ssl_no_verify enabled.
  3. It should not be able to connect to the database and logs the errors above.

Context

I'm also using the MySQLi adapter. Here is the database configuration:

[database]
<redacted>
adapter = "MYSQLI"
enable_ssl = 1
ssl_ca = "/opt/lib/mysql-ssl/server-ca.pem"
ssl_cert = "/opt/lib/mysql-ssl/client-cert.pem"
ssl_key = "/opt/lib/mysql-ssl/client-key.pem"
ssl_no_verify = 1

Impact - I'm unable to upgrade to 4.6.1 from 4.5.0.

Your Environment

  • Matomo Version: 4.6.1
  • PHP Version: PHP 8.0.13
  • Server Operating System: 20.04.1-Ubuntu
  • Additionally installed plugins: none
@e0001ed9 e0001ed9 added the Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. label Dec 10, 2021
@sgiehl
Copy link
Member

sgiehl commented Dec 10, 2021

Hi @e0001ed9.
Thanks for the report. Could you maybe try if changing some code solves your issue.
Could you try adding 'ssl_no_verify' => null, to this array definition:

$ssl_options = array (
'ssl_ca' => null,
'ssl_ca_path' => null,
'ssl_cert' => null,
'ssl_cipher' => null,
'ssl_key' => null,
);

It's not a final solution, but if it works I might be able to provide a proper fix.

@e0001ed9
Copy link
Author

@sgiehl That did appear to work!

Disclaimer - I only tested this in a local test setup with docker so as not to impact my production deployment, but I can confirm that test setup did exhibit the problem above without your suggested change, then resolved with that fix 🎉

@sgiehl sgiehl added Bug For errors / faults / flaws / inconsistencies etc. and removed Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. labels Dec 11, 2021
@sgiehl sgiehl added this to the 4.7.0 milestone Dec 11, 2021
@sgiehl sgiehl self-assigned this Dec 11, 2021
@justinvelluppillai
Copy link
Contributor

By the way this issue is probably related to the docker image using PHP8 vs 7.4, rather than the upgrade from Matomo 4.5.0 to 4.6.1

@e0001ed9
Copy link
Author

Totally makes sense @justinvelluppillai - thanks! Since I use Matomo via the official docker images, it wasn't immediately obvious that those other dependencies had changed along with the Matomo version.

@justinvelluppillai justinvelluppillai changed the title Undefined constant "SSL_NO_VERIFY" after upgrading to 4.6.1 Fix possible undefined constant exception when using ssl_no_verify Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants