prompt to accept an expired server certificate in settings test connection, and say an expired saved certificate has expired rather than changed
What changed, and why it matters
This commit improves the user experience when a Bitcoin wallet connects to a server whose security certificate has expired. It changes the warning message to clearly say 'expired' instead of 'changed' and lets users accept an expired certificate during a settings test connection. The change itself is a usability improvement, but it slightly weakens the security prompt because it makes it easier to proceed with an expired certificate.
Review whether prompting users to accept expired certificates is acceptable for your threat model. Consider requiring certificate renewal rather than allowing expired certificates to be saved, or at minimum add a stronger warning and a fingerprint comparison before saving an expired certificate. If this change is intentional, document the security trade-off in release notes.
Security signals we found
User-facing TLS certificate warning text softened from 'changed/possible MITM' to 'expired' when a saved certificate has expired
New code path allows saving an expired server certificate and continuing the connection after user confirmation
No cryptographic enforcement change: the trust decision remains delegated to the user via a dialog
No validation that the newly accepted expired certificate actually belongs to the intended server
Evidence from the diff
The patch adds a helper method getExpiredAt(File) in TcpOverTlsTransport that reads a saved X.509 certificate and returns its expiry date if it has already passed. It then uses this in AppServices.java and ServerSettingsController.java to distinguish between a genuinely changed certificate and an expired saved certificate, showing a more specific message. It also adds handling for UnknownCertificateExpiredException in ServerSettingsController, allowing the user to save the expired server certificate and retry the connection. The code still asks the user before proceeding, so it is not a silent bypass.
Changed components
src/main/java/com/sparrowwallet/sparrow/AppServices.javasrc/main/java/com/sparrowwallet/sparrow/net/TcpOverTlsTransport.javasrc/main/java/com/sparrowwallet/sparrow/settings/ServerSettingsController.javaInspect captured patch +34 / −4
### src/main/java/com/sparrowwallet/sparrow/AppServices.java
@@ -357,7 +357,10 @@ private ElectrumServer.ConnectionService createConnectionService() {
crtFile = Storage.getCaCertificateFile(tlsServerException.getServer().getHost());
}
if(crtFile != null) {
- Optional<ButtonType> optButton = AppServices.showErrorDialog("SSL Handshake Failed", "The certificate provided by the server at " + tlsServerException.getServer().getHost() + " appears to have changed." +
+ Date expiredAt = TcpOverTlsTransport.getExpiredAt(crtFile);
+ 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."
+ : "The certificate provided by the server at " + tlsServerException.getServer().getHost() + " appears to have changed.";
+ Optional<ButtonType> optButton = AppServices.showErrorDialog("SSL Handshake Failed", problem +
"\n\nThis may be simply due to a certificate renewal, or it may indicate a man-in-the-middle attack." +
"\n\nDo you still want to proceed?", ButtonType.NO, ButtonType.YES);
if(optButton.isPresent() && optButton.get() == ButtonType.YES) {
### src/main/java/com/sparrowwallet/sparrow/net/TcpOverTlsTransport.java
@@ -15,6 +15,7 @@
import java.security.cert.*;
import java.security.cert.Certificate;
import java.util.Collection;
+import java.util.Date;
import java.util.List;
public class TcpOverTlsTransport extends TcpTransport {
@@ -132,6 +133,21 @@ public void checkServerTrusted(X509Certificate[] certs, String authType) throws
return trustManagerFactory.getTrustManagers();
}
+ /**
+ * Returns the expiry date of the certificate in the given file if it has expired, otherwise null.
+ */
+ public static Date getExpiredAt(File crtFile) {
+ try(FileInputStream fis = new FileInputStream(crtFile)) {
+ if(CertificateFactory.getInstance("X.509").generateCertificate(fis) instanceof X509Certificate x509Certificate && x509Certificate.getNotAfter().before(new Date())) {
+ return x509Certificate.getNotAfter();
+ }
+ } catch(IOException | CertificateException e) {
+ log.warn("Could not read certificate at " + crtFile.getAbsolutePath(), e);
+ }
+
+ return null;
+ }
+
protected void createSocket() throws IOException {
socket = sslSocketFactory.createSocket();
socket.connect(new InetSocketAddress(server.getHost(), server.getPortOrDefault(Protocol.SSL.getDefaultPort())));
### src/main/java/com/sparrowwallet/sparrow/settings/ServerSettingsController.java
@@ -705,9 +705,11 @@ private void showConnectionFailure(Throwable exception) {
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);
@@ -717,6 +719,15 @@ private void showConnectionFailure(Throwable exception) {
}
}
}
+ } else if(exception.getCause().getCause() instanceof UnknownCertificateExpiredException expiredException) {
+ Optional<ButtonType> optButton = AppServices.showErrorDialog("SSL Handshake Failed", "The certificate provided by the server at " + tlsServerException.getServer().getHost() + " has expired. "
+ + tlsServerException.getMessage() + "." +
+ "\n\nDo you still want to proceed?", ButtonType.NO, ButtonType.YES);
+ if(optButton.isPresent() && optButton.get() == ButtonType.YES) {
+ Storage.saveCertificate(tlsServerException.getServer().getHost(), expiredException.getCertificate());
+ Platform.runLater(this::startElectrumConnection);
+ return;
+ }
}
reason = tlsServerException.getMessage() + "\n\n" + reason;Why this scored 29/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.