src/HOL/Auth/NS_Public_Bad.ML
author paulson
Tue Dec 23 11:56:09 1997 +0100 (1997-12-23)
changeset 4476 fbdc87f8ac7e
parent 4449 df30e75f670f
child 4477 b3e5857d8d99
permissions -rw-r--r--
Tidied using rev_iffD1
     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 set proof_timing;
    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 AddSDs [Spy_see_priK RSN (2, rev_iffD1), 
    71 	Spy_analz_priK RSN (2, rev_iffD1)];
    72 
    73 
    74 (**** Authenticity properties obtained from NS2 ****)
    75 
    76 (*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
    77   is secret.  (Honest users generate fresh nonces.)*)
    78 goal thy 
    79  "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs); \
    80 \           Nonce NA ~: analz (spies evs);   evs : ns_public |]       \
    81 \ ==> Crypt (pubK C) {|NA', Nonce NA|} ~: parts (spies evs)";
    82 by (etac rev_mp 1);
    83 by (etac rev_mp 1);
    84 by (parts_induct_tac 1);
    85 (*NS3*)
    86 by (blast_tac (claset() addSEs partsEs) 3);
    87 (*NS2*)
    88 by (blast_tac (claset() addSEs partsEs) 2);
    89 by (Fake_parts_insert_tac 1);
    90 qed "no_nonce_NS1_NS2";
    91 
    92 
    93 (*Unicity for NS1: nonce NA identifies agents A and B*)
    94 goal thy 
    95  "!!evs. [| Nonce NA ~: analz (spies evs);  evs : ns_public |]      \
    96 \ ==> EX A' B'. ALL A B.                                            \
    97 \      Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs) --> \
    98 \      A=A' & B=B'";
    99 by (etac rev_mp 1);
   100 by (parts_induct_tac 1);
   101 by (ALLGOALS
   102     (asm_simp_tac (simpset() addsimps [all_conj_distrib, 
   103 				       parts_insert_spies])));
   104 (*NS1*)
   105 by (expand_case_tac "NA = ?y" 2 THEN blast_tac (claset() addSEs partsEs) 2);
   106 (*Fake*)
   107 by (Clarify_tac 1);
   108 by (ex_strip_tac 1);
   109 by (Fake_parts_insert_tac 1);
   110 val lemma = result();
   111 
   112 goal thy 
   113  "!!evs. [| Crypt(pubK B)  {|Nonce NA, Agent A|}  : parts(spies evs); \
   114 \           Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(spies evs); \
   115 \           Nonce NA ~: analz (spies evs);                            \
   116 \           evs : ns_public |]                                        \
   117 \        ==> A=A' & B=B'";
   118 by (prove_unique_tac lemma 1);
   119 qed "unique_NA";
   120 
   121 
   122 (*Tactic for proving secrecy theorems*)
   123 fun analz_induct_tac i = 
   124     etac ns_public.induct i   THEN
   125     ALLGOALS (asm_simp_tac (simpset() addsplits [expand_if]));
   126 
   127 
   128 (*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure*)
   129 goal thy 
   130  "!!evs. [| Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set evs;   \
   131 \           A ~: bad;  B ~: bad;  evs : ns_public |]                    \
   132 \        ==>  Nonce NA ~: analz (spies evs)";
   133 by (etac rev_mp 1);
   134 by (analz_induct_tac 1);
   135 (*NS3*)
   136 by (blast_tac (claset() addDs  [Says_imp_spies RS parts.Inj]
   137                         addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 4);
   138 (*NS2*)
   139 by (blast_tac (claset() addSEs [MPair_parts]
   140 		       addDs  [Says_imp_spies RS parts.Inj,
   141 			       parts.Body, unique_NA]) 3);
   142 (*NS1*)
   143 by (blast_tac (claset() addSEs spies_partsEs
   144                        addIs  [impOfSubs analz_subset_parts]) 2);
   145 (*Fake*)
   146 by (spy_analz_tac 1);
   147 qed "Spy_not_see_NA";
   148 
   149 
   150 (*Authentication for A: if she receives message 2 and has used NA
   151   to start a run, then B has sent message 2.*)
   152 goal thy 
   153  "!!evs. [| Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs;  \
   154 \           Says B' A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs;  \
   155 \           A ~: bad;  B ~: bad;  evs : ns_public |]                    \
   156 \        ==> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs";
   157 by (etac rev_mp 1);
   158 (*prepare induction over Crypt (pubK A) {|NA,NB|} : parts H*)
   159 by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
   160 by (etac ns_public.induct 1);
   161 by (ALLGOALS Asm_simp_tac);
   162 by (ALLGOALS Clarify_tac);
   163 (*NS2*)
   164 by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj,
   165 			      Spy_not_see_NA, unique_NA]) 3);
   166 (*NS1*)
   167 by (blast_tac (claset() addSEs spies_partsEs) 2);
   168 (*Fake*)
   169 by (blast_tac (claset() addSDs [impOfSubs Fake_parts_insert]
   170                        addDs  [Spy_not_see_NA, 
   171 			       impOfSubs analz_subset_parts]) 1);
   172 qed "A_trusts_NS2";
   173 
   174 (*If the encrypted message appears then it originated with Alice in NS1*)
   175 goal thy 
   176  "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs); \
   177 \           Nonce NA ~: analz (spies evs);                            \
   178 \           evs : ns_public |]                                        \
   179 \   ==> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs";
   180 by (etac rev_mp 1);
   181 by (etac rev_mp 1);
   182 by (parts_induct_tac 1);
   183 by (Fake_parts_insert_tac 1);
   184 qed "B_trusts_NS1";
   185 
   186 
   187 
   188 (**** Authenticity properties obtained from NS2 ****)
   189 
   190 (*Unicity for NS2: nonce NB identifies agent A and nonce NA
   191   [proof closely follows that for unique_NA] *)
   192 goal thy 
   193  "!!evs. [| Nonce NB ~: analz (spies evs);  evs : ns_public |]  \
   194 \ ==> EX A' NA'. ALL A NA.                                      \
   195 \      Crypt (pubK A) {|Nonce NA, Nonce NB|}                    \
   196 \        : parts (spies evs)  -->  A=A' & NA=NA'";
   197 by (etac rev_mp 1);
   198 by (parts_induct_tac 1);
   199 by (ALLGOALS
   200     (asm_simp_tac (simpset() addsimps [all_conj_distrib, parts_insert_spies])));
   201 (*NS2*)
   202 by (expand_case_tac "NB = ?y" 2 THEN blast_tac (claset() addSEs partsEs) 2);
   203 (*Fake*)
   204 by (Clarify_tac 1);
   205 by (ex_strip_tac 1);
   206 by (Fake_parts_insert_tac 1);
   207 val lemma = result();
   208 
   209 goal thy 
   210  "!!evs. [| Crypt(pubK A) {|Nonce NA, Nonce NB|}  : parts(spies evs); \
   211 \           Crypt(pubK A'){|Nonce NA', Nonce NB|} : parts(spies evs); \
   212 \           Nonce NB ~: analz (spies evs);                            \
   213 \           evs : ns_public |]                                        \
   214 \        ==> A=A' & NA=NA'";
   215 by (prove_unique_tac lemma 1);
   216 qed "unique_NB";
   217 
   218 
   219 (*NB remains secret PROVIDED Alice never responds with round 3*)
   220 goal thy 
   221  "!!evs.[| Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs;  \
   222 \          ALL C. Says A C (Crypt (pubK C) (Nonce NB)) ~: set evs;      \
   223 \          A ~: bad;  B ~: bad;  evs : ns_public |]                     \
   224 \       ==> Nonce NB ~: analz (spies evs)";
   225 by (etac rev_mp 1);
   226 by (etac rev_mp 1);
   227 by (analz_induct_tac 1);
   228 by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
   229 by (ALLGOALS Clarify_tac);
   230 (*NS3: because NB determines A*)
   231 by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj, unique_NB]) 4);
   232 (*NS2: by freshness and unicity of NB*)
   233 by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj]
   234                        addEs [no_nonce_NS1_NS2 RSN (2, rev_notE)]
   235                        addEs partsEs
   236 		       addIs [impOfSubs analz_subset_parts]) 3);
   237 (*NS1: by freshness*)
   238 by (blast_tac (claset() addSEs spies_partsEs) 2);
   239 (*Fake*)
   240 by (spy_analz_tac 1);
   241 qed "Spy_not_see_NB";
   242 
   243 
   244 
   245 (*Authentication for B: if he receives message 3 and has used NB
   246   in message 2, then A has sent message 3--to somebody....*)
   247 goal thy 
   248  "!!evs. [| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs; \
   249 \           Says A' B (Crypt (pubK B) (Nonce NB)): set evs;              \
   250 \           A ~: bad;  B ~: bad;  evs : ns_public |]                   \
   251 \        ==> EX C. Says A C (Crypt (pubK C) (Nonce NB)) : set evs";
   252 by (etac rev_mp 1);
   253 (*prepare induction over Crypt (pubK B) NB : parts H*)
   254 by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
   255 by (parts_induct_tac 1);
   256 by (ALLGOALS (asm_simp_tac (simpset() addsimps [ex_disj_distrib])));
   257 by (ALLGOALS Clarify_tac);
   258 (*NS3: because NB determines A (this use of unique_NB is more robust) *)
   259 by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj, Spy_not_see_NB]
   260 			addIs [unique_NB RS conjunct1]) 3);
   261 (*NS1: by freshness*)
   262 by (blast_tac (claset() addSEs spies_partsEs) 2);
   263 (*Fake*)
   264 by (blast_tac (claset() addSDs [impOfSubs Fake_parts_insert]
   265                        addDs  [Spy_not_see_NB, 
   266 			       impOfSubs analz_subset_parts]) 1);
   267 qed "B_trusts_NS3";
   268 
   269 
   270 (*Can we strengthen the secrecy theorem?  NO*)
   271 goal thy 
   272  "!!evs. [| A ~: bad;  B ~: bad;  evs : ns_public |]           \
   273 \ ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs \
   274 \     --> Nonce NB ~: analz (spies evs)";
   275 by (analz_induct_tac 1);
   276 by (ALLGOALS Clarify_tac);
   277 (*NS2: by freshness and unicity of NB*)
   278 by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj]
   279                        addEs [no_nonce_NS1_NS2 RSN (2, rev_notE)]
   280                        addEs partsEs
   281 		       addIs [impOfSubs analz_subset_parts]) 3);
   282 (*NS1: by freshness*)
   283 by (blast_tac (claset() addSEs spies_partsEs) 2);
   284 (*Fake*)
   285 by (spy_analz_tac 1);
   286 (*NS3: unicity of NB identifies A and NA, but not B*)
   287 by (forw_inst_tac [("A'","A")] (Says_imp_spies RS parts.Inj RS unique_NB) 1
   288     THEN REPEAT (eresolve_tac [asm_rl, Says_imp_spies RS parts.Inj] 1));
   289 by (Auto_tac());
   290 by (rename_tac "C B' evs3" 1);
   291 
   292 (*
   293 THIS IS THE ATTACK!
   294 Level 8
   295 !!evs. [| A ~: bad; B ~: bad; evs : ns_public |]
   296        ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs -->
   297            Nonce NB ~: analz (spies evs)
   298  1. !!C B' evs3.
   299        [| A ~: bad; B ~: bad; evs3 : ns_public;
   300           Says A C (Crypt (pubK C) {|Nonce NA, Agent A|}) : set evs3;
   301           Says B' A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs3; C : bad;
   302           Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs3;
   303           Nonce NB ~: analz (spies evs3) |]
   304        ==> False
   305 *)