Retrieve the certificate from the server at the specified address, and return it as a PEM-encoded string. If 'ca_certs' is specified, validate the server cert against it. If 'ssl_version' is specified, use it in the connection attempt. If 'timeout' is specified, use it in the con
(addr, ssl_version=PROTOCOL_TLS_CLIENT,
ca_certs=None, timeout=_GLOBAL_DEFAULT_TIMEOUT)
| 1544 | return base64.decodebytes(d.encode('ASCII', 'strict')) |
| 1545 | |
| 1546 | def get_server_certificate(addr, ssl_version=PROTOCOL_TLS_CLIENT, |
| 1547 | ca_certs=None, timeout=_GLOBAL_DEFAULT_TIMEOUT): |
| 1548 | """Retrieve the certificate from the server at the specified address, |
| 1549 | and return it as a PEM-encoded string. |
| 1550 | If 'ca_certs' is specified, validate the server cert against it. |
| 1551 | If 'ssl_version' is specified, use it in the connection attempt. |
| 1552 | If 'timeout' is specified, use it in the connection attempt. |
| 1553 | """ |
| 1554 | |
| 1555 | host, port = addr |
| 1556 | if ca_certs is not None: |
| 1557 | cert_reqs = CERT_REQUIRED |
| 1558 | else: |
| 1559 | cert_reqs = CERT_NONE |
| 1560 | context = _create_stdlib_context(ssl_version, |
| 1561 | cert_reqs=cert_reqs, |
| 1562 | cafile=ca_certs) |
| 1563 | with create_connection(addr, timeout=timeout) as sock: |
| 1564 | with context.wrap_socket(sock, server_hostname=host) as sslsock: |
| 1565 | dercert = sslsock.getpeercert(True) |
| 1566 | return DER_cert_to_PEM_cert(dercert) |
| 1567 | |
| 1568 | def get_protocol_name(protocol_code): |
| 1569 | return _PROTOCOL_NAMES.get(protocol_code, '<unknown>') |
nothing calls this directly
no test coverage detected