Check if a TLS protocol is available and enabled :param protocol: enum ssl._SSLMethod member or name :return: bool
(protocol)
| 186 | |
| 187 | |
| 188 | def has_tls_protocol(protocol): |
| 189 | """Check if a TLS protocol is available and enabled |
| 190 | |
| 191 | :param protocol: enum ssl._SSLMethod member or name |
| 192 | :return: bool |
| 193 | """ |
| 194 | if isinstance(protocol, str): |
| 195 | assert protocol.startswith('PROTOCOL_') |
| 196 | protocol = getattr(ssl, protocol, None) |
| 197 | if protocol is None: |
| 198 | return False |
| 199 | if protocol in { |
| 200 | ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLS_SERVER, |
| 201 | ssl.PROTOCOL_TLS_CLIENT |
| 202 | }: |
| 203 | # auto-negotiate protocols are always available |
| 204 | return True |
| 205 | name = protocol.name |
| 206 | return has_tls_version(name[len('PROTOCOL_'):]) |
| 207 | |
| 208 | |
| 209 | @functools.lru_cache |
no test coverage detected
searching dependent graphs…