magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.46k stars 9.28k forks source link

rtrim() expects parameter 1 to be string, bool given vendor/magento/framework/Encryption/Adapter/Mcrypt.php(171): rtrim() #35464

Open hoangngo-calvin opened 2 years ago

hoangngo-calvin commented 2 years ago

Preconditions (*)

  1. Magento 2.4.3-p2
  2. php7.4.29
  3. MySQL 8.0
  4. Ubuntu 22.04

Steps to reproduce (*)

  1. Run composer to download source code
  2. run the install command
    php bin/magento setup:install \
    --base-url=http://mc243p2.local/ \
    --db-host=127.0.0.1:8030 \
    --db-user=root \
    --db-password=RootAD111!!! \
    --backend-frontname=admin \
    --admin-firstname=admin \
    --admin-lastname=admin \
    --admin-email=adminwww@admin.com \
    --admin-user=admin \
    --admin-password=Admin111!!! \
    --use-rewrites=1 \
    --elasticsearch-host=127.0.0.1 \
    --elasticsearch-port=9230 \
    --elasticsearch-index-prefix=demo_mc243p2 \
    --db-name=demo_mc243p2_01

Expected result (*)

Command run successfully

Actual result (*)

There is an exception

[Progress: 1015 / 1382]
Module 'Dotdigitalgroup_Email':
Installing data... Upgrading data... 
Enabling caches:
Current status:
layout: 1
block_html: 1
full_page: 1
rtrim() expects parameter 1 to be string, bool given#0 /var/www/mc243p2/vendor/magento/framework/Encryption/Adapter/Mcrypt.php(171): rtrim()
#1 /var/www/mc243p2/vendor/magento/framework/Encryption/Encryptor.php(452): Magento\Framework\Encryption\Adapter\Mcrypt->decrypt()
#2 /var/www/mc243p2/vendor/magento/module-config/Model/Config/Backend/Encrypted.php(111): Magento\Framework\Encryption\Encryptor->decrypt()
#3 /var/www/mc243p2/generated/code/Magento/Config/Model/Config/Backend/Encrypted/Interceptor.php(32): Magento\Config\Model\Config\Backend\Encrypted->processValue()
#4 /var/www/mc243p2/vendor/magento/framework/App/Config/MetadataConfigTypeProcessor.php(133): Magento\Config\Model\Config\Backend\Encrypted\Interceptor->processValue()
#5 /var/www/mc243p2/vendor/magento/framework/App/Config/MetadataConfigTypeProcessor.php(152): Magento\Framework\App\Config\MetadataConfigTypeProcessor->processScopeData()
#6 /var/www/mc243p2/vendor/magento/framework/App/Config/PostProcessorComposite.php(36): Magento\Framework\App\Config\MetadataConfigTypeProcessor->process()
#7 /var/www/mc243p2/generated/code/Magento/Framework/App/Config/PostProcessorComposite/Proxy.php(95): Magento\Framework\App\Config\PostProcessorComposite->process()
#8 /var/www/mc243p2/vendor/magento/module-config/App/Config/Type/System.php(397): Magento\Framework\App\Config\PostProcessorComposite\Proxy->process()
#9 /var/www/mc243p2/vendor/magento/framework/Cache/LockGuardedCacheLoader.php(136): Magento\Config\App\Config\Type\System->readData()
#10 /var/www/mc243p2/vendor/magento/module-config/App/Config/Type/System.php(281): Magento\Framework\Cache\LockGuardedCacheLoader->lockedLoadData()
#11 /var/www/mc243p2/vendor/magento/module-config/App/Config/Type/System.php(207): Magento\Config\App\Config\Type\System->loadDefaultScopeData()
#12 /var/www/mc243p2/vendor/magento/module-config/App/Config/Type/System.php(181): Magento\Config\App\Config\Type\System->getWithParts()
#13 /var/www/mc243p2/vendor/magento/framework/App/Config.php(132): Magento\Config\App\Config\Type\System->get()
#14 /var/www/mc243p2/vendor/magento/framework/App/Config.php(80): Magento\Framework\App\Config->get()
#15 /var/www/mc243p2/vendor/magento/framework/App/Config.php(93): Magento\Framework\App\Config->getValue()
#16 /var/www/mc243p2/vendor/dotmailer/dotmailer-magento2-extension/Setup/UpgradeData.php(400): Magento\Framework\App\Config->isSetFlag()
#17 /var/www/mc243p2/vendor/dotmailer/dotmailer-magento2-extension/Setup/UpgradeData.php(170): Dotdigitalgroup\Email\Setup\UpgradeData->upgradeFourFiveTwo()
#18 /var/www/mc243p2/setup/src/Magento/Setup/Model/Installer.php(1076): Dotdigitalgroup\Email\Setup\UpgradeData->upgrade()
#19 /var/www/mc243p2/setup/src/Magento/Setup/Model/Installer.php(960): Magento\Setup\Model\Installer->handleDBSchemaData()
#20 [internal function]: Magento\Setup\Model\Installer->installDataFixtures()
#21 /var/www/mc243p2/setup/src/Magento/Setup/Model/Installer.php(389): call_user_func_array()
#22 /var/www/mc243p2/setup/src/Magento/Setup/Console/Command/InstallCommand.php(231): Magento\Setup\Model\Installer->install()
#23 /var/www/mc243p2/vendor/symfony/console/Command/Command.php(255): Magento\Setup\Console\Command\InstallCommand->execute()
#24 /var/www/mc243p2/vendor/symfony/console/Application.php(1009): Symfony\Component\Console\Command\Command->run()
#25 /var/www/mc243p2/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#26 /var/www/mc243p2/vendor/magento/framework/Console/Cli.php(115): Symfony\Component\Console\Application->doRun()
#27 /var/www/mc243p2/vendor/symfony/console/Application.php(149): Magento\Framework\Console\Cli->doRun()
#28 /var/www/mc243p2/bin/magento(23): Symfony\Component\Console\Application->run()
#29 {main}

