I have an AngularJS application that is running on a SSL secured server. Now I want to contact a RaspberryPI via a websocket to get some stream data. The Raspberry doesn't have it's own webserver (nginx/apache) so i can't use e.g. letsencrypt but self signed certificates, only. The Problem is that it isn't working and I couldn't find a working solution (after spending 6h of reading forums). Here is my code:
I created my self signed certificate via:
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 9999 -nodes
In AngularJS I do simple:
const ip = IPADDRESS:9030
connection = new WebSocket('wss://' + ip);
A node server is running on the Raspberry. It looks like this:
const net = require('net');
const fs = require('fs');
const https = require('https');
var options = {
key: fs.readFileSync('ssl/key.pem'),
cert: fs.readFileSync('ssl/cert.pem'),
requestCert: false,
rejectUnauthorized: false
};
//pass in your express app and credentials to create an https server
const httpsServer = https.createServer(options);
httpsServer.listen(9030);
/**
* server
*/
let connections = {};
let WebSocketServer = require('ws').Server;
let wss = new WebSocketServer({server: httpsServer}),
wss.on('connection', function(ws) {
...
}
When starting the server with node server.js
and start my AngularJS app I get the error message:
WebSocket connection to 'wss://IPADDRESS:9030/' failed: Error in connection establishment: net::ERR_CERT_AUTHORITY_INVALID
What can I do to get it to work? Thx for your help!