22 lines
675 B
Python
22 lines
675 B
Python
import ssl
|
|
from components.logs import logger
|
|
from config import defaults
|
|
|
|
|
|
def get_ssl_context(type_value: str):
|
|
if type_value == "client":
|
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
elif type_value == "server":
|
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
else:
|
|
raise Exception("Unknown type_value")
|
|
|
|
context.load_cert_chain(
|
|
certfile=defaults.TLS_CERTFILE, keyfile=defaults.TLS_KEYFILE
|
|
)
|
|
context.load_verify_locations(cafile=defaults.TLS_CA)
|
|
context.check_hostname = False
|
|
context.verify_mode = ssl.VerifyMode.CERT_REQUIRED
|
|
context.minimum_version = ssl.TLSVersion.TLSv1_3
|
|
return context
|