<div dir="ltr">Hello,<br><div><br></div><div>I have a question regarding the flag "X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS".</div><div><br></div><div>In the book of Ivan Ristic (Bullet Proof TLS and PKI), chapter 12, section <i>Creating Certificates for Multiple Hostnames</i>, the author uses a wildcard in the SAN (*.<a href="http://feistyduck.com">feistyduck.com</a>).  </div><div><br></div><div>So, if the SAN has *.<a href="http://feistyduck.com">feistyduck.com</a> and <a href="http://feistyduck.com">feistyduck.com</a>, what will be accepted with the above flag?</div><div><br></div><div>1. <a href="http://www.feistyduck.com">www.feistyduck.com</a> ?</div><div>2. <a href="http://www.sub.feistyduck.com">www.sub.feistyduck.com</a> ?</div><div>3. <a href="http://www.sub.sub2.feistyduck.com">www.sub.sub2.feistyduck.com</a> ?</div><div>4. <a href="http://feistyduck.com">feistyduck.com</a> ?</div><div><br></div><div>Thank you</div><div><br></div><div>Pierre-Luc</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>