local switch: Implement shared-secret feature

This allows for a “shared secret” to be entered for a network switch,
segmenting traffic so that multiple people could use the feature
simultaneously without accidentally entering into or interfering with
each other's networks.

Takes a string specified in the configuration file (using the
net_%02i_secret key) and hashes it through SHA3-256 to prepend to each
data packet.  This hash is used to compare packets on reception and
allow or discard them.
This commit is contained in:
Mike Swanson
2026-02-09 19:06:45 -08:00
parent ad235874c7
commit f3d22bbef3
4 changed files with 538 additions and 4 deletions

View File

@@ -915,6 +915,11 @@ load_network(void)
if (nc->switch_group < NET_SWITCH_GRP_MIN)
nc->switch_group = NET_SWITCH_GRP_MIN;
sprintf(temp, "net_%02i_secret", c + 1);
p = ini_section_get_string(cat, temp, NULL);
strncpy(nc->secret, p ? p : "", sizeof(nc->secret) - 1);
nc->secret[sizeof(net_cards_conf[c].secret) - 1] = '\0';
sprintf(temp, "net_%02i_promisc", c + 1);
nc->promisc_mode = ini_section_get_int(cat, temp, 0);
@@ -3025,6 +3030,12 @@ save_network(void)
else
ini_section_set_int(cat, temp, nc->switch_group);
sprintf(temp, "net_%02i_secret", c + 1);
if (nc->secret[0] == '\0')
ini_section_delete_var(cat, temp);
else
ini_section_set_string(cat, temp, net_cards_conf[c].secret);
sprintf(temp, "net_%02i_promisc", c + 1);
if (nc->promisc_mode == 0)
ini_section_delete_var(cat, temp);