Self-Signed Certificate for Node Web Server inside Electron

fyroc

I have an Electron app with a node web server where our website can POST and GET information from the Electron app. The issue is that the website is SSL enabled (HTTPS) but the Electron app is HTTP. Of course, this causes a mixed content exception.

Current Electron Web Server example

http.createServer(function(req,res){
    var pathname=url.parse(req.url).pathname;
    var query = url.parse(req.url).query;
    //enable CORS
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Request-Method', '*');
    res.setHeader('Access-Control-Allow-Headers', '*');
    switch(pathname){
        case '/post':
            createPrintWindow(query);
            res.end('{"status":"200 OK"}');
        break;
        default:
            res.end('{"status":"running","currentVersion":"'+app.getVersion()+'","isUpdateAvailable":"false"}');
        break;
    }
}).listen(3000);

I see that I can enable SSL pretty easily:

var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');

// This line is from the Node.js HTTPS documentation.
var options = {
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.cert')
};

// Create a service (the app object is just a callback).
var app = express();

// Create an HTTP service.
http.createServer(app).listen(80);
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(443);

How to create an HTTPS server in Node.js?

My problem is, I'm not sure how to generate the actual certificates for both win32 and 64x during the installation process (I'm using electron-buider). I know I can do openSSL, but most machines with not have openSSL installed.

I've even found this, but I don't see any documentation or usage examples of it. https://github.com/electron-userland/electron-builder/blob/master/packages/electron-builder/src/cli/create-self-signed-cert.ts

fyroc

It seems like you don't need to generate the .cert and .pem files from each computer that installs it. You can simply just create them once, then package the certificates together in the Electron app.

However, you may want to note that you'll need to visit the page once https://localhost:3000 and accept/ignore and warnings the browser gives you beforehand or else it will not work correctly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Self-signed server certificate for Postfix TLS

Chef Server - How to deal with self signed certificate?

How do I trust a self signed certificate from an electron app?

How to trust a self-signed server certificate with the node-opcua client

From wsdl to client java web service(Server has self signed certificate)

verify server certificate against self-signed certificate authority

Self signed key certificate

Self Signed Certificate in Android

Self Signed Certificate for localhost

SequelizeConnectionError: self signed certificate

InternetOpenUrl with self signed certificate

Using a Self-Signed CA Certificate for WebSocket (ws) in Node JS

Cannot use IP in Node.js for self-signed certificate

'Error: self signed certificate' with node+express application

How to use feh to open web image with self-signed certificate

Progresive Web App Service Worker with Self Signed Certificate

Using a self signed SSL certificate just for a web service

"common name invalid" for a self-signed certificate for websocket server

Wget or curl a self-signed certificate from server

Accept server's self-signed ssl certificate in Java client

ELB to backend server using HTTPS with self-signed certificate

AWS ELB -> Backend Server over HTTPS with Self-Signed Certificate

self signed certificate with openssl for server at home and no domain name

Android - Obtain self-signed server certificate and add to trusted keystore

Self-signed certificate security for private server/client

TLS-secured TCP server and client with self-signed certificate

ASP.NET Core Web API client does not trust self-signed certificate used by the Identity Server instance

Self -Signed certificate vs CA

egit with self signed certificate, https