Open jbarlow83 opened 7 years ago
I really really appreciate that you open this issue!! thanks. đ
Unfortunately, the security cheat sheet
was too simple that programmers SHOULD NOT just copy past the code. It will case lots of security issues. I will give a warning on the top of cheat sheet soon.
based on karanlyons said:
The AES examples use CBC with PKCS7 and no MAC, which is the classic example of a scheme open to padding oracle attacks. Nowadays Iâd recommend GCM (or EAX) as your block mode if itâs available, and otherwise CTR or CBC with a MAC on the IV & ciphertext using a separate key. And I wouldnât consider myself within even spitting distance of a crypto expert.
Whatâs weird is that cryptography has all of those primitives, so itâs concerning that the author didnât use them. The key stretching is also using a custom function as opposed to one of the KDFs in cryptography as well (it looks like the function is basically HKDF, but the first rule of crypto is âdonât roll your own crypto,â so at the very least we could use the primitives).
Thereâs also no guarding against nonce/IV reuse (which is a bad idea in general, but thankfully not catastrophic for CBC) in the symmetric crypto. Worse, the key & IV are derived from the initial key, guaranteeing that any given key will always have the same IV, which opens you up to all sorts of attacks based around inference of plaintexts from a corpus of ciphertexts (With CBC if (Keyâ, IVâ) == (Keyâ, IVâ) then if Câ == Câ, Pâ == Pâ. Additionally the first block is now effectively in ECB mode. With CTR/GCM/EAX/etc. the results are way worse).
Thereâs probably more stuff wrong, too (like the stuff around certificates seemingly ignoring any trust model, and the implication of a lack of understanding as to the maximum message length given a key size), but thatâs what I found from a quick glance. The one bit of good news is that if you just use TLS with strong cipher suites (and a trusted cert with pinning) almost all of this will be done properly for you.
I get the intent behind this, and I think that intent is genuinely good, but crypto is really not a place where you want to be giving any advice unless youâre either an expert or willing to couch your advice in a bunch of caveats.
(Also, and somewhat tangential: if weâre going to put together a âthis is how you do thingsâ cheatsheet, it wouldnât hurt to espouse the most modern stuff weâve got: ECDSA, AES-GCM, ECDHE, ECC and AEAD in general, scrypt, etc.)
I agree that there still have a lot of work to do ...
https://www.reddit.com/r/Python/comments/6utwyn/a_python_cheat_sheet_about_security/dlvo6n2/