tlsd 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- package/index.js +77 -0
- package/package.json +24 -0
- package/test.js +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# tlsd
|
|
2
|
+
|
|
3
|
+
A simple way to make a Node.js based HTTPS server that uses a real SSL/TLS certificate.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Step 1: Point your domain name to your server
|
|
7
|
+
|
|
8
|
+
For example, if you domain is "foo.com", and your server's IP address is
|
|
9
|
+
"1.2.3.4", then you might create a DNS "A" record that points the domain
|
|
10
|
+
"foo.com" to "1.2.3.4".
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Step 2: Install this Node module
|
|
14
|
+
|
|
15
|
+
npm install tlsd
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## Step 3: Use this Node module
|
|
19
|
+
|
|
20
|
+
Write your server code:
|
|
21
|
+
|
|
22
|
+
const tlsd = require( "." ).create( "foo@yourdomain.com", true );
|
|
23
|
+
|
|
24
|
+
const handler = function( req, res ) {
|
|
25
|
+
res.write( "Hello, world.\n" );
|
|
26
|
+
res.end();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
tlsd.add_domain( "yourdomain.com", handler );
|
|
30
|
+
|
|
31
|
+
tlsd.listen();
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## Step 4: Test
|
|
35
|
+
|
|
36
|
+
When you run your code, yyou should be able to do something like:
|
|
37
|
+
|
|
38
|
+
curl "https:foo.com"
|
|
39
|
+
|
|
40
|
+
The output should be your "Hello, world.\n" text.
|
|
41
|
+
|
|
42
|
+
Note that the first time you make the request there is short detail whil
|
|
43
|
+
the certificate is being created and registered.
|
|
44
|
+
|
|
45
|
+
|
package/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright 2021 -- Sleepless Software Inc. -- All Rights Reserved
|
|
2
|
+
|
|
3
|
+
require( "sleepless" );
|
|
4
|
+
|
|
5
|
+
const L = log5.mkLog( "TLS: " )( 2 );
|
|
6
|
+
|
|
7
|
+
// ----------------
|
|
8
|
+
|
|
9
|
+
function TLS( email = null, agreeTos = false ) {
|
|
10
|
+
|
|
11
|
+
// This handles all incoming requests and passes control to the domain specific handler
|
|
12
|
+
const app = function(req, res) {
|
|
13
|
+
L.V("_____________________________");
|
|
14
|
+
|
|
15
|
+
let domain = req.headers.host || ""; // sometimes missing, hence the || ""
|
|
16
|
+
domain = domain.replace( /:.*/, "" ); // remove port # if present
|
|
17
|
+
L.V( domain+": "+req.method+" "+req.url );
|
|
18
|
+
|
|
19
|
+
let d = domains[ domain ];
|
|
20
|
+
if( ! d ) {
|
|
21
|
+
res.end();
|
|
22
|
+
L.W( "bogus host: "+domain );
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return d.handler( req, res );
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/*const approver = function( options, certs, cb ) {
|
|
30
|
+
L.I( "approving domain: " + options.domain );
|
|
31
|
+
cb( null, { options, certs } );
|
|
32
|
+
};*/
|
|
33
|
+
|
|
34
|
+
let cfg = {
|
|
35
|
+
version: "draft-11",
|
|
36
|
+
server: "https://acme-v02.api.letsencrypt.org/directory",
|
|
37
|
+
configDir: "./acme/",
|
|
38
|
+
store: require( "greenlock-store-fs" ),
|
|
39
|
+
app,
|
|
40
|
+
// approver,
|
|
41
|
+
agreeTos,
|
|
42
|
+
email,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let domains = {};
|
|
46
|
+
|
|
47
|
+
const add_domain = function add_domain( domain, handler ) {
|
|
48
|
+
domains[ domain ] = { handler };
|
|
49
|
+
L.I( "domain added: "+domain );
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const listen = function listen( http_port = 80, https_port = 443 ) {
|
|
53
|
+
let server = require( 'greenlock-express' ).create( cfg ).listen( http_port, https_port );
|
|
54
|
+
server.on( 'listening', function() {
|
|
55
|
+
L.I( "listening on " + o2j( server.address() ) );
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const debug = function set_log_level( n ) {
|
|
60
|
+
L( n );
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
add_domain,
|
|
65
|
+
listen,
|
|
66
|
+
debug,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// ----------------
|
|
73
|
+
|
|
74
|
+
exports.create = function create( email = null, agreeTos = false ) {
|
|
75
|
+
return new TLS( email, agreeTos );
|
|
76
|
+
};
|
|
77
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tlsd",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/sleeplessinc/tls.git"
|
|
12
|
+
},
|
|
13
|
+
"author": "Joe Hitchens <joe@sleepless.com>",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/sleeplessinc/tls/issues"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/sleeplessinc/tls#readme",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"greenlock-express": "^2.7.8",
|
|
21
|
+
"greenlock-store-fs": "^3.2.2",
|
|
22
|
+
"sleepless": "^4.4.3"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/test.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
// create the TLS daemon
|
|
4
|
+
// You must explicity agree to lets-encrypet terms of service with the "true" arg.
|
|
5
|
+
const tlsd = require( "." ).create( "foo@sleepless.com", true );
|
|
6
|
+
|
|
7
|
+
// Optionally set debug logging level 0 thru 5 (0 = none, 5 = max)
|
|
8
|
+
// Default is 2
|
|
9
|
+
tlsd.debug(3);
|
|
10
|
+
|
|
11
|
+
// A request handler for "sleepless.com"
|
|
12
|
+
const handler = function( req, res ) {
|
|
13
|
+
res.write( "okay!\n" );
|
|
14
|
+
res.end();
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// A request handler for "www.sleepless.com"
|
|
18
|
+
const www_handler = function( req, res ) {
|
|
19
|
+
res.write( "www okay!\n" );
|
|
20
|
+
res.end();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Add the domain handlers to the daemon
|
|
24
|
+
tlsd.add_domain( "sleepless.com", handler );
|
|
25
|
+
tlsd.add_domain( "www.sleepless.com", www_handler );
|
|
26
|
+
|
|
27
|
+
// start listening
|
|
28
|
+
tlsd.listen( 8080, 8443 );
|
|
29
|
+
// ... or
|
|
30
|
+
// tlsd.listen(); // use default http and https ports
|
|
31
|
+
|
|
32
|
+
|