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

Setting a new password for 2FA #259

Closed
88ee55 opened this issue Sep 23, 2017 · 13 comments
Closed

Setting a new password for 2FA #259

88ee55 opened this issue Sep 23, 2017 · 13 comments

Comments

@88ee55
Copy link
Contributor

88ee55 commented Sep 23, 2017

No set password for 2FA

r = self.tgclient(account.UpdatePasswordSettingsRequest(password_hash, password_new))
  File "/usr/lib64/python3.5/site-packages/telethon/telegram_client.py", line 243, in invoke
    retries=kwargs.get('retries', 5)
  File "/usr/lib64/python3.5/site-packages/telethon/telegram_bare_client.py", line 338, in invoke
    raise request.rpc_error
telethon.errors.rpc_errors.RPCError: INPUT_FETCH_ERROR (code 400)

       r = self(account.GetPasswordRequest())
        r = r.new_salt
        password = ''
        password_hash = get_password_hash(password, r)
        pw_new = 'secret'
        password_new_hash = get_password_hash(pw_new, r)
        password_new = PasswordInputSettings(new_salt=r, new_password_hash=password_new_hash)
        r = self(account.UpdatePasswordSettingsRequest(password_hash, password_new)) 

More information

centos 7 x64
python 3.5.2
telethon 0.13.4

@Lonami
Copy link
Member

Lonami commented Sep 23, 2017

INPUT_FETCH_ERROR, that's new. Checking https://rpc.pwrtelegram.xyz/?description_for=INPUT_FETCH_ERROR out, we see:

{"ok":true,"result":"An error occurred while deserializing TL parameters"}

So… something went wrong there. I've never tried those requests myself so no idea.

@Lonami
Copy link
Member

Lonami commented Sep 23, 2017

I found this after a while looking.

@88ee55
Copy link
Contributor Author

88ee55 commented Sep 25, 2017

i added 'hint'
password_new = PasswordInputSettings(new_salt=r, new_password_hash=password_new_hash' hint='hint')
and changed 'current_password_hash'
r = self.tgclient(account.UpdatePasswordSettingsRequest(current_password_hash=bytes(0), new_settings=password_new)

r = self.tgclient(account.GetPasswordRequest())
salt = r.new_salt
pw = 'secret'
pw_byte = pw.encode("UTF-8")
pw_salt = salt + pw_byte + salt
pw_hash = sha256(pw_salt).digest()
password_new = PasswordInputSettings(new_salt=salt, new_password_hash=password_new_hash, hint='hint')
r = self.tgclient(account.UpdatePasswordSettingsRequest(current_password_hash=bytes(0), new_settings=password_new)

get error NEW_SALT_INVALID

  File "/usr/lib64/python3.5/site-packages/telethon/telegram_client.py", line 263, in invoke
    retries=kwargs.get('retries', 5)
  File "/usr/lib64/python3.5/site-packages/telethon/telegram_bare_client.py", line 340, in invoke
    raise request.rpc_error
telethon.errors.rpc_errors.RPCError: NEW_SALT_INVALID (code 400)

@Lonami
Copy link
Member

Lonami commented Sep 25, 2017

Did you try using salt = r.current_salt instead? Then, new_salt=r.new_salt, just a guess.

@88ee55
Copy link
Contributor Author

88ee55 commented Sep 25, 2017

account.GetPasswordRequest()
return
NoPassword: {email_unconfirmed_pattern: '', new_salt: b'\xfd:\x03\x06Ij\xeeV'}

@Lonami
Copy link
Member

Lonami commented Sep 25, 2017

Hm… Besides, I noticed the salt is 8 bytes long, and you're using bytes(0).

@Lonami
Copy link
Member

Lonami commented Sep 25, 2017

Also check this code:

if (!silent) {
    passwordEntered = currentPassword != null || response instanceof TLRPC.TL_account_noPassword;
}
currentPassword = (TLRPC.account_Password) response;
waitingForEmail = currentPassword.email_unconfirmed_pattern.length() > 0;
byte[] salt = new byte[currentPassword.new_salt.length + 8];
Utilities.random.nextBytes(salt);
System.arraycopy(currentPassword.new_salt, 0, salt, 0, currentPassword.new_salt.length);
currentPassword.new_salt = salt;

@88ee55
Copy link
Contributor Author

88ee55 commented Sep 25, 2017

EXCELLENT!

r = self.tgclient(account.GetPasswordRequest())
salt_new = r.new_salt
salt_random = os.urandom(8)
salt = salt_new + salt_random
pw = 'secret'
pw_byte = pw.encode("UTF-8")
pw_salt = salt + pw_byte + salt
pw_hash = sha256(pw_salt).digest()
password_new = PasswordInputSettings(new_salt=salt, new_password_hash=pw_hash, hint='hint')
r = self.tgclient(account.UpdatePasswordSettingsRequest(current_password_hash=salt, new_settings=password_new)

@Lonami
Copy link
Member

Lonami commented Sep 25, 2017

It works?

@88ee55
Copy link
Contributor Author

88ee55 commented Sep 25, 2017

yes

@Lonami
Copy link
Member

Lonami commented Sep 25, 2017

Awesome, would you like to write a wiki page for that yourself? Make a pull request with example code? Otherwise, I can do that for you, just saying this so that you can become a contributor. Glad you solved it.

@Lonami Lonami closed this as completed Sep 25, 2017
@Lonami Lonami changed the title No set password Setting a new password for 2FA Sep 25, 2017
@88ee55
Copy link
Contributor Author

88ee55 commented Sep 25, 2017

better you write a wiki
my English is poor (

@Lonami
Copy link
Member

Lonami commented Sep 25, 2017

Okay then I will do it)

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

2 participants