image

m2-assistant[bot] commented 2 years ago

Hi @hoangss. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

hoangngo-calvin commented 2 years ago

While I'm debugging I saw this method return false: openssl_decrypt() in:

\phpseclib\Crypt\Base::decrypt
vendor/phpseclib/phpseclib/phpseclib/Crypt/Base.php:1084

image

I'm not quite sure what is wrong.

Can it be because of this OpenSSL version?

$ php -i | grep 'OpenSSL\|openssl'

SSL Version => OpenSSL/3.0.2
libSSH Version => libssh/0.9.6/openssl/zlib
openssl
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 3.0.2 15 Mar 2022
OpenSSL Header Version => OpenSSL 3.0.2 15 Mar 2022
Openssl default config => /usr/lib/ssl/openssl.cnf
openssl.cafile => no value => no value
openssl.capath => no value => no value
Native OpenSSL support => enabled
shoaibpnp commented 2 years ago

I had the same issue today. I found out the php mcrypt library was not installed.

I just installed it on my server using apt install php7.4-mcrypt

Now installation worked perfectly

edgarspatmalnieks commented 2 years ago

The solution of @shoaibpnp worked for me as well.

Thanks!

m2-assistant[bot] commented 2 years ago

Hi @engcom-Dash. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:


engcom-Dash commented 2 years ago

Hello @hoangss,

We have tried to reproduce the issue in Magento 2.4.3-p2 instance. the issue is not reproducible. Please refer the below screenshot for the reference;

Screenshot from 2022-05-17 17-45-35

We have followed the below steps in order to reproduce the issue:

  1. To Install Magento 2.4.3-p2 Instance
  2. Run setup Install Comment Without Mcrypt Extension.
  3. Command Ran Successfully. ...

Let us know in case we have missed anything.

Thanks

hoangngo-calvin commented 2 years ago

So, do we need to have mcrypt extension? According to devdocs System requirements: seem we don't need it.

pnt9948 commented 2 years ago

Thanks @shoaibpnp for notifying about the mcrypt issue. After installing the extension, it got resolved.

engcom-Dash commented 2 years ago

Hello @hoangss ,

We have tried to reproduce the issue in Magento 2.4-develop branch the issue is not reproducible. Please refer the below screenshot for the reference;

Screenshot from 2022-05-31 14-55-20

