verify ssl certificates

master
mutantmonkey 2012-03-21 23:10:15 -04:00
parent 825bf46fc0
commit 8fbc3f6fcc
1 changed files with 5 additions and 2 deletions

7
irc.py
View File

@ -79,7 +79,9 @@ class Bot(asynchat.async_chat):
raise
#pass
def run(self, host, port=6667, ssl=False, ipv6=False):
def run(self, host, port=6667, ssl=False,
ipv6=False, ca_certs='/etc/ssl/certs/ca-certificates.crt'):
self.ca_certs = ca_certs
self.initiate_connect(host, port, ssl, ipv6)
def initiate_connect(self, host, port, use_ssl, ipv6):
@ -100,7 +102,8 @@ class Bot(asynchat.async_chat):
self.family_and_type = family, type
sock = socket.socket(family, type)
if use_ssl:
sock = ssl.wrap_socket(sock, ssl_version=ssl.PROTOCOL_TLSv1)
sock = ssl.wrap_socket(sock, ssl_version=ssl.PROTOCOL_TLSv1,
cert_reqs=ssl.CERT_OPTIONAL, ca_certs=self.ca_certs)
# FIXME: ssl module does not appear to work properly with nonblocking sockets
#sock.setblocking(0)
self.set_socket(sock)