36
Intro to Cryptography on the Web

Intro to Cryptography on the Web

Embed Size (px)

Citation preview

Page 1: Intro to Cryptography on the Web

Intro to Cryptographyon the Web

Page 2: Intro to Cryptography on the Web

Mike Wynholds@mwynholds

Page 3: Intro to Cryptography on the Web

Basicswarning… math ahead

Page 4: Intro to Cryptography on the Web

What is Crypto?cryptography = code makingcryptanalysis = code breaking

Modern crypto is all about mathprime number factorizationelliptic curvespolynomials from finite fields

Page 5: Intro to Cryptography on the Web

“A function used to map data of arbitrary size (message)

to data of fixed size (digest).”

Cryptographic Hash Function

Example: MD5, SHA

Page 6: Intro to Cryptography on the Web

Cryptographic Hash Function

Page 7: Intro to Cryptography on the Web

Cipher

Example: AES, RSA

“An algorithm used to perform encryption or

decryption, via a symmetric or asymmetric key.”

Page 8: Intro to Cryptography on the Web

Cipher

X

X

De X

Page 9: Intro to Cryptography on the Web

RSAKeys

Public key - (n, e) Private key - (n, d)

Encryption

c = me mod n

Decryption

m = cd mod n

Example

p = 61, q = 53 n = pq = 3233 e = 17 d = 2753

Encrypt with public key

m = 123 c = 12317 mod 3233 = 855

Decrypt with private key

c = 855 m = 8552753 mod 3233 = 123

Page 10: Intro to Cryptography on the Web

ECCy2 = x3 + ax + b

● A B = C⦿● Shoot a ball from A to B● Continue to next point on curse● Reflect straight up or down● Next point on the curve is C

● A A = B⦿● A B = C⦿● A C = D⦿● … n times● A X = Y⦿

Given A and n, it is easy to compute Y.Given A and Y, it is hard to compute n.

Page 11: Intro to Cryptography on the Web

Message Authentication Code (MAC)

msg = {attack: ‘dawn’} + Custer + (1876-06-26 T 02:56 UTC)

key = “secret-password-banana-elmo”

mac = h( msg + key )

payload = msg + mac

Page 12: Intro to Cryptography on the Web

Symmetric Key Cryptography

Page 13: Intro to Cryptography on the Web

Public Key Cryptography

Page 14: Intro to Cryptography on the Web

Key ExchangeDiffie-Hellman protocol

● large primes● elliptic curves● quantum shenanigans● paint

Page 15: Intro to Cryptography on the Web

Key Exchange - RSA

Page 16: Intro to Cryptography on the Web

Key Exchange - ECC

Page 17: Intro to Cryptography on the Web

SSLthat thing we use everyday

Page 18: Intro to Cryptography on the Web

TLS - Handshake (RSA)

Page 19: Intro to Cryptography on the Web

TLS - Handshake (DH)

Page 20: Intro to Cryptography on the Web

TLS - Record

Encrypt using master secretUse HMAC for validationNumber all records within HMAC body

Page 21: Intro to Cryptography on the Web

X.509 Certificates

“A small electronic document used to prove

ownership of a public key.”

Page 22: Intro to Cryptography on the Web

X.509 Certificates-----BEGIN CERTIFICATE-----MIIFRjCCBC6gAwIBAgIQIPr7QQi026A+m+4kgYqqJzANBgkqhkiG9w0BAQsFADCBkDELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxNjA0BgNVBAMTLUNPTU9ETyBSU0EgRG9tYWluIFZhbGlkYXRpb24gU2VjdXJlIFNlcnZlciBDQTAeFw0xNTEwMTUwMDAwMDBaFw0xNjEwMTQyMzU5NTlaMFAxITAfBgNVBAsTGERvbWFpbiBDb250cm9sIFZhbGlkYXRlZDEVMBMGA1UECxMMRXNzZW50aWFsU1NMMRQwEgYDVQQDEwtzdGlja2llcy5pbzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMW0wy+upYHx6YSZvYMpEi6/ZQimwfrAexNP8hvUgsXyfURC3SyE0khhWA4ksEjzr1TI0xlX/ajwYpKXUEnssc8sUkOMiWi1D09bKbGcH3xmAm5dwz2QinWNJbrPBaV7CYkwDmSSmb3gaigR5WnAI5vu5v4o+pjKz9QH6kOSh4UujBt/DIp5MYDZLfZdJv046D/ipSfHzNb8PmP+ad8oyXPjmQoP6SyO++Wbgu585cHCE5D9m1xJ+rQm0e5NETi83MrZwsOiFNVqgGvhLtODhOFjpxgPUbAVZNZftp2X3BZRnyOb1+M4QjGbJzudoAuhTS2D+7fh2vbHY+S7R1u3g2sCAwEAAaOCAdkwggHVMB8GA1UdIwQYMBaAFJCvajqUWgvYkOoSVnPfQ7Q6KNrnMB0GA1UdDgQWBBS51J87AwSMuHXTigX9E6NREsl05kU0N04ThSTJaQ==-----END CERTIFICATE-----

