-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple_client.py
59 lines (52 loc) · 1.93 KB
/
simple_client.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
58
59
import socket
from tlslite import TLSConnection
from tlslite.api import *
from tlslite.utils.cryptomath import *
import sys
import ipaddress
import time
import random
import os
if __name__ == '__main__':
if len(sys.argv) != 3:
print 'usage: ' + sys.argv[0] + ' server_ip server_port'
else:
server_ip = sys.argv[1]
server_port = int(sys.argv[2])
cipher_suite = 'aes256gcm'
curve_name = 'x25519'
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((server_ip, server_port))
# now use sock to establish TLS 1.3 connection with the remote server
connection = TLSConnection(sock)
settings = HandshakeSettings()
settings.cipherNames = [cipher_suite]
settings.eccCurves = list([curve_name])
settings.defaultCurve = curve_name
settings.keyShares = [curve_name]
settings.maxVersion = (3, 3) # tls 1.2
settings.versions = [(3, 3)]
#settings.number_of_middleboxes = number_of_middleboxes
settings.print_debug_info = True
cert_file = "tests/serverX509Cert.pem"
s = open(cert_file, "rb").read()
if sys.version_info[0] >= 3:
s = str(s, 'utf-8')
x509 = X509()
x509.parse(s)
cert_chain = X509CertChain([x509])
middlebox_public_key = cert_chain.getEndEntityPublicKey()
settings.middlebox_public_key = middlebox_public_key
connection.middlebox_public_key = middlebox_public_key
#connection.number_of_middleboxes = number_of_middleboxes
connection.handshakeClientCert(settings=settings)
amout = 1024 * 1024 * 5
count = 0
time1 = time.time()
while count < amout:
data = connection.recv(4096)
count += len(data)
time2 = time.time()
result = 5 / (time2 - time1)
print 'throughput is ' + str(result) + ' MB/s'
connection.close()