<div dir="ltr"><div dir="ltr">Yes, indeed I don't want to take into account the CN, only the SANs. Thanks for the extra flag and all the clarifications!<div><br></div><div>Best regards,</div><div>Theodor</div></div><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br><br>
<br>
> >  > For now I am using X509_VERIFY_PARAM_set1_host with SSL_CTX_set1_param to<br>
> >  > do this specific check.<br>
> >  <br>
> >  That's the slightly less convenient legacy API from OpenSSL 1.0.2.<br>
> >  In 1.1.0 and later, you can use SSL_set1_host() (and in some<br>
> >  cases also SSL_add1_host()).<br>
> >  <br>
> >  See the SSL_set1_host(3) manpage for details.<br>
> <br>
> Indeed I re-read the docs and it says that users should not assume that<br>
> hostnames are validated by default without explicitly calling the API, I<br>
> must've missed that bit and thank you for letting me know. I will shift<br>
> towards using the newer SSL_set1_host together with some flags (I don't<br>
> want any wildcards).<br>
<br>
If your needs are sufficiently narrow to rule out connecting to sites<br>
that use wildcard certificates, perhaps they're also narrow enough to<br>
rule out sites that don't have subjectAltNames, in which case the<br>
flags could be:<br>
<br>
So you'll call either of (here a NULL callback, set a non-null callback<br>
if appropriate):<br>
<br>
    SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);     /* Just once */<br>
    SSL_set_verify(ssl, SSL_VERIFY_PEER, NULL);         /* Per connection */<br>
<br>
followed by (per connection):<br>
<br>
    SSL_set1_host(ssl, "<a href="http://www.example.org" rel="noreferrer" target="_blank">www.example.org</a>");<br>
    SSL_set_hostflags(ssl, X509_CHECK_FLAG_NO_WILDCARDS<br>
                         | X509_CHECK_FLAG_NEVER_CHECK_SUBJECT);<br>
<br>
which also insists on a DNS subject altname (the preferred way to<br>
authenticate DNS names), and never looks at any CN field in the subject<br>
DN.<br>
<br>
> Now just to be extra safe I'm still asking: will the VERIFY_PEER option<br>
> together with SSL_set1_host instruct OpenSSL to perform all possible checks<br>
> on the certificate presented by the server such that no security breach<br>
> remains at this level? Is there anything else that I should call or perform<br>
> manually?<br>
<br>
No, the above is enough.  <br>
<br>
-- <br>
    Viktor.<br>
</blockquote></div></div>