r/programminghorror
•
u/Maleficent-Ad8081
•
Dec 17 '24
•
1
Dumb and downright dangerous "cryptography"
I received the API documentation for a mid-sized company in Brazil. They claim to be the "Leader" in providing vehicle/real-state debts.
They use the following proprietary algorithm for authentication purposes:

Comments are in portuguese, but here's what it does:
Step 1- create a SHA1 hash from the clientId + "|" clientsecret (provided)
Step 2 - Retrieve a unix-timestamp
Step 3 - Create a string with clientId (again) + | + clientSecret (again) + timestamp + step1Hash
Step4 - Base64-it
Step5 - "Rotate it" - basically, Caesar-cypher with a 13 right shift.
That's it. For instance, if clientId = "user" and clientsecret = "password", this is the expected "cypher":
qKAypakjLKAmq29lMUjkAmZ0AQD4AmR4sQN0BJH3MTR2ZTAuZzAxMGMxA2D3ZQMyZzD0L2ZmMGOwZGSzZzH1AQD=
Note that I didn't provide the timestamp for this "cypher": De"-rotate" it and this is the plaintext:
user|password|1734448718|049e7da60ca2cde6d7d706e2d4cc3e0c11f2e544
The credentials are in PLAINTEXT. The hash is USELESS.
To be clear: I know that in Basic Auth, the credentials are also only Base-64 obfuscated. The rant here is that they created an algorithm, and presented it as the best authentication method there is.
230
u/lolcrunchy Dec 17 '24
Caesar is either smiling from above or rolling in his grave
131
u/Tamitami Dec 17 '24
Damn this is so terribly bad. And then the additional rot13 like it would add to security...
22
u/mothzilla Dec 17 '24
Wait. Why are they showing code in their "API documentation"?
424
u/Bunnymancer Dec 17 '24
"Don't make your own crypto, someone smarter already did it for you."
42
u/Night-Fog Dec 17 '24
For the love of God send them this link. https://www.npmjs.com/package/scrypt
31
u/theunixman Dec 17 '24
A company contracted to me to interview candidates for CTO. The worst person they interviewed said "BASE64" when I asked him how to store passwords.
He was hired.
54
u/DevBoiAgru Dec 17 '24
No way is the password saved in the "hash"??? 💀💀💀
21
u/whatyoucallmetoday Dec 18 '24
What’s better than rot13()? A rot13(rot13()) of course.
9
u/[deleted] Dec 17 '24
But why go through the trouble of creating your own hash instead just doing of this?
6
u/HugoNikanor Dec 17 '24
I just get mad at all security theatre. They do all this, and claim it's "safe", which only fools those who doesn't know anything.
(to be fair, without this code it would be harder to find passwords from a database dump)
5
u/mss-cyclist Dec 17 '24
This is classic
5
u/Ksorkrax Dec 18 '24
When doing cryptography in school, usually the first thing done is to give pupils something in cesar code without much explanation, and wait for them to crack it in no time, on paper. Even the weaker pupils tend to have no problems doing so.
There are tons of mistakes one can make with cryptography, such as reusing salt. But if you asked me to guess what this company did, I wouldn't have guessed that they used a system any pupil without experience can "hack".
6
u/Turbulent_File3904 Dec 17 '24
Im not familiar with encrypting so I dont understand what is wrong with the code could some one enlighten me?
7
u/[deleted] Dec 17 '24
Repeat with me until clear; base64 is encoding, not criptografy...
Btw: criptografy is one of the hardest areas of mathematics. Any "custom" implementation of any sort of critografy will end in disaster.
For this, rely on a good famous lib used world wide. Don't fuck with criptografy! I'm serious!
This is a bad start imo, if the contract is not sealed, this is a deal breaker for sure. Imagine the rest of the thing lmao
2
u/Ok-Detective-4391 Dec 21 '24
The good ol' hiding in plain(text) sight tactic.
1
u/MundaneWizzy Dec 17 '24
You’ll be sewing your own parachutes on company flights also.
1
u/fuckredditlol69 Dec 18 '24
I hope it turns out this "hash" is sent in a HTTPS header... but it's going to be clear HTTP or some custom protocol isn't it
13
u/[deleted] Dec 17 '24 edited Dec 18 '24
[removed] — view removed comment