git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 2/3] imap-send: let OpenSSL do the hostname verification

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 19, 2026, 06:39 UTC
Message-ID
<atW7DJZwHYK_hABy@pks.im>
In-Reply-To
<20261017100956.529225-2-dev+git@drbeat.li>
On Sat, Oct 17, 2026 at 12:09:55PM +0200, Beat Bolli wrote:
Show 21 quoted lines
> imap-send performs its own TLS hostname verification. This is not ideal
> because it does not support all certificate features.
> 
> Let's use OpenSSL built-in verification, which is supported in its
> current form since OpenSSL 1.1.0. This gets us all present and future
> improvements done by OpenSSL for free. E.g., the old code did not handle
> IP addresses in the subject alternative names, while the new code does.
> 
> If the verification fails, print the error message as returned by
> OpenSSL.
> 
> [1]: https://wiki.openssl.org/index.php/Hostname_validation
> 
> Suggested-by: brian m. carlson <sandals@crustytoothpaste.net>
> Signed-off-by: Beat Bolli <dev+git@drbeat.li>
> ---
> We cannot easily print the certificate's hostname in case of a mismatch,
> but the cURL branch does not, either.
> 
> Unfortuately, the diff looks bad because two functions are replaced by
> the new verify_peer() function that is completely unrelated.

Would it have been possible to make the diff a bit easier to read, for example by having a preparatory patch that simply moves code around into this new `verify_peer()` function without yet changing semantics, and then changing semantics in a second patch?

Show 10 quoted lines
> diff --git a/imap-send.c b/imap-send.c
> index 9f21705d77..ec4e28e423 100644
> --- a/imap-send.c
> +++ b/imap-send.c
> @@ -348,20 +320,13 @@ static int ssl_socket_connect(struct imap_socket *sock,
>  	ret = SSL_connect(sock->ssl);
>  	if (ret <= 0) {
>  		socket_perror("SSL_connect", sock, ret);
> +		if (cfg->ssl_verify)
> +			verify_peer(sock->ssl, 0);

Why do we need to verify the certificate when we failed connecting to the peer? We didn't do that before, either, did we?

Patrick
Previous: Beat BolliNext: Xiangfei Ding
Message 15 of 23 in “imap-send: future proofing and two correctness fixes”
  1. 0/3 imap-send: future proofing and two correctness fixesBeat Bolli, Sep 7, 2026
  2. 3/3 imap-send: only check the CN if no SAN DNS names are presentBeat Bolli, Sep 7, 2026
  3. brian m. carlsonSep 8, 2026
  4. 2/3 imap-send: don't expect an ASN1_STRING to be NUL-terminatedBeat Bolli, Sep 7, 2026
  5. Junio C HamanoSep 8, 2026
  6. Patrick SteinhardtSep 8, 2026
  7. 1/3 imap-send: prepare for OpenSSL 4.1Beat Bolli, Sep 7, 2026
  8. Junio C HamanoSep 8, 2026
  9. Patrick SteinhardtSep 8, 2026
  10. Beat BolliSep 14, 2026
  11. Patrick SteinhardtSep 23, 2026
  12. 1/2 imap-send: use the recommended TLS_method()Beat Bolli, Oct 12, 2026
  13. 1/3 imap-send: use the recommended TLS_method()Beat Bolli, Oct 17, 2026
  14. 2/3 imap-send: let OpenSSL do the hostname verificationBeat Bolli, Oct 17, 2026
  15. Patrick SteinhardtOct 19, 2026
  16. Xiangfei DingOct 19, 2026
  17. 3/3 imap-send: prepare for OpenSSL 4.0Beat Bolli, Oct 17, 2026
  18. Patrick SteinhardtOct 19, 2026
  19. Patrick SteinhardtOct 19, 2026
  20. 2/2 imap-send: let OpenSSL do the hostname verificationBeat Bolli, Oct 12, 2026
  21. Aniket GuptaOct 12, 2026
  22. Xiangfei DingOct 16, 2026
  23. Patrick SteinhardtOct 13, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.