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