From c7bb163e8ca868b2f86231aa3617c7c1334d3b39 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Sat, 14 Nov 2026 22:17:24 -0700 Subject: [PATCH] Certificates: reuse the installer's HTTP-01 account, and ask port 80 or 443 The guides only knew DNS-01 and TLS-ALPN-01, so on an installer setup they never reused its HTTP-01 Let's Encrypt account and always added a TLS-ALPN-01 one, which can't validate while the installer's web server holds port 443. Both guides now ask how Let's Encrypt reaches the server for names checked without DNS: port 80 (HTTP-01) or port 443 (TLS-ALPN-01). It starts on port 80 when the server already has an HTTP-01 account, as an installer setup does, so that account is reused; otherwise on port 443, as before. The texts that said port 443 say the chosen port. Fixes #206 --- .../certificates/CertificateSetupPage.tsx | 29 +++++++---- src/features/certificates/DirectChoice.tsx | 48 +++++++++++++++++++ .../certificates/OrderCertificatePage.tsx | 22 ++++++--- src/features/certificates/shared.test.ts | 42 ++++++++++++++++ src/features/certificates/shared.ts | 41 ++++++++++++++-- src/i18n/en.json | 15 ++++-- 6 files changed, 173 insertions(+), 24 deletions(-) create mode 100644 src/features/certificates/DirectChoice.tsx create mode 100644 src/features/certificates/shared.test.ts diff --git a/src/features/certificates/CertificateSetupPage.tsx b/src/features/certificates/CertificateSetupPage.tsx index 3847e03..64fc1fc 100644 --- a/src/features/certificates/CertificateSetupPage.tsx +++ b/src/features/certificates/CertificateSetupPage.tsx @@ -8,7 +8,8 @@ * inbuxa: guided setup, "Certificates, automatically" (settings-reorg, first * wave). Picks domains, checks every name the certificate will cover before * anything is ordered, chooses how Let's Encrypt checks them (through DNS - * when the domain's DNS is connected, otherwise on port 443), switches the + * when the domain's DNS is connected, otherwise on port 80 or 443: an + * existing HTTP-01 account, as the installer makes, picks port 80), switches the * domains to automatic, and watches the certificates arrive. */ @@ -29,13 +30,15 @@ import type { JmapSetResponse } from '@/types/jmap'; import { RESOLVER_NAME } from '@/features/dns/liveCheck'; import { cn } from '@/lib/utils'; import { classify, orderNames, type Method } from './names'; +import { DirectChoice } from './DirectChoice'; import { addProvider, - CHALLENGE, type CertRow, type Check, coveringCert, currentCert, + defaultDirect, + type Direct, type DomainRow, fmtDate, LE_PRODUCTION, @@ -43,6 +46,8 @@ import { type Loaded, load, pollOrders, + PORT, + providerFor, resolveAddresses, } from './shared'; import { StateIcon } from './StateIcon'; @@ -72,6 +77,7 @@ export function CertificateSetupPage() { const [anyway, setAnyway] = useState>(new Set()); const [staging, setStaging] = useState(false); const [contact, setContact] = useState(''); + const [direct, setDirect] = useState('TlsAlpn01'); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [startedAt, setStartedAt] = useState(null); @@ -87,6 +93,7 @@ export function CertificateSetupPage() { setData(d); setPicked(new Set(d.domains.filter((x) => !x.automatic).map((x) => x.id))); setContact(d.providers.find((p) => p.contact.length > 0)?.contact[0] ?? ''); + setDirect(defaultDirect(d.providers)); }) .catch((e: unknown) => live && setLoadError(e instanceof Error ? e.message : String(e))); return () => { @@ -157,9 +164,9 @@ export function CertificateSetupPage() { const directory = staging ? LE_STAGING : LE_PRODUCTION; const methodsNeeded = [...new Set(going.map(methodOf))]; - const providerFor = (m: Method) => - data?.providers.find((p) => p.directory === directory && p.challengeType === CHALLENGE[m]); - const needsNewProvider = methodsNeeded.some((m) => !providerFor(m)); + const existingFor = (m: Method) => (data ? providerFor(data.providers, directory, m, direct) : undefined); + const needsNewProvider = methodsNeeded.some((m) => !existingFor(m)); + const port = PORT[direct]; const poll = useCallback(async () => { setWatch(await pollOrders()); @@ -189,12 +196,12 @@ export function CertificateSetupPage() { try { const ids: Partial> = {}; for (const m of methodsNeeded) { - const existing = providerFor(m); + const existing = existingFor(m); if (existing) { ids[m] = existing.id; continue; } - const id = await addProvider(m, contact, staging); + const id = await addProvider(m, direct, contact, staging); ids[m] = id; made.push(id); } @@ -272,7 +279,8 @@ export function CertificateSetupPage() {

{t( 'certSetup.howTls', - 'Otherwise Let’s Encrypt connects to this server on port 443 for each name. Those names must point straight at this server, not through a proxy.', + 'Otherwise Let’s Encrypt connects to this server on port {{port}} for each name. Those names must point straight at this server, not through a proxy.', + { port }, )}

@@ -316,7 +324,7 @@ export function CertificateSetupPage() { : t('certSetup.noCert', 'No certificate yet.')}{' '} {methodOf(d) === 'dns' ? t('certSetup.viaDns', 'Checked through DNS.') - : t('certSetup.viaTls', 'Checked on port 443.')} + : t('certSetup.viaTls', 'Checked on port {{port}}.', { port })} @@ -467,6 +475,7 @@ export function CertificateSetupPage() { } > + {methodsNeeded.includes('tls') && } {needsNewProvider ? (
@@ -553,7 +562,7 @@ export function CertificateSetupPage() { how: methodOf(d) === 'dns' ? t('certSetup.howDnsWord', 'through DNS') - : t('certSetup.howTlsWord', 'on port 443'), + : t('certSetup.howTlsWord', 'on port {{port}}', { port }), names: namesOf(d).join(', '), }, )} diff --git a/src/features/certificates/DirectChoice.tsx b/src/features/certificates/DirectChoice.tsx new file mode 100644 index 0000000..6ad9e6a --- /dev/null +++ b/src/features/certificates/DirectChoice.tsx @@ -0,0 +1,48 @@ +/* + * SPDX-FileCopyrightText: 2026 Coffey Labs LLC + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +/** + * inbuxa: how Let’s Encrypt reaches this server for names checked without + * DNS, port 80 or port 443 (#206). Both certificate guides ask it. + */ + +import { useTranslation } from 'react-i18next'; +import type { Direct } from './shared'; + +export function DirectChoice({ value, onChange }: { value: Direct; onChange: (v: Direct) => void }) { + const { t } = useTranslation(); + const choice = (v: Direct, title: string, body: string) => ( + + ); + return ( +
+ + {t('certSetup.directTitle', 'How Let’s Encrypt reaches this server')} + + {choice( + 'Http01', + t('certSetup.directHttp', 'Port 80 (HTTP-01)'), + t( + 'certSetup.directHttpHint', + 'A web server in front of this one holds port 443 and passes /.well-known/acme-challenge/ on port 80 to it. The installer sets it up this way.', + ), + )} + {choice( + 'TlsAlpn01', + t('certSetup.directTls', 'Port 443 (TLS-ALPN-01)'), + t('certSetup.directTlsHint', 'This server answers HTTPS on port 443 itself.'), + )} +
+ ); +} diff --git a/src/features/certificates/OrderCertificatePage.tsx b/src/features/certificates/OrderCertificatePage.tsx index 496eab8..ffeff35 100644 --- a/src/features/certificates/OrderCertificatePage.tsx +++ b/src/features/certificates/OrderCertificatePage.tsx @@ -41,12 +41,14 @@ import { sameNames, suggestDomain, } from './orders'; +import { DirectChoice } from './DirectChoice'; import { addProvider, - CHALLENGE, type CertRow, type Check, coveringCert, + defaultDirect, + type Direct, type DomainRow, fmtDate, LE_PRODUCTION, @@ -54,6 +56,8 @@ import { type Loaded, load, pollOrders, + PORT, + providerFor, refusal, resolveAddresses, } from './shared'; @@ -79,6 +83,7 @@ export function OrderCertificatePage() { const [anyway, setAnyway] = useState(false); const [staging, setStaging] = useState(false); const [contact, setContact] = useState(''); + const [direct, setDirect] = useState('TlsAlpn01'); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [startedAt, setStartedAt] = useState(null); @@ -101,6 +106,7 @@ export function OrderCertificatePage() { if (!live) return; setData(d); setContact(d.providers.find((p) => p.contact.length > 0)?.contact[0] ?? ''); + setDirect(defaultDirect(d.providers)); }) .catch((e: unknown) => live && setLoadError(e instanceof Error ? e.message : String(e))); return () => { @@ -135,7 +141,8 @@ export function OrderCertificatePage() { const replaced = domain?.automatic && !unchanged ? currentNames.filter((n) => !names.includes(n)) : []; const directory = staging ? LE_STAGING : LE_PRODUCTION; - const provider = data?.providers.find((p) => p.directory === directory && p.challengeType === CHALLENGE[method]); + const provider = data ? providerFor(data.providers, directory, method, direct) : undefined; + const port = PORT[direct]; const runChecks = useCallback(async () => { if (!data || method !== 'tls') return; @@ -223,7 +230,7 @@ export function OrderCertificatePage() { try { let providerId = provider?.id; if (!providerId) { - providerId = await addProvider(method, contact, staging); + providerId = await addProvider(method, direct, contact, staging); made = providerId; } const [res] = await jmapSet('x:Domain', getAccountId('x:Domain'), { @@ -290,7 +297,8 @@ export function OrderCertificatePage() { {error}

); - const how = method === 'dns' ? t('certSetup.howDnsWord', 'through DNS') : t('certSetup.howTlsWord', 'on port 443'); + const how = + method === 'dns' ? t('certSetup.howDnsWord', 'through DNS') : t('certSetup.howTlsWord', 'on port {{port}}', { port }); // ── Step 1: names (also where it goes back to if the domain stops fitting) ── if (step === 0 || !domain) { @@ -319,7 +327,8 @@ export function OrderCertificatePage() {

{t( 'certOrder.howDns', - 'When the domain’s DNS is connected, the names are checked through DNS, and wildcards work. Otherwise Let’s Encrypt connects to this server on port 443 for each name.', + 'When the domain’s DNS is connected, the names are checked through DNS, and wildcards work. Otherwise Let’s Encrypt connects to this server on port {{port}} for each name.', + { port }, )}

@@ -371,7 +380,7 @@ export function OrderCertificatePage() {

{method === 'dns' ? t('certSetup.viaDns', 'Checked through DNS.') - : t('certSetup.viaTls', 'Checked on port 443.')} + : t('certSetup.viaTls', 'Checked on port {{port}}.', { port })}

{wildcardBlocked && ( @@ -575,6 +584,7 @@ export function OrderCertificatePage() { } > + {method === 'tls' && } {provider ? (

{t('certSetup.reuse', 'The Let’s Encrypt account already set up on this server will be used.')} diff --git a/src/features/certificates/shared.test.ts b/src/features/certificates/shared.test.ts new file mode 100644 index 0000000..7aacf33 --- /dev/null +++ b/src/features/certificates/shared.test.ts @@ -0,0 +1,42 @@ +/* + * SPDX-FileCopyrightText: 2026 Coffey Labs LLC + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { describe, expect, it } from 'vitest'; +import { challengeOf, defaultDirect, LE_PRODUCTION, LE_STAGING, PORT, providerFor, type ProviderRow } from './shared'; + +const row = (id: string, challengeType: string, directory = LE_PRODUCTION): ProviderRow => ({ + id, + directory, + challengeType, + contact: [], +}); + +describe('certificate accounts (#206)', () => { + it('prefers port 80 when the server has an HTTP-01 account, as an installer setup does', () => { + expect(defaultDirect([row('a', 'Http01')])).toBe('Http01'); + expect(defaultDirect([row('a', 'TlsAlpn01'), row('b', 'Http01', LE_STAGING)])).toBe('Http01'); + expect(defaultDirect([row('a', 'TlsAlpn01'), row('b', 'Dns01')])).toBe('TlsAlpn01'); + expect(defaultDirect([])).toBe('TlsAlpn01'); + expect(PORT.Http01).toBe(80); + expect(PORT.TlsAlpn01).toBe(443); + }); + + it('reuses the installer’s HTTP-01 account instead of adding one', () => { + const providers = [row('installer', 'Http01'), row('dns', 'Dns01')]; + expect(providerFor(providers, LE_PRODUCTION, 'tls', 'Http01')?.id).toBe('installer'); + expect(providerFor(providers, LE_PRODUCTION, 'dns', 'Http01')?.id).toBe('dns'); + // Port 443 picked: an HTTP-01 account doesn't do, so one is added. + expect(providerFor(providers, LE_PRODUCTION, 'tls', 'TlsAlpn01')).toBeUndefined(); + // Staging is its own account. + expect(providerFor(providers, LE_STAGING, 'tls', 'Http01')).toBeUndefined(); + }); + + it('asks for the challenge that matches the way names are checked', () => { + expect(challengeOf('dns', 'Http01')).toBe('Dns01'); + expect(challengeOf('tls', 'Http01')).toBe('Http01'); + expect(challengeOf('tls', 'TlsAlpn01')).toBe('TlsAlpn01'); + }); +}); diff --git a/src/features/certificates/shared.ts b/src/features/certificates/shared.ts index 61e8d52..ea7e71a 100644 --- a/src/features/certificates/shared.ts +++ b/src/features/certificates/shared.ts @@ -14,7 +14,37 @@ import type { Method, NameState } from './names'; export const LE_PRODUCTION = 'https://acme-v02.api.letsencrypt.org/directory'; export const LE_STAGING = 'https://acme-staging-v02.api.letsencrypt.org/directory'; -export const CHALLENGE: Record = { dns: 'Dns01', tls: 'TlsAlpn01' }; + +/** + * How Let’s Encrypt reaches this server for names checked without DNS: + * HTTP-01 on port 80, or TLS-ALPN-01 on port 443. The server answers either. + * Behind a web server that holds 443, only HTTP-01 works: the installer's + * Caddy forwards /.well-known/acme-challenge/ on port 80 to the server, and + * the installer makes an HTTP-01 account for it (#206). + */ +export type Direct = 'Http01' | 'TlsAlpn01'; + +export const PORT: Record = { Http01: 80, TlsAlpn01: 443 }; + +/** HTTP-01 when the server already has an account for it, as an installer setup does; otherwise TLS-ALPN-01. */ +export function defaultDirect(providers: ProviderRow[]): Direct { + return providers.some((p) => p.challengeType === 'Http01') ? 'Http01' : 'TlsAlpn01'; +} + +/** The challenge type an account needs for one way of checking names. */ +export function challengeOf(method: Method, direct: Direct): string { + return method === 'dns' ? 'Dns01' : direct; +} + +/** The existing Let’s Encrypt account for one way of checking names, if there is one. */ +export function providerFor( + providers: ProviderRow[], + directory: string, + method: Method, + direct: Direct, +): ProviderRow | undefined { + return providers.find((p) => p.directory === directory && p.challengeType === challengeOf(method, direct)); +} export interface DomainRow { id: string; @@ -163,12 +193,17 @@ export async function pollOrders(): Promise<{ certs: CertRow[]; tasks: Record { +export async function addProvider( + method: Method, + direct: Direct, + contact: string, + staging: boolean, +): Promise { const [res] = await jmapSet('x:AcmeProvider', getAccountId('x:AcmeProvider'), { create: { acme: { directory: staging ? LE_STAGING : LE_PRODUCTION, - challengeType: CHALLENGE[method], + challengeType: challengeOf(method, direct), contact: { [contact.trim()]: true }, }, }, diff --git a/src/i18n/en.json b/src/i18n/en.json index 0423944..377131e 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -659,7 +659,7 @@ "subtitle": "Free certificates from Let’s Encrypt for your domains, renewed by the server before they expire.", "howTitle": "How the server proves it’s yours", "howDns": "A domain whose DNS is connected is checked through DNS: the certificate covers the domain and everything under it (*.domain), and nothing needs to reach this server.", - "howTls": "Otherwise Let’s Encrypt connects to this server on port 443 for each name. Those names must point straight at this server, not through a proxy.", + "howTls": "Otherwise Let’s Encrypt connects to this server on port {{port}} for each name. Those names must point straight at this server, not through a proxy.", "noDomains": "There are no domains yet.", "addDomain": "Add one first", "alreadyAuto": "Already automatic.", @@ -667,7 +667,7 @@ "validUntil": "Current certificate valid until {{date}}.", "noCert": "No certificate yet.", "viaDns": "Checked through DNS.", - "viaTls": "Checked on port 443.", + "viaTls": "Checked on port {{port}}.", "checkedWith": "How this is checked", "checkedHow": "Each name is looked up in public DNS through {{resolver}}, and compared with where {{server}} points. Nothing is ordered yet.", "thisServer": "this server", @@ -701,7 +701,7 @@ "stagingWord": "staging ", "domainAuto": "{{domain}} gets its certificate automatically, checked {{how}}: {{names}}.", "howDnsWord": "through DNS", - "howTlsWord": "on port 443", + "howTlsWord": "on port {{port}}", "skipped": "Left as they are until their names are fixed: {{names}}.", "issued": "Issued. Valid until {{date}}.", "failed": "Failed.", @@ -712,7 +712,12 @@ "after": "The server renews each certificate well before it expires. Failed renewals show under Management › Tasks › Failed.", "keepWatching": "Keep watching", "watchingHint": "Checking every few seconds. Most certificates arrive within a minute.", - "tabTitle": "Certificates" + "tabTitle": "Certificates", + "directTitle": "How Let’s Encrypt reaches this server", + "directHttp": "Port 80 (HTTP-01)", + "directHttpHint": "A web server in front of this one holds port 443 and passes /.well-known/acme-challenge/ on port 80 to it. The installer sets it up this way.", + "directTls": "Port 443 (TLS-ALPN-01)", + "directTlsHint": "This server answers HTTPS on port 443 itself." }, "overview": { "first": "First record", @@ -2718,7 +2723,7 @@ "subtitle": "A free Let’s Encrypt certificate for the names you choose, renewed by the server before it expires.", "oneDomainTitle": "One certificate per domain", "oneDomain": "The server orders each certificate for a domain, and renews it for as long as the domain says so. The names you enter become that domain’s certificate hostnames.", - "howDns": "When the domain’s DNS is connected, the names are checked through DNS, and wildcards work. Otherwise Let’s Encrypt connects to this server on port 443 for each name.", + "howDns": "When the domain’s DNS is connected, the names are checked through DNS, and wildcards work. Otherwise Let’s Encrypt connects to this server on port {{port}} for each name.", "namesLabel": "Names the certificate covers", "namesHint": "One per line. A wildcard (*.example.com) covers every name one level under it.", "invalid": "Not a name a certificate can cover: {{names}}", -- 2.54.0