MCPcopy Index your code
hub / github.com/RustPython/RustPython / get_server_certificate

Function get_server_certificate

Lib/ssl.py:1506–1526  ·  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 connect

(addr, ssl_version=PROTOCOL_TLS_CLIENT,
                           ca_certs=None, timeout=_GLOBAL_DEFAULT_TIMEOUT)

Source from the content-addressed store, hash-verified

1504 return base64.decodebytes(d.encode('ASCII', 'strict'))
1505
1506def get_server_certificate(addr, ssl_version=PROTOCOL_TLS_CLIENT,
1507 ca_certs=None, timeout=_GLOBAL_DEFAULT_TIMEOUT):
1508 """Retrieve the certificate from the server at the specified address,
1509 and return it as a PEM-encoded string.
1510 If 'ca_certs' is specified, validate the server cert against it.
1511 If 'ssl_version' is specified, use it in the connection attempt.
1512 If 'timeout' is specified, use it in the connection attempt.
1513 """
1514
1515 host, port = addr
1516 if ca_certs is not None:
1517 cert_reqs = CERT_REQUIRED
1518 else:
1519 cert_reqs = CERT_NONE
1520 context = _create_stdlib_context(ssl_version,
1521 cert_reqs=cert_reqs,
1522 cafile=ca_certs)
1523 with create_connection(addr, timeout=timeout) as sock:
1524 with context.wrap_socket(sock, server_hostname=host) as sslsock:
1525 dercert = sslsock.getpeercert(True)
1526 return DER_cert_to_PEM_cert(dercert)
1527
1528def get_protocol_name(protocol_code):
1529 return _PROTOCOL_NAMES.get(protocol_code, '<unknown>')

Callers

nothing calls this directly

Calls 4

create_connectionFunction · 0.90
wrap_socketMethod · 0.80
DER_cert_to_PEM_certFunction · 0.70
getpeercertMethod · 0.45

Tested by

no test coverage detected