robrichards / xmlseclibs

A PHP library for XML Security
BSD 3-Clause "New" or "Revised" License
386 stars 180 forks source link

Uncaught Error: Undefined constant "RobRichards\XMLSecLibs\OPENSSL_PKCS1_PADDING" // Library not detecting openssl extension #261

Closed naspy971 closed 3 months ago

naspy971 commented 3 months ago

Hi,

I just upgraded my Symfony 4.4 project to 5.4 along with using php 8.3.

I use :

When i try to login using a Saml/SSO mechanism, i get this critical error

php.CRITICAL: Uncaught Error: Undefined constant "RobRichards\XMLSecLibs\OPENSSL_PKCS1_PADDING" {"exception":"[object] (Error(code: 0): Undefined constant \"RobRichards\XMLSecLibs\OPENSSL_PKCS1_PADDING\" at C:\Apache24\htdocs\qms\vendor\robrichards\xmlseclibs\src\XMLSecurityKey.php:212)"} []

EDIT : Apache does not actually load my openssl extension

naspy971 commented 3 months ago

I think you're missing the openssl php-extension ...

I doubled checked, and phpinfo() gives me this

image

tvdijen commented 3 months ago

Are you comfortable editing the file and put a backslash in front of the constant? So OPENSSL_PKCS1_PADDING becomes \OPENSSL_PKCS1_PADDING..

I doubt it will solve the issue, but it's worth a try

naspy971 commented 3 months ago

Are you comfortable editing the file and put a backslash in front of the constant? So OPENSSL_PKCS1_PADDING becomes \OPENSSL_PKCS1_PADDING..

I doubt it will solve the issue, but it's worth a try

I edited my question, I replace the constant with its value (1) but then i get an error on the function openssl_x509_read

The library acts as I don't have openssl extension enabled, but it actually is. I really don't understand.

tvdijen commented 3 months ago

Are you compiling PHP and/or openssl yourself? I've seen similar issues where an extension was loaded twice ..

Type php --ini and fix any issues that are reported.

naspy971 commented 3 months ago

Are you compiling PHP and/or openssl yourself? I've seen similar issues where an extension was loaded twice ..

Type php --ini and fix any issues that are reported.

The apps runs via Apache.

I have this line inside httpd.conf

LoadModule ssl_module modules/mod_ssl.so

And i don't have any issue displayed :

image

tvdijen commented 3 months ago

I'm out of ideas then.. I use this lib on Apache + PHP 8.3, but on Linux. No issues there. It's a little strange though that your list of parsed ini-files is empty.. I get a huge list of includes when I do php --ini..

naspy971 commented 3 months ago

I'm out of ideas then.. I use this lib on Apache + PHP 8.3, but on Linux. No issues there.

When i run the app on localhost without https it works perfectly but the issue comes when i run with https...

Well, thanks anyway, I'll keep on digging

naspy971 commented 3 months ago

I'm out of ideas then.. I use this lib on Apache + PHP 8.3, but on Linux. No issues there. It's a little strange though that your list of parsed ini-files is empty.. I get a huge list of includes when I do php --ini..

Ok I think I almost got it, actually I just did a phpinfo() via the apache loading of my app, and indeed openssl is not loaded by apache.

When I first told you it is loaded, it was when I ran a php server myself with php -S 127.0.0.1:8001 -t public/

@tvdijen do you know how to configure apache to load the extension ?

tvdijen commented 3 months ago

Apache doesn't load PHP-extensions... Apache only loads the PHP-module (or offloads requests to a PHP daemon, depending on your setup). There is however a difference in configuration between normal use through a webserver and using the command-line. The first one uses php.ini and the second one uses php-cli.ini. Perhaps that's something you could figure out?

naspy971 commented 3 months ago

Apache doesn't load PHP-extensions... Apache only loads the PHP-module (or offloads requests to a PHP daemon, depending on your setup). There is however a difference in configuration between normal use through a webserver and using the command-line. The first one uses php.ini and the second one uses php-cli.ini. Perhaps that's something you could figure out?

Ok i finally found the bug and fixed it...

It's a strange behavior I got with sqlsrv extension... when I do extension=openssl and inside my ext/ folder I have php_openssl.dll, the file is not recognized, but if I change the name and the path, then it works !

Problem solved.