SLIDE 1
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 7: Using
SLIDE 2
SLIDE 3
Values: ¡Channels, ¡Messages, ¡PaFerns ¡
3 ¡
SLIDE 4
Processes ¡
SLIDE 5
DeclaraCons ¡and ¡Scripts ¡
SLIDE 6
ReducCon ¡SemanCcs ¡
SLIDE 7
Query ¡SaCsfacCon ¡
- Recall ¡the ¡definiCon ¡of ¡queries ¡in ¡F ¡
- We ¡say ¡a ¡process ¡P ¡saCsfies ¡a ¡query ¡q: ¡P ¡|= ¡q ¡
SLIDE 8
Opponents, ¡Robust ¡Safety ¡
A ¡∆s-‑opponent ¡is ¡a ¡process ¡O ¡with ¡no ¡events, ¡s.t. ¡ ¡
- the ¡script ¡∆s ¡process ¡O ¡is ¡well ¡formed ¡and ¡ ¡
- O ¡contains ¡no ¡constructor ¡or ¡destructor ¡
declared ¡private ¡in ¡∆s. ¡ A ¡script ¡∆s ¡process ¡P ¡is ¡robustly ¡safe ¡for ¡q ¡ ¡ if ¡and ¡only ¡if ¡for ¡all ¡∆s-‑opponents ¡O, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡P ¡| ¡O ¡is ¡safe ¡for ¡q. ¡
SLIDE 9
Correctness ¡of ¡ProVerif ¡ ¡
[Abadi,Blanchet ¡JACM’05] ¡ ¡ ¡ ¡Theorem: ¡Given ¡a ¡script ¡S ¡= ¡∆s ¡process ¡P ¡ ¡ containing ¡a ¡query ¡q ¡
– If ¡ProVerif ¡returns ¡true, ¡then ¡S ¡is ¡robustly ¡safe ¡for ¡q ¡ – If ¡ProVerif ¡returns ¡false, ¡then ¡S ¡is ¡not ¡robustly ¡safe ¡for ¡q ¡ – If ¡ProVerif ¡returns ¡“cannot ¡be ¡proved”, ¡ ¡
- r ¡if ¡ProVerif ¡does ¡not ¡terminate, ¡we ¡don’t ¡know ¡
- Usually, ¡“Cannot ¡be ¡proved” ¡means ¡“Not ¡robustly ¡safe” ¡
SLIDE 10
Using ¡ProVerif ¡on ¡F# ¡Programs ¡
To ¡verify ¡realisCc ¡programs, ¡we ¡need ¡to ¡ ¡ understand ¡various ¡modeling ¡idioms: ¡
- How ¡do ¡we ¡encode ¡database ¡servers? ¡
- How ¡do ¡we ¡model ¡key ¡leakage? ¡
- How ¡do ¡we ¡specify ¡message ¡secrecy? ¡
- How ¡do ¡we ¡translate ¡F# ¡to ¡ProVerif? ¡
– funcCons ¡to ¡processes, ¡programs ¡to ¡scripts ¡
SLIDE 11
Lecture ¡7: ¡ Using ¡ProVerif: ¡ ¡ Encodings ¡and ¡Embeddings ¡
Databases ¡and ¡Key ¡Servers ¡
SLIDE 12
A ¡Simple ¡Private ¡Database ¡
- Let ¡us ¡treat ¡a ¡database ¡like ¡a ¡hash ¡table ¡that ¡
maps ¡indices ¡to ¡values ¡
– Insert ¡adds ¡a ¡mapping ¡from ¡an ¡index ¡to ¡a ¡value ¡ – Select ¡retrieves ¡a ¡value ¡at ¡an ¡index ¡ – There ¡is ¡no ¡operaCon ¡to ¡remove ¡a ¡value ¡
- By ¡default, ¡a ¡database ¡can ¡only ¡be ¡used ¡by ¡
someone ¡who ¡is ¡explicitly ¡given ¡access ¡to ¡it ¡ ¡
– Indices ¡are ¡typically ¡not ¡secret, ¡but ¡values ¡may ¡be ¡
SLIDE 13
A ¡Database ¡Server ¡in ¡ProVerif ¡
- The ¡private ¡database ¡is ¡modeled ¡as ¡a ¡channel ¡
¡ ¡ ¡ ¡ ¡private ¡free ¡db. ¡
- The ¡contents ¡of ¡the ¡database ¡are ¡messages ¡sent ¡ ¡
(but ¡not ¡yet ¡received) ¡on ¡this ¡channel ¡db ¡
- To ¡insert ¡a ¡value ¡v ¡with ¡index ¡i, ¡send ¡(i,v) ¡on ¡db ¡
¡ ¡ ¡ ¡ ¡out(db,(i,v)); ¡… ¡
- To ¡select ¡at ¡index ¡i, ¡receive ¡and ¡paFern-‑match: ¡
¡ ¡ ¡ ¡ ¡in(db,(=i,v’)); ¡ ¡ ¡ ¡ ¡(* ¡Remove ¡from ¡database ¡at ¡i ¡*) ¡ ¡ ¡ ¡ ¡ ¡out(db,(i,v’)); ¡ ¡ ¡ ¡ ¡(* ¡Restore ¡value ¡to ¡database ¡*) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡… ¡ ¡ ¡
SLIDE 14
Recall ¡ProVerif ¡Example ¡
- We ¡code ¡a ¡simple ¡client, ¡server ¡example: ¡
¡A ¡logs ¡Send(x) ¡ ¡A ¡ ¡B: ¡msg(enc(x,kab)) ¡ ¡B ¡logs ¡Accept(x) ¡ – All ¡messages ¡are ¡sent ¡on ¡a ¡public ¡channel ¡net ¡ – Messages ¡are ¡tagged ¡with ¡a ¡tag ¡msg ¡ – A ¡and ¡B ¡are ¡triggered ¡by ¡a ¡message ¡on ¡channel ¡app ¡ – A ¡and ¡B ¡share ¡the ¡key ¡kab ¡ – Security ¡Goal: ¡Accept(x) ¡=> ¡Send(x) ¡
SLIDE 15
Recall ¡ProVerif ¡Script ¡
- msg: ¡constructor ¡tag ¡
- enc-‑dec: ¡constructor-‑destructor ¡pair ¡
- kab: ¡fresh ¡name ¡(key) ¡generated ¡for ¡this ¡script ¡
- client, ¡server: ¡replicated ¡processes ¡(share ¡kab ¡
SLIDE 16
Generalizing ¡to ¡MulCple ¡Principals ¡
- A ¡and ¡B ¡are ¡not ¡hard-‑coded ¡(A ¡chooses ¡B): ¡
¡A ¡logs ¡Send(A,B,x) ¡ ¡A ¡ ¡B: ¡msg(A,B,enc(x,kab)) ¡ ¡B ¡logs ¡Accept(A,B,x) ¡ – Each ¡pair ¡of ¡principals ¡(p1,p2) ¡shares ¡a ¡key ¡ – Security ¡Goal: ¡Accept(p1,p2,x) ¡=> ¡Send(p1,p2,x) ¡
SLIDE 17
Example: ¡A ¡Key ¡Database ¡
- We ¡encode ¡a ¡database ¡that ¡stores ¡symmetric ¡
keys, ¡indexed ¡by ¡names ¡of ¡principals ¡(a,b) ¡ ¡ ¡ ¡ ¡private ¡free ¡keydb ¡
- We ¡represent ¡principals ¡by ¡0-‑ary ¡constructors ¡
¡ ¡ ¡ ¡data ¡A/0. ¡data ¡B/0. ¡data ¡C/0. ¡
- For ¡each ¡principal ¡pair, ¡we ¡generate ¡keys ¡
new ¡kAB; ¡out(keydb,((A,B),kAB); ¡ new ¡kAC; ¡out(keydb,((A,C),kAC); ¡… ¡
SLIDE 18
Example ¡ProVerif ¡Script ¡
SLIDE 19
Unbounded ¡Number ¡of ¡Principals ¡
- How ¡can ¡we ¡generalize ¡further? ¡
- The ¡current ¡model ¡has ¡a ¡fixed ¡A, ¡B, ¡C. ¡
- How ¡about ¡unlimited ¡number ¡of ¡principals? ¡
– Let ¡the ¡aFacker ¡choose ¡an ¡arbitrary ¡p1, ¡p2 ¡ – We ¡will ¡need ¡a ¡key ¡in ¡keydb ¡for ¡(p1,p2) ¡ – Shall ¡we ¡give ¡the ¡aFacker ¡db? ¡ – How ¡can ¡we ¡control ¡access ¡to ¡db, ¡but ¡sCll ¡allow ¡ the ¡aFacker ¡to ¡generate ¡a ¡key ¡for ¡any ¡(p1,p2)? ¡
SLIDE 20
Keys ¡Controlled ¡by ¡the ¡AFacker ¡
- How ¡about ¡keys ¡between ¡A ¡and ¡the ¡aFacker? ¡
– Can ¡we ¡allow ¡the ¡aFacker ¡to ¡inject ¡keys ¡for ¡principals ¡ he ¡controls? ¡ – Would ¡the ¡query ¡sCll ¡be ¡true? ¡ ¡ ¡ ¡ ¡query ¡ev:Accept(p1,p2,x) ¡==> ¡ev:Send(p1,p2,x) ¡
- We ¡use ¡a ¡new ¡event ¡BadKey ¡to ¡indicate ¡keys ¡that ¡
belong ¡to ¡the ¡adversary ¡
¡ ¡ ¡ ¡ ¡query ¡ev:Accept(p1,p2,x) ¡==> ¡ev:Send(p1,p2,x) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡| ¡ev:BadKey(p1,p2,k) ¡
SLIDE 21
Lecture ¡7: ¡ Using ¡ProVerif: ¡ ¡ Encodings ¡and ¡Embeddings ¡
Advanced ¡Security ¡Goals ¡
SLIDE 22
AuthenCcaCon ¡and ¡Secrecy ¡
- We ¡use ¡crypto ¡for ¡secure ¡communicaCons ¡over ¡an ¡
insecure ¡network ¡
- We ¡are ¡concerned ¡with ¡two ¡kinds ¡of ¡threats ¡
– The ¡aFacker ¡should ¡not ¡be ¡able ¡to ¡inject ¡his ¡(tainted) ¡ messages ¡into ¡our ¡servers ¡ ¡ – The ¡aFacker ¡should ¡not ¡be ¡able ¡to ¡steal ¡our ¡secrets ¡
- For ¡authenCcaCon, ¡check ¡every ¡received ¡message ¡
- For ¡secrecy, ¡guard ¡every ¡sent ¡message ¡
SLIDE 23
AuthenCcaCon ¡Queries ¡ ¡
- Message ¡integrity ¡
¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡query ¡ev:Accept(x) ¡==> ¡ev:Send(x) ¡
– The ¡message ¡was ¡not ¡tampered ¡with ¡
- Sender ¡authenCcaCon ¡
¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡query ¡ev:Accept(a,x) ¡==> ¡ev:Send(a,x) ¡
– Message ¡was ¡indeed ¡sent ¡by ¡this ¡sender ¡
- Intended ¡receiver ¡authenCcaCon ¡
¡ ¡ ¡ ¡query ¡ev:Accept(a,b,x) ¡==> ¡ev:Send(a,b,x) ¡
– Message ¡was ¡intended ¡for ¡this ¡receiver ¡
SLIDE 24
AuthenCcaCon ¡with ¡AFacker ¡Keys ¡
- We ¡only ¡guarantee ¡authenCcaCon ¡between ¡good ¡principals ¡
- Suppose ¡a ¡key ¡k ¡is ¡shared ¡between ¡principals ¡p1 ¡and ¡p2 ¡
- If ¡k ¡becomes ¡known ¡to ¡the ¡aFacker ¡(he ¡may ¡be ¡p1, ¡or ¡p2) ¡
- Then, ¡assume ¡that ¡an ¡event ¡BadKey(p1,p2,k) ¡has ¡been ¡logged ¡
- Message, ¡sender, ¡receiver ¡authenCcaCon ¡
¡ ¡ ¡ ¡query ¡ev:Accept(a,b,x) ¡==> ¡ev:Send(a,b,x) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡| ¡ ¡ev:BadKey(a,b,k) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡
– If ¡a ¡good ¡server ¡logs ¡Accept(a,b,x), ¡then ¡ ¡ either ¡a ¡good ¡client ¡logged ¡Send(a,b,x), ¡ ¡
- r ¡some ¡key ¡k ¡shared ¡between ¡a ¡& ¡b ¡is ¡known ¡to ¡the ¡aFacker ¡
SLIDE 25
Secrecy ¡
- How ¡de ¡we ¡check ¡that ¡a ¡key ¡is ¡kept ¡secret? ¡
- For ¡a ¡fixed ¡key, ¡use ¡the ¡query ¡a>acker: ¡
¡ ¡ ¡ ¡private ¡free ¡kab. ¡ ¡ ¡ ¡ ¡query ¡a>acker:kab. ¡
– Can ¡the ¡aFacker ¡every ¡find ¡kab? ¡
SLIDE 26
Secrecy ¡of ¡Database ¡Values ¡
- What ¡if ¡we ¡don’t ¡have ¡a ¡fixed ¡number ¡of ¡secrets? ¡
– How ¡do ¡we ¡specify ¡secrecy ¡of ¡databases? ¡
- To ¡check ¡whether ¡a ¡value ¡in ¡an ¡unbounded ¡database ¡is ¡
kept ¡secret, ¡we ¡code ¡an ¡oracle ¡
¡ ¡ ¡ ¡!in(guess,(index,value)); ¡
¡ ¡ ¡ ¡ ¡in(db,(=index,value’)); ¡ ¡ ¡ ¡ ¡ ¡if ¡value ¡= ¡value’ ¡ ¡ ¡then ¡event ¡SecretLeaked(index,value) ¡
- The ¡secrecy ¡query ¡then ¡becomes: ¡
¡ ¡ ¡ ¡ ¡ ¡query ¡ev:SecretLeaked(index,value) ¡
SLIDE 27
Key ¡Database ¡Secrecy ¡with ¡AFacker ¡Keys ¡
For ¡a ¡key ¡database, ¡we ¡have ¡ ¡
¡ ¡query ¡ev:KeyLeaked((a,b),key) ¡==> ¡BadKey(a,b,key) ¡
- If ¡a ¡Key ¡is ¡known ¡to ¡the ¡aFacker, ¡ ¡
then ¡it ¡must ¡have ¡been ¡explicitly ¡injected ¡using ¡injectkey, ¡ ¡
- r ¡it ¡must ¡have ¡been ¡explicitly ¡leaked ¡using ¡leakkey ¡
- The ¡protocol ¡itself ¡does ¡not ¡ever ¡leak ¡the ¡key ¡
- The ¡aFacker ¡does ¡not ¡get ¡keys ¡between ¡good ¡principals ¡
SLIDE 28
Message ¡Secrecy ¡
- How ¡do ¡we ¡model ¡secret ¡messages? ¡
data ¡msg/0. ¡ ¡ ¡ ¡(* ¡constant, ¡not ¡secret ¡*) ¡ !in(app,x);… ¡ ¡ ¡ ¡(* ¡from ¡the ¡aFacker, ¡not ¡secret ¡*) ¡
- The ¡message ¡must ¡contain ¡a ¡secret ¡name ¡
!in(app,x); ¡ ¡ ¡new ¡n; ¡ ¡ ¡ ¡let ¡msg ¡= ¡concat(x,n) ¡in ¡ ¡ ¡out(msgdb,msg); ¡(* ¡put ¡msg ¡in ¡a ¡database ¡for ¡query ¡*) ¡
- Message ¡secrecy ¡is ¡then ¡the ¡secrecy ¡of ¡msgdb ¡
SLIDE 29
Lecture ¡7: ¡ Using ¡ProVerif: ¡ ¡ Encodings ¡and ¡Embeddings ¡
FuncCons ¡as ¡Processes ¡
SLIDE 30
How ¡to ¡code ¡a ¡funcCon? ¡
- F# ¡programs ¡consist ¡of ¡datatypes ¡and ¡funcCons ¡
- Type ¡constructors ¡become ¡ProVerif ¡constructors ¡
- Types ¡themselves ¡are ¡erased ¡(except ¡for ¡ariCes) ¡
- How ¡can ¡we ¡write ¡a ¡funcCon ¡in ¡ProVerif? ¡
- Can ¡we ¡code ¡it ¡as ¡a ¡destructor? ¡
- Can ¡we ¡code ¡it ¡as ¡a ¡process? ¡
SLIDE 31
How ¡to ¡code ¡a ¡funcCon? ¡
FuncCon ¡DefiniCon: ¡let ¡f ¡x ¡= ¡x ¡ FuncCon ¡Call: ¡let ¡y ¡= ¡f ¡M ¡in ¡… ¡ Destructor ¡DefiniCon: ¡reduc ¡f(x) ¡= ¡x ¡ Destructor ¡Call: ¡let ¡y ¡= ¡f(M) ¡in ¡… ¡ Process ¡DefiniCon: ¡!in(f,(x,ret)); ¡out(ret,x) ¡ Process ¡Invoke: ¡new ¡ret; ¡out(f,(x,ret)); ¡in(ret,y); ¡… ¡ ¡
SLIDE 32
A ¡Full ¡TranslaCon ¡
- We ¡translate ¡well-‑formed ¡programs ¡S ¡:: ¡Ipub ¡
¡to ¡well-‑formed ¡scripts ¡∆s ¡process ¡P ¡
SLIDE 33
Ambient ¡DeclaraCons ¡
- One ¡public ¡channel: ¡publish ¡
- F ¡constructors ¡-‑> ¡ProVerif ¡data ¡
- F ¡constructors ¡not ¡in ¡the ¡public ¡interface ¡
become ¡private ¡fun ¡
- ¡ ¡
SLIDE 34
Expressions ¡to ¡Processes ¡
SLIDE 35
Programs ¡to ¡DeclaraCons ¡
SLIDE 36
Top ¡Level ¡Process ¡
SLIDE 37
Using ¡the ¡TranslaCon ¡
- The ¡FS2PV ¡tool ¡translates ¡F# ¡to ¡ProVerif ¡
- Available ¡from ¡Microsos ¡Research ¡
– Download ¡from ¡here ¡
- Works ¡for ¡all ¡examples ¡discussed ¡so ¡far ¡
– You ¡must ¡code ¡in ¡the ¡F ¡subset ¡of ¡F# ¡
- DEMO ¡
SLIDE 38
Final ¡Exercise ¡(Due ¡Oct ¡31) ¡
- Write ¡your ¡own ¡web ¡applicaCon ¡in ¡F# ¡
– Code ¡in ¡the ¡subset ¡F ¡ – Use ¡any ¡of ¡the ¡crypto ¡protocols ¡appropriate ¡for ¡your ¡ applicaCon ¡ – Use ¡Data, ¡Crypto, ¡Net, ¡Principals ¡
- Specify ¡the ¡security ¡goals ¡of ¡your ¡applicaCon ¡as ¡
queries ¡
- Translate ¡your ¡web ¡applicaCon ¡to ¡ProVerif ¡using ¡
FS2PV ¡ ¡
- Use ¡ProVerif ¡to ¡prove ¡that ¡your ¡applicaCon ¡is ¡