feat: add tls certificate, but not success
This commit is contained in:
19
tls_certificate.py
Executable file
19
tls_certificate.py
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
import socket
|
||||
import ssl
|
||||
|
||||
def get_server_certificate(hostname, port=443):
|
||||
# context = ssl.create_default_context()
|
||||
context = ssl._create_unverified_context()
|
||||
|
||||
with socket.create_connection((hostname, port)) as sock:
|
||||
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
|
||||
cert = ssock.getpeercert()
|
||||
return cert
|
||||
|
||||
# not success, but why?
|
||||
if __name__ == "__main__":
|
||||
certificate = get_server_certificate("hatter.ink")
|
||||
print(f"Certificate: {certificate}")
|
||||
for key, value in certificate.items():
|
||||
print(f"{key}: {value}")
|
||||
Reference in New Issue
Block a user