fix: scope server pins by port (fumi-core rev 1468f3c)

This commit is contained in:
randogoth 2026-09-30 08:52:57 +03:00
parent 996e879509
commit 7d2a147fec
16 changed files with 109 additions and 79 deletions

View file

@ -144,7 +144,7 @@ class SmolClient {
// registration and fetching demand it anyway (sec 4), so restoring is
// stopped at the pin step rather than letting the account bind to a
// server whose key nobody verified.
if (store.serverPin(addr.host) == null) {
if (store.serverPin(addr.host, addr.port) == null) {
throw SmolError("no pinned key for ${addr.host}. Obtain it from the "
"operator through a trusted channel, then pin it in settings.");
}
@ -157,7 +157,8 @@ class SmolClient {
}
}
void pinServer(String host, String keyB32) => store.pinServer(host, keyB32);
void pinServer(String host, String keyB32, int port) =>
store.pinServer(host, keyB32, port);
Future<void> registerAccount(String addressText, {String token = ""}) async {
final addr = parseAddress(addressText);

View file

@ -9,6 +9,7 @@
// removable in settings like any other, and never overwrites a host the user
// (or a previous install) already pinned.
import "package:smol_mail/smol/address.dart";
import "package:smol_mail/smol/store.dart";
const _presetHost = String.fromEnvironment("SMOL_PRESET_SERVER");
@ -16,7 +17,7 @@ const _presetKey = String.fromEnvironment("SMOL_PRESET_SERVER_KEY");
void applyPresetServer(SmolStore store) {
if (_presetHost.isEmpty || _presetKey.isEmpty) return;
if (store.serverPin(_presetHost) != null) return;
if (store.serverPin(_presetHost, defaultPort) != null) return;
// A malformed preset leaves the host unpinned rather than blocking boot.
store.pinServer(_presetHost, _presetKey);
store.pinServer(_presetHost, _presetKey, defaultPort);
}

View file

@ -291,10 +291,11 @@ class SmolStore {
// --- pins -------------------------------------------------------------------
/// Pins a server's static key (§4): sync, because it is one local write.
void pinServer(String host, String keyB32) =>
_ffi.pinServer(_native.store!, host, keyB32);
void pinServer(String host, String keyB32, int port) =>
_ffi.pinServer(_native.store!, host, keyB32, port);
String? serverPin(String host) => _ffi.serverPin(_native.store!, host);
String? serverPin(String host, int port) =>
_ffi.serverPin(_native.store!, host, port);
List<(String, String)> allPins() {
final rows = _ffi.pins(_native.store!);
@ -304,7 +305,8 @@ class SmolStore {
];
}
Future<void> unpinServer(String host) async => _native.unpinServer(host);
Future<void> unpinServer(String host, int port) async =>
_native.unpinServer(host, port);
// --- backups ----------------------------------------------------------------