-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtls.py
26 lines (20 loc) · 862 Bytes
/
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
import ssl
class SSLContext(object):
""" Ref: http://www.tornadoweb.org/en/stable/httputil.html?highlight=httpserverrequest#tornado.httputil.HTTPServerRequest.get_ssl_certificate """
def __init__(self, cert: str, key: str, cacert: str):
self._cert = cert
self._key = key
self._cacert = cacert
@property
def client_auth(self):
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
context.verify_mode = ssl.CERT_REQUIRED
context.load_cert_chain(self._cert, self._key)
context.load_verify_locations(self._cacert)
return context
@property
def server_auth(self):
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
context.load_cert_chain(self._cert, self._key)
context.load_verify_locations(self._cacert)
return context