mirror of
https://github.com/pyrogram/pyrogram
synced 2025-09-01 14:55:12 +00:00
Re-implement change_cloud_password using SRP
This commit is contained in:
@@ -17,9 +17,9 @@
|
|||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from hashlib import sha256
|
|
||||||
|
|
||||||
from pyrogram.api import functions, types
|
from pyrogram.api import functions, types
|
||||||
|
from .utils import compute_hash, compute_check, btoi, itob
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
@@ -38,28 +38,30 @@ class ChangeCloudPassword(BaseClient):
|
|||||||
A new password hint.
|
A new password hint.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True on success, False otherwise.
|
True on success.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
||||||
|
``ValueError`` in case there is no cloud password to change.
|
||||||
"""
|
"""
|
||||||
r = self.send(functions.account.GetPassword())
|
r = self.send(functions.account.GetPassword())
|
||||||
|
|
||||||
if isinstance(r, types.account.Password):
|
if not r.has_password:
|
||||||
current_password_hash = sha256(r.current_salt + current_password.encode() + r.current_salt).digest()
|
raise ValueError("There is no cloud password to change")
|
||||||
|
|
||||||
new_salt = r.new_salt + os.urandom(8)
|
r.new_algo.salt1 += os.urandom(32)
|
||||||
new_password_hash = sha256(new_salt + new_password.encode() + new_salt).digest()
|
new_hash = btoi(compute_hash(r.new_algo, new_password))
|
||||||
|
new_hash = itob(pow(r.new_algo.g, new_hash, btoi(r.new_algo.p)))
|
||||||
|
|
||||||
return self.send(
|
self.send(
|
||||||
functions.account.UpdatePasswordSettings(
|
functions.account.UpdatePasswordSettings(
|
||||||
current_password_hash=current_password_hash,
|
password=compute_check(r, current_password),
|
||||||
new_settings=types.account.PasswordInputSettings(
|
new_settings=types.account.PasswordInputSettings(
|
||||||
new_salt=new_salt,
|
new_algo=r.new_algo,
|
||||||
new_password_hash=new_password_hash,
|
new_password_hash=new_hash,
|
||||||
hint=new_hint
|
hint=new_hint
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
)
|
||||||
return False
|
|
||||||
|
return True
|
||||||
|
Reference in New Issue
Block a user