-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
33 lines (31 loc) · 964 Bytes
/
server.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
'''
This is the server for the TLS simulation. We will keep this server static and one which supports all possible configurations.
'''
import SocketServer
import socket
import OpenSSL
from OpenSSL import crypto
from OpenSSL import SSL
cntxt = SSL.Context(OpenSSL.SSL.TLSv1_2_METHOD)
cntxt.use_certificate_file("cert.pem")
cntxt.use_privatekey_file("privkey.pem")
cntxt.load_client_ca("cacert.pem")
cntxt.load_tmp_dh("dhparams.pem")
cntxt.set_tmp_ecdh(OpenSSL.crypto.get_elliptic_curve("prime256v1"))
class securessl(SocketServer.BaseRequestHandler):
def handle(self):
ssl_conn = SSL.Connection(cntxt,self.request)
ssl_conn.set_accept_state()
ssl_conn.do_handshake()
while True:
try:
x = ssl_conn.recv(bufsiz = 100)
if x == "":
return
except:
return
return
ssl_serverloc = ("127.0.0.1",6000)
SocketServer.TCPServer.allow_reuse_address = True
ssl_server = SocketServer.TCPServer(ssl_serverloc,securessl)
ssl_server.serve_forever()