Check if a TLS protocol is available and enabled :param protocol: enum ssl._SSLMethod member or name :return: bool
(protocol)
| 166 | |
| 167 | |
| 168 | def has_tls_protocol(protocol): |
| 169 | """Check if a TLS protocol is available and enabled |
| 170 | |
| 171 | :param protocol: enum ssl._SSLMethod member or name |
| 172 | :return: bool |
| 173 | """ |
| 174 | if isinstance(protocol, str): |
| 175 | assert protocol.startswith('PROTOCOL_') |
| 176 | protocol = getattr(ssl, protocol, None) |
| 177 | if protocol is None: |
| 178 | return False |
| 179 | if protocol in { |
| 180 | ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLS_SERVER, |
| 181 | ssl.PROTOCOL_TLS_CLIENT |
| 182 | }: |
| 183 | # auto-negotiate protocols are always available |
| 184 | return True |
| 185 | name = protocol.name |
| 186 | return has_tls_version(name[len('PROTOCOL_'):]) |
| 187 | |
| 188 | |
| 189 | @functools.lru_cache |
no test coverage detected