New UNITY theory, the N-S protocol
authorpaulson
Mon Sep 07 10:43:31 1998 +0200 (1998-09-07)
changeset 54304a179dba527a
parent 5429 0833486c23ce
child 5431 d50c2783f941
New UNITY theory, the N-S protocol
src/HOL/IsaMakefile
src/HOL/UNITY/NSP_Bad.ML
src/HOL/UNITY/NSP_Bad.thy
src/HOL/UNITY/ROOT.ML
     1.1 --- a/src/HOL/IsaMakefile	Mon Sep 07 10:40:17 1998 +0200
     1.2 +++ b/src/HOL/IsaMakefile	Mon Sep 07 10:43:31 1998 +0200
     1.3 @@ -163,7 +163,8 @@
     1.4    UNITY/Network.ML UNITY/Network.thy UNITY/Reach.ML UNITY/Reach.thy\
     1.5    UNITY/SubstAx.ML UNITY/SubstAx.thy UNITY/Token.ML UNITY/Token.thy\
     1.6    UNITY/Traces.ML UNITY/Traces.thy UNITY/UNITY.ML UNITY/UNITY.thy\
     1.7 -  UNITY/WFair.ML UNITY/WFair.thy UNITY/Lift.ML UNITY/Lift.thy
     1.8 +  UNITY/WFair.ML UNITY/WFair.thy UNITY/Lift.ML UNITY/Lift.thy\
     1.9 +  UNITY/NSP_Bad.ML UNITY/NSP_Bad.thy
    1.10  	@$(ISATOOL) usedir $(OUT)/HOL UNITY
    1.11  
    1.12  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/HOL/UNITY/NSP_Bad.ML	Mon Sep 07 10:43:31 1998 +0200
     2.3 @@ -0,0 +1,310 @@
     2.4 +(*  Title:      HOL/Auth/NSP_Bad
     2.5 +    ID:         $Id$
     2.6 +    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     2.7 +    Copyright   1996  University of Cambridge
     2.8 +
     2.9 +Inductive relation "ns_public" for the Needham-Schroeder Public-Key protocol.
    2.10 +Flawed version, vulnerable to Lowe's attack.
    2.11 +
    2.12 +From page 260 of
    2.13 +  Burrows, Abadi and Needham.  A Logic of Authentication.
    2.14 +  Proc. Royal Soc. 426 (1989)
    2.15 +*)
    2.16 +
    2.17 +AddEs spies_partsEs;
    2.18 +AddDs [impOfSubs analz_subset_parts];
    2.19 +AddDs [impOfSubs Fake_parts_insert];
    2.20 +
    2.21 +AddIffs [Spy_in_bad];
    2.22 +
    2.23 +(*For other theories, e.g. Mutex and Lift, using AddIffs slows proofs down.
    2.24 +  Here, it facilitates re-use of the Auth proofs.*)
    2.25 +
    2.26 +AddIffs (map simp_of_act [Fake_def, NS1_def, NS2_def, NS3_def]);
    2.27 +
    2.28 +Addsimps [Nprg_def RS def_prg_simps];
    2.29 +
    2.30 +(*A "possibility property": there are traces that reach the end*)
    2.31 +Goal "A ~= B ==> EX NB. EX s: reachable Nprg.                \
    2.32 +\                  Says A B (Crypt (pubK B) (Nonce NB)) : set s";
    2.33 +by (REPEAT (resolve_tac [exI,bexI] 1));
    2.34 +by (res_inst_tac [("act", "NS3")] reachable.Acts 2);
    2.35 +by (res_inst_tac [("act", "NS2")] reachable.Acts 3);
    2.36 +by (res_inst_tac [("act", "NS1")] reachable.Acts 4);
    2.37 +br reachable.Init 5;
    2.38 +by (ALLGOALS Asm_simp_tac);
    2.39 +by (REPEAT_FIRST (resolve_tac [exI]));
    2.40 +by possibility_tac;
    2.41 +result();
    2.42 +
    2.43 +
    2.44 +(**** Inductive proofs about ns_public ****)
    2.45 +
    2.46 +(*Nobody sends themselves messages*)
    2.47 +Goal "Invariant Nprg {s. ALL X. Says A A X ~: set s}";
    2.48 +by (rtac InvariantI 1);
    2.49 +by (Force_tac 1);
    2.50 +by (constrains_tac 1);
    2.51 +by Auto_tac;
    2.52 +qed "not_Says_to_self";
    2.53 +
    2.54 +(** HOW TO USE??  They don't seem to be needed!
    2.55 +Addsimps [not_Says_to_self];
    2.56 +AddSEs   [not_Says_to_self RSN (2, rev_notE)];
    2.57 +**)
    2.58 +
    2.59 +
    2.60 +(*can be used to simulate analz_mono_contra_tac
    2.61 +val analz_impI = read_instantiate_sg (sign_of thy)
    2.62 +                [("P", "?Y ~: analz (spies ?evs)")] impI;
    2.63 +
    2.64 +val spies_Says_analz_contraD = 
    2.65 +    spies_subset_spies_Says RS analz_mono RS contra_subsetD;
    2.66 +
    2.67 +by (rtac analz_impI 2);
    2.68 +by (auto_tac (claset() addSDs [spies_Says_analz_contraD], simpset()));
    2.69 +*)
    2.70 +
    2.71 +val parts_induct_tac = 
    2.72 +  (SELECT_GOAL o EVERY)
    2.73 +     [etac reachable.induct 1,
    2.74 +      Force_tac 1,
    2.75 +      Full_simp_tac 1,
    2.76 +      safe_tac (claset() delrules [impI,impCE]),
    2.77 +      REPEAT (FIRSTGOAL analz_mono_contra_tac),
    2.78 +      ALLGOALS Asm_simp_tac];
    2.79 +
    2.80 +
    2.81 +(** Theorems of the form X ~: parts (spies evs) imply that NOBODY
    2.82 +    sends messages containing X! **)
    2.83 +
    2.84 +(*Spy never sees another agent's private key! (unless it's bad at start)*)
    2.85 +Goal "Invariant Nprg {s. (Key (priK A) : parts (spies s)) = (A : bad)}";
    2.86 +by (rtac InvariantI 1);
    2.87 +by (Force_tac 1);
    2.88 +by (constrains_tac 1);
    2.89 +by Auto_tac;
    2.90 +qed "Spy_see_priK";
    2.91 +
    2.92 +(** HOW TO USE??
    2.93 +Addsimps [Spy_see_priK];
    2.94 +*)
    2.95 +
    2.96 +Goal "s : reachable Nprg ==> (Key (priK A) : parts (spies s)) = (A : bad)";
    2.97 +be reachable.induct 1;
    2.98 +by Auto_tac;
    2.99 +qed "Spy_see_priK";
   2.100 +Addsimps [Spy_see_priK];
   2.101 +
   2.102 +Goal "s : reachable Nprg ==> (Key (priK A) : analz (spies s)) = (A : bad)";
   2.103 +by Auto_tac;
   2.104 +qed "Spy_analz_priK";
   2.105 +Addsimps [Spy_analz_priK];
   2.106 +
   2.107 +AddSDs [Spy_see_priK RSN (2, rev_iffD1), 
   2.108 +	Spy_analz_priK RSN (2, rev_iffD1)];
   2.109 +
   2.110 +
   2.111 +(**** Authenticity properties obtained from NS2 ****)
   2.112 +
   2.113 +(*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
   2.114 +  is secret.  (Honest users generate fresh nonces.)*)
   2.115 +Goal "[| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies s); \
   2.116 +\        Nonce NA ~: analz (spies s);   s : reachable Nprg |]       \
   2.117 +\     ==> Crypt (pubK C) {|NA', Nonce NA|} ~: parts (spies s)";
   2.118 +by (etac rev_mp 1);
   2.119 +by (etac rev_mp 1);
   2.120 +by (parts_induct_tac 1);
   2.121 +by (ALLGOALS Blast_tac);
   2.122 +qed "no_nonce_NS1_NS2";
   2.123 +
   2.124 +(*Adding it to the claset slows down proofs...*)
   2.125 +val nonce_NS1_NS2_E = no_nonce_NS1_NS2 RSN (2, rev_notE);
   2.126 +
   2.127 +
   2.128 +(*Unicity for NS1: nonce NA identifies agents A and B*)
   2.129 +Goal "[| Nonce NA ~: analz (spies s);  s : reachable Nprg |]      \
   2.130 +\     ==> EX A' B'. ALL A B.                                            \
   2.131 +\            Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies s) --> \
   2.132 +\               A=A' & B=B'";
   2.133 +by (etac rev_mp 1);
   2.134 +by (parts_induct_tac 1);
   2.135 +by (ALLGOALS (simp_tac (simpset() addsimps [all_conj_distrib])));
   2.136 +(*NS1*)
   2.137 +by (expand_case_tac "NA = ?y" 2 THEN Blast_tac 2);
   2.138 +(*Fake*)
   2.139 +by (Blast_tac 1);
   2.140 +val lemma = result();
   2.141 +
   2.142 +Goal "[| Crypt(pubK B)  {|Nonce NA, Agent A|}  : parts(spies s); \
   2.143 +\        Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(spies s); \
   2.144 +\        Nonce NA ~: analz (spies s);                            \
   2.145 +\        s : reachable Nprg |]                                   \
   2.146 +\     ==> A=A' & B=B'";
   2.147 +by (prove_unique_tac lemma 1);
   2.148 +qed "unique_NA";
   2.149 +
   2.150 +
   2.151 +(*Tactic for proving secrecy theorems*)
   2.152 +val analz_induct_tac = 
   2.153 +  (SELECT_GOAL o EVERY)
   2.154 +     [etac reachable.induct 1,
   2.155 +      Force_tac 1,
   2.156 +      Full_simp_tac 1,
   2.157 +      safe_tac (claset() delrules [impI,impCE]),
   2.158 +      ALLGOALS Asm_simp_tac];
   2.159 +
   2.160 +
   2.161 +
   2.162 +(*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure*)
   2.163 +Goal "[| Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set s;   \
   2.164 +\        A ~: bad;  B ~: bad;  s : reachable Nprg |]                    \
   2.165 +\     ==>  Nonce NA ~: analz (spies s)";
   2.166 +by (etac rev_mp 1);
   2.167 +by (analz_induct_tac 1);
   2.168 +(*NS3*)
   2.169 +by (blast_tac (claset() addEs [nonce_NS1_NS2_E]) 4);
   2.170 +(*NS2*)
   2.171 +by (blast_tac (claset() addDs [unique_NA]) 3);
   2.172 +(*NS1*)
   2.173 +by (Blast_tac 2);
   2.174 +(*Fake*)
   2.175 +by (spy_analz_tac 1);
   2.176 +qed "Spy_not_see_NA";
   2.177 +
   2.178 +
   2.179 +(*Authentication for A: if she receives message 2 and has used NA
   2.180 +  to start a run, then B has sent message 2.*)
   2.181 +Goal "[| Says A  B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set s;  \
   2.182 +\        Says B' A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set s;  \
   2.183 +\        A ~: bad;  B ~: bad;  s : reachable Nprg |]                    \
   2.184 +\     ==> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set s";
   2.185 +by (etac rev_mp 1);
   2.186 +(*prepare induction over Crypt (pubK A) {|NA,NB|} : parts H*)
   2.187 +by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
   2.188 +by (parts_induct_tac 1);
   2.189 +by (ALLGOALS Clarify_tac);
   2.190 +(*NS2*)
   2.191 +by (blast_tac (claset() addDs [Spy_not_see_NA, unique_NA]) 3);
   2.192 +(*NS1*)
   2.193 +by (Blast_tac 2);
   2.194 +(*Fake*)
   2.195 +by (blast_tac (claset() addDs [Spy_not_see_NA]) 1);
   2.196 +qed "A_trusts_NS2";
   2.197 +
   2.198 +
   2.199 +(*If the encrypted message appears then it originated with Alice in NS1*)
   2.200 +Goal "[| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies s); \
   2.201 +\        Nonce NA ~: analz (spies s);                            \
   2.202 +\        s : reachable Nprg |]                                        \
   2.203 +\     ==> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set s";
   2.204 +by (etac rev_mp 1);
   2.205 +by (etac rev_mp 1);
   2.206 +by (parts_induct_tac 1);
   2.207 +by (Blast_tac 1);
   2.208 +qed "B_trusts_NS1";
   2.209 +
   2.210 +
   2.211 +
   2.212 +(**** Authenticity properties obtained from NS2 ****)
   2.213 +
   2.214 +(*Unicity for NS2: nonce NB identifies nonce NA and agent A
   2.215 +  [proof closely follows that for unique_NA] *)
   2.216 +Goal "[| Nonce NB ~: analz (spies s);  s : reachable Nprg |]         \
   2.217 +\     ==> EX A' NA'. ALL A NA.                                       \
   2.218 +\           Crypt (pubK A) {|Nonce NA, Nonce NB|} : parts (spies s)  \
   2.219 +\                -->  A=A' & NA=NA'";
   2.220 +by (etac rev_mp 1);
   2.221 +by (parts_induct_tac 1);
   2.222 +by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
   2.223 +(*NS2*)
   2.224 +by (expand_case_tac "NB = ?y" 2 THEN Blast_tac 2);
   2.225 +(*Fake*)
   2.226 +by (Blast_tac 1);
   2.227 +val lemma = result();
   2.228 +
   2.229 +Goal "[| Crypt(pubK A) {|Nonce NA, Nonce NB|}  : parts(spies s); \
   2.230 +\        Crypt(pubK A'){|Nonce NA', Nonce NB|} : parts(spies s); \
   2.231 +\        Nonce NB ~: analz (spies s);                            \
   2.232 +\        s : reachable Nprg |]                                        \
   2.233 +\     ==> A=A' & NA=NA'";
   2.234 +by (prove_unique_tac lemma 1);
   2.235 +qed "unique_NB";
   2.236 +
   2.237 +
   2.238 +(*NB remains secret PROVIDED Alice never responds with round 3*)
   2.239 +Goal "[| Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set s;  \
   2.240 +\       ALL C. Says A C (Crypt (pubK C) (Nonce NB)) ~: set s;      \
   2.241 +\       A ~: bad;  B ~: bad;  s : reachable Nprg |]                     \
   2.242 +\    ==> Nonce NB ~: analz (spies s)";
   2.243 +by (etac rev_mp 1);
   2.244 +by (etac rev_mp 1);
   2.245 +by (analz_induct_tac 1);
   2.246 +by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
   2.247 +by (ALLGOALS Clarify_tac);
   2.248 +(*NS3: because NB determines A*)
   2.249 +by (blast_tac (claset() addDs [unique_NB]) 4);
   2.250 +(*NS2: by freshness and unicity of NB*)
   2.251 +by (blast_tac (claset() addEs [nonce_NS1_NS2_E]) 3);
   2.252 +(*NS1: by freshness*)
   2.253 +by (Blast_tac 2);
   2.254 +(*Fake*)
   2.255 +by (spy_analz_tac 1);
   2.256 +qed "Spy_not_see_NB";
   2.257 +
   2.258 +
   2.259 +
   2.260 +(*Authentication for B: if he receives message 3 and has used NB
   2.261 +  in message 2, then A has sent message 3--to somebody....*)
   2.262 +Goal "[| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set s; \
   2.263 +\        Says A' B (Crypt (pubK B) (Nonce NB)): set s;              \
   2.264 +\        A ~: bad;  B ~: bad;  s : reachable Nprg |]                \
   2.265 +\     ==> EX C. Says A C (Crypt (pubK C) (Nonce NB)) : set s";
   2.266 +by (etac rev_mp 1);
   2.267 +(*prepare induction over Crypt (pubK B) NB : parts H*)
   2.268 +by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
   2.269 +by (parts_induct_tac 1);
   2.270 +by (ALLGOALS (asm_simp_tac (simpset() addsimps [ex_disj_distrib])));
   2.271 +by (ALLGOALS Clarify_tac);
   2.272 +(*NS3: because NB determines A (this use of unique_NB is more robust) *)
   2.273 +by (blast_tac (claset() addDs [Spy_not_see_NB]
   2.274 +			addIs [unique_NB RS conjunct1]) 3);
   2.275 +(*NS1: by freshness*)
   2.276 +by (Blast_tac 2);
   2.277 +(*Fake*)
   2.278 +by (blast_tac (claset() addDs [Spy_not_see_NB]) 1);
   2.279 +qed "B_trusts_NS3";
   2.280 +
   2.281 +
   2.282 +(*Can we strengthen the secrecy theorem?  NO*)
   2.283 +Goal "[| A ~: bad;  B ~: bad;  s : reachable Nprg |]           \
   2.284 +\     ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set s \
   2.285 +\           --> Nonce NB ~: analz (spies s)";
   2.286 +by (analz_induct_tac 1);
   2.287 +by (ALLGOALS Clarify_tac);
   2.288 +(*NS2: by freshness and unicity of NB*)
   2.289 +by (blast_tac (claset() addEs [nonce_NS1_NS2_E]) 3);
   2.290 +(*NS1: by freshness*)
   2.291 +by (Blast_tac 2);
   2.292 +(*Fake*)
   2.293 +by (spy_analz_tac 1);
   2.294 +(*NS3: unicity of NB identifies A and NA, but not B*)
   2.295 +by (forw_inst_tac [("A'","A")] (Says_imp_spies RS parts.Inj RS unique_NB) 1
   2.296 +    THEN REPEAT (eresolve_tac [asm_rl, Says_imp_spies RS parts.Inj] 1));
   2.297 +by Auto_tac;
   2.298 +by (rename_tac "s B' C" 1);
   2.299 +
   2.300 +(*
   2.301 +THIS IS THE ATTACK!
   2.302 +Level 8
   2.303 +!!s. [| A ~: bad; B ~: bad; s : reachable Nprg |]
   2.304 +       ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set s -->
   2.305 +           Nonce NB ~: analz (spies s)
   2.306 + 1. !!s B' C.
   2.307 +       [| A ~: bad; B ~: bad; s : reachable Nprg;
   2.308 +          Says A C (Crypt (pubK C) {|Nonce NA, Agent A|}) : set s;
   2.309 +          Says B' A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set s; C : bad;
   2.310 +          Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set s;
   2.311 +          Nonce NB ~: analz (spies s) |]
   2.312 +       ==> False
   2.313 +*)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/HOL/UNITY/NSP_Bad.thy	Mon Sep 07 10:43:31 1998 +0200
     3.3 @@ -0,0 +1,60 @@
     3.4 +(*  Title:      HOL/Auth/NSP_Bad
     3.5 +    ID:         $Id$
     3.6 +    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3.7 +    Copyright   1996  University of Cambridge
     3.8 +
     3.9 +loadpath := "../Auth" :: !loadpath; use_thy"NSP_Bad";
    3.10 +
    3.11 +Security protocols in UNITY: Needham-Schroeder, public keys (flawed version).
    3.12 +
    3.13 +Original file is ../Auth/NS_Public_Bad
    3.14 +*)
    3.15 +
    3.16 +NSP_Bad = Public + Constrains + 
    3.17 +
    3.18 +types state = event list
    3.19 +
    3.20 +constdefs
    3.21 +  
    3.22 +  (*The spy MAY say anything he CAN say.  We do not expect him to
    3.23 +    invent new nonces here, but he can also use NS1.  Common to
    3.24 +    all similar protocols.*)
    3.25 +  Fake :: "(state*state) set"
    3.26 +    "Fake == {(s,s').
    3.27 +	      EX B X. s' = Says Spy B X # s
    3.28 +		    & B ~= Spy & X: synth (analz (spies s))}"
    3.29 +  
    3.30 +  (*The numeric suffixes on A identify the rule*)
    3.31 +
    3.32 +  (*Alice initiates a protocol run, sending a nonce to Bob*)
    3.33 +  NS1 :: "(state*state) set"
    3.34 +    "NS1 == {(s1,s').
    3.35 +	     EX A1 B NA.
    3.36 +	         s' = Says A1 B (Crypt (pubK B) {|Nonce NA, Agent A1|}) # s1
    3.37 +	       & A1 ~= B & Nonce NA ~: used s1}"
    3.38 +  
    3.39 +  (*Bob responds to Alice's message with a further nonce*)
    3.40 +  NS2 :: "(state*state) set"
    3.41 +    "NS2 == {(s2,s').
    3.42 +	     EX A' A2 B NA NB.
    3.43 +	         s' = Says B A2 (Crypt (pubK A2) {|Nonce NA, Nonce NB|}) # s2
    3.44 +               & Says A' B (Crypt (pubK B) {|Nonce NA, Agent A2|}) : set s2
    3.45 +	       & A2 ~= B & Nonce NB ~: used s2}"
    3.46 + 
    3.47 +  (*Alice proves her existence by sending NB back to Bob.*)
    3.48 +  NS3 :: "(state*state) set"
    3.49 +    "NS3 == {(s3,s').
    3.50 +	     EX A3 B' B NA NB.
    3.51 +	         s' = Says A3 B (Crypt (pubK B) (Nonce NB)) # s3
    3.52 +               & Says A3  B (Crypt (pubK B) {|Nonce NA, Agent A3|}) : set s3
    3.53 +	       & Says B' A3 (Crypt (pubK A3) {|Nonce NA, Nonce NB|}) : set s3}"
    3.54 +
    3.55 +
    3.56 +
    3.57 +constdefs
    3.58 +  Nprg :: state program
    3.59 +    (*Initial trace is empty*)
    3.60 +    "Nprg == (|Init = {[]},   
    3.61 +	       Acts = {id, Fake, NS1, NS2, NS3}|)"
    3.62 +
    3.63 +end
     4.1 --- a/src/HOL/UNITY/ROOT.ML	Mon Sep 07 10:40:17 1998 +0200
     4.2 +++ b/src/HOL/UNITY/ROOT.ML	Mon Sep 07 10:43:31 1998 +0200
     4.3 @@ -21,3 +21,6 @@
     4.4  time_use_thy "Reach";
     4.5  time_use_thy "Handshake";
     4.6  time_use_thy "Lift";
     4.7 +
     4.8 +loadpath := "../Auth" :: !loadpath;  (*necessary to find the Auth theories*)
     4.9 +use_thy"NSP_Bad";