From 65d016bd36196381d50110a27b71d83c21503d62 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 24 Mar 2021 20:51:33 +0100 Subject: [PATCH] Socket SSL attempt (No hostname validation) --- oyoyo/client.py | 10 +++++++--- oyoyo/examplebot.py | 45 --------------------------------------------- profile.py | 2 +- 3 files changed, 8 insertions(+), 49 deletions(-) delete mode 100644 oyoyo/examplebot.py diff --git a/oyoyo/client.py b/oyoyo/client.py index b5c819a..163973a 100644 --- a/oyoyo/client.py +++ b/oyoyo/client.py @@ -24,6 +24,7 @@ import time import threading import os import traceback +import ssl from oyoyo.parse import * from oyoyo import helpers @@ -81,7 +82,10 @@ class IRCClient: ... cli_con.next() ... """ + self.context = ssl.create_default_context() + self.context.check_hostname = False self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.socket = self.context.wrap_socket(self.socket) self.nick = None self.real_name = None self.host = None @@ -123,10 +127,10 @@ class IRCClient: raise IRCClientError('Refusing to send one of the args from provided: %s' % repr([(type(arg), arg) for arg in args])) - msg = bytes(" ", "ascii").join(bargs) + msg = bytes(" ", "UTF-8").join(bargs) logging.info('---> send "%s"' % msg) try: - self.socket.send(msg + bytes("\r\n", "ascii")) + self.socket.send(msg + bytes("\r\n", "UTF-8")) except socket.error as se: try: # a little dance of compatibility to get the errno errno = se.errno @@ -183,7 +187,7 @@ class IRCClient: if len(buffer) == 0 and self.blocking: raise socket.error("Connection closed") - data = buffer.split(bytes("\n", "ascii")) + data = buffer.split(bytes("\n", "UTF-8")) buffer = data.pop() for el in data: diff --git a/oyoyo/examplebot.py b/oyoyo/examplebot.py deleted file mode 100644 index dfd1885..0000000 --- a/oyoyo/examplebot.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/python -"""Example bot for oyoyo that responds to !say""" - -import logging -import re - -from oyoyo.client import IRCClient -from oyoyo.cmdhandler import DefaultCommandHandler -from oyoyo import helpers - - -HOST = 'irc.freenode.net' -PORT = 6667 -NICK = 'oyoyo-example' -CHANNEL = '#oyoyo-test' - - -class MyHandler(DefaultCommandHandler): - def privmsg(self, nick, chan, msg): - msg = msg.decode() - match = re.match('\!say (.*)', msg) - if match: - to_say = match.group(1).strip() - print(('Saying, "%s"' % to_say)) - helpers.msg(self.client, chan, to_say) - - -def connect_cb(cli): - helpers.join(cli, CHANNEL) - - -def main(): - logging.basicConfig(level=logging.DEBUG) - - cli = IRCClient(MyHandler, host=HOST, port=PORT, nick=NICK, - connect_cb=connect_cb) - conn = cli.connect() - - while True: - next(conn) ## python 2 - # next(conn) ## python 3 - - -if __name__ == '__main__': - main() diff --git a/profile.py b/profile.py index 32cf576..f8a4510 100644 --- a/profile.py +++ b/profile.py @@ -299,7 +299,7 @@ class userConfig(object): def port(self): if hasattr(self.parent, 'portOverride'): return self.parent.portOverride - return self.config.get('port', '6667') + return self.config.get('port', '6697') def soundOn(self): if 'soundon' not in self.config: self.set('soundon', True)