-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
executable file
·42 lines (31 loc) · 1.29 KB
/
Copy pathclient.py
File metadata and controls
executable file
·42 lines (31 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# N.B. to use this successfully, you must have an entry like this in your
# hosts (with IP matching socket bind in server.py):
#
# 127.2.1.1 myserver.cluster.local othername.cluster.local
import ssl
import socket
import logging
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
msg_size_b = 64
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.load_verify_locations('root-ca-cert.pem')
context.minimum_version = ssl.TLSVersion.TLSv1_3
with open('passphrase.txt') as inf:
pass_text = inf.readline().strip()
context.load_cert_chain(certfile='client-certchain.pem', keyfile='client-key.pem', password=pass_text)
# all of these should work b/c they're DNS and IP SANs in the x509 extension field
for hostname in [
'myserver.cluster.local',
'127.2.1.1',
'othername.cluster.local',
]:
logger.info(f"Attempting to connect to {hostname}")
with socket.create_connection((hostname, 8443)) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
ssock.settimeout(2)
logger.info(f"{ssock.version()}, peercert: {ssock.getpeercert()}")
d = ssock.recv(msg_size_b)
logger.info("ts from server: {}".format(d.rstrip(b"\0").decode()))