
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
greenlock-express
Advanced tools
Free SSL and managed or automatic HTTPS for node.js with Express, Koa, Connect, Hapi, and all other middleware systems.
Down with Google, Apple, and Facebook!
We're re-decentralizing the web and making it read-write again - one home cloud system at a time.
Tired of serving the Empire? Come join the Rebel Alliance:
jobs@daplie.com | Invest in Daplie on Wefunder | Pre-order Cloud, The World's First Home Server for Everyone
| greenlock (lib) | greenlock-cli | greenlock-express | greenlock-cluster | greenlock-koa | greenlock-hapi |
Free SSL and managed or automatic HTTPS for node.js with Express, Koa, Connect, Hapi, and all other middleware systems.
httpsOptions.SNICallback
)
All you have to do is start the webserver and then visit it at its domain name.
npm install --save greenlock-express@2.x
Important: Use node v4.5+ or v6.x, node <= v4.4 has a known bug in the Buffer
implementation.
Here's a completely working example that will get you started:
app.js
:
'use strict';
require('greenlock-express').create({
server: 'staging'
, email: 'john.doe@example.com'
, agreeTos: true
, approveDomains: [ 'example.com' ]
, app: require('express')().use('/', function (req, res) {
res.end('Hello, World!');
})
}).listen(80, 443);
Certificates will be stored in ~/letsencrypt
.
Important:
You must set server
to https://acme-v01.api.letsencrypt.org/directory
after
you have tested that your setup works.
There are a number of common problems related to system configuration - firewalls, ports, permissions, etc - that you are likely to run up against when using greenlock for your first time.
In order to avoid being blocked by hitting rate limits with bad requests,
you should always test against the 'staging'
server
(https://acme-staging.api.letsencrypt.org/directory
) first.
Whereas v1.x had a few hundred lines of code, v2.x is a single small file of about 50 lines.
A few important things to note:
~/letsencrypt
directory, otherwise you get this:
{ type: 'urn:acme:error:malformed', detail: 'Parse error reading JWS', status: 400 }
approveRegistration
has been replaced by approveDomains
.listen()
helper. It's just there for looks.lex.createAcmeResponder()
is now lex.middleware(require('redirect-https')())
or lex.middleware(app)
The oversimplified example was the bait (because everyone seems to want an example that fits in 3 lines, even if it's terribly bad practices), now here's the switch:
serve.js
:
'use strict';
// returns an instance of node-greenlock with additional helper methods
var lex = require('greenlock-express').create({
// set to https://acme-v01.api.letsencrypt.org/directory in production
server: 'staging'
// If you wish to replace the default plugins, you may do so here
//
, challenges: { 'http-01': require('le-challenge-fs').create({ webrootPath: '/tmp/acme-challenges' }) }
, store: require('le-store-certbot').create({ webrootPath: '/tmp/acme-challenges' })
// You probably wouldn't need to replace the default sni handler
// See https://git.daplie.com/Daplie/le-sni-auto if you think you do
//, sni: require('le-sni-auto').create({})
, approveDomains: approveDomains
});
function approveDomains(opts, certs, cb) {
// This is where you check your database and associated
// email addresses with domains and agreements and such
// The domains being approved for the first time are listed in opts.domains
// Certs being renewed are listed in certs.altnames
if (certs) {
opts.domains = certs.altnames;
}
else {
opts.email = 'john.doe@example.com';
opts.agreeTos = true;
}
// NOTE: you can also change other options such as `challengeType` and `challenge`
// opts.challengeType = 'http-01';
// opts.challenge = require('le-challenge-fs').create({});
cb(null, { options: opts, certs: certs });
}
// handles acme-challenge and redirects to https
require('http').createServer(lex.middleware(require('redirect-https')())).listen(80, function () {
console.log("Listening for ACME http-01 challenges on", this.address());
});
var app = require('express')();
app.use('/', function (req, res) {
res.end('Hello, World!');
});
// handles your app
require('https').createServer(lex.httpsOptions, lex.middleware(app)).listen(443, function () {
console.log("Listening for ACME tls-sni-01 challenges and serve app on", this.address());
});
Security Warning:
If you don't do proper checks in approveDomains(opts, certs, cb)
an attacker will spoof SNI packets with bad hostnames and that will
cause you to be rate-limited and or blocked from the ACME server.
This module is an elaborate ruse (to provide an oversimplified example and to nab some SEO).
The API is actually located at node-greenlock options
(because all options are simply passed through to node-greenlock
proper without modification).
The only "API" consists of two options, the rest is just a wrapper around node-greenlock
to take LOC from 15 to 5:
opts.app
An express app in the format function (req, res) { ... }
(no next
).lex.listen(plainPort, tlsPort)
Accepts port numbers (or arrays of port numbers) to listen on.Brief overview of some simple options for node-greenlock
:
opts.server
set to https://acme-v01.api.letsencrypt.org/directory in productionopts.email
The default email to use to accept agreements.opts.agreeTos
When set to true
, this always accepts the LetsEncrypt TOS. When a string it checks the agreement url first.opts.approveDomains
can be either of:
[ 'example.com', 'www.example.com' ]
function (opts, certs, cb) { cb(null, { options: opts, certs: certs }); }
for setting email
, agreeTos
, domains
, etc (as shown in usage example above)opts.renewWithin
is the maximum number of days (in ms) before expiration to renew a certificate.opts.renewBy
is the minimum number of days (in ms) before expiration to renew a certificate.FAQs
Free SSL and managed or automatic HTTPS for node.js with Express, Koa, Connect, Hapi, and all other middleware systems.
The npm package greenlock-express receives a total of 3,820 weekly downloads. As such, greenlock-express popularity was classified as popular.
We found that greenlock-express demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.