-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_tls.py
57 lines (44 loc) · 1.41 KB
/
test_tls.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import socket
from tls import TLSClientSession
def main():
quit = False
sock = None
def callback(data):
nonlocal quit, sock
print(data)
if data == b"bye\n":
quit = True
psk = bytes.fromhex(
"b2c9b9f57ef2fbbba8b624070b301d7f278f1b39c352d5fa849f85a3e7a3f77b"
)
# session = TLSClientSession(
# server_names="127.0.0.1", psk=psk, data_callback=callback, psk_only=True, early_data=b"hoho"
# )
session = TLSClientSession(server_names="127.0.0.1", data_callback=callback)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("127.0.0.1", 1799))
sock.sendall(session.pack_client_hello())
parser = session.parser()
while not quit:
server_data = sock.recv(4096)
parser.send(server_data)
data = parser.read()
if data:
sock.sendall(data)
sock.sendall(session.pack_close())
sock.close()
quit = False
session = session.resumption(data_callback=callback)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("127.0.0.1", 1799))
sock.sendall(session.pack_client_hello())
parser = session.parser()
while not quit:
server_data = sock.recv(4096)
parser.send(server_data)
data = parser.read()
if data:
sock.sendall(data)
sock.sendall(session.pack_close())
sock.close()
main()