We have followed the below steps in order to reproduce the issue:

1.Run composer to download source code 2.run the install command 3.Even Installed and verified with M crypt Extension 4.Command Ran Successfully. ...

Let us know in case we have missed anything.

Thanks

hoangngo-calvin commented 2 years ago

Thank @engcom-Dash Yes mcrypt resolved the issue for me. But according the devdocs, mcrypt is not in required extension list.

So is it out of date document or something wrong with code?

engcom-Dash commented 2 years ago

Hi @hoangss We were Worked With mcrypt extension as well as Without Mcrypt Extension.But We are not able to Reproduce the Issue.We got Expected Result in 2.4.3-p2.

hoangngo-calvin commented 2 years ago

hi @engcom-Dash, Thank you for the info. You are not able to reproduce this issue even you don't have mcrypt installed in your system, is my understanding correct?

hostep commented 2 years ago

@hoangss: out of curiosity, did you had the sodium php extension installed when you ran against the problem? (you can find it via php -m on the cli) Not saying it will solve your problem, but it might, so this is just a guess ...

hoangngo-calvin commented 2 years ago

@hostep Thank you for replying Yes. I have sodium(also openssl) installed when I run magento install command

engcom-Dash commented 2 years ago

Hi @hoangss , Thanks for your Reply. Yes,we tried to reproduce the issue with M crypt extension as well as without M crypt also.But we were unable to reproduce.

hoangngo-calvin commented 2 years ago

Hi @engcom-Dash thank you for the update. It is a little bit weird that it still works for you even you dont have mcryt installed.

Seem @pnt9948 @edgarspatmalnieks @shoaibpnp also have the same issue with me and it fixed by installing mcrypt.

Could you share list php extension that you have when you test without mcrypt?

engcom-Dash commented 2 years ago

Hi @hoangss , We are used following php without Mcrypt and with Mcrypt. ext-bcmath ext-ctype ext-curl ext-dom ext-fileinfo ext-gd ext-hash ext-iconv ext-intl ext-json ext-libxml ext-mbstring ext-openssl ext-pcre ext-pdo_mysql ext-simplexml ext-soap ext-sockets ext-sodium ext-tokenizer ext-xmlwriter ext-xsl ext-zip lib-libxml lib-openssl

Thanks.

hoangngo-calvin commented 2 years ago

lib-openssl

hi @engcom-Dash, thank you for the response. Sorry I may ask stupid questions: what is this extension: lib-openssl, and how to install it? seems it's different with openssl, isn't it?

engcom-Dash commented 2 years ago

Hi @hoangss , Yes ,for php 7.4 we did't use this extension...its come under the system requirements.

Thanks.

engcom-Hotel commented 2 years ago

Hello @hoangss,

I think SSL support doesn't depend on an extension, it's already built into Ubuntu's PHP. We haven't installed it separately.

You can check it via the output of <?php phpinfo() ?>.

We have also rechecked the issue in another system without the MCrypt library and the Magento installation is successful.

I have also checked the PHP Doc, The MCrypt feature was DEPRECATED in PHP 7.1.0 and REMOVED in PHP 7.2.0. The alternative for the same is:

I request you to please recheck the same with removing MCrypt and installing Sodium, and OpenSSL, and let us know in case you face any issues.

Thanks

hoangngo-calvin commented 2 years ago

Hi @engcom-Hotel

In earlier comment, I mentioned that I have both Sodium and OpenSSl installed and I still got the issue.

https://github.com/magento/magento2/issues/35464#issuecomment-1145880824

hostep commented 2 years ago

@hoangss: just out of curiosity, I've tried it myself as well without the mcrypt extension being installed. And a clean installation of Magento 2.4.3-p2 with PHP 7.4.29 works just fine, no errors.

Here's my full php extensions list:

$ php -m
[PHP Modules]
apcu
bcmath
blackfire
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
imagick
intl
json
libxml
mbstring
mongodb
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
SimpleXML
soap
sockets
sodium
SPL
sqlite3
ssh2
standard
tokenizer
xdebug
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Xdebug
Zend OPcache
blackfire

