Skip to content

Simple way to retrieve SSL certificate using HTTP ACME challenge

License

Notifications You must be signed in to change notification settings

megahertz/letssl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

letssl

Tests npm version

Description

Simple way to retrieve SSL certificate using HTTP ACME challenge. By default, Let's Encrypt Authority is used.

Installation

Install with npm:

npm install --save letssl

Usage

const express = require('express');
const https = require('https');
const { getCertificate } = require('letssl');

async function startServer() {
  const [key, cert] = await getCertificate({ commonName: 'example.com' });
  
  const app = express();
  app.get('/', (req, res) => {
    res.end('Using SSL');
  });
  
  const server = https.createServer({ key, cert }, app).listen(443);
}

startServer();

Testing

There are three ways how certificate obtaining process could be tested.

Self-signed certificate

When you don't need to test real domain you can set the provider option to selfSigned:

const [key, cert] = await getCertificate({
  commonName: 'example.localhost',
  provider: 'selfSigned',
});

Let's Encrypt staging

When debugLevel is set and no directoryUrl provider, https://acme-staging-v02.api.letsencrypt.org/directory is used as directoryUrl

const [key, cert] = await getCertificate({ commonName: 'stage.example.com', debugLevel: 1, // when > 0 and no directoryUrl, });

Test ACME server

If you need to run tests frequently, you can use Pebble, a small ACME test server. See the e2e test for example.

Credits