mollie / mollie-api-node

Official Mollie API client for Node
http://www.mollie.com
BSD 3-Clause "New" or "Revised" License
237 stars 63 forks source link

error:0906D06C:PEM routines:PEM_read_bio:no start line #3

Closed GlennGeenen closed 9 years ago

GlennGeenen commented 9 years ago

When I test locally the mollie payment is created just fine and I get redirected to mollie. Whenever I try the same on my test server (Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-43-generic x86_64)) I get the following error when I try to create a payment.

The only difference is that my test server runs node v0.12.0 while I run v0.10.33.

Error: error:0906D06C:PEM routines:PEM_read_bio:no start line at Error (native) at Object.createSecureContext (_tls_common.js:130:19) at Object.exports.connect (_tls_wrap.js:850:21) at Agent.createConnection (https.js:82:14) at Agent.createSocket (_http_agent.js:194:16) at Agent.addRequest (_http_agent.js:166:23) at new ClientRequest (_http_client.js:154:16) at Object.exports.request (http.js:49:10) at Object.exports.request (https.js:136:15) at Client.module.exports.Mollie.API.Client.Client.callRest (/var/www/test/node_modules/mollie-api-node/lib/mollie/api/client.js:91:23) at Payments.module.exports.Mollie.API.Resource.Base.Base.create (/var/www/test/node_modules/mollie-api-node/lib/mollie/api/resource/base.js:66:23)

Edit: I installed v0.10.37 on the server, module works for node v0.10 not for v0.12.

willemstuursma commented 9 years ago

Hi @GlennGeenen. This is most likely a problem with the underlaying transport layer. We use SNI to attach multiple certificates to the same IP-address. I fear that you will need to upgrade your server's node version.

GlennGeenen commented 9 years ago

@willemstuursma The module is not compatible with node v0.12.0. I added sample code. This works in node v0.10.37 and not in v0.12.0.

var Mollie = require('mollie-api-node');
var http = require('http');

var mollie = new Mollie.API.Client();
mollie.setApiKey('molliekey');

var pay = {
    amount: 10,
    description: 'Payment Test',
    redirectUrl: 'http://localhost:1337/back'
};

http.createServer(function (req, res) {

    if (req.url === '/back') {

        res.end('Welcome Back\n');

    } else {

        mollie.payments.create(pay, function (payment) {
            if (payment.error) {
                console.error('Payment Error: ' + payment.error);
            }
            res.writeHead(302, {
                Location: payment.getPaymentUrl()
            });
            return res.end();
        });

    }
}).listen(1337, '127.0.0.1');
amirshakya2010 commented 9 years ago

We have the same issue when i upgraded my node version from the 0.10.21 to 0.12.4.

Module is not compatible with new version of node 0.12.4.

GlennGeenen commented 9 years ago

I'm still running on v0.10.38 because of this. I'll look into the problem when I have some time since I want to upgrade node.

willemstuursma commented 9 years ago

Thanks, we are going to look into this. If you could provide a PR, that would help immensely.

GlennGeenen commented 9 years ago

It seems to crash on reading/loading the certificate. Node v0.12 has SSLv2 and SSLv3 disabled, could that be the problem?

Edit: Not the problem, SSLv2 and SSLv3 are disabled since v0.10.33 and it works on v0.10.38. It all look like something is wrong with the certificate (that's what the errors say). Maybe some of the v0.12 changes to buffer created this problem? How is the certificate created?

jasminjane commented 9 years ago

Hi, we are also experiencing this. Has this issue been resolved? Is there a work-around?

daanbrandt commented 9 years ago

Hey there. Ive been working on this all day and can't make it work :( If anyone has a work-arund please post greetz,

Voidkn1ghtz

GlennGeenen commented 9 years ago

I've also spent some time on it, as far as I understand reading certdata.txt fails in node v0.12 while it works in v0.10. I guess it's a matter of recreating certdata.txt?

jasminjane commented 9 years ago

certdata.txt? Where can I find this?

GlennGeenen commented 9 years ago

https://github.com/mollie/mollie-api-node/blob/master/lib/mollie/api/certdata.txt

jasminjane commented 9 years ago

Thanks for your quick response, Glenn. But what I don't quite get yet is how I can recreate this file?

lvgunst commented 9 years ago

Have you tried using the .pem file from our PHP client (https://raw.githubusercontent.com/mollie/mollie-api-php/master/src/Mollie/API/cacert.pem) on Node v0.12?

Place it next to certdata.txt and change https://github.com/mollie/mollie-api-node/blob/master/lib/mollie/api/client.js#L84

GlennGeenen commented 9 years ago

@lvgunst When I use the cacert.pem I can read the certificate and send a create payment request that provides following error:

Payment Error: {"type":"request","message":"Unauthorized request","links":{"documentation":"https://www.mollie.com/en/docs"}

paetor commented 9 years ago

@amirshakya2010, @GlennGeenen, @jasminjane, @daanbrandt: Release 1.0.4 should fix this issue.

The format of the cacert was incorrect but due to the fact that it was also incorrectly the single element of an array this error didn't surface in older versions of node. Older versions would then use the system-installed CA instead which works fine for most of us with a soundly setup system. With node v0.12 the error was no longer silently ignored and so caused the problem. I've corrected the format of the cacert fixed the buggy array use. Now this file is actually used on all versions of node and also prevents the error from happening in node v0.12.

paetor commented 9 years ago

@GlennGeenen "The Unauthorized request" error usually means you're not using valid credentials (api-key).