TiddlyServer icon indicating copy to clipboard operation
TiddlyServer copied to clipboard

Unable to setup SSL

Open UjCbFwtBayFM opened this issue 3 years ago • 2 comments

Using Windows 10 19041.1415 (2004) with TiddlyServer 2.1.4 and OpenSSL 1.1.1m. Followed instructions in documentation and https.js to create keys. Command openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 365 -keyout tiddlyserver.key -out tiddlyserver.cer works but openssl req -x509 -out localhost.cer -keyout localhost.key -days 365 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' -extensions EXT -config <( printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth") fails with error "specified file cannot be found".

UjCbFwtBayFM avatar Jan 25 '22 00:01 UjCbFwtBayFM

I am also trying to do this.

The documentation refers to https.js but I've never been able to find it. Where is it?

marksweston avatar Feb 02 '22 02:02 marksweston

Those instructions are old, I guess. The current docs are "read the source" for that, unfortunately. In short, you set config.bindInfo.https to a JS file relative to the settings file (as shown below), and export the function serverOptions (as shown second).

"bindInfo": {
    "https": "./relative to this file.js",
  },

Refer to the NodeJS documentation for the available options. The options object is passed directly into the https.createServer call.

The host argument is the same that gets passed to the server.listen function ( this.server.listen(port, host); )

// using example object from nodejs docs
exports.serverOptions: = (host) => { 
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};

The object is literally passed directly into the createServer call as shown below (in pseudo code).

var serverOptions = require("/resolved/path/to/https.js").serverOptions;
foreach (var host in hosts) https.createServer(serverOptions(host));

If more than one listener gets created it will be called for each listener, so keep that in mind.

Arlen22 avatar Mar 20 '22 18:03 Arlen22