mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
[acme] gets certificates from Let's Encrypt, ZeroSSL or any ACME CA and renews them before they run out, in the manner of acme.sh, built on lego (MIT). [acme NAME] adds more. HTTP-01 (its own port 80 listener or the BBS's web server there), TLS-ALPN-01 (any TLS server of the BBS on 443) and DNS-01 (15 providers built in, exec:PROGRAM, or acme.sh's own dnsapi scripts through acmesh:dns_xx) are supported; renewal follows renew_days and the CA's ARI; a hook runs after each new certificate. internal/certs is where every TLS server now gets its certificate: a file pair read again when it changes, or the ACME client's (cert_file = acme or acme:NAME, and by default when a TLS server has no files and [acme] is set). Gemini keeps its pinned certificate and Yahoo its login.yahoo.com one unless told. bbs acme list / renew, bbs check lists them, a Certificates page in the configurator, the sample config, Configuration Reference and a new Certificates wiki page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRSjWGPJDHVw7cyWKvE
107 lines
3.6 KiB
Go
107 lines
3.6 KiB
Go
package server
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net"
|
|
"os"
|
|
"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"
|
|
"github.com/D-Modem/bbs/internal/gopher"
|
|
)
|
|
|
|
// infoSections reads [finger], [gopher] and [gemini].
|
|
func (c *Config) infoSections(cf *config.File) error {
|
|
var err error
|
|
if s := cf.Get("finger", ""); s != nil {
|
|
f := &finger.Settings{Address: s.String("address", ":79")}
|
|
if _, _, err := net.SplitHostPort(f.Address); err != nil {
|
|
return fmt.Errorf("[finger] address: %v", err)
|
|
}
|
|
if f.Online, err = s.Bool("online", true); err != nil {
|
|
return fmt.Errorf("[finger] %w", err)
|
|
}
|
|
if f.Users, err = s.Bool("users", true); err != nil {
|
|
return fmt.Errorf("[finger] %w", err)
|
|
}
|
|
if f.MaxClients, err = s.Int("max_clients", 16, 1, 1000); err != nil {
|
|
return fmt.Errorf("[finger] %w", err)
|
|
}
|
|
if f.MaxPerIP, err = s.Int("max_per_ip", 4, 0, 1000); err != nil {
|
|
return fmt.Errorf("[finger] %w", err)
|
|
}
|
|
c.Finger = f
|
|
}
|
|
if s := cf.Get("gopher", ""); s != nil {
|
|
g := &gopher.Settings{Address: s.String("address", ":70")}
|
|
_, port, err := net.SplitHostPort(g.Address)
|
|
if err != nil {
|
|
return fmt.Errorf("[gopher] address: %v", err)
|
|
}
|
|
host, _ := os.Hostname()
|
|
g.Host = s.String("hostname", host)
|
|
p, _ := strconv.Atoi(port)
|
|
if g.Port, err = s.Int("port", p, 1, 65535); err != nil {
|
|
return fmt.Errorf("[gopher] %w", err)
|
|
}
|
|
g.Areas = s.String("areas", "")
|
|
if g.Files, err = s.Bool("files", false); err != nil {
|
|
return fmt.Errorf("[gopher] %w", err)
|
|
}
|
|
if g.MaxClients, err = s.Int("max_clients", 32, 1, 1000); err != nil {
|
|
return fmt.Errorf("[gopher] %w", err)
|
|
}
|
|
if g.MaxPerIP, err = s.Int("max_per_ip", 8, 0, 1000); err != nil {
|
|
return fmt.Errorf("[gopher] %w", err)
|
|
}
|
|
if g.Areas != "" || g.Files {
|
|
c.Warnings = append(c.Warnings, "[gopher] shows message or file areas to anyone, without a login")
|
|
}
|
|
c.Gopher = g
|
|
}
|
|
if s := cf.Get("gemini", ""); s != nil {
|
|
g := &gemini.Settings{Address: s.String("address", ":1965")}
|
|
if _, _, err := net.SplitHostPort(g.Address); err != nil {
|
|
return fmt.Errorf("[gemini] address: %v", err)
|
|
}
|
|
host, _ := os.Hostname()
|
|
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")
|
|
case g.CertFile == "" || g.KeyFile == "":
|
|
return errors.New("[gemini] cert_file and key_file go together (or neither, for one made by bbs gemini cert)")
|
|
}
|
|
g.Areas = s.String("areas", "")
|
|
if g.Files, err = s.Bool("files", false); err != nil {
|
|
return fmt.Errorf("[gemini] %w", err)
|
|
}
|
|
if g.Users, err = s.Bool("users", true); err != nil {
|
|
return fmt.Errorf("[gemini] %w", err)
|
|
}
|
|
if g.MaxClients, err = s.Int("max_clients", 32, 1, 1000); err != nil {
|
|
return fmt.Errorf("[gemini] %w", err)
|
|
}
|
|
if g.MaxPerIP, err = s.Int("max_per_ip", 8, 0, 1000); err != nil {
|
|
return fmt.Errorf("[gemini] %w", err)
|
|
}
|
|
if g.Areas != "" || g.Files {
|
|
c.Warnings = append(c.Warnings, "[gemini] shows message or file areas to anyone, without a login")
|
|
}
|
|
c.Gemini = g
|
|
}
|
|
return nil
|
|
}
|