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

Example authenticated replayer is not working; Solved #390

Open
volkerjaenisch opened this issue Dec 18, 2023 · 0 comments
Open

Example authenticated replayer is not working; Solved #390

volkerjaenisch opened this issue Dec 18, 2023 · 0 comments

Comments

@volkerjaenisch
Copy link

Dear aiosmtpd people!
Thank you for your work!

The "authenticated replayer" example has two bugs:

  • The username and password have to be decoded to utf-8 since they may be bytes (dependent of the client).
  • Argon2 hashes cannot simply be compared, they have to be verified.

Here the fixed code.

class Authenticator:
    def __init__(self, auth_database):
        self.auth_db = Path(auth_database)
        self.ph = PasswordHasher()

    def __call__(self, server, session, envelope, mechanism, auth_data):
        fail_nothandled = AuthResult(success=False, handled=False)
        if mechanism not in ("LOGIN", "PLAIN"):
            return fail_nothandled
        if not isinstance(auth_data, LoginPassword):
            return fail_nothandled
        username = auth_data.login.decode()
        password = auth_data.password.decode()
        conn = sqlite3.connect(self.auth_db)
        curs = conn.execute(
            "SELECT hashpass FROM userauth WHERE username=?", (username,)
        )
        hash_db = curs.fetchone()
        conn.close()
        if not hash_db:
            return fail_nothandled
        if not self.ph.verify(hash_db[0], password):
            return fail_nothandled
        return AuthResult(success=True)

Cheers,
Volker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant