Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions proton/session/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class ProtonCryptoError(ProtonError):
In general this has to be handled as being fatal, as something is super-wrong."""


class ProtonCryptoPasswordTooLongError(ProtonCryptoError):
"""Exception raised when the password exceeds bcrypt's 72-byte limit.
The user should shorten their password to at most 72 bytes."""


class ProtonUnsupportedAuthVersionError(ProtonCryptoError):
"""When the auth_version returned by the API is lower then what is currently supported.
This is usually fixed with a login via the webclient."""
Expand Down
10 changes: 8 additions & 2 deletions proton/session/srp/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import bcrypt
import os

from proton.session.exceptions import ProtonUnsupportedAuthVersionError
from proton.session.exceptions import ProtonUnsupportedAuthVersionError, ProtonCryptoPasswordTooLongError


PM_VERSION = 4
Expand All @@ -39,7 +39,13 @@ def bcrypt_b64_encode(s): # The joy of bcrypt
def hash_password_3(hash_class, password, salt, modulus):
salt = (salt + b"proton")[:16]
salt = bcrypt_b64_encode(salt)[:22]
hashed = bcrypt.hashpw(password, b"$2y$10$" + salt)
try:
hashed = bcrypt.hashpw(password, b"$2y$10$" + salt)
except ValueError as e:
raise ProtonCryptoPasswordTooLongError(
"Password exceeds bcrypt's 72-byte limit. "
"Please shorten your password to at most 72 bytes."
) from e
return hash_class(hashed + modulus).digest()


Expand Down