src/HOL/Auth/NS_Public_Bad.ML
author paulson
Tue Nov 11 11:16:18 1997 +0100 (1997-11-11)
changeset 4198 c63639beeff1
parent 4197 1547bc6daa5a
child 4449 df30e75f670f
permissions -rw-r--r--
Fixed spelling error
     1 (*  Title:      HOL/Auth/NS_Public_Bad
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1996  University of Cambridge
     5 
     6 Inductive relation "ns_public" for the Needham-Schroeder Public-Key protocol.
     7 Flawed version, vulnerable to Lowe's attack.
     8 
     9 From page 260 of
    10   Burrows, Abadi and Needham.  A Logic of Authentication.
    11   Proc. Royal Soc. 426 (1989)
    12 *)
    13 
    14 open NS_Public_Bad;
    15 
    16 proof_timing:=true;
    17 HOL_quantifiers := false;
    18 
    19 AddIffs [Spy_in_bad];
    20 
    21 (*A "possibility property": there are traces that reach the end*)
    22 goal thy 
    23  "!!A B. A ~= B ==> EX NB. EX evs: ns_public.               \
    24 \                     Says A B (Crypt (pubK B) (Nonce NB)) : set evs";
    25 by (REPEAT (resolve_tac [exI,bexI] 1));
    26 by (rtac (ns_public.Nil RS ns_public.NS1 RS ns_public.NS2 RS ns_public.NS3) 2);
    27 by possibility_tac;
    28 result();
    29 
    30 
    31 (**** Inductive proofs about ns_public ****)
    32 
    33 (*Nobody sends themselves messages*)
    34 goal thy "!!evs. evs : ns_public ==> ALL A X. Says A A X ~: set evs";
    35 by (etac ns_public.induct 1);
    36 by (Auto_tac());
    37 qed_spec_mp "not_Says_to_self";
    38 Addsimps [not_Says_to_self];
    39 AddSEs   [not_Says_to_self RSN (2, rev_notE)];
    40 
    41 
    42 (*Induction for regularity theorems.  If induction formula has the form
    43    X ~: analz (spies evs) --> ... then it shortens the proof by discarding
    44    needless information about analz (insert X (spies evs))  *)
    45 fun parts_induct_tac i = 
    46     etac ns_public.induct i
    47     THEN 
    48     REPEAT (FIRSTGOAL analz_mono_contra_tac)
    49     THEN 
    50     prove_simple_subgoals_tac i;
    51 
    52 
    53 (** Theorems of the form X ~: parts (spies evs) imply that NOBODY
    54     sends messages containing X! **)
    55 
    56 (*Spy never sees another agent's private key! (unless it's bad at start)*)
    57 goal thy 
    58  "!!A. evs: ns_public ==> (Key (priK A) : parts (spies evs)) = (A : bad)";
    59 by (parts_induct_tac 1);
    60 by (Fake_parts_insert_tac 1);
    61 qed "Spy_see_priK";
    62 Addsimps [Spy_see_priK];
    63 
    64 goal thy 
    65  "!!A. evs: ns_public ==> (Key (priK A) : analz (spies evs)) = (A : bad)";
    66 by (auto_tac(claset() addDs [impOfSubs analz_subset_parts], simpset()));
    67 qed "Spy_analz_priK";
    68 Addsimps [Spy_analz_priK];
    69 
    70 goal thy  "!!A. [| Key (priK A) : parts (spies evs);       \
    71 \                  evs : ns_public |] ==> A:bad";
    72 by (blast_tac (claset() addDs [Spy_see_priK]) 1);
    73 qed "Spy_see_priK_D";
    74 
    75 bind_thm ("Spy_analz_priK_D", analz_subset_parts RS subsetD RS Spy_see_priK_D);
    76 AddSDs [Spy_see_priK_D, Spy_analz_priK_D];
    77 
    78 
    79 (**** Authenticity properties obtained from NS2 ****)
    80 
    81 (*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
    82   is secret.  (Honest users generate fresh nonces.)*)
    83 goal thy 
    84  "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs); \
    85 \           Nonce NA ~: analz (spies evs);   evs : ns_public |]       \
    86 \ ==> Crypt (pubK C) {|NA', Nonce NA|} ~: parts (spies evs)";
    87 by (etac rev_mp 1);
    88 by (etac rev_mp 1);
    89 by (parts_induct_tac 1);
    90 (*NS3*)
    91 by (blast_tac (claset() addSEs partsEs) 3);
    92 (*NS2*)
    93 by (blast_tac (claset() addSEs partsEs) 2);
    94 by (Fake_parts_insert_tac 1);
    95 qed "no_nonce_NS1_NS2";
    96 
    97 
    98 (*Unicity for NS1: nonce NA identifies agents A and B*)
    99 goal thy 
   100  "!!evs. [| Nonce NA ~: analz (spies evs);  evs : ns_public |]      \
   101 \ ==> EX A' B'. ALL A B.                                            \
   102 \      Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs) --> \
   103 \      A=A' & B=B'";
   104 by (etac rev_mp 1);
   105 by (parts_induct_tac 1);
   106 by (ALLGOALS
   107     (asm_simp_tac (simpset() addsimps [all_conj_distrib, parts_insert_spies])));
   108 (*NS1*)
   109 by (expand_case_tac "NA = ?y" 2 THEN blast_tac (claset() addSEs partsEs) 2);
   110 (*Fake*)
   111 by (Clarify_tac 1);
   112 by (ex_strip_tac 1);
   113 by (Fake_parts_insert_tac 1);
   114 val lemma = result();
   115 
   116 goal thy 
   117  "!!evs. [| Crypt(pubK B)  {|Nonce NA, Agent A|}  : parts(spies evs); \
   118 \           Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(spies evs); \
   119 \           Nonce NA ~: analz (spies evs);                            \
   120 \           evs : ns_public |]                                        \
   121 \        ==> A=A' & B=B'";
   122 by (prove_unique_tac lemma 1);
   123 qed "unique_NA";
   124 
   125 
   126 (*Tactic for proving secrecy theorems*)
   127 fun analz_induct_tac i = 
   128     etac ns_public.induct i   THEN
   129     ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if]));
   130 
   131 
   132 (*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure*)
   133 goal thy 
   134  "!!evs. [| Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set evs;   \
   135 \           A ~: bad;  B ~: bad;  evs : ns_public |]                    \
   136 \        ==>  Nonce NA ~: analz (spies evs)";
   137 by (etac rev_mp 1);
   138 by (analz_induct_tac 1);
   139 (*NS3*)
   140 by (blast_tac (claset() addDs  [Says_imp_spies RS parts.Inj]
   141                        addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 4);
   142 (*NS2*)
   143 by (blast_tac (claset() addSEs [MPair_parts]
   144 		       addDs  [Says_imp_spies RS parts.Inj,
   145 			       parts.Body, unique_NA]) 3);
   146 (*NS1*)
   147 by (blast_tac (claset() addSEs spies_partsEs
   148                        addIs  [impOfSubs analz_subset_parts]) 2);
   149 (*Fake*)
   150 by (spy_analz_tac 1);
   151 qed "Spy_not_see_NA";
   152 
   153 
   154 (*Authentication for A: if she receives message 2 and has used NA
   155   to start a run, then B has sent message 2.*)
   156 goal thy 
   157  "!!evs. [| Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs;  \
   158 \           Says B' A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs;  \
   159 \           A ~: bad;  B ~: bad;  evs : ns_public |]                    \
   160 \        ==> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs";
   161 by (etac rev_mp 1);
   162 (*prepare induction over Crypt (pubK A) {|NA,NB|} : parts H*)
   163 by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
   164 by (etac ns_public.induct 1);
   165 by (ALLGOALS Asm_simp_tac);
   166 by (ALLGOALS Clarify_tac);
   167 (*NS2*)
   168 by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj,
   169 			      Spy_not_see_NA, unique_NA]) 3);
   170 (*NS1*)
   171 by (blast_tac (claset() addSEs spies_partsEs) 2);
   172 (*Fake*)
   173 by (blast_tac (claset() addSDs [impOfSubs Fake_parts_insert]
   174                        addDs  [Spy_not_see_NA, 
   175 			       impOfSubs analz_subset_parts]) 1);
   176 qed "A_trusts_NS2";
   177 
   178 (*If the encrypted message appears then it originated with Alice in NS1*)
   179 goal thy 
   180  "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs); \
   181 \           Nonce NA ~: analz (spies evs);                            \
   182 \           evs : ns_public |]                                        \
   183 \   ==> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs";
   184 by (etac rev_mp 1);
   185 by (etac rev_mp 1);
   186 by (parts_induct_tac 1);
   187 by (Fake_parts_insert_tac 1);
   188 qed "B_trusts_NS1";
   189 
   190 
   191 
   192 (**** Authenticity properties obtained from NS2 ****)
   193 
   194 (*Unicity for NS2: nonce NB identifies agent A and nonce NA
   195   [proof closely follows that for unique_NA] *)
   196 goal thy 
   197  "!!evs. [| Nonce NB ~: analz (spies evs);  evs : ns_public |]  \
   198 \ ==> EX A' NA'. ALL A NA.                                      \
   199 \      Crypt (pubK A) {|Nonce NA, Nonce NB|}                    \
   200 \        : parts (spies evs)  -->  A=A' & NA=NA'";
   201 by (etac rev_mp 1);
   202 by (parts_induct_tac 1);
   203 by (ALLGOALS
   204     (asm_simp_tac (simpset() addsimps [all_conj_distrib, parts_insert_spies])));
   205 (*NS2*)
   206 by (expand_case_tac "NB = ?y" 2 THEN blast_tac (claset() addSEs partsEs) 2);
   207 (*Fake*)
   208 by (Clarify_tac 1);
   209 by (ex_strip_tac 1);
   210 by (Fake_parts_insert_tac 1);
   211 val lemma = result();
   212 
   213 goal thy 
   214  "!!evs. [| Crypt(pubK A) {|Nonce NA, Nonce NB|}  : parts(spies evs); \
   215 \           Crypt(pubK A'){|Nonce NA', Nonce NB|} : parts(spies evs); \
   216 \           Nonce NB ~: analz (spies evs);                            \
   217 \           evs : ns_public |]                                        \
   218 \        ==> A=A' & NA=NA'";
   219 by (prove_unique_tac lemma 1);
   220 qed "unique_NB";
   221 
   222 
   223 (*NB remains secret PROVIDED Alice never responds with round 3*)
   224 goal thy 
   225  "!!evs.[| Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs;  \
   226 \          ALL C. Says A C (Crypt (pubK C) (Nonce NB)) ~: set evs;      \
   227 \          A ~: bad;  B ~: bad;  evs : ns_public |]                     \
   228 \       ==> Nonce NB ~: analz (spies evs)";
   229 by (etac rev_mp 1);
   230 by (etac rev_mp 1);
   231 by (analz_induct_tac 1);
   232 by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
   233 by (ALLGOALS Clarify_tac);
   234 (*NS3: because NB determines A*)
   235 by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj, unique_NB]) 4);
   236 (*NS2: by freshness and unicity of NB*)
   237 by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj]
   238                        addEs [no_nonce_NS1_NS2 RSN (2, rev_notE)]
   239                        addEs partsEs
   240 		       addIs [impOfSubs analz_subset_parts]) 3);
   241 (*NS1: by freshness*)
   242 by (blast_tac (claset() addSEs spies_partsEs) 2);
   243 (*Fake*)
   244 by (spy_analz_tac 1);
   245 qed "Spy_not_see_NB";
   246 
   247 
   248 
   249 (*Authentication for B: if he receives message 3 and has used NB
   250   in message 2, then A has sent message 3--to somebody....*)
   251 goal thy 
   252  "!!evs. [| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs; \
   253 \           Says A' B (Crypt (pubK B) (Nonce NB)): set evs;              \
   254 \           A ~: bad;  B ~: bad;  evs : ns_public |]                   \
   255 \        ==> EX C. Says A C (Crypt (pubK C) (Nonce NB)) : set evs";
   256 by (etac rev_mp 1);
   257 (*prepare induction over Crypt (pubK B) NB : parts H*)
   258 by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
   259 by (parts_induct_tac 1);
   260 by (ALLGOALS (asm_simp_tac (simpset() addsimps [ex_disj_distrib])));
   261 by (ALLGOALS Clarify_tac);
   262 (*NS3: because NB determines A (this use of unique_NB is more robust) *)
   263 by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj, Spy_not_see_NB]
   264 			addIs [unique_NB RS conjunct1]) 3);
   265 (*NS1: by freshness*)
   266 by (blast_tac (claset() addSEs spies_partsEs) 2);
   267 (*Fake*)
   268 by (blast_tac (claset() addSDs [impOfSubs Fake_parts_insert]
   269                        addDs  [Spy_not_see_NB, 
   270 			       impOfSubs analz_subset_parts]) 1);
   271 qed "B_trusts_NS3";
   272 
   273 
   274 (*Can we strengthen the secrecy theorem?  NO*)
   275 goal thy 
   276  "!!evs. [| A ~: bad;  B ~: bad;  evs : ns_public |]           \
   277 \ ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs \
   278 \     --> Nonce NB ~: analz (spies evs)";
   279 by (analz_induct_tac 1);
   280 by (ALLGOALS Clarify_tac);
   281 (*NS2: by freshness and unicity of NB*)
   282 by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj]
   283                        addEs [no_nonce_NS1_NS2 RSN (2, rev_notE)]
   284                        addEs partsEs
   285 		       addIs [impOfSubs analz_subset_parts]) 3);
   286 (*NS1: by freshness*)
   287 by (blast_tac (claset() addSEs spies_partsEs) 2);
   288 (*Fake*)
   289 by (spy_analz_tac 1);
   290 (*NS3: unicity of NB identifies A and NA, but not B*)
   291 by (forw_inst_tac [("A'","A")] (Says_imp_spies RS parts.Inj RS unique_NB) 1
   292     THEN REPEAT (eresolve_tac [asm_rl, Says_imp_spies RS parts.Inj] 1));
   293 by (Auto_tac());
   294 by (rename_tac "C B' evs3" 1);
   295 
   296 (*
   297 THIS IS THE ATTACK!
   298 Level 8
   299 !!evs. [| A ~: bad; B ~: bad; evs : ns_public |]
   300        ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs -->
   301            Nonce NB ~: analz (spies evs)
   302  1. !!C B' evs3.
   303        [| A ~: bad; B ~: bad; evs3 : ns_public;
   304           Says A C (Crypt (pubK C) {|Nonce NA, Agent A|}) : set evs3;
   305           Says B' A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs3; C : bad;
   306           Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs3;
   307           Nonce NB ~: analz (spies evs3) |]
   308        ==> False
   309 *)