Node.js interactive NA 2016: Tales From the Crypt

40

Transcript of Node.js interactive NA 2016: Tales From the Crypt

Page 1: Node.js interactive NA 2016: Tales From the Crypt
Page 2: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Tales From the CryptA Cryptography Primer

Adam Englander, iovation

Page 3: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Who Am I?

Page 4: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

What We Will Discuss

Wearegoingtotalkaboutthecommonmethodsandtermsusedforcryptographyinapplicationdevelopment.

Page 5: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Don’t Dwell

Donotfeelashamedbecauseyouaredoinganyofthiswrong.Justfixitmovingforward.

Page 6: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

What Is Cryptography?

Cryptography…isthepracticeandstudyoftechniquesforsecurecommunicationinthepresenceofthirdpartiescalledadversaries. Wikipedia

Page 7: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

My Definition of Cryptography

Cryptographyobscuresdatainsuchawaythatitisdifficultandcostlytoduplicateorreverse.

Page 8: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

What is Good Cryptography?

Goodcryptographyhasahighlevelofentropy.Thatis,thattheencryptedorhasheddatahasalowlevelofpredictability.

Page 9: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Why Is Entropy Important?

Alldatahaspatterns.Ifyourencryptedorhasheddataretainsthosepatterns,itismuchlessdifficultandlesscostlytoduplicateorreverse.

Page 10: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Example of Poor Entropy

Page 11: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

How To Increase Entropy

•Increaseentropybymixingincryptographicallysecurepseudorandomdataintheformofaninitializationvector(IV)orsalt•Increaseentropywithfeedbackloops

Page 12: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Feedback Loop Example

Page 13: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Example of Good Entropy

Page 14: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Localized vs Global Entropy

• Highentropyonanitemisgood• Highentropyacrossthedatasetisbetter• Patternsexistacrossyourentiredatasetthatmayaidadversaries

Page 15: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Cryptography Types

• Symmetric Key Cryptography uses shared secrets• Asymmetric Key Cryptography uses

private/public key pairs

Page 16: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Cryptography Applications

• Encryption• Digital Signatures• Key Derivation

Page 17: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Encryption

• Protecting data that needs to be recalled• Can be reversed via decryption

Page 18: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Digital Signature

• Used to verify authenticity of data• Used mostly for data transfer• Can not be reversed but can be

reproduced for verification

Page 19: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Key Derivation

• A.K.A. password hashing• Cannot be reversed• Computationally expensive by design

Page 20: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Symmetric Key Cryptography

Page 21: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Symmetric Key Cryptography

• Shared secrets• Uses cipher algorithms against blocks

or streams of data• Most implementations will use block

Page 22: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Block Cipher Modes

• DO NOT USE Electronic Cookbook (ECB)!!!• Cipher Block Chaining (CBC) will be

the right choice for most implementations

Page 23: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Cipher Block Chaining (CBC)

• Entire message is required for decryption• Full cipher text block is used as the

seed for the next block

Page 24: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Cipher Block Chaining (CBC)

Page 25: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Digital Signatures (HMAC)

• Hash-based Message Authentication Code (HMAC)• Hashing combined with key• SHA-256 or better is preferred to

ensure uniqueness

Page 26: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Asymmetric Key Cryptography

Page 27: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Asymmetric Key Cryptography

• RSA is common and available• Uses very large prime integers• Very computationally expensive• Uses key pairs to protect secret

Page 28: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Private/Public Key Pair

• Private key can do encrypt, decrypt, sign, and verify signature• Public key does not have enough data

to decrypt or sign. Can only encrypt and verify signature

Page 29: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Key Size and Hash Algorithm

• Current minimum recommend key size is 2048• SHA1 is considered safe but SHA-256

is better

Page 30: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Data Limitations

• RSA can only encrypt or sign data up to the length of the key size• Signatures use hashing• Crypto often mixed with symmetric key

cryptography

Page 31: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Padding

• Padding is how RSA creates additional entropy• RSA_PKCS1_OAEP_PADDING is

default and should always be used• RSA_PKCS1_PADDING is not safe

Page 32: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Key Derivation Functionsa.k.a Password Hashing

Page 33: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Password Hashing

NEVERusestandardhashingfunctionlikeMD5orSHA!

Onlyusekeyderivationfunctions!

Page 34: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Key Derivation

• Injects salt for entropy• Iterates to increase cost• Can create cost via threads and memory• Bigger is better!

Page 35: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Which KDF Should I Use

• argon2i is the new hotness• scrypt is preferred• bcrypt is acceptable• pbkdf2 can be used in a pinch• No passwords are best

Page 36: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Recommendations

Page 37: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Types

• Use RSA asymmetric key cryptography when transferring data and AES/CBC otherwise• Mix with AES and random keys/IVs per transfer• Use crypto.randomBytes for randomness• Use bcrypt/scrypt/argon2i for passwords

Page 38: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Strength

• AES: aes-256-cbc / sha256• RSA: 2048+ PKCS1_OAEP / RSA-

SHA256• Hash until it hurts!

Page 39: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Further Reading

• https://nodejs.org/api/crypto.html• https://www.wikipedia.org/• https://www.npmjs.com/package/bcrypt• https://www.npmjs.com/package/scrypt• https://www.npmjs.com/package/argon2

Page 40: Node.js interactive NA 2016: Tales From the Crypt

@adam_englander

Please Provide Feedback

• @adam_englander• https://speakerrate.com/talks/70701-

tales-from-the-crypt-a-cryptography-primer