Socket SSL attempt (No hostname validation)

This commit is contained in:
BuildTools 2021-03-24 20:51:33 +01:00
parent e069f2b31e
commit 65d016bd36
3 changed files with 8 additions and 49 deletions

View file

@ -24,6 +24,7 @@ import time
import threading import threading
import os import os
import traceback import traceback
import ssl
from oyoyo.parse import * from oyoyo.parse import *
from oyoyo import helpers from oyoyo import helpers
@ -81,7 +82,10 @@ class IRCClient:
... cli_con.next() ... 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 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket = self.context.wrap_socket(self.socket)
self.nick = None self.nick = None
self.real_name = None self.real_name = None
self.host = None self.host = None
@ -123,10 +127,10 @@ class IRCClient:
raise IRCClientError('Refusing to send one of the args from provided: %s' raise IRCClientError('Refusing to send one of the args from provided: %s'
% repr([(type(arg), arg) for arg in args])) % repr([(type(arg), arg) for arg in args]))
msg = bytes(" ", "ascii").join(bargs) msg = bytes(" ", "UTF-8").join(bargs)
logging.info('---> send "%s"' % msg) logging.info('---> send "%s"' % msg)
try: try:
self.socket.send(msg + bytes("\r\n", "ascii")) self.socket.send(msg + bytes("\r\n", "UTF-8"))
except socket.error as se: except socket.error as se:
try: # a little dance of compatibility to get the errno try: # a little dance of compatibility to get the errno
errno = se.errno errno = se.errno
@ -183,7 +187,7 @@ class IRCClient:
if len(buffer) == 0 and self.blocking: if len(buffer) == 0 and self.blocking:
raise socket.error("Connection closed") raise socket.error("Connection closed")
data = buffer.split(bytes("\n", "ascii")) data = buffer.split(bytes("\n", "UTF-8"))
buffer = data.pop() buffer = data.pop()
for el in data: for el in data:

View file

@ -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()

View file

@ -299,7 +299,7 @@ class userConfig(object):
def port(self): def port(self):
if hasattr(self.parent, 'portOverride'): if hasattr(self.parent, 'portOverride'):
return self.parent.portOverride return self.parent.portOverride
return self.config.get('port', '6667') return self.config.get('port', '6697')
def soundOn(self): def soundOn(self):
if 'soundon' not in self.config: if 'soundon' not in self.config:
self.set('soundon', True) self.set('soundon', True)