4040def verify_certificate_hostname (
4141 certificate : Certificate , hostname : str
4242) -> None :
43- """
43+ r """
4444 Verify whether *certificate* is valid for *hostname*.
4545
46- .. note:: Nothing is verified about the *authority* of the certificate;
47- the caller must verify that the certificate chains to an appropriate
48- trust root themselves.
46+ .. note::
47+ Nothing is verified about the *authority* of the certificate;
48+ the caller must verify that the certificate chains to an appropriate
49+ trust root themselves.
50+
51+ Args:
52+ certificate: A *cryptography* X509 certificate object.
53+
54+ hostname: The hostname that *certificate* should be valid for.
4955
50- :param certificate: A *cryptography* X509 certificate object.
51- :param hostname: The hostname that *certificate* should be valid for.
56+ Raises:
57+ service_identity.VerificationError:
58+ If *certificate* is not valid for *hostname*.
5259
53- :raises service_identity.VerificationError: If *certificate* is not valid
54- for *hostname*.
55- :raises service_identity.CertificateError: If *certificate* contains
56- invalid / unexpected data.
60+ service_identity.CertificateError:
61+ If *certificate* contains invalid / unexpected data. This includes
62+ the case where the certificate contains no `subjectAltName`\ s.
5763
58- :returns: ``None``
64+ .. versionchanged:: 24.1.0
65+ :exc:`~service_identity.CertificateError` is raised if the certificate
66+ contains no ``subjectAltName``\ s instead of
67+ :exc:`~service_identity.VerificationError`.
5968 """
6069 verify_service_identity (
6170 cert_patterns = extract_patterns (certificate ),
@@ -67,25 +76,35 @@ def verify_certificate_hostname(
6776def verify_certificate_ip_address (
6877 certificate : Certificate , ip_address : str
6978) -> None :
70- """
79+ r """
7180 Verify whether *certificate* is valid for *ip_address*.
7281
73- .. note:: Nothing is verified about the *authority* of the certificate;
74- the caller must verify that the certificate chains to an appropriate
75- trust root themselves.
82+ .. note::
83+ Nothing is verified about the *authority* of the certificate;
84+ the caller must verify that the certificate chains to an appropriate
85+ trust root themselves.
86+
87+ Args:
88+ certificate: A *cryptography* X509 certificate object.
7689
77- :param certificate: A *cryptography* X509 certificate object.
78- :param ip_address: The IP address that *connection* should be valid
79- for. Can be an IPv4 or IPv6 address.
90+ ip_address:
91+ The IP address that *connection* should be valid for. Can be an
92+ IPv4 or IPv6 address.
8093
81- :raises service_identity.VerificationError: If *certificate* is not valid
82- for *ip_address*.
83- :raises service_identity.CertificateError: If *certificate* contains
84- invalid / unexpected data.
94+ Raises:
95+ service_identity.VerificationError:
96+ If *certificate* is not valid for *ip_address*.
8597
86- :returns: ``None``
98+ service_identity.CertificateError:
99+ If *certificate* contains invalid / unexpected data. This includes
100+ the case where the certificate contains no ``subjectAltName``\ s.
87101
88102 .. versionadded:: 18.1.0
103+
104+ .. versionchanged:: 24.1.0
105+ :exc:`~service_identity.CertificateError` is raised if the certificate
106+ contains no ``subjectAltName``\ s instead of
107+ :exc:`~service_identity.VerificationError`.
89108 """
90109 verify_service_identity (
91110 cert_patterns = extract_patterns (certificate ),
@@ -101,9 +120,11 @@ def extract_patterns(cert: Certificate) -> Sequence[CertificatePattern]:
101120 """
102121 Extract all valid ID patterns from a certificate for service verification.
103122
104- :param cert: The certificate to be dissected.
123+ Args:
124+ cert: The certificate to be dissected.
105125
106- :return: List of IDs.
126+ Returns:
127+ List of IDs.
107128
108129 .. versionchanged:: 23.1.0
109130 ``commonName`` is not used as a fallback anymore.
0 commit comments