bunq / sdk_php

PHP SDK for bunq API
MIT License
84 stars 54 forks source link

openssl_pkey_get_details() expects parameter 1 to be resource, boolean given #102

Closed dqos closed 6 years ago

dqos commented 6 years ago

Steps to reproduce:

Run vendor/bin/bunq-install (Windows 10, PHP 7.2)

What should happen:

I guess it should be working.

What happens:

It throws an error.

Traceback

PHP Warning:  openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Security\KeyPair.php on line 56
PHP Fatal error:  Uncaught TypeError: Argument 2 passed to bunq\Model\Core\Installation::create() must be of the type string, null given, called in C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Context\ApiContext.php on line 133 and defined in C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Model\Core\Installation.php:61
Stack trace:
#0 C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Context\ApiContext.php(133): bunq\Model\Core\Installation::create(Object(bunq\Context\ApiContext), NULL)
#1 [internal function]: bunq\Context\ApiContext->initializeInstallationContext()
#2 C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Util\InstallationUtil.php(84): ReflectionMethod->invoke(Object(bunq\Context\ApiContext))
#3 C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\bin\bunq-install(16): bunq\Util\InstallationUtil::interactiveInstall()
#4 {main}
  thrown in C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Model\Core\Installation.php on line 61

SDK version and environment

OGKevin commented 6 years ago

Hey @qarizma,

Thanks for reporting!

Could you try and run the API context example instead: https://github.com/bunq/sdk_php/blob/develop/example/api_context_save_example.php and continue from there.

I think im even going to remove this install script as there is really no use for it 🤔

dqos commented 6 years ago

I tested that initially, then I tried the script. Here is the output of the php script you referred to.

[Fri Jan 12 16:20:21 2018] PHP Warning:  openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Security\KeyPair.php on line 56
[Fri Jan 12 16:20:21 2018] PHP Fatal error:  Uncaught TypeError: Argument 2 passed to bunq\Model\Core\Installation::create() must be of the type string, null given, called in C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Context\ApiContext.php on line 133 and defined in C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Model\Core\Installation.php:61
Stack trace:
#0 C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Context\ApiContext.php(133): bunq\Model\Core\Installation::create(Object(bunq\Context\ApiContext), NULL)
#1 C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Context\ApiContext.php(121): bunq\Context\ApiContext->initializeInstallationContext()
#2 C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Context\ApiContext.php(110): bunq\Context\ApiContext->initialize('Server 1', Array)
#3 C:\Users\REMOVED\Google Drive\PROJECT\bunq\index.php(14): bunq\Context\ApiContext::create(Object(bunq\Util\BunqEnumApiEnvironmentType), '2dbbae8330e47de...', 'Server 1')
#4 {main in C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Model\Core\Installation.php on line 61
[Fri Jan 12 16:20:21 2018] ::1:60769 [500]: /bunq/index.php - Uncaught TypeError: Argument 2 passed to bunq\Model\Core\Installation::create() must be of the type string, null given, called in C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Context\ApiContext.php on line 133 and defined in C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Model\Core\Installation.php:61
Stack trace:
#0 C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Context\ApiContext.php(133): bunq\Model\Core\Installation::create(Object(bunq\Context\ApiContext), NULL)
#1 C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Context\ApiContext.php(121): bunq\Context\ApiContext->initializeInstallationContext()
#2 C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Context\ApiContext.php(110): bunq\Context\ApiContext->initialize('Server 1', Array)
#3 C:\Users\REMOVED\Google Drive\PROJECT\bunq\index.php(14): bunq\Context\ApiContext::create(Object(bunq\Util\BunqEnumApiEnvironmentType), '2dbbae8330e47de...', 'Server 1')
#4 {main in C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\bunq\sdk_php\src\Model\Core\Installation.php on line 61
OGKevin commented 6 years ago

Aha! @qarizma

http://php.net/manual/en/function.openssl-pkey-new.php

Returns a resource identifier for the pkey on success, or FALSE on error.

So it seems that an error is happening when the SDK tries to generate a new keypair! openssl_pkey_new returns false and we don't check for this :see_no_evil:. Thanks for reporting this, ill make sure we catch this error.

I have a felling that the key generation failure might have something to do with windows but im not 100% sure. Do you have another device that is running linux or mac os and see if you're getting the error as well ?

Note: You need to have a valid openssl.cnf installed for this function to operate correctly. See the notes under the installation section for more information. To use PHP's OpenSSL support you must also compile PHP --with-openssl[=DIR] .

Could you also double check if you have compiled PHP with openssl as described on the PHP documentation ?

dqos commented 6 years ago

Okay I solved it by following this: https://stackoverflow.com/a/36070260

Now next issue is:

[Fri Jan 12 16:38:36 2018] PHP Fatal error:  Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in C:\Users\REMOVED\Google Drive\PROJECT\bunq\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:187
Stack trace:

I guess it has something to do with VERIFY_PEER. I can disable it, but I'm not sure if that's a good practice 😄

OGKevin commented 6 years ago

@qarizma could you update your comment with the full stack trace please ?

For sandbox, because its fake data, you can disable verification but i would not recommend doing this on production!

Also, for better issue tracking, as this is a different error and does not have anything to do with the previous reported error. Do you mind opening a new issue for this new error ? Thanks.

dqos commented 6 years ago

Sure, done!