mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
tls_cert = ca ([msn], [ymsg], [oscar]) and cert_file = ca ([gemini]) have the BBS's CA sign the server's certificate for the names its clients ask for: bbs serve makes the CA if there is none, signs at start and looks daily, keeping keys across renewals (Gemini's good as long as the CA, as its clients pin). RSA 2048 throughout; bbs ca init -sha1 for Windows before XP SP3. bbs ca issue signs a certificate for a TLS proxy; bbs ca package (and serve, into ca/install-ca.zip) writes what puts the CA on callers' machines: the .cer, an .inf and .reg writing the machine's trusted roots (Windows 95 on), remove-ca.reg, an install .bat (certutil), a macOS/iOS .mobileconfig, the PEM and a README with the fingerprint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRTuaG98f8wiWHbNhPo
109 lines
3.7 KiB
Go
109 lines
3.7 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.IsCA(g.CertFile):
|
|
// signed by the BBS's CA for hostname when the BBS starts
|
|
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
|
|
}
|