Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

gilboom-acme-client

publishlab30MIT4.1.3TypeScript support: included

Simple and unopinionated ACME client

acme, client, lets, encrypt, acmev2, boulder

readme

acme-client CircleCI

A simple and unopinionated ACME client.

This module is written to handle communication with a Boulder/Let's Encrypt-style ACME API.

Compatibility

acme-client API Style Node.js
v4.x ACMEv2 Promise >= v10
v3.x ACMEv2 Promise >= v8
v2.x ACMEv2 Promise >= v4
v1.x ACMEv1 callback >= v4

Table of contents

Installation

$ npm install acme-client

Usage

const acme = require('acme-client');

const accountPrivateKey = '<PEM encoded private key>';

const client = new acme.Client({
    directoryUrl: acme.directory.letsencrypt.staging,
    accountKey: accountPrivateKey
});

Directory URLs

acme.directory.letsencrypt.staging;
acme.directory.letsencrypt.production;

Cryptography

For key pair generation and Certificate Signing Requests, acme-client uses node-forge, a pure JavaScript implementation of the TLS protocol.

These utility methods are exposed through .forge.

API documentation: docs/forge.md

Example

const privateKey = await acme.forge.createPrivateKey();

const [certificateKey, certificateCsr] = await acme.forge.createCsr({
    commonName: '*.example.com',
    altNames: ['example.com']
});

Auto mode

For convenience an auto() method is included in the client that takes a single config object. This method will handle the entire process of getting a certificate for one or multiple domains.

A full example can be found at examples/auto.js.

Documentation: docs/client.md#AcmeClient+auto

Example

const autoOpts = {
    csr: '<PEM encoded CSR>',
    email: 'test@example.com',
    termsOfServiceAgreed: true,
    challengeCreateFn: async (authz, challenge, keyAuthorization) => {},
    challengeRemoveFn: async (authz, challenge, keyAuthorization) => {}
};

const certificate = await client.auto(autoOpts);

Challenge priority

When ordering a certificate using auto mode, acme-client uses a priority list when selecting challenges to respond to. Its default value is ['http-01', 'dns-01'] which translates to "use http-01 if any challenges exist, otherwise fall back to dns-01".

While most challenges can be validated using the method of your choosing, please note that wildcard certificates can only be validated through dns-01. More information regarding Let's Encrypt challenge types can be found here.

To modify challenge priority, provide a list of challenge types in challengePriority:

await client.auto({
    ...,
    challengePriority: ['http-01', 'dns-01']
});

Internal challenge verification

When using auto mode, acme-client will first validate that challenges are satisfied internally before completing the challenge at the ACME provider. In some cases (firewalls, etc) this internal challenge verification might not be possible to complete.

If internal challenge validation needs to travel through an HTTP proxy, see HTTP client defaults.

To completely disable acme-clients internal challenge verification, enable skipChallengeVerification:

await client.auto({
    ...,
    skipChallengeVerification: true
});

API

For more fine-grained control you can interact with the ACME API using the methods documented below.

A full example can be found at examples/api.js.

API documentation: docs/client.md

Example

const account = await client.createAccount({
    termsOfServiceAgreed: true,
    contact: ['mailto:test@example.com']
});

const order = await client.createOrder({
    identifiers: [
        { type: 'dns', value: 'example.com' },
        { type: 'dns', value: '*.example.com' }
    ]
});

HTTP client defaults

This module uses axios when communicating with the ACME HTTP API, and exposes the client instance through .axios.

For example, should you need to change the default axios configuration to route requests through an HTTP proxy, this can be achieved as follows:

const acme = require('acme-client');

acme.axios.defaults.proxy = {
    host: '127.0.0.1',
    port: 9000
};

A complete list of axios options and documentation can be found at:

Debugging

acme-client uses debug for debugging which can be enabled by running

DEBUG=acme-client node index.js

License

MIT

changelog

Changelog

