src/HOL/Auth/OtwayRees_AN.ML
changeset 2090 307ebbbec862
child 2106 1a52e2c5897e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Auth/OtwayRees_AN.ML	Thu Oct 10 18:40:34 1996 +0200
     1.3 @@ -0,0 +1,536 @@
     1.4 +(*  Title:      HOL/Auth/OtwayRees
     1.5 +    ID:         $Id$
     1.6 +    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     1.7 +    Copyright   1996  University of Cambridge
     1.8 +
     1.9 +Inductive relation "otway" for the Otway-Rees protocol.
    1.10 +
    1.11 +Simplified version with minimal encryption but explicit messages
    1.12 +
    1.13 +From page 11 of
    1.14 +  Abadi and Needham.  Prudent Engineering Practice for Cryptographic Protocols.
    1.15 +  IEEE Trans. SE 22 (1), 1996
    1.16 +*)
    1.17 +
    1.18 +open OtwayRees_AN;
    1.19 +
    1.20 +proof_timing:=true;
    1.21 +HOL_quantifiers := false;
    1.22 +
    1.23 +
    1.24 +(*Weak liveness: there are traces that reach the end*)
    1.25 +goal thy 
    1.26 + "!!A B. [| A ~= B; A ~= Server; B ~= Server |]   \
    1.27 +\        ==> EX K. EX NA. EX evs: otway lost.          \
    1.28 +\             Says B A (Crypt {|Nonce NA, Agent A, Agent B, Key K|} (shrK A)) \
    1.29 +\             : set_of_list evs";
    1.30 +by (REPEAT (resolve_tac [exI,bexI] 1));
    1.31 +by (rtac (otway.Nil RS otway.OR1 RS otway.OR2 RS otway.OR3 RS otway.OR4) 2);
    1.32 +by (ALLGOALS (simp_tac (!simpset setsolver safe_solver)));
    1.33 +by (REPEAT_FIRST (resolve_tac [refl, conjI]));
    1.34 +by (REPEAT_FIRST (fast_tac (!claset addss (!simpset setsolver safe_solver))));
    1.35 +result();
    1.36 +
    1.37 +
    1.38 +(**** Inductive proofs about otway ****)
    1.39 +
    1.40 +goal thy "!!evs. lost' <= lost ==> otway lost' <= otway lost";
    1.41 +by (rtac subsetI 1);
    1.42 +by (etac otway.induct 1);
    1.43 +by (REPEAT_FIRST
    1.44 +    (best_tac (!claset addIs (impOfSubs (sees_mono RS analz_mono RS synth_mono)
    1.45 +                              :: otway.intrs))));
    1.46 +qed "otway_mono";
    1.47 +
    1.48 +(*Nobody sends themselves messages*)
    1.49 +goal thy "!!evs. evs : otway lost ==> ALL A X. Says A A X ~: set_of_list evs";
    1.50 +by (etac otway.induct 1);
    1.51 +by (Auto_tac());
    1.52 +qed_spec_mp "not_Says_to_self";
    1.53 +Addsimps [not_Says_to_self];
    1.54 +AddSEs   [not_Says_to_self RSN (2, rev_notE)];
    1.55 +
    1.56 +
    1.57 +(** For reasoning about the encrypted portion of messages **)
    1.58 +
    1.59 +goal thy "!!evs. Says S B {|X, X'|} : set_of_list evs ==> \
    1.60 +\                X : analz (sees lost Spy evs)";
    1.61 +by (fast_tac (!claset addSDs [Says_imp_sees_Spy RS analz.Inj]) 1);
    1.62 +qed "OR4_analz_sees_Spy";
    1.63 +
    1.64 +goal thy "!!evs. Says B' A (Crypt {|N,Agent A,B,K|} K') : set_of_list evs ==> \
    1.65 +\                K : parts (sees lost Spy evs)";
    1.66 +by (fast_tac (!claset addSEs partsEs
    1.67 +                      addSDs [Says_imp_sees_Spy RS parts.Inj]) 1);
    1.68 +qed "Reveal_parts_sees_Spy";
    1.69 +
    1.70 +(*OR2_analz... and OR4_analz... let us treat those cases using the same 
    1.71 +  argument as for the Fake case.  This is possible for most, but not all,
    1.72 +  proofs: Fake does not invent new nonces (as in OR2), and of course Fake
    1.73 +  messages originate from the Spy. *)
    1.74 +
    1.75 +bind_thm ("OR4_parts_sees_Spy",
    1.76 +          OR4_analz_sees_Spy RS (impOfSubs analz_subset_parts));
    1.77 +
    1.78 +(*We instantiate the variable to "lost".  Leaving it as a Var makes proofs
    1.79 +  harder to complete, since simplification does less for us.*)
    1.80 +val parts_Fake_tac = 
    1.81 +    forw_inst_tac [("lost","lost")] OR4_parts_sees_Spy 6 THEN
    1.82 +    forw_inst_tac [("lost","lost")] Reveal_parts_sees_Spy 7;
    1.83 +
    1.84 +(*For proving the easier theorems about X ~: parts (sees lost Spy evs) *)
    1.85 +fun parts_induct_tac i = SELECT_GOAL
    1.86 +    (DETERM (etac otway.induct 1 THEN parts_Fake_tac THEN
    1.87 +	     (*Fake message*)
    1.88 +	     TRY (best_tac (!claset addDs [impOfSubs analz_subset_parts,
    1.89 +					   impOfSubs Fake_parts_insert]
    1.90 +                                    addss (!simpset)) 2)) THEN
    1.91 +     (*Base case*)
    1.92 +     fast_tac (!claset addss (!simpset)) 1 THEN
    1.93 +     ALLGOALS Asm_simp_tac) i;
    1.94 +
    1.95 +(** Theorems of the form X ~: parts (sees lost Spy evs) imply that NOBODY
    1.96 +    sends messages containing X! **)
    1.97 +
    1.98 +(*Spy never sees another agent's shared key! (unless it's lost at start)*)
    1.99 +goal thy 
   1.100 + "!!evs. [| evs : otway lost;  A ~: lost |]    \
   1.101 +\        ==> Key (shrK A) ~: parts (sees lost Spy evs)";
   1.102 +by (parts_induct_tac 1);
   1.103 +by (Auto_tac());
   1.104 +qed "Spy_not_see_shrK";
   1.105 +
   1.106 +bind_thm ("Spy_not_analz_shrK",
   1.107 +          [analz_subset_parts, Spy_not_see_shrK] MRS contra_subsetD);
   1.108 +
   1.109 +Addsimps [Spy_not_see_shrK, Spy_not_analz_shrK];
   1.110 +
   1.111 +(*We go to some trouble to preserve R in the 3rd and 4th subgoals
   1.112 +  As usual fast_tac cannot be used because it uses the equalities too soon*)
   1.113 +val major::prems = 
   1.114 +goal thy  "[| Key (shrK A) : parts (sees lost Spy evs);       \
   1.115 +\             evs : otway lost;                                 \
   1.116 +\             A:lost ==> R                                  \
   1.117 +\           |] ==> R";
   1.118 +by (rtac ccontr 1);
   1.119 +by (rtac ([major, Spy_not_see_shrK] MRS rev_notE) 1);
   1.120 +by (swap_res_tac prems 2);
   1.121 +by (ALLGOALS (fast_tac (!claset addIs prems)));
   1.122 +qed "Spy_see_shrK_E";
   1.123 +
   1.124 +bind_thm ("Spy_analz_shrK_E", 
   1.125 +          analz_subset_parts RS subsetD RS Spy_see_shrK_E);
   1.126 +
   1.127 +AddSEs [Spy_see_shrK_E, Spy_analz_shrK_E];
   1.128 +
   1.129 +
   1.130 +(*** Future keys can't be seen or used! ***)
   1.131 +
   1.132 +(*Nobody can have SEEN keys that will be generated in the future.
   1.133 +  This has to be proved anew for each protocol description,
   1.134 +  but should go by similar reasoning every time.  Hardest case is the
   1.135 +  standard Fake rule.  
   1.136 +      The Union over C is essential for the induction! *)
   1.137 +goal thy "!!evs. evs : otway lost ==> \
   1.138 +\                length evs <= length evs' --> \
   1.139 +\                          Key (newK evs') ~: (UN C. parts (sees lost C evs))";
   1.140 +by (parts_induct_tac 1);
   1.141 +by (REPEAT_FIRST (best_tac (!claset addDs [impOfSubs analz_subset_parts,
   1.142 +                                           impOfSubs parts_insert_subset_Un,
   1.143 +                                           Suc_leD]
   1.144 +                                    addss (!simpset))));
   1.145 +val lemma = result();
   1.146 +
   1.147 +(*Variant needed for the main theorem below*)
   1.148 +goal thy 
   1.149 + "!!evs. [| evs : otway lost;  length evs <= length evs' |]    \
   1.150 +\        ==> Key (newK evs') ~: parts (sees lost C evs)";
   1.151 +by (fast_tac (!claset addDs [lemma]) 1);
   1.152 +qed "new_keys_not_seen";
   1.153 +Addsimps [new_keys_not_seen];
   1.154 +
   1.155 +(*Another variant: old messages must contain old keys!*)
   1.156 +goal thy 
   1.157 + "!!evs. [| Says A B X : set_of_list evs;  \
   1.158 +\           Key (newK evt) : parts {X};    \
   1.159 +\           evs : otway lost                 \
   1.160 +\        |] ==> length evt < length evs";
   1.161 +by (rtac ccontr 1);
   1.162 +by (dtac leI 1);
   1.163 +by (fast_tac (!claset addSDs [new_keys_not_seen, Says_imp_sees_Spy]
   1.164 +                      addIs  [impOfSubs parts_mono]) 1);
   1.165 +qed "Says_imp_old_keys";
   1.166 +
   1.167 +
   1.168 +(*** Future nonces can't be seen or used! [proofs resemble those above] ***)
   1.169 +
   1.170 +goal thy "!!evs. evs : otway lost ==> \
   1.171 +\                length evs <= length evt --> \
   1.172 +\                Nonce (newN evt) ~: (UN C. parts (sees lost C evs))";
   1.173 +by (etac otway.induct 1);
   1.174 +(*auto_tac does not work here, as it performs safe_tac first*)
   1.175 +by (ALLGOALS (asm_simp_tac (!simpset addsimps [parts_insert2]
   1.176 +                                     addcongs [disj_cong])));
   1.177 +by (REPEAT_FIRST (fast_tac (!claset 
   1.178 +                              addSEs partsEs
   1.179 +                              addSDs  [Says_imp_sees_Spy RS parts.Inj]
   1.180 +                              addDs  [impOfSubs analz_subset_parts,
   1.181 +                                      impOfSubs parts_insert_subset_Un,
   1.182 +                                      Suc_leD]
   1.183 +                              addss (!simpset))));
   1.184 +val lemma = result();
   1.185 +
   1.186 +(*Variant needed for the main theorem below*)
   1.187 +goal thy 
   1.188 + "!!evs. [| evs : otway lost;  length evs <= length evs' |]    \
   1.189 +\        ==> Nonce (newN evs') ~: parts (sees lost C evs)";
   1.190 +by (fast_tac (!claset addDs [lemma]) 1);
   1.191 +qed "new_nonces_not_seen";
   1.192 +Addsimps [new_nonces_not_seen];
   1.193 +
   1.194 +(*Another variant: old messages must contain old nonces!*)
   1.195 +goal thy 
   1.196 + "!!evs. [| Says A B X : set_of_list evs;  \
   1.197 +\           Nonce (newN evt) : parts {X};    \
   1.198 +\           evs : otway lost                 \
   1.199 +\        |] ==> length evt < length evs";
   1.200 +by (rtac ccontr 1);
   1.201 +by (dtac leI 1);
   1.202 +by (fast_tac (!claset addSDs [new_nonces_not_seen, Says_imp_sees_Spy]
   1.203 +                      addIs  [impOfSubs parts_mono]) 1);
   1.204 +qed "Says_imp_old_nonces";
   1.205 +
   1.206 +
   1.207 +(*Nobody can have USED keys that will be generated in the future.
   1.208 +  ...very like new_keys_not_seen*)
   1.209 +goal thy "!!evs. evs : otway lost ==> \
   1.210 +\                length evs <= length evs' --> \
   1.211 +\                newK evs' ~: keysFor (UN C. parts (sees lost C evs))";
   1.212 +by (parts_induct_tac 1);
   1.213 +(*OR1 and OR3*)
   1.214 +by (EVERY (map (fast_tac (!claset addDs [Suc_leD] addss (!simpset))) [4,2]));
   1.215 +(*Fake, OR2, OR4: these messages send unknown (X) components*)
   1.216 +by (EVERY 
   1.217 +    (map
   1.218 +     (best_tac
   1.219 +      (!claset addDs [impOfSubs (analz_subset_parts RS keysFor_mono),
   1.220 +                      impOfSubs (parts_insert_subset_Un RS keysFor_mono),
   1.221 +                      Suc_leD]
   1.222 +               addEs [new_keys_not_seen RS not_parts_not_analz RSN(2,rev_notE)]
   1.223 +               addss (!simpset)))
   1.224 +     [3,2,1]));
   1.225 +(*Reveal: dummy message*)
   1.226 +by (best_tac (!claset addEs  [new_keys_not_seen RSN(2,rev_notE)]
   1.227 +                      addIs  [less_SucI, impOfSubs keysFor_mono]
   1.228 +                      addss (!simpset addsimps [le_def])) 1);
   1.229 +val lemma = result();
   1.230 +
   1.231 +goal thy 
   1.232 + "!!evs. [| evs : otway lost;  length evs <= length evs' |]    \
   1.233 +\        ==> newK evs' ~: keysFor (parts (sees lost C evs))";
   1.234 +by (fast_tac (!claset addSDs [lemma] addss (!simpset)) 1);
   1.235 +qed "new_keys_not_used";
   1.236 +
   1.237 +bind_thm ("new_keys_not_analzd",
   1.238 +          [analz_subset_parts RS keysFor_mono,
   1.239 +           new_keys_not_used] MRS contra_subsetD);
   1.240 +
   1.241 +Addsimps [new_keys_not_used, new_keys_not_analzd];
   1.242 +
   1.243 +
   1.244 +
   1.245 +(*** Proofs involving analz ***)
   1.246 +
   1.247 +(*Describes the form of Key K when the following message is sent.  The use of
   1.248 +  "parts" strengthens the induction hyp for proving the Fake case.  The
   1.249 +  assumption A ~: lost prevents its being a Faked message.  (Based
   1.250 +  on NS_Shared/Says_S_message_form) *)
   1.251 +goal thy
   1.252 + "!!evs. evs: otway lost ==>                                           \
   1.253 +\        Crypt {|N, Agent A, B, Key K|} (shrK A) : parts (sees lost Spy evs)  \
   1.254 +\        --> A ~: lost --> (EX evt: otway lost. K = newK evt)";
   1.255 +by (parts_induct_tac 1);
   1.256 +by (Auto_tac());
   1.257 +qed_spec_mp "Reveal_message_lemma";
   1.258 +
   1.259 +(*EITHER describes the form of Key K when the following message is sent, 
   1.260 +  OR     reduces it to the Fake case.*)
   1.261 +
   1.262 +goal thy 
   1.263 + "!!evs. [| Says B' A (Crypt {|N, Agent A, B, Key K|} (shrK A)) \
   1.264 +\            : set_of_list evs;                                 \
   1.265 +\           evs : otway lost |]                                 \
   1.266 +\        ==> (EX evt: otway lost. K = newK evt)                 \
   1.267 +\          | Key K : analz (sees lost Spy evs)";
   1.268 +br (Reveal_message_lemma RS disjCI) 1;
   1.269 +ba 1;
   1.270 +by (fast_tac (!claset addSDs [Says_imp_sees_Spy RS analz.Inj]
   1.271 +                      addDs [impOfSubs analz_subset_parts]) 1);
   1.272 +by (fast_tac (!claset addSDs [Says_Crypt_lost]) 1);
   1.273 +qed "Reveal_message_form";
   1.274 +
   1.275 +
   1.276 +(*For proofs involving analz.  We again instantiate the variable to "lost".*)
   1.277 +val analz_Fake_tac = 
   1.278 +    dres_inst_tac [("lost","lost")] OR4_analz_sees_Spy 6 THEN
   1.279 +    forw_inst_tac [("lost","lost")] Reveal_message_form 7;
   1.280 +
   1.281 +
   1.282 +(****
   1.283 + The following is to prove theorems of the form
   1.284 +
   1.285 +          Key K : analz (insert (Key (newK evt)) (sees lost Spy evs)) ==>
   1.286 +          Key K : analz (sees lost Spy evs)
   1.287 +
   1.288 + A more general formula must be proved inductively.
   1.289 +
   1.290 +****)
   1.291 +
   1.292 +
   1.293 +(*NOT useful in this form, but it says that session keys are not used
   1.294 +  to encrypt messages containing other keys, in the actual protocol.
   1.295 +  We require that agents should behave like this subsequently also.*)
   1.296 +goal thy 
   1.297 + "!!evs. evs : otway lost ==> \
   1.298 +\        (Crypt X (newK evt)) : parts (sees lost Spy evs) & \
   1.299 +\        Key K : parts {X} --> Key K : parts (sees lost Spy evs)";
   1.300 +by (etac otway.induct 1);
   1.301 +by parts_Fake_tac;
   1.302 +by (ALLGOALS Asm_simp_tac);
   1.303 +(*Deals with Faked messages*)
   1.304 +by (best_tac (!claset addSEs partsEs
   1.305 +                      addDs [impOfSubs parts_insert_subset_Un]
   1.306 +                      addss (!simpset)) 2);
   1.307 +(*Base case and Reveal*)
   1.308 +by (Auto_tac());
   1.309 +result();
   1.310 +
   1.311 +
   1.312 +(** Session keys are not used to encrypt other session keys **)
   1.313 +
   1.314 +(*The equality makes the induction hypothesis easier to apply*)
   1.315 +goal thy  
   1.316 + "!!evs. evs : otway lost ==> \
   1.317 +\  ALL K E. (Key K : analz (Key``(newK``E) Un (sees lost Spy evs))) = \
   1.318 +\           (K : newK``E | Key K : analz (sees lost Spy evs))";
   1.319 +by (etac otway.induct 1);
   1.320 +by analz_Fake_tac;
   1.321 +by (REPEAT_FIRST (ares_tac [allI, analz_image_newK_lemma]));
   1.322 +by (REPEAT ((eresolve_tac [bexE, disjE] ORELSE' hyp_subst_tac) 7));
   1.323 +by (ALLGOALS (*Takes 28 secs*)
   1.324 +    (asm_simp_tac 
   1.325 +     (!simpset addsimps ([insert_Key_singleton, insert_Key_image, pushKey_newK]
   1.326 +                         @ pushes)
   1.327 +               setloop split_tac [expand_if])));
   1.328 +(** LEVEL 5 **)
   1.329 +(*Reveal case 2, OR4, OR2, Fake*) 
   1.330 +by (EVERY (map spy_analz_tac [6, 4, 2]));
   1.331 +(*Reveal case 1, OR3, Base*)
   1.332 +by (REPEAT (fast_tac (!claset addIs [image_eqI] addss (!simpset)) 1));
   1.333 +qed_spec_mp "analz_image_newK";
   1.334 +
   1.335 +
   1.336 +goal thy
   1.337 + "!!evs. evs : otway lost ==>                               \
   1.338 +\        Key K : analz (insert (Key (newK evt)) (sees lost Spy evs)) = \
   1.339 +\        (K = newK evt | Key K : analz (sees lost Spy evs))";
   1.340 +by (asm_simp_tac (HOL_ss addsimps [pushKey_newK, analz_image_newK, 
   1.341 +                                   insert_Key_singleton]) 1);
   1.342 +by (Fast_tac 1);
   1.343 +qed "analz_insert_Key_newK";
   1.344 +
   1.345 +
   1.346 +(*** The Key K uniquely identifies the Server's  message. **)
   1.347 +
   1.348 +fun ex_strip_tac i = REPEAT (ares_tac [exI, conjI] i) THEN assume_tac (i+1);
   1.349 +
   1.350 +goal thy 
   1.351 + "!!evs. evs : otway lost ==>                      \
   1.352 +\      EX A' B' NA' NB'. ALL A B NA NB.                    \
   1.353 +\       Says Server B \
   1.354 +\         {|Crypt {|NA, Agent A, Agent B, K|} (shrK A),                    \
   1.355 +\           Crypt {|NB, Agent A, Agent B, K|} (shrK B)|} : set_of_list evs  \
   1.356 +\       --> A=A' & B=B' & NA=NA' & NB=NB'";
   1.357 +by (etac otway.induct 1);
   1.358 +by (ALLGOALS (asm_simp_tac (!simpset addsimps [all_conj_distrib])));
   1.359 +by (Step_tac 1);
   1.360 +(*Remaining cases: OR3 and OR4*)
   1.361 +by (ex_strip_tac 2);
   1.362 +by (Fast_tac 2);
   1.363 +by (expand_case_tac "K = ?y" 1);
   1.364 +by (REPEAT (ares_tac [refl,exI,impI,conjI] 2));
   1.365 +(*...we assume X is a very new message, and handle this case by contradiction*)
   1.366 +by (fast_tac (!claset addEs [Says_imp_old_keys RS less_irrefl]
   1.367 +                      delrules [conjI]    (*prevent split-up into 4 subgoals*)
   1.368 +                      addss (!simpset addsimps [parts_insertI])) 1);
   1.369 +val lemma = result();
   1.370 +
   1.371 +
   1.372 +goal thy 
   1.373 +"!!evs. [| Says Server B                                           \
   1.374 +\            {|Crypt {|NA, Agent A, Agent B, K|} (shrK A),         \
   1.375 +\              Crypt {|NB, Agent A, Agent B, K|} (shrK B)|}        \
   1.376 +\           : set_of_list evs;                                     \
   1.377 +\          Says Server B'                                          \
   1.378 +\            {|Crypt {|NA', Agent A', Agent B', K|} (shrK A'),     \
   1.379 +\              Crypt {|NB', Agent A', Agent B', K|} (shrK B')|}    \
   1.380 +\           : set_of_list evs;                                     \
   1.381 +\          evs : otway lost |]                                     \
   1.382 +\       ==> A=A' & B=B' & NA=NA' & NB=NB'";
   1.383 +by (dtac lemma 1);
   1.384 +by (REPEAT (etac exE 1));
   1.385 +(*Duplicate the assumption*)
   1.386 +by (forw_inst_tac [("psi", "ALL C.?P(C)")] asm_rl 1);
   1.387 +by (fast_tac (!claset addSDs [spec]) 1);
   1.388 +qed "unique_session_keys";
   1.389 +
   1.390 +
   1.391 +
   1.392 +(**** Authenticity properties relating to NA ****)
   1.393 +
   1.394 +(*If the encrypted message appears then it originated with the Server!*)
   1.395 +goal thy 
   1.396 + "!!evs. [| A ~: lost;  evs : otway lost |]                 \
   1.397 +\ ==> Crypt {|NA, Agent A, Agent B, Key K|} (shrK A)        \
   1.398 +\      : parts (sees lost Spy evs)                          \
   1.399 +\     --> (EX NB. Says Server B                                     \
   1.400 +\                  {|Crypt {|NA, Agent A, Agent B, Key K|} (shrK A),     \
   1.401 +\                    Crypt {|NB, Agent A, Agent B, Key K|} (shrK B)|}    \
   1.402 +\                  : set_of_list evs)";
   1.403 +by (parts_induct_tac 1);
   1.404 +by (ALLGOALS (asm_simp_tac (!simpset addsimps [ex_disj_distrib])));
   1.405 +(*OR3*)
   1.406 +by (Fast_tac 1);
   1.407 +qed_spec_mp "NA_Crypt_imp_Server_msg";
   1.408 +
   1.409 +
   1.410 +(*Corollary: if A receives B's OR4 message and the nonce NA agrees
   1.411 +  then the key really did come from the Server!  CANNOT prove this of the
   1.412 +  bad form of this protocol, even though we can prove
   1.413 +  Spy_not_see_encrypted_key*)
   1.414 +goal thy 
   1.415 + "!!evs. [| Says B' A (Crypt {|NA, Agent A, Agent B, Key K|} (shrK A))  \
   1.416 +\            : set_of_list evs;                                         \
   1.417 +\           A ~: lost;  evs : otway lost |]                             \
   1.418 +\        ==> EX NB. Says Server B                                       \
   1.419 +\                    {|Crypt {|NA, Agent A, Agent B, Key K|} (shrK A),  \
   1.420 +\                      Crypt {|NB, Agent A, Agent B, Key K|} (shrK B)|} \
   1.421 +\                   : set_of_list evs";
   1.422 +by (fast_tac (!claset addSIs [NA_Crypt_imp_Server_msg]
   1.423 +                      addEs  partsEs
   1.424 +                      addDs  [Says_imp_sees_Spy RS parts.Inj]) 1);
   1.425 +qed "A_trust_OR4";
   1.426 +
   1.427 +
   1.428 +(*Describes the form of K and NA when the Server sends this message.*)
   1.429 +goal thy 
   1.430 + "!!evs. [| Says Server B \
   1.431 +\           {|Crypt {|NA, Agent A, Agent B, K|} (shrK A),                    \
   1.432 +\             Crypt {|NB, Agent A, Agent B, K|} (shrK B)|} : set_of_list evs; \
   1.433 +\           evs : otway lost |]                                        \
   1.434 +\        ==> (EX evt: otway lost. K = Key(newK evt)) &                  \
   1.435 +\            (EX i. NA = Nonce i) &                  \
   1.436 +\            (EX j. NB = Nonce j)";
   1.437 +by (etac rev_mp 1);
   1.438 +by (etac otway.induct 1);
   1.439 +by (ALLGOALS (fast_tac (!claset addss (!simpset))));
   1.440 +qed "Says_Server_message_form";
   1.441 +
   1.442 +
   1.443 +(** Crucial secrecy property: Spy does not see the keys sent in msg OR3
   1.444 +    Does not in itself guarantee security: an attack could violate 
   1.445 +    the premises, e.g. by having A=Spy **)
   1.446 +
   1.447 +goal thy 
   1.448 + "!!evs. [| A ~: lost;  B ~: lost;  evs : otway lost;  evt : otway lost |] \
   1.449 +\        ==> Says Server B                                                 \
   1.450 +\             {|Crypt {|NA, Agent A, Agent B, Key K|} (shrK A),            \
   1.451 +\               Crypt {|NB, Agent A, Agent B, Key K|} (shrK B)|}           \
   1.452 +\            : set_of_list evs -->                                         \
   1.453 +\            Says A Spy {|NA, Key K|} ~: set_of_list evs -->               \
   1.454 +\            Key K ~: analz (sees lost Spy evs)";
   1.455 +by (etac otway.induct 1);
   1.456 +by analz_Fake_tac;
   1.457 +by (REPEAT_FIRST (eresolve_tac [asm_rl, bexE, disjE] ORELSE' hyp_subst_tac));
   1.458 +by (ALLGOALS
   1.459 +    (asm_full_simp_tac 
   1.460 +     (!simpset addsimps ([analz_subset_parts RS contra_subsetD,
   1.461 +                          analz_insert_Key_newK] @ pushes)
   1.462 +               setloop split_tac [expand_if])));
   1.463 +(** LEVEL 4 **)
   1.464 +(*OR3*)
   1.465 +by (fast_tac (!claset addSIs [parts_insertI]
   1.466 +                      addEs [Says_imp_old_keys RS less_irrefl]
   1.467 +                      addss (!simpset addsimps [parts_insert2])) 2);
   1.468 +(*Reveal case 2, OR4, Fake*) 
   1.469 +by (REPEAT_FIRST (resolve_tac [conjI, impI] ORELSE' spy_analz_tac));
   1.470 +(*Reveal case 1*) (** LEVEL 6 **)
   1.471 +by (excluded_middle_tac "Aa : lost" 1);
   1.472 +(*But this contradicts Key K ~: analz (sees lost Spy evsa) *)
   1.473 +by (dtac (Says_imp_sees_Spy RS analz.Inj) 2);
   1.474 +by (fast_tac (!claset addSDs [analz.Decrypt] addss (!simpset)) 2);
   1.475 +(*So now we have  Aa ~: lost *)
   1.476 +by (dtac A_trust_OR4 1);
   1.477 +by (REPEAT (assume_tac 1));
   1.478 +by (fast_tac (!claset addDs [unique_session_keys] addss (!simpset)) 1);
   1.479 +val lemma = result() RS mp RS mp RSN(2,rev_notE);
   1.480 +
   1.481 +goal thy 
   1.482 + "!!evs. [| Says Server B \
   1.483 +\           {|Crypt {|NA, Agent A, Agent B, K|} (shrK A),                    \
   1.484 +\             Crypt {|NB, Agent A, Agent B, K|} (shrK B)|} : set_of_list evs; \
   1.485 +\           Says A Spy {|NA, K|} ~: set_of_list evs;                     \
   1.486 +\           A ~: lost;  B ~: lost;  evs : otway lost |]                  \
   1.487 +\        ==> K ~: analz (sees lost Spy evs)";
   1.488 +by (forward_tac [Says_Server_message_form] 1 THEN assume_tac 1);
   1.489 +by (fast_tac (!claset addSEs [lemma]) 1);
   1.490 +qed "Spy_not_see_encrypted_key";
   1.491 +
   1.492 +
   1.493 +goal thy 
   1.494 + "!!evs. [| C ~: {A,B,Server};                                           \
   1.495 +\           Says Server B \
   1.496 +\           {|Crypt {|NA, Agent A, Agent B, K|} (shrK A),                    \
   1.497 +\             Crypt {|NB, Agent A, Agent B, K|} (shrK B)|} : set_of_list evs; \
   1.498 +\           Says A Spy {|NA, K|} ~: set_of_list evs;                     \
   1.499 +\           A ~: lost;  B ~: lost;  evs : otway lost |]                  \
   1.500 +\        ==> K ~: analz (sees lost C evs)";
   1.501 +by (rtac (subset_insertI RS sees_mono RS analz_mono RS contra_subsetD) 1);
   1.502 +by (rtac (sees_lost_agent_subset_sees_Spy RS analz_mono RS contra_subsetD) 1);
   1.503 +by (FIRSTGOAL (rtac Spy_not_see_encrypted_key));
   1.504 +by (REPEAT_FIRST (fast_tac (!claset addIs [otway_mono RS subsetD])));
   1.505 +qed "Agent_not_see_encrypted_key";
   1.506 +
   1.507 +
   1.508 +(**** Authenticity properties relating to NB ****)
   1.509 +
   1.510 +(*If the encrypted message appears then it originated with the Server!*)
   1.511 +goal thy 
   1.512 + "!!evs. [| B ~: lost;  evs : otway lost |]                   \
   1.513 +\    ==> Crypt {|NB, Agent A, Agent B, Key K|} (shrK B)       \
   1.514 +\         : parts (sees lost Spy evs)                         \
   1.515 +\        --> (EX NA. Says Server B                                          \
   1.516 +\                     {|Crypt {|NA, Agent A, Agent B, Key K|} (shrK A),     \
   1.517 +\                       Crypt {|NB, Agent A, Agent B, Key K|} (shrK B)|}    \
   1.518 +\                     : set_of_list evs)";
   1.519 +by (parts_induct_tac 1);
   1.520 +by (ALLGOALS (asm_simp_tac (!simpset addsimps [ex_disj_distrib])));
   1.521 +(*OR3*)
   1.522 +by (Fast_tac 1);
   1.523 +qed_spec_mp "NB_Crypt_imp_Server_msg";
   1.524 +
   1.525 +
   1.526 +(*Guarantee for B: if it gets a message with matching NB then the Server
   1.527 +  has sent the correct message.*)
   1.528 +goal thy 
   1.529 + "!!evs. [| B ~: lost;  evs : otway lost;               \
   1.530 +\           Says S B {|X, Crypt {|NB, Agent A, Agent B, Key K|} (shrK B)|} \
   1.531 +\            : set_of_list evs |]                                  \
   1.532 +\        ==> EX NA. Says Server B                                          \
   1.533 +\                     {|Crypt {|NA, Agent A, Agent B, Key K|} (shrK A),     \
   1.534 +\                       Crypt {|NB, Agent A, Agent B, Key K|} (shrK B)|}    \
   1.535 +\                     : set_of_list evs";
   1.536 +by (fast_tac (!claset addSIs [NB_Crypt_imp_Server_msg]
   1.537 +                      addEs  partsEs
   1.538 +                      addDs  [Says_imp_sees_Spy RS parts.Inj]) 1);
   1.539 +qed "B_trust_OR3";