offer to replace a saved server certificate when the new certificate has the same subject, as it fails path validation rather than path building
What changed, and why it matters
This commit improves how Sparrow Wallet handles TLS certificate changes for Electrum servers. Previously, if a server presented a new certificate with the same subject (common name) as a saved certificate, the app would not recognize it as a certificate change and would not offer to replace the saved certificate. The fix broadens the detection to include both 'path building failed' and 'path validation failed' errors, and improves user messaging when a saved certificate has expired. This is a defensive hardening change that helps users recover from legitimate certificate renewals while still warning about potential man-in-the-middle attacks.
This appears to be a defensive fix improving certificate change detection and user messaging. Users running affected versions should update to a version containing this commit if they experience TLS connection failures after legitimate server certificate renewals. No immediate emergency action is indicated, but review of the certificate pinning flow is warranted to ensure the broader detection does not introduce false positives.
Security signals we found
TLS certificate pinning logic changed
User prompt before accepting changed server certificate preserved
Detection broadened from path building to also include path validation failures
Improved UX messaging for expired certificates vs. changed certificates
No cryptographic verification logic bypassed
Evidence from the diff
The patch modifies TLS certificate error handling in Sparrow Wallet. It introduces TlsServerException.isCertificatePathFailure() which detects both ‘PKIX path building failed’ and ‘PKIX path validation failed’ exception messages. Previously only ‘PKIX path building failed’ was detected. The change propagates this broader check through AppServices, ServerSettingsController, and ServerTestDialog. Additionally, ServerTestDialog now checks if the saved certificate has expired via TcpOverTlsTransport.getExpiredAt() and presents a more specific, less alarming message when the failure may be due to certificate renewal rather than a changed certificate. The core security behavior—prompting the user before replacing a pinned certificate—remains intact.
Changed components
com.sparrowwallet.sparrow.AppServicescom.sparrowwallet.sparrow.net.TlsServerExceptioncom.sparrowwallet.sparrow.settings.ServerSettingsControllercom.sparrowwallet.sparrow.terminal.settings.ServerTestDialogInspect captured patch +19 / −7
### src/main/java/com/sparrowwallet/sparrow/AppServices.java
@@ -346,7 +346,7 @@ private ElectrumServer.ConnectionService createConnectionService() {
if(failEvent.getSource().getException() instanceof TlsServerException tlsServerException && failEvent.getSource().getException().getCause() != null) {
connectionService.setRestartOnFailure(false);
- if(tlsServerException.getCause().getMessage().contains("PKIX path building failed")) {
+ if(tlsServerException.isCertificatePathFailure()) {
File crtFile = Config.get().getElectrumServerCert();
if(crtFile != null && Config.get().getServerType() == ServerType.ELECTRUM_SERVER) {
AppServices.showErrorDialog("SSL Handshake Failed", "The configured server certificate at " + crtFile.getAbsolutePath() + " did not match the certificate provided by the server at " + tlsServerException.getServer().getHost() + "." +
### src/main/java/com/sparrowwallet/sparrow/net/TlsServerException.java
@@ -33,9 +33,18 @@ public HostAndPort getServer() {
return server;
}
+ public boolean isCertificatePathFailure() {
+ return isCertificatePathFailure(getCause());
+ }
+
+ private static boolean isCertificatePathFailure(Throwable cause) {
+ //A server certificate with the same subject as the saved certificate fails path validation rather than path building
+ return cause != null && cause.getMessage() != null && (cause.getMessage().contains("PKIX path building failed") || cause.getMessage().contains("PKIX path validation failed"));
+ }
+
private static String getMessage(Throwable cause, HostAndPort server) {
if(cause != null) {
- if(cause.getMessage().contains("PKIX path building failed")) {
+ if(isCertificatePathFailure(cause)) {
File configCrtFile = Config.get().getElectrumServerCert();
File savedCrtFile = Storage.getCertificateFile(server.getHost());
if(configCrtFile != null) {
### src/main/java/com/sparrowwallet/sparrow/settings/ServerSettingsController.java
@@ -703,7 +703,7 @@ private void showConnectionFailure(Throwable exception) {
if(exception instanceof TlsServerException && exception.getCause() != null) {
TlsServerException tlsServerException = (TlsServerException)exception;
- if(exception.getCause().getMessage().contains("PKIX path building failed")) {
+ if(tlsServerException.isCertificatePathFailure()) {
File configCrtFile = Config.get().getElectrumServerCert();
File savedCrtFile = Storage.getCertificateFile(tlsServerException.getServer().getHost());
if(savedCrtFile == null) {
### src/main/java/com/sparrowwallet/sparrow/terminal/settings/ServerTestDialog.java
@@ -19,6 +19,7 @@
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.List;
import java.util.Optional;
@@ -198,16 +199,18 @@ private void showConnectionFailure(Throwable exception) {
String reason = exception.getCause() != null ? exception.getCause().getMessage() : exception.getMessage();
if(exception instanceof TlsServerException && exception.getCause() != null) {
TlsServerException tlsServerException = (TlsServerException)exception;
- if(exception.getCause().getMessage().contains("PKIX path building failed")) {
+ if(tlsServerException.isCertificatePathFailure()) {
File configCrtFile = Config.get().getElectrumServerCert();
File savedCrtFile = Storage.getCertificateFile(tlsServerException.getServer().getHost());
if(savedCrtFile == null) {
savedCrtFile = Storage.getCaCertificateFile(tlsServerException.getServer().getHost());
}
if(configCrtFile == null && savedCrtFile != null) {
- Optional<ButtonType> optButton = AppServices.showErrorDialog("SSL Handshake Failed", "The certificate provided by the server at " + tlsServerException.getServer().getHost() + " appears to have changed." +
- "\n\nThis may indicate a man-in-the-middle attack!" +
- "\n\nDo you still want to proceed?", ButtonType.NO, ButtonType.YES);
+ Date expiredAt = TcpOverTlsTransport.getExpiredAt(savedCrtFile);
+ String problem = expiredAt != null ? "The saved certificate for the server at " + tlsServerException.getServer().getHost() + " expired at " + expiredAt + ", and the certificate the server provided could not be verified." +
+ "\n\nThis may be simply due to a certificate renewal, or it may indicate a man-in-the-middle attack."
+ : "The certificate provided by the server at " + tlsServerException.getServer().getHost() + " appears to have changed.\n\nThis may indicate a man-in-the-middle attack!";
+ Optional<ButtonType> optButton = AppServices.showErrorDialog("SSL Handshake Failed", problem + "\n\nDo you still want to proceed?", ButtonType.NO, ButtonType.YES);
if(optButton.isPresent() && optButton.get() == ButtonType.YES) {
if(savedCrtFile.delete()) {
Platform.runLater(this::startElectrumConnection);Why this scored 37/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.