Page 23: Intro to Cryptography on the Web

X.509 CertificatesNeed: Public key cryptography with entities you don’t personally know or trust

Solution: Centralized, trusted* Certificate Authorities (CA)

* sort of - don’t forget DigiNotar and many others

Page 24: Intro to Cryptography on the Web

X.509 CertificatesEntity generates public and private keyCA issues cert binding public key to certCert is downloaded during key exchangeCerts can be chained togetherRoot certs embedded in OSes and browsersAnd we trust , right?

Page 25: Intro to Cryptography on the Web

Forward SecrecyUse ephemeral session keys during TLS

record phasePeriodic new key exchangeA stolen key only works for that session

Page 26: Intro to Cryptography on the Web

Forward Secrecy

Page 27: Intro to Cryptography on the Web

Perfect Forward SecrecyPiggyback new key exchange on existing TLS

messages

Stolen key can now only compromise the last two messages

Page 28: Intro to Cryptography on the Web

HTTP Strict Transport Security

Page 29: Intro to Cryptography on the Web

Show me the Codezlet’s use nginx

Page 30: Intro to Cryptography on the Web

The Basicsserver { listen 443 ssl; server_name stickies.io; ssl_certificate certs/stickies_io.pem; ssl_certificate_key certs/stickies_io.key; # <-- 2048 bit RSA}

Page 31: Intro to Cryptography on the Web

Custom Diffie-Hellman Primesserver { listen 443 ssl; server_name stickies.io; ssl_certificate certs/stickies_io.pem; ssl_certificate_key certs/stickies_io.key; ssl_dhparam certs/dhparam.pem;}

but first…

root@server# openssl dhparam -out dhparam.pem 4096

Page 32: Intro to Cryptography on the Web

Disable SSLv3 and TLS1.0server { listen 443 ssl; server_name stickies.io; ssl_certificate certs/stickies_io.pem; ssl_certificate_key certs/stickies_io.key; ssl_dhparam certs/dhparam.pem; ssl_protocols TLSv1.1 TLSv1.2;}

Note: TLS 1.0 is required for IE 7 - 10

Page 33: Intro to Cryptography on the Web

Perfect Forward Secrecyserver { listen 443 ssl; server_name stickies.io; ssl_certificate certs/stickies_io.pem; ssl_certificate_key certs/stickies_io.key; ssl_dhparam certs/dhparam.pem; ssl_protocols TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers “EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH EDH+aRSA !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4”}

Page 34: Intro to Cryptography on the Web

HTTP Strict Transport Securityserver { listen 443 ssl; server_name stickies.io; ssl_certificate certs/stickies_io.pem; ssl_certificate_key certs/stickies_io.key; ssl_dhparam certs/dhparam.pem; ssl_protocols TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers “...” add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";}

Page 35: Intro to Cryptography on the Web

Speed it Up!server { listen 443 ssl; server_name stickies.io; ssl_certificate certs/stickies_io.pem; ssl_certificate_key certs/stickies_io.key; ssl_dhparam certs/dhparam.pem; ssl_protocols TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers “...” add_header Strict-Transport-Security "max-age=31536000; includeSubdomains"; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m;}

Page 36: Intro to Cryptography on the Web