Cryptography for Django Applications
A review of encryption in the context of a web application storing sensitive information. Topics covered include choosing whether to use crypto, selection of tools, proper usage (including examples), and operational considerations with respect to security assessment.
The web is a hostile place, and isn't showing any signs of becoming less so. In order to mitigate this, many developers turn to cryptography. Unfortunately, cryptography can be complicated, and is easily circumvented if not properly handled. This presentation will provide an introduction to cryptographic tools available to Python/Django applications, appropriate use cases for each, proper usage, and operational concerns necessary to operate in a certified environment. Finally, we will also demonstrate a reusable application that wraps this all up, providing secure key-management capabilities to a running Django environment via the Django admin.
Rules of Encryption
- Don't do it if you don't need it.
- Don't write your own.
- Understand what you're doing if you do.
When to encrypt?
Understand what you're protecting
- User records
Understand your attack vectors
- Data (backups, revision control)
Understand the types of encryption you might use:
Passwords are a special case. Use a key derivation function
- PBKDF2 – Upgrade to Django 1.4!
- MD5 - fine as a checksum. not fine as a cryptographic hash.
- SHA1 - fine as a checksum. becoming less fine as a cryptographic hash every day
- SHA2 - so far so good. use as many bits as you can handle.
- Caesar Cipher (for fun puzzles)
- DES (don't use)
- AES (certified)
Web of Trust
Doing it right
Use known-good algorithms
Use known-good implementations
- Open Source is good
- FIPS 140 certified implementations
- FIPS 140 / NIST configurations
Transport (always use HTTPS)
- Use good algorithms AES-256
At Rest (insecure servers or backups)
- Understand the ramifications of key management
- Use a key-derivation function
Don't be linked-in
- Salt your hashes (with a secret).
- Salt and pepper your hashes if possible (with a known unique value)
- Forced connections
- Making the application aware
- Hardened cipher selection
- Client authentication
- SSL Test Page
- Using GPG Agent
- GPG Manager App
- Use Asymmetric Encryption
Use a unique Initialization Vector if possible
- LoopBack Devices