Merge pull request #42 from D-Modem/claude/project-thread-xv85ad

Add an ACME client: Let's Encrypt and ZeroSSL certificates for every TLS server
This commit is contained in:
Neo authored and GitHub committed 2026-11-09 02:39:54 -08:00
commit db1f6c1ae8
44 files changed
+2768 -130

No files matched your search

+1
View File
@@ -36,6 +36,7 @@ Main menu
- Terminals: ANSI, VT, PETSCII, RIPscrip, sixel and 3270 graphics
- On the web: a forum, image boards, a web terminal and an HTTP API
- Time: follows NTP, NTS and PTP servers, and serves all three
- Certificates: its own ACME client gets and renews them from Let's Encrypt, ZeroSSL and others, for every TLS server
- SQLite, PostgreSQL, MySQL or MariaDB
The full list is on the [wiki's home page](https://github.com/D-Modem/bbs/wiki/Home).
+77 -5
View File
@@ -200,6 +200,73 @@ throttle_time = 600
; keys alone)
;files = yes
; Certificates from Let's Encrypt, ZeroSSL or any ACME CA, got and renewed
; by the BBS itself (in the manner of acme.sh), for every TLS server here:
; one given no cert_file (or tls_cert) and key_file uses them, the one whose
; names cover the name the client asks for, or the first. cert_file = acme
; says so outright; cert_file = acme:NAME picks an [acme NAME]. Gemini
; (its pinned certificate) and Yahoo! Messenger (login.yahoo.com's) keep
; their own unless told. They are kept in acme/
; beside the database, renewed 30 days before they run out (or when the CA
; says), and read again by every server as they change. bbs acme list
; shows them; bbs acme renew gets them now. See docs/wiki/Certificates.md
;[acme]
; the account's contact: the CA writes here of a certificate not renewed
;email = sysop@example.org
; letsencrypt, letsencrypt-staging (for trying it out), zerossl, buypass,
; google, sslcom, or a directory's URL
;ca = letsencrypt
; External Account Binding, for CAs that need it (Google's; ZeroSSL's is got
; by email if not given)
;eab_kid = kid-from-the-ca
;eab_hmac_key = base64url-key
; the names of [acme]'s own certificate (named default); more in [acme NAME]
;domains = bbs.example.org, www.bbs.example.org
; how the CA is shown the names are this host's: http (a token on port 80),
; tls-alpn (a certificate on port 443, from any TLS server of the BBS's
; there) or dns (a TXT record; the only one for *.wildcards)
;challenge = http
; HTTP-01's port 80 (by default :80 when a certificate uses it, unless a web
; server here is on port 80 already, which answers it then; no: none)
;http_address = :80
; DNS-01's provider: cloudflare, route53, digitalocean, hetzner, gandiv5,
; ovh, namecheap, porkbun, godaddy, desec, duckdns, pdns, rfc2136, acme-dns,
; httpreq; exec:PROGRAM (run as PROGRAM present|cleanup NAME VALUE); or
; acmesh:dns_xx, one of acme.sh's 150 dnsapi scripts (needs acmesh)
;dns = cloudflare
; KEY=value lines: the provider's credentials, as lego names them for its
; providers (CF_DNS_API_TOKEN=...) or acme.sh for its (CF_Token=...)
;dns_env_file = /etc/bbs/acme-dns.env
; acme.sh, for dns = acmesh:..., and its home if not beside it (where its
; account.conf keeps the credentials it saved)
;acmesh = /home/bbs/.acme.sh/acme.sh
;acmesh_home = /home/bbs/.acme.sh
; DNS servers asked whether the record is out yet (default: the system's)
;dns_resolvers = 1.1.1.1:53, 8.8.8.8:53
; how: authoritative (the zone's own servers), resolvers (dns_resolvers) or
; no (just wait dns_wait seconds, as acme.sh's --dnssleep)
;dns_check = authoritative
;dns_wait = 0
; the key: ec256, ec384, rsa2048, rsa3072 or rsa4096 (Windows XP's clients
; know only RSA)
;key_type = ec256
; renew this many days before the end
;renew_days = 30
; run (by sh) after each new certificate, with CERT_NAME, CERT_FILE,
; KEY_FILE and CERT_DOMAINS set: to hand it to other programs
;hook = systemctl reload nginx
; where the account and certificates are kept (default acme/ beside the
; database)
;dir = /var/lib/bbs/acme
; a certificate of its own, for a TLS server to name (cert_file =
; acme:mail); challenge, dns and key_type as in [acme], whose they are by
; default
;[acme mail]
;domains = mail.example.org, imap.example.org, smtp.example.org
;challenge = tls-alpn
;key_type = ec256
; telnet and TN3270, for everyone (port 23 needs root or
; CAP_NET_BIND_SERVICE)
[listen telnet]
@@ -208,7 +275,8 @@ address = :2300
tn3270 = yes
max_per_ip = 4
; telnet over TLS (port 992), for SyncTERM (TelnetS), c3270 L:host:992
; telnet over TLS (port 992), for SyncTERM (TelnetS), c3270 L:host:992;
; tls_cert = acme for the [acme] certificate
;[listen telnets]
;type = telnet
;address = :992
@@ -286,7 +354,8 @@ address = 127.0.0.1:2513
; bbs token add USER -scope read,post. Without this section there is none
;[http]
;address = :8443
; TLS is the default; tls = no only on 127.0.0.1 behind a proxy that has it
; TLS is the default; tls = no only on 127.0.0.1 behind a proxy that has it.
; With no cert_file and key_file, the [acme] certificates
;cert_file = /etc/bbs/tls/cert.pem
;key_file = /etc/bbs/tls/key.pem
; behind a reverse proxy (nginx, Caddy): its addresses (or ranges), which
@@ -720,7 +789,8 @@ address = 127.0.0.1:2513
; password as name:password). See docs/wiki/IRC.md
;[irc]
;address = :6667
; IRC over TLS (and address = none for TLS only)
; IRC over TLS (and address = none for TLS only); with no tls_cert and
; tls_key, the [acme] certificates
;tls_address = :6697
;tls_cert = /etc/bbs/tls.crt
;tls_key = /etc/bbs/tls.key
@@ -914,7 +984,8 @@ address = 127.0.0.1:2513
; the certificate and key (PEM); with neither, gemini-cert.pem and
; gemini-key.pem beside the database, which bbs gemini cert makes (it asks
; for the host names, organization and years first). Clients trust it on
; first use and warn if it ever changes
; first use and warn if it ever changes, so an ACME one (cert_file = acme)
; is for capsules whose visitors check it against a CA
;cert_file = /etc/bbs/gemini-cert.pem
;key_file = /etc/bbs/gemini-key.pem
; message areas shown (a wildmat of area names; "": none)
@@ -955,7 +1026,8 @@ address = 127.0.0.1:2513
; an NTS-KE server (RFC 8915): TLS 1.3, its clients' keys and cookies for
; [ntp], which then answers NTS-secured requests too. The certificate is
; read again when its file changes (a renewal)
; read again when its file changes (a renewal); with no tls_cert and
; tls_key, the [acme] certificates
;[nts]
;address = :4460
;tls_cert = /etc/bbs/cert.pem
+130
View File
@@ -0,0 +1,130 @@
package main
import (
"context"
"errors"
"flag"
"fmt"
"io"
"log"
"net/http"
"os"
"os/signal"
"slices"
"strings"
"syscall"
"time"
"github.com/D-Modem/bbs/internal/acme"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/server"
"github.com/D-Modem/bbs/internal/sockets"
)
// acmeCmd is bbs acme: list shows the ACME client's certificates, renew
// gets them now (those due, or -force all, or those named).
func acmeCmd(cfg *server.Config, args []string) {
if cfg.ACME == nil {
fatal(errors.New("no [acme] section in the configuration"))
}
if len(args) == 0 {
args = []string{"list"}
}
lg := log.New(os.Stderr, "", 0)
m, err := acme.New(*cfg.ACME, lg)
if err != nil {
fatal(err)
}
switch args[0] {
case "list":
acmeList(m, os.Stdout)
case "renew":
fs := flag.NewFlagSet("acme renew", flag.ExitOnError)
force := fs.Bool("force", false, "get them even if they are not due")
fs.Parse(args[1:])
if err := acmeRenew(m, *force, fs.Args()); err != nil {
fatal(err)
}
default:
usage()
}
}
// acmeList prints each certificate: its names, how it is proved, and how
// long it has.
func acmeList(m *acme.Manager, w io.Writer) {
fmt.Fprintf(w, "CA %s, account %s\n", m.S.CA, or(m.S.Email, "(no email)"))
for _, st := range m.Status() {
how := st.Challenge
if how == acme.DNS01 {
how += " (" + st.DNS + ")"
}
fmt.Fprintf(w, "%s: %s, by %s, key %s\n", st.Name, strings.Join(st.Domains, ", "), how, st.KeyType)
if st.Have {
fmt.Fprintf(w, " from %s until %s (%d days)\n", st.Issuer, st.NotAfter.Format(time.DateOnly),
int(time.Until(st.NotAfter).Hours()/24))
}
if st.Due {
fmt.Fprintf(w, " due: %s\n", st.Why)
}
fmt.Fprintf(w, " %s, %s\n", st.CertFile, st.KeyFile)
}
}
// acmeRenew gets certificates now. HTTP-01 is answered on http_address
// (or :80) while it runs, or, with that port bbs serve's, by bbs serve:
// the challenges are put in the acme directory for it, TLS-ALPN-01's
// too. A running bbs serve reads what it gets within a minute.
func acmeRenew(m *acme.Manager, force bool, names []string) error {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer stop()
certs.SetManager(m)
for _, n := range names {
if !m.Has(n) {
return fmt.Errorf("no certificate %s (%s)", n, strings.Join(m.S.Names(), ", "))
}
}
http01 := false
for _, c := range m.S.Certs {
http01 = http01 || c.Challenge == acme.HTTP01
}
if http01 {
addr := or(m.S.HTTPAddress, ":80")
ln, err := sockets.Listen("tcp", addr)
if err != nil {
// a running bbs serve answers for this process (the
// challenges go through the acme directory)
fmt.Fprintf(os.Stderr, "bbs: %s is in use, so HTTP-01 is left to bbs serve (%v)\n", addr, err)
} else {
hs := &http.Server{Handler: m, ReadHeaderTimeout: 10 * time.Second}
go hs.Serve(ln)
defer hs.Close()
}
}
failed := 0
for _, c := range m.S.Certs {
if len(names) > 0 && !slices.Contains(names, c.Name) {
continue
}
due, why := m.Due(c.Name)
if !due && !force && len(names) == 0 {
fmt.Printf("%s: not due\n", c.Name)
continue
}
if why == "" {
why = "asked for"
}
fmt.Printf("%s: getting a certificate for %s (%s)\n", c.Name, strings.Join(c.Domains, ", "), why)
if err := m.Obtain(ctx, c.Name); err != nil {
fmt.Fprintf(os.Stderr, "bbs: %s: %v\n", c.Name, err)
failed++
continue
}
crt, _ := m.Files(c.Name)
fmt.Printf("%s: got it: %s\n", c.Name, crt)
}
if failed > 0 {
return fmt.Errorf("%d certificate(s) not got", failed)
}
return nil
}
+33 -1
View File
@@ -60,9 +60,11 @@ import (
"golang.org/x/term"
"github.com/D-Modem/bbs/internal/acme"
"github.com/D-Modem/bbs/internal/aol"
"github.com/D-Modem/bbs/internal/api"
"github.com/D-Modem/bbs/internal/bbs"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/email"
"github.com/D-Modem/bbs/internal/events"
"github.com/D-Modem/bbs/internal/fido"
@@ -167,6 +169,8 @@ func usage() {
bbs [-config FILE] chan ban list | del ID
bbs [-config FILE] gemini cert [-force] make the Gemini server's certificate (it asks
for host names, organization and years)
bbs [-config FILE] acme [list] the ACME client's certificates: names, expiry
bbs [-config FILE] acme renew [-force] [NAME...] get them now: those due, all (-force) or those named
`)
os.Exit(2)
}
@@ -327,7 +331,18 @@ func main() {
}
if g := cfg.Gemini; g != nil {
fmt.Printf("gemini: %s, areas %q, files %v, users %v\n", g.Address, g.Areas, g.Files, g.Users)
fmt.Printf("gemini certificate %s: %s\n", g.CertFile, gemini.CertInfo(g.CertFile))
if certs.IsACME(g.CertFile) {
fmt.Printf("gemini certificate: the ACME client's (%s)\n", g.CertFile)
} else {
fmt.Printf("gemini certificate %s: %s\n", g.CertFile, gemini.CertInfo(g.CertFile))
}
}
if a := cfg.ACME; a != nil {
if m, err := acme.New(*a, log.New(io.Discard, "", 0)); err != nil {
fmt.Printf("acme: %v\n", err)
} else {
acmeList(m, os.Stdout)
}
}
for _, d := range cfg.Doors {
if r := d.Remote; r != nil {
@@ -388,6 +403,8 @@ func main() {
chanCmd(cfg, args)
case "gemini":
geminiCmd(cfg, args)
case "acme":
acmeCmd(cfg, args)
default:
usage()
}
@@ -485,6 +502,21 @@ func serve(cfg *server.Config, path string) int {
}
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer stop()
if a := cfg.ACME; a != nil {
// first, so the TLS servers find the ACME client's certificates
am, err := acme.New(*a, lg)
if err != nil {
lg.Printf("%v", err)
return 1
}
certs.SetManager(am)
go func() {
if err := am.Run(ctx); err != nil {
lg.Printf("%v", err)
stop()
}
}()
}
svc := &nntp.Service{B: b, MaxArticle: int(cfg.MaxArticle)}
if cfg.NNTP != nil {
ns, err := nntp.NewServer(svc, *cfg.NNTP, cfg.Peers)
+194
View File
@@ -0,0 +1,194 @@
The BBS has its own ACME client, in the manner of acme.sh. It gets
certificates from Let's Encrypt, ZeroSSL or any other ACME CA, keeps them
beside the database, and renews them before they run out. Every TLS server
of the BBS can use them: the web server, mail (IMAP, POP3, SMTP), news,
FTP, IRC, IRC linking, NTS, telnet over TLS, and Gemini and Yahoo!
Messenger when told.
It is built on [lego](https://github.com/go-acme/lego) (MIT). It is off
unless there is an `[acme]` section.
## The short way
```
[acme]
email = sysop@example.org
domains = bbs.example.org, mail.example.org
[http]
address = :443
```
That is all a web server and mail server need. The CA checks the names
over HTTP on port 80, which the BBS answers itself. Any TLS server with no
`cert_file` and `key_file` (or `tls_cert` and `tls_key`) then uses the
certificate. The first is got at start-up, so the servers have none for
the few seconds that takes.
Port 80 and 443 need root (the BBS binds them before it gives root up,
with `user =`) or `CAP_NET_BIND_SERVICE`.
## Which certificate a server uses
| `cert_file` | the certificate |
|---|---|
| none, with `[acme]` | the ACME one whose names cover the name the client asks for (SNI), or the first |
| `acme` | the same, said outright (the way for `[listen]`'s `tls_cert`, for Gemini and for Yahoo) |
| `acme:NAME` | the `[acme NAME]` certificate |
| a path | that file, with `key_file` |
Files are read again when they change, whatever renews them. The ACME
client's are read again within a minute of each renewal, with no restart.
Two servers keep their own unless told:
- **Gemini** clients pin the certificate they first see, and an ACME
certificate gets a new key each renewal, so Gemini keeps the one `bbs
gemini cert` makes. Use `cert_file = acme` for a capsule whose visitors
check it against a CA.
- **Yahoo! Messenger**'s login is `login.yahoo.com`, a name no CA will
sign for this host. It still needs a certificate the client trusts.
## More than one certificate
`[acme]`'s own `domains` make the certificate named `default`. Each
`[acme NAME]` makes another, with its own `challenge`, `dns` and
`key_type` if they differ:
```
[acme]
email = sysop@example.org
domains = bbs.example.org
[acme mail]
domains = mail.example.org, imap.example.org, smtp.example.org
challenge = tls-alpn
[acme wild]
domains = *.example.org, example.org
challenge = dns
dns = cloudflare
dns_env_file = /etc/bbs/acme-dns.env
[irc]
tls_address = :6697
tls_cert = acme:wild
```
## Challenges
How the CA is shown the names are this host's:
- **`http`** (the default): a token at
`http://NAME/.well-known/acme-challenge/`. A plain web server of the
BBS's already on port 80 (`[http]` with `tls = no`, or `[ymsg]`'s
`http_address`) answers it. Otherwise the client listens on
`http_address`, `:80` by default.
- **`tls-alpn`**: a certificate on port 443, from whichever TLS server of
the BBS is there. Nothing has to listen on port 80.
- **`dns`**: a TXT record at `_acme-challenge.NAME`. This is the only one
for `*.wildcards`, and the one for a BBS behind a firewall. `dns` names
how the record is made.
## DNS providers
`dns =` is one of:
- A provider built in: `cloudflare`, `route53`, `digitalocean`, `hetzner`,
`gandiv5`, `ovh`, `namecheap`, `porkbun`, `godaddy`, `desec`, `duckdns`,
`pdns` (PowerDNS), `rfc2136` (BIND and the like, by TSIG), `acme-dns`
and `httpreq`. Their credentials are lego's environment variables, such
as `CF_DNS_API_TOKEN` for Cloudflare. See
[lego's DNS providers](https://go-acme.github.io/lego/dns/).
- **`acmesh:dns_xx`**: one of acme.sh's 150 or so
[dnsapi scripts](https://github.com/acmesh-official/acme.sh/wiki/dnsapi),
run with acme.sh's own functions loaded. Set `acmesh` to acme.sh's path.
Their credentials are acme.sh's variables (`CF_Token`, `GD_Key`...), and
those acme.sh saved in its `account.conf` work too.
- **`exec:PROGRAM`**: a program of the sysop's, run as `PROGRAM present
_acme-challenge.NAME. VALUE` and then `PROGRAM cleanup ...`.
Credentials go in the environment (systemd's `Environment=` or
`EnvironmentFile=`) or in `dns_env_file`, `KEY=value` lines kept out of
`bbs.conf`:
```
# /etc/bbs/acme-dns.env, mode 0600, the BBS user's
CF_DNS_API_TOKEN=...
```
The client waits for the record to be out before the CA looks:
- `dns_check = authoritative` (the default) asks the zone's own servers.
- `dns_check = resolvers` asks `dns_resolvers`.
- `dns_check = no` only waits `dns_wait` seconds, like acme.sh's
`--dnssleep`.
## CAs
`ca =` is `letsencrypt` (the default), `letsencrypt-staging` (for trying
it out: it has much higher limits, and its certificates are not trusted),
`zerossl`, `buypass`, `google`, `sslcom`, or a directory's URL.
ZeroSSL and Google need External Account Binding: `eab_kid` and
`eab_hmac_key` from the CA. For ZeroSSL, as with acme.sh, an `email` is
enough: the client gets the binding for it.
The account is made when first needed, agreeing to the CA's terms. It is
kept under `acme/accounts/` with the CA's host name.
## Renewal
A certificate is got again when:
- it has `renew_days` (30) or fewer days left,
- the CA's renewal information (ARI) says to,
- or its `domains` or `key_type` have changed.
The client looks every 12 hours, and an hour after a failure. After each
new certificate, `hook` is run (by `sh`) with `CERT_NAME`, `CERT_FILE`,
`KEY_FILE` and `CERT_DOMAINS` set, to hand it to other programs:
```
hook = cp "$CERT_FILE" /etc/nginx/bbs.crt && cp "$KEY_FILE" /etc/nginx/bbs.key && systemctl reload nginx
```
## Files
Under `acme/` beside the database (or `dir`):
| path | what |
|---|---|
| `certs/NAME.crt` | the certificate and its chain (PEM) |
| `certs/NAME.key` | its key (PEM, mode 0600) |
| `accounts/HOST/` | the account at that CA: its key and registration |
| `challenges/` | challenges being answered for `bbs acme renew` |
Other programs can use the certificates from `certs/`.
## Commands
```
bbs acme list the certificates: names, challenge, CA, expiry, files
bbs acme renew get the ones due now
bbs acme renew -force get them all now
bbs acme renew NAME... get these now
```
`bbs check` lists them too.
`bbs acme renew` can run while `bbs serve` does. When `bbs serve` holds
port 80 or 443, it answers that renewal's challenges itself: they are put
in `acme/challenges/` for it. `bbs serve` reads the new certificate within
a minute.
## Trying it out
Use `ca = letsencrypt-staging` until a certificate comes, then remove it.
Let's Encrypt's production limits are tight for repeated failures.
To try it with no public name at all, run
[Pebble](https://github.com/letsencrypt/pebble), Let's Encrypt's test CA,
with `ca = https://localhost:14000/dir` and
`LEGO_CA_CERTIFICATES=pebble.minica.pem` in the environment so the client
trusts it.
+41 -12
View File
@@ -17,6 +17,7 @@ the file is laid out.
| [`[security]`](#security) | keeping callers out: a file of addresses and networks refused, one of names no new user may take (* wildcards), the hack log, and how long an address throttled for failed logins is banned outright. |
| [`[event NAME]`](#event-name) | scheduled events: a program (no shell), daily at a time or every N minutes; see the wiki's Sysop tools. |
| [`[backup]`](#backup) | Backups: this file, the database (a SQLite file, whatever the engine, taken whole at one moment while callers are on) and the files' directories (file areas, image boards, FidoNet, screens, scripts), one archive (bbs-YYYYMMDD-HHMMSS.tar.gz) a backup. |
| [`[acme NAME]`](#acme-name) | Certificates from Let's Encrypt, ZeroSSL or any ACME CA, got and renewed by the BBS itself (in the manner of acme.sh), for every TLS server here: one given no cert_file (or tls_cert) and key_file uses them, the one whose names cover the name the client asks for, or the first. |
| [`[modemmenu]`](#modemmenu) | modemmenu's auth socket ([authd] there): the accounts modemmenu logs in (no password here) log in by telnet, SSH, the web ... |
| [`[http]`](#http) | The HTTP API (REST, server-sent events, and WebSockets in JSON and protobuf): see docs/wiki/HTTP-API.md. |
| [`[chan]`](#chan) | How the image boards are run. |
@@ -175,6 +176,34 @@ Backups: this file, the database (a SQLite file, whatever the engine, taken whol
| `files` | | yes | the files' directories too (no: the configuration, database and SSH host keys alone) Examples: `yes`. |
## `[acme NAME]`
Certificates from Let's Encrypt, ZeroSSL or any ACME CA, got and renewed by the BBS itself (in the manner of acme.sh), for every TLS server here: one given no cert_file (or tls_cert) and key_file uses them, the one whose names cover the name the client asks for, or the first. cert_file = acme says so outright; cert_file = acme:NAME picks an [acme NAME]. Gemini (its pinned certificate) and Yahoo! Messenger (login.yahoo.com's) keep their own unless told. They are kept in acme/ beside the database, renewed 30 days before they run out (or when the CA says), and read again by every server as they change. bbs acme list shows them; bbs acme renew gets them now. See docs/wiki/Certificates.md.
There may be any number of these, each with its own NAME.
| key | default | live | what it does |
|---|---|---|---|
| `email` | | | the account's contact: the CA writes here of a certificate not renewed. Examples: `sysop@example.org`. |
| `ca` | | | letsencrypt, letsencrypt-staging (for trying it out), zerossl, buypass, google, sslcom, or a directory's URL. Examples: `letsencrypt`. |
| `eab_kid` | | | External Account Binding, for CAs that need it (Google's; ZeroSSL's is got by email if not given) Examples: `kid-from-the-ca`. |
| `eab_hmac_key` | | | External Account Binding, for CAs that need it (Google's; ZeroSSL's is got by email if not given) Examples: `base64url-key`. |
| `domains` | | | the names of [acme]'s own certificate (named default); more in [acme NAME]. Examples: `bbs.example.org, www.bbs.example.org`, `mail.example.org, imap.example.org, smtp.example.org`. |
| `challenge` | | | how the CA is shown the names are this host's: http (a token on port 80), tls-alpn (a certificate on port 443, from any TLS server of the BBS's there) or dns (a TXT record; the only one for *.wildcards) Examples: `http`, `tls-alpn`. |
| `http_address` | | | HTTP-01's port 80 (by default :80 when a certificate uses it, unless a web server here is on port 80 already, which answers it then; no: none) Examples: `:80`. |
| `dns` | | | DNS-01's provider: cloudflare, route53, digitalocean, hetzner, gandiv5, ovh, namecheap, porkbun, godaddy, desec, duckdns, pdns, rfc2136, acme-dns, httpreq; exec:PROGRAM (run as PROGRAM present\|cleanup NAME VALUE); or acmesh:dns_xx, one of acme.sh's 150 dnsapi scripts (needs acmesh) Examples: `cloudflare`. |
| `dns_env_file` | | | KEY=value lines: the provider's credentials, as lego names them for its providers (CF_DNS_API_TOKEN=...) or acme.sh for its (CF_Token=...) Examples: `/etc/bbs/acme-dns.env`. |
| `acmesh` | | | acme.sh, for dns = acmesh:..., and its home if not beside it (where its account.conf keeps the credentials it saved) Examples: `/home/bbs/.acme.sh/acme.sh`. |
| `acmesh_home` | | | acme.sh, for dns = acmesh:..., and its home if not beside it (where its account.conf keeps the credentials it saved) Examples: `/home/bbs/.acme.sh`. |
| `dns_resolvers` | | | DNS servers asked whether the record is out yet (default: the system's) Examples: `1.1.1.1:53, 8.8.8.8:53`. |
| `dns_check` | | | how: authoritative (the zone's own servers), resolvers (dns_resolvers) or no (just wait dns_wait seconds, as acme.sh's --dnssleep) Examples: `authoritative`. |
| `dns_wait` | | | how: authoritative (the zone's own servers), resolvers (dns_resolvers) or no (just wait dns_wait seconds, as acme.sh's --dnssleep) Examples: `0`. |
| `key_type` | | | the key: ec256, ec384, rsa2048, rsa3072 or rsa4096 (Windows XP's clients know only RSA) Examples: `ec256`. |
| `renew_days` | | | renew this many days before the end. Examples: `30`. |
| `hook` | | | run (by sh) after each new certificate, with CERT_NAME, CERT_FILE, KEY_FILE and CERT_DOMAINS set: to hand it to other programs. Examples: `systemctl reload nginx`. |
| `dir` | | | where the account and certificates are kept (default acme/ beside the database) Examples: `/var/lib/bbs/acme`. |
## `[modemmenu]`
modemmenu's auth socket ([authd] there): the accounts modemmenu logs in (no password here) log in by telnet, SSH, the web ... with their modemmenu password, asked of modemmenu's backends. See docs/wiki/Modem-Callers.md.
@@ -193,8 +222,8 @@ The HTTP API (REST, server-sent events, and WebSockets in JSON and protobuf): se
| key | default | live | what it does |
|---|---|---|---|
| `address` | | | See the section above. Examples: `:8443`. |
| `cert_file` | | | TLS is the default; tls = no only on 127.0.0.1 behind a proxy that has it. Examples: `/etc/bbs/tls/cert.pem`. |
| `key_file` | | | TLS is the default; tls = no only on 127.0.0.1 behind a proxy that has it. Examples: `/etc/bbs/tls/key.pem`. |
| `cert_file` | | | TLS is the default; tls = no only on 127.0.0.1 behind a proxy that has it. With no cert_file and key_file, the [acme] certificates. Examples: `/etc/bbs/tls/cert.pem`. |
| `key_file` | | | TLS is the default; tls = no only on 127.0.0.1 behind a proxy that has it. With no cert_file and key_file, the [acme] certificates. Examples: `/etc/bbs/tls/key.pem`. |
| `trusted_proxies` | | | behind a reverse proxy (nginx, Caddy): its addresses (or ranges), which are believed when they say whose a request is (X-Forwarded-For, Forwarded, X-Real-IP), for rate limits, logs, bans and the deny lists. secure_cookies: logins' cookies over HTTPS only (the default with tls = yes; say yes when the proxy has TLS) Examples: `127.0.0.1, ::1`. |
| `secure_cookies` | | | behind a reverse proxy (nginx, Caddy): its addresses (or ranges), which are believed when they say whose a request is (X-Forwarded-For, Forwarded, X-Real-IP), for rate limits, logs, bans and the deny lists. secure_cookies: logins' cookies over HTTPS only (the default with tls = yes; say yes when the proxy has TLS) Examples: `yes`. |
| `anonymous` | | | anonymous callers may see /system and /who. Examples: `yes`. |
@@ -528,13 +557,13 @@ IRC: the chat rooms as channels (#main ...), for IRC clients. Users log in with
| key | default | live | what it does |
|---|---|---|---|
| `address` | | | See the section above. Examples: `:6667`. |
| `tls_address` | | | IRC over TLS (and address = none for TLS only) Examples: `:6697`. |
| `tls_cert` | | | IRC over TLS (and address = none for TLS only) Examples: `/etc/bbs/tls.crt`. |
| `tls_key` | | | IRC over TLS (and address = none for TLS only) Examples: `/etc/bbs/tls.key`. |
| `server_name` | | | IRC over TLS (and address = none for TLS only) Examples: `irc.example.org`. |
| `network` | | | IRC over TLS (and address = none for TLS only) Examples: `DModem`. |
| `max_clients` | | | IRC over TLS (and address = none for TLS only) Examples: `64`. |
| `max_per_ip` | | | IRC over TLS (and address = none for TLS only) Examples: `4`. |
| `tls_address` | | | IRC over TLS (and address = none for TLS only); with no tls_cert and tls_key, the [acme] certificates. Examples: `:6697`. |
| `tls_cert` | | | IRC over TLS (and address = none for TLS only); with no tls_cert and tls_key, the [acme] certificates. Examples: `/etc/bbs/tls.crt`. |
| `tls_key` | | | IRC over TLS (and address = none for TLS only); with no tls_cert and tls_key, the [acme] certificates. Examples: `/etc/bbs/tls.key`. |
| `server_name` | | | IRC over TLS (and address = none for TLS only); with no tls_cert and tls_key, the [acme] certificates. Examples: `irc.example.org`. |
| `network` | | | IRC over TLS (and address = none for TLS only); with no tls_cert and tls_key, the [acme] certificates. Examples: `DModem`. |
| `max_clients` | | | IRC over TLS (and address = none for TLS only); with no tls_cert and tls_key, the [acme] certificates. Examples: `64`. |
| `max_per_ip` | | | IRC over TLS (and address = none for TLS only); with no tls_cert and tls_key, the [acme] certificates. Examples: `4`. |
| `service` | | | the services bot's nick: /msg BBSServ HELP (your account's settings) Examples: `BBSServ`. |
@@ -693,8 +722,8 @@ gemini: gopher's capsule over Gemini (gemini://, TLS): about the system, who is
|---|---|---|---|
| `address` | | | See the section above. Examples: `:1965`. |
| `hostname` | | | the host name bbs gemini cert offers for a new certificate. Examples: `bbs.example.org`. |
| `cert_file` | | | the certificate and key (PEM); with neither, gemini-cert.pem and gemini-key.pem beside the database, which bbs gemini cert makes (it asks for the host names, organization and years first). Clients trust it on first use and warn if it ever changes. Examples: `/etc/bbs/gemini-cert.pem`. |
| `key_file` | | | the certificate and key (PEM); with neither, gemini-cert.pem and gemini-key.pem beside the database, which bbs gemini cert makes (it asks for the host names, organization and years first). Clients trust it on first use and warn if it ever changes. Examples: `/etc/bbs/gemini-key.pem`. |
| `cert_file` | | | the certificate and key (PEM); with neither, gemini-cert.pem and gemini-key.pem beside the database, which bbs gemini cert makes (it asks for the host names, organization and years first). Clients trust it on first use and warn if it ever changes, so an ACME one (cert_file = acme) is for capsules whose visitors check it against a CA. Examples: `/etc/bbs/gemini-cert.pem`. |
| `key_file` | | | the certificate and key (PEM); with neither, gemini-cert.pem and gemini-key.pem beside the database, which bbs gemini cert makes (it asks for the host names, organization and years first). Clients trust it on first use and warn if it ever changes, so an ACME one (cert_file = acme) is for capsules whose visitors check it against a CA. Examples: `/etc/bbs/gemini-key.pem`. |
| `areas` | | | message areas shown (a wildmat of area names; "": none) Examples: `general,announcements`. |
| `files` | | | file areas listed and downloadable. Examples: `no`. |
| `users` | | | /users: look up a user, as finger tells of them. Examples: `yes`. |
@@ -728,7 +757,7 @@ an NTP server (UDP). Port 123 needs CAP_NET_BIND_SERVICE.
## `[nts]`
an NTS-KE server (RFC 8915): TLS 1.3, its clients' keys and cookies for [ntp], which then answers NTS-secured requests too. The certificate is read again when its file changes (a renewal)
an NTS-KE server (RFC 8915): TLS 1.3, its clients' keys and cookies for [ntp], which then answers NTS-secured requests too. The certificate is read again when its file changes (a renewal); with no tls_cert and tls_key, the [acme] certificates.
| key | default | live | what it does |
|---|---|---|---|
+4 -2
View File
@@ -105,8 +105,9 @@ which is generated from `bbs.conf.sample`.
prompts, and [scripting](Scripting) in JavaScript
- [SQLite, PostgreSQL, MySQL or MariaDB](Databases), with `bbs db copy`
between them
- [Backups](Backups) while callers are on, and [security](Security)
settings to keep callers out
- [Backups](Backups) while callers are on, [security](Security)
settings to keep callers out, and [certificates](Certificates) from
Let's Encrypt and other ACME CAs, got and renewed
## All pages
@@ -153,6 +154,7 @@ which is generated from `bbs.conf.sample`.
| [Image boards](Image-Boards) | anonymous image boards, in the style of kusaba x and 4chan |
| [HTTP API](HTTP-API) | REST, events, WebSockets in JSON and protobuf, tokens, metrics |
| [Security](Security) | what is guarded, and how |
| [Certificates](Certificates) | the ACME client: Let's Encrypt and ZeroSSL certificates for every TLS server, renewed |
| [Development](Development) | the source's layout, the shared screens, the tests |
## More
+8 -1
View File
@@ -143,7 +143,14 @@ tls_key = /etc/bbs/key.pem
A telnet or raw listener with `tls_cert` and `tls_key` accepts TLS (1.2 or
later) and then telnet (or TN3270) as usual. SyncTERM (TelnetS) and
`c3270 L:host:992` both speak it. A client has 15 seconds to finish the
handshake.
handshake. `tls_cert = acme` uses the [ACME client's](Certificates)
certificate instead of files.
## Certificates
Every TLS server reads its certificate again when the file changes, so a
renewal needs no restart. The BBS's own [ACME client](Certificates) gets
and renews certificates from Let's Encrypt or ZeroSSL for all of them.
**See also:** [SSH](SSH), [Configuration](Configuration), [Sysop tools](Sysop-Tools)
+1
View File
@@ -49,4 +49,5 @@
**More**
- [Security](Security)
- [Certificates (ACME)](Certificates)
- [Development](Development)
+44 -2
View File
@@ -18,6 +18,7 @@ require (
github.com/ergochat/irc-go v0.7.0
github.com/facebook/time v0.0.0-20261106180548-d4b419b4eef5
github.com/fclairamb/ftpserverlib v0.30.0
github.com/go-acme/lego/v4 v4.35.2
github.com/go-sql-driver/mysql v1.8.1
github.com/jackc/pgx/v5 v5.7.2
github.com/jlaffaye/ftp v0.2.0
@@ -28,28 +29,69 @@ require (
golang.org/x/sys v0.45.0
golang.org/x/term v0.43.0
golang.org/x/text v0.37.0
google.golang.org/protobuf v1.36.6
google.golang.org/protobuf v1.36.11
modernc.org/sqlite v1.33.1
)
require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/alexbrainman/sspi v0.0.0-20180613141037-e580b900e9f5 // indirect
github.com/aws/aws-sdk-go-v2 v1.41.6 // indirect
github.com/aws/aws-sdk-go-v2/config v1.32.16 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.19.15 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.22 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.22 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.22 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.23 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.8 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.22 // indirect
github.com/aws/aws-sdk-go-v2/service/route53 v1.62.6 // indirect
github.com/aws/aws-sdk-go-v2/service/signin v1.0.10 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.30.16 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.20 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.42.0 // indirect
github.com/aws/smithy-go v1.25.0 // indirect
github.com/bodgit/tsig v1.2.2 // indirect
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/dlclark/regexp2 v1.11.4 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-jose/go-jose/v4 v4.1.4 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
github.com/jcmturner/goidentity/v6 v6.0.1 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jinzhu/copier v0.4.0 // indirect
github.com/mattn/go-isatty v0.0.21 // indirect
github.com/miekg/dns v1.1.72 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/nrdcg/desec v0.11.1 // indirect
github.com/nrdcg/goacmedns v0.2.0 // indirect
github.com/nrdcg/porkbun v0.4.0 // indirect
github.com/openshift/gssapi v0.0.0-20161010215902-5fb4217df13b // indirect
github.com/ovh/go-ovh v1.9.0 // indirect
github.com/peterhellberg/link v1.2.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/tink-crypto/tink-go/v2 v2.4.0 // indirect
golang.org/x/mod v0.35.0 // indirect
golang.org/x/oauth2 v0.36.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/tools v0.44.0 // indirect
gopkg.in/ini.v1 v1.67.1 // indirect
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
modernc.org/libc v1.55.3 // indirect
modernc.org/mathutil v1.6.0 // indirect
+143 -6
View File
@@ -8,9 +8,48 @@ github.com/D-Modem/menu v0.0.0-20261106031303-853189d86fb2 h1:D7hJgxHbKQzr8850Cd
github.com/D-Modem/menu v0.0.0-20261106031303-853189d86fb2/go.mod h1:A+lNApUdQ5HSXW07R5aRm97MkhHYTQ1DkN0m+Vgorwg=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/alexbrainman/sspi v0.0.0-20180613141037-e580b900e9f5 h1:P5U+E4x5OkVEKQDklVPmzs71WM56RTTRqV4OrDC//Y4=
github.com/alexbrainman/sspi v0.0.0-20180613141037-e580b900e9f5/go.mod h1:976q2ETgjT2snVCf2ZaBnyBbVoPERGjUz+0sofzEfro=
github.com/aws/aws-sdk-go-v2 v1.41.6 h1:1AX0AthnBQzMx1vbmir3Y4WsnJgiydmnJjiLu+LvXOg=
github.com/aws/aws-sdk-go-v2 v1.41.6/go.mod h1:dy0UzBIfwSeot4grGvY1AqFWN5zgziMmWGzysDnHFcQ=
github.com/aws/aws-sdk-go-v2/config v1.32.16 h1:Q0iQ7quUgJP0F/SCRTieScnaMdXr9h/2+wze1u3cNeM=
github.com/aws/aws-sdk-go-v2/config v1.32.16/go.mod h1:duCCnJEFqpt2RC6no1iK6q+8HpwOAkiUua0pY507dQc=
github.com/aws/aws-sdk-go-v2/credentials v1.19.15 h1:fyvgWTszojq8hEnMi8PPBTvZdTtEVmAVyo+NFLHBhH4=
github.com/aws/aws-sdk-go-v2/credentials v1.19.15/go.mod h1:gJiYyMOjNg8OEdRWOf3CrFQxM2a98qmrtjx1zuiQfB8=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.22 h1:IOGsJ1xVWhsi+ZO7/NW8OuZZBtMJLZbk4P5HDjJO0jQ=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.22/go.mod h1:b+hYdbU+jGKfXE8kKM6g1+h+L/Go3vMvzlxBsiuGsxg=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.22 h1:GmLa5Kw1ESqtFpXsx5MmC84QWa/ZrLZvlJGa2y+4kcQ=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.22/go.mod h1:6sW9iWm9DK9YRpRGga/qzrzNLgKpT2cIxb7Vo2eNOp0=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.22 h1:dY4kWZiSaXIzxnKlj17nHnBcXXBfac6UlsAx2qL6XrU=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.22/go.mod h1:KIpEUx0JuRZLO7U6cbV204cWAEco2iC3l061IxlwLtI=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.23 h1:FPXsW9+gMuIeKmz7j6ENWcWtBGTe1kH8r9thNt5Uxx4=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.23/go.mod h1:7J8iGMdRKk6lw2C+cMIphgAnT8uTwBwNOsGkyOCm80U=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.8 h1:HtOTYcbVcGABLOVuPYaIihj6IlkqubBwFj10K5fxRek=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.8/go.mod h1:VsK9abqQeGlzPgUr+isNWzPlK2vKe9INMLWnY65f5Xs=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.22 h1:PUmZeJU6Y1Lbvt9WFuJ0ugUK2xn6hIWUBBbKuOWF30s=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.22/go.mod h1:nO6egFBoAaoXze24a2C0NjQCvdpk8OueRoYimvEB9jo=
github.com/aws/aws-sdk-go-v2/service/route53 v1.62.6 h1:6b+KS0uVMMsCUKlW8OPNxmcEmoEUtqP1LfnzSzWmuQM=
github.com/aws/aws-sdk-go-v2/service/route53 v1.62.6/go.mod h1:+wmraHmxwqi7feUL/41uULJWl8V1HxtxzOJH6a4ZRg4=
github.com/aws/aws-sdk-go-v2/service/signin v1.0.10 h1:a1Fq/KXn75wSzoJaPQTgZO0wHGqE9mjFnylnqEPTchA=
github.com/aws/aws-sdk-go-v2/service/signin v1.0.10/go.mod h1:p6+MXNxW7IA6dMgHfTAzljuwSKD0NCm/4lbS4t6+7vI=
github.com/aws/aws-sdk-go-v2/service/sso v1.30.16 h1:x6bKbmDhsgSZwv6q19wY/u3rLk/3FGjJWyqKcIRufpE=
github.com/aws/aws-sdk-go-v2/service/sso v1.30.16/go.mod h1:CudnEVKRtLn0+3uMV0yEXZ+YZOKnAtUJ5DmDhilVnIw=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.20 h1:oK/njaL8GtyEihkWMD4k3VgHCT64RQKkZwh0DG5j8ak=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.20/go.mod h1:JHs8/y1f3zY7U5WcuzoJ/yAYGYtNIVPKLIbp61euvmg=
github.com/aws/aws-sdk-go-v2/service/sts v1.42.0 h1:ks8KBcZPh3PYISr5dAiXCM5/Thcuxk8l+PG4+A0exds=
github.com/aws/aws-sdk-go-v2/service/sts v1.42.0/go.mod h1:pFw33T0WLvXU3rw1WBkpMlkgIn54eCB5FYLhjDc9Foo=
github.com/aws/smithy-go v1.25.0 h1:Sz/XJ64rwuiKtB6j98nDIPyYrV1nVNJ4YU74gttcl5U=
github.com/aws/smithy-go v1.25.0/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc=
github.com/bodgit/tsig v1.2.2 h1:RgxTCr8UFUHyU4D8Ygb2UtXtS4niw4B6XYYBpgCjl0k=
github.com/bodgit/tsig v1.2.2/go.mod h1:rIGNOLZOV/UA03fmCUtEFbpWOrIoaOuETkpaeTvnLF4=
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
github.com/coder/websocket v1.8.13 h1:f3QZdXy7uGVz+4uCJy2nTZyM0yTBj8yANEHhqlXZ9FE=
github.com/coder/websocket v1.8.13/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dop251/goja v0.0.0-20260603125802-cfe4039cb6d7 h1:g7JYcX9Y5RNJhrqpC/N/vHtp9BuFU1MVc4BO64scbKo=
@@ -27,12 +66,22 @@ github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6 h1:oP4q0fw+fOSWn3
github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
github.com/emersion/go-smtp v0.25.1 h1:y6nzefT6PtFeMItFw97GX/ZCkVbh0rqSXG8b3ang8/w=
github.com/emersion/go-smtp v0.25.1/go.mod h1:ZtRRkbTyp2XTHCA+BmyTFTrj8xY4I+b4McvHxCU2gsQ=
github.com/enceve/crypto v0.0.0-20160707101852-34d48bb93815/go.mod h1:wYFFK4LYXbX7j+76mOq7aiC/EAw2S22CrzPHqgsisPw=
github.com/ergochat/irc-go v0.7.0 h1:IYaATcjiPRlPcmn8F63Sgb4ulvvmCif/adeKHnk2B3g=
github.com/ergochat/irc-go v0.7.0/go.mod h1:2vi7KNpIPWnReB5hmLpl92eMywQvuIeIIGdt/FQCph0=
github.com/facebook/time v0.0.0-20261106180548-d4b419b4eef5 h1:HZryXSIVH4OkS/1EWmBpM4vgSJgIWwLvJQp4l8LJRzE=
github.com/facebook/time v0.0.0-20261106180548-d4b419b4eef5/go.mod h1:tvIlGl1H0y35Opsd4n7WmsVYxaTCHOsGhaGCNw4UsfQ=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fclairamb/ftpserverlib v0.30.0 h1:caB9sDn1Au//q0j2ev/icPn388qPuk4k1ajSvglDcMQ=
github.com/fclairamb/ftpserverlib v0.30.0/go.mod h1:QmogtltTOgkihyKza0GNo37Mu4AEzbJ+sH6W9Y0MBIQ=
github.com/go-acme/lego/v4 v4.35.2 h1:uVQg+KC/yj9R2g7Q9W5wDqhvQvxV5SMu5eqFVoN5xZU=
github.com/go-acme/lego/v4 v4.35.2/go.mod h1:pX2jN5n8OphMGY1IaMjYm5DAEzguBaKRt8AvJAgJXpc=
github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA=
github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
@@ -43,10 +92,23 @@ github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd h1:gbpYu9NMq8jhDVbvlG
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48=
github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
@@ -57,14 +119,52 @@ github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI=
github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jarcoal/httpmock v1.3.0 h1:2RJ8GP0IIaWwcC9Fp2BmVi8Kog3v2Hn7VXM3fTd+nuc=
github.com/jarcoal/httpmock v1.3.0/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8=
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo=
github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
github.com/jcmturner/gofork v1.7.6 h1:QH0l3hzAU1tfT3rZCnW5zXl+orbkNMMRGJfdJjHVETg=
github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo=
github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o=
github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg=
github.com/jcmturner/gokrb5/v8 v8.4.3/go.mod h1:dqRwJGXznQrzw6cWmyo6kH+E7jksEQG/CyVWsJEsJO0=
github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh687T8=
github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs=
github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY=
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/jlaffaye/ftp v0.2.0 h1:lXNvW7cBu7R/68bknOX3MrRIIqZ61zELs1P2RAiA3lg=
github.com/jlaffaye/ftp v0.2.0/go.mod h1:is2Ds5qkhceAPy2xD6RLI6hmp/qysSoymZ+Z2uTnspI=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.21 h1:xYae+lCNBP7QuW4PUnNG61ffM4hVIfm+zUzDuSzYLGs=
github.com/mattn/go-isatty v0.0.21/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g=
github.com/maxatome/go-testdeep v1.12.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM=
github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
github.com/miekg/dns v1.1.72 h1:vhmr+TF2A3tuoGNkLDFK9zi36F2LS+hKTRW0Uf8kbzI=
github.com/miekg/dns v1.1.72/go.mod h1:+EuEPhdHOsfk6Wk5TT2CzssZdqkmFhf8r+aVyDEToIs=
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/nrdcg/desec v0.11.1 h1:ilpKmCr4gGsLcyq3RHfHNmlRzm9fzT2XbWxoVaUCS0s=
github.com/nrdcg/desec v0.11.1/go.mod h1:2LuxHlOcwML/7cntu0eimONmA1U+ZxFDAonoSXr4igQ=
github.com/nrdcg/goacmedns v0.2.0 h1:ADMbThobzEMnr6kg2ohs4KGa3LFqmgiBA22/6jUWJR0=
github.com/nrdcg/goacmedns v0.2.0/go.mod h1:T5o6+xvSLrQpugmwHvrSNkzWht0UGAwj2ACBMhh73Cg=
github.com/nrdcg/porkbun v0.4.0 h1:rWweKlwo1PToQ3H+tEO9gPRW0wzzgmI/Ob3n2Guticw=
github.com/nrdcg/porkbun v0.4.0/go.mod h1:/QMskrHEIM0IhC/wY7iTCUgINsxdT2WcOphktJ9+Q54=
github.com/openshift/gssapi v0.0.0-20161010215902-5fb4217df13b h1:it0YPE/evO6/m8t8wxis9KFI2F/aleOKsI6d9uz0cEk=
github.com/openshift/gssapi v0.0.0-20161010215902-5fb4217df13b/go.mod h1:tNrEB5k8SI+g5kOlsCmL2ELASfpqEofI0+FLBgBdN08=
github.com/ovh/go-ovh v1.9.0 h1:6K8VoL3BYjVV3In9tPJUdT7qMx9h0GExN9EXx1r2kKE=
github.com/ovh/go-ovh v1.9.0/go.mod h1:cTVDnl94z4tl8pP1uZ/8jlVxntjSIf09bNcQ5TJSC7c=
github.com/peterhellberg/link v1.2.0 h1:UA5pg3Gp/E0F2WdX7GERiNrPQrM1K6CVJUUWfHa4t6c=
github.com/peterhellberg/link v1.2.0/go.mod h1:gYfAh+oJgQu2SrZHg5hROVRQe1ICoK0/HHJTcE0edxc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/secsy/goftp v0.0.0-20200609142545-aa2de14babf4 h1:PT+ElG/UUFMfqy5HrxJxNzj3QBOf7dZwupeVC+mG1Lo=
@@ -72,43 +172,73 @@ github.com/secsy/goftp v0.0.0-20200609142545-aa2de14babf4/go.mod h1:MnkX001NG75g
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/objx v0.5.3 h1:jmXUvGomnU1o3W/V5h2VEradbpJDwGrzugQQvL0POH4=
github.com/stretchr/objx v0.5.3/go.mod h1:rDQraq+vQZU7Fde9LOZLr8Tax6zZvy4kuNKF+QYS+U0=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
github.com/tink-crypto/tink-go/v2 v2.4.0 h1:8VPZeZI4EeZ8P/vB6SIkhlStrJfivTJn+cQ4dtyHNh0=
github.com/tink-crypto/tink-go/v2 v2.4.0/go.mod h1:l//evrF2Y3MjdbpNDNGnKgCpo5zSmvUvnQ4MU+yE2sw=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.52.0 h1:RMs7fP2rXdep0CftQlK8Uf+kibLm7qkCcradZWYz988=
golang.org/x/crypto v0.52.0/go.mod h1:1QgfPxDqh0T2M/elOJtp9RvuR95kVjir0e6/BvEmGbc=
golang.org/x/image v0.23.0 h1:HseQ7c2OpPKTPVzNjG5fwJsOTCiiwS4QdsYi5XU6H68=
golang.org/x/image v0.23.0/go.mod h1:wJJBTdLfCCf3tiHa1fNxpZmUI4mmoZvwMCPP0ddoNKY=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220725212005-46097bf591d3/go.mod h1:AaygXjzTFtRAg2ttMY5RMuhpJ3cNnI0XpyFJD1iQRSM=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
@@ -118,6 +248,7 @@ golang.org/x/term v0.43.0 h1:S4RLU2sB31O/NCl+zFN9Aru9A/Cq2aqKpTZJ6B+DwT4=
golang.org/x/term v0.43.0/go.mod h1:lrhlHNdQJHO+1qVYiHfFKVuVioJIheAc3fBSMFYEIsk=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
@@ -125,14 +256,20 @@ golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.1 h1:tVBILHy0R6e4wkYOn3XmiITt/hEVH4TFMYvAX2Ytz6k=
gopkg.in/ini.v1 v1.67.1/go.mod h1:x/cyOwCgZqOkJoDIJ3c1KNHMo10+nLGAhh+kn3Zizss=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+189
View File
@@ -0,0 +1,189 @@
package acme
import (
"context"
"crypto"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/x509"
"encoding/json"
"encoding/pem"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
"time"
"github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration"
)
// user is the ACME account, one for each CA: accounts/HOST/ beside the
// certificates.
type user struct {
Email string `json:"email"`
Registration *registration.Resource `json:"registration"`
key crypto.PrivateKey
dir string
}
func (u *user) GetEmail() string { return u.Email }
func (u *user) GetRegistration() *registration.Resource { return u.Registration }
func (u *user) GetPrivateKey() crypto.PrivateKey { return u.key }
// accountDir is the CA's account's directory.
func (m *Manager) accountDir() string {
host := "ca"
if u, err := url.Parse(m.S.CA); err == nil && u.Host != "" {
host = strings.ReplaceAll(u.Host, ":", "_")
}
return filepath.Join(m.S.Dir, "accounts", host)
}
// account is the CA's account as kept, or a new key for one.
func (m *Manager) account(ctx context.Context) (*user, error) {
dir := m.accountDir()
u := &user{Email: m.S.Email, dir: dir}
keyFile := filepath.Join(dir, "account.key")
if b, err := os.ReadFile(keyFile); err == nil {
blk, _ := pem.Decode(b)
if blk == nil {
return nil, fmt.Errorf("%s: not PEM", keyFile)
}
k, err := x509.ParseECPrivateKey(blk.Bytes)
if err != nil {
return nil, fmt.Errorf("%s: %w", keyFile, err)
}
u.key = k
} else {
k, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
return nil, err
}
der, err := x509.MarshalECPrivateKey(k)
if err != nil {
return nil, err
}
if err := os.MkdirAll(dir, 0o700); err != nil {
return nil, err
}
if err := writeFile(keyFile, pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: der}), 0o600); err != nil {
return nil, err
}
u.key = k
}
if b, err := os.ReadFile(filepath.Join(dir, "account.json")); err == nil {
var kept user
if err := json.Unmarshal(b, &kept); err != nil {
return nil, fmt.Errorf("%s/account.json: %w", dir, err)
}
if kept.Email == u.Email {
u.Registration = kept.Registration
}
}
return u, nil
}
// register makes (or finds again, by its key) the account at the CA,
// agreeing to its terms, and keeps it.
func (m *Manager) register(client *lego.Client, u *user) error {
var (
reg *registration.Resource
err error
)
kid, hmac := m.S.EABKeyID, m.S.EABHMAC
if kid == "" && client.GetExternalAccountRequired() && m.S.CA == CAs["zerossl"] {
if kid, hmac, err = zeroSSLEAB(m.S.Email); err != nil {
return err
}
}
if kid != "" {
reg, err = client.Registration.RegisterWithExternalAccountBinding(registration.RegisterEABOptions{
TermsOfServiceAgreed: true, Kid: kid, HmacEncoded: hmac})
} else {
if client.GetExternalAccountRequired() {
return errors.New("the CA wants External Account Binding: set eab_kid and eab_hmac_key")
}
reg, err = client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true})
}
if err != nil {
return fmt.Errorf("registering the account: %w", err)
}
u.Registration = reg
b, err := json.MarshalIndent(u, "", "\t")
if err != nil {
return err
}
m.Log.Printf("acme: registered %s at %s", reg.URI, m.S.CA)
return writeFile(filepath.Join(u.dir, "account.json"), b, 0o600)
}
// zeroSSLEAB gets External Account Binding for email from ZeroSSL, as
// acme.sh does: a ZeroSSL account is made for it if there is none.
func zeroSSLEAB(email string) (kid, hmac string, err error) {
if email == "" {
return "", "", errors.New("zerossl needs email (or eab_kid and eab_hmac_key)")
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, "POST", "https://api.zerossl.com/acme/eab-credentials-email",
strings.NewReader(url.Values{"email": {email}}.Encode()))
if err != nil {
return "", "", err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return "", "", fmt.Errorf("zerossl: %w", err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<16))
var r struct {
Success bool `json:"success"`
Kid string `json:"eab_kid"`
HMAC string `json:"eab_hmac_key"`
}
if err := json.Unmarshal(body, &r); err != nil || !r.Success || r.Kid == "" {
return "", "", fmt.Errorf("zerossl: no EAB credentials for %s: %s", email, strings.TrimSpace(string(body)))
}
return r.Kid, r.HMAC, nil
}
// suggested is when the CA's renewal information (ARI, RFC 9773) says to
// renew name's certificate, as last asked (zero: not known).
func (m *Manager) suggested(name string) time.Time {
m.mu.RLock()
defer m.mu.RUnlock()
return m.ari[name]
}
// askARI asks the CA when to renew name's certificate (best effort: not
// every CA answers).
func (m *Manager) askARI(ctx context.Context, name string) {
c := m.cert(name)
tc := m.load(name)
if c == nil || tc == nil || tc.Leaf == nil {
return
}
m.obtain.Lock()
client, err := m.client(ctx, c)
m.obtain.Unlock()
if err != nil {
return
}
ri, err := client.Certificate.GetRenewalInfo(certificate.RenewalInfoRequest{Cert: tc.Leaf})
if err != nil {
return
}
if t := ri.ShouldRenewAt(m.Now(), 13*time.Hour); t != nil {
m.mu.Lock()
m.ari[name] = *t
m.mu.Unlock()
}
}
+615
View File
@@ -0,0 +1,615 @@
// Package acme is the BBS's ACME client, in the manner of acme.sh: it gets
// certificates from Let's Encrypt, ZeroSSL or any ACME CA, keeps them
// beside the database, and renews them before they run out, for every TLS
// server of the BBS to share (internal/certs).
//
// Each certificate is proved by one challenge: HTTP-01 (a token on port
// 80: the BBS's own web server, or a listener of the client's), TLS-ALPN-01
// (a certificate on port 443, from any TLS server of the BBS there) or
// DNS-01 (a TXT record, through a DNS provider's API, a program of the
// sysop's, or acme.sh's own dnsapi scripts), the only one for wildcards.
//
// It is built on lego (github.com/go-acme/lego, MIT).
package acme
import (
"context"
"crypto/ecdsa"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"log"
"math/rand/v2"
"net/http"
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"sync"
"time"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/challenge/dns01"
"github.com/go-acme/lego/v4/challenge/tlsalpn01"
"github.com/go-acme/lego/v4/lego"
legolog "github.com/go-acme/lego/v4/log"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/sockets"
)
// The CAs known by name; ca may also be a directory's URL.
var CAs = map[string]string{
"letsencrypt": lego.LEDirectoryProduction,
"letsencrypt-staging": lego.LEDirectoryStaging,
"zerossl": "https://acme.zerossl.com/v2/DV90",
"buypass": "https://api.buypass.com/acme/directory",
"buypass-test": "https://api.test4.buypass.no/acme/directory",
"google": "https://dv.acme-v02.api.pki.goog/directory",
"google-test": "https://dv.acme-v02.test-api.pki.goog/directory",
"sslcom": "https://acme.ssl.com/sslcom-dv-ecc",
}
// KeyTypes are the keys a certificate can have, by their names here.
var KeyTypes = map[string]certcrypto.KeyType{
"ec256": certcrypto.EC256, "ec384": certcrypto.EC384,
"rsa2048": certcrypto.RSA2048, "rsa3072": certcrypto.RSA3072, "rsa4096": certcrypto.RSA4096,
}
// Challenges.
const (
HTTP01 = "http"
TLSALPN01 = "tls-alpn"
DNS01 = "dns"
)
// DefaultName is the name of [acme]'s own certificate (its domains).
const DefaultName = "default"
// Settings is [acme] and its [acme NAME] certificates.
type Settings struct {
Dir string // the account and certificates
Email string // the account's contact, told of problems
CA string // the directory's URL
EABKeyID string // External Account Binding (ZeroSSL's, Google's)
EABHMAC string // base64url
KeyType string // a KeyTypes name
RenewDays int // renew this many days before the end (or when the CA says)
HTTPAddress string // a listener for HTTP-01 ("": the [http] server answers)
DNSEnvFile string // KEY=value lines: the DNS provider's credentials
Resolvers []string // asked whether a DNS-01 record is out yet
DNSCheck string // how: "authoritative" (its zone's servers), "resolvers" (Resolvers) or "no"
DNSWait time.Duration // before the CA is told to look (acme.sh's --dnssleep)
ACMEsh string // acme.sh, for dns = acmesh:dns_xx
ACMEshHome string // its home (LE_WORKING_DIR): its saved credentials
Hook string // run after a certificate is renewed
Certs []Cert // the first is the default
}
// Cert is one certificate.
type Cert struct {
Name string
Domains []string // the first is its subject
Challenge string // HTTP01, TLSALPN01 or DNS01
DNS string // DNS-01's provider: a DNSProviders name, exec:PROGRAM or acmesh:dns_xx
KeyType string
}
// Names lists the certificates' names.
func (s *Settings) Names() []string {
var out []string
for _, c := range s.Certs {
out = append(out, c.Name)
}
return out
}
// Manager keeps the certificates.
type Manager struct {
S Settings
Log *log.Logger
Now func() time.Time
mu sync.RWMutex
held map[string]*held
tokens map[string]string // HTTP-01: token → key authorization
alpn map[string]*tls.Certificate // TLS-ALPN-01: name → its certificate
ari map[string]time.Time // when the CA says to renew, by certificate
envSet bool
obtain sync.Mutex // one order at a time
}
// held is a certificate as it is on disk.
type held struct {
cert *tls.Certificate
mod time.Time
checked time.Time
}
// New is a manager for s; it reads the certificates already got.
func New(s Settings, lg *log.Logger) (*Manager, error) {
if lg == nil {
lg = log.New(os.Stderr, "", log.LstdFlags)
}
if len(s.Certs) == 0 {
return nil, errors.New("acme: no certificates (domains)")
}
if s.RenewDays == 0 {
s.RenewDays = 30
}
m := &Manager{S: s, Log: lg, Now: time.Now, held: map[string]*held{},
tokens: map[string]string{}, alpn: map[string]*tls.Certificate{}, ari: map[string]time.Time{}}
for _, c := range s.Certs {
m.held[c.Name] = &held{}
m.load(c.Name)
}
return m, nil
}
func (m *Manager) cert(name string) *Cert {
for i := range m.S.Certs {
if m.S.Certs[i].Name == name {
return &m.S.Certs[i]
}
}
return nil
}
// Has reports whether there is a certificate called name.
func (m *Manager) Has(name string) bool { return m.cert(name) != nil }
// load reads name's certificate from disk if it has changed (looked at no
// more than every 30 seconds): renewed by this process, or by bbs acme
// in another.
func (m *Manager) load(name string) *tls.Certificate {
m.mu.Lock()
defer m.mu.Unlock()
h := m.held[name]
if h == nil {
return nil
}
now := time.Now()
if h.cert != nil && now.Sub(h.checked) < 30*time.Second {
return h.cert
}
h.checked = now
crt, key := m.files(name)
fi, err := os.Stat(crt)
if err != nil || (h.cert != nil && fi.ModTime().Equal(h.mod)) {
return h.cert
}
c, err := tls.LoadX509KeyPair(crt, key)
if err != nil {
m.Log.Printf("acme: %s: %v", name, err)
return h.cert
}
h.cert, h.mod = &c, fi.ModTime()
return h.cert
}
// Certificate is the certificate called name, or ("") the one whose names
// cover hello's server name, or the first there is.
func (m *Manager) Certificate(name string, hello *tls.ClientHelloInfo) (*tls.Certificate, error) {
if name != "" {
if c := m.load(name); c != nil {
return c, nil
}
return nil, fmt.Errorf("acme: no certificate %s yet", name)
}
var first *tls.Certificate
for _, c := range m.S.Certs {
tc := m.load(c.Name)
if tc == nil {
continue
}
if first == nil {
first = tc
}
if hello != nil && hello.ServerName != "" && tc.Leaf != nil && tc.Leaf.VerifyHostname(hello.ServerName) == nil {
return tc, nil
}
}
if first == nil {
return nil, errors.New("acme: no certificate yet")
}
return first, nil
}
// Challenge is TLS-ALPN-01's certificate for serverName, while it is being
// validated.
func (m *Manager) Challenge(serverName string) *tls.Certificate {
name := strings.ToLower(serverName)
m.mu.RLock()
c := m.alpn[name]
m.mu.RUnlock()
if c != nil || !safeName(name) {
return c
}
// one bbs acme renew is answering through this process
b, err := os.ReadFile(filepath.Join(m.challengeDir("alpn"), name))
if err != nil {
return nil
}
tc, err := tls.X509KeyPair(b, b)
if err != nil {
return nil
}
return &tc
}
// ServeHTTP answers HTTP-01's /.well-known/acme-challenge/TOKEN.
func (m *Manager) ServeHTTP(w http.ResponseWriter, r *http.Request) {
token, ok := strings.CutPrefix(r.URL.Path, certs.ChallengePath)
m.mu.RLock()
ka, found := m.tokens[token]
m.mu.RUnlock()
if ok && !found && safeName(token) {
// one bbs acme renew is answering through this process
if b, err := os.ReadFile(filepath.Join(m.challengeDir("http"), token)); err == nil {
ka, found = string(b), true
}
}
if !ok || !found {
http.NotFound(w, r)
return
}
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte(ka))
}
// Run gets the certificates there are not yet, and renews them, until ctx
// is done; it also answers HTTP-01 on HTTPAddress, if set.
func (m *Manager) Run(ctx context.Context) error {
if m.S.HTTPAddress != "" {
ln, err := sockets.Listen("tcp", m.S.HTTPAddress)
if err != nil {
return fmt.Errorf("acme: http_address: %w", err)
}
hs := &http.Server{Handler: m, ReadHeaderTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second}
go hs.Serve(ln)
go func() { <-ctx.Done(); hs.Close() }()
m.Log.Printf("acme: answering HTTP-01 on %s", ln.Addr())
}
for {
wait := m.RenewAll(ctx, false)
select {
case <-ctx.Done():
return nil
case <-time.After(wait):
}
}
}
// RenewAll gets each certificate that is due (all of them, if force), and
// says how long until it should look again: 12 hours, or one after a
// failure.
func (m *Manager) RenewAll(ctx context.Context, force bool) time.Duration {
wait := 12*time.Hour + time.Duration(rand.Int64N(int64(time.Hour)))
for _, c := range m.S.Certs {
if ctx.Err() != nil {
break
}
if !force {
m.askARI(ctx, c.Name)
}
due, why := m.Due(c.Name)
if !due && !force {
continue
}
m.Log.Printf("acme: %s: getting a certificate for %s (%s)", c.Name, strings.Join(c.Domains, ", "), why)
if err := m.Obtain(ctx, c.Name); err != nil {
m.Log.Printf("acme: %s: %v", c.Name, err)
wait = min(wait, time.Hour)
continue
}
m.Log.Printf("acme: %s: got it", c.Name)
}
return wait
}
// Due reports whether name's certificate should be got now, and why.
func (m *Manager) Due(name string) (bool, string) {
c := m.cert(name)
tc := m.load(name)
if c == nil {
return false, "no such certificate"
}
if tc == nil || tc.Leaf == nil {
return true, "none yet"
}
leaf := tc.Leaf
for _, d := range c.Domains {
if !slices.Contains(leaf.DNSNames, d) {
return true, "the domains have changed"
}
}
if len(leaf.DNSNames) != len(c.Domains) {
return true, "the domains have changed"
}
if kt := keyType(leaf); kt != m.keyType(c) {
return true, "the key type has changed"
}
left := leaf.NotAfter.Sub(m.Now())
if left < time.Duration(m.S.RenewDays)*24*time.Hour {
return true, fmt.Sprintf("it runs out %s", leaf.NotAfter.Format(time.DateOnly))
}
if t := m.suggested(name); !t.IsZero() && !m.Now().Before(t) {
return true, "the CA asks for it to be renewed"
}
return false, ""
}
// keyType names a certificate's key as KeyTypes does.
func keyType(leaf *x509.Certificate) string {
switch k := leaf.PublicKey.(type) {
case *rsa.PublicKey:
return fmt.Sprintf("rsa%d", k.N.BitLen())
case *ecdsa.PublicKey:
return fmt.Sprintf("ec%d", k.Curve.Params().BitSize)
}
return ""
}
func (m *Manager) keyType(c *Cert) string {
if c.KeyType != "" {
return c.KeyType
}
if m.S.KeyType != "" {
return m.S.KeyType
}
return "ec256"
}
// files are name's certificate (the chain) and key.
func (m *Manager) files(name string) (string, string) {
return filepath.Join(m.certDir(), name+".crt"), filepath.Join(m.certDir(), name+".key")
}
func (m *Manager) certDir() string { return filepath.Join(m.S.Dir, "certs") }
// Files are the certificate's and key's paths (for a sysop's other
// programs).
func (m *Manager) Files(name string) (string, string) { return m.files(name) }
// Obtain gets name's certificate now, and keeps it.
func (m *Manager) Obtain(ctx context.Context, name string) error {
c := m.cert(name)
if c == nil {
return fmt.Errorf("no certificate %s", name)
}
m.obtain.Lock()
defer m.obtain.Unlock()
legolog.Logger = log.New(m.Log.Writer(), m.Log.Prefix()+"acme: lego: ", m.Log.Flags())
client, err := m.client(ctx, c)
if err != nil {
return err
}
if err := m.challenge(client, c); err != nil {
return err
}
res, err := client.Certificate.Obtain(certificate.ObtainRequest{Domains: c.Domains, Bundle: true})
if err != nil {
return err
}
if err := m.keep(name, res); err != nil {
return err
}
m.mu.Lock()
m.held[name].checked = time.Time{}
m.mu.Unlock()
m.load(name)
m.hook(c)
return nil
}
// keep writes a certificate and its key, the key first and both by
// renaming, so a reader never sees half of one or a key that is not its.
func (m *Manager) keep(name string, res *certificate.Resource) error {
crt, key := m.files(name)
if err := os.MkdirAll(m.certDir(), 0o700); err != nil {
return err
}
if err := writeFile(key, res.PrivateKey, 0o600); err != nil {
return err
}
return writeFile(crt, res.Certificate, 0o644)
}
func writeFile(path string, data []byte, mode os.FileMode) error {
tmp := path + ".new"
if err := os.WriteFile(tmp, data, mode); err != nil {
return err
}
return os.Rename(tmp, path)
}
// hook runs the sysop's command after a renewal, with the certificate's
// name, files and domains in its environment.
func (m *Manager) hook(c *Cert) {
if m.S.Hook == "" {
return
}
crt, key := m.files(c.Name)
cmd := exec.Command("/bin/sh", "-c", m.S.Hook)
cmd.Env = append(os.Environ(), "CERT_NAME="+c.Name, "CERT_FILE="+crt, "KEY_FILE="+key,
"CERT_DOMAINS="+strings.Join(c.Domains, " "))
out, err := cmd.CombinedOutput()
if err != nil {
m.Log.Printf("acme: %s: hook: %v: %s", c.Name, err, strings.TrimSpace(string(out)))
}
}
// client is a lego client for c, with the account (registered now if it
// is new).
func (m *Manager) client(ctx context.Context, c *Cert) (*lego.Client, error) {
u, err := m.account(ctx)
if err != nil {
return nil, err
}
cfg := lego.NewConfig(u)
cfg.CADirURL = m.S.CA
cfg.UserAgent = "D-Modem-BBS"
cfg.Certificate.KeyType = KeyTypes[m.keyType(c)]
client, err := lego.NewClient(cfg)
if err != nil {
return nil, err
}
if u.Registration == nil {
if err := m.register(client, u); err != nil {
return nil, err
}
}
return client, nil
}
// challenge sets c's challenge on client.
func (m *Manager) challenge(client *lego.Client, c *Cert) error {
var err error
switch c.Challenge {
case HTTP01:
err = client.Challenge.SetHTTP01Provider(httpSolver{m})
case TLSALPN01:
err = client.Challenge.SetTLSALPN01Provider(alpnSolver{m})
case DNS01:
p, perr := m.dnsProvider(c.DNS)
if perr != nil {
return perr
}
var opts []dns01.ChallengeOption
if len(m.S.Resolvers) > 0 {
opts = append(opts, dns01.AddRecursiveNameservers(dns01.ParseNameservers(m.S.Resolvers)))
}
switch m.S.DNSCheck {
case "resolvers":
opts = append(opts, dns01.RecursiveNSsPropagationRequirement())
case "no":
opts = append(opts, dns01.PropagationWait(m.S.DNSWait, true))
}
if m.S.DNSWait > 0 && m.S.DNSCheck != "no" {
opts = append(opts, dns01.PropagationWait(m.S.DNSWait, false))
}
err = client.Challenge.SetDNS01Provider(p, opts...)
default:
err = fmt.Errorf("challenge %q", c.Challenge)
}
return err
}
// challengeDir is where challenges are put for a running bbs serve to
// answer when another process (bbs acme renew) has them: kind "http"
// (TOKEN: the key authorization) or "alpn" (NAME: certificate and key).
func (m *Manager) challengeDir(kind string) string {
return filepath.Join(m.S.Dir, "challenges", kind)
}
// safeName is a token or host name fit to be a file's name.
func safeName(s string) bool {
if s == "" || len(s) > 255 || s[0] == '.' {
return false
}
for _, r := range s {
if !(r >= 'a' && r <= 'z' || r >= 'A' && r <= 'Z' || r >= '0' && r <= '9' || r == '-' || r == '_' || r == '.') {
return false
}
}
return true
}
// share puts a challenge on disk too (best effort), for a bbs serve to
// answer while this process is bbs acme renew.
func (m *Manager) share(kind, name string, data []byte) {
if !safeName(name) {
return
}
dir := m.challengeDir(kind)
if os.MkdirAll(dir, 0o755) == nil {
os.WriteFile(filepath.Join(dir, name), data, 0o644)
}
}
func (m *Manager) unshare(kind, name string) {
if safeName(name) {
os.Remove(filepath.Join(m.challengeDir(kind), name))
}
}
// httpSolver answers HTTP-01 through ServeHTTP.
type httpSolver struct{ m *Manager }
func (s httpSolver) Present(domain, token, keyAuth string) error {
s.m.mu.Lock()
s.m.tokens[token] = keyAuth
s.m.mu.Unlock()
s.m.share("http", token, []byte(keyAuth))
return nil
}
func (s httpSolver) CleanUp(domain, token, keyAuth string) error {
s.m.mu.Lock()
delete(s.m.tokens, token)
s.m.mu.Unlock()
s.m.unshare("http", token)
return nil
}
// alpnSolver answers TLS-ALPN-01 through the TLS servers (certs.Config).
type alpnSolver struct{ m *Manager }
func (s alpnSolver) Present(domain, token, keyAuth string) error {
c, err := tlsalpn01.ChallengeCert(domain, keyAuth)
if err != nil {
return err
}
s.m.mu.Lock()
s.m.alpn[strings.ToLower(domain)] = c
s.m.mu.Unlock()
if pemCert, pemKey, err := tlsalpn01.ChallengeBlocks(domain, keyAuth); err == nil {
// the key is only this challenge's: it may be read by anyone
s.m.share("alpn", strings.ToLower(domain), append(pemCert, pemKey...))
}
return nil
}
func (s alpnSolver) CleanUp(domain, token, keyAuth string) error {
s.m.mu.Lock()
delete(s.m.alpn, strings.ToLower(domain))
s.m.mu.Unlock()
s.m.unshare("alpn", strings.ToLower(domain))
return nil
}
var _ certs.Manager = (*Manager)(nil)
// Status is a certificate as bbs acme list and bbs check show it.
type Status struct {
Cert
CertFile, KeyFile string
Have bool
Issuer string
NotAfter time.Time
Due bool
Why string
}
// Status describes each certificate.
func (m *Manager) Status() []Status {
var out []Status
for _, c := range m.S.Certs {
st := Status{Cert: c}
st.CertFile, st.KeyFile = m.files(c.Name)
if tc := m.load(c.Name); tc != nil && tc.Leaf != nil {
st.Have, st.Issuer, st.NotAfter = true, tc.Leaf.Issuer.CommonName, tc.Leaf.NotAfter
if o := tc.Leaf.Issuer.Organization; len(o) > 0 {
st.Issuer = o[0] + " " + st.Issuer
}
}
st.Due, st.Why = m.Due(c.Name)
out = append(out, st)
}
return out
}
+230
View File
@@ -0,0 +1,230 @@
package acme
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/asn1"
"encoding/pem"
"io"
"log"
"math/big"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
"time"
"github.com/go-acme/lego/v4/certificate"
)
// issue makes a self-signed certificate for names, good until notAfter, as
// a CA's would be kept.
func issue(t *testing.T, notAfter time.Time, names ...string) *certificate.Resource {
t.Helper()
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
t.Fatal(err)
}
tmpl := &x509.Certificate{SerialNumber: big.NewInt(time.Now().UnixNano()), Subject: pkix.Name{CommonName: names[0]},
NotBefore: time.Now().Add(-time.Hour), NotAfter: notAfter, DNSNames: names}
der, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, &key.PublicKey, key)
if err != nil {
t.Fatal(err)
}
kd, _ := x509.MarshalECPrivateKey(key)
return &certificate.Resource{Certificate: pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: der}),
PrivateKey: pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: kd})}
}
func testManager(t *testing.T) *Manager {
t.Helper()
m, err := New(Settings{Dir: t.TempDir(), CA: CAs["letsencrypt-staging"], Certs: []Cert{
{Name: "default", Domains: []string{"bbs.example.org", "www.example.org"}, Challenge: HTTP01},
{Name: "mail", Domains: []string{"mail.example.org"}, Challenge: TLSALPN01},
{Name: "wild", Domains: []string{"*.example.net"}, Challenge: DNS01, DNS: "cloudflare"},
}}, log.New(io.Discard, "", 0))
if err != nil {
t.Fatal(err)
}
return m
}
// TestCertificates: the certificate for the name asked for (SNI), the
// first for any other; one renewed on disk is read again.
func TestCertificates(t *testing.T) {
m := testManager(t)
if _, err := m.Certificate("", &tls.ClientHelloInfo{ServerName: "bbs.example.org"}); err == nil {
t.Error("a certificate before there is one")
}
if due, why := m.Due("default"); !due || why != "none yet" {
t.Errorf("due %v %q", due, why)
}
later := time.Now().Add(80 * 24 * time.Hour)
m.keep("default", issue(t, later, "bbs.example.org", "www.example.org"))
m.keep("mail", issue(t, later, "mail.example.org"))
m.keep("wild", issue(t, later, "*.example.net"))
for name, want := range map[string]string{"bbs.example.org": "bbs.example.org", "www.example.org": "bbs.example.org",
"mail.example.org": "mail.example.org", "x.example.net": "*.example.net", "": "bbs.example.org", "other.test": "bbs.example.org"} {
c, err := m.Certificate("", &tls.ClientHelloInfo{ServerName: name})
if err != nil || c.Leaf.Subject.CommonName != want {
t.Errorf("%q: %v %v", name, c, err)
}
}
if c, err := m.Certificate("mail", &tls.ClientHelloInfo{ServerName: "bbs.example.org"}); err != nil || c.Leaf.Subject.CommonName != "mail.example.org" {
t.Errorf("named: %v", err)
}
if due, why := m.Due("default"); due {
t.Errorf("due: %s", why)
}
// renewed by another process: read again once its file changes
old, _ := m.Certificate("default", nil)
m.keep("default", issue(t, later.Add(time.Hour), "bbs.example.org", "www.example.org"))
crt, _ := m.Files("default")
os.Chtimes(crt, time.Now().Add(time.Minute), time.Now().Add(time.Minute))
m.mu.Lock()
m.held["default"].checked = time.Time{}
m.mu.Unlock()
if c, _ := m.Certificate("default", nil); c.Leaf.SerialNumber.Cmp(old.Leaf.SerialNumber) == 0 {
t.Error("not read again")
}
if fi, _ := os.Stat(filepath.Join(m.certDir(), "default.key")); fi.Mode().Perm() != 0o600 {
t.Errorf("key mode %v", fi.Mode())
}
}
// TestDue: renewed when the domains change, the key type changes, or the
// end is near.
func TestDue(t *testing.T) {
m := testManager(t)
m.keep("default", issue(t, time.Now().Add(80*24*time.Hour), "bbs.example.org"))
if due, why := m.Due("default"); !due || !strings.Contains(why, "domains") {
t.Errorf("domains: %v %q", due, why)
}
m.keep("mail", issue(t, time.Now().Add(10*24*time.Hour), "mail.example.org"))
if due, why := m.Due("mail"); !due || !strings.Contains(why, "runs out") {
t.Errorf("end: %v %q", due, why)
}
m.S.Certs[2].KeyType = "rsa2048"
m.keep("wild", issue(t, time.Now().Add(80*24*time.Hour), "*.example.net"))
if due, why := m.Due("wild"); !due || !strings.Contains(why, "key") {
t.Errorf("key: %v %q", due, why)
}
}
// TestChallenges: HTTP-01 tokens and TLS-ALPN-01 certificates are
// answered from memory, and from disk (put there by bbs acme renew).
func TestChallenges(t *testing.T) {
m := testManager(t)
get := func(path string) (int, string) {
w := httptest.NewRecorder()
m.ServeHTTP(w, httptest.NewRequest("GET", path, nil))
return w.Code, w.Body.String()
}
httpSolver{m}.Present("bbs.example.org", "tok-1", "tok-1.thumb")
if code, body := get("/.well-known/acme-challenge/tok-1"); code != 200 || body != "tok-1.thumb" {
t.Errorf("token: %d %q", code, body)
}
if code, _ := get("/.well-known/acme-challenge/../../etc/passwd"); code != 404 {
t.Errorf("traversal: %d", code)
}
// another process's
other := &Manager{S: m.S, Log: m.Log, held: map[string]*held{}, tokens: map[string]string{},
alpn: map[string]*tls.Certificate{}, ari: map[string]time.Time{}}
httpSolver{other}.Present("bbs.example.org", "tok-2", "tok-2.thumb")
if code, body := get("/.well-known/acme-challenge/tok-2"); code != 200 || body != "tok-2.thumb" {
t.Errorf("shared token: %d %q", code, body)
}
httpSolver{other}.CleanUp("bbs.example.org", "tok-2", "")
httpSolver{m}.CleanUp("bbs.example.org", "tok-1", "")
for _, tok := range []string{"tok-1", "tok-2"} {
if code, _ := get("/.well-known/acme-challenge/" + tok); code != 404 {
t.Errorf("%s after clean up: %d", tok, code)
}
}
if m.Challenge("mail.example.org") != nil {
t.Error("a TLS-ALPN-01 certificate before one is presented")
}
alpnSolver{other}.Present("mail.example.org", "t", "t.thumb")
c := m.Challenge("MAIL.example.org")
if c == nil {
t.Fatal("no shared TLS-ALPN-01 certificate")
}
leaf, _ := x509.ParseCertificate(c.Certificate[0])
found := false
for _, ext := range leaf.Extensions {
found = found || ext.Id.Equal(asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 1, 31}) // id-pe-acmeIdentifier
}
if !found || leaf.DNSNames[0] != "mail.example.org" {
t.Errorf("challenge certificate %v %v", leaf.DNSNames, found)
}
alpnSolver{other}.CleanUp("mail.example.org", "t", "")
if m.Challenge("mail.example.org") != nil {
t.Error("still there after clean up")
}
}
// TestReadEnv: KEY=value lines as shells and systemd write them.
func TestReadEnv(t *testing.T) {
p := filepath.Join(t.TempDir(), "env")
os.WriteFile(p, []byte("# Cloudflare\nCF_DNS_API_TOKEN=abc\nexport CF_Account_ID = \"x y\"\n\nQ='z'\n"), 0o600)
env, err := ReadEnv(p)
if err != nil || env["CF_DNS_API_TOKEN"] != "abc" || env["CF_Account_ID"] != "x y" || env["Q"] != "z" || len(env) != 3 {
t.Errorf("%v %v", env, err)
}
os.WriteFile(p, []byte("not a line\n"), 0o600)
if _, err := ReadEnv(p); err == nil {
t.Error("took a bad line")
}
}
// TestAcmesh: an acme.sh dnsapi script is run with acme.sh's functions,
// given the record's name and value; a missing one is an error.
func TestAcmesh(t *testing.T) {
dir := t.TempDir()
// enough of acme.sh: its last line runs its arguments, and the two
// functions the bridge calls
os.WriteFile(filepath.Join(dir, "acme.sh"), []byte(`
_initpath() { :; }
_findHook() { [ -f "$_SCRIPT_HOME/$2/$3.sh" ] && printf %s "$_SCRIPT_HOME/$2/$3.sh"; }
_info() { echo "$@"; }
main() { "$@"; }
main "$@"
`), 0o755)
os.Mkdir(filepath.Join(dir, "dnsapi"), 0o755)
os.WriteFile(filepath.Join(dir, "dnsapi", "dns_test.sh"), []byte(`
dns_test_add() { _info add; echo "add $1 $2 $T_Token" >> "$LE_WORKING_DIR/log"; }
dns_test_rm() { echo "rm $1 $2" >> "$LE_WORKING_DIR/log"; }
`), 0o644)
m := testManager(t)
m.S.ACMEsh = filepath.Join(dir, "acme.sh")
t.Setenv("T_Token", "sekrit")
p, err := m.acmesh("dns_test")
if err != nil {
t.Fatal(err)
}
if err := p.Present("example.org", "tok", "tok.thumb"); err != nil {
t.Fatal(err)
}
if err := p.CleanUp("example.org", "tok", "tok.thumb"); err != nil {
t.Fatal(err)
}
b, _ := os.ReadFile(filepath.Join(dir, "log"))
lines := strings.Split(strings.TrimSpace(string(b)), "\n")
if len(lines) != 2 || !strings.HasPrefix(lines[0], "add _acme-challenge.example.org ") || !strings.HasSuffix(lines[0], " sekrit") ||
!strings.HasPrefix(lines[1], "rm _acme-challenge.example.org ") {
t.Errorf("log %q", lines)
}
if p, _ := m.acmesh("dns_none"); p.Present("example.org", "t", "t.k") == nil {
t.Error("no error for a missing script")
}
if _, err := m.acmesh("../x"); err == nil {
t.Error("took a path")
}
}
+15
View File
@@ -0,0 +1,15 @@
# Runs one of acme.sh's dnsapi scripts with acme.sh's functions loaded:
# sh -c "$(cat acmesh.sh)" acmesh ACME.SH dns_xx add|rm FQDN VALUE
# acme.sh's last line runs its arguments as a command, so it is given
# "true" to load quietly; LE_WORKING_DIR is its home (account.conf).
acmesh=$1 api=$2 action=$3 fqdn=$4 value=$5
_SCRIPT_HOME=$(dirname "$acmesh")
: "${LE_WORKING_DIR:=$_SCRIPT_HOME}"
export LE_WORKING_DIR
set -- true
. "$acmesh" || exit 1
_initpath
d_api=$(_findHook "" dnsapi "$api")
[ -n "$d_api" ] || { echo "acme.sh has no dnsapi/$api.sh" >&2; exit 1; }
. "$d_api" || exit 1
"${api}_$action" "$fqdn" "$value"
+206
View File
@@ -0,0 +1,206 @@
package acme
import (
"bufio"
_ "embed"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"sort"
"strings"
"time"
"github.com/go-acme/lego/v4/challenge"
"github.com/go-acme/lego/v4/challenge/dns01"
"github.com/go-acme/lego/v4/providers/dns/acmedns"
"github.com/go-acme/lego/v4/providers/dns/cloudflare"
"github.com/go-acme/lego/v4/providers/dns/desec"
"github.com/go-acme/lego/v4/providers/dns/digitalocean"
"github.com/go-acme/lego/v4/providers/dns/duckdns"
legoexec "github.com/go-acme/lego/v4/providers/dns/exec"
"github.com/go-acme/lego/v4/providers/dns/gandiv5"
"github.com/go-acme/lego/v4/providers/dns/godaddy"
"github.com/go-acme/lego/v4/providers/dns/hetzner"
"github.com/go-acme/lego/v4/providers/dns/httpreq"
"github.com/go-acme/lego/v4/providers/dns/namecheap"
"github.com/go-acme/lego/v4/providers/dns/ovh"
"github.com/go-acme/lego/v4/providers/dns/pdns"
"github.com/go-acme/lego/v4/providers/dns/porkbun"
"github.com/go-acme/lego/v4/providers/dns/rfc2136"
"github.com/go-acme/lego/v4/providers/dns/route53"
)
// DNSProviders are the DNS APIs built in, by lego's names for them; each
// takes its credentials from lego's environment variables (dns_env_file).
// Any other is reached through acme.sh's scripts (acmesh:dns_xx) or a
// program (exec:PATH).
var DNSProviders = map[string]func() (challenge.Provider, error){
"acme-dns": func() (challenge.Provider, error) { return acmedns.NewDNSProvider() },
"cloudflare": func() (challenge.Provider, error) { return cloudflare.NewDNSProvider() },
"desec": func() (challenge.Provider, error) { return desec.NewDNSProvider() },
"digitalocean": func() (challenge.Provider, error) { return digitalocean.NewDNSProvider() },
"duckdns": func() (challenge.Provider, error) { return duckdns.NewDNSProvider() },
"gandiv5": func() (challenge.Provider, error) { return gandiv5.NewDNSProvider() },
"godaddy": func() (challenge.Provider, error) { return godaddy.NewDNSProvider() },
"hetzner": func() (challenge.Provider, error) { return hetzner.NewDNSProvider() },
"httpreq": func() (challenge.Provider, error) { return httpreq.NewDNSProvider() },
"namecheap": func() (challenge.Provider, error) { return namecheap.NewDNSProvider() },
"ovh": func() (challenge.Provider, error) { return ovh.NewDNSProvider() },
"pdns": func() (challenge.Provider, error) { return pdns.NewDNSProvider() },
"porkbun": func() (challenge.Provider, error) { return porkbun.NewDNSProvider() },
"rfc2136": func() (challenge.Provider, error) { return rfc2136.NewDNSProvider() },
"route53": func() (challenge.Provider, error) { return route53.NewDNSProvider() },
}
// ProviderNames lists the DNS providers built in.
func ProviderNames() []string {
var out []string
for n := range DNSProviders {
out = append(out, n)
}
sort.Strings(out)
return out
}
// CheckDNS tells whether a dns setting names a provider there is.
func CheckDNS(name string) error {
switch {
case name == "":
return errors.New("challenge = dns needs dns (a provider, exec:PROGRAM or acmesh:dns_xx)")
case strings.HasPrefix(name, "exec:"), strings.HasPrefix(name, "acmesh:dns_"):
return nil
case DNSProviders[name] != nil:
return nil
}
return fmt.Errorf("dns = %s: not built in (%s; or exec:PROGRAM, acmesh:dns_xx)", name, strings.Join(ProviderNames(), ", "))
}
// dnsProvider makes the DNS-01 provider called name, its credentials from
// the environment and dns_env_file.
func (m *Manager) dnsProvider(name string) (challenge.Provider, error) {
if err := m.loadEnv(); err != nil {
return nil, err
}
switch {
case strings.HasPrefix(name, "exec:"):
cfg := legoexec.NewDefaultConfig()
cfg.Program = strings.TrimPrefix(name, "exec:")
return legoexec.NewDNSProviderConfig(cfg)
case strings.HasPrefix(name, "acmesh:"):
return m.acmesh(strings.TrimPrefix(name, "acmesh:"))
case DNSProviders[name] != nil:
return DNSProviders[name]()
}
return nil, CheckDNS(name)
}
// loadEnv puts dns_env_file's KEY=value lines in the environment, where
// lego's providers and acme.sh's scripts look for their credentials (once;
// those already set by the service manager stay).
func (m *Manager) loadEnv() error {
m.mu.Lock()
defer m.mu.Unlock()
if m.envSet || m.S.DNSEnvFile == "" {
return nil
}
env, err := ReadEnv(m.S.DNSEnvFile)
if err != nil {
return err
}
for k, v := range env {
if _, ok := os.LookupEnv(k); !ok {
os.Setenv(k, v)
}
}
m.envSet = true
return nil
}
// ReadEnv reads KEY=value lines (# comments, export and quotes allowed, as
// a shell or systemd's EnvironmentFile has them).
func ReadEnv(path string) (map[string]string, error) {
f, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("dns_env_file: %w", err)
}
defer f.Close()
out := map[string]string{}
sc := bufio.NewScanner(f)
n := 0
for sc.Scan() {
n++
line := strings.TrimSpace(sc.Text())
if line == "" || line[0] == '#' {
continue
}
line = strings.TrimPrefix(line, "export ")
k, v, ok := strings.Cut(line, "=")
k = strings.TrimSpace(k)
if !ok || k == "" || strings.ContainsAny(k, " \t") {
return nil, fmt.Errorf("%s:%d: not KEY=value", path, n)
}
v = strings.TrimSpace(v)
if len(v) >= 2 && (v[0] == '"' || v[0] == '\'') && v[len(v)-1] == v[0] {
v = v[1 : len(v)-1]
}
out[k] = v
}
return out, sc.Err()
}
//go:embed acmesh.sh
var acmeshShim string
// acmeshProvider adds and removes the TXT record with one of acme.sh's
// dnsapi scripts (dns_cf, dns_gd, ...): acme.sh's own functions are loaded
// for it, so its saved credentials (account.conf) and its environment
// variables both work.
type acmeshProvider struct {
m *Manager
api string
}
func (m *Manager) acmesh(api string) (challenge.Provider, error) {
if m.S.ACMEsh == "" {
return nil, errors.New("dns = acmesh:...: set acmesh, the path of acme.sh")
}
if _, err := os.Stat(m.S.ACMEsh); err != nil {
return nil, fmt.Errorf("acmesh: %w", err)
}
if strings.ContainsAny(api, "/ ") || !strings.HasPrefix(api, "dns_") {
return nil, fmt.Errorf("acmesh:%s: not a dnsapi name like dns_cf", api)
}
return &acmeshProvider{m: m, api: api}, nil
}
func (p *acmeshProvider) run(action, domain, keyAuth string) error {
info := dns01.GetChallengeInfo(domain, keyAuth)
fqdn := strings.TrimSuffix(info.EffectiveFQDN, ".")
cmd := exec.Command("/bin/sh", "-c", acmeshShim, "acmesh", p.m.S.ACMEsh, p.api, action, fqdn, info.Value)
cmd.Env = os.Environ()
home := p.m.S.ACMEshHome
if home == "" {
home = filepath.Dir(p.m.S.ACMEsh)
}
cmd.Env = append(cmd.Env, "LE_WORKING_DIR="+home)
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("acme.sh %s_%s: %v: %s", p.api, action, err, strings.TrimSpace(string(out)))
}
return nil
}
func (p *acmeshProvider) Present(domain, token, keyAuth string) error {
return p.run("add", domain, keyAuth)
}
func (p *acmeshProvider) CleanUp(domain, token, keyAuth string) error {
return p.run("rm", domain, keyAuth)
}
// Timeout gives acme.sh's slower DNS APIs time to publish the record.
func (p *acmeshProvider) Timeout() (timeout, interval time.Duration) {
return 5 * time.Minute, 10 * time.Second
}
+6 -2
View File
@@ -20,6 +20,7 @@ import (
"time"
"github.com/D-Modem/bbs/internal/bbs"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/fido"
"github.com/D-Modem/bbs/internal/forum"
"github.com/D-Modem/bbs/internal/imageboard"
@@ -465,7 +466,7 @@ func (s *Server) Run(ctx context.Context) error {
// Serve serves on ln until ctx is done.
func (s *Server) Serve(ctx context.Context, ln net.Listener) error {
s.Ctx = ctx
h := s.Handler()
h := certs.WrapHTTP(s.Handler())
hs := &http.Server{Handler: h, ReadHeaderTimeout: 10 * time.Second, IdleTimeout: 2 * time.Minute,
MaxHeaderBytes: 16 << 10, ErrorLog: s.B.Log,
BaseContext: func(net.Listener) context.Context { return ctx }}
@@ -483,7 +484,10 @@ func (s *Server) Serve(ctx context.Context, ln net.Listener) error {
s.B.Log.Printf("http: listening on %s (tls %v)", ln.Addr(), s.S.TLS)
var err error
if s.S.TLS {
err = hs.ServeTLS(l, s.S.CertFile, s.S.KeyFile)
if hs.TLSConfig, err = certs.Config(s.S.CertFile, s.S.KeyFile); err != nil {
return fmt.Errorf("http: %w", err)
}
err = hs.ServeTLS(l, "", "")
} else {
err = hs.Serve(l)
}
+223
View File
@@ -0,0 +1,223 @@
// Package certs is where every TLS server of the BBS gets its certificate:
// a certificate and key file of the sysop's, read again when the files
// change (a renewal by certbot or acme.sh), or one the BBS's own ACME
// client keeps ([acme], internal/acme).
//
// A server's cert_file names which:
//
// /etc/bbs/bbs.crt that file, with key_file beside it
// acme the ACME certificate for the name the client asks
// for (SNI), or the first one
// acme:NAME the [acme NAME] certificate
//
// The server configuration fills in "acme" for a TLS server given no
// files when [acme] is set (Default).
package certs
import (
"crypto/tls"
"errors"
"fmt"
"net/http"
"os"
"slices"
"strings"
"sync"
"time"
)
// ACME is cert_file's value for the ACME client's certificates.
const ACME = "acme"
// ALPNProto is TLS-ALPN-01's protocol (RFC 8737).
const ALPNProto = "acme-tls/1"
// IsACME reports whether a cert_file is the ACME client's.
func IsACME(certFile string) bool {
return certFile == ACME || strings.HasPrefix(certFile, ACME+":")
}
// Name is the [acme NAME] a cert_file of the ACME client's names ("" for
// "acme": the one for the name asked for, or the first).
func Name(certFile string) string {
_, n, _ := strings.Cut(certFile, ":")
return n
}
// Manager is the ACME client, as the TLS servers see it.
type Manager interface {
// Certificate is the certificate called name ("": the one for
// hello's server name, or the first).
Certificate(name string, hello *tls.ClientHelloInfo) (*tls.Certificate, error)
// Challenge is the TLS-ALPN-01 certificate for a name being
// validated now, or nil.
Challenge(serverName string) *tls.Certificate
// Has reports whether there is a certificate called name.
Has(name string) bool
}
var (
mu sync.RWMutex
mgr Manager
)
// SetManager makes m the ACME client the servers use (nil: none).
func SetManager(m Manager) {
mu.Lock()
mgr = m
mu.Unlock()
}
func manager() Manager {
mu.RLock()
defer mu.RUnlock()
return mgr
}
// Default is the cert_file and key_file a TLS server uses: those given, or
// the ACME client's when neither is and acme is on.
func Default(certFile, keyFile string, acme bool) (string, string) {
if certFile == "" && keyFile == "" && acme {
return ACME, ""
}
return certFile, keyFile
}
// Check tells whether a cert_file and key_file will do: both given and
// loading, or the ACME client's (acmeNames: the [acme NAME]s there are,
// nil: no [acme]).
func Check(certFile, keyFile string, acmeNames []string) error {
if IsACME(certFile) {
if acmeNames == nil {
return errors.New("cert_file = acme needs an [acme] section")
}
if n := Name(certFile); n != "" && !slices.Contains(acmeNames, n) {
return fmt.Errorf("cert_file = %s: there is no [acme %s]", certFile, n)
}
return nil
}
if certFile == "" || keyFile == "" {
return errors.New("needs cert_file and key_file (or an [acme] section)")
}
_, err := tls.LoadX509KeyPair(certFile, keyFile)
return err
}
// Source is a server's certificate, as GetCertificate wants it.
type Source struct {
CertFile, KeyFile string
mu sync.Mutex
cert *tls.Certificate
mod time.Time
checked time.Time
}
// New is the certificate named by cert_file and key_file, loaded now if
// they are files.
func New(certFile, keyFile string) (*Source, error) {
s := &Source{CertFile: certFile, KeyFile: keyFile}
if IsACME(certFile) {
if manager() == nil {
return nil, errors.New("cert_file = acme, but the ACME client is not running")
}
return s, nil
}
if _, err := s.file(); err != nil {
return nil, err
}
return s, nil
}
// GetCertificate is the certificate for hello.
func (s *Source) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error) {
if IsACME(s.CertFile) {
m := manager()
if m == nil {
return nil, errors.New("no ACME client")
}
return m.Certificate(Name(s.CertFile), hello)
}
return s.file()
}
// file is the certificate from the files, read again when cert_file has
// changed (looked at no more than every few seconds); the last good one
// stays while a new one does not load.
func (s *Source) file() (*tls.Certificate, error) {
s.mu.Lock()
defer s.mu.Unlock()
now := time.Now()
if s.cert != nil && now.Sub(s.checked) < 5*time.Second {
return s.cert, nil
}
s.checked = now
fi, err := os.Stat(s.CertFile)
if err == nil && s.cert != nil && fi.ModTime().Equal(s.mod) {
return s.cert, nil
}
c, err := tls.LoadX509KeyPair(s.CertFile, s.KeyFile)
if err != nil {
if s.cert != nil {
return s.cert, nil
}
return nil, err
}
s.cert = &c
if fi != nil {
s.mod = fi.ModTime()
}
return s.cert, nil
}
// Config is TLS 1.2 and later with the certificate from cert_file and
// key_file; it also answers TLS-ALPN-01 challenges for the ACME client.
// The caller may change the rest (MinVersion, CipherSuites, NextProtos).
func Config(certFile, keyFile string) (*tls.Config, error) {
s, err := New(certFile, keyFile)
if err != nil {
return nil, err
}
return s.Config(), nil
}
// Config is s as a TLS configuration (see the function Config).
func (s *Source) Config() *tls.Config {
return &tls.Config{MinVersion: tls.VersionTLS12, GetCertificate: s.GetCertificate,
GetConfigForClient: challengeConfig}
}
// challengeConfig answers a CA's TLS-ALPN-01 validation: a client asking
// only for acme-tls/1, for a name being validated now.
func challengeConfig(hello *tls.ClientHelloInfo) (*tls.Config, error) {
if !slices.Contains(hello.SupportedProtos, ALPNProto) {
return nil, nil
}
m := manager()
if m == nil {
return nil, nil
}
c := m.Challenge(hello.ServerName)
if c == nil {
return nil, nil
}
return &tls.Config{Certificates: []tls.Certificate{*c}, NextProtos: []string{ALPNProto},
MinVersion: tls.VersionTLS12}, nil
}
// ChallengePath is where HTTP-01 is answered (RFC 8555 8.3).
const ChallengePath = "/.well-known/acme-challenge/"
// WrapHTTP answers the ACME client's HTTP-01 challenges on a web server of
// the BBS's, before next sees the request.
func WrapHTTP(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, ChallengePath) {
if h, ok := manager().(http.Handler); ok {
h.ServeHTTP(w, r)
return
}
}
next.ServeHTTP(w, r)
})
}
+123
View File
@@ -0,0 +1,123 @@
package certs
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"math/big"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"time"
)
func writePair(t *testing.T, dir, cn string) (string, string) {
t.Helper()
key, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
tmpl := &x509.Certificate{SerialNumber: big.NewInt(time.Now().UnixNano()), Subject: pkix.Name{CommonName: cn},
NotBefore: time.Now().Add(-time.Hour), NotAfter: time.Now().Add(time.Hour), DNSNames: []string{cn}}
der, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, &key.PublicKey, key)
if err != nil {
t.Fatal(err)
}
kd, _ := x509.MarshalECPrivateKey(key)
crt, k := filepath.Join(dir, "c.pem"), filepath.Join(dir, "k.pem")
os.WriteFile(k, pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: kd}), 0o600)
os.WriteFile(crt, pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: der}), 0o644)
return crt, k
}
type fakeManager struct{ cert, challenge *tls.Certificate }
func (f fakeManager) Certificate(string, *tls.ClientHelloInfo) (*tls.Certificate, error) {
return f.cert, nil
}
func (f fakeManager) Challenge(string) *tls.Certificate { return f.challenge }
func (f fakeManager) Has(string) bool { return true }
func (f fakeManager) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("answered"))
}
// TestFiles: a file pair is read again when it changes; a bad new one
// leaves the old in use.
func TestFiles(t *testing.T) {
dir := t.TempDir()
crt, key := writePair(t, dir, "one.example")
s, err := New(crt, key)
if err != nil {
t.Fatal(err)
}
c, _ := s.GetCertificate(nil)
if c.Leaf.Subject.CommonName != "one.example" {
t.Fatalf("%v", c.Leaf.Subject)
}
writePair(t, dir, "two.example")
os.Chtimes(crt, time.Now().Add(time.Minute), time.Now().Add(time.Minute))
s.checked = time.Time{}
if c, _ = s.GetCertificate(nil); c.Leaf.Subject.CommonName != "two.example" {
t.Errorf("not read again: %v", c.Leaf.Subject)
}
os.WriteFile(crt, []byte("junk"), 0o644)
os.Chtimes(crt, time.Now().Add(2*time.Minute), time.Now().Add(2*time.Minute))
s.checked = time.Time{}
if c, err = s.GetCertificate(nil); err != nil || c.Leaf.Subject.CommonName != "two.example" {
t.Errorf("bad file: %v %v", c, err)
}
if _, err := New(filepath.Join(dir, "none"), key); err == nil {
t.Error("no error for a missing file")
}
}
// TestACME: cert_file = acme goes to the manager, and TLS-ALPN-01 is
// answered only for a client asking for acme-tls/1 alone.
func TestACME(t *testing.T) {
if Check("acme", "", nil) == nil || Check("acme:x", "", []string{"default"}) == nil || Check("acme:x", "", []string{"x"}) != nil {
t.Error("Check")
}
if c, k := Default("", "", true); c != "acme" || k != "" {
t.Error("Default")
}
if c, _ := Default("", "", false); c != "" {
t.Error("Default without acme")
}
SetManager(nil)
if _, err := New("acme", ""); err == nil {
t.Error("acme with no manager")
}
dir := t.TempDir()
crt, key := writePair(t, dir, "bbs.example")
pair, _ := tls.LoadX509KeyPair(crt, key)
crt2, key2 := writePair(t, t.TempDir(), "challenge")
ch, _ := tls.LoadX509KeyPair(crt2, key2)
SetManager(fakeManager{cert: &pair, challenge: &ch})
defer SetManager(nil)
cfg, err := Config("acme", "")
if err != nil {
t.Fatal(err)
}
if c, _ := cfg.GetCertificate(&tls.ClientHelloInfo{ServerName: "bbs.example"}); c != &pair {
t.Error("not the manager's")
}
if c, _ := cfg.GetConfigForClient(&tls.ClientHelloInfo{SupportedProtos: []string{"h2"}}); c != nil {
t.Error("challenge config for an ordinary client")
}
c, _ := cfg.GetConfigForClient(&tls.ClientHelloInfo{ServerName: "bbs.example", SupportedProtos: []string{ALPNProto}})
if c == nil || c.NextProtos[0] != ALPNProto || len(c.Certificates) != 1 {
t.Errorf("challenge config %+v", c)
}
h := WrapHTTP(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("site")) }))
for path, want := range map[string]string{"/.well-known/acme-challenge/x": "answered", "/": "site"} {
w := httptest.NewRecorder()
h.ServeHTTP(w, httptest.NewRequest("GET", path, nil))
if w.Body.String() != want {
t.Errorf("%s: %q", path, w.Body.String())
}
}
}
+18
View File
@@ -318,6 +318,7 @@ func (e *Editor) servicesMenu() page {
e.single("FTP", "ftp"),
menu("News (NNTP)", e.onOff(sec("nntp")), func() error { return e.show(e.newsPage()) }),
menu("Web: API, forum, image boards", e.onOff(sec("http")), func() error { return e.show(e.webPage()) }),
menu("Certificates (ACME)", e.onOff(sec("acme")), func() error { return e.show(e.acmePage()) }),
}
}}
}
@@ -448,6 +449,23 @@ func (e *Editor) timeMenu() page {
}}
}
// acmePage is Certificates (ACME): the ACME client, and its [acme NAME]
// certificates.
func (e *Editor) acmePage() page {
named := func(s confedit.Section) bool { return s.Name != "" }
return page{title: "Certificates (ACME)", items: func() []item {
out := []item{e.enabled(sec("acme"), "ACME client")}
out = append(out, e.sectionFields(sec("acme"))...)
out = append(out, heading("More certificates"), menu("Certificates", e.count("acme", named, "certificate"), func() error {
return e.show(e.listPage("Certificates", "acme", "certificate", named, func(s confedit.Section) string {
d, _ := e.doc.Get(s, "domains")
return d
}, map[string]string{"domains": "mail.example.org"}))
}))
return out
}}
}
// tn3270Page is TN3270: the 3270 pictures and logo, and the tn3270 key of
// each telnet listener.
func (e *Editor) tn3270Page() page {
+3 -2
View File
@@ -11,6 +11,7 @@ import (
"time"
"github.com/D-Modem/bbs/internal/bbs"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/sockets"
)
@@ -40,11 +41,11 @@ func tlsConfig(set ServerSettings) (*tls.Config, error) {
if set.TLS == "" || set.TLS == TLSNo {
return nil, nil
}
cert, err := tls.LoadX509KeyPair(set.CertFile, set.KeyFile)
cfg, err := certs.Config(set.CertFile, set.KeyFile)
if err != nil {
return nil, fmt.Errorf("certificate: %w", err)
}
return &tls.Config{Certificates: []tls.Certificate{cert}, MinVersion: tls.VersionTLS12}, nil
return cfg, nil
}
// isUnix reports whether an address is a unix socket's path.
+3 -2
View File
@@ -24,6 +24,7 @@ import (
"github.com/spf13/afero"
"github.com/D-Modem/bbs/internal/bbs"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/files"
"github.com/D-Modem/bbs/internal/sockets"
"github.com/D-Modem/bbs/internal/store"
@@ -72,11 +73,11 @@ func New(b *bbs.BBS, set Settings) (*Server, error) {
}
s := &Server{B: b, Set: set, perIP: map[string]int{}}
if set.TLS != TLSNo {
cert, err := tls.LoadX509KeyPair(set.CertFile, set.KeyFile)
cfg, err := certs.Config(set.CertFile, set.KeyFile)
if err != nil {
return nil, fmt.Errorf("ftp: certificate: %w", err)
}
s.tlsConfig = &tls.Config{Certificates: []tls.Certificate{cert}, MinVersion: tls.VersionTLS12}
s.tlsConfig = cfg
}
return s, nil
}
+22 -5
View File
@@ -19,6 +19,7 @@ import (
"unicode/utf8"
"github.com/D-Modem/bbs/internal/bbs"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/finger"
"github.com/D-Modem/bbs/internal/gopher"
"github.com/D-Modem/bbs/internal/sockets"
@@ -63,23 +64,39 @@ const (
const MaxRequest = 1024
// Run listens until ctx is done.
// The certificate is its own pinned one (bbs gemini cert), or with
// cert_file = acme the ACME client's.
func (s *Server) Run(ctx context.Context) error {
cert, err := LoadCert(s.S.CertFile, s.S.KeyFile)
if err != nil {
return fmt.Errorf("gemini: %w", err)
var cfg *tls.Config
if certs.IsACME(s.S.CertFile) {
c, err := certs.Config(s.S.CertFile, s.S.KeyFile)
if err != nil {
return fmt.Errorf("gemini: %w", err)
}
cfg = c
} else {
cert, err := LoadCert(s.S.CertFile, s.S.KeyFile)
if err != nil {
return fmt.Errorf("gemini: %w", err)
}
cfg = &tls.Config{Certificates: []tls.Certificate{cert}, MinVersion: tls.VersionTLS12}
}
ln, err := sockets.Listen("tcp", s.S.Address)
if err != nil {
return fmt.Errorf("gemini: %w", err)
}
return s.Serve(ctx, ln, cert)
return s.serve(ctx, ln, cfg)
}
// Serve answers on ln, with TLS by cert, until ctx is done.
func (s *Server) Serve(ctx context.Context, ln net.Listener, cert tls.Certificate) error {
return s.serve(ctx, ln, &tls.Config{Certificates: []tls.Certificate{cert}, MinVersion: tls.VersionTLS12})
}
func (s *Server) serve(ctx context.Context, ln net.Listener, cfg *tls.Config) error {
s.g = &gopher.Server{B: s.B, S: gopher.Settings{Areas: s.S.Areas, Files: s.S.Files}}
s.f = &finger.Server{B: s.B, S: finger.Settings{Users: true}}
tl := tls.NewListener(ln, &tls.Config{Certificates: []tls.Certificate{cert}, MinVersion: tls.VersionTLS12})
tl := tls.NewListener(ln, cfg)
ts := &tcpserv.Server{Name: "gemini", MaxClients: s.S.MaxClients, MaxPerIP: s.S.MaxPerIP,
Refuse: func(c net.Conn) bool { return s.B.Refuse("gemini", c.RemoteAddr()) },
Timeout: 5 * time.Minute, Log: s.B.Log, Handle: s.handle,
+4 -3
View File
@@ -21,6 +21,7 @@ import (
"time"
"github.com/D-Modem/bbs/internal/bbs"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/ircd/isupport"
"github.com/D-Modem/bbs/internal/sockets"
"github.com/D-Modem/bbs/internal/tcpserv"
@@ -57,7 +58,7 @@ func New(b *bbs.BBS, s Settings) (*Server, error) {
return nil, errors.New("irc: no address to listen on")
}
if s.TLSAddress != "" {
if _, err := tls.LoadX509KeyPair(s.CertFile, s.KeyFile); err != nil {
if _, err := certs.New(s.CertFile, s.KeyFile); err != nil {
return nil, fmt.Errorf("irc: certificate: %w", err)
}
}
@@ -124,13 +125,13 @@ func (s *Server) Run(ctx context.Context) error {
lns = append(lns, ln)
}
if s.S.TLSAddress != "" {
cert, err := tls.LoadX509KeyPair(s.S.CertFile, s.S.KeyFile)
cfg, err := certs.Config(s.S.CertFile, s.S.KeyFile)
if err != nil {
return fmt.Errorf("irc: certificate: %w", err)
}
ln, err := sockets.Listen("tcp", s.S.TLSAddress)
if err == nil {
ln = tls.NewListener(ln, &tls.Config{Certificates: []tls.Certificate{cert}, MinVersion: tls.VersionTLS12})
ln = tls.NewListener(ln, cfg)
}
if err != nil {
for _, l := range lns {
+3 -2
View File
@@ -27,6 +27,7 @@ import (
"time"
"github.com/D-Modem/bbs/internal/bbs"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/ircd"
"github.com/D-Modem/bbs/internal/sockets"
)
@@ -208,7 +209,7 @@ func (h *Hub) Run(ctx context.Context) error {
lns = append(lns, ln)
}
if h.S.TLSAddress != "" {
cert, err := tls.LoadX509KeyPair(h.S.CertFile, h.S.KeyFile)
cfg, err := certs.Config(h.S.CertFile, h.S.KeyFile)
if err != nil {
return fmt.Errorf("irclink: certificate: %w", err)
}
@@ -216,7 +217,7 @@ func (h *Hub) Run(ctx context.Context) error {
if err != nil {
return fmt.Errorf("irclink: %w", err)
}
lns = append(lns, tls.NewListener(ln, &tls.Config{Certificates: []tls.Certificate{cert}, MinVersion: tls.VersionTLS12}))
lns = append(lns, tls.NewListener(ln, cfg))
}
var wg sync.WaitGroup
for _, ln := range lns {
+3 -2
View File
@@ -15,6 +15,7 @@ import (
"time"
"github.com/D-Modem/bbs/internal/bbs"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/news"
"github.com/D-Modem/bbs/internal/sockets"
"github.com/D-Modem/bbs/internal/store"
@@ -58,11 +59,11 @@ type Server struct {
func NewServer(svc *Service, set ServerSettings, peers []*Peer) (*Server, error) {
s := &Server{Svc: svc, Set: set, Peers: peers, perIP: map[string]int{}, conns: map[net.Conn]bool{}}
if set.TLS != TLSNo {
cert, err := tls.LoadX509KeyPair(set.CertFile, set.KeyFile)
cfg, err := certs.Config(set.CertFile, set.KeyFile)
if err != nil {
return nil, fmt.Errorf("nntp: certificate: %w", err)
}
s.tlsConfig = &tls.Config{Certificates: []tls.Certificate{cert}, MinVersion: tls.VersionTLS12}
s.tlsConfig = cfg
}
return s, nil
}
+210
View File
@@ -0,0 +1,210 @@
package server
import (
"errors"
"fmt"
"net"
"path/filepath"
"slices"
"strings"
"github.com/D-Modem/bbs/internal/acme"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/config"
)
// acmeSection reads [acme] and its [acme NAME] certificates.
func (c *Config) acmeSection(cf *config.File) error {
var s *config.Section
var named []*config.Section
for _, sec := range cf.All("acme") {
if sec.Name == "" {
if s != nil {
return fmt.Errorf("[acme] line %d: a second [acme]", sec.Line)
}
s = sec
} else {
named = append(named, sec)
}
}
if s == nil {
if len(named) > 0 {
return fmt.Errorf("[acme %s] needs an [acme] section", named[0].Name)
}
return nil
}
a := &acme.Settings{Dir: s.String("dir", filepath.Join(c.DataDir(), "acme")), Email: s.String("email", ""),
EABKeyID: s.String("eab_kid", ""), EABHMAC: s.String("eab_hmac_key", ""),
DNSEnvFile: s.String("dns_env_file", ""), ACMEsh: s.String("acmesh", ""),
ACMEshHome: s.String("acmesh_home", ""), Hook: s.String("hook", "")}
ca := s.String("ca", "letsencrypt")
switch {
case acme.CAs[strings.ToLower(ca)] != "":
a.CA = acme.CAs[strings.ToLower(ca)]
case strings.HasPrefix(ca, "https://"), strings.HasPrefix(ca, "http://"):
a.CA = ca
default:
return fmt.Errorf("[acme] ca: %q is not a directory URL or one of letsencrypt, letsencrypt-staging, zerossl, buypass, google, sslcom", ca)
}
if (a.EABKeyID == "") != (a.EABHMAC == "") {
return errors.New("[acme] eab_kid and eab_hmac_key go together")
}
if a.CA == acme.CAs["zerossl"] && a.EABKeyID == "" && a.Email == "" {
return errors.New("[acme] ca = zerossl needs email (or eab_kid and eab_hmac_key)")
}
a.KeyType = strings.ToLower(s.String("key_type", "ec256"))
if _, ok := acme.KeyTypes[a.KeyType]; !ok {
return fmt.Errorf("[acme] key_type: %q is not ec256, ec384, rsa2048, rsa3072 or rsa4096", a.KeyType)
}
var err error
if a.RenewDays, err = s.Int("renew_days", 30, 1, 89); err != nil {
return fmt.Errorf("[acme] %w", err)
}
a.Resolvers = splitList(s.String("dns_resolvers", ""))
switch a.DNSCheck = strings.ToLower(s.String("dns_check", "authoritative")); a.DNSCheck {
case "authoritative", "no":
case "resolvers":
if len(a.Resolvers) == 0 {
return errors.New("[acme] dns_check = resolvers needs dns_resolvers")
}
default:
return fmt.Errorf("[acme] dns_check: %q is not authoritative, resolvers or no", a.DNSCheck)
}
if a.DNSWait, err = s.Seconds("dns_wait", 0, 0, 3600); err != nil {
return fmt.Errorf("[acme] %w", err)
}
defChallenge := strings.ToLower(s.String("challenge", acme.HTTP01))
defDNS := s.String("dns", "")
cert := func(sec *config.Section, name string, required bool) error {
ct := acme.Cert{Name: name, Domains: splitList(strings.ToLower(sec.String("domains", "")))}
where := "[acme]"
if sec != s {
where = "[acme " + name + "]"
}
if len(ct.Domains) == 0 {
if required {
return fmt.Errorf("%s domains: none given", where)
}
return nil
}
ct.Challenge, ct.DNS, ct.KeyType = defChallenge, defDNS, a.KeyType
if sec != s {
ct.Challenge = strings.ToLower(sec.String("challenge", defChallenge))
ct.DNS = sec.String("dns", defDNS)
ct.KeyType = strings.ToLower(sec.String("key_type", a.KeyType))
}
if _, ok := acme.KeyTypes[ct.KeyType]; !ok {
return fmt.Errorf("%s key_type: %q is not ec256, ec384, rsa2048, rsa3072 or rsa4096", where, ct.KeyType)
}
for _, d := range ct.Domains {
if strings.HasPrefix(d, "*.") && ct.Challenge != acme.DNS01 {
return fmt.Errorf("%s domains: %s, a wildcard, needs challenge = dns", where, d)
}
if strings.ContainsAny(d, "/: ") || !strings.Contains(d, ".") {
return fmt.Errorf("%s domains: %q is not a domain name", where, d)
}
}
switch ct.Challenge {
case acme.HTTP01, acme.TLSALPN01:
case acme.DNS01:
if err := acme.CheckDNS(ct.DNS); err != nil {
return fmt.Errorf("%s %w", where, err)
}
if strings.HasPrefix(ct.DNS, "acmesh:") && a.ACMEsh == "" {
return fmt.Errorf("%s dns = %s needs acmesh, acme.sh's path, in [acme]", where, ct.DNS)
}
default:
return fmt.Errorf("%s challenge: %q is not http, tls-alpn or dns", where, ct.Challenge)
}
a.Certs = append(a.Certs, ct)
return nil
}
if err := cert(s, acme.DefaultName, false); err != nil {
return err
}
for _, sec := range named {
if sec.Name == acme.DefaultName || slices.Contains(a.Names(), sec.Name) {
return fmt.Errorf("[acme %s] line %d: that name is taken", sec.Name, sec.Line)
}
if strings.ContainsAny(sec.Name, "/\\:") {
return fmt.Errorf("[acme %s]: a name without / \\ or :", sec.Name)
}
if err := cert(sec, sec.Name, true); err != nil {
return err
}
}
if len(a.Certs) == 0 {
return errors.New("[acme] domains: none given (here or in an [acme NAME])")
}
if a.Email == "" {
c.Warnings = append(c.Warnings, "[acme] has no email: the CA cannot warn of a certificate that is not being renewed")
}
a.HTTPAddress = s.String("http_address", "")
if strings.EqualFold(a.HTTPAddress, "no") {
a.HTTPAddress = ""
} else if a.HTTPAddress != "" {
if _, _, err := net.SplitHostPort(a.HTTPAddress); err != nil {
return fmt.Errorf("[acme] http_address: %v", err)
}
}
c.ACME = a
c.acmeHTTPDefault = !s.Has("http_address")
return nil
}
// acmeHTTP settles where HTTP-01 is answered, the other sections read: a
// web server of the BBS's on port 80 answers it, or else a listener of the
// ACME client's on :80 does, if a certificate uses it.
func (c *Config) acmeHTTP() {
a := c.ACME
if a == nil || !c.acmeHTTPDefault {
return
}
uses := false
for _, ct := range a.Certs {
uses = uses || ct.Challenge == acme.HTTP01
}
if !uses || c.port80() {
return
}
a.HTTPAddress = ":80"
}
// port80 reports whether a plain web server of the BBS's is on port 80
// (they answer HTTP-01 themselves).
func (c *Config) port80() bool {
on80 := func(addr string) bool {
_, p, err := net.SplitHostPort(addr)
return err == nil && p == "80"
}
if h := c.HTTP; h != nil && !h.TLS && on80(h.Address) {
return true
}
if y := c.YMSG; y != nil && on80(y.HTTPAddress) {
return true
}
return false
}
// acmeNames are the ACME certificates' names (nil: no [acme]).
func (c *Config) acmeNames() []string {
if c.ACME == nil {
return nil
}
return c.ACME.Names()
}
// tlsFiles is a TLS server's cert_file and key_file: those given, or the
// ACME client's if neither is; checked.
func (c *Config) tlsFiles(certFile, keyFile string) (string, string, error) {
certFile, keyFile = certs.Default(certFile, keyFile, c.ACME != nil)
return certFile, keyFile, certs.Check(certFile, keyFile, c.acmeNames())
}
func splitList(s string) []string {
var out []string
for _, f := range strings.FieldsFunc(s, func(r rune) bool { return r == ',' || r == ' ' || r == '\t' }) {
out = append(out, f)
}
return out
}
+102
View File
@@ -0,0 +1,102 @@
package server
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/D-Modem/bbs/internal/acme"
)
// TestACMEConfig: [acme] and [acme NAME] with their defaults; TLS servers
// with no files take the ACME client's certificates, Gemini and Yahoo
// only when told; HTTP-01's listener left to a web server on port 80;
// bad settings refused.
func TestACMEConfig(t *testing.T) {
load := func(body string) (*Config, error) {
p := filepath.Join(t.TempDir(), "bbs.conf")
os.WriteFile(p, []byte("[general]\ndatabase = /var/lib/bbs/bbs.db\n[listen telnet]\ntype = telnet\naddress = :2300\n"+body), 0600)
return Load(p)
}
c, err := load(`
[acme]
email = sysop@example.org
domains = bbs.example.org, www.example.org
[acme mail]
domains = mail.example.org
challenge = tls-alpn
key_type = rsa2048
[acme wild]
domains = *.example.org
challenge = dns
dns = cloudflare
[http]
address = :443
[irc]
tls_address = :6697
tls_cert = acme:wild
[gemini]
[nntp]
tls = implicit
`)
if err != nil {
t.Fatal(err)
}
a := c.ACME
if a.CA != acme.CAs["letsencrypt"] || a.Dir != "/var/lib/bbs/acme" || a.KeyType != "ec256" || a.RenewDays != 30 ||
a.HTTPAddress != ":80" || strings.Join(a.Names(), ",") != "default,mail,wild" {
t.Errorf("acme %+v", a)
}
if ct := a.Certs[0]; strings.Join(ct.Domains, ",") != "bbs.example.org,www.example.org" || ct.Challenge != "http" {
t.Errorf("default %+v", ct)
}
if ct := a.Certs[1]; ct.Challenge != "tls-alpn" || ct.KeyType != "rsa2048" {
t.Errorf("mail %+v", ct)
}
if c.HTTP.CertFile != "acme" || c.IRC.CertFile != "acme:wild" || c.NNTP.CertFile != "acme" {
t.Errorf("http %q irc %q nntp %q", c.HTTP.CertFile, c.IRC.CertFile, c.NNTP.CertFile)
}
if c.Gemini.CertFile != "/var/lib/bbs/gemini-cert.pem" {
t.Errorf("gemini %q: should keep its pinned certificate", c.Gemini.CertFile)
}
// a plain web server on port 80 answers HTTP-01 itself
c, err = load("[acme]\ndomains = bbs.example.org\n[http]\naddress = :80\ntls = no\n")
if err != nil || c.ACME.HTTPAddress != "" {
t.Errorf("port 80: %q %v", c.ACME.HTTPAddress, err)
}
// no HTTP-01 certificate: no listener
c, err = load("[acme]\ndomains = bbs.example.org\nchallenge = tls-alpn\n")
if err != nil || c.ACME.HTTPAddress != "" {
t.Errorf("tls-alpn: %q %v", c.ACME.HTTPAddress, err)
}
// only [acme NAME]s; Gemini told to use one
c, err = load("[acme]\nca = zerossl\nemail = a@example.org\n[acme g]\ndomains = gem.example.org\n[gemini]\ncert_file = acme:g\n")
if err != nil || c.ACME.CA != acme.CAs["zerossl"] || c.Gemini.CertFile != "acme:g" ||
!strings.Contains(strings.Join(c.Warnings, "\n"), "pin") {
t.Errorf("gemini acme: %+v %v %v", c.Gemini, c.Warnings, err)
}
for _, bad := range []string{
"[acme]\n", // no domains
"[acme]\ndomains = *.example.org\n", // wildcard over HTTP-01
"[acme]\ndomains = a.example.org\nca = nope\n", // unknown CA
"[acme]\ndomains = a.example.org\nkey_type = dsa\n",
"[acme]\ndomains = a.example.org\nchallenge = dns\n", // no provider
"[acme]\ndomains = a.example.org\nchallenge = dns\ndns = nowhere\n", // unknown provider
"[acme]\ndomains = a.example.org\nchallenge = dns\ndns = acmesh:dns_cf\n", // no acmesh
"[acme]\ndomains = a.example.org\nca = zerossl\n", // no email
"[acme]\ndomains = a.example.org\neab_kid = x\n",
"[acme]\ndomains = a.example.org\n[acme default]\ndomains = b.example.org\n",
"[acme x]\ndomains = a.example.org\n", // no [acme]
"[acme]\ndomains = a.example.org\n[irc]\ntls_address = :6697\ntls_cert = acme:none\n",
"[http]\naddress = :443\n", // TLS with no files, no [acme]
"[irc]\ntls_address = :6697\ntls_cert = acme\n", // no [acme]
"[acme]\ndomains = a.example.org\n[ymsg]\nhttps_address = :443\n", // Yahoo: never by default
} {
if _, err := load(bad); err == nil {
t.Errorf("accepted %q", bad)
}
}
}
+3
View File
@@ -106,6 +106,9 @@ func Bind(cfg *Config) ([]sockets.Socket, error) {
if t := cfg.Time; t != nil && t.NTS != nil {
addrs = append(addrs, t.NTS.Address)
}
if a := cfg.ACME; a != nil && a.HTTPAddress != "" {
addrs = append(addrs, a.HTTPAddress)
}
for _, a := range addrs {
if err := tcp(a); err != nil {
return fail(err)
+53 -45
View File
@@ -2,11 +2,8 @@ package server
import (
"bytes"
"crypto/tls"
"errors"
"fmt"
"github.com/D-Modem/bbs/internal/aol"
"github.com/D-Modem/bbs/internal/api"
"net"
"os"
"os/exec"
@@ -15,6 +12,11 @@ import (
"strings"
"time"
"github.com/D-Modem/bbs/internal/acme"
"github.com/D-Modem/bbs/internal/aol"
"github.com/D-Modem/bbs/internal/api"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/bbs"
"github.com/D-Modem/bbs/internal/config"
"github.com/D-Modem/bbs/internal/door"
@@ -57,42 +59,44 @@ type Config struct {
FTP *ftp.Settings // nil: no FTP server
FTPAdvertise string // the FTP server's address, as users are told it
News bbs.NewsSettings
MaxArticle int64
NNTP *nntp.ServerSettings // nil: no NNTP server
Peers []*nntp.Peer
Mail *email.Settings // [mail]; nil: no e-mail
MailServers []*MailServer
Fido *fido.Settings // nil: not on FidoNet
QWKNets []*qwknet.Net // [qwknet NAME]: QWK networks this is a node of
Binkp *BinkpSettings // nil: no binkp answering
Doors []*door.Door
Finger *finger.Settings // nil: no finger server
IRC *ircd.Settings // nil: no IRC server
OSCAR *oscar.Settings // nil: no AIM/ICQ server
AOL *aol.Settings // nil: no host for AOL clients
MSN *msn.Settings // nil: no MSN Messenger server
Marvel *marvel.Settings // nil: no host for the MSN (1995) client over TCP
YMSG *ymsg.Settings // nil: no Yahoo! Messenger server
MRC *mrc.Settings // nil: not on Multi Relay Chat
IRCLink *irclink.Settings // nil: not linked to an IRC network
Screens *screens.Set // nil: no screens of the sysop's
ScriptsDir string // "": no scripts
Menus map[string]*bbs.Menu
Text map[string]string // [strings]
HTTP *api.Settings // nil: no HTTP API
Chan imageboard.Settings
Gopher *gopher.Settings // nil: no gopher server
Gemini *gemini.Settings // nil: no Gemini server
Time *TimeSettings // nil: no [time], [ntp], [nts] or [ptp]
Database string
Log string // syslog, stderr, none, or a file
Listeners []*Listener
Warnings []string
Guard *guard.Guard // [security]
RunAs *sockets.Account // [general] user and group: who serve becomes, its ports bound (nil: as it is started)
MenuAuth *MenuAuth // [modemmenu]: passwords asked of modemmenu (nil: none)
Events []*events.Event
News bbs.NewsSettings
MaxArticle int64
NNTP *nntp.ServerSettings // nil: no NNTP server
Peers []*nntp.Peer
Mail *email.Settings // [mail]; nil: no e-mail
MailServers []*MailServer
Fido *fido.Settings // nil: not on FidoNet
QWKNets []*qwknet.Net // [qwknet NAME]: QWK networks this is a node of
Binkp *BinkpSettings // nil: no binkp answering
Doors []*door.Door
Finger *finger.Settings // nil: no finger server
IRC *ircd.Settings // nil: no IRC server
OSCAR *oscar.Settings // nil: no AIM/ICQ server
AOL *aol.Settings // nil: no host for AOL clients
MSN *msn.Settings // nil: no MSN Messenger server
Marvel *marvel.Settings // nil: no host for the MSN (1995) client over TCP
YMSG *ymsg.Settings // nil: no Yahoo! Messenger server
ACME *acme.Settings // nil: no ACME client; certificates are the sysop's files
MRC *mrc.Settings // nil: not on Multi Relay Chat
IRCLink *irclink.Settings // nil: not linked to an IRC network
Screens *screens.Set // nil: no screens of the sysop's
ScriptsDir string // "": no scripts
Menus map[string]*bbs.Menu
Text map[string]string // [strings]
HTTP *api.Settings // nil: no HTTP API
Chan imageboard.Settings
Gopher *gopher.Settings // nil: no gopher server
Gemini *gemini.Settings // nil: no Gemini server
Time *TimeSettings // nil: no [time], [ntp], [nts] or [ptp]
Database string
Log string // syslog, stderr, none, or a file
Listeners []*Listener
Warnings []string
Guard *guard.Guard // [security]
RunAs *sockets.Account // [general] user and group: who serve becomes, its ports bound (nil: as it is started)
MenuAuth *MenuAuth // [modemmenu]: passwords asked of modemmenu (nil: none)
Events []*events.Event
acmeHTTPDefault bool // [acme] has no http_address: acmeHTTP settles it
}
// DefaultListeners are used when the file has no [listen] section: telnet
@@ -140,6 +144,9 @@ func load(cf *config.File) (*Config, error) {
if err := c.files(cf.Get("general", "")); err != nil {
return nil, fmt.Errorf("[general] %w", err)
}
if err := c.acmeSection(cf); err != nil {
return nil, err
}
if err := c.newsSections(cf); err != nil {
return nil, err
}
@@ -223,7 +230,7 @@ func load(cf *config.File) (*Config, error) {
}
names := map[string]bool{}
for _, sec := range cf.All("listen") {
l, err := listener(sec)
l, err := listener(sec, c.acmeNames())
if err != nil {
return nil, fmt.Errorf("[listen %s] %w", sec.Name, err)
}
@@ -243,9 +250,10 @@ func load(cf *config.File) (*Config, error) {
if len(c.Listeners) == 0 {
c.Listeners = DefaultListeners()
}
c.acmeHTTP()
for _, s := range cf.Sections {
switch s.Kind {
case "general", "security", "backup", "modemmenu", "event", "listen", "ftp", "news", "nntp", "peer", "qwknet", "fido", "binkp", "link", "door", "finger", "gopher", "gemini", "time", "ntp", "nts", "ptp", "irc", "oscar", "aol", "msn", "marvel", "ymsg", "mrc", "irclink", "ircpeer", "menu", "strings", "http", "level", "chan",
case "general", "security", "acme", "backup", "modemmenu", "event", "listen", "ftp", "news", "nntp", "peer", "qwknet", "fido", "binkp", "link", "door", "finger", "gopher", "gemini", "time", "ntp", "nts", "ptp", "irc", "oscar", "aol", "msn", "marvel", "ymsg", "mrc", "irclink", "ircpeer", "menu", "strings", "http", "level", "chan",
"mail", "smarthost", "pop3", "imap", "smtp", "mx", "lmtp":
default:
return nil, fmt.Errorf("line %d: unknown section [%s]", s.Line, s.Kind)
@@ -485,7 +493,7 @@ func (c *Config) securitySection(sec *config.Section) error {
// listener reads a [listen NAME]: its type, address and options, refusing
// those its type cannot have and a tls_cert whose key does not load.
func listener(sec *config.Section) (*Listener, error) {
func listener(sec *config.Section, acmeNames []string) (*Listener, error) {
if sec.Name == "" {
return nil, errors.New("a listener needs a name: [listen NAME]")
}
@@ -561,14 +569,14 @@ func listener(sec *config.Section) (*Listener, error) {
return nil, err
}
l.CertFile, l.KeyFile = sec.String("tls_cert", ""), sec.String("tls_key", "")
if (l.CertFile == "") != (l.KeyFile == "") {
return nil, errors.New("tls_cert and tls_key: both, or neither")
if (l.CertFile == "") != (l.KeyFile == "") && !certs.IsACME(l.CertFile) {
return nil, errors.New("tls_cert and tls_key: both, or neither (or tls_cert = acme)")
}
if l.CertFile != "" && (l.Kind != "telnet" && l.Kind != "raw" || l.Unix()) {
return nil, errors.New("tls_cert: only for telnet and raw listeners on a TCP port")
}
if l.CertFile != "" {
if _, err := tls.LoadX509KeyPair(l.CertFile, l.KeyFile); err != nil {
if err := certs.Check(l.CertFile, l.KeyFile, acmeNames); err != nil {
return nil, fmt.Errorf("tls_cert, tls_key: %v", err)
}
}
+5 -2
View File
@@ -83,8 +83,11 @@ func (c *Config) ftpSection(f *config.Section) error {
}
set.CertFile = f.String("cert_file", "")
set.KeyFile = f.String("key_file", "")
if set.TLS != ftp.TLSNo && (set.CertFile == "" || set.KeyFile == "") {
return errors.New("cert_file and key_file are needed for TLS (or tls = no)")
if set.TLS != ftp.TLSNo {
var err error
if set.CertFile, set.KeyFile, err = c.tlsFiles(set.CertFile, set.KeyFile); err != nil {
return fmt.Errorf("TLS %v (or tls = no)", err)
}
}
var err error
if set.Anonymous, err = f.Bool("anonymous", false); err != nil {
+4 -2
View File
@@ -28,8 +28,10 @@ func (c *Config) httpSection(s *config.Section) error {
return err
}
h.CertFile, h.KeyFile = s.String("cert_file", ""), s.String("key_file", "")
if h.TLS && (h.CertFile == "" || h.KeyFile == "") {
return errors.New("cert_file and key_file are needed for TLS (or tls = no, behind a proxy that has it)")
if h.TLS {
if h.CertFile, h.KeyFile, err = c.tlsFiles(h.CertFile, h.KeyFile); err != nil {
return fmt.Errorf("TLS %v (or tls = no, behind a proxy that has it)", err)
}
}
if h.TrustedProxies, err = api.ParseProxies(s.String("trusted_proxies", "")); err != nil {
return fmt.Errorf("trusted_proxies: %v", err)
+6
View File
@@ -8,6 +8,7 @@ import (
"path/filepath"
"strconv"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/config"
"github.com/D-Modem/bbs/internal/finger"
"github.com/D-Modem/bbs/internal/gemini"
@@ -72,6 +73,11 @@ func (c *Config) infoSections(cf *config.File) error {
g.Host = s.String("hostname", host)
g.CertFile, g.KeyFile = s.String("cert_file", ""), s.String("key_file", "")
switch {
case certs.IsACME(g.CertFile):
if err := certs.Check(g.CertFile, g.KeyFile, c.acmeNames()); err != nil {
return fmt.Errorf("[gemini] %v", err)
}
c.Warnings = append(c.Warnings, "[gemini] cert_file = acme: Gemini clients pin the certificate they first see, and a renewed one has a new key")
case g.CertFile == "" && g.KeyFile == "":
g.CertFile = filepath.Join(c.DataDir(), "gemini-cert.pem")
g.KeyFile = filepath.Join(c.DataDir(), "gemini-key.pem")
+3 -6
View File
@@ -1,7 +1,6 @@
package server
import (
"crypto/tls"
"errors"
"fmt"
"net"
@@ -39,11 +38,9 @@ func (c *Config) ircSection(cf *config.File) error {
return errors.New("address or tls_address: somewhere to listen")
}
if i.TLSAddress != "" {
if i.CertFile == "" || i.KeyFile == "" {
return errors.New("tls_address needs tls_cert and tls_key")
}
if _, err := tls.LoadX509KeyPair(i.CertFile, i.KeyFile); err != nil {
return fmt.Errorf("tls_cert, tls_key: %v", err)
var err error
if i.CertFile, i.KeyFile, err = c.tlsFiles(i.CertFile, i.KeyFile); err != nil {
return fmt.Errorf("tls_address: tls_cert, tls_key: %v", err)
}
}
var err error
+4 -2
View File
@@ -51,8 +51,10 @@ func (c *Config) irclinkSection(cf *config.File) error {
return fmt.Errorf("%s: %v", a.key, err)
}
}
if l.TLSAddress != "" && (l.CertFile == "" || l.KeyFile == "") {
return errors.New("tls_address needs tls_cert and tls_key")
if l.TLSAddress != "" {
if l.CertFile, l.KeyFile, err = c.tlsFiles(l.CertFile, l.KeyFile); err != nil {
return fmt.Errorf("tls_address: tls_cert, tls_key: %v", err)
}
}
if l.Network == "" {
l.Network = c.Settings.Name
+7 -4
View File
@@ -119,7 +119,7 @@ func (c *Config) mailSections(cf *config.File) error {
if s == nil {
continue
}
srv, err := mailServer(s, ms.kind, ms.addr, ms.tls, certFile, keyFile)
srv, err := c.mailServer(s, ms.kind, ms.addr, ms.tls, certFile, keyFile)
if err != nil {
return fmt.Errorf("[%s] %w", ms.kind, err)
}
@@ -135,7 +135,7 @@ func (c *Config) mailSections(cf *config.File) error {
}
// mailServer reads a mail server's section.
func mailServer(s *config.Section, kind, addr, tls, certFile, keyFile string) (*MailServer, error) {
func (c *Config) mailServer(s *config.Section, kind, addr, tls, certFile, keyFile string) (*MailServer, error) {
ms := &MailServer{Kind: kind, Set: email.ServerSettings{Address: s.String("address", addr),
TLS: strings.ToLower(s.String("tls", tls)), CertFile: s.String("cert_file", certFile), KeyFile: s.String("key_file", keyFile)}}
set := &ms.Set
@@ -152,8 +152,11 @@ func mailServer(s *config.Section, kind, addr, tls, certFile, keyFile string) (*
default:
return nil, fmt.Errorf("tls: %q is not no, optional, required or implicit", set.TLS)
}
if set.TLS != email.TLSNo && (set.CertFile == "" || set.KeyFile == "") {
return nil, errors.New("cert_file and key_file are needed for TLS (here or in [mail]), or tls = no")
if set.TLS != email.TLSNo {
var err error
if set.CertFile, set.KeyFile, err = c.tlsFiles(set.CertFile, set.KeyFile); err != nil {
return nil, fmt.Errorf("TLS %v (here or in [mail]), or tls = no", err)
}
}
var err error
if set.MaxClients, err = s.Int("max_clients", 64, 1, 10000); err != nil {
+5 -2
View File
@@ -50,8 +50,11 @@ func (c *Config) newsSections(cf *config.File) error {
}
set.CertFile = s.String("cert_file", "")
set.KeyFile = s.String("key_file", "")
if set.TLS != nntp.TLSNo && (set.CertFile == "" || set.KeyFile == "") {
return errors.New("[nntp] cert_file and key_file are needed for TLS")
if set.TLS != nntp.TLSNo {
var err error
if set.CertFile, set.KeyFile, err = c.tlsFiles(set.CertFile, set.KeyFile); err != nil {
return fmt.Errorf("[nntp] TLS %v", err)
}
}
switch r := strings.ToLower(s.String("read", "anyone")); r {
case "anyone":
+3 -3
View File
@@ -41,6 +41,7 @@ import (
"golang.org/x/crypto/ssh"
"github.com/D-Modem/bbs/internal/bbs"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/cis"
"github.com/D-Modem/bbs/internal/marvel"
"github.com/D-Modem/bbs/internal/sockets"
@@ -173,7 +174,7 @@ func (s *Server) Run(ctx context.Context) error {
// from those bound before root was given up, or made now).
func (s *Server) listen(l *Listener) (net.Listener, error) {
if l.CertFile != "" {
cert, err := tls.LoadX509KeyPair(l.CertFile, l.KeyFile)
cfg, err := certs.Config(l.CertFile, l.KeyFile)
if err != nil {
return nil, fmt.Errorf("tls: %w", err)
}
@@ -181,8 +182,7 @@ func (s *Server) listen(l *Listener) (net.Listener, error) {
if err != nil {
return nil, err
}
return tls.NewListener(ln, &tls.Config{Certificates: []tls.Certificate{cert},
MinVersion: tls.VersionTLS12}), nil
return tls.NewListener(ln, cfg), nil
}
if !l.Unix() {
return sockets.Listen("tcp", l.Address)
+3 -7
View File
@@ -1,7 +1,6 @@
package server
import (
"crypto/tls"
"errors"
"fmt"
"net"
@@ -105,13 +104,10 @@ func (c *Config) timeSections(cf *config.File) error {
if _, _, err := net.SplitHostPort(k.Address); err != nil {
return fmt.Errorf("address: %v", err)
}
if k.CertFile == "" || k.KeyFile == "" {
return errors.New("tls_cert and tls_key: NTS-KE is TLS")
}
if _, err := tls.LoadX509KeyPair(k.CertFile, k.KeyFile); err != nil {
return fmt.Errorf("tls_cert, tls_key: %v", err)
}
var err error
if k.CertFile, k.KeyFile, err = c.tlsFiles(k.CertFile, k.KeyFile); err != nil {
return fmt.Errorf("NTS-KE is TLS: tls_cert, tls_key: %v", err)
}
if k.MaxClients, err = ks.Int("max_clients", 64, 1, 10000); err != nil {
return err
}
+4 -4
View File
@@ -1,12 +1,12 @@
package server
import (
"crypto/tls"
"errors"
"fmt"
"net"
"strings"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/config"
"github.com/D-Modem/bbs/internal/ymsg"
)
@@ -34,10 +34,10 @@ func (c *Config) ymsgSection(cf *config.File) error {
return errors.New("address: where the pager listens (:5050)")
}
if y.HTTPSAddress != "" {
if y.CertFile == "" || y.KeyFile == "" {
return errors.New("https_address needs tls_cert and tls_key")
if y.CertFile == "" || y.KeyFile == "" && !certs.IsACME(y.CertFile) {
return errors.New("https_address needs tls_cert and tls_key (one for login.yahoo.com: not a name a CA will sign for this host)")
}
if _, err := tls.LoadX509KeyPair(y.CertFile, y.KeyFile); err != nil {
if err := certs.Check(y.CertFile, y.KeyFile, c.acmeNames()); err != nil {
return fmt.Errorf("tls_cert, tls_key: %v", err)
}
}
+9
View File
@@ -14,6 +14,7 @@ import (
"sync"
"time"
"github.com/D-Modem/bbs/internal/certs"
"github.com/facebook/time/ntp/ntske"
ntp "github.com/facebook/time/ntp/protocol"
)
@@ -93,6 +94,14 @@ type KEServer struct {
// TLSConfig is the server's TLS: 1.3, ntske/1, the certificate read again
// when its file changes (a renewal).
func (s *KEServer) TLSConfig() (*tls.Config, error) {
if certs.IsACME(s.CertFile) {
src, err := certs.New(s.CertFile, s.KeyFile)
if err != nil {
return nil, err
}
return &tls.Config{MinVersion: tls.VersionTLS13, NextProtos: []string{alpn},
GetCertificate: src.GetCertificate}, nil
}
if _, err := s.certificate(); err != nil {
return nil, err
}
+6 -5
View File
@@ -12,6 +12,7 @@ import (
"time"
"github.com/D-Modem/bbs/internal/bbs"
"github.com/D-Modem/bbs/internal/certs"
"github.com/D-Modem/bbs/internal/sockets"
)
@@ -35,7 +36,7 @@ func (s *Server) serveWeb(ctx context.Context) error {
if cfg != nil {
ln = tls.NewListener(ln, cfg)
}
hs := &http.Server{Handler: s, ReadHeaderTimeout: 30 * time.Second, WriteTimeout: time.Minute,
hs := &http.Server{Handler: certs.WrapHTTP(s), ReadHeaderTimeout: 30 * time.Second, WriteTimeout: time.Minute,
ErrorLog: nil}
srvs = append(srvs, hs)
go func() {
@@ -51,11 +52,11 @@ func (s *Server) serveWeb(ctx context.Context) error {
}
}
if s.S.HTTPSAddress != "" {
cert, err := tls.LoadX509KeyPair(s.S.CertFile, s.S.KeyFile)
src, err := certs.New(s.S.CertFile, s.S.KeyFile)
if err != nil {
return fmt.Errorf("ymsg: tls_cert, tls_key: %w", err)
}
if err := start(s.S.HTTPSAddress, tlsConfig(cert)); err != nil {
if err := start(s.S.HTTPSAddress, tlsConfig(src.GetCertificate)); err != nil {
return err
}
}
@@ -75,8 +76,8 @@ func (s *Server) serveWeb(ctx context.Context) error {
// tlsConfig takes the old clients: Windows XP's TLS 1.0, with RSA key
// exchange and 3DES or RC4 (all it has), as well as current ones.
func tlsConfig(cert tls.Certificate) *tls.Config {
return &tls.Config{Certificates: []tls.Certificate{cert}, MinVersion: tls.VersionTLS10,
func tlsConfig(get func(*tls.ClientHelloInfo) (*tls.Certificate, error)) *tls.Config {
return &tls.Config{GetCertificate: get, MinVersion: tls.VersionTLS10,
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
+1 -1
View File
@@ -619,7 +619,7 @@ func TestOldTLS(t *testing.T) {
t.Fatal(err)
}
cert := tls.Certificate{Certificate: [][]byte{der}, PrivateKey: key}
ln, err := tls.Listen("tcp", "127.0.0.1:0", tlsConfig(cert))
ln, err := tls.Listen("tcp", "127.0.0.1:0", tlsConfig(func(*tls.ClientHelloInfo) (*tls.Certificate, error) { return &cert, nil }))
if err != nil {
t.Fatal(err)
}
+1
View File
@@ -62,4 +62,5 @@ nav:
- "HTTP API": HTTP-API.md
- More:
- "Security": Security.md
- "Certificates (ACME)": Certificates.md
- "Development": Development.md