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

ValueError: plaintext is too long #17

Open
jtleniger opened this issue Nov 14, 2016 · 12 comments
Open

ValueError: plaintext is too long #17

jtleniger opened this issue Nov 14, 2016 · 12 comments

Comments

@jtleniger
Copy link

I have a pretty lengthy password and receive this exception when trying to login.

@simon-weber
Copy link
Owner

Huh, that's a new one. Can you provide a traceback? I'm not sure off the top of my head where this would be coming from.

@jtleniger
Copy link
Author

jtleniger commented Nov 14, 2016

I think I must have pasted my password more than once on accident. Can't reproduce with my actual password, but if I paste it 2-3 times:

Traceback (most recent call last):
  File "ImportList.py", line 193, in <module>
    api = open_api()
  File "D:\gmusic-playlist\common.py", line 181, in open_api
    if not api.login(username, password, Mobileclient.FROM_MAC_ADDRESS):
  File "C:\python27\lib\site-packages\gmusicapi\clients\mobileclient.py", line 122, in login
    if not self.session.login(email, password, android_id):
  File "C:\python27\lib\site-packages\gmusicapi\session.py", line 191, in login
    res = gpsoauth.perform_master_login(email, password, android_id)
  File "C:\python27\lib\site-packages\gpsoauth\__init__.py", line 60, in perform_master_login
    'EncryptedPasswd': google.signature(email, password, android_key_7_3_29),
  File "C:\python27\lib\site-packages\gpsoauth\google.py", line 50, in signature
    encrypted_login = cipher.encrypt((email + u'\x00' + password).encode('utf-8'))
  File "C:\python27\lib\site-packages\Cryptodome\Cipher\PKCS1_OAEP.py", line 141, in encrypt
    raise ValueError("Plaintext is too long.")
ValueError: Plaintext is too long.

Can probably close this unless it happens on someone's real password.

@simon-weber
Copy link
Owner

Ah, ok, that makes sense. We can check the size of the key to find the max plaintext length, and see if anybody has looked into what Google does to handle longer plaintext (probably some kind of chunking?).

@jackwilsdon
Copy link

I can reproduce this with a long password (64 characters long).

@simon-weber
Copy link
Owner

Gotcha. There's a mention of an 80-char username+password limit in the blog post I based my code on, but it's not immediately clear to me how to work around it.

@jackwilsdon
Copy link

jackwilsdon commented Jan 13, 2018

@jackwilsdon
Copy link

Just spent the last 30 minutes reverse-engineering the original Java source from Android from 2014, and it seems that it also has the 80 character combined limitation!

I did some more research, and it looks like authentication has changed how it works for these services, as linking a Google account to your device uses this URL for setup now. I've not looked into how it stores the authentication token or uses it with Google Play Services though.

@simon-weber
Copy link
Owner

Interesting. Nice work!

@PaddyMac
Copy link

PaddyMac commented Nov 9, 2020

Have you looked into this any further? Google has details about it's OAuth implementation at https://developers.google.com/identity/protocols/oauth2

@derekantrican
Copy link

I can reproduce this even with my "short" password (12 characters). I'm just following the instructions at the README: https://github.com/simon-weber/gpsoauth/blob/master/README.md#alternative-flow

Here's my code (sanitized a bit, of course):

email = '[email]'
token = '[oauth_token]'
android_id = '[device_id]'

print('perform_master_login')

master_response = gpsoauth.perform_master_login(email, token, android_id)
master_token = master_response['Token']

And here's the exception thrown with stack trace:

Traceback (most recent call last):
  File "C:\Users\derek\Desktop\GKeepToGmail\syncNotes.py", line 63, in <module>
    master_response = gpsoauth.perform_master_login(email, token, android_id)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\derek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\gpsoauth\__init__.py", line 141, in perform_master_login
    "EncryptedPasswd": google.construct_signature(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\derek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\gpsoauth\google.py", line 58, in construct_signature
    encrypted_login = cipher.encrypt((email + "\x00" + password).encode("utf-8"))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\derek\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\Cryptodome\Cipher\PKCS1_OAEP.py", line 117, in encrypt
    raise ValueError("Plaintext is too long.")
ValueError: Plaintext is too long.

I have 2FA on - don't know if that matters using the oauth token, though

@jackwilsdon
Copy link

@derekantrican is your email + password combination around 80 characters? The limit is for both combined.

@derekantrican
Copy link

No. However, I think I found later that I should be using exchange_token instead of perform_master_login. I think I was trying to use the oauth token for perform_master_login instead of the "master token"

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

5 participants