Formal Security Analysis of Cryptographic Protocol Code - - PowerPoint PPT Presentation
Formal Security Analysis of Cryptographic Protocol Code - - PowerPoint PPT Presentation
Formal Security Analysis of Cryptographic Protocol Code Karthikeyan Bhargavan INRIA Karthikeyan.Bhargavan@inria.fr IIT Delhi, Fall 2010 Lecture 3: Coding
Lecture ¡3: ¡ Coding ¡Symbolic ¡Abstrac3ons ¡in ¡F# ¡
IntroducCon ¡
A ¡Crypto ¡Protocol ¡ImplementaCon ¡
Protocol ¡ Code ¡ Key ¡ Management ¡ Cryptographic ¡ ¡ Library ¡ Network ¡ ¡ Stack ¡
Database ¡of ¡secrets ¡ (keys, ¡passwords) ¡ Crypto ¡algorithms ¡ Network ¡Protocols ¡
ApplicaCon ¡ Code ¡ Network ¡ ¡ Based ¡ Opponent ¡
Untrusted ¡Network ¡ ParGally ¡Trusted ¡
Towards ¡Symbolic ¡VerificaCon ¡
One ¡Source, ¡Many ¡Tasks ¡
ApplicaCons ¡ ¡
¡ ¡Crypto, ¡Net ¡
¡ ¡Concrete ¡Libraries ¡
¡ ¡Crypto, ¡Net ¡
¡ ¡ ¡Symbolic ¡Libraries ¡ Interoperability ¡Tes3ng ¡ ¡ ¡Compile ¡
Network ¡
¡ ¡Compile ¡
Other ¡ Implementa3ons ¡ ¡
Symbolic ¡ ¡ Debugging ¡ Run ¡ Run ¡
No ¡AAack ¡
Verify ¡
Diverges ¡ AAack ¡
Symbolic ¡ ¡ Verifica3on ¡ Protocol ¡Code ¡ Security ¡ Goals ¡
One ¡Source ¡ Many ¡Tasks ¡
Lecture ¡Outline ¡
- Library ¡modules ¡review: ¡Data, ¡Net, ¡Crypto ¡
- An ¡example ¡protocol ¡using ¡these ¡modules ¡
– AuthenCcated ¡RPC ¡ – Security ¡goals, ¡how ¡shall ¡we ¡formalize ¡them? ¡
- A ¡symbolic ¡cryptographic ¡library ¡
– New ¡implementaCons ¡for ¡Data, ¡Crypto, ¡Net ¡
- Symbolic ¡debugging ¡
– AuthenCcated ¡EncrypCon ¡example ¡
Lecture ¡3: ¡ Coding ¡Symbolic ¡Abstrac3ons ¡in ¡F# ¡
Library ¡Modules ¡
Data ¡Module: ¡Strings, ¡Bytestrings ¡
- str ¡represents ¡string ¡
- bytes ¡represents ¡byte[] ¡ ¡
Interface ¡
Net ¡Module: ¡Networking ¡
- Uses ¡Data.bytes ¡
- fork ¡creates ¡a ¡new ¡thread ¡running ¡the ¡funcCon ¡ ¡ ¡
Crypto ¡Module: ¡Cryptography ¡
AUTHENTICATED ¡RPC ¡
SAMPLE ¡PROTOCOL ¡
Client ¡ ¡ Server ¡ request ¡ HMAC(key,request) ¡ response ¡ HMAC(key,request,response) ¡
Informal ¡DescripCon ¡
Why ¡Is ¡This ¡Protocol ¡Secure? ¡
Logical ¡SpecificaCon ¡
F# ¡ImplementaCon ¡
Connecting to localhost:8080 Sending {BgAyICsgMj9mhJa7iDAcW3Rrk...} (28 bytes) Listening at ::1:8080 Received Request 2 + 2? Sending {AQA0NccjcuL/WOaYS0GGtOtPm...} (23 bytes) Received Response 4
Test ¡
Is ¡The ¡Protocol ¡Code ¡Secure? ¡
- 1. Can ¡the ¡opponent ¡cause ¡one ¡of ¡our ¡
authenCcaCon ¡goals ¡to ¡fail? ¡
- 2. What ¡if ¡the ¡opponent ¡sent ¡a ¡forged ¡message ¡to ¡
the ¡server? ¡
- 3. What ¡if ¡the ¡client ¡started ¡concurrent ¡sessions ¡
with ¡both ¡an ¡honest ¡and ¡a ¡dishonest ¡server? ¡
- 4. What ¡if ¡the ¡MAC ¡key ¡is ¡compromised? ¡
More ¡importantly, ¡what ¡is ¡the ¡formal ¡model ¡under ¡ which ¡we ¡may ¡prove ¡our ¡security ¡goals? ¡ ¡
Lecture ¡3: ¡ Coding ¡Symbolic ¡Abstrac3ons ¡in ¡F# ¡
A ¡Symbolic ¡AbstracCon ¡of ¡ Cryptography ¡
A ¡New ¡ImplementaCon ¡of ¡Data, ¡Crypto ¡
- str, ¡bytes ¡are ¡both ¡now ¡algebraic ¡datatypes ¡
- peraCons ¡on ¡bytes ¡are ¡represented ¡as ¡constructors ¡
– One-‑one ¡determinisCc ¡funcCons ¡
Recall: ¡Data ¡Interface ¡
- We ¡must ¡implement ¡all ¡these ¡funcCons ¡
Conversions ¡using ¡InverCble ¡Constructors ¡
- UTF8, ¡Base64, ¡Concat ¡modeled ¡as ¡constructors ¡ ¡
– one-‑one ¡determinisCc ¡funcCons ¡
- Inverse ¡funcCons ¡modeled ¡using ¡pacern ¡matching ¡
Random ¡Values ¡using ¡Fresh ¡Names ¡
- A ¡name ¡is ¡a ¡freshly ¡generated ¡value ¡
– The ¡name ¡datatype ¡is ¡hidden ¡from ¡the ¡interface ¡ – Hence, ¡given ¡a ¡name, ¡one ¡cannot ¡deconstruct ¡it ¡ – And ¡given ¡a ¡counter, ¡one ¡cannot ¡construct ¡a ¡name ¡
Hash/MAC ¡as ¡One-‑way ¡Constructors ¡
- Hash, ¡MAC ¡are ¡constructors ¡
– One-‑one ¡funcCons ¡[Collision ¡resistance] ¡
- The ¡implementaCon ¡of ¡type ¡bytes ¡is ¡hidden ¡
– No ¡funcCon ¡for ¡inverCng ¡Hash/MAC ¡ – Hence, ¡noboby ¡can ¡look ¡inside ¡a ¡Hash ¡or ¡a ¡MAC ¡ – [Preimage ¡resistance] ¡
- To ¡construct ¡a ¡MAC ¡one ¡must ¡use ¡mac ¡
– One ¡must ¡know ¡the ¡key ¡[Unforgeability] ¡
- AssumpGons ¡too ¡strong? ¡
– Nobody ¡can ¡read ¡the ¡contents ¡of ¡MAC ¡[Secrecy] ¡
Symbolic ¡Symmetric ¡EncrypCon ¡ ¡
- DecrypCon ¡succeeds ¡on ¡encrypted ¡values ¡
– [DeterminisGc ¡DecrypGon] ¡
- SymEncrypt ¡constructor ¡hidden ¡from ¡interface ¡
– Only ¡way ¡to ¡open ¡it ¡is ¡to ¡use ¡sym_decrypt ¡ – Hence, ¡one ¡must ¡know ¡key ¡to ¡recover ¡plaintext ¡ – [Secrecy] ¡
Public ¡and ¡Private ¡Keys ¡
- Private ¡keys ¡are ¡fresh ¡names ¡
- One ¡can ¡go ¡from ¡a ¡private ¡key ¡to ¡a ¡public ¡key ¡
– But ¡not ¡the ¡other ¡way ¡round ¡[Private ¡Key ¡Secrecy] ¡
Symbolic ¡Asymmetric ¡EncrypCon ¡
- EncrypCon ¡with ¡public ¡key ¡
– DecrypCon ¡with ¡private ¡key ¡ – AsymEncrypt ¡constructor ¡is ¡hidden ¡from ¡interface ¡ – Nobody ¡can ¡access ¡plaintext ¡without ¡calling ¡ asym_decrypt ¡with ¡private ¡key ¡[Secrecy] ¡ ¡
Symbolic ¡Signatures ¡ ¡
- Only ¡way ¡to ¡construct ¡Sign(k,b) ¡is ¡through ¡sign ¡
– One ¡must ¡know ¡k ¡[Unforgeability] ¡
- VerificaCon ¡guarantees ¡that ¡the ¡signer ¡knows ¡
the ¡private ¡key ¡[Non-‑repudiaGon] ¡
Recall: ¡Net ¡Interface ¡
Networking ¡using ¡Channels ¡
- The ¡network ¡is ¡a ¡public ¡channel ¡
- Channels ¡are ¡asynchronous, ¡unordered, ¡buffered ¡
– send ¡adds ¡a ¡message ¡to ¡the ¡buffer ¡
Networking ¡using ¡Channels ¡
- recv ¡is ¡blocking ¡
– It ¡waits ¡for ¡a ¡message ¡to ¡appear ¡on ¡the ¡network ¡ – Code ¡uses ¡monitors ¡to ¡avoid ¡race ¡condiCons ¡
Network-‑based ¡Acacker ¡
- The ¡network ¡channel ¡netChan ¡is ¡made ¡
available ¡to ¡the ¡acacker ¡
– He ¡knows ¡all ¡connecCon ¡idenCfiers ¡ – He ¡can ¡send ¡any ¡message ¡using ¡Net.send ¡ – He ¡can ¡intercept ¡any ¡message ¡using ¡Net.recv ¡
- Hence, ¡the ¡acacker ¡controls ¡the ¡network ¡
AUTHENTICATED ¡RPC ¡REVISITED ¡
SAMPLE ¡PROTOCOL ¡
Client ¡ ¡ Server ¡ request ¡ HMAC(key,request) ¡ response ¡ HMAC(key,request,response) ¡
F# ¡ImplementaCon ¡
Connecting to http://localhost:8081 Listening at http://localhost:8081 Accepted channels Sending: Foo | HMAC-SHA1{symkey[1]}[Foo] Sending Bar in response to Foo Sending: Bar | HMAC-SHA1{symkey[1]}[Foo | Bar] Accepted Bar as response to Foo
Test ¡with ¡Symbolic ¡Libraries ¡
Connecting to localhost:8080 Sending {BgAyICsgMj9mhJa7iDAcW3Rrk...} (28 bytes) Listening at ::1:8080 Received Request 2 + 2? Sending {AQA0NccjcuL/WOaYS0GGtOtPm...} (23 bytes) Received Response 4
Compare ¡with ¡the ¡original ¡concrete ¡run: ¡
Is ¡The ¡Protocol ¡Code ¡Secure? ¡
- 1. Can ¡the ¡opponent ¡cause ¡one ¡of ¡our ¡
authenCcaCon ¡goals ¡to ¡fail? ¡
- 2. What ¡if ¡the ¡opponent ¡sent ¡a ¡forged ¡message ¡to ¡
the ¡server? ¡
- 3. What ¡if ¡the ¡client ¡started ¡concurrent ¡sessions ¡
with ¡both ¡an ¡honest ¡and ¡a ¡dishonest ¡server? ¡
- 4. What ¡if ¡the ¡MAC ¡key ¡is ¡compromised? ¡
More ¡importantly, ¡what ¡is ¡the ¡formal ¡model ¡under ¡ which ¡we ¡may ¡prove ¡our ¡security ¡goals? ¡ ¡
Security ¡SpecificaCon ¡
- Assume ¡the ¡protocol ¡implementaCon ¡runs ¡with ¡
the ¡symbolic ¡code ¡for ¡Data, ¡Crypto, ¡Net ¡
- An ¡acacker ¡is ¡any ¡F# ¡program ¡that ¡has ¡access ¡to ¡
Data, ¡Crypto, ¡Net, ¡but ¡only ¡through ¡their ¡ interfaces ¡
- For ¡all ¡such ¡acackers, ¡in ¡all ¡runs ¡of ¡the ¡protocol ¡
- ur ¡security ¡goals ¡must ¡hold: ¡
– If ¡b ¡accepts ¡s ¡from ¡a, ¡a ¡must ¡have ¡sent ¡s ¡to ¡b ¡ – If ¡a ¡accepts ¡t ¡from ¡b, ¡b ¡must ¡have ¡sent ¡t ¡as ¡a ¡response ¡ to ¡s ¡from ¡a ¡
Summary ¡
- New ¡symbolic ¡implementaCons ¡for ¡libraries ¡
– Data, ¡Net, ¡Crypto ¡
- They ¡code ¡up ¡our ¡security ¡abstracCon ¡
– AssumpCons ¡on ¡crypto ¡primiCves ¡ – Abstract ¡model ¡of ¡data ¡conversions ¡ – Network ¡under ¡the ¡control ¡of ¡the ¡adversary ¡
- Symbolic ¡libraries ¡enable ¡symbolic ¡debugging ¡
– We ¡can ¡see ¡the ¡structure ¡of ¡crypto ¡messages ¡ ¡
- They ¡enable ¡a ¡precise ¡security ¡specificaCon ¡as ¡a ¡