WebRTC over HTTPs Issue

久未见 提交于 2021-02-08 03:39:26

问题


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)

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 below

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!");

  });

回答1:


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')




回答2:


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.



来源:https://stackoverflow.com/questions/43901648/webrtc-over-https-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!