From: Patrick Steinhardt <ps@pks.im>
To: Beat Bolli <dev+git@drbeat.li>
Cc: git@vger.kernel.org, Xiangfei Ding <xfding@google.com>,
Aniket Gupta <aniketgupta3001@gmail.com>,
"brian m. carlson" <sandals@crustytoothpaste.net>
Subject: Re: [PATCH v2 2/2] imap-send: let OpenSSL do the hostname verification
Date: Tue, 13 Oct 2026 15:14:40 +0200 [thread overview]
Message-ID: <as4uwMflv6qzcoTh@pks.im> (raw)
In-Reply-To: <20261012203057.969878-2-dev+git@drbeat.li>
On Mon, Oct 12, 2026 at 10:30:57PM +0200, Beat Bolli wrote:
> According to the OpenSSL Wiki[1], OpenSSL knows how to verify the peer's
> hostname since version 1.0.2. A simpler interface is available since
> 1.1.0, which is what is implemented here.
What is implicit here is that Git performs its own hostname
verification. A short introduction explaining the status quo and why
the status quo is insufficient would help the reviewer.
What's also missing is a quick note on the minimum supported version of
OpenSSL.
> As a side-effect, we get 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.
That sounds like it's win-win: less code and more supported scenarios!
> 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>
> ---
> imap-send.c | 86 +++++++++--------------------------------------------
> 1 file changed, 14 insertions(+), 72 deletions(-)
Don't we have any tests for this? If not, can we maybe add some to make
sure that we indeed still verify the hostname?
> diff --git a/imap-send.c b/imap-send.c
> index 9f21705d77..cd9eae15d0 100644
> --- a/imap-send.c
> +++ b/imap-send.c
> @@ -325,6 +261,15 @@ static int ssl_socket_connect(struct imap_socket *sock,
> ssl_socket_perror("SSL_new");
> return -1;
> }
> + if (cfg->ssl_verify) {
> + SSL_set_hostflags(sock->ssl, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
This matches the documentation, but it also points out the
X509_CHECK_FLAG_NO_WILDCARDS as a second commonly used flag. Why do we
pick one over the other?
> @@ -352,14 +297,11 @@ static int ssl_socket_connect(struct imap_socket *sock,
> }
>
> if (cfg->ssl_verify) {
> - /* make sure the hostname matches that of the certificate */
> - cert = SSL_get_peer_certificate(sock->ssl);
> - if (!cert)
> - return error("unable to get peer certificate.");
> - if (SSL_get_verify_result(sock->ssl) != X509_V_OK)
> - return error("unable to verify peer certificate");
> - if (verify_hostname(cert, cfg->host) < 0)
> - return -1;
> + /* make sure the certificate was verified */
> + long res = SSL_get_verify_result(sock->ssl);
> + if (res != X509_V_OK)
> + return error("unable to verify peer certificate: %s",
> + X509_verify_cert_error_string(res));
Wait, this feels fishy to me. Take the following from [1]:
In other cases where no peer certificate or raw public key was
presented, the returned result can still be X509_V_OK, for example
when a server did not request a client certificate during the initial
handshake. X509_V_OK alone does not establish how or whether the peer
was authenticated. A suitably provisioned external PSK can
authenticate a peer without a certificate or raw public key. When
certificate or raw public key authentication is expected, applications
must also check that the expected credential is present using
SSL_get_peer_certificate(3) or SSL_get0_peer_rpk(3).
So this here basically allows for a MITM attack in case the intercepting
adversary simply strips the certificate altogether if I understand
correctly. And to fix that we must retain the call to
`SSL_get_peer_certificate()`.
That makes me want to have tests even more now.
[1]: https://docs.openssl.org/4.1/man3/SSL_get_verify_result/#bugs
Patrick
prev parent reply other threads:[~2026-10-13 13:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 21:12 [PATCH 0/3] imap-send: future proofing and two correctness fixes Beat Bolli
2026-09-07 21:12 ` [PATCH 1/3] imap-send: prepare for OpenSSL 4.1 Beat Bolli
2026-09-08 4:17 ` Junio C Hamano
2026-09-08 8:26 ` Patrick Steinhardt
2026-09-14 9:10 ` Beat Bolli
2026-09-23 12:32 ` Patrick Steinhardt
2026-09-07 21:12 ` [PATCH 2/3] imap-send: don't expect an ASN1_STRING to be NUL-terminated Beat Bolli
2026-09-08 1:17 ` Junio C Hamano
2026-09-08 8:26 ` Patrick Steinhardt
2026-09-07 21:12 ` [PATCH 3/3] imap-send: only check the CN if no SAN DNS names are present Beat Bolli
2026-09-08 1:28 ` brian m. carlson
2026-10-12 20:30 ` [PATCH v2 1/2] imap-send: use the recommended TLS_method() Beat Bolli
2026-10-12 20:30 ` [PATCH v2 2/2] imap-send: let OpenSSL do the hostname verification Beat Bolli
2026-10-12 22:00 ` Aniket Gupta
2026-10-13 13:14 ` Patrick Steinhardt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=as4uwMflv6qzcoTh@pks.im \
--to=ps@pks.im \
--cc=aniketgupta3001@gmail.com \
--cc=dev+git@drbeat.li \
--cc=git@vger.kernel.org \
--cc=sandals@crustytoothpaste.net \
--cc=xfding@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox