#!/usr/bin/env python3# -*- coding: utf-8 -*-importsocketHOST, PORT ="localhost", 9999with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect((HOST, PORT))
sock.sendall(bytes("Hello, I am Client", "utf-8"))
received =str(sock.recv(1024), "utf-8")
print(received)
Country Name (2 letter code) [AU]:CN // 国家码
State or Province Name (full name) [Some-State]:GuangDong // 省份
Locality Name (eg, city) []:GuangZhou // 城市
Organization Name (eg, company) [Internet Widgits Pty Ltd]: Personal // 组织机构或公司名
Organizational Unit Name (eg, section) []: Personal // 机构部门
Common Name (e.g. server FQDN or YOUR name) []:域名 // *.abc.com
Email Address []:[email protected] // 邮件地址
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456 // 证书密码
An optional company name []:Personal // 公司名
#!/usr/bin/env python3# -*- coding: utf-8 -*-importsocketimportsslHOST, PORT ="127.0.0.1", 9999context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.check_hostname =Falsecontext.maximum_version = ssl.TLSVersion.TLSv1_2
context.load_default_certs()
context.load_verify_locations("ca.crt")
with socket.create_connection((HOST, PORT)) as sock:
with context.wrap_socket(sock) as ssock:
ssock.sendall(bytes("Hello, I am Client", "utf-8"))
received =str(ssock.recv(1024), "utf-8")
print(received)
#!/usr/bin/env python3# -*- coding: utf-8 -*-importsocketimportsslHOST, PORT ="127.0.0.1", 9999context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.check_hostname =Falsecontext.maximum_version = ssl.TLSVersion.TLSv1_2
context.load_cert_chain(certfile="client.crt", keyfile="client.key", password="123456")
context.load_verify_locations("ca.crt")
with socket.create_connection((HOST, PORT)) as sock:
with context.wrap_socket(sock) as ssock:
ssock.sendall(bytes("Hello, I am Client", "utf-8"))
received =str(ssock.recv(1024), "utf-8")
print(received)