What I do notice as a difference, is that in my case, I'm seeing 1383 steps in the installation output, and you only get 1382 steps, so it sounds like one module is maybe not being installed, maybe the absence of that one module causes trouble somehow?

hoangngo-calvin commented 2 years ago

hi @hostep thank you for helping me. This is my PHP's extension list

php -m
[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
intl
json
libxml
mbstring
mcrypt <======== I installed this to bypass the issue
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xdebug
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Xdebug
Zend OPcache

I'm seeing 1383 steps in the installation output,

Do you mind sharing your installation output? is that CE or EE version?

hostep commented 2 years ago

It's CE (which is called Open Source these days). Just try setting up Magento 2.4.3-p2 again from scratch, maybe some dependency got some newer version and that bumps the number by one?

If you still run into the same problem when the mcrypt extension is not installed, try debugging these lines, and see why they return an Mcrypt instance and maybe also what exact data is trying to be decrypted, and where that data comes from.

hoangngo-calvin commented 2 years ago

hi @hostep According to this comment: https://github.com/magento/magento2/issues/35464#issuecomment-1124892017 I tried to debug, IIRC It seems doesn't return the Mcrypt instance, It used OpenSSL to decrypt and the data returned by processValue() is false (in the image) And then it throw the exception rtrim() expects parameter 1 to be string, bool given#0 /var/www/mc243p2/vendor/magento/framework/Encryption/Adapter/Mcrypt.php(171): rtrim()

openssl_decrypt was called: $plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options);

m2-assistant[bot] commented 2 years ago

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Hotel commented 2 years ago

Thanks, @hostep for the guidance.

Hello @hoangss,

We have tried to debug the issue as per this https://github.com/magento/magento2/issues/35464#issuecomment-1160022835 and add a breakpoint in the getCrypt method at line no. 517 and 538. As we can see, it always returns the SodiumChachaIetf object and does not break on line 538.

Thanks

zeljko989 commented 2 years ago

I had the same issue today. I found out the php mcrypt library was not installed.

I just installed it on my server using apt install php7.4-mcrypt

Now installation worked perfectly

YEAH, that was issue with my setup also, and I got this error below ( maybe to someone will be helpful ):

Type Error occurred when creating object: Magento\Framework\Locale\Resolver, rtrim() expects parameter 1 to be string, bool given
In AbstractFactory.php line 131:
  Type Error occurred when creating object: Magento\Framework\Locale\Resolver, rtrim() expects parameter 1 to be string, bool given
engcom-Hotel commented 2 years ago

Hello @zeljko989,

Thanks for the contribution!

Please let us know from which version to which version you are trying to upgrade the Magento.

Thanks

shuvoenr commented 2 years ago

@engcom-Hotel

Please do try with configuration @hoangngo-calvin at first line.

Magento 2.4.3-p2 php7.4.30 MySQL 8.0 Ubuntu 22.04

With ubuntu 22.04.

I tried with that configuration and every-time found same issue & that's weird.

apt install php7.4-mcrypt install solved the issue but which obviously not optimal. As Magento release on 12 April. On the other hand ubuntu release on 21st april.

There may be compatibility issue

engcom-Hotel commented 2 years ago

Hello @hoangngo-calvin @shuvoenr,

Thanks for the report and collaboration!

We are able to reproduce the issue with Magento 2.4.3-P2 with the below configuration:

Versions

Getting the error: error

But after installing Mcrypt, the installation is successful: after_mcrypt_installation

We have also tried to install Magento 2.4.4 and 2.4-develop with the below configuration:

The installation is successfully done.

So confirming this issue for 2.4.3-p2.

Thanks

github-jira-sync-bot commented 2 years ago

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-5900 is successfully created for this GitHub issue.

m2-assistant[bot] commented 2 years ago

:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

hoangngo-calvin commented 2 years ago

Hi @engcom-Hotel Thank you so much for your effort.

webloft commented 1 year ago

This bug appeared out of nowhere yesterday. The mcrypt workaround solved the issue it seems.

What happens in background? The log says it tries to decrypt the value 'Paypal'. Is that something related to an invalid API key or something?

Magento\\Framework\\Encryption\\Encryptor->decrypt('PayPal')