bpo-28182: restore backwards compatibility (#3464) · python/cpython@0915360 (original) (raw)

Original file line number Diff line number Diff line change
@@ -485,18 +485,23 @@ fill_and_set_sslerror(PySSLSocket *sslsock, PyObject *type, int ssl_errno,
485 485 }
486 486
487 487 switch (verify_code) {
488 +#ifdef X509_V_ERR_HOSTNAME_MISMATCH
489 +/* OpenSSL >= 1.0.2, LibreSSL >= 2.5.3 */
488 490 case X509_V_ERR_HOSTNAME_MISMATCH:
489 491 verify_obj = PyUnicode_FromFormat(
490 492 "Hostname mismatch, certificate is not valid for '%S'.",
491 493 sslsock->server_hostname
492 494 );
493 495 break;
496 +#endif
497 +#ifdef X509_V_ERR_IP_ADDRESS_MISMATCH
494 498 case X509_V_ERR_IP_ADDRESS_MISMATCH:
495 499 verify_obj = PyUnicode_FromFormat(
496 500 "IP address mismatch, certificate is not valid for '%S'.",
497 501 sslsock->server_hostname
498 502 );
499 503 break;
504 +#endif
500 505 default:
501 506 verify_str = X509_verify_cert_error_string(verify_code);
502 507 if (verify_str != NULL) {