feat(relays): accept a self-signed certificate on a generic HTTP board

HTTPS to a relay board could not work. Nearly every board that offers it signs
its own certificate — there is no authority anywhere that could have signed it —
so the request failed verification before it left.

A checkbox, per board, off by default. Not a blanket switch, because the other
HTTPS case is real and opposite: a board reached from outside through a proxy
with a genuine certificate, where verification is the only thing standing
between an antenna switch and the internet. Same setting, two boards, different
answers.

Off by default is only safe if the failure explains itself, so a certificate
error now names the box to tick. Go's own "x509: certificate signed by unknown
authority" is accurate and tells an operator nothing about what to do next.

Shown only once an https:// URL is actually in the board's configuration. A
board on plain HTTP has no certificate to argue about, and an option that cannot
matter yet is one more thing to wonder about.

The flag joins the driver cache key: ticking it has to rebuild the driver, or
the cached one would go on refusing the certificate with the verifying client it
already holds.

The boards that take a bare host — WebSwitch, KMTronic — keep verification. An
https:// typed there is the proxy case by construction, since they default to
plain HTTP on the LAN.

Three tests against a real self-signed TLS server: accepted with the box,
refused with a message naming it without the box, and one board's setting not
leaking into another's.
This commit is contained in:
2026-08-17 10:57:29 +02:00
parent dc898ce2af
commit 0bab7f05b9
10 changed files with 193 additions and 30 deletions
+12 -2
View File
@@ -14940,6 +14940,13 @@ type StationDevice struct {
OffURLs []string `json:"off_urls,omitempty"`
OnPat string `json:"on_pattern,omitempty"` // fallback, {relay} substituted
OffPat string `json:"off_pattern,omitempty"`
// InsecureTLS accepts an HTTPS certificate that cannot be verified — which
// is the only kind a relay board on the LAN can present, having signed it
// itself. Off by default, because the other HTTPS case is the opposite one:
// a board reached from outside through a proxy with a real certificate,
// where verification is what stands between an antenna switch and the
// internet.
InsecureTLS bool `json:"insecure_tls,omitempty"`
}
// deviceRelayCount is the relay count for a configured device — fixed by type,
@@ -15000,7 +15007,7 @@ func buildDeviceDriver(d StationDevice) relaydev.Device {
// generic board fall through to the WebSwitch driver below: it answered
// the WebSwitch's own address, never sent one configured URL, and
// reported itself offline so every relay button stayed greyed out.
return relaydev.NewHTTPGeneric(d.OnURLs, d.OffURLs, d.OnPat, d.OffPat, d.User, d.Pass, deviceRelayCount(d), d.Labels)
return relaydev.NewHTTPGeneric(d.OnURLs, d.OffURLs, d.OnPat, d.OffPat, d.User, d.Pass, deviceRelayCount(d), d.Labels, d.InsecureTLS)
default:
return relaydev.NewWebswitch(d.Host)
}
@@ -15020,7 +15027,10 @@ func deviceKey(d StationDevice) string {
// The labels are part of the wire format here: {value} sends them.
// Renaming a relay re-addresses it, and the cached driver would keep
// commanding the old name.
"|" + strings.Join(d.Labels, "\x1f")
"|" + strings.Join(d.Labels, "\x1f") +
// Ticking the box has to rebuild the driver: the cached one holds the
// verifying client and would go on refusing the certificate.
fmt.Sprintf("|%t", d.InsecureTLS)
}
return k
}