src/HOL/Auth/NS_Public_Bad.ML
author nipkow
Tue Apr 08 10:48:42 1997 +0200 (1997-04-08)
changeset 2919 953a47dc0519
parent 2637 e9b203f854ae
child 3121 cbb6c0c1c58a
permissions -rw-r--r--
Dep. on Provers/nat_transitive
     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 val op addss = op unsafe_addss;
    20 
    21 AddIffs [Spy_in_lost];
    22 
    23 (*Replacing the variable by a constant improves search speed by 50%!*)
    24 val Says_imp_sees_Spy' = 
    25     read_instantiate_sg (sign_of thy) [("lost","lost")] Says_imp_sees_Spy;
    26 
    27 
    28 (*A "possibility property": there are traces that reach the end*)
    29 goal thy 
    30  "!!A B. A ~= B ==> EX NB. EX evs: ns_public.               \
    31 \                     Says A B (Crypt (pubK B) (Nonce NB)) : set_of_list evs";
    32 by (REPEAT (resolve_tac [exI,bexI] 1));
    33 by (rtac (ns_public.Nil RS ns_public.NS1 RS ns_public.NS2 RS ns_public.NS3) 2);
    34 by possibility_tac;
    35 result();
    36 
    37 
    38 (**** Inductive proofs about ns_public ****)
    39 
    40 (*Nobody sends themselves messages*)
    41 goal thy "!!evs. evs : ns_public ==> ALL A X. Says A A X ~: set_of_list evs";
    42 by (etac ns_public.induct 1);
    43 by (Auto_tac());
    44 qed_spec_mp "not_Says_to_self";
    45 Addsimps [not_Says_to_self];
    46 AddSEs   [not_Says_to_self RSN (2, rev_notE)];
    47 
    48 
    49 (*For proving the easier theorems about X ~: parts (sees lost Spy evs) *)
    50 fun parts_induct_tac i = SELECT_GOAL
    51     (DETERM (etac ns_public.induct 1 THEN 
    52              (*Fake message*)
    53              TRY (best_tac (!claset addDs [impOfSubs analz_subset_parts,
    54                                            impOfSubs Fake_parts_insert]
    55                                     addss (!simpset)) 2)) THEN
    56      (*Base case*)
    57      fast_tac (!claset addss (!simpset)) 1 THEN
    58      ALLGOALS Asm_simp_tac) i;
    59 
    60 (** Theorems of the form X ~: parts (sees lost Spy evs) imply that NOBODY
    61     sends messages containing X! **)
    62 
    63 (*Spy never sees another agent's private key! (unless it's lost at start)*)
    64 goal thy 
    65  "!!evs. evs : ns_public \
    66 \        ==> (Key (priK A) : parts (sees lost Spy evs)) = (A : lost)";
    67 by (parts_induct_tac 1);
    68 by (Auto_tac());
    69 qed "Spy_see_priK";
    70 Addsimps [Spy_see_priK];
    71 
    72 goal thy 
    73  "!!evs. evs : ns_public \
    74 \        ==> (Key (priK A) : analz (sees lost Spy evs)) = (A : lost)";
    75 by (auto_tac(!claset addDs [impOfSubs analz_subset_parts], !simpset));
    76 qed "Spy_analz_priK";
    77 Addsimps [Spy_analz_priK];
    78 
    79 goal thy  "!!A. [| Key (priK A) : parts (sees lost Spy evs);       \
    80 \                  evs : ns_public |] ==> A:lost";
    81 by (fast_tac (!claset addDs [Spy_see_priK]) 1);
    82 qed "Spy_see_priK_D";
    83 
    84 bind_thm ("Spy_analz_priK_D", analz_subset_parts RS subsetD RS Spy_see_priK_D);
    85 AddSDs [Spy_see_priK_D, Spy_analz_priK_D];
    86 
    87 
    88 fun analz_induct_tac i = 
    89     etac ns_public.induct i     THEN
    90     ALLGOALS (asm_simp_tac 
    91               (!simpset addsimps [not_parts_not_analz]
    92                         setloop split_tac [expand_if]));
    93 
    94 
    95 (**** Authenticity properties obtained from NS2 ****)
    96 
    97 (*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
    98   is secret.  (Honest users generate fresh nonces.)*)
    99 goal thy 
   100  "!!evs. [| Nonce NA ~: analz (sees lost Spy evs);  \
   101 \           Crypt (pubK B) {|Nonce NA, Agent A|} : parts (sees lost Spy evs); \
   102 \           evs : ns_public |]                      \
   103 \ ==> Crypt (pubK C) {|NA', Nonce NA|} ~: parts (sees lost Spy evs)";
   104 by (etac rev_mp 1);
   105 by (etac rev_mp 1);
   106 by (analz_induct_tac 1);
   107 (*NS3*)
   108 by (fast_tac (!claset addSEs partsEs) 4);
   109 (*NS2*)
   110 by (fast_tac (!claset addSEs partsEs) 3);
   111 (*Fake*)
   112 by (deepen_tac (!claset addSIs [analz_insertI]
   113                         addDs [impOfSubs analz_subset_parts,
   114 			       impOfSubs Fake_parts_insert]
   115 			addss (!simpset)) 0 2);
   116 (*Base*)
   117 by (fast_tac (!claset addss (!simpset)) 1);
   118 qed "no_nonce_NS1_NS2";
   119 
   120 
   121 (*Unicity for NS1: nonce NA identifies agents A and B*)
   122 goal thy 
   123  "!!evs. [| Nonce NA ~: analz (sees lost Spy evs);  evs : ns_public |]      \
   124 \ ==> EX A' B'. ALL A B.                                                    \
   125 \      Crypt (pubK B) {|Nonce NA, Agent A|} : parts (sees lost Spy evs) --> \
   126 \      A=A' & B=B'";
   127 by (etac rev_mp 1);
   128 by (analz_induct_tac 1);
   129 (*NS1*)
   130 by (simp_tac (!simpset addsimps [all_conj_distrib]) 3);
   131 by (expand_case_tac "NA = ?y" 3 THEN
   132     REPEAT (fast_tac (!claset addSEs partsEs) 3));
   133 (*Base*)
   134 by (fast_tac (!claset addss (!simpset)) 1);
   135 (*Fake*)
   136 by (simp_tac (!simpset addsimps [all_conj_distrib, parts_insert_sees]) 1);
   137 by (step_tac (!claset addSIs [analz_insertI]) 1);
   138 by (ex_strip_tac 1);
   139 by (best_tac (!claset delrules [conjI]
   140                       addSDs [impOfSubs Fake_parts_insert]
   141                       addDs  [impOfSubs analz_subset_parts]
   142                       addss (!simpset)) 1);
   143 val lemma = result();
   144 
   145 goal thy 
   146  "!!evs. [| Crypt(pubK B)  {|Nonce NA, Agent A|}  : parts(sees lost Spy evs); \
   147 \           Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(sees lost Spy evs); \
   148 \           Nonce NA ~: analz (sees lost Spy evs);                            \
   149 \           evs : ns_public |]                                                \
   150 \        ==> A=A' & B=B'";
   151 by (prove_unique_tac lemma 1);
   152 qed "unique_NA";
   153 
   154 
   155 (*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure*)
   156 goal thy 
   157  "!!evs. [| Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set_of_list evs; \
   158 \           A ~: lost;  B ~: lost;  evs : ns_public |]                        \
   159 \        ==>  Nonce NA ~: analz (sees lost Spy evs)";
   160 by (etac rev_mp 1);
   161 by (analz_induct_tac 1);
   162 (*NS3*)
   163 by (fast_tac (!claset addSDs [Says_imp_sees_Spy' RS parts.Inj]
   164                       addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 4);
   165 (*NS2*)
   166 by (deepen_tac (!claset addSDs [Says_imp_sees_Spy' RS parts.Inj]
   167                         addSEs [MPair_parts]
   168 			addDs  [parts.Body, unique_NA]) 0 3);
   169 (*NS1*)
   170 by (fast_tac (!claset addSEs sees_Spy_partsEs
   171                       addIs  [impOfSubs analz_subset_parts]) 2);
   172 (*Fake*)
   173 by (spy_analz_tac 1);
   174 qed "Spy_not_see_NA";
   175 
   176 
   177 (*Authentication for A: if she receives message 2 and has used NA
   178   to start a run, then B has sent message 2.*)
   179 goal thy 
   180  "!!evs. [| Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set_of_list evs;\
   181 \           Says B' A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set_of_list evs;\
   182 \           A ~: lost;  B ~: lost;  evs : ns_public |]  \
   183 \        ==> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set_of_list evs";
   184 by (etac rev_mp 1);
   185 (*prepare induction over Crypt (pubK A) {|NA,NB|} : parts H*)
   186 by (etac (Says_imp_sees_Spy' RS parts.Inj RS rev_mp) 1);
   187 by (etac ns_public.induct 1);
   188 by (ALLGOALS Asm_simp_tac);
   189 (*NS1*)
   190 by (fast_tac (!claset addSEs sees_Spy_partsEs) 2);
   191 (*Fake*)
   192 by (REPEAT_FIRST (resolve_tac [impI, conjI]));
   193 by (fast_tac (!claset addss (!simpset)) 1);
   194 by (forward_tac [Spy_not_see_NA] 1 THEN REPEAT (assume_tac 1));
   195 by (best_tac (!claset addSIs [disjI2]
   196                       addSDs [impOfSubs Fake_parts_insert]
   197                       addDs  [impOfSubs analz_subset_parts]
   198                       addss (!simpset)) 1);
   199 (*NS2*)
   200 by (Step_tac 1);
   201 by (forward_tac [Spy_not_see_NA] 1 THEN REPEAT (assume_tac 1));
   202 by (deepen_tac (!claset addSDs [Says_imp_sees_Spy' RS parts.Inj]
   203                         addDs  [unique_NA]) 1 1);
   204 qed "A_trusts_NS2";
   205 
   206 (*If the encrypted message appears then it originated with Alice in NS1*)
   207 goal thy 
   208  "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (sees lost Spy evs); \
   209 \           Nonce NA ~: analz (sees lost Spy evs);                 \
   210 \           evs : ns_public |]                                     \
   211 \   ==> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set_of_list evs";
   212 by (etac rev_mp 1);
   213 by (etac rev_mp 1);
   214 by (analz_induct_tac 1);
   215 (*Fake*)
   216 by (best_tac (!claset addSIs [disjI2]
   217                       addSDs [impOfSubs Fake_parts_insert]
   218                       addIs  [analz_insertI]
   219                       addDs  [impOfSubs analz_subset_parts]
   220                       addss (!simpset)) 2);
   221 (*Base*)
   222 by (fast_tac (!claset addss (!simpset)) 1);
   223 qed_spec_mp "B_trusts_NS1";
   224 
   225 
   226 
   227 (**** Authenticity properties obtained from NS2 ****)
   228 
   229 (*Unicity for NS2: nonce NB identifies agent A and nonce NA
   230   [proof closely follows that for unique_NA] *)
   231 goal thy 
   232  "!!evs. [| Nonce NB ~: analz (sees lost Spy evs);  evs : ns_public |]      \
   233 \ ==> EX A' NA'. ALL A NA.                                                  \
   234 \      Crypt (pubK A) {|Nonce NA, Nonce NB|}                                \
   235 \        : parts (sees lost Spy evs)  -->  A=A' & NA=NA'";
   236 by (etac rev_mp 1);
   237 by (analz_induct_tac 1);
   238 (*NS2*)
   239 by (simp_tac (!simpset addsimps [all_conj_distrib]) 3);
   240 by (expand_case_tac "NB = ?y" 3 THEN
   241     REPEAT (fast_tac (!claset addSEs partsEs) 3));
   242 (*Base*)
   243 by (fast_tac (!claset addss (!simpset)) 1);
   244 (*Fake*)
   245 by (simp_tac (!simpset addsimps [all_conj_distrib, parts_insert_sees]) 1);
   246 by (step_tac (!claset addSIs [analz_insertI]) 1);
   247 by (ex_strip_tac 1);
   248 by (best_tac (!claset delrules [conjI]
   249                       addSDs [impOfSubs Fake_parts_insert]
   250                       addDs  [impOfSubs analz_subset_parts] 
   251                       addss (!simpset)) 1);
   252 val lemma = result();
   253 
   254 goal thy 
   255  "!!evs. [| Crypt(pubK A) {|Nonce NA, Nonce NB|}  : parts(sees lost Spy evs); \
   256 \           Crypt(pubK A'){|Nonce NA', Nonce NB|} : parts(sees lost Spy evs); \
   257 \           Nonce NB ~: analz (sees lost Spy evs);                            \
   258 \           evs : ns_public |]                                                \
   259 \        ==> A=A' & NA=NA'";
   260 by (prove_unique_tac lemma 1);
   261 qed "unique_NB";
   262 
   263 
   264 (*NB remains secret PROVIDED Alice never responds with round 3*)
   265 goal thy 
   266  "!!evs.[| Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set_of_list evs;\
   267 \          (ALL C. Says A C (Crypt (pubK C) (Nonce NB)) ~: set_of_list evs);  \
   268 \          A ~: lost;  B ~: lost;  evs : ns_public |]   \
   269 \       ==> Nonce NB ~: analz (sees lost Spy evs)";
   270 by (etac rev_mp 1);
   271 by (etac rev_mp 1);
   272 by (analz_induct_tac 1);
   273 (*NS1*)
   274 by (fast_tac (!claset addSEs sees_Spy_partsEs) 2);
   275 (*Fake*)
   276 by (spy_analz_tac 1);
   277 (*NS2 and NS3*)
   278 by (ALLGOALS (asm_simp_tac (!simpset addsimps [all_conj_distrib])));
   279 by (step_tac (!claset delrules [allI]) 1);
   280 by (Fast_tac 5);
   281 by (fast_tac (!claset addSIs [impOfSubs analz_subset_parts]) 1);
   282 (*NS2*)
   283 by (fast_tac (!claset addSEs sees_Spy_partsEs) 2);
   284 by (fast_tac (!claset addSDs [Says_imp_sees_Spy' RS parts.Inj]
   285                       addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 1);
   286 (*NS3*)
   287 by (forw_inst_tac [("A'","A")] (Says_imp_sees_Spy' RS parts.Inj RS unique_NB) 1
   288     THEN REPEAT (eresolve_tac [asm_rl, Says_imp_sees_Spy' RS parts.Inj] 1));
   289 by (Fast_tac 1);
   290 qed "Spy_not_see_NB";
   291 
   292 
   293 
   294 (*Authentication for B: if he receives message 3 and has used NB
   295   in message 2, then A has sent message 3--to somebody....*)
   296 goal thy 
   297  "!!evs. [| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB|})          \
   298 \             : set_of_list evs;                                       \
   299 \           Says A' B (Crypt (pubK B) (Nonce NB)): set_of_list evs;    \
   300 \           A ~: lost;  B ~: lost;  evs : ns_public |]                 \
   301 \        ==> EX C. Says A C (Crypt (pubK C) (Nonce NB)) : set_of_list evs";
   302 by (etac rev_mp 1);
   303 (*prepare induction over Crypt (pubK B) NB : parts H*)
   304 by (etac (Says_imp_sees_Spy' RS parts.Inj RS rev_mp) 1);
   305 by (analz_induct_tac 1);
   306 by (ALLGOALS (asm_simp_tac (!simpset addsimps [ex_disj_distrib])));
   307 (*NS1*)
   308 by (fast_tac (!claset addSEs sees_Spy_partsEs) 2);
   309 (*Fake*)
   310 by (REPEAT_FIRST (resolve_tac [impI, conjI]));
   311 by (fast_tac (!claset addss (!simpset)) 1);
   312 by (rtac (ccontr RS disjI2) 1);
   313 by (forward_tac [Spy_not_see_NB] 1 THEN (REPEAT_FIRST assume_tac)
   314     THEN Fast_tac 1);
   315 by (best_tac (!claset addSDs [impOfSubs Fake_parts_insert]
   316                       addDs  [impOfSubs analz_subset_parts] 
   317                       addss (!simpset)) 1);
   318 (*NS3*)
   319 by (Step_tac 1);
   320 by (forward_tac [Spy_not_see_NB] 1 THEN (REPEAT_FIRST assume_tac)
   321     THEN Fast_tac 1);
   322 by (best_tac (!claset addSDs [Says_imp_sees_Spy' RS parts.Inj]
   323                       addDs  [unique_NB]) 1);
   324 qed "B_trusts_NS3";
   325 
   326 
   327 (*Can we strengthen the secrecy theorem?  NO*)
   328 goal thy 
   329  "!!evs. [| A ~: lost;  B ~: lost;  evs : ns_public |]   \
   330 \ ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set_of_list evs \
   331 \     --> Nonce NB ~: analz (sees lost Spy evs)";
   332 by (analz_induct_tac 1);
   333 (*NS1*)
   334 by (fast_tac (!claset addSEs partsEs
   335                       addSDs [Says_imp_sees_Spy' RS parts.Inj]) 2);
   336 (*Fake*)
   337 by (spy_analz_tac 1);
   338 (*NS2 and NS3*)
   339 by (Step_tac 1);
   340 by (fast_tac (!claset addSIs [impOfSubs analz_subset_parts, usedI]) 1);
   341 (*NS2*)
   342 by (fast_tac (!claset addSEs partsEs
   343                       addSDs [Says_imp_sees_Spy' RS parts.Inj]) 2);
   344 by (fast_tac (!claset addSDs [Says_imp_sees_Spy' RS parts.Inj]
   345                       addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 1);
   346 (*NS3*)
   347 by (forw_inst_tac [("A'","A")] (Says_imp_sees_Spy' RS parts.Inj RS unique_NB) 1
   348     THEN REPEAT (eresolve_tac [asm_rl, Says_imp_sees_Spy' RS parts.Inj] 1));
   349 by (Step_tac 1);
   350 
   351 (*
   352 THIS IS THE ATTACK!
   353 Level 9
   354 !!evs. [| A ~: lost; B ~: lost; evs : ns_public |]
   355        ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|})
   356            : set_of_list evs -->
   357            Nonce NB ~: analz (sees lost Spy evs)
   358  1. !!evs Aa Ba B' NAa NBa evsa.
   359        [| A ~: lost; B ~: lost; evsa : ns_public; A ~= Ba;
   360           Says B' A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set_of_list evsa;
   361           Says A Ba (Crypt (pubK Ba) {|Nonce NA, Agent A|}) : set_of_list evsa;
   362           Ba : lost;
   363           Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set_of_list evsa;
   364           Nonce NB ~: analz (sees lost Spy evsa) |]
   365        ==> False
   366 *)
   367 
   368 
   369