BUG/MEDIUM: ssl: prevent CN fallback when a SAN extension is present
Yang Hailong of Alipay Security Team reported that backend hostname
verification accepts a certificate with a URI-only SAN and a matching
subject CN. The fallback was disabled only after encountering a DNS SAN,
so certificates containing other SAN types could still match their CN.
Use the status returned by X509_get_ext_d2i() to allow CN fallback only
when the SAN extension is absent. Present but undecodable or duplicate
SAN extensions do not permit fallback either.
RFC 9525 obsoletes RFC 6125 and prohibits using the subject Common Name
to identify a service. This change does not fully implement that policy:
CN fallback is retained for certificates without a SAN extension to
preserve compatibility with legacy deployments.
This intentionally tightens certificate acceptance: non-DNS SANs now
suppress CN matching, while certificates without SAN retain CN fallback.
Verified with the existing verifyhost regression and live backend TLS
checks covering URI-only SAN rejection, mixed URI/DNS SAN acceptance,
and CN-only compatibility, using both verifyhost and SNI.
This change must not be backported because it changes certificate
acceptance and could break existing deployments on stable branches.