MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / get_server_certificate

Function get_server_certificate

tools/python-3.11.9-amd64/Lib/ssl.py:1546–1566  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1544 return base64.decodebytes(d.encode('ASCII', 'strict'))
1545
1546def 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
1568def get_protocol_name(protocol_code):
1569 return _PROTOCOL_NAMES.get(protocol_code, '<unknown>')

Callers

nothing calls this directly

Calls 4

create_connectionFunction · 0.90
DER_cert_to_PEM_certFunction · 0.85
wrap_socketMethod · 0.45
getpeercertMethod · 0.45

Tested by

no test coverage detected