Skip to content

Commit

Permalink
update ssl code thx to @lunar, (close #34, might handle #36)
Browse files Browse the repository at this point in the history
  • Loading branch information
RouxRC committed Apr 14, 2017
1 parent b745898 commit d4f9773
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions gazouilleur/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1601,16 +1601,17 @@ class IRCBotFactory(protocol.ReconnectingClientFactory):
channels.append("#gazouilleur")


class ClientTLSContext(ssl.ClientContextFactory):
isClient = 1
def getContext(self):
return SSL.Context(SSL.TLSv1_METHOD)

ssl_options = ssl.optionsForClientTLS(hostname=config.HOST.decode("utf-8"))
#class ClientTLSContext(ssl.ClientContextFactory):
# isClient = 1
# def getContext(self):
# return SSL.Context(SSL.TLSv1_METHOD)

# Run as 'python gazouilleur/bot.py' ...
if __name__ == '__main__':
if is_ssl(config):
reactor.connectSSL(config.HOST, config.PORT, IRCBotFactory(), ssl.ClientContextFactory())
reactor.connectSSL(config.HOST, config.PORT, IRCBotFactory(), ssl_options)
#reactor.connectSSL(config.HOST, config.PORT, IRCBotFactory(), ssl.ClientContextFactory())
else:
reactor.connectTCP(config.HOST, config.PORT, IRCBotFactory())
log.startLogging(sys.stdout)
Expand All @@ -1622,7 +1623,8 @@ def getContext(self):
filelog.timeFormat = "%Y-%m-%d %H:%M:%S"
application.setComponent(log.ILogObserver, filelog.emit)
if is_ssl(config):
ircService = internet.SSLClient(config.HOST, config.PORT, IRCBotFactory(), ClientTLSContext())
ircService = internet.SSLClient(config.HOST, config.PORT, IRCBotFactory(), ssl_options)
#ircService = internet.SSLClient(config.HOST, config.PORT, IRCBotFactory(), ClientTLSContext())
else:
ircService = internet.TCPClient(config.HOST, config.PORT, IRCBotFactory())
ircService.setServiceParent(application)

0 comments on commit d4f9773

Please sign in to comment.