GithubHelp home page GithubHelp logo

Handle Invalid IRC Password about irc HOT 6 CLOSED

jaraco avatar jaraco commented on August 25, 2024
Handle Invalid IRC Password

from irc.

Comments (6)

jaraco avatar jaraco commented on August 25, 2024

Because IRC is asynchronous, I believe it needs a handler for whatever response might be given by the server. I'm not familiar with the protocol, but what I suspect is that you'll need add a global handler to the client for an appropriate event, and when the event comes in that indicates a bad password, you can handle that however is appropriate (disconnect, prompt, re-try, etc).


Original comment by: Jason R. Coombs

from irc.

jaraco avatar jaraco commented on August 25, 2024

What would really help here is more detail about what a server does (either according to the spec or inferred from actual behavior) in the case of an invalid password. You can probably run the client with debug logging enabled against a server where you transmit an invalid password. That will provide a better indication of what response might be handled by the client.


Original comment by: Jason R. Coombs

from irc.

jaraco avatar jaraco commented on August 25, 2024

All great points. Thanks to your input I believe I have a plan to move forward. Thanks!


Original comment by: Brendan Ashby

from irc.

jaraco avatar jaraco commented on August 25, 2024

On further consideration, I suspect the client should probably raise an error if it attempts to send a password which is rejected by the server. I wonder if the server always sends a response to a PASS command, only only when it's invalid. If only the latter, then it'll be harder to detect an error condition.

I'd be interested to hear what you've encountered regarding this issue.


Original comment by: Jason R. Coombs

from irc.

jaraco avatar jaraco commented on August 25, 2024

After looking into this more, I'm a little frustrated with the way the library handles errors. Using a server my company has, which also requires a password, I attempted to connect using an invalid password with this script:

import logging
import ssl

logging.basicConfig(level=logging.DEBUG)

import irc.client
import irc.connection

client = irc.client.IRC()
server = client.server()
password = 'foo'
ssl_factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
conn = server.connect(
    'irc.example.net', 7000, 'jaraco_test',
    password=password,
    connect_factory=ssl_factory,
)

def on_error(connection, event):
    print(event.target)
    if 'Password mismatch' in event.target:
        connection.disconnect("You can't fire me; I quit!")
        raise Exception("Failed to authenticate")

client.add_global_handler('error', on_error)
client.process_forever()

(I've replaced our actual server and port)

What I get if I run that is this:

> python .\bad-pass.py
DEBUG:irc.client:connect(server='irc.example.com', port=7000, nickname='jaraco_test', ...)
DEBUG:irc.client:TO SERVER: PASS foo
DEBUG:irc.client:TO SERVER: NICK jaraco_test
DEBUG:irc.client:TO SERVER: USER jaraco_test 0 * :jaraco_test
DEBUG:irc.client:process_forever(timeout=0.2)
DEBUG:irc.client:FROM SERVER: :irc.example.com NOTICE AUTH :*** Looking up your hostname...
DEBUG:irc.client:command: privnotice, source: irc.example.com, target: AUTH, arguments: ['*** Looking up your hostname...']
DEBUG:irc.client:FROM SERVER: :irc.example.com NOTICE AUTH :*** Found your hostname
DEBUG:irc.client:command: privnotice, source: irc.example.com, target: AUTH, arguments: ['*** Found your hostname']
DEBUG:irc.client:FROM SERVER: ERROR :Closing Link: jaraco_test[c-68-55-72-219.hsd1.dc.comcast.net] (Password mismatch)
DEBUG:irc.client:command: error, source: None, target: Closing Link: jaraco_test[c-68-55-72-219.hsd1.dc.comcast.net] (Password mismatch), arguments: []
Closing Link: jaraco_test[c-68-55-72-219.hsd1.dc.comcast.net] (Password mismatch)
DEBUG:irc.client:TO SERVER: QUIT :You can't fire me; I quit!
Traceback (most recent call last):
  File ".\bad-pass.py", line 26, in <module>
    client.process_forever()
  File "C:\Users\jaraco\projects\irc\irc\client.py", line 266, in process_forever
    self.process_once(timeout)
  File "C:\Users\jaraco\projects\irc\irc\client.py", line 247, in process_once
    self.process_data(i)
  File "C:\Users\jaraco\projects\irc\irc\client.py", line 212, in process_data
    c.process_data()
  File "C:\Users\jaraco\projects\irc\irc\client.py", line 645, in process_data
    self._handle_event(Event(command, NickMask(prefix), target, arguments))
  File "C:\Users\jaraco\projects\irc\irc\client.py", line 649, in _handle_event
    self.irclibobj._handle_event(self, event)
  File "C:\Users\jaraco\projects\irc\irc\client.py", line 386, in _handle_event
    result = handler.callback(connection, event)
  File ".\bad-pass.py", line 23, in on_error
    raise Exception("Failed to authenticate")
Exception: Failed to authenticate

But more interestingly, if I leave out the 'raise Exception' clause, the script will run indefinitely. It will 'process_forever' even though it'll never have any sockets in the main event loop.

So a few things to note. First, the IRC library could probably handle better the circumstance where it doesn't have any connections. Second, the IRC server we use doesn't follow the RFC for handling the invalid password. Third, it was fairly straightforward to write a handler to capture when the password is invalid.

I realize this doesn't "fix" the issue, but it should help anyone struggling with it to better understand how to handle it.


Original comment by: Jason R. Coombs

from irc.

jaraco avatar jaraco commented on August 25, 2024

I'm going to close this as wontfix for now. If someone wishes to provide a session (perhaps using the script above) to show a transcript of a session against a server that follows the RFC for bad passwords, please do so, and I will gladly add support for the library.

As it is, the one example I have is a non-compliant example, so probably belongs in custom code and not in the library.


Original comment by: Jason R. Coombs

from irc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.