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 Outline of Lectures Lecture 1 (Jan 22, Today) Intro to Verified Protocol Implementations
(Slides from A.D. Gordon and C. Fournet)
Spring, 2014
– Intro to Verified Protocol Implementations – RCF type system
– F7 typechecker for RCF – Symbolic verification with F7
– Computational RCF – Using F7 for computational verification
– Advanced verification techniques
security functionality by using cryptographic schemes
– Transport Layer Security (TLS)
– SOAP Message Security (WS-Security)
– Part of our trusted computing base – Can we guarantee that they work correctly?
violate their abstract security goals
– Protocols too large to analyze by hand
– Models miss many low-level implementation details
– HTTPs, 802.1x (EAP), FTPS, VPN, SMTP , XMPP , ….
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)
– OpenSSL, NSS, SChannel, GnuTLS, JSSE, PolarSSL, Bouncy Castle
– Few analyses of TLS implementations, but many attacks
1996 ¡-‑ ¡Schneier ¡& ¡Wagner ¡“Analysis ¡of ¡the ¡SSL3.0 ¡protocol”, ¡informal, ¡full ¡protocol ¡ 1998 ¡-‑ ¡Mitchell, ¡Schma;kov, ¡Stern ¡“Finite ¡state ¡analysis ¡of ¡SSL ¡3.0”, ¡model-‑checking, ¡handshak 1999 ¡-‑ ¡Paulson ¡“Induc=ve ¡Analysis ¡of ¡the ¡Internet ¡protocol ¡TLS”, ¡theorem-‑proving, ¡handshake ¡p 2001 ¡-‑ ¡Krawczyk ¡“The ¡Order ¡of ¡Encryp=on ¡and ¡Authen=ca=on ¡for ¡Protec=ng ¡Communica=ons ¡( 2001 ¡-‑ ¡Yasinac, ¡Childs ¡"Analyzing ¡Internet ¡Security ¡Protocols", ¡automa;c ¡symbolic ¡analysis, ¡han 2002 ¡-‑ ¡Jonsson, ¡Kaliski, ¡“On ¡the ¡Security ¡of ¡RSA ¡Encryp=on ¡in ¡TLS”, ¡computa;onal ¡analysis, ¡han 2004 ¡-‑ ¡Diaz, ¡Curtero, ¡Valero, ¡Pelayo, ¡"Automa=c ¡Verifica=on ¡of ¡the ¡TLS ¡Handshake ¡Protocol", ¡m 2005 ¡-‑ ¡Ogata, ¡Futatsugi ¡"Equa=onal ¡Approach ¡to ¡Formal ¡Analysis ¡of ¡TLS“, ¡symbolic ¡analysis, ¡han 2005 ¡-‑ ¡He, ¡Sundararajan, ¡DaVa, ¡Derek, ¡Mitchell, ¡"A ¡modular ¡correctness ¡proof ¡of ¡IEEE802.11i ¡a 2008 ¡-‑ ¡Kamil, ¡Lowe ¡“Analysing ¡TLS ¡in ¡the ¡Strand ¡Spaces ¡Model”, ¡manual ¡symbolic ¡analysis, ¡full ¡ 2008 ¡-‑ ¡Chaki, ¡DaVa ¡“Automated ¡verifica=on ¡of ¡security ¡protocol ¡implementa=on”, ¡automa;c ¡(w 2008 ¡-‑ ¡Morrisay, ¡Smart, ¡Warinschi, ¡“A ¡modular ¡security ¡analysis ¡of ¡SSL/TLS”, ¡manual ¡comp. ¡anal (…) ¡
reliable ¡transport ¡protocol ¡(e.g. ¡TCP) ¡ Record ¡ Handshake ¡ Applica;on ¡ Alert ¡
Change ¡ Cipher ¡ Spec ¡
– payload + additional data is MACed – payload + MAC is padded – the result is encrypted
– yet attacks are found on implementations – models often do not account for error handling
– None account for rekeying, renegotiation, multiple versions, ciphersuites
– multiple ciphersuites: block ciphers, stream ciphers, MAC only – multiple protocol versions: SSL 3.0 – TLS 1.2
– interleaving: Handshake, Alert, and Application messages – session evolution: initial, resumption, rekeying, renegotiation
– what to reveal to the application, what to hide? – socket state: when can data be safely sent or received – error handling: notification of failures and warnings
OpenSSL OpenSSL 0.9.8 Server Certificate V 0.9.8 Server Certificate Verification erification
in one case, a signature verification failure was incorrectly assumed to be a success
if (EVP_VerifyFinal(&md_ctx,p,(int)n,pkey)){ /* good signature */ …}
the adversary could bypass certificate checking
– A standard programming error that becomes a security flaw – It only appears in certain ciphersuites and certain control flows
OpenSSL OpenSSL 1.0.0 Alert Fragment Handling 1.0.0 Alert Fragment Handling
– t = 1 for warning, t = 2 for fatal error
(during the initial handshake)
– The attack only appears when we consider Alert fragmentation composed with the full TLS state machine
Sun Java Sun Java SSLSocket SSLSocket API Renegotiation Hiding API Renegotiation Hiding
public abstract class SSLSocket extends Socket
performs a handshake if necessary, silently modifying the underlying session, without notifying the application.
– What if the underlying session changed? – What if we are not using the safe renegotiation extension?
running protocol code, under precise cryptographic assumptions, and against realistic attackers
precise enough to handle implementation details?
– Maybe we can generate code from models? See Spi2Java (ProVerif to Java), CV2ML (CryptoVerif to ML)
– Directly verify running code, and all its details We will explor e will explore this appr e this approach in these lectur
es
TLS ¡ Kerberos ¡ WS-‑Security ¡ IPsec ¡ SSH ¡ Protocol ¡Standards ¡ Protocol ¡Implementa;ons ¡and ¡Applica;ons ¡
Java ¡ ML, ¡F# ¡ C# ¡ Ruby ¡ ProVerif ¡(’01) ¡ Casper ¡ Cryptyc ¡ ¡ AVISPA ¡ Computa;onal ¡ Analyses ¡ CryptoVerif ¡(‘06) ¡ EasyCrypt ¡(‘11) ¡ F7 ¡(’11) ¡ ¡RF*(’13) ¡ Hand ¡Proofs ¡ ¡ ¡ ¡ ¡NRL ¡ Athena ¡ Scyther ¡ Securify ¡ F7 ¡(’08) ¡ ¡ ¡ ¡F* ¡(‘11) ¡ General ¡Verifica;on ¡ SMT ¡Solvers ¡ Theorem ¡ Provers ¡ Model ¡ Checkers ¡ Symbolic ¡ ¡ ¡Analyses ¡
Applica;ons ¡ ¡
¡ ¡Crypto, ¡Net ¡
¡ ¡Concrete ¡Libraries ¡
¡ ¡Crypto, ¡Net ¡
¡ ¡ ¡Abstract ¡Libraries ¡ Interoperability ¡TesIng ¡ ¡ ¡Compile ¡
Network ¡
¡ ¡Compile ¡
Other ¡ ImplementaIons ¡ ¡
Symbolic ¡ ¡ Debugging ¡ Run ¡ Run ¡
No ¡AOack ¡
Verify ¡
Diverges ¡ AOack ¡
Symbolic/ ¡ ComputaIonal ¡ VerificaIon ¡
Proof ¡
Verify ¡
No ¡Proof ¡
Typechecking ¡ (Symbolic/ ¡ ComputaIonal) ¡ Protocol ¡Code ¡ Security ¡ Goals ¡ Typed ¡Library ¡ Interfaces ¡
One ¡Source ¡ Many ¡Tasks ¡
– Modular programming based on strong interfaces – Algebraic data types with pattern matching useful for symbolic cryptography, message formats
call-‑by-‑value ¡ lambda-‑calculus ¡
communica;on ¡
logical ¡assumes ¡ ¡ and ¡asserts ¡
We identify a set of platform libraries used in protocol code
Data: string and byte array conversion functions
Net: communication over TCP
Crypto: cryptographic primitives
Principals: certificate and password store
Xml: manipulating XML documents
Db: managing private databases Each library is implemented as a wrapper ar Each library is implemented as a wrapper around the
corr corresponding .NET class esponding .NET class (System.Net.Sockets.T
System.Net.Sockets.TcpClient cpClient, System.Security System.Security.Cryptography .Cryptography.HMACSHA1 .HMACSHA1)
– Translate F# code to ProVerif Needs symbolic abstraction of libraries (tool: fs2pv) – Translate F# code to CryptoVerif Needs probabilistic semantics of ML, and computational abstraction of libraries (tool: fs2cv)
– Define secure type system for F# Needs semantics, abstractions, plus manual annotations, constraint solver (tool: F7)
and Crypto in F
an algebraic datatype
name generation
(private) constructors
Given a protocol implementation P .ml with public interface P .mli Suppose we have symbolic models for our libraries LIBS=Data.ml, Crypto.ml, Net.ml, Principals.ml
Data.mli, Crypto.mli, Net.mli, Principals.mli
Our goal is that the program LIBS P .ml is robustly safe. That is, for all opponents O.ml that respect the public interfaces of LIBS and P .mli , LIBS P .ml O.ml is safe
– Follows Milner’s “Functions as processes” – Includes optimizations for eliminating irrelevant code
To use ProVerif for security verification:
1. Write symbolic models of libraries and their public interfaces
Crypto.ml, Crypto.mli, Net.ml, Net.mli …
2. Annotate the program with security goals
P .ml
3. Define the public (attacker) F# interface
P-pub.mli
4. Translate all modules and their interfaces to applied pi fs2pv Crypto.ml Crypto.mli … P
.ml P-pub.mli > Script.pv
ProVerif may verify the script, or produce a counterexample,
Security Theor Security Theorem em: If the script Script.pv is verified by ProVerif then the program
Crypto.ml Crypto.mli … P .ml P .ml is robustly safe.
(by soundness of the translation and the correctness of ProVerif)
An enhanced type system that tracks logical invariants:
x:ty{ϕ}
– x:int { x > 0 } – pwd:string {Password(“Alice”,pwd)}
x:ty ->
ty’
– lookup: u:string {User(u)} -> p:string {Password(u,p)}
– Pre-condition: User(u), post-condition: Password(u,p)
ty <: <: ty ty’
– x:ty{ϕ} <: ty
no assert assert will fail at run-time
– That is, each assert assert is entailed by its preceding assumes – It relies on an external SMT solver for logical proof obligations
Crypto.ml7, Net.ml7, …
P .ml7, P .ml
P-pub.mli
both the public interface and the program interface
Crypto.ml7, Net.ml7, … |- P .ml : P .ml7 <: P-pub.mli
Security Theor Security Theorem em (by type safety): If the libraries Lib.ml satisfy Crypto.ml7, Net.ml7, … then the program Lib.ml P
.ml is robustly safe.
a usage precondition
MACSays(k,b) says that mackey k may be used to MAC b
MACSays for its own keys
not be encrypted with compromised keys
authenticate data
– Secure Multi-Party Sessions (2k lines, 2m) – TLS Transport Protocol (computational) (>5k lines, 13m)
Fournet, R. Corin, and E. Zalinescu. ACM Transactions on Information and System Security, 15(1), 2012. (Also CCS 2008)
Bhargavan, C. Fournet, A.D. Gordon, and S. Maffeis. ACM Transactions on Programming Languages and Systems, 33(2), 2011.
Bhargavan, C. Fournet, A.D. Gordon. ACM Symposium on Principles
Bhargavan, C. Fournet, A.D. Gordon, and S. Tse. ACM Transactions
management protocol, K. Bhargavan, C. Fournet, A.D. Gordon, and
Communications Security, 123–135, 2008.
– Generate code from models (e.g. CV2ML) – Extract models from code (e.g. fs2pv) – Directly analyze protocol code (e.g. F7)
Slides adapted from A. D. Gordon’s see also the RCF tutorial
Lecture notes on the course website:
exercises
Implementation, a tutorial on F7 Research papers: http://research.microsoft.com/f7
constructions in language-based security
– FPC FPC (Plotkin 1985, Gunter 1992) – core of ML and Haskell – Concurrency in style of the pi-calculus pi-calculus (Milner, Parrow, Walker 1989) but for a lambda-calculus (like 80s languages PFL, Poly/ML, CML) – Symbolic crypto is derivable e.g. by coding up seals seals (Morris 1973, Sumii and Pierce 2002), not primitive as in the applied pi calculus – Security specs via assume/assert assume/assert (Floyd, Hoare, Dijkstra 1970s), generalizing eg correspondences (Woo and Lam 1992) – To check assertions statically, rely on dependent functions and pairs with subtyping (Cardelli 1988) and refinement types efinement types (Pfenning 1992, ...) aka pr predicate edicate subtyping subtyping (as in PVS, and more recently Russell) – Public/tainted kinds Public/tainted kinds to track data that may flow to or from the
RCF Part 1:
Reduc;ons ¡step ¡are ¡ “up ¡to ¡structural ¡rearrangements” ¡ Communica;on ¡ ¡step ¡
Reduc;ons ¡step ¡are ¡ “up ¡to ¡structural ¡rearrangements” ¡
log
assume C, add C to the log, and return ().
assert C, return ().
– If C logically follows from the logged formulas, we say the assertion succeeds succeeds; otherwise, we say the assertion fails fails. – The log is only for specification purposes; it does not affect execution
conventional assertions (like assert assert i>0 in eg JML, Spec#)
– Such predicates usefully represent security-related concepts like roles, permissions, events, compromises
run;me ¡configura;ons ¡are ¡expressions ¡of ¡the ¡form ¡ ¡ ¡
¡ ¡ ¡ ¡
for ¡all ¡runs ¡of ¡A, ¡all ¡asserIons ¡succeed ¡
ac;ve ¡ assump;ons ¡ running ¡ threads ¡ pending ¡ messages ¡
PROGRAMMING EXAMPLE: PROGRAMMING EXAMPLE:
call a trusted library
expresses security policy with assumes and asserts
causes an assertion failure
statically prevent any assertion failures by typing
stated ¡in ¡terms ¡of ¡ dynamic ¡events ¡such ¡ as ¡role ¡ac;va;ons ¡or ¡ data ¡checks ¡
by ¡adding ¡formulas ¡to ¡ the ¡log ¡with ¡assume ¡
all preconditions (and hence all asserts) hold at runtime
We typecheck programs against interfaces
& calls Z3, an SMT solver,
crypto libraries and verify protocol implementations
RPC.fs7 ¡ RPC.fs ¡ RPC.fsi ¡ Type ¡ (F7) ¡ Prove ¡ (Z3) ¡ Compile ¡ (F#) ¡
Erase ¡ ¡ types ¡
AES.fs7 ¡ Lib.fs7 ¡ RPC.v ¡ Prove ¡ (coq) ¡
RCF Part 2:
efinement types {x : T | C} whose values are those of T that satisfy C
meaning that C follows from the refinement types in E
versions of the function and pair types, and (2) subtyping
– functional programming a la ML – concurrency in the style of process calculus, and – refinement types allowing correctness properties to be stated in the style of dependent type theory.
http://research.microsoft.com/F7 http://research.microsoft.com/Fstar
Aura, Fable, F7, F5, Fine, F*…
sample protocol
Client ¡ ¡ Service ¡ request ¡ HMAC(key,request) ¡ response ¡ HMAC(key,request,response) ¡
Connecting to localhost:8080 Sending {BgAyICsgMj9mhJa7iDAcW3Rrk...} (28 bytes) Listening at ::1:8080 Received Request 2 + 2? Sending {AQA0NccjcuL/WOaYS0GGtOtPm...} (23 bytes) Received Response 4
SYMBOLIC THEORY
“all asserted formulas follow from previously-assumed formulas”
– Either by deducibility deducibility, enforced by typing (the typing environment contains less assumptions than those that will be present at run-time) – Or in interpr interpretations etations satisfying all assumptions
– Inductive definitions (Horn clauses) – Logical theorems additional properties that hold in our model – Operational theorems additional properties that hold at run-time
east models for inductive definitions (not all models)
we can assume assume them so that they can be used for typechecking
Can we do it once for all?
– An F7 interface, including inductive definitions & theorems – A well-typed implementation Theor Theorem: em: refined modules with disjoint supports can be composed into semantically safe protocols
Pub)
it suffices to show that the protocol itself is a refined module, assuming all the definitions and theorems of the libraries.
APPLICATIONS
Crypto: a library for basic cryptographic operations
– Public-key encryption and signing (RSA-based) – Symmetric key encryption and MACs – Key derivation from seed + nonce, from passwords – Certificates (x.509)
Principals: a library for managing keys, associating keys with principals, and modelling compromise
– Between Crypto and protocol code, defining user predicates on behalf of protocol code – Higher-level interface to cryptography – Principals are units of compromise (not individual keys)
XML: a library for XML formats and WS* security