Allow loading a custom CA certificate via a ssl_cafile option (#677)

Co-authored-by: Paige Thompson <paigeadele@gmail.com>
This commit is contained in:
Paige Thompson 2022-09-06 19:04:54 -07:00 committed by GitHub
parent 523c1d2b13
commit c453926718
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -1796,6 +1796,7 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils):
Initializes SSL/TLS for this network.
"""
log.info('(%s) Using TLS/SSL for this connection...', self.name)
cafile = self.serverdata.get('ssl_cafile')
certfile = self.serverdata.get('ssl_certfile')
keyfile = self.serverdata.get('ssl_keyfile')
@ -1804,10 +1805,11 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils):
# Cert and key files are optional, load them if specified.
if certfile and keyfile:
try:
cafile != None and context.load_verify_locations(cafile)
context.load_cert_chain(certfile, keyfile)
except OSError:
log.exception('(%s) Caught OSError trying to initialize the SSL connection; '
'are "ssl_certfile" and "ssl_keyfile" set correctly?',
'are "ssl_certfile", "ssl_keyfile", and "ssl_cafile" set correctly?',
self.name)
raise