TECS Week 2005 SSL TLS Case Study John

  • Slides: 48
Download presentation
TECS Week 2005 SSL / TLS Case Study John Mitchell Stanford Reference: http: //www.

TECS Week 2005 SSL / TLS Case Study John Mitchell Stanford Reference: http: //www. stanford. edu/class/cs 259/

Overview u. Introduction to the SSL / TLS protocol • Widely deployed, “real-world” security

Overview u. Introduction to the SSL / TLS protocol • Widely deployed, “real-world” security protocol u. Protocol analysis case study • • Start with the RFC describing the protocol Create an abstract model and code it up in Murj Specify security properties Run Murj to check whether security properties are satisfied

What is SSL / TLS? u. Transport Layer Security protocol, ver 1. 0 •

What is SSL / TLS? u. Transport Layer Security protocol, ver 1. 0 • De facto standard for Internet security • “The primary goal of the TLS protocol is to provide privacy and data integrity between two communicating applications” • In practice, used to protect information transmitted between browsers and Web servers u. Based on Secure Sockets Layers protocol, ver 3. 0 • Same protocol design, different algorithms u. Deployed in nearly every web browser

SSL / TLS in the Real World

SSL / TLS in the Real World

History of the Protocol u. SSL 1. 0 • Internal Netscape design, early 1994?

History of the Protocol u. SSL 1. 0 • Internal Netscape design, early 1994? • Lost in the mists of time u. SSL 2. 0 • Published by Netscape, November 1994 • Badly broken u. SSL 3. 0 • Designed by Netscape and Paul Kocher, November 1996 u. TLS 1. 0 • Internet standard based on SSL 3. 0, January 1999 • Not interoperable with SSL 3. 0

Let’s Get Going… Informal Protocol Description Formal Protocol Intruder Model RFC (request for comments)

Let’s Get Going… Informal Protocol Description Formal Protocol Intruder Model RFC (request for comments) Find error Analysis Tool

Request for Comments u. Network protocols are usually disseminated in the form of an

Request for Comments u. Network protocols are usually disseminated in the form of an RFC u. TLS version 1. 0 is described in RFC 2246 u. Intended to be a self-contained definition • Describes the protocol in sufficient detail for readers who will be implementing it and those who will be doing protocol analysis (that’s you!) • Mixture of informal prose and pseudo-code u. Read some RFCs to get a flavor of what protocols look like when they emerge from the committee

Evolution of the SSL/TLS RFC

Evolution of the SSL/TLS RFC

From RFC to Murj Informal Protocol Description RFC Model Formal Protocol Intruder Model Murj

From RFC to Murj Informal Protocol Description RFC Model Formal Protocol Intruder Model Murj code Find error Analysis Tool

TLS Basics u. TLS consists of two protocols u. Handshake protocol • Use public-key

TLS Basics u. TLS consists of two protocols u. Handshake protocol • Use public-key cryptography to establish a shared secret key between the client and the server u. Record protocol • Use the secret key established in the handshake protocol to protect communication between the client and the server u. We will focus on the handshake protocol

TLS Handshake Protocol u. Two parties: client and server u. Negotiate version of the

TLS Handshake Protocol u. Two parties: client and server u. Negotiate version of the protocol and the set of cryptographic algorithms to be used • Interoperability between different implementations of the protocol u. Authenticate client and server (optional) • Use digital certificates to learn each other’s public keys and verify each other’s identity u. Use public keys to establish a shared secret

Handshake Protocol Client. Hello C S C, Ver. C, Suite. C, NC Server. Hello

Handshake Protocol Client. Hello C S C, Ver. C, Suite. C, NC Server. Hello S C Ver. S, Suite. S, NS, sign. CA{ S, KS } Client. Verify C S sign. CA{ C, VC } { Ver. C, Secret. C } KS S sign. C { Hash( Master(NC, NS, Secret. C) + Pad 2 + Hash(Msgs + C + Master(NC, NS, Secret. C) + Pad 1)) } (Change to negotiated cipher) Server. Finished S C { Hash( Master(NC, NS, Secret. C) + Pad 2 + Hash( Msgs + S + Master(NC, NS, Secret. C) + Pad 1)) } Master(NC, NS, Secret. C) Client. Finished C S { Hash( Master(NC, NS, Secret. C) + Pad 2 + Hash( Msgs + C + Master(NC, NS, Secret. C) + Pad 1)) } Master(N , Secret ) C S C

