Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coretasks: better SASL handling #1928

Merged
merged 5 commits into from Oct 12, 2020
Merged

coretasks: better SASL handling #1928

merged 5 commits into from Oct 12, 2020

Conversation

dgw
Copy link
Member

@dgw dgw commented Aug 24, 2020

Description

Took a WIP fix for #1780 I found lying around the branches and extended it.

Checklist

  • I have read CONTRIBUTING.md
  • I can and do license this contribution under the EFLv2
  • No issues are reported by make qa (runs make quality and make test)
  • I have tested the functionality of the things this change touches

Notes

Better late than never (just look how long this PR sat open…)

@dgw dgw added the Tweak label Aug 24, 2020
@dgw dgw added this to the 7.1.0 milestone Aug 24, 2020
This only works for SASL 3.2 spec. In 3.1, the supported mechanisms are
only advertised after (and if) the client tries to use an unsupported
mechanism first, and THEN the server sends a 908 RPL_SASLMECHS numeric.
(And the 908 isn't required, so…)
@dgw dgw force-pushed the fail-sasl-on-unadvertised-mech branch from a8a007b to 58eb6e9 Compare October 10, 2020 05:34
@dgw dgw marked this pull request as ready for review October 10, 2020 06:03
Copy link
Contributor

@Exirel Exirel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nitpick for you to fix (unless there is a reason I'm not seeing), and also don't hesitate to change the PR's description. 👍

sopel/coretasks.py Show resolved Hide resolved
Handles SASL 3.1 advertised mechanisms, sent after Sopel's configured
mechanism fails, *sometimes* (the 908 numeric is sadly optional).
@dgw dgw force-pushed the fail-sasl-on-unadvertised-mech branch from e73d0c5 to 70e442e Compare October 11, 2020 00:58
@dgw
Copy link
Member Author

dgw commented Oct 11, 2020

@Exirel Yes, I saw your aside on IRC about the repeated SASL mech/password lookup code. What do you think now? 😁

Copy link
Contributor

@Exirel Exirel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nitpick that doesn't prevent this PR to be accepted in my opinion. 👍

Comment on lines +879 to +888
def _get_sasl_pass_and_mech(bot):
password = None
mech = None
if bot.config.core.auth_method == 'sasl':
password = bot.config.core.auth_password
mech = bot.config.core.auth_target
elif bot.config.core.server_auth_method == 'sasl':
password = bot.config.core.server_auth_password
mech = bot.config.core.server_auth_sasl_mech
return password, mech
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _get_sasl_pass_and_mech(bot):
password = None
mech = None
if bot.config.core.auth_method == 'sasl':
password = bot.config.core.auth_password
mech = bot.config.core.auth_target
elif bot.config.core.server_auth_method == 'sasl':
password = bot.config.core.server_auth_password
mech = bot.config.core.server_auth_sasl_mech
return password, mech
def _get_sasl_pass_and_mech(settings):
password = None
mech = None
if settings.core.auth_method == 'sasl':
password = settings.core.auth_password
mech = settings.core.auth_target
elif settings.core.server_auth_method == 'sasl':
password = settings.core.server_auth_password
mech = settings.core.server_auth_sasl_mech
return password, mech

def sasl_mechs(bot, trigger):
# Presumably we're only here if we said we actually *want* sasl, but still
# check anyway in case the server glitched.
password, mech = _get_sasl_pass_and_mech(bot)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
password, mech = _get_sasl_pass_and_mech(bot)
password, mech = _get_sasl_pass_and_mech(bot.config)

password = bot.config.core.server_auth_password
mech = bot.config.core.server_auth_sasl_mech
# check anyway in case the server glitched.
password, mech = _get_sasl_pass_and_mech(bot)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK it's kind of a nitpick here: if all you need is the settings, then just provide the settings. I've added other suggestion to reflect that change, so you can commit them in one go.

Suggested change
password, mech = _get_sasl_pass_and_mech(bot)
password, mech = _get_sasl_pass_and_mech(bot.config)

@dgw dgw requested a review from Exirel October 12, 2020 01:51
@dgw
Copy link
Member Author

dgw commented Oct 12, 2020

@Exirel Review re-requested because of the new commit making three SASL handlers "unblockable", which I noticed while browsing through coretasks again to look for something else.

About changing the helper to take bot.config as input instead of bot: Why not go all the way and pass bot.config.core? It certainly doesn't need any of the other sections. Where do we stop? 😁

@Exirel
Copy link
Contributor

Exirel commented Oct 12, 2020

Where do we stop? 😁

We stop at the most accurate higher level of objects. The function wants the settings for SASL. Today it's in core, maybe tomorrow that'll be in core and another section, or only in another section, etc.

@dgw
Copy link
Member Author

dgw commented Oct 12, 2020

Today it's in core, maybe tomorrow that'll be in core and another section, or only in another section, etc.

Or maybe it'll be in bot.db next week. 😼

@dgw dgw merged commit 005a534 into master Oct 12, 2020
@dgw dgw deleted the fail-sasl-on-unadvertised-mech branch October 12, 2020 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants