Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

restify JSON client returns DEPTH_ZERO_SELF_SIGNED_CERT error

I have server runing on heroku with heroku SSL addon. Server is created with this options:

name: 'ServerName',
version: '1.0.0',

And the I run server like this:

    server.listen(process.env.PORT || 5000)

And it works fine, I can call my api for example: https://myapp.herokuapp.com/some-path. SSL cert on heroku is self-signed so there is a big warning in webbrowser but I can click continue and it works.

When I want to call my server with restify JSON client, created as follows:

var client   = restify.createJsonClient({
    url: 'https://myapp.herokuapp.com'
});

and then call some api like this client.get('/some-path',...) then client returns error:

DEPTH_ZERO_SELF_SIGNED_CERT

I tried to set option rejectUnauthorized on both server and client (as constructor option) but it didnt help...

like image 778
user606521 Avatar asked Feb 15 '23 08:02

user606521


2 Answers

I've just tested on my own HTTPS server with a self-signed certificate. rejectUnauthorized on the client side should definitely solve it for you

var restify = require('restify'),

    client = restify.createJsonClient({
        url: 'https://127.0.0.1/booking',
        rejectUnauthorized: false
    }),

    assert = require('assert');

describe('/booking/ component\'s JSON-HAL HTTP API description', function () {
    it('responds with status 200', function (done) {
        client.get('/', function (error, request, response) {
            assert(!error);
            assert.strictEqual(response.statusCode, 200);
            done();
        });
    });
});

As soon as I remove the rejectUnauthorized option, the test fails with DEPTH_ZERO_SELF_SIGNED_CERT.

like image 115
Ivan Krechetov Avatar answered Feb 19 '23 05:02

Ivan Krechetov


For me rejectUnauthorized didn't work. Finally I ended up with:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

And it works...

like image 44
user606521 Avatar answered Feb 19 '23 07:02

user606521