bitpay / php-bitpay-client

PHP implementation for the BitPay cryptographically secure RESTful API
MIT License
166 stars 147 forks source link

Critical issue with bcmath #237

Closed quantumwebco closed 6 years ago

quantumwebco commented 7 years ago

Why??

try {
    /**
     * Now create our invoice...
     */
    $client->createInvoice($invoice);

} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}

So I edited client.php to actually output an error from the request instead of just the generic one from the exception.

It says invalid signature.

This code/token/keys works on every other server but on an Azure server it isn't playing along.

Maybe something to do with the Request?

Any ideas?

pieterpoorthuis commented 7 years ago

I presume you're running the script in a web server. Do you have mcrypt enabled in your PHP? And either bcmath or gmp? You can easily check using phpinfo()

quantumwebco commented 7 years ago

System Windows NT RD0003FFA23CC4 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586 PHP-5.6.30

mcrypt support enabled mcrypt_filter support enabled Version 2.5.8 Api No 20021217 Supported ciphers cast-128 gost rijndael-128 twofish cast-256 loki97 rijndael-192 saferplus wake blowfish-compat des rijndael-256 serpent xtea blowfish enigma rc2 tripledes arcfour Supported modes cbc cfb ctr ecb ncfb nofb ofb stream

bcmath

BCMath support enabled Directive Local Value Master Value bcmath.scale 0 0

GNU GMP support Stanislav Malyshev

quantumwebco commented 7 years ago

There is a critical issue with php 5.6.3 and bcmath.

The signature does not sign correctly using php 5.6.3 and bcmath.

Do you have a solution for this please??

quantumwebco commented 7 years ago

Same issue with PHP 7.1.x and bcmath on MS Azure App Service

quantumwebco commented 7 years ago

Same issue with bcmath on all servers.

Bcmath does not work with this library.

pieterpoorthuis commented 7 years ago

I'm testing on Mac OS, both with PHP 5.6.30 and PHP7.1.6, but unable to replicate the bcmath issue. I've saved & loaded private keys using both gmp & bcmath, in different orders. The signatures that are created are always valid for me.

Which version of BitPay's PHP library are you using? Are you using a password to encrypt your private key when storing it? Did you create the private key file with a previous version of the PHP library?

pieterpoorthuis commented 7 years ago

Can you show your bcmath configuration, e.g. using:

MacBook-Air$ php --ri bcmath
bcmath
BCMath support => enabled
Directive => Local Value => Master Value
bcmath.scale => 0 => 0
pieterpoorthuis commented 7 years ago

Just saw your bcmath config in your initial post.

Still trying to replicate the issue (with no success yet)

quantumwebco commented 7 years ago

Yes. Please do try and read properly. I do try and add all relevant information to my questions and posts.

I have now installed and activated GMP on this MS azure windows server and it has solved the problem.

Therefore I have never been able to get this library to work with bcmath on any server but with GMP it works fine on all servers I have tested.

It all connects with the merchant token not generating properly and only returning half the characters but this issue has never even been acknowledged by you or Andy. https://github.com/bitpay/php-bitpay-client/issues/236

There is some critical issue with bcmath, other people have reported it too. I don't know how you can recreate it. Did you try turning off GMP?? Or setting up a windows server with only bcmath enabled?? It also happened on my windows/apache server too with bcmath too so It seems like its bcmath related and the library isn't working properly with bcmath on windows.

quantumwebco commented 7 years ago

You are trying to replicate on a mac. The error occurs in windows.

pieterpoorthuis commented 7 years ago

I just tried on Windows 10 (PHP 5.6.30) and Ubuntu, everything works correctly for me when using bcmath. So I still can't replicate and thus can't find the root cause.

If bcmath keeps being an issue for certain users, we'll deploy the next version with gmp only support (disabling bcmath support).

estebandelaf commented 7 years ago

Not working with bcmath in Debian/GNU Linux stretch with PHP 7.0.19-1.

I removed bcmath and I installed only gmp and it works.