v4.1.3 (2021-02-22)

v4.1.2 (2020-11-16)

  • fixed Bug when encoding PEM payloads, potentially causing malformed requests

v4.1.1 (2020-11-13)

  • fixed Missing TypeScript definitions

v4.1.0 (2020-11-12)

  • added Option preferredChain added to client.getCertificate() and client.auto() to indicate which certificate chain is preferred if a CA offers multiple
  • added Method client.getOrder() to refresh order from CA
  • fixed Upgrade `axios@0.21.0`
  • fixed Error when attempting to revoke a certificate chain
  • fixed Missing URL augmentation in client.finalizeOrder() and client.deactivateAuthorization()
  • fixed Add certificate issuer to response from forge.readCertificateInfo()

v4.0.2 (2020-10-09)

v4.0.1 (2020-09-15)

v4.0.0 (2020-05-29)

  • fixed Incorrect TypeScript CertificateInfo definitions
  • fixed Allow trailing whitespace character in http-01 challenge response
  • breaking Remove support for Node v8
  • breaking Remove deprecated openssl crypto module

v3.3.1 (2020-01-07)

  • fixed Improvements to TypeScript definitions

v3.3.0 (2019-12-19)

v3.2.1 (2019-11-14)

  • added New option skipChallengeVerification added to client.auto() to bypass internal challenge verification

v3.2.0 (2019-08-26)

  • added More extensive testing using letsencrypt/pebble
  • changed When creating a CSR, commonName no longer defaults to 'localhost'
    • This change is not considered breaking since commonName: 'localhost' will result in an error when ordering a certificate
  • fixed Retry signed API requests on urn:ietf:params:acme:error:badNonce - RFC 8555 Section 6.5
  • fixed Minor bugs related to POST-as-GET when calling updateAccount()
  • fixed Ensure subject common name is present in SAN when creating a CSR - CAB v1.2.3 Section 9.2.2
  • fixed Send empty JSON body when responding to challenges - RFC 8555 Section 7.5.1

v2.3.1 (2019-08-26)

  • backport Minor bugs related to POST-as-GET when calling client.updateAccount()
  • backport Send empty JSON body when responding to challenges

v3.1.0 (2019-08-21)

  • added UTF-8 support when generating a CSR subject using forge - RFC 5280
  • fixed Implemented POST-as-GET for all ACME API requests - RFC 8555 Section 6.3

v2.3.0 (2019-08-21)

  • backport Implemented POST-as-GET for all ACME API requests

v3.0.0 (2019-07-13)

  • added Expose axios instance to allow manipulating HTTP client defaults
  • breaking Remove support for Node v4 and v6
  • breaking Remove Babel transpilation

v2.2.3 (2019-01-25)

  • added DNS CNAME detection when verifying dns-01 challenges

v2.2.2 (2019-01-07)

  • added Support for tls-alpn-01 challenge key authorization

v2.2.1 (2019-01-04)

  • fixed Handle and throw errors from OpenSSL process

v2.2.0 (2018-11-06)

  • added New node-forge crypto engine, removes OpenSSL CLI dependency
  • added Support native crypto.generateKeyPair() API when generating key pairs

v2.1.0 (2018-10-21)

  • added Ability to set and get current account URL
  • fixed Replace HTTP client request with axios
  • fixed Auto-mode no longer tries to create account when account URL exists

v2.0.1 (2018-08-17)

v2.0.0 (2018-04-02)

  • breaking ACMEv2
  • breaking API changes
  • breaking Rewrite to ES6
  • breaking Promises instead of callbacks

v1.0.0 (2017-10-20)

  • API stable

v0.2.1 (2017-09-27)

  • fixed Bug causing invalid anti-replay nonce

v0.2.0 (2017-09-21)

  • breaking OpenSSL method readCsrDomains and readCertificateInfo now return domains as an object
  • fixed Added and fixed some tests

v0.1.0 (2017-09-14)

  • acme-client released