deepstreamIO / deepstream.io

deepstream.io server
https://deepstreamio.github.io
MIT License
7.14k stars 381 forks source link

deepstream@5.0.5 SSL self signed certificate #1040

Closed caracal7 closed 4 years ago

caracal7 commented 4 years ago

deepstream.io server

const fs = require('fs');
const path = require('path');
const { Deepstream } = require( '@deepstream/server' );

const keyUrl = name => path.resolve(__dirname, '../server/cert', name);
const keyFile = name => fs.readFileSync(keyUrl(name), 'utf8');

const DeepstreamServer = new Deepstream( {
    httpServer: {
        type: 'uws', //  type: 'default',
        options: {
            port: 6020,
            host: '127.0.0.1',
            allowAllOrigins: true,
            ssl: {
                key: keyUrl("privkey.pem"),  //  key: keyFile("privkey.pem"),
                cert: keyUrl("fullchain.pem"),  // cert: keyFile("fullchain.pem"),
            }
        }
    },
});

. Browser client and NODE.js client is the same

import { DeepstreamClient } from '@deepstream/client';
const client = new DeepstreamClient('wss://localhost:6020');

Chrome console error

WebSocket connection to 'wss://localhost:6020/deepstream' failed: 
Error in connection establishment: net::ERR_CERT_COMMON_NAME_INVALID 
socket-factory.js:21 

Safari console error

ReferenceError: Can't find variable: Buffer

Node.js 12.4.0 error With uWS server

CONNECTION_ERROR
"connect ECONNREFUSED 127.0.0.1:6020" 

With default server

CONNECTION_ERROR
DEPTH_ZERO_SELF_SIGNED_CERT
"self signed certificate" 
caracal7 commented 4 years ago

solve problem in Node.js by adding

process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;

But can't solve in browser

caracal7 commented 4 years ago

Solve problem with accepting self signed certificate in Chrome

Simply paste this in Chrome:

chrome://flags/#allow-insecure-localhost

Now the same console error like in Safari

ReferenceError: Can't find variable: Buffer

Next install Buffer polyfill

npm i buffer

and use it

import { DeepstreamClient } from '@deepstream/client';
window.Buffer = require('buffer').Buffer;

const client = new DeepstreamClient('wss://localhost:6020'); 

Bingo! can close the issue

P.S. everything is worked with "default" httpServer. If I try uWS then browser client connect without problems but Node client get ECONNREFUSED without text message

yasserf commented 4 years ago

Interesting! I wonder why we need the buffer tho, should be bundled normally.

Thanks for mentioning the fix! Closing