src/HOL/Auth/NS_Public_Bad.ML
author paulson
Thu Sep 23 13:06:31 1999 +0200 (1999-09-23)
changeset 7584 5be4bb8e4e3f
parent 5434 9b4bed3f394c
child 8054 2ce57ef2a4aa
permissions -rw-r--r--
tidied; added lemma restrict_to_left
     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 AddEs spies_partsEs;
    15 AddDs [impOfSubs analz_subset_parts];
    16 AddDs [impOfSubs Fake_parts_insert];
    17 
    18 AddIffs [Spy_in_bad];
    19 
    20 (*A "possibility property": there are traces that reach the end*)
    21 Goal
    22   "EX NB. EX evs: ns_public. Says A B (Crypt (pubK B) (Nonce NB)) : set evs";
    23 by (REPEAT (resolve_tac [exI,bexI] 1));
    24 by (rtac (ns_public.Nil RS ns_public.NS1 RS ns_public.NS2 RS ns_public.NS3) 2);
    25 by possibility_tac;
    26 result();
    27 
    28 
    29 (**** Inductive proofs about ns_public ****)
    30 
    31 (*Induction for regularity theorems.  If induction formula has the form
    32    X ~: analz (spies evs) --> ... then it shortens the proof by discarding
    33    needless information about analz (insert X (spies evs))  *)
    34 fun parts_induct_tac i = 
    35     etac ns_public.induct i
    36     THEN 
    37     REPEAT (FIRSTGOAL analz_mono_contra_tac)
    38     THEN 
    39     prove_simple_subgoals_tac i;
    40 
    41 
    42 (** Theorems of the form X ~: parts (spies evs) imply that NOBODY
    43     sends messages containing X! **)
    44 
    45 (*Spy never sees another agent's private key! (unless it's bad at start)*)
    46 Goal "evs: ns_public ==> (Key (priK A) : parts (spies evs)) = (A : bad)";
    47 by (parts_induct_tac 1);
    48 by (Blast_tac 1);
    49 qed "Spy_see_priK";
    50 Addsimps [Spy_see_priK];
    51 
    52 Goal "evs: ns_public ==> (Key (priK A) : analz (spies evs)) = (A : bad)";
    53 by Auto_tac;
    54 qed "Spy_analz_priK";
    55 Addsimps [Spy_analz_priK];
    56 
    57 AddSDs [Spy_see_priK RSN (2, rev_iffD1), 
    58 	Spy_analz_priK RSN (2, rev_iffD1)];
    59 
    60 
    61 (**** Authenticity properties obtained from NS2 ****)
    62 
    63 (*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
    64   is secret.  (Honest users generate fresh nonces.)*)
    65 Goal "[| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs); \
    66 \        Nonce NA ~: analz (spies evs);   evs : ns_public |]       \
    67 \ ==> Crypt (pubK C) {|NA', Nonce NA|} ~: parts (spies evs)";
    68 by (etac rev_mp 1);
    69 by (etac rev_mp 1);
    70 by (parts_induct_tac 1);
    71 by (ALLGOALS Blast_tac);
    72 qed "no_nonce_NS1_NS2";
    73 
    74 (*Adding it to the claset slows down proofs...*)
    75 val nonce_NS1_NS2_E = no_nonce_NS1_NS2 RSN (2, rev_notE);
    76 
    77 
    78 (*Unicity for NS1: nonce NA identifies agents A and B*)
    79 Goal "[| Nonce NA ~: analz (spies evs);  evs : ns_public |]      \
    80 \ ==> EX A' B'. ALL A B.                                            \
    81 \   Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs) --> \
    82 \   A=A' & B=B'";
    83 by (etac rev_mp 1);
    84 by (parts_induct_tac 1);
    85 by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
    86 (*NS1*)
    87 by (expand_case_tac "NA = ?y" 2 THEN Blast_tac 2);
    88 (*Fake*)
    89 by (Clarify_tac 1);
    90 by (Blast_tac 1);
    91 val lemma = result();
    92 
    93 Goal "[| Crypt(pubK B)  {|Nonce NA, Agent A|}  : parts(spies evs); \
    94 \        Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(spies evs); \
    95 \        Nonce NA ~: analz (spies evs);                            \
    96 \        evs : ns_public |]                                        \
    97 \     ==> A=A' & B=B'";
    98 by (prove_unique_tac lemma 1);
    99 qed "unique_NA";
   100 
   101 
   102 (*Tactic for proving secrecy theorems*)
   103 fun analz_induct_tac i = 
   104     etac ns_public.induct i   THEN
   105     ALLGOALS Asm_simp_tac;
   106 
   107 
   108 (*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure*)
   109 Goal "[| Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set evs;   \
   110 \        A ~: bad;  B ~: bad;  evs : ns_public |]                    \
   111 \     ==>  Nonce NA ~: analz (spies evs)";
   112 by (etac rev_mp 1);
   113 by (analz_induct_tac 1);
   114 (*NS3*)
   115 by (blast_tac (claset() addEs [nonce_NS1_NS2_E]) 4);
   116 (*NS2*)
   117 by (blast_tac (claset() addDs [unique_NA]) 3);
   118 (*NS1*)
   119 by (Blast_tac 2);
   120 (*Fake*)
   121 by (spy_analz_tac 1);
   122 qed "Spy_not_see_NA";
   123 
   124 
   125 (*Authentication for A: if she receives message 2 and has used NA
   126   to start a run, then B has sent message 2.*)
   127 Goal "[| Says A  B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set evs;  \
   128 \        Says B' A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs;  \
   129 \        A ~: bad;  B ~: bad;  evs : ns_public |]                    \
   130 \     ==> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB|}): set evs";
   131 by (etac rev_mp 1);
   132 (*prepare induction over Crypt (pubK A) {|NA,NB|} : parts H*)
   133 by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
   134 by (etac ns_public.induct 1);
   135 by (ALLGOALS Asm_simp_tac);
   136 by (ALLGOALS Clarify_tac);
   137 (*NS2*)
   138 by (blast_tac (claset() addDs [Spy_not_see_NA, unique_NA]) 3);
   139 (*NS1*)
   140 by (Blast_tac 2);
   141 (*Fake*)
   142 by (blast_tac (claset() addDs [Spy_not_see_NA]) 1);
   143 qed "A_trusts_NS2";
   144 
   145 
   146 (*If the encrypted message appears then it originated with Alice in NS1*)
   147 Goal "[| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs); \
   148 \        Nonce NA ~: analz (spies evs);                            \
   149 \        evs : ns_public |]                                        \
   150 \==> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs";
   151 by (etac rev_mp 1);
   152 by (etac rev_mp 1);
   153 by (parts_induct_tac 1);
   154 by (Blast_tac 1);
   155 qed "B_trusts_NS1";
   156 
   157 
   158 
   159 (**** Authenticity properties obtained from NS2 ****)
   160 
   161 (*Unicity for NS2: nonce NB identifies nonce NA and agent A
   162   [proof closely follows that for unique_NA] *)
   163 Goal "[| Nonce NB ~: analz (spies evs);  evs : ns_public |]            \
   164 \ ==> EX A' NA'. ALL A NA.                                                \
   165 \   Crypt (pubK A) {|Nonce NA, Nonce NB|} : parts (spies evs)          \
   166 \      -->  A=A' & NA=NA'";
   167 by (etac rev_mp 1);
   168 by (parts_induct_tac 1);
   169 by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
   170 (*NS2*)
   171 by (expand_case_tac "NB = ?y" 2 THEN Blast_tac 2);
   172 (*Fake*)
   173 by (Blast_tac 1);
   174 val lemma = result();
   175 
   176 Goal "[| Crypt(pubK A) {|Nonce NA, Nonce NB|}  : parts(spies evs); \
   177 \        Crypt(pubK A'){|Nonce NA', Nonce NB|} : parts(spies evs); \
   178 \        Nonce NB ~: analz (spies evs);                            \
   179 \        evs : ns_public |]                                        \
   180 \     ==> A=A' & NA=NA'";
   181 by (prove_unique_tac lemma 1);
   182 qed "unique_NB";
   183 
   184 
   185 (*NB remains secret PROVIDED Alice never responds with round 3*)
   186 Goal "[| Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs;  \
   187 \       ALL C. Says A C (Crypt (pubK C) (Nonce NB)) ~: set evs;      \
   188 \       A ~: bad;  B ~: bad;  evs : ns_public |]                     \
   189 \    ==> Nonce NB ~: analz (spies evs)";
   190 by (etac rev_mp 1);
   191 by (etac rev_mp 1);
   192 by (analz_induct_tac 1);
   193 by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
   194 by (ALLGOALS Clarify_tac);
   195 (*NS3: because NB determines A*)
   196 by (blast_tac (claset() addDs [unique_NB]) 4);
   197 (*NS2: by freshness and unicity of NB*)
   198 by (blast_tac (claset() addEs [nonce_NS1_NS2_E]) 3);
   199 (*NS1: by freshness*)
   200 by (Blast_tac 2);
   201 (*Fake*)
   202 by (spy_analz_tac 1);
   203 qed "Spy_not_see_NB";
   204 
   205 
   206 
   207 (*Authentication for B: if he receives message 3 and has used NB
   208   in message 2, then A has sent message 3--to somebody....*)
   209 Goal "[| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs; \
   210 \        Says A' B (Crypt (pubK B) (Nonce NB)): set evs;              \
   211 \        A ~: bad;  B ~: bad;  evs : ns_public |]                   \
   212 \     ==> EX C. Says A C (Crypt (pubK C) (Nonce NB)) : set evs";
   213 by (etac rev_mp 1);
   214 (*prepare induction over Crypt (pubK B) NB : parts H*)
   215 by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
   216 by (parts_induct_tac 1);
   217 by (ALLGOALS (asm_simp_tac (simpset() addsimps [ex_disj_distrib])));
   218 by (ALLGOALS Clarify_tac);
   219 (*NS3: because NB determines A (this use of unique_NB is more robust) *)
   220 by (blast_tac (claset() addDs [Spy_not_see_NB]
   221 			addIs [unique_NB RS conjunct1]) 3);
   222 (*NS1: by freshness*)
   223 by (Blast_tac 2);
   224 (*Fake*)
   225 by (blast_tac (claset() addDs [Spy_not_see_NB]) 1);
   226 qed "B_trusts_NS3";
   227 
   228 
   229 (*Can we strengthen the secrecy theorem?  NO*)
   230 Goal "[| A ~: bad;  B ~: bad;  evs : ns_public |]           \
   231 \ ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs \
   232 \  --> Nonce NB ~: analz (spies evs)";
   233 by (analz_induct_tac 1);
   234 by (ALLGOALS Clarify_tac);
   235 (*NS2: by freshness and unicity of NB*)
   236 by (blast_tac (claset() addEs [nonce_NS1_NS2_E]) 3);
   237 (*NS1: by freshness*)
   238 by (Blast_tac 2);
   239 (*Fake*)
   240 by (spy_analz_tac 1);
   241 (*NS3: unicity of NB identifies A and NA, but not B*)
   242 by (forw_inst_tac [("A'","A")] (Says_imp_spies RS parts.Inj RS unique_NB) 1
   243     THEN REPEAT (eresolve_tac [asm_rl, Says_imp_spies RS parts.Inj] 1));
   244 by Auto_tac;
   245 by (rename_tac "C B' evs3" 1);
   246 
   247 (*
   248 THIS IS THE ATTACK!
   249 Level 8
   250 !!evs. [| A ~: bad; B ~: bad; evs : ns_public |]
   251        ==> Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs -->
   252            Nonce NB ~: analz (spies evs)
   253  1. !!C B' evs3.
   254        [| A ~: bad; B ~: bad; evs3 : ns_public;
   255           Says A C (Crypt (pubK C) {|Nonce NA, Agent A|}) : set evs3;
   256           Says B' A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs3; C : bad;
   257           Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) : set evs3;
   258           Nonce NB ~: analz (spies evs3) |]
   259        ==> False
   260 *)