-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
26 lines (23 loc) · 729 Bytes
/
client.py
File metadata and controls
26 lines (23 loc) · 729 Bytes
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
import http.client
import ssl
# Create custom context
context = ssl.create_default_context()
context.check_hostname = True # Enforce hostname validation
context.verify_mode = ssl.CERT_REQUIRED # Mandatory certificate verification
# Load the server's certificate directly
context.load_verify_locations('server.crt')
try:
conn = http.client.HTTPSConnection(
'localhost', # Must match certificate's CN/SAN
8443,
context=context,
timeout=10
)
conn.request('GET', '/')
response = conn.getresponse()
print(f"Status: {response.status}")
print(f"Response: {response.read().decode()}")
except Exception as e:
print(f"Connection failed: {str(e)}")
finally:
conn.close()