Top Banner
CS 645 : Lecture 6 Hashes, HMAC, and Authentication Rachel Greenstadt May 16, 2012 Wednesday, May 16, 2012
64

CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Feb 10, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

CS 645 : Lecture 6Hashes, HMAC, and

AuthenticationRachel Greenstadt

May 16, 2012

Wednesday, May 16, 2012

Page 2: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Reminders

• Graded project 2, midterm, available on bbvista

• Project 3 out (crypto)

• Next two weeks entirely online. I will send out links to lectures.

• Short simple quiz on lectures will be on bbvista week of June 4 (folded into participation grade)

Wednesday, May 16, 2012

Page 3: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Authenticating Messages

• Hash Functions

• MAC

• HMAC

• SSL Man-in-the-middle / Project 4

Wednesday, May 16, 2012

Page 4: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Introduction to Hash Functions

• If H is a hash function, m is an input bit string, and h is the output of H applied to the input m, then we write h = H(m). Some common and useful terminology:

• If h = H(m) then

• h is called the "hash" of m,

• m is called a "preimage" of h,

• for a given input m, a "second preimage" of m is a different input m' such that H(m) = H(m'),

• if m and m' are different inputs such that H(m) = H(m') then the pair {m,m'}

is called a "collision" for H.

Wednesday, May 16, 2012

Page 5: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Collision Resistance

• Strong collision resistance

• Hard to find *any* x,y such that h(x)=h(y)

• Weak collision resistance / preimage attacks

• First preimage attack: given hash h1, find m such that h(m) = h1

• Second preimage attack : Given message m1 find message m2 such that h(m1) = h(m2)

Wednesday, May 16, 2012

Page 6: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Exercise

• Explain the difference between breaking strong collision resistance and a second pre-image attack?

• Quantify this difference in how long it would take to brute-force the attack for a perfect hash function of n bits.

Wednesday, May 16, 2012

Page 7: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

• First case

• H(“hello world”) = x find y such that H(y) =x

• Second case

• m and m’ s.t. H(m) = H(m’)

Wednesday, May 16, 2012

Page 8: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Birthday Attacks on Collision Resistance

• Given function h, goal is find two inputs x,y such that h(x) = h(y)

• Based on the birthday paradox: A group of 23 or more people will have the same probability > 50%

• H different outputs, then expected 1.25*sqrt(H) to find a match

• so 2160 outputs for SHA-1, leads to approx 280 tries

Wednesday, May 16, 2012

Page 9: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Types of Hash Functions

• MD5

• 128-bit output

• Designed by Ron Rivest, used very widely

• Collision-resistance broken (summer of 2004 and it keeps getting worse)

• RIPEMD-160

• 160-bit variant of MD5

• SHA-1 (Secure Hash Algorithm)

• 160-bit output

• US government (NIST) standard as of 1993-95

• Also the hash algorithm for Digital Signature Standard (DSS)

Wednesday, May 16, 2012

Page 10: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Group exercise

• Hash functions are reasonably fast, but here's a much faster function to compute. Take your message,divide it into 128-bit chunks, and xor all the chunks together to get a 128-bit result. Do the standard hash function on the result. Is this a good hash function? Why or why not?

Wednesday, May 16, 2012

Page 11: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

SHA-1

Wednesday, May 16, 2012

Page 12: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

SHA-1 Compression Function

Wednesday, May 16, 2012

Page 13: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

How Strong is SHA-1?

• Every bit of output depends on every bit of input

• Very important for collision resistance

• Brute-force inversion requires 2160 ops, birthday attack on collision resistance requires 280

• Recent weaknesses (2005)

• Collisions can be found in 263 ops

Wednesday, May 16, 2012

Page 14: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Authentication without Encryption

Integrity and Authentication: only someone who knows key can compute MAC for a given message

Wednesday, May 16, 2012

Page 15: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

How to hash the key and message?

• Seems easy, just compute h(key|message)

• Problems?

• Assume h is SHA-1

• Recall that in SHA-1, the message is hashed from left to right in 512 bit chunks

Wednesday, May 16, 2012

Page 16: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Enter Carol• Bob is Carol’s boss, and Alice is Bob’s boss

• Carol appends “P.S. Give Carol a promotion and triple her salary” to Alice’s message to Bob

Carol can take the original message, add some padding, then add her postscript and pass it into SHA-1

Wednesday, May 16, 2012

Page 17: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

HMAC

• MAC that is “as secure as underlying hash”

• Strong collision resistance

• attacker that doesn’t know key K cannot compute digest(K,x) for data x even if the attacker can see digest(K,y) for arbitrary y not equal to x

• Result slow but provable

Wednesday, May 16, 2012

Page 18: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

HMAC

• Construct MAC by applying cryptographic hash function to message and key

• Could also use encryption instead of hashing, but…

• Hashing is faster than encryption in software

• Library code for hash functions widely available

• Can easily replace one hash function with another

• There used to be US export restrictions on encryption

• Invented by Bellare, Canetti, and Krawczyk (1996)

• HMAC strength established by cryptographic analysis

• Mandatory for IP security, also used in SSL/TLS

Wednesday, May 16, 2012

Page 19: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

How HMAC Works

• If key > 512 bits, digest(key) and pad to 512 else if key < 512 bits, pad to 512

• result1 = digest ((Const1 XOR padded key) . message)

• result2 = digest((Const2 XOR padded key) . result1)

• HMAC(message, key) = result2

Wednesday, May 16, 2012

Page 20: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

HMAC

Wednesday, May 16, 2012

Page 21: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Combine encryption and MAC for confidentiality and

integrity

Wednesday, May 16, 2012

Page 22: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Encrypt-and-MAC

Wednesday, May 16, 2012

Page 23: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Insecure!

Wednesday, May 16, 2012

Page 24: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Attacks• Confidentiality considers indistinguishability

under...

• Chosen Plaintext Attack (CPA) An attacker can obtain the ciphertext for any provided plaintext (but does not have the key).

• Chosen Ciphertext Attack (CCA) An attacker can obtain the plaintext for any provided ciphertext (but does not have the key).

• Integrity

• PTXT - Integrity of Plaintext - computationally infeasible to produce a ciphertext decrypting to a message that the sender had never encrypted.

• CTXT - Integrity of Ciphertext To be computationally infeasible to produce a ciphertext not previously produced by the sender.

Wednesday, May 16, 2012

Page 25: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Wednesday, May 16, 2012

Page 26: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Authenticating Users

• Passwords

• Alternatives

• Multi-factor Authentication

“Something you forget, something you lose, and something you used to be”

Wednesday, May 16, 2012

Page 27: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Password Security Review

• Summarize system

• Identify assets: What do you wish to protect

• Identify adversaries and threats

• Identify vulnerabilities

• Calculate the risks

• Evaluate controls/mitigation strategies

• Iterate

Wednesday, May 16, 2012

Page 28: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Assets

Wednesday, May 16, 2012

Page 29: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Adversaries

Wednesday, May 16, 2012

Page 30: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Vulnerabilities

Wednesday, May 16, 2012

Page 31: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Vulnerabilities

• Online guessing/dictionary attack

• Offline guessing/dictionary attack

• Shared passwords

• Password fallback schemes

Wednesday, May 16, 2012

Page 32: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Risks

Wednesday, May 16, 2012

Page 33: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Mitigation Strategies

Wednesday, May 16, 2012

Page 34: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Mitigation Strategies

• Salts

• Encrypted Storage

• Challenge/Response

Wednesday, May 16, 2012

Page 35: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Alternatives to Passwords

• Graphical passwords, phrases

• Tokens/dongles

• Biometrics

Wednesday, May 16, 2012

Page 36: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Multifactor Authentication

Wednesday, May 16, 2012

Page 37: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Public Key Authentication

Wednesday, May 16, 2012

Page 38: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Wednesday, May 16, 2012

Page 39: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Wednesday, May 16, 2012

Page 40: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Wednesday, May 16, 2012

Page 41: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

X509 Certificates

Wednesday, May 16, 2012

Page 42: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Bad Certificates

• What to do if a bad certificate is issued?

• In practice...wait for it to expire

• In theory

• Revocation Services

• Revocation Lists

Wednesday, May 16, 2012

Page 43: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Programming Project 4• Out May 12

• Due May 26 11:59pm

• Teams of up to three people

• New teams OK (old teams also OK)

• Basic idea: Implement a “Man-in-the-Middle” attack against SSL

• Recall Security and Privacy Ethics

• Based on Dan Boneh’s CS255 project (Stanford)/ Yoshi Kohno’s CSE 484 project (U Washington)

• Slides: http://crypto.stanford.edu/~dabo/cs255/proj2_pres.pdf

Wednesday, May 16, 2012

Page 44: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Overview

• Implement a simple Man In The Middle

(MITM) attack on SSL

• Use Java’s networking, SSL and

Certificate implementations

– No need for low level packet manipulation

• Also implement a password based

authentication system for the MITM server

– Allows hacker to issue commands to server

Wednesday, May 16, 2012

Page 45: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Overview

• Normal SSL

– SSL encrypted data routed like normal TCP/IP

data over the internet

Internet

SSL Web

Server

Wednesday, May 16, 2012

Page 46: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Proxy Server

• Browser connects to proxy

• Proxy connects to web server and

forwards between the two

Internet

SSL Web

Server

Wednesday, May 16, 2012

Page 47: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Man in the Middle

• Instead of forwarding encrypted data between the two hosts, our proxy will set up two DIFFERENT SSL connections between the two.

• Proxy<->Remote Server– Sets up a normal SSL client connection to requested

remote site

• Proxy<->Browser– Sets up a SSL server connection to the browser,

using its own certificate, generated as a copy of the remote host’s cert

• If the browser accepts this fake cert, the proxy has access to the data in the clear!

Wednesday, May 16, 2012

Page 48: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Security Features

• Secure connection between admin client and proxy server using SSL

• Password based authentication

• Secure storage

• Passwords stored hashed using public and private salts

Wednesday, May 16, 2012

Page 49: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Proxy Server

• Already listens for the browser CONNECT request and sets up the needed SSL connections

• You need to– Understand the connections being made

– Obtain the remote server cert from the remote SSL conn

– Copy the relevant fields and sign the forged cert using your CA cert (from your keystore) (use IAIK)

– Modify the code creating the client SSL conn to use the newly forged cert

Wednesday, May 16, 2012

Page 50: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Signing Certificate

• Build a self signed cert for the proxy server using keytool– keytool –genkey –keyalg RSA

– Store this in a JKS keystore for use by your proxy server

– Use it for signing your programmatically generated certs

– You pretend to be a CA e.g. Verisign

• Submit a keystore with your project

Wednesday, May 16, 2012

Page 51: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Generating Certs “On the Fly”

• Not easy to generate certs

programmatically using standard Java libs

• Use the IAIK-JCE library

– iaik.x509.X509Certificate

Wednesday, May 16, 2012

Page 52: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

iaik.x509.X509Certificate

• To convert from a java cert:

– new X509Certficate(javaCert.getEncoded());

• Signing

– cert.sign(

AlgorithmID.sha256withRSAEncryption,

issuerPk );

• See iaik.asn1.structures.Name

– For extracting info (e.g. common name) from

the cert’s DN (cert.getSubjectDN() )

Wednesday, May 16, 2012

Page 53: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Managing Certs and SSL

Sockets• Use the KeyStore class for

– Loading certs from file (e.g. your CA cert)

– Storing programmatically generated certs

• Use SSLContext class for setting up certs to be used with an SSLServerSocket– Create a cert

– Load into new KeyStore

– Init a KeyFactoryManager with new KeyStore

– Init SSLContext with new KeyFactoryManager and provided “TrustEveryone” TrustManager

• Use SSLContext for creating SSLSocketFactories

Wednesday, May 16, 2012

Page 54: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Admin Server

• Already listens for client connections and parses the data sent, using plain sockets

• You need to– Modify the code to use SSL sockets (see the

proxy server code for examples)

– Implement authentication for the transmitted username and password

– Implement the required admin commands• Shutdown – the proxy server to stops accepting

connections and exit

• Stats – the proxy server returns a summary of the number of connections it has processed. Add code to record these

Wednesday, May 16, 2012

Page 55: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Password Authentication

• Proxy server listens for SSL connections

from admin client too

• On connection client transmits a username

and password

• Server verifies these from its local

password file, and executes command if

the client is authenticated

Wednesday, May 16, 2012

Page 56: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Password File

• Need to store a file containing usernames, salts, and hashed passwords

• Use BOTH public and secret salts (AKA pepper)

• Should be stored encrypted/MACed

Wednesday, May 16, 2012

Page 57: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Password File Utility

• You need to add a utility for creating these

password files

• Simple method:

– Make a class to take a file with a list of

usernames and passwords and convert it to a

password file

Wednesday, May 16, 2012

Page 58: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Configuring Mozilla

Wednesday, May 16, 2012

Page 59: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Wednesday, May 16, 2012

Page 60: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Wednesday, May 16, 2012

Page 61: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Getting the Proxy to Work

• Try it out on (non-sensitive) SSL sites

• You should see one warning, be able to click past it (continue) and go to site

• (Not Firefox 3)

• Click View Certificate (or see details) to see your cert and verify that its fields are correct

Wednesday, May 16, 2012

Page 62: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Possible Problems

• You should be able to start up the proxy server and connect to it “out of the box”

• If you are having problems– Is someone else using the port? (default 8001)

• Try a different port on the command line

– Firewall problems?• Try opening the needed ports 8001/8002 (or whatever)

– Try running your browser on the same machine and setting the proxy as localhost

– We can’t debug your local network setup

Wednesday, May 16, 2012

Page 63: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Grading

• Security comes first

– Design choices

– Correctness of the implementation

• Did you implement all required parts?

• Secondary

– Cosmetics

– Coding style

– Efficiency

Wednesday, May 16, 2012

Page 64: CS 645 : Lecture 6 Hashes, HMAC, and Authentication

Submitting (Email a tarball)

• README file

• Names

• Describe your design choices

• How to run your system (e.g. create passwords)

• Answer to discussion question

• Your sources

• A sample of data recorded from your proxy

Wednesday, May 16, 2012