npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

le-sni-auto

v2.1.9

Published

An auto-sni strategy for registering and renewing letsencrypt certificates using SNICallback

Downloads

15,788

Readme

le-sni-auto

| Sponsored by ppl

An auto-sni strategy for registering and renewing letsencrypt certificates using SNICallback.

This does a couple of rather simple things:

  • caches certificates in memory
  • calls getCertificatesAsync(domain, null) when a certificate is not in memory
  • calls getCertificatesASync(domain, certs) when a certificate is up for renewal or expired

Install

npm install --save [email protected]

Usage

With node-letsencrypt

'use strict';



var leSni = require('le-sni-auto').create({

  renewWithin: 14 * 24 * 60 * 60 1000     // do not renew more than 14 days before expiration
, renewBy: 10 * 24 * 60 * 60 1000         // do not wait more than 10 days before expiration

, tlsOptions: {
    rejectUnauthorized: true              // These options will be used with tls.createSecureContext()
  , requestCert: false                    // in addition to key (privkey.pem) and cert (cert.pem + chain.pem),
  , ca: null                              // which are provided by letsencrypt
  , crl: null
  }

});



var le = require('letsencrypt').create({
  server: 'staging'

, sni: leSni

, approveDomains: function (domain, cb) {
    // here you would lookup details such as email address in your db
    cb(null, { email: '[email protected].', domains: [domain, 'www.' + domain], agreeTos: true }}
  }
});



var redirectHttps = require('redirect-https').create();
http.createServer(le.middleware(redirectHttps));



var app = require('express')();
https.createServer(le.tlsOptions, le.middleware(app)).listen(443);

You can also provide a thunk-style getCertificates(domain, certs, cb).

Standalone

'use strict';



var leSni = require('le-sni-auto').create({
  renewWithin: 14 * 24 * 60 * 60 1000       // do not renew prior to 10 days before expiration
, renewBy: 10 * 24 * 60 * 60 1000         // do not wait more than 5 days before expiration

  // key (privkey.pem) and cert (cert.pem + chain.pem) will be provided by letsencrypt
, tlsOptions: { rejectUnauthorized: true, requestCert: false, ca: null, crl: null }

, getCertificatesAsync: function (domain, certs) {
    // return a promise with an object with the following keys:
    // { privkey, cert, chain, expiresAt, issuedAt, subject, altnames }
  }
});



var tlsOptions = {
  SNICallback: leSni.sniCallback
};

https.createServer(tlsOptions, app);

You can also provide a thunk-style getCertificates(domain, certs, cb).

API

  • create(options)
    • getCertificates(domain, certs, cb) or getCertificatesAsync(domain, certs)
    • renewWithin (default 7 days, min 3 days)
    • renewBy (default 2 days, min 12 hours)
  • sniCallback(domain, cb)
  • cacheCerts(certs)
  • uncacheDomain(domain)

.renewWithin

Specifies the maximum amount of time (in ms) before the certificate expires to renew it.

Say the cert expires in 90 days and you would like to renew, at earliest 10 days before it expires.

You would set this to 10 * 24 * 60 * 60 * 1000.

.renewBy

Specifies the maximum amount of time (in ms) before the certificate expires to renew it.

Say the cert expires in 90 days and you would like to renew, at latest 10 days before it expires.

You would set this to 10 * 24 * 60 * 60 * 1000.

MUST be less than renewWithin.

.sniCallback()

This gets passed to https.createServer(tlsOptions, app) as tlsOptions.SNICallback.

var leSni = require('le-sni-auto').create({
  renewWithin: 14 * 24 * 60 * 60 1000
});

var tlsOptions = {
  SNICallback: leSni.sniCallback
};

function app(req, res) {
  res.end("Hello, World!");
}

https.createServer(tlsOptions, app);

.cacheCerts()

Manually load a certificate into the cache.

This is useful in a cluster environment where the master may wish to inform multiple workers of a new or renewed certificate, or to satisfy tls-sni-01 challenges.

leSni.cacheCerts({
, privkey: '<<privkey.pem>>'
, cert: '<<cert.pem + chain.pem>>'
, subject: 'example.com'
, altnames: [ 'example.com', 'www.example.com' ]
, issuedAt: 1470975565000
, expiresAt: 1478751565000
, auto: true
});

.uncacheCerts()

Remove cached certificates from the cache.

This is useful once a tls-sni-01 challenge has been satisfied.

leSni.uncacheCerts({
, subject: 'example.com'
, altnames: [ 'example.com', 'www.example.com' ]
});