aboutsummaryrefslogtreecommitdiff
path: root/http2irc.py
diff options
context:
space:
mode:
Diffstat (limited to 'http2irc.py')
-rw-r--r--http2irc.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/http2irc.py b/http2irc.py
index e568e48..86d0491 100644
--- a/http2irc.py
+++ b/http2irc.py
@@ -255,12 +255,16 @@ class IRCClientProtocol(asyncio.Protocol):
self.channels = channels # Currently joined/supposed-to-be-joined channels; set(str)
self.unconfirmedMessages = []
self.pongReceivedEvent = asyncio.Event()
+ self.sasl = bool(self.config['irc']['certfile'] and self.config['irc']['certkeyfile'])
+ self.authenticated = False
def connection_made(self, transport):
self.logger.info('IRC connected')
self.transport = transport
self.connected = True
nickb = self.config['irc']['nick'].encode('utf-8')
+ if self.sasl:
+ self.send(b'CAP REQ :sasl')
self.send(b'NICK ' + nickb)
self.send(b'USER ' + nickb + b' ' + nickb + b' ' + nickb + b' :' + self.config['irc']['real'].encode('utf-8'))
@@ -357,8 +361,22 @@ class IRCClientProtocol(asyncio.Protocol):
self.send(b'PONG ' + message[5:])
elif message.startswith(b'PONG '):
self.pongReceivedEvent.set()
+ elif message.startswith(b'CAP ') and self.sasl and message[message.find(b' ', 4) + 1:] == b'ACK :sasl':
+ self.send(b'AUTHENTICATE EXTERNAL')
+ elif message == b'AUTHENTICATE +':
+ self.send(b'AUTHENTICATE +')
+ elif message.startswith(b'903 '): # SASL auth successful
+ self.authenticated = True
+ self.send(b'CAP END')
+ elif any(message.startswith(x) for x in (b'902 ', b'904 ', b'905 ', b'906 ', b'908 ')):
+ self.logger.error('SASL error, terminating connection')
+ self.transport.close()
elif message.startswith(b'001 '):
self.logger.info('IRC connection registered')
+ if self.sasl and not self.authenticated:
+ self.logger.error('IRC connection registered but not authenticated, terminating connection')
+ self.transport.close()
+ return
self.send(b'JOIN ' + ','.join(self.channels).encode('utf-8')) #TODO: Split if too long
asyncio.create_task(self.send_messages())
asyncio.create_task(self.confirm_messages())