src/HOL/Auth/NS_Public.ML
author paulson
Tue Nov 11 11:16:18 1997 +0100 (1997-11-11)
changeset 4198 c63639beeff1
parent 4197 1547bc6daa5a
child 4422 21238c9d363e
permissions -rw-r--r--
Fixed spelling error
     1 (*  Title:      HOL/Auth/NS_Public
     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 Version incorporating Lowe's fix (inclusion of B's identify in round 2).
     8 *)
     9 
    10 open NS_Public;
    11 
    12 proof_timing:=true;
    13 HOL_quantifiers := false;
    14 
    15 AddIffs [Spy_in_bad];
    16 
    17 (*A "possibility property": there are traces that reach the end*)
    18 goal thy 
    19  "!!A B. A ~= B ==> EX NB. EX evs: ns_public.               \
    20 \                     Says A B (Crypt (pubK B) (Nonce NB)) : set evs";
    21 by (REPEAT (resolve_tac [exI,bexI] 1));
    22 by (rtac (ns_public.Nil RS ns_public.NS1 RS ns_public.NS2 RS ns_public.NS3) 2);
    23 by possibility_tac;
    24 result();
    25 
    26 
    27 (**** Inductive proofs about ns_public ****)
    28 
    29 (*Nobody sends themselves messages*)
    30 goal thy "!!evs. evs : ns_public ==> ALL A X. Says A A X ~: set evs";
    31 by (etac ns_public.induct 1);
    32 by (Auto_tac());
    33 qed_spec_mp "not_Says_to_self";
    34 Addsimps [not_Says_to_self];
    35 AddSEs   [not_Says_to_self RSN (2, rev_notE)];
    36 
    37 
    38 (*Induction for regularity theorems.  If induction formula has the form
    39    X ~: analz (spies evs) --> ... then it shortens the proof by discarding
    40    needless information about analz (insert X (spies evs))  *)
    41 fun parts_induct_tac i = 
    42     etac ns_public.induct i
    43     THEN 
    44     REPEAT (FIRSTGOAL analz_mono_contra_tac)
    45     THEN 
    46     prove_simple_subgoals_tac i;
    47 
    48 
    49 (** Theorems of the form X ~: parts (spies evs) imply that NOBODY
    50     sends messages containing X! **)
    51 
    52 (*Spy never sees another agent's private key! (unless it's bad at start)*)
    53 goal thy 
    54  "!!A. evs: ns_public ==> (Key (priK A) : parts (spies evs)) = (A : bad)";
    55 by (parts_induct_tac 1);
    56 by (Fake_parts_insert_tac 1);
    57 qed "Spy_see_priK";
    58 Addsimps [Spy_see_priK];
    59 
    60 goal thy 
    61  "!!A. evs: ns_public ==> (Key (priK A) : analz (spies evs)) = (A : bad)";
    62 by (auto_tac(claset() addDs [impOfSubs analz_subset_parts], simpset()));
    63 qed "Spy_analz_priK";
    64 Addsimps [Spy_analz_priK];
    65 
    66 goal thy  "!!A. [| Key (priK A) : parts (spies evs);       \
    67 \                  evs : ns_public |] ==> A:bad";
    68 by (blast_tac (claset() addDs [Spy_see_priK]) 1);
    69 qed "Spy_see_priK_D";
    70 
    71 bind_thm ("Spy_analz_priK_D", analz_subset_parts RS subsetD RS Spy_see_priK_D);
    72 AddSDs [Spy_see_priK_D, Spy_analz_priK_D];
    73 
    74 
    75 (**** Authenticity properties obtained from NS2 ****)
    76 
    77 (*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
    78   is secret.  (Honest users generate fresh nonces.)*)
    79 goal thy 
    80  "!!evs. [| Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs); \
    81 \           Nonce NA ~: analz (spies evs);       \
    82 \           evs : ns_public |]                      \
    83 \ ==> Crypt (pubK C) {|NA', Nonce NA, Agent D|} ~: parts (spies evs)";
    84 by (etac rev_mp 1);
    85 by (etac rev_mp 1);
    86 by (parts_induct_tac 1);
    87 (*NS3*)
    88 by (blast_tac (claset() addSEs partsEs) 3);
    89 (*NS2*)
    90 by (blast_tac (claset() addSEs partsEs) 2);
    91 by (Fake_parts_insert_tac 1);
    92 qed "no_nonce_NS1_NS2";
    93 
    94 
    95 (*Unicity for NS1: nonce NA identifies agents A and B*)
    96 goal thy 
    97  "!!evs. [| Nonce NA ~: analz (spies evs);  evs : ns_public |]      \
    98 \ ==> EX A' B'. ALL A B.                                            \
    99 \      Crypt (pubK B) {|Nonce NA, Agent A|} : parts (spies evs) --> \
   100 \      A=A' & B=B'";
   101 by (etac rev_mp 1);
   102 by (parts_induct_tac 1);
   103 by (ALLGOALS
   104     (asm_simp_tac (simpset() addsimps [all_conj_distrib, parts_insert_spies])));
   105 (*NS1*)
   106 by (expand_case_tac "NA = ?y" 2 THEN blast_tac (claset() addSEs partsEs) 2);
   107 (*Fake*)
   108 by (Clarify_tac 1);
   109 by (ex_strip_tac 1);
   110 by (Fake_parts_insert_tac 1);
   111 val lemma = result();
   112 
   113 goal thy 
   114  "!!evs. [| Crypt(pubK B)  {|Nonce NA, Agent A|}  : parts(spies evs); \
   115 \           Crypt(pubK B') {|Nonce NA, Agent A'|} : parts(spies evs); \
   116 \           Nonce NA ~: analz (spies evs);                            \
   117 \           evs : ns_public |]                                        \
   118 \        ==> A=A' & B=B'";
   119 by (prove_unique_tac lemma 1);
   120 qed "unique_NA";
   121 
   122 
   123 (*Tactic for proving secrecy theorems*)
   124 fun analz_induct_tac i = 
   125     etac ns_public.induct i   THEN
   126     ALLGOALS (asm_simp_tac 
   127               (simpset() addsplits [expand_if]));
   128 
   129 
   130 (*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure*)
   131 goal thy 
   132  "!!evs. [| Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) : set evs;         \
   133 \           A ~: bad;  B ~: bad;  evs : ns_public |]                        \
   134 \        ==>  Nonce NA ~: analz (spies evs)";
   135 by (etac rev_mp 1);
   136 by (analz_induct_tac 1);
   137 (*NS3*)
   138 by (blast_tac (claset() addDs  [Says_imp_spies RS parts.Inj]
   139                        addEs  [no_nonce_NS1_NS2 RSN (2, rev_notE)]) 4);
   140 (*NS2*)
   141 by (blast_tac (claset() addSEs [MPair_parts]
   142 		       addDs  [Says_imp_spies RS parts.Inj,
   143 			       parts.Body, unique_NA]) 3);
   144 (*NS1*)
   145 by (blast_tac (claset() addSEs spies_partsEs
   146                        addIs  [impOfSubs analz_subset_parts]) 2);
   147 (*Fake*)
   148 by (spy_analz_tac 1);
   149 qed "Spy_not_see_NA";
   150 
   151 
   152 (*Authentication for A: if she receives message 2 and has used NA
   153   to start a run, then B has sent message 2.*)
   154 goal thy 
   155  "!!evs. [| Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs;  \
   156 \           Says B' A (Crypt(pubK A) {|Nonce NA, Nonce NB, Agent B|})   \
   157 \             : set evs;                                                \
   158 \           A ~: bad;  B ~: bad;  evs : ns_public |]                  \
   159 \        ==> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB, Agent B|})   \
   160 \              : set evs";
   161 by (etac rev_mp 1);
   162 (*prepare induction over Crypt (pubK A) {|NA,NB,B|} : 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 (*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 nonce NA and agents A, B 
   191   [unicity of B makes Lowe's fix work]
   192   [proof closely follows that for unique_NA] *)
   193 goal thy 
   194  "!!evs. [| Nonce NB ~: analz (spies evs);  evs : ns_public |]            \
   195 \ ==> EX A' NA' B'. ALL A NA B.                                           \
   196 \      Crypt (pubK A) {|Nonce NA, Nonce NB, Agent B|} : parts (spies evs) \
   197 \         -->  A=A' & NA=NA' & B=B'";
   198 by (etac rev_mp 1);
   199 by (parts_induct_tac 1);
   200 by (ALLGOALS
   201     (asm_simp_tac (simpset() addsimps [all_conj_distrib, parts_insert_spies])));
   202 (*NS2*)
   203 by (expand_case_tac "NB = ?y" 2 THEN blast_tac (claset() addSEs partsEs) 2);
   204 (*Fake*)
   205 by (Clarify_tac 1);
   206 by (ex_strip_tac 1);
   207 by (Fake_parts_insert_tac 1);
   208 val lemma = result();
   209 
   210 goal thy 
   211  "!!evs. [| Crypt(pubK A)  {|Nonce NA, Nonce NB, Agent B|}   \
   212 \             : parts(spies evs);                            \
   213 \           Crypt(pubK A') {|Nonce NA', Nonce NB, Agent B'|} \
   214 \             : parts(spies evs);                            \
   215 \           Nonce NB ~: analz (spies evs);                   \
   216 \           evs : ns_public |]                               \
   217 \        ==> A=A' & NA=NA' & B=B'";
   218 by (prove_unique_tac lemma 1);
   219 qed "unique_NB";
   220 
   221 
   222 (*Secrecy: Spy does not see the nonce sent in msg NS2 if A and B are secure*)
   223 goal thy 
   224  "!!evs. [| Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB, Agent B|}) \
   225 \             : set evs;                                              \
   226 \           A ~: bad;  B ~: bad;  evs : ns_public |]                \
   227 \ ==> Nonce NB ~: analz (spies evs)";
   228 by (etac rev_mp 1);
   229 by (analz_induct_tac 1);
   230 (*NS3*)
   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*)
   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 (*Authentication for B: if he receives message 3 and has used NB
   245   in message 2, then A has sent message 3.*)
   246 goal thy 
   247  "!!evs. [| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB, Agent B|}) \
   248 \             : set evs;                                               \
   249 \           Says A' B (Crypt (pubK B) (Nonce NB)): set evs;            \
   250 \           A ~: bad;  B ~: bad;  evs : ns_public |]                   \
   251 \        ==> Says A B (Crypt (pubK B) (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 Clarify_tac);
   257 (*NS3: because NB determines A (this use of unique_NB is more robust) *)
   258 by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj, Spy_not_see_NB]
   259 			addIs [unique_NB RS conjunct1]) 3);
   260 (*NS1: by freshness*)
   261 by (blast_tac (claset() addSEs spies_partsEs) 2);
   262 (*Fake*)
   263 by (blast_tac (claset() addSDs [impOfSubs Fake_parts_insert]
   264                         addDs  [Spy_not_see_NB, 
   265 			        impOfSubs analz_subset_parts]) 1);
   266 qed "B_trusts_NS3";
   267 
   268 
   269 (**** Overall guarantee for B*)
   270 
   271 (*Matches only NS2, not NS1 (or NS3)*)
   272 val Says_imp_spies' = 
   273     read_instantiate [("X","Crypt ?K {|?XX,?YY,?ZZ|}")] Says_imp_spies;
   274 
   275 
   276 (*If B receives NS3 and the nonce NB agrees with the nonce he joined with
   277   NA, then A initiated the run using NA.  SAME proof as B_trusts_NS3!*)
   278 goal thy 
   279  "!!evs. [| Says B A  (Crypt (pubK A) {|Nonce NA, Nonce NB, Agent B|}) \
   280 \             : set evs;                                               \
   281 \           Says A' B (Crypt (pubK B) (Nonce NB)): set evs;            \
   282 \           A ~: bad;  B ~: bad;  evs : ns_public |]                 \
   283 \    ==> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) : set evs";
   284 by (etac rev_mp 1);
   285 (*prepare induction over Crypt (pubK B) {|NB|} : parts H*)
   286 by (etac (Says_imp_spies RS parts.Inj RS rev_mp) 1);
   287 by (etac ns_public.induct 1);
   288 by (ALLGOALS Asm_simp_tac);
   289 by (ALLGOALS Clarify_tac);
   290 (*NS3: because NB determines A and NA*)
   291 by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj, 
   292                                Spy_not_see_NB, unique_NB]) 3);
   293 (*NS1*)
   294 by (blast_tac (claset() addSEs spies_partsEs) 2);
   295 (*Fake*)
   296 by (blast_tac (claset() addSDs [impOfSubs Fake_parts_insert]
   297                         addDs  [Spy_not_see_NB, 
   298 			        impOfSubs analz_subset_parts]) 1);
   299 qed "B_trusts_protocol";
   300