<div dir="ltr">Hello,<br><div><br></div><div>My compiler doesn't like the following defines : "X509_CHECK_FLAG_NEVER_CHECK_SUBJECT" and "X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS".  When I add the include file "x509v3.h", the compiler now complains about line 181 in x509v3.h, which is probably because he doesn't know what is "X509_NAME".</div><div><br></div><div>My compiler version is visual studio 2017 and I use OpenSSL (compiled under visual studio 2017 as well)</div><div><br></div><div>Should I ask this question under the dev mailing list instead?</div><div><br></div><div>Thank you.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mer. 15 févr. 2023, à 12 h 28, Viktor Dukhovni <<a href="mailto:openssl-users@dukhovni.org">openssl-users@dukhovni.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Feb 15, 2023 at 09:45:01AM -0500, Pierre-Luc Boily wrote:<br>
<br>
> I guess that you also tell me to use another library because if this<br>
> simple thing (checking the ip address) is not well implemented, we<br>
> cannot trust the rest of the implementation!<br>
<br>
Actually, what disturbed me was not lack of support for IP addresses,<br>
but:<br>
<br>
    - The library maintainer's handwaving response to the issue<br>
    - The fact that reportedly in-application name checks have<br>
      not yet been removed, though a decade or so obsolete.<br>
<br>
> So, I guess that I should do something like this instead :<br>
<br>
Yes, with minor tweaks:<br>
<br>
    if (isIpAddress(host))<br>
    {<br>
       // We are connecting to an IP address.  let OpenSSL validate the<br>
       // IP address in SAN<br>
       X509_VERIFY_PARAM *param = SSL_get0_param(_ssl_connection);<br>
       X509_VERIFY_PARAM_set1_host(param, NULL, 0);<br>
       X509_VERIFY_PARAM_set1_ip_asc(param, host.c_str());<br>
    }<br>
    else<br>
    {<br>
       SSL_set1_host(_ssl_connection, host.c_str());<br>
       // Both CN-ID and partial wildcards are deprecated<br>
       // Optionally, reject all wildcards via:<br>
       //     X509_CHECK_FLAG_NO_WILDCARDS<br>
       // See X509_check_host(3).<br>
       //<br>
       SSL_set_hostflags(_ssl_connection, <br>
           X509_CHECK_FLAG_NEVER_CHECK_SUBJECT |<br>
           X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);<br>
    }<br>
<br>
The hostname is presumed NUL-terminated, otherwise indeed use<br>
X509_VERIFY_PARAM_set1_host() also for hostnames.  It would also be<br>
appropriate to check the success/failure of the various calls, check the<br>
documentation for details.<br>
<br>
If (very unlikely) you want to check the certificate for BOTH a matching<br>
name AND a matching IP address, you can set up the verification<br>
parameters to have both a hostname and an IP addresss.<br>
<br>
-- <br>
    Viktor.<br>
</blockquote></div>