MPRI 2-30:! Automated Verification of ! Cryptographic Protocol Implementations
K Bhargavan
(Slides from A.D. Gordon and C. Fournet)
Spring, 2014
MPRI 2-30: ! Automated Verification of ! Cryptographic Protocol - - PowerPoint PPT Presentation
MPRI 2-30: ! Automated Verification of ! Cryptographic Protocol Implementations K Bhargavan (Slides from A.D. Gordon and C. Fournet) Spring, 2014 TLS Handshakes ''''''ClientHello''''''''''''''''''99999999>'
(Slides from A.D. Gordon and C. Fournet)
Spring, 2014
''''''ClientHello''''''''''''''''''99999999>' ''''''''''''''''''''''''''''''''''''''''''''''''''''''ServerHello' '''''''''''''''''''''''''''''''''''''''''''''''''''''Certificate*' '''''''''''''''''''''''''''''''''''''''''''''''ServerKeyExchange*' ''''''''''''''''''''''''''''''''''''''''''''''CertificateRequest*' '''''''''''''''''''''''''''''''''''<99999999''''''ServerHelloDone' ''''''Certificate*' ''''''ClientKeyExchange' ''''''CertificateVerify*' ''''''[ChangeCipherSpec]' ''''''Finished'''''''''''''''''''''99999999>' '''''''''''''''''''''''''''''''''''''''''''''''[ChangeCipherSpec]' '''''''''''''''''''''''''''''''''''<99999999'''''''''''''Finished' ''''''Application'Data'''''''''''''<9999999>'''''Application'Data' ''''''ClientHello''''''''''''''''''99999999>' ''''''''''''''''''''''''''''''''''''''''''''''''''''''ServerHello' '''''''''''''''''''''''''''''''''''''''''''''''[ChangeCipherSpec]' '''''''''''''''''''''''''''''''''''<99999999'''''''''''''Finished' ''''''[ChangeCipherSpec]' ''''''Finished'''''''''''''''''''''99999999>' ''''''Application'Data'''''''''''''<9999999>'''''Application'Data'
– Negotiates protocol version,! handshake method and algorithms,! authenticated encryption method and algorithms – Authenticates peers from their certificates – Derives connection keys
''''''ClientHello' ''''''' ' ''''''''''''99999999>' ''''''''''''''''''''''''''''''''''''''''''''''''''''''ServerHello' '''''''''''''''''''''''''''''''''''''''''''''''''''''Certificate*' '''''''''''''''''''''''''''''''''''''''''''''''ServerKeyExchange*' ''''''''''''''''''''''''''''''''''''''''''''''CertificateRequest*' ''''''''''''''''''''''''''<99999999'''''''''''''''ServerHelloDone' ''''''Certificate*' ''''''ClientKeyExchange' ''''''CertificateVerify*' ''''''ChangeCipherSpec' ''''''Finished''''''''''''99999999>' '''''''''''''''''''''''''''''''''''''''''''''''''ChangeCipherSpec' ''''''''''''''''''''''''''<99999999''''''''''''''''''''''Finished' ''''''''''''''''''''''''''<9999999>''''''''''''''Application'Data' ''''''Application'Data' ' '
''''''ClientHello'Vmax$Cr$sId*$CSs$CMs$Cext'' ''''''' ' ''''''''''''99999999>' ''''''''''''''''''''''''''''''''''ServerHello'V$Sr$sId$CS$CM$Sext$' '''''''''''''''''''''''''''''''''''''''''''''''''''''Certificate*' '''''''''''''''''''''''''''''''''''''''''''''''ServerKeyExchange*' ''''''''''''''''''''''''''''''''''''''''''''''CertificateRequest*' ''''''''''''''''''''''''''<99999999'''''''''''''''ServerHelloDone' ''''''Certificate*' ''''''ClientKeyExchange' ''''''CertificateVerify*' ''''''ChangeCipherSpec' ''''''Finished'MAC(Clog)''99999999>' '''''''''''''''''''''''''''''''''''''''''''''''''ChangeCipherSpec' ''''''''''''''''''''''''''<99999999''''''''''''Finished'MAC(Slog)' ''''''''''''''''''''''''''<9999999>''''''''''''''Application'Data' ''''''Application'Data' ' ''The'key'exchange'messages'are'used'to'compute'shared' ''pre9master9secret'(PMS)'then'master9secret'(MS)'for'the'session' ' ''The'MS'and'(Cr,Sr)'are'used'to'(1)'derive'fresh'connection'keys' ''and'(2)'authenticate'the'handshake'digests'in'Finished'messages''
'''''ClientHello'Vmax$Cr$sId$CSs$CMs$Cext'' ' ' '''''''99999999>' ' '''''''''''''''''''''''''''''''''ServerHello'V$Sr$sId$CS$CM$Sext'' ''''''''''''''''''''''''''''''''''''''''''''''''ChangeCipherSpec'''''''''''''''' ''''''''''''''''''''''''''''<99999999'''''''''Finished'MAC(Slog)' '''''ChangeCipherSpec' '''''Finished'MAC(Clog)$$'''99999999>' '''''Application'Data'''''''<9999999>'''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''Application'Data' ' ' ' ''Provided'the'client'and'server'already'share'a'session'sId,' ''they'can'use'its'pre9established'master'secret'and'(Cr,'Sr)' ''to'derive'fresh'connection'keys.'' ' ''This'saves'one'round'trip'&'any'public9key'cryptography.' ' ''Otherwise'the'server'continues'with'a'full'handshake'' ''(picking'some'fresh'sId).''
''ClientHello'[Cr]''''''99999999>' '''''''''''''''''''''''''''''''''''''''''' 'ServerHello'[Sr]' ''''''''''''''''''''''Certificate'chain[dk]'''''''' '''''''''''''''''CertificateRequest*' <99999999''''''''''''''''ServerHelloDone' ''Certificate*' ''ClientKeyExchange[{pms}_ek]'' ''CertificateVerify*[sig(Clog’)]''' ''ChangeCipherSpec' ''Finished'MAC(Clog)''''99999999>''''''' '''''''''''''''''''''''''''''''''''''''''ChangeCipherSpec' ''''''''''''''''''''<99999999'''' '''''''Finished'MAC(Slog)' Application'Data''''''<9999999>'''''''''''''''Application'Data' ' ' ' ' The'client'samples'a'fresh'pms'(mostly)'at'random' ' Here'*'stands'for'“if'Client'auth”,'at'the'server'initiative' (prescribing'“for'signing”'as'X.509'attributes)'
''ClientHello'[Cr]'''''''''99999999>' '''''''''''''''''''''''''''''''''ServerHello[Sr]' ''''''''''''''''''''''Certificate'chain[vk|fixed$p$g$g^y]$ ServerKeyExchange' [p$g$g^y'sig(Cr'Sr'p'g'g^y)_vk]'''''''''''''''''' CertificateRequest*' [for'signing|fixed]' <99999999''''''''''''''''ServerHelloDone''''''' ''Certificate*'chain[for'signing|fixed'p'g'g^x]' ''ClientKeyExchange'[fixed'?'empty':'g^x']'' ''CertificateVerify*[sig(Clog’)]'' ''ChangeCipherSpec' ''Finished'MAC(Clog)$$$$$$$99999999>' '''''''''''''''''''''''''''''''''''''''''''''''ChangeCipherSpec' '''''''''''''''''''<99999999'''''''''''''Finished'MAC(Slog)'''''''' Application'Data'''''''''<9999999>'''''''''''''''Application'Data' '
' ' E'stands'for'server9ephemeral;'client9ephemeral'!'“for'signing”' Here'*'stands'for'“if'Client'auth”,'at'the'server'initiative'(prescribing'“for' signing”,'“fixed”,'or'both,'as'X.509'attributes)' …_DSA'and'…_RSA'only'affect'X.509'certs' EC…'should'only'affects'the'crypto'parameters'
'''''Alice' ' ' ' ''' ' ' ' 'Bob' agree'on'public'parameters:' p'prime,'g'generator'of'Z/pZ*,'q'='|Z/pZ*|' ' let'x'='sample'q ' ' ' ' ' 'let'y'='sample'q' let'X'='gx '
' ' ' ' ' ' 'let'Y'='gy' ' ' ' ' ' 'exchange'
' ' ' ' ' ''X'&'Y' let'Z'='Yx''
' ' ' ' ' ' 'let'Z'='Xy'' '
now'sharing'Z'='g(x*y)' we'can'derive'keys'as'PRF(Z,…)''
the probability of distinguishing between the exponentials!
El Gamal! encryption! is CPA
agree'on'public'parameters:' p'prime,'g'generator'of'Z/pZ*,'q'='|Z/pZ*|'
'
''''''Concrete ' ' ' ' ' ' ''''''Ideal'
'
let'x'='sample'q ' ' ' ' ' 'let'x'='sample'q' let'y'='sample'q ' ' ' ' ' 'let'y'='sample'q' ' ' ' ' ' ' ' ' ' 'let'z'='sample'q' ('gx,'gy,'gx*y') ' ' ' ' ' ' '('gx,'gy,'gz')' let'GEN()'='' ''let'x'='sample'q' ''(x,'gx)'
'
'
'
let'ENC'X'm'='' ''let'y'='sample'0..q' ''(gy','Xy'*'m)''
' '
let'DEC'x'(Y,M)'='M/Yx' let'ENC*'X'm'='' ''let'y'='sample'q' ''let'z'='sample'q''' ''(gy','gz'*'m)''
'
– Handshake messages and their formats – Certificate formats and public key infrastructure – Database of past sessions, available for abbreviated handshakes
safe when
– Its ciphersuite is cryptographically strong; and – Its peer authentication materials are trustworthy! e.g. the private key for the peer certificate! is used only by compliant handshake sessions
– Generates fresh abstract keys instead of calling the concrete KDF – Drops “Complete” notifications not preceded by a Finished ! with matching parameters sent by a compliant peer instance.
type$(;r:role,o:config)$state$//$for$each$local$instance$of$the$protocol$ type$(;ki:KeyInfo)$fragment$$$//$content$type$for$the$Handshake$protocol$ type$(;ki:KeyInfo)$ccs$$$$$$$$//$content$type$for$the$Handshake$protocol$
$
//$Control$Interface$$ val$init:$$$$$$$$$$$r:role$$$$$$$$$$$$$$N>$o:config$N>$(;r$$$$$,o)$state$$ val$resume:$$$$$$$$$si:SessionInfo$$$$$$N>$o:config$N>$(;Client,o)$state$ val$rehandshake:$$$(;Client,idle)$state$N>$o:config$N>$(;Client,o)$state$ val$rekey:$$$$$$$$$(;Client,idle)$state$N>$o:config$N>$(;Client,o)$state$ val$request:$$$$$$$(;Server,idle)$state$N>$o:config$N>$(;Server,o)$state$
$
//$Network$Interface$(output)$ type$(;r:role,o:config,ki:KeyInfo)$outgoing$=$$ $$|$OutFragment$of$$$$$(;r,o)$state$*$(;ki)$fragment$option$$$$$$$$$$$$$$ $$|$OutCCS$of$$$$$$$$s:(;r,o)$state$*$(;ki)$ccs$*$(;OutKi(s))$ccs_data$ $$|$OutComplete$of$$$s:(;r,o)$state${Complete(r,o,s)}$$ $$|$...$ val$nextFragment:$ $$r:role$N>$o:config$N>$ki:KeyInfo$N>$$ $$(;r,o)$state$N>$(;r,o,ki)$outgoing$$
$
//$Network$Interface$(input)$ type$(;r:role,o:config)$incoming$=$$ $$|$InTLSVersion$of$$$$(;r,o)$state$*$ProtocolVersion$ $$|$InComplete$of$$$$s:(;r,_)$state${Complete(r,o,s)}$$$ $$|$...$ val$recvFragment:$$ $$r:role$N>$o:config$N>$ki:KeyInfo$N>$ $$(;r,o)$state$N>$(;ki)$fragment$N>$(;r,o)$incoming$ val$recvCCS:$ $$r:role$N>$o:config$N>$ki:KeyInfo$N>$$ $$(;r,o)$state$N>$(;ki)$ccs$N>$s:(;r,o)$state$*$(;InKi(s))$ccs_data$$$ $
are%delivered% before%% handshake% comple4on%
parameters%% can%be%read%
imply%precise% matching%% conversa4ons%
Two proposed extensions trading speed for security:
– a client contacts a secure server; the server policy demands AES – an active adversary suggests using RC4 instead! (accepted by the client, but not the server) – the client starts sending secrets shared with the server – the adversary logs all traffic, decrypts in a few years’ time
ClientHello'''''''''''99999999>' ''''''''''''''''''''''''''''''''''''ServerHello' ''''''''''''''''''''''''''''''''''''Certificate*' ''''''''''''''''''''''''''''''''''''ServerKeyExchange*' ''''''''''''''''''''''''''''''''''''CertificateRequest*' ''''''''''''''''''''''<99999999'''''ServerHelloDone' Certificate*' ClientKeyExchange' CertificateVerify*' [ChangeCipherSpec]' Finished''''''''''''''99999999>' ''''''''''''''''''''''''''''''''''''[ChangeCipherSpec]' ''''''''''''''''''''''<99999999'''''Finished' Application'Data''''''<9999999>'''''Application'Data' ClientHello' ServerHello$ Certificate*$ ServerKeyExchange*$ CertificateRequest*$ ServerHelloDone$ Certificate*' ClientKeyExchange' CertificateVerify*' [ChangeCipherSpec]' Finished' Application$Data''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''99999999> ''''[ChangeCipherSpec]' ''''''''''''''''''''''<99999999'''''Finished' Application'Data''''''<9999999>'''''Application'Data'
– We run on the caller’s thread,! letting the application do the scheduling & multiplexing – We give more control to the application code,! and reflect more information from the underlying TLS state! (lengths, fragmentation, authorization queries)
type$cn$//'for'each'local'instance'of'the'protocol'
$//'creating'new'client'and'server'instances' val$connect:$TcpStream$N>$params$N>$(;Client)$nullCn$Result$ val$accept:$$TcpStream$N>$params$N>$(;Server)$nullCn$Result$
$//'triggering'new'handshakes,'and'closing'connections' val$rehandshake:$c:cn{Role(c)=Client}$N>$cn$Result$ val$request:$$$$$c:cn{Role(c)=Server}$N>$cn$Result$ val$shutdown:$$$$c:cn$N>$TcpStream$Result$
$//'writing'data''' type$(;c:cn,data:(;c)$msg_o)$ioresult_o$=$ |$WriteComplete$of$c':cn$ $ $$ |$WritePartial$$of$c':cn$*$rest:(;c')$msg_o$ |$MustRead$$$$$$of$c':cn$ val$write:$c:cn$N>$data:(;c)$msg_o$N>$(;c,data)$ioresult_o$
$//'reading'data''' type$(;c:cn)$ioresult_i$=$ |$Read$$$$$$of$c':cn$*$data:(;c)$msg_i $$ |$CertQuery$of$c':cn$ $ $$ |$Handshake$of$c':cn$ $ $$ |$Close$$$$$of$TcpStream$$$ $$ |$Warning$$$of$c':cn$*$a:alertDescription$ |$Fatal$$$$$of$a:alertDescription$$$ val$read$:$c:cn$N>$(;c)$ioresult_i$
Each%applica4on%provides% its%own%plaintext%module% for%data%streams:%%
secrecy%and%authen4city% at%safe%indexes%
Each%applica4on%creates% and%runs%session%&% connec4ons%in%parallel%%%
ciphersuites%and%% cer4ficates%
detailed%informa4on%
TLS&implementa?on% %
TLS.fs7&
Bytes,&Network& lib.fs% Cryptographic&Provider%
cryptographic&assump?ons&
Main result:! concr concrete TLS and ete TLS and ! ideal TLS ar ideal TLS are e indistinguishable indistinguishable Our typed ideal API! for TLS thus yields application security! by typing
TLS&implementa?on% %
TLS.fs7&
Bytes,&Network& lib.fs% any$typed$ F#$program$
Main result:! concr concrete TLS and ete TLS and ! ideal TLS ar ideal TLS are e indistinguishable indistinguishable Our typed ideal API! for TLS thus yields application security! by typing
applica?on& data&streams% TLS&applica?on& verified&by&typing% Cryptographic&Provider%
cryptographic&assump?ons&
DH% CRE% PRF% RSA% Sig% StAE% AEAD% TLS% Untyped%Adversary% Handshake% Untyped%API% Nonce% Applica4on% Untyped%Adversary% Datastream%
6% 5% 7% 1% 2% 3% 4%
StAEPlain%
Ideal/Concrete& stream.fs%
indis4nguishability% for%all%PPT%adversaries%
plain&typed&interface% (aTacker%%model)%
TLS&implementa?on% %
TLS.fs7&
any$typed$ F#$program$ TLS&proxy&with&bytesBonly&API& % Bytes,&Network& lib.fs% any$typed$ F#$program$
TLS_Adv.fs7&
Cryptographic&Provider%
cryptographic&assump?ons&
RPC&Payload& plain.fs%
ac4ve% adversaries%
TLS&implementa?on% %
TLS.fs7&
any$typed$ F#$program$ RPC& rpc.fs% Bytes,&Network& lib.fs% RpcAdv.fs%
applica4on%code%
any$typed$ F#$program$ any$typed$ F#$program$ Cryptographic&Provider%
cryptographic&assump?ons&
We run clients against an OpenSSL 1.0.1e server for various ciphersuites
automated typechecking typechecking: F7 and Z3
– Now: mechanized type theory – Next: certified typechecker (F*, POPL’12) and SMT solver
cryptographic assumptions, with handwritten proofs
– Next: better concrete reductions, with tighter bounds – Next: mechanized proofs a la Certicrypt & Easycrypt
the F# compiler and runtime: Windows and .NET
core cryptographic pr e cryptographic providers
– Next: correctness proofs for selected algorithms (elliptic curves)
TLS Kerberos WS-Security IPsec SSH Protocol Standards Protocol Implementations and Applications C/C++ Java ML C# F# Ruby Symbolic Analyses ProVerif (‘01) Casper Cryptyc, F7 AVISPA Applied-Pi Computational Analyses CryptoVerif (‘06) Hand Proofs NRL Athena Scyther
TLS Kerberos WS-Security IPsec SSH Protocol Standards Protocol Implementations and Applications C/C++ Java ML C# F# Ruby Symbolic Analyses ProVerif (‘01) Casper Cryptyc, F7 AVISPA Applied-Pi Computational Analyses CryptoVerif (‘06) Hand Proofs
FS2PV ¡(‘06) ¡ FS2CV (new)
NRL Athena Scyther
Protocol Code Applications Crypto, Net Concrete Libraries Interoperability Testing Compile
Network
Other Implementations
Run
Protocol Code Applications Crypto, Net Concrete Libraries Crypto, Net Symbolic Libraries Interoperability Testing Compile
Network
Compile
Other Implementations
Symbolic Debugging Run Run
No Attack
Verify
Diverges Attack
Symbolic Verification Security Goals
Computational Crypto Model Protocol Code Applications Crypto, Net Concrete Libraries Crypto, Net Symbolic Libraries Interoperability Testing Compile
Network
Compile
Other Implementations
Symbolic Debugging Run Run
No Attack
Verify
Diverges Attack
Symbolic Verification Security Goals
Proof
Verify
No Proof
Computational Verification
Source language of the ProVerif theorem prover 46
47
This is the core of model extraction, but additionally we perform transformations to speed up verification.
48
Our tool specifically targets symbolic verification,
with many optimization to help ProVerif converge
Complete inlining (anticipating resolution)
+ Dead Code Elimination
We select a translation for each function
Pure non-recursive functions are compiled to
term reductions (as supported by ProVerif)
Pure recursive functions are compiled to
predicate declarations (logic programming)
Functions with side-effects are compiled to Pi Processes
The generated reduction, predicate, or process is declared
public or private depending on whether it is in the interface
49
50
Crypto Model Secrets and Channels Pi Calculus Process for A Pi Calculus Process for B Full Protocol
ProVerif’s applied pi-calculus syntax
51
52
Message Authentication Password Secrecy
If a property is false, ProVerif exhibits the counter-
example as an attack
E.g. Suppose A does not include text in the HMACSHA1
53
Attack Trace
We cannot write higher-order functions
Upcoming version will allow higher-order functions as long
as they do not appear in interfaces
We cannot use some builtin types such as refs, arrays
We use channels instead to store/retrieve data Upcoming version will allow limited references
To use additional libraries, such as System.SQL or List,
the user must code up symbolic implementations
We provide implementations for Crypto, Net, Prins, XML
We avoid recursive and stateful functions
Recursive functions often lead to non-terminating analyses Stateful functions often take a lot of memory to verify
54
– Widely-deployed industrial protocol – Well-understood, with detailed specs – Good benchmark for analysis techniques
– 1994 – Netscape’s Secure Sockets Layer (SSL) – 1994 – SSL2 (known attacks) – 1995 – SSL3 (fixed them) – 1999 – IETF’s ¡TLS1.0 (RFC2246, ¡≈SSL3) – 2006 – TLS1.1 (RFC4346) – 2008 – TLS1.2 (RFC5246)
– Itself a layered protocol: Handshake over Record
– provides a private and reliable connection
– authenticates one or both parties, negotiates security parameters – establishes secret connection keys for the Record protocol
– abbreviated version of Handshake: generates connection keys from previous handshake
reliable transport protocol (e.g. TCP) Record Handshake Application Alert
Change Cipher Spec
We implement a subset of TLS as a modular library (9700 LOC)
– Supports SSL3.0, TLS1.0, TLS1.1 (with session resumption) – Supports any ciphersuite using DES, AES, RC4, SHA1, MD5 – Server-only authentication, RSA mode only – No compression, fragmentation, or alerts
We test it using three basic sample applications:
– An HTTPS client that can retrieve pages from any web server (tested against IIS, Apache, and our F# server) – An HTTPS server that can serve pages to any web client (tested against IE, Firefox, Opera, and our F# client) – A client-server application that performs password-based authentication over TLS
HTTPS_Client.fs (application code)
let client_request url = let netconn = Net.connect url in
let connid, sessionid = Handshake.connect netconn url in run Handshake protocol let request = httpRequest url in build HTTP request Record.send connid request; send HTTP request over Record protocol let response = Record.recv connid in receive HTTP response over Record protocol response return the HTTP response
Record.fsi (interface)
type ConnectionId = bytes val send: ConnectionId -> bytes -> unit val recv: ConnectionId -> bytes (* private *) type Connection = { type ConnectionState = { net_conn: Net.conn; cipher_state: CipherState; crt_version: ProtocolVersion; mackey: bytes; write: ConnectionState; seq_num: bytes; read: ConnectionState } sparams: SecurityParameters; } val getConnection: ConnectionId -> Connection
Handhake.fsi (interface)
type SessionId = bytes val connect: Net.conn -> ServerName -> ConnectionId * SessionId val accept: Net.conn -> CertName -> ConnectionId * SessionId val resume: Net.conn -> SessionId -> ConnectionId * SessionId val close: ConnectionId -> unit (*private *) type Session = { sid: SessionId; ms: bytes; serverCertificate: bytes; } val getSession: SessionId -> Session
Record.fs (implementation excerpt)
let recv (connid:ConnectionId) =
letconn = getConnection connid in let conn, input = recvRecordconn in let conn, msg = verifyPayload conn CT_application_datainput in let id,entity = connid in log tr (Recv (id,entity,msg)); storeConnection connid conn; msg
let verifyPayload (conn:Connection) (ct:ContentType) (input:bytes) =
let (bct, bver, blen, ciphertext) = parseRecord input in let rct, rver, rlen = getAbstractValues bct bver blen in let ver = conn.crt_versionin if rver = ver then let connst = conn.read in let connst, plaintext = decrypt ver connst ciphertext in let payload, recvmac = parsePlaintext ver connst plaintext in let len = bytes_of_int 2 (length payload) in let bseq = bytes_of_seq connst.seq_num in let maced = append5 bseq bct bver len payload in let conn = updateConnection_readconn connst in checkContentType ct rct payload; ifhmacVerify connst maced recvmac = true then (conn,payload) else failwith"bad record mac" else failwith"bad version
Retrieve connection Decryption
supports multiple ciphersuites
Message parsing Security event: message accepted! MAC verification
data data fragment mac header encrypted fragment and mac data fragment
Record protocol (informal narration)
A B : {m,[m]ak}ek
– Implementations are free to choose the interface
– Multiple versions and ciphersuites – Poor testing tools – But results in good insights (e.g. understanding rollback issues) and ensures a very precise model
– Crypto: cryptographic operations are algebraic constructors/destructors – Net: networking functions defined using Pi calculus channels – Prins: database of (server) principals, each with a certificate and private key
– Crypto, Net, Prins: can perform crypto, control the network, compromise principals – Handshake: can open (and resume) connections with any clients and servers – Record: can send/recv application messages on any open connections
– from F# code for TLS, for symbolic libraries + F# interface for attacker + security goals
against any attacker with access to this interface
– security guarantees for any number of clients and servers running any number of Handshake, Resumption, and Record instances
type bytes = | Name of Pi.name | Hash of bytes | SymEncrypt of bytes * bytes | ¡…
Record Message Authentication
If the client receives message p over connection c, then either the server has sent p over c,
(and similarly in the other direction)
Record Payload Secrecy
If the attacker obtains a fresh message p sent over connection c then either the client or the server has been compromised.
Handshake Authentication
At the end of the handshake, the client and the server agree on all negotiated parameters and keys, provided that the client and the server are not compromised.
Key Secrecy
If the attacker obtains a connection key, then either the client or the server has been compromised.
and similarly when using Resumption
in particular both sets of negotiated parameters are authenticated and correlated
Crypto.fsi (interface) type bytes (* byte arrays *) type symkey (* symmetric keys *) … val mkNonce: unit -> bytes (* generate nonce *) val mkKey: nonce -> symkey (* make key *) val sha1: bytes -> byte val aes_encrypt: symkey -> bytes -> bytes val aes_decrypt: symkey -> bytes -> bytes …
Crypto.fs (symbolic implementation) type bytes = | Name of Pi.name | Hash of bytes | SymEncrypt of bytes * bytes | ¡… type symkey = Sym of bytes let mkNonce () ¡= ¡Pi.name ¡“nonce” let mkKey () = Sym(mkNonce()) let sha1 b = Hash(b) let aes_encrypt (Sym(k)) x = SymEncrypt(k,x) let aes_decrypt (Sym(k)) (SymEncrypt(k’,x)) ¡= ¡ if k ¡= ¡k’ ¡then x else raise Fail
– But after a lot of hand-tuning on the source code (otherwise ProVerif runs out of memory or does not finish) – Final ProVerif script of Handshake+Resumption+Record still large (2100LOC) – Proving Record/Handshake separately is much easier (but less precise)
Part of protocol verified # of queries PV running time Memory used Handshake (auth. queries) 2 16sec 60MB Handshake (secr. queries) 2 10sec 80MB Handshake + Resumption (resumption auth. queries) 2 4min 460MB Handshake + Resumption + Record (record auth. queries) 2 6min 700MB Handshake + Resumption + Record 8 2hours 1.7GB
certificates; this leads to a counter-example of Handshake authentication
– Common mistake: Ruby/Cisco/OpenSSL
– The version rollback protection in ClientKeyExchange is absent during Resumption – Experimentally, we could not downgrade to SSL 2.0 with e.g. IIS, Apache.
Client Server ClientHello ServerHello Certificate ServerHelloDone ClientKeyExchange [ChangeCipherSpec] Finished [ChangeCipherSpec] Finished
ClientHello : (ver_max, cipher_suites, ¡…) ClientKeyExchange : {pms}pk(server) with pms = ver_max || random
instead of terms, PPT adversaries), but harder to work with
– CV script = PPT processes + crypto assumptions + security goals – Automatic computational proofs using the game-hopping technique
– Networking and sampling functions translate to CryptoVerif primitives – Public functions translate to polynomially replicated processes
– Must define types and assumptions for all cryptographic primitives used in the protocol (HMAC, ¡AES, ¡RSA,…) ¡using ¡probabilistic ¡equivalences ¡encoding ¡indistinguishability – Crypto assumptions change rarely
to computationally verify these goals against PPT adversaries
– Assume a pre-established connection – Any (polynomial) number of clients and servers share the connection
– UF-CMA for HMAC: Correlates valid macs with their possible origin(s) – SPRP (super pseudo-random permutation) for block ciphers (AES/DES):
Replaces encryptions and decryptions by random bitstrings
Message Authentication
In any polynomial run of the protocol, with overwhelming probability, if the client receives message p, then the server has sent p.
Payload Secrecy
In any polynomial run of the protocol, the sequence of sent payload values is indistinguishable from a sequence of independent random values.
Crypto.fsi (interface)
type bytes (* byte arrays *) type symkey (* symmetric keys *) type keyseed = bytes (* seed for symkey *) … val mkNonce: unit -> bytes (* fresh nonce *) val mkKey: bytes -> symkey (* make key *) … val aes_encrypt: symkey -> bytes -> bytes val aes_decrypt: symkey -> bytes -> bytes …
Crypto.cv (CryptoVerif script)
(* type bytes = blocksize *) type symkey [fixed]. type keyseed [large,fixed]. fun aes_encrypt(symkey, blocksize): blocksize. fun mkKey(keyseed):key. fun aes_decrypt(key, blocksize): blocksize. forall m:blocksize, r:keyseed; aes_decrypt(mkKey(r), aes_encrypt(mkKey(r), m)) = m. (* SPRP assumption for AES Encryption *) equiv !N new r: keyseed; ((x:blocksize) Nsymenc -> aes_encrypt(mkKey(r),x), (m:blocksize) Nsymdec -> aes_decrypt(mkKey(r),m)) <= (N * Psymenc(time, Nsymenc, Nsymdec)) => …
equiv !N new r: keyseed; ((x:blocksize) N1 -> symenc(x, kgen(r)), (m:blocksize) N2 -> symdec(m, kgen(r))) <= (N * Psymenc(time, N1, N2)) => !N new r: keyseed; ((x:blocksize) N1 -> find j<=N1 suchthat defined(x[j],r2[j]) && otheruses(r2[j]) && x = x[j] then r2[j]
else new r2: blocksize; r2, (m:blocksize) N2 -> find j<=N1 suchthat defined(x[j],r2[j]) && otheruses(r2[j]) && m = r2[j] then x[j]
else new r4: blocksize; r4).
– We assume pre-established parameters and a public/private keypair – The client sends ClientKeyExchange, generates connection keys, and sends Finished
– IND-CCA2 for asymmetric encryption: indistinguishability against chosen- ciphertext attacks – random oracle for PRF (key derivation): turns derived keys into random bitstrings
Secrecy of PMS Random (recall that pms = ver_max || random)
In any polynomial run of the protocol, the sequence of random values is indistinguishable from a sequence of independent fresh values.
– we assume pre-established parameters and a public/private keypair – parties generate connection keys, and send and receive Finished messages – the messages are sent over the Record layer in NULL mode (enc=mac=identity)
– random oracle for PRF when used for key derivation – UF-CMA for PRF when used to build the Finished messages
Agreement on PMS
In any polynomial run of the protocol, with overwhelming probability, if the client receives the Finished message, then the server has sent it, and they agree on the value of pms.
– Computationally, mac functions give no secrecy guarantees – For the Handshake protocol, symbolically, pms is (syntactically) secret, but computationally, only random is secret (where pms = ver_max || random) – Encryption keys are secret computationally only before they are used – let Concat(x,y) = m prevents a type-flaw symbolically, but not computationally
but not (yet) computationally
– mac-then-encrypt is difficult in CryptoVerif – CryptoVerif interactive mode hard to use with generated code
Secure Is SSL?)“, ¡computational ¡analysis, ¡record ¡protocol
checking, handshake protocol
manual symbolic analysis, handshake protocol
handshake and record protocols
Copper) symbolic analysis of OpenSSL code
a variant of the TLS handshake
Verifying&miTLS&
FS2PV/% ProVerif% FS2CV/% CryptoVerif% RCF/F7%
– Can prove authentication queries and syntactic secrecy – New work on strong secrecy, equivalence-based reasoning! See: http://proverif.inria.fr – Other new tools can better handle stateful protocols, ! Diffie-Hellman key exchanges! See e.g.: Tamarin, StatVerif
– Can prove authentication and computational indistinguishability – New improvements in type inference, stateful programs! See: http://research.microsoft.com/fstar – Other similar tools can verify Java, C programs! See: CVJ, Csec
– Tools can be proof assistants – Results relate well to cryptographic literature – Many new tools: EasyCrypt, CertiCrypt, RF*
– Prove weaker properties – Against weaker adversaries – Useful for finding attacks attacks – Results relate to programming language semantics – Stable, well-documented tools: ProVerif, Tamarin, F7, F*
– Both symbolic and computational
– Encrypt-Then-MAC (IPsec-style) – MAC-And-Encrypt (SSH style)
– Use typing with RCF, both symbolic and computational
module'MAC$
$
type'text'='bytes' type'mac'='bytes' type'key $ $$
'
val'GEN''':'unit'9>'key'' val'LEAK'':'key$9>'bytes' val'COERCE:'bytes9>'key' ' val'MAC''':'key'9>'text'9>'mac' val'VERIFY:'key'9>'text'9>'mac$9>'bool'
module'ENC$ type'plain' type'cipher'='bytes' type'key$
$ '
val'GEN''':'unit'9>'key'' val'LEAK'':'key$9>'bytes' val'COERCE:'bytes9>'key' ' val'ENC''':'key'9>'plain'9>'cipher' val'DEC$$$:'key'9>'cipher'9>'plain$
– Encryption turns secret data into public data – Data returned by decryption is guaranteed to be the same as the data that was encrypted
– Enc-Then-Mac (IPsec).! Encryption returns: MAC k (ENC k’ t) – Mac-And-Enc (SSH)! Encryption returns: (MAC k t, ENC k’ t)
– Similar to ENC, but with stronger guarantees
– Can you weaken the crypto assumptions? – Does your proof give computational security?