feat: update tls certificate
This commit is contained in:
@@ -13,6 +13,7 @@ trusted-host=mirrors.aliyun.com
|
|||||||
|
|
||||||
```shell
|
```shell
|
||||||
pip install requests
|
pip install requests
|
||||||
|
pip install cryptography
|
||||||
```
|
```
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import base64
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
|
|
||||||
|
from cryptography import x509
|
||||||
|
|
||||||
|
|
||||||
def get_server_certificate(hostname, port=443):
|
def get_server_certificate(hostname, port=443):
|
||||||
# context = ssl.create_default_context()
|
# context = ssl.create_default_context()
|
||||||
@@ -9,13 +12,19 @@ def get_server_certificate(hostname, port=443):
|
|||||||
|
|
||||||
with socket.create_connection((hostname, port)) as sock:
|
with socket.create_connection((hostname, port)) as sock:
|
||||||
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
|
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
|
||||||
cert = ssock.getpeercert()
|
cert = ssock.getpeercert(binary_form=True)
|
||||||
return cert
|
return cert
|
||||||
|
|
||||||
|
|
||||||
# not success, but why?
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
certificate = get_server_certificate("hatter.ink")
|
certificate = get_server_certificate("hatter.ink")
|
||||||
print(f"Certificate: {certificate}")
|
# print(f"Certificate: {certificate}")
|
||||||
for key, value in certificate.items():
|
print(base64.encodebytes(certificate).decode('utf-8'))
|
||||||
print(f"{key}: {value}")
|
cert = x509.load_der_x509_certificate(certificate)
|
||||||
|
print(cert)
|
||||||
|
print(cert.subject)
|
||||||
|
print(cert.issuer)
|
||||||
|
print(cert.not_valid_before_utc, ' --> ', cert.not_valid_after_utc)
|
||||||
|
print("-" * 88)
|
||||||
|
for ext in cert.extensions:
|
||||||
|
print(ext.oid, ':', ext.value)
|
||||||
|
|||||||
Reference in New Issue
Block a user