Comments (8)
i think you may have already seen this, but iliana had a good writeup on What Specific Base64 Bullshit is going on (spoiler: it's a join inaccuracy between sodium and the client-side arraybuffer library we use, that we never noticed because they're both broken in the same way) but the good news is the workaround isn't that bad, just dumb, and already mostly described in this thread https://cohost.org/iliana/post/180187-eggbug-rs-v0-1-3-d
EDIT LIKE A MINUTE LATER: wait i'm a dumbass and just saw that y'all already solved this. ignore everything i said and keep up the good work
from cohost.py.
thats strange, could you try with this login function?
def login(email, password):
# base64 terribleness
salt = fetch("GET", "/login/salt", {"email": email})['salt']
if len(salt)%4: salt = salt + "=" * (4 - len(salt) % 4)
saltDecoded = base64.b64decode(salt.encode("ascii"))
# generating the hash
hash = pbkdf2_hmac("sha384", password.encode("utf-8"), saltDecoded, 200000, 128)
clientHash = base64.b64encode(hash).decode("ascii")
# getting cookie
res = fetch("POST", "/login", {"email": email, "clientHash": clientHash}, complex=True)
sessionCookie = res['headers']['set-cookie'].split(";")[0].split("=")[1]
u = User(sessionCookie)
# if no error we're good
u.userInfo
return u
from cohost.py.
Yup! Same thing. Stacktrace below:
(Cohost.py) ➜ Cohost.py git:(main) ✗ python loginWithPass.py
Traceback (most recent call last):
File "/Users/val.knight/Documents/src/git/Cohost.py/loginWithPass.py", line 4, in <module>
User.login(userName, userPass)
File "/Users/val.knight/Documents/src/git/Cohost.py/cohost/models/user.py", line 98, in login
res = fetch("POST", "/login", {"email": email, "clientHash": clientHash}, complex=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/val.knight/Documents/src/git/Cohost.py/cohost/network.py", line 53, in fetch
raise Exception(res)
Exception: {'status': 422, 'message': 'Login Failed'}
Interestingly, if I add a character to my username (taking it from 21 characters to 22 characters) I just get an (expected)
(Cohost.py) ➜ Cohost.py git:(main) ✗ python loginWithPass.py
Traceback (most recent call last):
File "/Users/val.knight/Documents/src/git/Cohost.py/loginWithPass.py", line 4, in <module>
User.login(userName, userPass)
File "/Users/val.knight/Documents/src/git/Cohost.py/cohost/models/user.py", line 98, in login
res = fetch("POST", "/login", {"email": email, "clientHash": clientHash}, complex=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/val.knight/Documents/src/git/Cohost.py/cohost/network.py", line 53, in fetch
raise Exception(res)
Exception: {'status': 422, 'message': 'Login Failed'}
I'll try changing my Cohost account to use an email with an extra character in - if that works, it's just wrangling the base64 function into working.
There's also a great writeup by @iliana who's implemented this in eggbug.rs - I'm going to try to find time and port this b64 function into Python (I tried it with JS but my brain and JavaScript just Do Not Collaborate)
from cohost.py.
got it!
we have to replace "_" and "-" with just "A" or it breaks - code sample as follows
[...]
salt = fetch("GET", "/login/salt", {"email": email})['salt']
salt = salt.replace('-', 'A')
salt = salt.replace('_', 'A')
salt = salt + "=="
[...]
i'll work on pushing out a new version now :)
thanks so much for the PR!
from cohost.py.
Ok! Pushed the changes, and I've published a new version to pypi. I'll close this, but, if we have issues again with login, I'll reopen this issue.
release link: https://github.com/valknight/Cohost.py/releases/tag/release%2F0.2.0
from cohost.py.
oh! i’ve seen this as a possible solution, didnt think it was the issue as my salt didn’t contain that. using base64.urlsafe_b64decode
was recommended instead of base64.b64decode
as the proper way to fix it (i think its for this exact issue), give it a go if you can.
from cohost.py.
ah! let me try that real quick :)
from cohost.py.
Yeah, that hits me with good friend Exception: {'status': 422, 'message': 'Login Failed'}
I'll keep this issue open, but I'll change the title to "clean up base64 weirdness", considering login stuff is now working 😄
from cohost.py.
Related Issues (14)
- backports.pbkdf2? HOT 2
- expose RSS/JSON feeds in API HOT 2
- Can't access indivual project notifcations HOT 3
- 403 error if page is private, but post is still made HOT 7
- AttributeError exception when trying to get information on draft HOT 2
- Fix notifications after Cohost changes HOT 1
- Unable to make posts with attachments HOT 6
- TypeError: 'type' object is not subscriptable HOT 3
- No clear error thrown when media larger than 10mb is uploaded HOT 3
- [Python 3.9 compatibility issue] TypeError: unsupported operand type(s) for |: 'types.GenericAlias' and 'type' HOT 4
- Notification history API appears to have changed on cohost's end HOT 1
- feature request: image descriptions in media blocks HOT 4
- Logins stopped working overnight HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cohost.py.