src/HOL/Auth/OtwayRees_AN.ML
author paulson
Tue Dec 16 15:17:26 1997 +0100 (1997-12-16)
changeset 4422 21238c9d363e
parent 4155 53f60f51333c
child 4449 df30e75f670f
permissions -rw-r--r--
Simplified proofs using rewrites for f``A where f is injective
     1 (*  Title:      HOL/Auth/OtwayRees
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1996  University of Cambridge
     5 
     6 Inductive relation "otway" for the Otway-Rees protocol.
     7 
     8 Simplified version with minimal encryption but explicit messages
     9 
    10 From page 11 of
    11   Abadi and Needham.  Prudent Engineering Practice for Cryptographic Protocols.
    12   IEEE Trans. SE 22 (1), 1996
    13 *)
    14 
    15 open OtwayRees_AN;
    16 
    17 proof_timing:=true;
    18 HOL_quantifiers := false;
    19 
    20 
    21 (*A "possibility property": there are traces that reach the end*)
    22 goal thy 
    23  "!!A B. [| A ~= B; A ~= Server; B ~= Server |]                               \
    24 \        ==> EX K. EX NA. EX evs: otway.                                      \
    25 \             Says B A (Crypt (shrK A) {|Nonce NA, Agent A, Agent B, Key K|}) \
    26 \             : set evs";
    27 by (REPEAT (resolve_tac [exI,bexI] 1));
    28 by (rtac (otway.Nil RS otway.OR1 RS otway.OR2 RS otway.OR3 RS otway.OR4) 2);
    29 by possibility_tac;
    30 result();
    31 
    32 
    33 (**** Inductive proofs about otway ****)
    34 
    35 (*Nobody sends themselves messages*)
    36 goal thy "!!evs. evs : otway ==> ALL A X. Says A A X ~: set evs";
    37 by (etac otway.induct 1);
    38 by (Auto_tac());
    39 qed_spec_mp "not_Says_to_self";
    40 Addsimps [not_Says_to_self];
    41 AddSEs   [not_Says_to_self RSN (2, rev_notE)];
    42 
    43 
    44 (** For reasoning about the encrypted portion of messages **)
    45 
    46 goal thy "!!evs. Says S' B {|X, Crypt(shrK B) X'|} : set evs ==> \
    47 \                X : analz (spies evs)";
    48 by (blast_tac (claset() addSDs [Says_imp_spies RS analz.Inj]) 1);
    49 qed "OR4_analz_spies";
    50 
    51 goal thy "!!evs. Says Server B {|X, Crypt K' {|NB, a, Agent B, K|}|} \
    52 \                  : set evs ==> K : parts (spies evs)";
    53 by (blast_tac (claset() addSEs spies_partsEs) 1);
    54 qed "Oops_parts_spies";
    55 
    56 (*OR4_analz_spies lets us treat those cases using the same 
    57   argument as for the Fake case.  This is possible for most, but not all,
    58   proofs, since Fake messages originate from the Spy. *)
    59 
    60 bind_thm ("OR4_parts_spies",
    61           OR4_analz_spies RS (impOfSubs analz_subset_parts));
    62 
    63 (*For proving the easier theorems about X ~: parts (spies evs).*)
    64 fun parts_induct_tac i = 
    65     etac otway.induct i			THEN 
    66     forward_tac [Oops_parts_spies] (i+6) THEN
    67     forward_tac [OR4_parts_spies]  (i+5) THEN
    68     prove_simple_subgoals_tac  i;
    69 
    70 
    71 (** Theorems of the form X ~: parts (spies evs) imply that NOBODY
    72     sends messages containing X! **)
    73 
    74 (*Spy never sees another agent's shared key! (unless it's bad at start)*)
    75 goal thy 
    76  "!!evs. evs : otway ==> (Key (shrK A) : parts (spies evs)) = (A : bad)";
    77 by (parts_induct_tac 1);
    78 by (Fake_parts_insert_tac 1);
    79 by (ALLGOALS Blast_tac);
    80 qed "Spy_see_shrK";
    81 Addsimps [Spy_see_shrK];
    82 
    83 goal thy 
    84  "!!evs. evs : otway ==> (Key (shrK A) : analz (spies evs)) = (A : bad)";
    85 by (auto_tac(claset() addDs [impOfSubs analz_subset_parts], simpset()));
    86 qed "Spy_analz_shrK";
    87 Addsimps [Spy_analz_shrK];
    88 
    89 goal thy  "!!A. [| Key (shrK A) : parts (spies evs); evs : otway |] ==> A:bad";
    90 by (blast_tac (claset() addDs [Spy_see_shrK]) 1);
    91 qed "Spy_see_shrK_D";
    92 
    93 bind_thm ("Spy_analz_shrK_D", analz_subset_parts RS subsetD RS Spy_see_shrK_D);
    94 AddSDs [Spy_see_shrK_D, Spy_analz_shrK_D];
    95 
    96 
    97 (*Nobody can have used non-existent keys!*)
    98 goal thy "!!evs. evs : otway ==>          \
    99 \         Key K ~: used evs --> K ~: keysFor (parts (spies evs))";
   100 by (parts_induct_tac 1);
   101 (*Fake*)
   102 by (best_tac
   103       (claset() addSDs [impOfSubs (parts_insert_subset_Un RS keysFor_mono)]
   104                addIs  [impOfSubs analz_subset_parts]
   105                addDs  [impOfSubs (analz_subset_parts RS keysFor_mono)]
   106                addss  (simpset())) 1);
   107 (*OR3*)
   108 by (Blast_tac 1);
   109 qed_spec_mp "new_keys_not_used";
   110 
   111 bind_thm ("new_keys_not_analzd",
   112           [analz_subset_parts RS keysFor_mono,
   113            new_keys_not_used] MRS contra_subsetD);
   114 
   115 Addsimps [new_keys_not_used, new_keys_not_analzd];
   116 
   117 
   118 
   119 (*** Proofs involving analz ***)
   120 
   121 (*Describes the form of K and NA when the Server sends this message.*)
   122 goal thy 
   123  "!!evs. [| Says Server B                                           \
   124 \              {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},    \
   125 \                Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}   \
   126 \             : set evs;                                            \
   127 \           evs : otway |]                                          \
   128 \        ==> K ~: range shrK & (EX i. NA = Nonce i) & (EX j. NB = Nonce j)";
   129 by (etac rev_mp 1);
   130 by (etac otway.induct 1);
   131 by (ALLGOALS Asm_simp_tac);
   132 by (Blast_tac 1);
   133 qed "Says_Server_message_form";
   134 
   135 
   136 (*For proofs involving analz.*)
   137 val analz_spies_tac = 
   138     dtac OR4_analz_spies 6 THEN
   139     forward_tac [Says_Server_message_form] 7 THEN
   140     assume_tac 7 THEN
   141     REPEAT ((eresolve_tac [exE, conjE] ORELSE' hyp_subst_tac) 7);
   142 
   143 
   144 (****
   145  The following is to prove theorems of the form
   146 
   147   Key K : analz (insert (Key KAB) (spies evs)) ==>
   148   Key K : analz (spies evs)
   149 
   150  A more general formula must be proved inductively.
   151 ****)
   152 
   153 
   154 (** Session keys are not used to encrypt other session keys **)
   155 
   156 (*The equality makes the induction hypothesis easier to apply*)
   157 goal thy  
   158  "!!evs. evs : otway ==>                                    \
   159 \  ALL K KK. KK <= Compl (range shrK) -->                   \
   160 \            (Key K : analz (Key``KK Un (spies evs))) =  \
   161 \            (K : KK | Key K : analz (spies evs))";
   162 by (etac otway.induct 1);
   163 by analz_spies_tac;
   164 by (REPEAT_FIRST (resolve_tac [allI, impI]));
   165 by (REPEAT_FIRST (rtac analz_image_freshK_lemma ));
   166 by (ALLGOALS (asm_simp_tac analz_image_freshK_ss));
   167 (*Fake*) 
   168 by (spy_analz_tac 1);
   169 qed_spec_mp "analz_image_freshK";
   170 
   171 
   172 goal thy
   173  "!!evs. [| evs : otway;  KAB ~: range shrK |] ==>          \
   174 \        Key K : analz (insert (Key KAB) (spies evs)) =  \
   175 \        (K = KAB | Key K : analz (spies evs))";
   176 by (asm_simp_tac (analz_image_freshK_ss addsimps [analz_image_freshK]) 1);
   177 qed "analz_insert_freshK";
   178 
   179 
   180 (*** The Key K uniquely identifies the Server's message. **)
   181 
   182 goal thy 
   183  "!!evs. evs : otway ==>                                            \
   184 \      EX A' B' NA' NB'. ALL A B NA NB.                             \
   185 \       Says Server B                                               \
   186 \         {|Crypt (shrK A) {|NA, Agent A, Agent B, K|},             \
   187 \           Crypt (shrK B) {|NB, Agent A, Agent B, K|}|} : set evs  \
   188 \       --> A=A' & B=B' & NA=NA' & NB=NB'";
   189 by (etac otway.induct 1);
   190 by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
   191 by (ALLGOALS Clarify_tac);
   192 (*Remaining cases: OR3 and OR4*)
   193 by (ex_strip_tac 2);
   194 by (Blast_tac 2);
   195 by (expand_case_tac "K = ?y" 1);
   196 by (REPEAT (ares_tac [refl,exI,impI,conjI] 2));
   197 (*...we assume X is a recent message and handle this case by contradiction*)
   198 by (blast_tac (claset() addSEs spies_partsEs
   199                        delrules[conjI] (*prevent splitup into 4 subgoals*)) 1);
   200 val lemma = result();
   201 
   202 
   203 goal thy 
   204 "!!evs. [| Says Server B                                           \
   205 \            {|Crypt (shrK A) {|NA, Agent A, Agent B, K|},         \
   206 \              Crypt (shrK B) {|NB, Agent A, Agent B, K|}|}        \
   207 \           : set evs;                                             \
   208 \          Says Server B'                                          \
   209 \            {|Crypt (shrK A') {|NA', Agent A', Agent B', K|},     \
   210 \              Crypt (shrK B') {|NB', Agent A', Agent B', K|}|}    \
   211 \           : set evs;                                             \
   212 \          evs : otway |]                                          \
   213 \       ==> A=A' & B=B' & NA=NA' & NB=NB'";
   214 by (prove_unique_tac lemma 1);
   215 qed "unique_session_keys";
   216 
   217 
   218 
   219 (**** Authenticity properties relating to NA ****)
   220 
   221 (*If the encrypted message appears then it originated with the Server!*)
   222 goal thy 
   223  "!!evs. [| A ~: bad;  evs : otway |]                 \
   224 \ ==> Crypt (shrK A) {|NA, Agent A, Agent B, Key K|} : parts (spies evs) \
   225 \     --> (EX NB. Says Server B                                          \
   226 \                  {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},     \
   227 \                    Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}    \
   228 \                  : set evs)";
   229 by (parts_induct_tac 1);
   230 by (Fake_parts_insert_tac 1);
   231 by (ALLGOALS (asm_simp_tac (simpset() addsimps [ex_disj_distrib])));
   232 (*OR3*)
   233 by (Blast_tac 1);
   234 qed_spec_mp "NA_Crypt_imp_Server_msg";
   235 
   236 
   237 (*Corollary: if A receives B's OR4 message then it originated with the Server.
   238   Freshness may be inferred from nonce NA.*)
   239 goal thy 
   240  "!!evs. [| Says B' A (Crypt (shrK A) {|NA, Agent A, Agent B, Key K|})  \
   241 \            : set evs;                                                 \
   242 \           A ~: bad;  evs : otway |]                                  \
   243 \        ==> EX NB. Says Server B                                       \
   244 \                    {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},  \
   245 \                      Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|} \
   246 \                   : set evs";
   247 by (blast_tac (claset() addSIs [NA_Crypt_imp_Server_msg]
   248                       addEs  spies_partsEs) 1);
   249 qed "A_trusts_OR4";
   250 
   251 
   252 (** Crucial secrecy property: Spy does not see the keys sent in msg OR3
   253     Does not in itself guarantee security: an attack could violate 
   254     the premises, e.g. by having A=Spy **)
   255 
   256 goal thy 
   257  "!!evs. [| A ~: bad;  B ~: bad;  evs : otway |]                 \
   258 \        ==> Says Server B                                         \
   259 \             {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},    \
   260 \               Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}   \
   261 \            : set evs -->                                         \
   262 \            Says B Spy {|NA, NB, Key K|} ~: set evs -->           \
   263 \            Key K ~: analz (spies evs)";
   264 by (etac otway.induct 1);
   265 by analz_spies_tac;
   266 by (ALLGOALS
   267     (asm_simp_tac (simpset() addcongs [conj_cong, if_weak_cong] 
   268                             addsimps [analz_insert_eq, analz_insert_freshK]
   269                             addsimps (pushes@expand_ifs))));
   270 (*Oops*)
   271 by (blast_tac (claset() addSDs [unique_session_keys]) 4);
   272 (*OR4*) 
   273 by (Blast_tac 3);
   274 (*OR3*)
   275 by (blast_tac (claset() addSEs spies_partsEs
   276                        addIs [impOfSubs analz_subset_parts]) 2);
   277 (*Fake*) 
   278 by (spy_analz_tac 1);
   279 val lemma = result() RS mp RS mp RSN(2,rev_notE);
   280 
   281 goal thy 
   282  "!!evs. [| Says Server B                                           \
   283 \              {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},    \
   284 \                Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}   \
   285 \             : set evs;                                            \
   286 \           Says B Spy {|NA, NB, Key K|} ~: set evs;                \
   287 \           A ~: bad;  B ~: bad;  evs : otway |]                  \
   288 \        ==> Key K ~: analz (spies evs)";
   289 by (forward_tac [Says_Server_message_form] 1 THEN assume_tac 1);
   290 by (blast_tac (claset() addSEs [lemma]) 1);
   291 qed "Spy_not_see_encrypted_key";
   292 
   293 
   294 (**** Authenticity properties relating to NB ****)
   295 
   296 (*If the encrypted message appears then it originated with the Server!*)
   297 goal thy 
   298  "!!evs. [| B ~: bad;  evs : otway |]                                 \
   299 \    ==> Crypt (shrK B) {|NB, Agent A, Agent B, Key K|} : parts (spies evs) \
   300 \        --> (EX NA. Says Server B                                          \
   301 \                     {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},     \
   302 \                       Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}    \
   303 \                     : set evs)";
   304 by (parts_induct_tac 1);
   305 by (Fake_parts_insert_tac 1);
   306 by (ALLGOALS (asm_simp_tac (simpset() addsimps [ex_disj_distrib])));
   307 (*OR3*)
   308 by (Blast_tac 1);
   309 qed_spec_mp "NB_Crypt_imp_Server_msg";
   310 
   311 
   312 (*Guarantee for B: if it gets a well-formed certificate then the Server
   313   has sent the correct message in round 3.*)
   314 goal thy 
   315  "!!evs. [| B ~: bad;  evs : otway;                                        \
   316 \           Says S' B {|X, Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|} \
   317 \            : set evs |]                                                   \
   318 \        ==> EX NA. Says Server B                                           \
   319 \                     {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},     \
   320 \                       Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}    \
   321 \                     : set evs";
   322 by (blast_tac (claset() addSIs [NB_Crypt_imp_Server_msg]
   323                        addEs  spies_partsEs) 1);
   324 qed "B_trusts_OR3";