import socket
import ssl
def test_connection(address):
certs_return = ""
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
try:
with socket.create_connection((address, 443), timeout=10) as sock:
with context.wrap_socket(sock, server_hostname=address) as ssock:
cert = ssock.getpeercert()
for (issuer, entry) in cert['issuer']:
certs_return += "{}={}\n".format(issuer, entry)
except Exception as e:
certs_return = "0"
return certs_return