Handshake Protocol Structure Client. Hello Server. Hello, [Certificate], [Server. Key. Exchange], [Certificate. Request], Server.

Handshake Protocol Structure Client. Hello Server. Hello, [Certificate], [Server. Key. Exchange], [Certificate. Request], Server. Hello. Done C [Certificate], Client. Key. Exchange, [Certificate. Verify] switch to negotiated cipher Finished S

Abbreviated Handshake u. The handshake protocol may be executed in an abbreviated form to

Abbreviated Handshake u. The handshake protocol may be executed in an abbreviated form to resume a previously established session • No authentication, key material not exchanged • Session resumed from an old state u. For complete analysis, have to model both full and abbreviated handshake protocol • This is a common situation: many protocols have several branches, subprotocols for error handling, etc.

Rational Reconstruction u Begin with simple, intuitive protocol • Ignore client authentication • Ignore

Rational Reconstruction u Begin with simple, intuitive protocol • Ignore client authentication • Ignore verification messages at the end of the handshake protocol • Model only essential parts of messages (e. g. , ignore padding) u. Execute the model checker and find a bug u. Add a piece of TLS to fix the bug and repeat • Better understand the design of the protocol

Protocol Step by Step: Client. Hello Client announces (in plaintext): • Protocol version he

Protocol Step by Step: Client. Hello Client announces (in plaintext): • Protocol version he is running • Cryptographic algorithms he supports C S

