eltel2910
eltel2910

Reputation: 345

WebRTC over HTTPs Issue

I have created a simple WebRTC application that works fine in testing overlocal host; However, WEBRTC isn't much use unless you have a secure connection, as browsers now will not run GetUserMedia unless you have HTTPs, so I am 'trying' to upgrade it for SSL-TLS. Below is a screen shot of my two applications side by side, one secure (not working) the other non secure (works)

enter image description here

As you can see above, localhost 'connects' while HTTPs 'can't establish connection'. I am new to SSL, so this may be a simple one. Just would appreciate some more eyes on this.

I do know my HTTPS server for the the Javascript is connecting securely, see image belowenter image description here

Below are my code snippets. Any help would be greatly appreciated:

SSL Client - Client.JS

var connection = new WebSocket('wss://localhost:8443'),

name = "";

Non Secure Client - Client.JS

var connection = new WebSocket('ws://localhost:8888'),

    name = "";

Non Secure JS Server - index.JS

var WebSocketServer = require('ws').Server,

wss = new WebSocketServer({ port: 8888 }),

users = {};
wss.on('connection', function (connection) {
connection.on('message', function (message) .....

Secure JS Server - SSLindex.JS

 Var https = require('https'),

fs = require('fs'),

 express = require('express'),

  app = express();


var wss = https.createServer({
key: fs.readFileSync('server.key'),

cert: fs.readFileSync('server.crt'),

ca: fs.readFileSync('ca.crt'),

requestCert: true,

rejectUnauthorized: false
 }, app).listen('8443', function() {
console.log("Secure Express server listening on port 8443");
});

 app.use("/", function(req, res, next) 
{
 res.send("index.js is working!");

  });

Upvotes: 2

Views: 9763

Answers (2)

Josh P
Josh P

Reputation: 1355

I was able to get my EasyRTC page working over HTTPS by using my server's IP address instead of localhost.
So:
https://localhost:8443/ did not work. Returned Connection Closed error.
https://192.168.0.113:8443/ worked OK and showed the web page as it should.

This might work for someone else too.

Upvotes: 2

Ajay
Ajay

Reputation: 2643

For developers convenience chrome will treat localhost as a secure origin.
If you are using http://localhost or ws://localhost there is no SSL involved, so its working just fine in right side screenshot.
But for https or wss, browser will verify the SSL certificate authority.

To resolve websocket connection issue with wss://localhost:8443/

Temporary work around: Open https://localhost:8443/ url and allow the browser exception by clicking Adavced => proceed
Actual Solution: Assign a domain name to your node server (node.kali2016.com) and configure node with Authorised SSL certificates. Then replace
var connection = new WebSocket('wss://localhost:8443')
with
var connection = new WebSocket('wss://yourdomainname:8443')

Upvotes: 5

Related Questions