ACME DNS-01 Interactive CLI Challenge Handler

3.0.7 · active · verified Wed Apr 22

acme-dns-01-cli is an interactive command-line interface (CLI) based strategy for handling ACME DNS-01 challenges, primarily designed for integration within the Greenlock and ACME.js ecosystems. As of version 3.0.7, it provides a simple, manual process where it prints the required DNS Host and Key Authorization Digest to the terminal, pauses for user input, and then verifies the challenge. Unlike HTTP-01 challenges, this module fully supports wildcard certificate requests, making it a crucial component for securing domains like `*.example.com`. Its main differentiation is its direct, interactive nature, serving as a reference implementation for those needing manual control over the DNS challenge process or adapting it to custom environments. While it requires manual intervention, it offers flexibility for environments where automated DNS provisioning isn't feasible or desired. It integrates seamlessly as a challenge handler within Greenlock's configuration.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate `acme-dns-01-cli` into a Greenlock instance as a DNS-01 challenge handler, initiating a certificate request that will prompt the user for manual DNS record updates.

import Greenlock from 'greenlock';
import { create as createDns01CliChallenge } from 'acme-dns-01-cli';

// Configure the acme-dns-01-cli challenge handler
const challengeConfig = createDns01CliChallenge({
  debug: true // Enable debug output for the CLI handler
});

// Initialize Greenlock with the custom challenge handler
const greenlock = Greenlock.create({
  package: {
    name: 'my-greenlock-app',
    version: '1.0.0',
  },
  configDir: './greenlock.d/', // Specify a configuration directory
  maintainerEmail: 'your-email@example.com',
  cluster: false, // Set to true for multi-process environments
  challenges: {
    'dns-01': challengeConfig // Register the interactive DNS-01 challenge
  },
  // Define how domains are approved (customize as needed)
  approveDomains: async (opts) => {
    console.log(`Greenlock is requesting approval for: ${opts.subject || opts.altnames.join(', ')}`);
    // For acme-dns-01-cli, the manual interaction will occur via the challengeConfig
    return opts;
  },
});

// Function to request a certificate (this will trigger the CLI prompt)
async function obtainCertificate() {
  const domainsToSecure = ['example.com', '*.example.com']; // Example domains
  console.log(`Attempting to obtain certificate for: ${domainsToSecure.join(', ')}`);
  try {
    const cert = await greenlock.add({
      subject: domainsToSecure[0], // Primary domain
      altnames: domainsToSecure,   // All domains including wildcard
      email: 'your-email@example.com', // Email for renewal notices
    });
    console.log('Successfully obtained certificate:', cert);
  } catch (err) {
    console.error('Failed to obtain certificate:', err);
    if (err.challenge && err.challenge.dnsHost && err.challenge.dnsAuthorization) {
        console.warn(`Please verify the TXT record for ${err.challenge.dnsHost} with value ${err.challenge.dnsAuthorization} is correctly set.`);
    }
  }
}

// Execute the certificate acquisition process
obtainCertificate();

// In a real application, Greenlock would also manage a server
// to handle certificate renewals and serve HTTPS traffic.
// Example (requires 'greenlock-express'):
/*
import greenlockExpress from 'greenlock-express';

greenlockExpress.create({
  package: greenlock.defaults.package,
  configDir: greenlock.defaults.configDir,
  maintainerEmail: greenlock.defaults.maintainerEmail,
  cluster: greenlock.defaults.cluster,
  challenges: greenlock.defaults.challenges,
  approveDomains: greenlock.defaults.approveDomains,
  // Add your server options here
}).listen(80, 443);
*/

view raw JSON →