Client. Hello (RFC) struct { Protocol. Version client_version; Session id (if the client wants

Client. Hello (RFC) struct { Protocol. Version client_version; Session id (if the client wants to Random random; resume an old session) Session. ID session_id; Cryptographic algorithms supported by the client (e. g. , Cipher. Suite cipher_suites; RSA or Diffie-Hellman) Compression. Method compression_methods; } Client. Hello Highest version of the protocol supported by the client

Client. Hello (Murj) ruleset i: Client. Id do ruleset j: Server. Id do rule

Client. Hello (Murj) ruleset i: Client. Id do ruleset j: Server. Id do rule "Client sends Client. Hello to server (new session)" cli[i]. state = M_SLEEP & cli[i]. resume. Session = false ==> var out. M: Message; -- outgoing message begin out. M. source : = i; out. M. dest : = j; out. M. session : = 0; out. M. m. Type : = M_CLIENT_HELLO; out. M. version : = cli[i]. version; out. M. suite : = cli[i]. suite; out. M. random : = fresh. Nonce(); multisetadd (out. M, cli. Net); cli[i]. state : = M_SERVER_HELLO; end;

Server. Hello C, Versionc, suitec, Nc Server. Hello C Server responds (in plaintext) with:

Server. Hello C, Versionc, suitec, Nc Server. Hello C Server responds (in plaintext) with: • Highest protocol version both client & server support • Strongest cryptographic suite selected from those offered by the client S

Server. Hello (Murj) ruleset i: Server. Id do choose l: ser. Net do rule

Server. Hello (Murj) ruleset i: Server. Id do choose l: ser. Net do rule “Server receives Server. Hello (new session)" ser[i]. clients[0]. state = M_CLIENT_HELLO & ser. Net[l]. dest = i & ser. Net[l]. session = 0 ==> var in. M: Message; -- incoming message out. M: Message; -- outgoing message begin in. M : = ser. Net[l]; -- receive message if in. M. m. Type = M_CLIENT_HELLO then out. M. source : = i; out. M. dest : = in. M. source; out. M. session : = fresh. Session. Id(); out. M. m. Type : = M_SERVER_HELLO; out. M. version : = ser[i]. version; out. M. suite : = ser[i]. suite; out. M. random : = fresh. Nonce(); multisetadd (out. M, ser. Net); ser[i]. state : = M_SERVER_SEND_KEY; end;

Server. Key. Exchange C, Versionc, suitec, Nc Versions, suites, Ns, Server. Key. Exchange C

Server. Key. Exchange C, Versionc, suitec, Nc Versions, suites, Ns, Server. Key. Exchange C Server responds with his public-key certificate containing either his RSA, or his Diffie-Hellman public key (depending on chosen crypto suite) S

“Abstract” Cryptography u. We will use abstract data types to model cryptographic operations •

“Abstract” Cryptography u. We will use abstract data types to model cryptographic operations • Assumes that cryptography is perfect • No details of the actual cryptographic schemes • Ignores bit length of keys, random numbers, etc. u. Simple notation for encryption, signatures, hashes • {M}k is message M encrypted with key k • sigk(M) is message M digitally signed with key k • hash(M) for the result of hashing message M with a cryptographically strong hash function

Client. Key. Exchange C, Versionc, suitec, Nc Versions, suites, Ns, sigca(S, Ks), “Server. Hello.

Client. Key. Exchange C, Versionc, suitec, Nc Versions, suites, Ns, sigca(S, Ks), “Server. Hello. Done” C Client. Key. Exchange Client generates some secret key material and sends it to the server encrypted with the server’s public key S

Client. Key. Exchange (RFC) Let’s model this as {Secret } struct { select (Key.

Client. Key. Exchange (RFC) Let’s model this as {Secret } struct { select (Key. Exchange. Algorithm) { case rsa: Encrypted. Pre. Master. Secret; case diffie_hellman: Client. Diffie. Hellman. Public; } exchange_keys } Client. Key. Exchange c Ks struct { Protocol. Version client_version; opaque random[46]; } Pre. Master. Secret

“Core” SSL C, Versionc, suitec, Nc Versions, suites, Ns, sigca(S, Ks), “Server. Hello. Done”

“Core” SSL C, Versionc, suitec, Nc Versions, suites, Ns, sigca(S, Ks), “Server. Hello. Done” C S {Secretc}Ks If the protocol is correct, C and S share some secret key material secretc at this point switch to key derived from secretc

Participants as Finite-State Machines Murj rules define a finite-state machine for each protocol participant

Participants as Finite-State Machines Murj rules define a finite-state machine for each protocol participant Client state Server state Client. Hello M_SLEEP M_CLIENT_HELLO Server. Hello M_SERVER_HELLO M_SEND_KEY Server. Key. Exchange M_SERVER_KEY M_SEND_KEY M_CLIENT_KEY Client. Key. Exchange M_DONE

Intruder Model Informal Protocol Description RFC Formal Protocol Intruder Model Murj code Find error

Intruder Model Informal Protocol Description RFC Formal Protocol Intruder Model Murj code Find error Murj code, similar for all protocols Analysis Tool

Intruder Can Intercept u. Store a message from the network in the data structure

Intruder Can Intercept u. Store a message from the network in the data structure modeling intruder’s “knowledge” ruleset i: Intruder. Id do choose l: cli. Net do rule "Intruder intercepts client's message" cli. Net[l]. from. Intruder = false ==> begin alias msg: cli. Net[l] do -- message from the net … alias known: int[i]. messages do if multisetcount(m: known, msg. Equal(known[m], msg)) = 0 then multisetadd(msg, known); end;

Intruder Can Decrypt if Knows Key u. If the key is stored in the

Intruder Can Decrypt if Knows Key u. If the key is stored in the data structure modeling intruder’s “knowledge”, then read message ruleset i: Intruder. Id do choose l: cli. Net do rule "Intruder intercepts client's message" cli. Net[l]. from. Intruder = false ==> begin alias msg: cli. Net[l] do -- message from the net … if msg. m. Type = M_CLIENT_KEY_EXCHANGE then if key. Equal(msg. enc. Key, int[i]. public. Key. key) then alias s. Keys: int[i]. secret. Keys do if multisetcount(s: s. Keys, key. Equal(s. Keys[s], msg. secret. Key)) = 0 then multisetadd(msg. secret. Key, s. Keys); end;

Intruder Can Create New Messages u. Assemble pieces stored in the intruder’s “knowledge” to

Intruder Can Create New Messages u. Assemble pieces stored in the intruder’s “knowledge” to form a message of the right format ruleset i: Intruder. Id do ruleset d: Client. Id do ruleset s: Valid. Session. Id do choose n: int[i]. nonces do ruleset version: Versions do rule "Intruder generates fake Server. Hello" cli[d]. state = M_SERVER_HELLO ==> var out. M: Message; -- outgoing message begin out. M. source : = i; out. M. dest : = d; out. M. session : = s; out. M. m. Type : = M_SERVER_HELLO; out. M. version : = version; out. M. random : = int[i]. nonces[n]; multisetadd (out. M, cli. Net); end;

Intruder Model and Cryptography u. There is no actual cryptography in our model •

Intruder Model and Cryptography u. There is no actual cryptography in our model • Messages are marked as “encrypted” or “signed”, and the intruder rules respect these markers u. Our assumption that cryptography is perfect is reflected in the absence of certain intruder rules • There is no rule for creating a digital signature with a key that is not known to the intruder • There is no rule for reading the contents of a message which is marked as “encrypted” with a certain key, when this key is not known to the intruder • There is no rule for reading the contents of a “hashed” message

Running Murj Analysis Informal Protocol Description RFC Formal Protocol Intruder Model Murj code Find

Running Murj Analysis Informal Protocol Description RFC Formal Protocol Intruder Model Murj code Find error Specify security conditions and run Murj code, similar for all protocols Analysis Tool

Secrecy u. Intruder should not be able to learn the secret generated by the

Secrecy u. Intruder should not be able to learn the secret generated by the client ruleset i: Client. Id do ruleset j: Intruder. Id do rule "Intruder has learned a client's secret" cli[i]. state = M_DONE & multisetcount(s: int[j]. secret. Keys, key. Equal(int[j]. secret. Keys[s], cli[i]. secret. Key)) > 0 ==> begin error "Intruder has learned a client's secret" end;

Shared Secret Consistency u. After the protocol has finished, client and server should agree

Shared Secret Consistency u. After the protocol has finished, client and server should agree on their shared secret ruleset i: Server. Id do ruleset s: Session. Id do rule "Server's shared secret is not the same as its client's" ismember(ser[i]. clients[s]. client, Client. Id) & ser[i]. clients[s]. state = M_DONE & cli[ser[i]. clients[s]. client]. state = M_DONE & !key. Equal(cli[ser[i]. clients[s]. client]. secret. Key, ser[i]. clients[s]. secret. Key) ==> begin error "S's secret is not the same as C's" end;

Version and Crypto Suite Consistency u. Client and server should be running the highest

Version and Crypto Suite Consistency u. Client and server should be running the highest version of the protocol they both support ruleset i: Server. Id do ruleset s: Session. Id do rule "Server has not learned the client's version or suite correctly" !ismember(ser[i]. clients[s]. client, Intruder. Id) & ser[i]. clients[s]. state = M_DONE & cli[ser[i]. clients[s]. client]. state = M_DONE & (ser[i]. clients[s]. client. Version != Max. Version | ser[i]. clients[s]. client. Suite. text != 0) ==> begin error "Server has not learned the client's version or suite correctly" end;

Finite-State Verification l . . . l l Correctness condition violated l Murj rules

Finite-State Verification l . . . l l Correctness condition violated l Murj rules for protocol participants and the intruder define a nondeterministic state transition graph Murj will exhaustively enumerate all graph nodes Murj will verify whether specified security conditions hold in every reachable node If not, the path to the violating node will describe the attack

When Does Murj Violation? Find a u. Bad abstraction • Removed too much detail

When Does Murj Violation? Find a u. Bad abstraction • Removed too much detail from the protocol when constructing the abstract model • Add the piece that fixes the bug and repeat • This is part of the rational reconstruction process u. Genuine attack • Yay! Hooray! • Attacks found by formal analysis are usually quite strong: independent of specific cryptographic schemes, OS implementation, etc. • Test an implementation of the protocol, if available

“Core” SSL 3. 0 C, Versionc=3. 0, suitec, Nc Versions=3. 0, suites, Ns, sigca(S,

“Core” SSL 3. 0 C, Versionc=3. 0, suitec, Nc Versions=3. 0, suites, Ns, sigca(S, Ks), “Server. Hello. Done” C S {Secretc}Ks If the protocol is correct, C and S share some secret key material secretc at this point switch to key derived from secretc

Version Consistency Fails! C, Versionc=2. 0, suitec, Nc Server is fooled into thinking he

Version Consistency Fails! C, Versionc=2. 0, suitec, Nc Server is fooled into thinking he is communicating with a client who supports only SSL 2. 0 C Versions=2. 0, suites, Ns, sigca(S, Ks), “Server. Hello. Done” {Secretc}Ks C and S end up communicating using SSL 2. 0 (weaker earlier version of the protocol) S

Fixed “Core” SSL C, Versionc=3. 0, suitec, Nc C Versions=3. 0, suites, Ns, sigca(S,

Fixed “Core” SSL C, Versionc=3. 0, suitec, Nc C Versions=3. 0, suites, Ns, sigca(S, Ks), “Server. Hello. Done” Prevents version rollback attack {Versionc, Secretc}Ks Add rule to check that received version is equal to version in Client. Hello If the protocol is correct, C and S share some secret key material secretc at this point switch to key derived from secretc S

A Case of Bad Abstraction Model this as {Version , Secret } struct {

A Case of Bad Abstraction Model this as {Version , Secret } struct { select (Key. Exchange. Algorithm) { case rsa: Encrypted. Pre. Master. Secret; case diffie_hellman: Client. Diffie. Hellman. Public; } exchange_keys } Client. Key. Exchange c This piece matters! Need to add it to the model. struct { Protocol. Version client_version; opaque random[46]; } Pre. Master. Secret c Ks

Summary of Reconstruction u. A = Basic protocol u. C = A + certificates

Summary of Reconstruction u. A = Basic protocol u. C = A + certificates for public keys – Authentication for client and server u. E = C + verification (Finished) messages – Prevention of version and crypto suite attacks u. F = E + nonces – Prevention of replay attacks u. Z = “Correct” subset of SSL

Anomaly (Protocol F) … Suite. C … … Suite. S … … C Switch

Anomaly (Protocol F) … Suite. C … … Suite. S … … C Switch to negotiated cipher Finished data S

Anomaly (Protocol F) … Suite if. Cy… d o M … Suite. Sf… y

Anomaly (Protocol F) … Suite if. Cy… d o M … Suite. Sf… y i d o M… C Switch to negotiated cipher X Finished data S

Protocol Resumption Session. Id, Ver. C= 3. 0, NC, . . . Ver. S=

Protocol Resumption Session. Id, Ver. C= 3. 0, NC, . . . Ver. S= 3. 0, NS, . . . C Finished data S

Version Rollback Attack Session. Id, Ver. C= 2. 0, NC, . . . Ver.

Version Rollback Attack Session. Id, Ver. C= 2. 0, NC, . . . Ver. S= 2. 0, NS, . . . C X Finished { NS } Secret. Key data X Finished { NC } Secret. Key data S

Basic Pattern for Doing This Yourself u. Read and understand protocol specification • Typically

Basic Pattern for Doing This Yourself u. Read and understand protocol specification • Typically an RFC or a research paper • We’ll have a few on the CS 259 website: take a look! u. Choose a tool • Murj works, also many other tools • Play with Murj now to get some experience (installing, running simple models, etc. ) u. Start with a simple (possibly flawed) model • Rational reconstruction is a good way to go u. Give careful thought to security conditions

Background Reading on SSL 3. 0 Optional, for deeper understanding of SSL / TLS

Background Reading on SSL 3. 0 Optional, for deeper understanding of SSL / TLS u D. Wagner and B. Schneier. “Analysis of the SSL 3. 0 protocol. ” USENIX Electronic Commerce ’ 96. • Nice study of an early proposal for SSL 3. 0 u J. C. Mitchell, V. Shmatikov, U. Stern. “Finite-State Analysis of SSL 3. 0”. USENIX Security ’ 98. • Mur analysis of SSL 3. 0 (similar to this lecture) • Actual Mur model available u D. Bleichenbacher. “Chosen Ciphertext Attacks against Protocols Based on RSA Encryption Standard PKCS #1”. CRYPTO ’ 98. • Cryptography is not perfect: this paper breaks SSL 3. 0 by directly attacking underlying implementation of RSA