feat(spv): verify the chain identity of a server on connect

After the handshake the wallet checks server.features genesis_hash and,
when the profile has checkpoints, the header at the highest checkpoint
not above the server's tip (mainnet shares Bitcoin's genesis, so the
checkpoint is what tells the chains apart). A server on another chain is
refused with WrongChainException and the next candidate is tried. Used by
the GUI, peer discovery, the CLI and the server probe. See ADR 0036.
This commit is contained in:
davide committed 2026-11-03 14:01:34 +01:00
1 parent 77f00d1b4e
commit 8bcee27c23
13 files changed
+341 -6

No files matched your search

+9
View File
@@ -467,6 +467,15 @@ public sealed class Loc
"Das TLS-Zertifikat von {0} hat sich gegenüber dem gespeicherten geändert. Wenn der Server das Zertifikat erneuert hat, setzen Sie die SSL-Zertifikate zurück.",
"{0} 的 TLS 证书与已保存的证书不同。如果服务器更新了证书,请重置 SSL 证书。"],
["msg.chain.wrong"] = [
"Il server {0} non è sulla catena Palladium (genesi o checkpoint diversi). Scegli un altro server.",
"The server {0} is not on the Palladium chain (different genesis or checkpoint). Choose another server.",
"El servidor {0} no está en la cadena Palladium (génesis o punto de control distintos). Elige otro servidor.",
"Le serveur {0} n'est pas sur la chaîne Palladium (genèse ou point de contrôle différent). Choisissez un autre serveur.",
"O servidor {0} não está na cadeia Palladium (gênese ou checkpoint diferente). Escolha outro servidor.",
"Der Server {0} befindet sich nicht auf der Palladium-Chain (anderer Genesis-Block oder Checkpoint). Wählen Sie einen anderen Server.",
"服务器 {0} 不在 Palladium 链上(创世块或检查点不同)。请选择其他服务器。"],
// Contacts
["contacts.name"] = ["Nome", "Name", "Nombre", "Nom", "Nome", "Name", "姓名"],
["contacts.address"] = ["Indirizzo", "Address", "Dirección", "Adresse", "Endereço", "Adresse", "地址"],
+18 -2
View File
@@ -215,7 +215,14 @@ public partial class MainWindowViewModel
try
{
var pins = new CertificatePinStore(AppPaths.CertificatePinsPath(Net));
_client = await ElectrumClient.ConnectAsync(h, p, UseSsl, pins, ct);
var connected = await ElectrumClient.ConnectAsync(h, p, UseSsl, pins, ct);
try { await connected.VerifyChainAsync(Profile, ct); }
catch
{
await connected.DisposeAsync();
throw;
}
_client = connected;
_client.NotificationReceived += OnServerNotification;
_client.Disconnected += _ => Dispatcher.UIThread.Post(() =>
{
@@ -428,7 +435,14 @@ public partial class MainWindowViewModel
try
{
var pins = new CertificatePinStore(AppPaths.CertificatePinsPath(Net));
temp = await ElectrumClient.ConnectAsync(h, p, UseSsl, pins);
var fresh = await ElectrumClient.ConnectAsync(h, p, UseSsl, pins);
try { await fresh.VerifyChainAsync(Profile); }
catch
{
await fresh.DisposeAsync();
throw;
}
temp = fresh;
lastError = null;
break;
}
@@ -480,6 +494,8 @@ public partial class MainWindowViewModel
{
CertificatePinMismatchException cert =>
string.Format(Loc.Tr("msg.cert.mismatch"), $"{cert.Host}:{cert.Port}"),
WrongChainException chain =>
string.Format(Loc.Tr("msg.chain.wrong"), $"{chain.Host}:{chain.Port}"),
_ => ex.Message,
};