Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Doel
Use the cryptography from the course with real tools. You prove a file was not changed (hash), protect a file with a password (symmetric encryption), exchange a secret with a public key, sign a release and check the signature, build a tiny certificate authority, and inspect the certificate of a real website. Every step answers one question an analyst gets in daily work.
Voordat je begint
openssl versionshows 3.x. Make the folder~/crypto-laband a test file:printf 'quarterly numbers: 42\n' > report.txt.
Taken
Vink een taak aan als hij klaar is. Alleen je browser onthoudt dit.
- Integrity: make the SHA-256 hash of
report.txt, change one character, and show that the hash changes completely. - Symmetric: encrypt
report.txtwith AES-256 and a password (with PBKDF2 and many iterations), decrypt it, and compare. - Asymmetric: make an RSA-3072 key pair for "Alice". Encrypt a short secret with Alice's public key; decrypt it with her private key.
- Signature: sign
report.txtwith Alice's private key (SHA-256), verify with her public key, then change the file and show that the check fails. - PKI: make a small CA (key + self-signed certificate), a certificate request for
lab.internal, sign it with the CA (with a SAN), and verify the chain. - Real world: show the issuer, the validity dates and the SANs of the certificate of
github.com. - Passwords: explain in one line why passwords are stored with a slow hash (bcrypt/argon2) and not with SHA-256, and make a SHA-512-crypt hash with
openssl passwd -6.
Controleer je werk
sha256sum report.txt
openssl dgst -sha256 -verify alice.pub -signature report.sig report.txt
openssl verify -CAfile ca.crt lab.crt
openssl x509 -in lab.crt -noout -ext subjectAltName- After the change in task 1 the hash looks totally different (avalanche effect).
- The decrypted files match the originals (
cmpprints nothing). Verified OKfor the original file,Verification failureafter a change.lab.crt: OKand the SAN showsDNS:lab.internal.
Hints
Toon de hints
openssl enc -aes-256-cbc -pbkdf2 -iter 200000 -salt -in IN -out OUT(add-dto decrypt).openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out alice.key; the public key:openssl pkey -in alice.key -pubout -out alice.pub.- RSA encrypts only small data; real tools encrypt a random AES key with RSA (hybrid encryption).
openssl s_client -connect github.com:443 -servername github.com </dev/null 2>/dev/null | openssl x509 -noout -issuer -dates -ext subjectAltName.
Oplossing
Toon de oplossing
- Hashes.
sha256sum report.txt sed 's/42/43/' report.txt > report2.txt && sha256sum report2.txt - Symmetric encryption.
- Public key encryption.
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out alice.key openssl pkey -in alice.key -pubout -out alice.pub printf 'db-password: S3cret\n' > secret.txt openssl pkeyutl -encrypt -pubin -inkey alice.pub -pkeyopt rsa_padding_mode:oaep -in secret.txt -out secret.enc openssl pkeyutl -decrypt -inkey alice.key -pkeyopt rsa_padding_mode:oaep -in secret.enc db-password: S3cret - Sign and verify.
- A small CA and a server certificate.
openssl req -x509 -newkey rsa:3072 -nodes -keyout ca.key -out ca.crt -days 365 -subj "/CN=Lab Root CA" openssl req -newkey rsa:2048 -nodes -keyout lab.key -out lab.csr -subj "/CN=lab.internal" printf 'subjectAltName=DNS:lab.internal\nextendedKeyUsage=serverAuth\n' > lab.ext openssl x509 -req -in lab.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out lab.crt -days 90 -extfile lab.ext openssl verify -CAfile ca.crt lab.crt lab.crt: OK - A real certificate.
- Passwords: a fast hash like SHA-256 lets an attacker try billions of guesses per second on a GPU; bcrypt / argon2 / SHA-512-crypt are slow on purpose and use a salt.
openssl passwd -6 'Correct-Horse-Battery'
Mijn notities
Nog geen notities.