1
0
Files
electrum/electrum
SomberNight 02a9ab80be interface: nicer error for CA-signed "Hostname mismatch" certs
Previously when encountering a CA-signed cert that failed verification with "Hostname mismatch",
we would
1. erroneously mark it as self-signed
2. save its cert to pin it
3. when connecting to it later, and being served a CA-signed cert, we would reject the connection
  - I think this is because we use the saved cert (the peer cert, just the last cert in the chain) as if it was a root CA,
    and then during the connection we try to verify against that root. This fails as we are served a different root then.
Error logged in step(3):
```
  3.85 | W | i/interface.[wirg2tsto7rme7n26lkd3ivbvxmjyy2pktlozwjuep22jcsfsghfqbqd.onion:50002] | Cannot connect to main server due to SSL error (maybe cert changed compared to "/home/user/.electrum/testnet/certs/wirg2tsto7rme7n26lkd3ivbvxmjyy2pktlozwjuep22jcsfsghfqbqd.onion"). Exc: ConnectError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)'))
```

This commit fixes step(1), we won't mark the cert as self-signed, instead the error is propagated out and the connection closed.
```
 35.05 | I | i/interface.[wirg2tsto7rme7n26lkd3ivbvxmjyy2pktlozwjuep22jcsfsghfqbqd.onion:50002] | disconnecting due to: ErrorGettingSSLCertFromServer(ConnectError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'wirg2tsto7rme7n26lkd3ivbvxmjyy2pktlozwjuep22jcsfsghfqbqd.onion'. (_ssl.c:1007)")))
```

Compare:
- SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'wirg2tsto7rme7n26lkd3ivbvxmjyy2pktlozwjuep22jcsfsghfqbqd.onion'. (_ssl.c:1007)")
  - verify_code=62
- SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1007)')
  - verify_code=18

Note: the verify_code constants look stable, though they might be openssl-specific. I guess that's ok(?)
140540189c/include/openssl/x509_vfy.h.in (L224)
2024-06-07 14:56:03 +00:00
..
2022-07-07 18:29:01 +02:00
2024-05-15 20:41:01 +08:00
2022-10-20 18:43:54 +00:00
2024-05-30 13:08:13 +00:00
2023-09-09 14:14:43 +02:00
2024-03-05 23:30:23 +01:00
2024-06-04 18:29:17 +00:00
2024-05-27 17:12:33 +00:00
2024-04-17 14:36:21 +00:00
2024-02-12 18:26:08 +00:00
2024-04-24 14:14:31 +00:00
2023-02-17 11:43:11 +00:00
2021-07-15 14:52:25 +00:00
2024-06-04 18:29:17 +00:00
2023-02-17 11:43:11 +00:00
2024-06-04 13:42:57 +00:00
2024-01-22 03:27:20 +00:00
2021-03-21 00:36:23 -04:00
2022-10-31 16:13:22 +00:00
2024-05-22 15:26:26 +00:00
2023-04-24 12:58:26 +00:00
2022-10-31 16:13:22 +00:00
2024-04-24 14:14:31 +00:00
2024-03-01 11:21:49 +01:00
2022-11-18 23:13:25 +01:00
2024-05-20 16:57:11 +02:00
2023-12-04 14:15:39 +08:00
2023-05-25 17:39:48 +00:00
2024-05-22 15:26:26 +00:00