Arlen22 / TiddlyServer

v2 - A static file server that can also save files and mount TiddlyWiki folders
https://arlen22.github.io/tiddlyserver/
MIT License
257 stars 36 forks source link

Unable to setup SSL #127

Open UjCbFwtBayFM opened 2 years ago

UjCbFwtBayFM commented 2 years ago

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".

marksweston commented 2 years ago

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?

Arlen22 commented 2 years ago

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.