src/HOL/Auth/OtwayRees.ML
author paulson
Mon Oct 28 15:59:39 1996 +0100 (1996-10-28)
changeset 2135 80477862ab33
parent 2134 04a71407089d
child 2160 ad4382e546fc
permissions -rw-r--r--
Minor corrections
     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 Version that encrypts Nonce NB
     9 
    10 From page 244 of
    11   Burrows, Abadi and Needham.  A Logic of Authentication.
    12   Proc. Royal Soc. 426 (1989)
    13 *)
    14 
    15 open OtwayRees;
    16 
    17 proof_timing:=true;
    18 HOL_quantifiers := false;
    19 Pretty.setdepth 15;
    20 
    21 
    22 (*Weak liveness: there are traces that reach the end*)
    23 goal thy 
    24  "!!A B. [| A ~= B; A ~= Server; B ~= Server |]   \
    25 \        ==> EX K. EX NA. EX evs: otway lost.          \
    26 \               Says B A {|Nonce NA, Crypt {|Nonce NA, Key K|} (shrK A)|} \
    27 \                 : set_of_list evs";
    28 by (REPEAT (resolve_tac [exI,bexI] 1));
    29 by (rtac (otway.Nil RS otway.OR1 RS otway.OR2 RS otway.OR3 RS otway.OR4) 2);
    30 by (ALLGOALS (simp_tac (!simpset setsolver safe_solver)));
    31 by (REPEAT_FIRST (resolve_tac [refl, conjI]));
    32 by (REPEAT_FIRST (fast_tac (!claset addss (!simpset setsolver safe_solver))));
    33 result();
    34 
    35 
    36 (**** Inductive proofs about otway ****)
    37 
    38 (*Monotonicity*)
    39 goal thy "!!evs. lost' <= lost ==> otway lost' <= otway lost";
    40 by (rtac subsetI 1);
    41 by (etac otway.induct 1);
    42 by (REPEAT_FIRST
    43     (best_tac (!claset addIs (impOfSubs (sees_mono RS analz_mono RS synth_mono)
    44                               :: otway.intrs))));
    45 qed "otway_mono";
    46 
    47 (*Nobody sends themselves messages*)
    48 goal thy "!!evs. evs : otway lost ==> ALL A X. Says A A X ~: set_of_list evs";
    49 by (etac otway.induct 1);
    50 by (Auto_tac());
    51 qed_spec_mp "not_Says_to_self";
    52 Addsimps [not_Says_to_self];
    53 AddSEs   [not_Says_to_self RSN (2, rev_notE)];
    54 
    55 
    56 (** For reasoning about the encrypted portion of messages **)
    57 
    58 goal thy "!!evs. Says A' B {|N, Agent A, Agent B, X|} : set_of_list evs \
    59 \                ==> X : analz (sees lost Spy evs)";
    60 by (fast_tac (!claset addSDs [Says_imp_sees_Spy RS analz.Inj]) 1);
    61 qed "OR2_analz_sees_Spy";
    62 
    63 goal thy "!!evs. Says S B {|N, X, X'|} : set_of_list evs \
    64 \                ==> X : analz (sees lost Spy evs)";
    65 by (fast_tac (!claset addSDs [Says_imp_sees_Spy RS analz.Inj]) 1);
    66 qed "OR4_analz_sees_Spy";
    67 
    68 goal thy "!!evs. Says Server B {|NA, X, Crypt {|NB,K|} K'|} : set_of_list evs \
    69 \                 ==> K : parts (sees lost Spy evs)";
    70 by (fast_tac (!claset addSEs partsEs
    71                       addSDs [Says_imp_sees_Spy RS parts.Inj]) 1);
    72 qed "Oops_parts_sees_Spy";
    73 
    74 (*OR2_analz... and OR4_analz... let us treat those cases using the same 
    75   argument as for the Fake case.  This is possible for most, but not all,
    76   proofs: Fake does not invent new nonces (as in OR2), and of course Fake
    77   messages originate from the Spy. *)
    78 
    79 bind_thm ("OR2_parts_sees_Spy",
    80           OR2_analz_sees_Spy RS (impOfSubs analz_subset_parts));
    81 bind_thm ("OR4_parts_sees_Spy",
    82           OR4_analz_sees_Spy RS (impOfSubs analz_subset_parts));
    83 
    84 (*We instantiate the variable to "lost".  Leaving it as a Var makes proofs
    85   harder to complete, since simplification does less for us.*)
    86 val parts_Fake_tac = 
    87     let val tac = forw_inst_tac [("lost","lost")] 
    88     in  tac OR2_parts_sees_Spy 4 THEN 
    89         tac OR4_parts_sees_Spy 6 THEN
    90         tac Oops_parts_sees_Spy 7
    91     end;
    92 
    93 (*For proving the easier theorems about X ~: parts (sees lost Spy evs) *)
    94 fun parts_induct_tac i = SELECT_GOAL
    95     (DETERM (etac otway.induct 1 THEN parts_Fake_tac THEN
    96 	     (*Fake message*)
    97 	     TRY (best_tac (!claset addDs [impOfSubs analz_subset_parts,
    98 					   impOfSubs Fake_parts_insert]
    99                                     addss (!simpset)) 2)) THEN
   100      (*Base case*)
   101      fast_tac (!claset addss (!simpset)) 1 THEN
   102      ALLGOALS Asm_simp_tac) i;
   103 
   104 (** Theorems of the form X ~: parts (sees lost Spy evs) imply that NOBODY
   105     sends messages containing X! **)
   106 
   107 (*Spy never sees another agent's shared key! (unless it's lost at start)*)
   108 goal thy 
   109  "!!evs. evs : otway lost \
   110 \        ==> (Key (shrK A) : parts (sees lost Spy evs)) = (A : lost)";
   111 by (parts_induct_tac 1);
   112 by (Auto_tac());
   113 qed "Spy_see_shrK";
   114 Addsimps [Spy_see_shrK];
   115 
   116 goal thy 
   117  "!!evs. evs : otway lost \
   118 \        ==> (Key (shrK A) : analz (sees lost Spy evs)) = (A : lost)";
   119 by (auto_tac(!claset addDs [impOfSubs analz_subset_parts], !simpset));
   120 qed "Spy_analz_shrK";
   121 Addsimps [Spy_analz_shrK];
   122 
   123 goal thy  "!!A. [| Key (shrK A) : parts (sees lost Spy evs);       \
   124 \                  evs : otway lost |] ==> A:lost";
   125 by (fast_tac (!claset addDs [Spy_see_shrK]) 1);
   126 qed "Spy_see_shrK_D";
   127 
   128 bind_thm ("Spy_analz_shrK_D", analz_subset_parts RS subsetD RS Spy_see_shrK_D);
   129 AddSDs [Spy_see_shrK_D, Spy_analz_shrK_D];
   130 
   131 
   132 (*** Future keys can't be seen or used! ***)
   133 
   134 (*Nobody can have SEEN keys that will be generated in the future.
   135   This has to be proved anew for each protocol description,
   136   but should go by similar reasoning every time.  Hardest case is the
   137   standard Fake rule.  
   138       The Union over C is essential for the induction! *)
   139 goal thy "!!evs. evs : otway lost ==> \
   140 \                length evs <= length evs' --> \
   141 \                          Key (newK evs') ~: (UN C. parts (sees lost C evs))";
   142 by (parts_induct_tac 1);
   143 by (REPEAT_FIRST (best_tac (!claset addDs [impOfSubs analz_subset_parts,
   144                                            impOfSubs parts_insert_subset_Un,
   145                                            Suc_leD]
   146                                     addss (!simpset))));
   147 val lemma = result();
   148 
   149 (*Variant needed for the main theorem below*)
   150 goal thy 
   151  "!!evs. [| evs : otway lost;  length evs <= length evs' |]    \
   152 \        ==> Key (newK evs') ~: parts (sees lost C evs)";
   153 by (fast_tac (!claset addDs [lemma]) 1);
   154 qed "new_keys_not_seen";
   155 Addsimps [new_keys_not_seen];
   156 
   157 (*Another variant: old messages must contain old keys!*)
   158 goal thy 
   159  "!!evs. [| Says A B X : set_of_list evs;  \
   160 \           Key (newK evt) : parts {X};    \
   161 \           evs : otway lost                 \
   162 \        |] ==> length evt < length evs";
   163 by (rtac ccontr 1);
   164 by (dtac leI 1);
   165 by (fast_tac (!claset addSDs [new_keys_not_seen, Says_imp_sees_Spy]
   166                       addIs  [impOfSubs parts_mono]) 1);
   167 qed "Says_imp_old_keys";
   168 
   169 
   170 (*** Future nonces can't be seen or used! [proofs resemble those above] ***)
   171 
   172 goal thy "!!evs. evs : otway lost ==> \
   173 \                length evs <= length evt --> \
   174 \                Nonce (newN evt) ~: (UN C. parts (sees lost C evs))";
   175 by (etac otway.induct 1);
   176 (*auto_tac does not work here, as it performs safe_tac first*)
   177 by (ALLGOALS (asm_simp_tac (!simpset addsimps [parts_insert2]
   178                                      addcongs [disj_cong])));
   179 by (REPEAT_FIRST (fast_tac (!claset 
   180                               addSEs partsEs
   181                               addSDs  [Says_imp_sees_Spy RS parts.Inj]
   182                               addDs  [impOfSubs analz_subset_parts,
   183                                       impOfSubs parts_insert_subset_Un,
   184                                       Suc_leD]
   185                               addss (!simpset))));
   186 val lemma = result();
   187 
   188 (*Variant needed for the main theorem below*)
   189 goal thy 
   190  "!!evs. [| evs : otway lost;  length evs <= length evs' |]    \
   191 \        ==> Nonce (newN evs') ~: parts (sees lost C evs)";
   192 by (fast_tac (!claset addDs [lemma]) 1);
   193 qed "new_nonces_not_seen";
   194 Addsimps [new_nonces_not_seen];
   195 
   196 (*Another variant: old messages must contain old nonces!*)
   197 goal thy 
   198  "!!evs. [| Says A B X : set_of_list evs;  \
   199 \           Nonce (newN evt) : parts {X};    \
   200 \           evs : otway lost                 \
   201 \        |] ==> length evt < length evs";
   202 by (rtac ccontr 1);
   203 by (dtac leI 1);
   204 by (fast_tac (!claset addSDs [new_nonces_not_seen, Says_imp_sees_Spy]
   205                       addIs  [impOfSubs parts_mono]) 1);
   206 qed "Says_imp_old_nonces";
   207 
   208 
   209 (*Nobody can have USED keys that will be generated in the future.
   210   ...very like new_keys_not_seen*)
   211 goal thy "!!evs. evs : otway lost ==> \
   212 \                length evs <= length evs' --> \
   213 \                newK evs' ~: keysFor (UN C. parts (sees lost C evs))";
   214 by (parts_induct_tac 1);
   215 (*OR1 and OR3*)
   216 by (EVERY (map (fast_tac (!claset addDs [Suc_leD] addss (!simpset))) [4,2]));
   217 (*Fake, OR2, OR4: these messages send unknown (X) components*)
   218 by (REPEAT
   219     (best_tac
   220       (!claset addDs [impOfSubs (analz_subset_parts RS keysFor_mono),
   221                       impOfSubs (parts_insert_subset_Un RS keysFor_mono),
   222                       Suc_leD]
   223                addEs [new_keys_not_seen RS not_parts_not_analz RSN(2,rev_notE)]
   224                addss (!simpset)) 1));
   225 val lemma = result();
   226 
   227 goal thy 
   228  "!!evs. [| evs : otway lost;  length evs <= length evs' |]    \
   229 \        ==> newK evs' ~: keysFor (parts (sees lost C evs))";
   230 by (fast_tac (!claset addSDs [lemma] addss (!simpset)) 1);
   231 qed "new_keys_not_used";
   232 
   233 bind_thm ("new_keys_not_analzd",
   234           [analz_subset_parts RS keysFor_mono,
   235            new_keys_not_used] MRS contra_subsetD);
   236 
   237 Addsimps [new_keys_not_used, new_keys_not_analzd];
   238 
   239 
   240 
   241 (*** Proofs involving analz ***)
   242 
   243 (*Describes the form of K and NA when the Server sends this message.  Also
   244   for Oops case.*)
   245 goal thy 
   246  "!!evs. [| Says Server B \
   247 \            {|NA, X, Crypt {|NB, K|} (shrK B)|} : set_of_list evs;  \
   248 \           evs : otway lost |]                                   \
   249 \        ==> (EX evt: otway lost. K = Key(newK evt)) &            \
   250 \            (EX i. NA = Nonce i) & (EX j. NB = Nonce j)";
   251 by (etac rev_mp 1);
   252 by (etac otway.induct 1);
   253 by (ALLGOALS (fast_tac (!claset addss (!simpset))));
   254 qed "Says_Server_message_form";
   255 
   256 
   257 (*For proofs involving analz.  We again instantiate the variable to "lost".*)
   258 val analz_Fake_tac = 
   259     dres_inst_tac [("lost","lost")] OR2_analz_sees_Spy 4 THEN 
   260     dres_inst_tac [("lost","lost")] OR4_analz_sees_Spy 6 THEN
   261     forw_inst_tac [("lost","lost")] Says_Server_message_form 7 THEN
   262     assume_tac 7 THEN Full_simp_tac 7 THEN
   263     REPEAT ((eresolve_tac [bexE, exE, conjE] ORELSE' hyp_subst_tac) 7);
   264 
   265 
   266 (****
   267  The following is to prove theorems of the form
   268 
   269           Key K : analz (insert (Key (newK evt)) (sees lost Spy evs)) ==>
   270           Key K : analz (sees lost Spy evs)
   271 
   272  A more general formula must be proved inductively.
   273 ****)
   274 
   275 
   276 (** Session keys are not used to encrypt other session keys **)
   277 
   278 (*The equality makes the induction hypothesis easier to apply*)
   279 goal thy  
   280  "!!evs. evs : otway lost ==> \
   281 \  ALL K E. (Key K : analz (Key``(newK``E) Un (sees lost Spy evs))) = \
   282 \           (K : newK``E | Key K : analz (sees lost Spy evs))";
   283 by (etac otway.induct 1);
   284 by analz_Fake_tac;
   285 by (REPEAT_FIRST (ares_tac [allI, analz_image_newK_lemma]));
   286 by (ALLGOALS (*Takes 22 secs*)
   287     (asm_simp_tac 
   288      (!simpset addsimps ([insert_Key_singleton, insert_Key_image, pushKey_newK]
   289                          @ pushes)
   290                setloop split_tac [expand_if])));
   291 (** LEVEL 5 **)
   292 (*OR4, OR2, Fake*) 
   293 by (EVERY (map spy_analz_tac [5,3,2]));
   294 (*Oops, OR3, Base*)
   295 by (REPEAT (fast_tac (!claset addIs [image_eqI] addss (!simpset)) 1));
   296 qed_spec_mp "analz_image_newK";
   297 
   298 
   299 goal thy
   300  "!!evs. evs : otway lost ==>                               \
   301 \        Key K : analz (insert (Key (newK evt)) (sees lost Spy evs)) = \
   302 \        (K = newK evt | Key K : analz (sees lost Spy evs))";
   303 by (asm_simp_tac (HOL_ss addsimps [pushKey_newK, analz_image_newK, 
   304                                    insert_Key_singleton]) 1);
   305 by (Fast_tac 1);
   306 qed "analz_insert_Key_newK";
   307 
   308 
   309 (*** The Key K uniquely identifies the Server's  message. **)
   310 
   311 goal thy 
   312  "!!evs. evs : otway lost ==>                                                 \
   313 \   EX B' NA' NB' X'. ALL B NA NB X.                                          \
   314 \     Says Server B {|NA, X, Crypt {|NB, K|} (shrK B)|} : set_of_list evs --> \
   315 \     B=B' & NA=NA' & NB=NB' & X=X'";
   316 by (etac otway.induct 1);
   317 by (ALLGOALS (asm_simp_tac (!simpset addsimps [all_conj_distrib])));
   318 by (Step_tac 1);
   319 (*Remaining cases: OR3 and OR4*)
   320 by (ex_strip_tac 2);
   321 by (Fast_tac 2);
   322 by (expand_case_tac "K = ?y" 1);
   323 by (REPEAT (ares_tac [refl,exI,impI,conjI] 2));
   324 (*...we assume X is a very new message, and handle this case by contradiction*)
   325 by (fast_tac (!claset addEs [Says_imp_old_keys RS less_irrefl]
   326                       delrules [conjI]    (*prevent split-up into 4 subgoals*)
   327                       addss (!simpset addsimps [parts_insertI])) 1);
   328 val lemma = result();
   329 
   330 goal thy 
   331  "!!evs. [| Says Server B {|NA, X, Crypt {|NB, K|} (shrK B)|}      \
   332 \            : set_of_list evs;                                    \ 
   333 \           Says Server B' {|NA',X',Crypt {|NB',K|} (shrK B')|}    \
   334 \            : set_of_list evs;                                    \
   335 \           evs : otway lost |] ==> X=X' & B=B' & NA=NA' & NB=NB'";
   336 by (dtac lemma 1);
   337 by (REPEAT (etac exE 1));
   338 (*Duplicate the assumption*)
   339 by (forw_inst_tac [("psi", "ALL C.?P(C)")] asm_rl 1);
   340 by (fast_tac (!claset addSDs [spec]) 1);
   341 qed "unique_session_keys";
   342 
   343 
   344 
   345 (**** Authenticity properties relating to NA ****)
   346 
   347 (*Only OR1 can have caused such a part of a message to appear.*)
   348 goal thy 
   349  "!!evs. [| A ~: lost;  evs : otway lost |]                        \
   350 \        ==> Crypt {|NA, Agent A, Agent B|} (shrK A)               \
   351 \             : parts (sees lost Spy evs) -->                      \
   352 \            Says A B {|NA, Agent A, Agent B,                      \
   353 \                       Crypt {|NA, Agent A, Agent B|} (shrK A)|}  \
   354 \             : set_of_list evs";
   355 by (parts_induct_tac 1);
   356 qed_spec_mp "Crypt_imp_OR1";
   357 
   358 
   359 (** The Nonce NA uniquely identifies A's message. **)
   360 
   361 goal thy 
   362  "!!evs. [| evs : otway lost; A ~: lost |]               \
   363 \ ==> EX B'. ALL B.    \
   364 \        Crypt {|NA, Agent A, Agent B|} (shrK A) : parts (sees lost Spy evs) \
   365 \        --> B = B'";
   366 by (parts_induct_tac 1);
   367 by (simp_tac (!simpset addsimps [all_conj_distrib]) 1); 
   368 (*OR1: creation of new Nonce.  Move assertion into global context*)
   369 by (expand_case_tac "NA = ?y" 1);
   370 by (best_tac (!claset addSEs partsEs
   371                       addEs  [new_nonces_not_seen RSN(2,rev_notE)]) 1);
   372 val lemma = result();
   373 
   374 goal thy 
   375  "!!evs.[| Crypt {|NA, Agent A, Agent B|} (shrK A): parts(sees lost Spy evs); \
   376 \          Crypt {|NA, Agent A, Agent C|} (shrK A): parts(sees lost Spy evs); \
   377 \          evs : otway lost;  A ~: lost |]                                    \
   378 \        ==> B = C";
   379 by (dtac lemma 1);
   380 by (assume_tac 1);
   381 by (etac exE 1);
   382 (*Duplicate the assumption*)
   383 by (forw_inst_tac [("psi", "ALL C.?P(C)")] asm_rl 1);
   384 by (fast_tac (!claset addSDs [spec]) 1);
   385 qed "unique_NA";
   386 
   387 
   388 val nonce_not_seen_now = le_refl RSN (2, new_nonces_not_seen) RSN (2,rev_notE);
   389 
   390 (*It is impossible to re-use a nonce in both OR1 and OR2.  This holds because
   391   OR2 encrypts Nonce NB.  It prevents the attack that can occur in the
   392   over-simplified version of this protocol: see OtwayRees_Bad.*)
   393 goal thy 
   394  "!!evs. [| A ~: lost;  evs : otway lost |]                            \
   395 \        ==> Crypt {|NA, Agent A, Agent B|} (shrK A)             \
   396 \             : parts (sees lost Spy evs) -->                       \
   397 \            Crypt {|NA', NA, Agent A', Agent A|} (shrK A)       \
   398 \             ~: parts (sees lost Spy evs)";
   399 by (parts_induct_tac 1);
   400 by (REPEAT (fast_tac (!claset addSEs (partsEs@[nonce_not_seen_now])
   401                               addSDs  [impOfSubs parts_insert_subset_Un]
   402                               addss (!simpset)) 1));
   403 qed_spec_mp"no_nonce_OR1_OR2";
   404 
   405 
   406 (*Crucial property: If the encrypted message appears, and A has used NA
   407   to start a run, then it originated with the Server!*)
   408 goal thy 
   409  "!!evs. [| A ~: lost;  A ~= Spy;  evs : otway lost |]                 \
   410 \    ==> Crypt {|NA, Key K|} (shrK A) : parts (sees lost Spy evs)      \
   411 \        --> Says A B {|NA, Agent A, Agent B,                          \
   412 \                       Crypt {|NA, Agent A, Agent B|} (shrK A)|}      \
   413 \             : set_of_list evs -->                                    \
   414 \            (EX NB. Says Server B                                     \
   415 \                 {|NA,                                                \
   416 \                   Crypt {|NA, Key K|} (shrK A),                      \
   417 \                   Crypt {|NB, Key K|} (shrK B)|}                     \
   418 \                   : set_of_list evs)";
   419 by (parts_induct_tac 1);
   420 (*OR1: it cannot be a new Nonce, contradiction.*)
   421 by (fast_tac (!claset addSIs [parts_insertI]
   422                       addSEs partsEs
   423                       addEs [Says_imp_old_nonces RS less_irrefl]
   424                       addss (!simpset)) 1);
   425 (*OR3 and OR4*) 
   426 (*OR4*)
   427 by (REPEAT (Safe_step_tac 2));
   428 by (REPEAT (best_tac (!claset addSDs [parts_cut]) 3));
   429 by (fast_tac (!claset addSIs [Crypt_imp_OR1]
   430                       addEs  partsEs
   431                       addDs [Says_imp_sees_Spy RS parts.Inj]) 2);
   432 (*OR3*)  (** LEVEL 5 **)
   433 by (asm_simp_tac (!simpset addsimps [ex_disj_distrib]) 1);
   434 by (step_tac (!claset delrules [disjCI, impCE]) 1);
   435 by (fast_tac (!claset addSEs [MPair_parts]
   436                       addSDs [Says_imp_sees_Spy RS parts.Inj]
   437                       addEs  [no_nonce_OR1_OR2 RSN (2, rev_notE)]
   438                       delrules [conjI] (*stop split-up into 4 subgoals*)) 2);
   439 by (fast_tac (!claset addSDs [Says_imp_sees_Spy RS parts.Inj]
   440                       addSEs [MPair_parts]
   441                       addEs  [unique_NA]) 1);
   442 qed_spec_mp "NA_Crypt_imp_Server_msg";
   443 
   444 
   445 (*Corollary: if A receives B's OR4 message and the nonce NA agrees
   446   then the key really did come from the Server!  CANNOT prove this of the
   447   bad form of this protocol, even though we can prove
   448   Spy_not_see_encrypted_key*)
   449 goal thy 
   450  "!!evs. [| Says B' A {|NA, Crypt {|NA, Key K|} (shrK A)|}         \
   451 \            : set_of_list evs;                                    \
   452 \           Says A B {|NA, Agent A, Agent B,                       \
   453 \                      Crypt {|NA, Agent A, Agent B|} (shrK A)|}   \
   454 \            : set_of_list evs;                                    \
   455 \           A ~: lost;  A ~= Spy;  evs : otway lost |]             \
   456 \        ==> EX NB. Says Server B                                  \
   457 \                     {|NA,                                        \
   458 \                       Crypt {|NA, Key K|} (shrK A),              \
   459 \                       Crypt {|NB, Key K|} (shrK B)|}             \
   460 \                       : set_of_list evs";
   461 by (fast_tac (!claset addSIs [NA_Crypt_imp_Server_msg]
   462                       addEs  partsEs
   463                       addDs  [Says_imp_sees_Spy RS parts.Inj]) 1);
   464 qed "A_trust_OR4";
   465 
   466 
   467 (** Crucial secrecy property: Spy does not see the keys sent in msg OR3
   468     Does not in itself guarantee security: an attack could violate 
   469     the premises, e.g. by having A=Spy **)
   470 
   471 goal thy 
   472  "!!evs. [| A ~: lost;  B ~: lost;  evs : otway lost;  evt : otway lost |] \
   473 \        ==> Says Server B                                                 \
   474 \              {|NA, Crypt {|NA, Key K|} (shrK A),                         \
   475 \                Crypt {|NB, Key K|} (shrK B)|} : set_of_list evs -->      \
   476 \            Says B Spy {|NA, NB, Key K|} ~: set_of_list evs -->           \
   477 \            Key K ~: analz (sees lost Spy evs)";
   478 by (etac otway.induct 1);
   479 by analz_Fake_tac;
   480 by (ALLGOALS
   481     (asm_full_simp_tac 
   482      (!simpset addsimps ([analz_subset_parts RS contra_subsetD,
   483                           analz_insert_Key_newK] @ pushes)
   484                setloop split_tac [expand_if])));
   485 (*OR3*)
   486 by (fast_tac (!claset addSIs [parts_insertI]
   487                       addEs [Says_imp_old_keys RS less_irrefl]
   488                       addss (!simpset addsimps [parts_insert2])) 3);
   489 (*OR4, OR2, Fake*) 
   490 by (REPEAT_FIRST (resolve_tac [conjI, impI] ORELSE' spy_analz_tac));
   491 (*Oops*) (** LEVEL 5 **)
   492 by (fast_tac (!claset delrules [disjE]
   493 		      addDs [unique_session_keys] addss (!simpset)) 1);
   494 val lemma = result() RS mp RS mp RSN(2,rev_notE);
   495 
   496 goal thy 
   497  "!!evs. [| Says Server B \
   498 \            {|NA, Crypt {|NA, K|} (shrK A),                             \
   499 \                  Crypt {|NB, K|} (shrK B)|} : set_of_list evs;         \
   500 \           Says B Spy {|NA, NB, K|} ~: set_of_list evs;                 \
   501 \           A ~: lost;  B ~: lost;  evs : otway lost |]                  \
   502 \        ==> K ~: analz (sees lost Spy evs)";
   503 by (forward_tac [Says_Server_message_form] 1 THEN assume_tac 1);
   504 by (fast_tac (!claset addSEs [lemma]) 1);
   505 qed "Spy_not_see_encrypted_key";
   506 
   507 
   508 goal thy 
   509  "!!evs. [| C ~: {A,B,Server};                                           \
   510 \           Says Server B                                                \
   511 \            {|NA, Crypt {|NA, K|} (shrK A),                             \
   512 \                  Crypt {|NB, K|} (shrK B)|} : set_of_list evs;         \
   513 \           Says B Spy {|NA, NB, K|} ~: set_of_list evs;                 \
   514 \           A ~: lost;  B ~: lost;  evs : otway lost |]                  \
   515 \        ==> K ~: analz (sees lost C evs)";
   516 by (rtac (subset_insertI RS sees_mono RS analz_mono RS contra_subsetD) 1);
   517 by (rtac (sees_lost_agent_subset_sees_Spy RS analz_mono RS contra_subsetD) 1);
   518 by (FIRSTGOAL (rtac Spy_not_see_encrypted_key));
   519 by (REPEAT_FIRST (fast_tac (!claset addIs [otway_mono RS subsetD])));
   520 qed "Agent_not_see_encrypted_key";
   521 
   522 
   523 (**** Authenticity properties relating to NB ****)
   524 
   525 (*Only OR2 can have caused such a part of a message to appear.  We do not
   526   know anything about X'.*)
   527 goal thy 
   528  "!!evs. [| B ~: lost;  evs : otway lost |]                    \
   529 \        ==> Crypt {|NA, NB, Agent A, Agent B|} (shrK B)       \
   530 \             : parts (sees lost Spy evs) -->                  \
   531 \            (EX X'. Says B Server                             \
   532 \             {|NA, Agent A, Agent B, X',                      \
   533 \               Crypt {|NA, NB, Agent A, Agent B|} (shrK B)|}  \
   534 \             : set_of_list evs)";
   535 by (parts_induct_tac 1);
   536 by (auto_tac (!claset, !simpset addcongs [conj_cong]));
   537 qed_spec_mp "Crypt_imp_OR2";
   538 
   539 
   540 (** The Nonce NB uniquely identifies B's  message. **)
   541 
   542 goal thy 
   543  "!!evs. [| evs : otway lost; B ~: lost |]               \
   544 \ ==> EX NA' A'. ALL NA A.                               \
   545 \      Crypt {|NA, NB, Agent A, Agent B|} (shrK B) : parts(sees lost Spy evs) \
   546 \      --> NA = NA' & A = A'";
   547 by (parts_induct_tac 1);
   548 by (simp_tac (!simpset addsimps [all_conj_distrib]) 1); 
   549 (*OR2: creation of new Nonce.  Move assertion into global context*)
   550 by (expand_case_tac "NB = ?y" 1);
   551 by (fast_tac (!claset addSEs (nonce_not_seen_now::partsEs)) 1);
   552 val lemma = result();
   553 
   554 goal thy 
   555  "!!evs.[| Crypt {|NA, NB, Agent A, Agent B|} (shrK B) \
   556 \                  : parts(sees lost Spy evs);         \
   557 \          Crypt {|NC, NB, Agent C, Agent B|} (shrK B) \
   558 \                  : parts(sees lost Spy evs);         \
   559 \          evs : otway lost;  B ~: lost |]             \
   560 \        ==> NC = NA & C = A";
   561 by (dtac lemma 1);
   562 by (assume_tac 1);
   563 by (REPEAT (etac exE 1));
   564 (*Duplicate the assumption*)
   565 by (forw_inst_tac [("psi", "ALL C.?P(C)")] asm_rl 1);
   566 by (fast_tac (!claset addSDs [spec]) 1);
   567 qed "unique_NB";
   568 
   569 
   570 (*If the encrypted message appears, and B has used Nonce NB,
   571   then it originated with the Server!*)
   572 goal thy 
   573  "!!evs. [| B ~: lost;  B ~= Spy;  evs : otway lost |]                   \
   574 \    ==> Crypt {|NB, Key K|} (shrK B) : parts (sees lost Spy evs)        \
   575 \        --> (ALL X'. Says B Server                                      \
   576 \                       {|NA, Agent A, Agent B, X',                      \
   577 \                         Crypt {|NA, NB, Agent A, Agent B|} (shrK B)|}  \
   578 \             : set_of_list evs                                          \
   579 \             --> Says Server B                                          \
   580 \                  {|NA, Crypt {|NA, Key K|} (shrK A),                   \
   581 \                        Crypt {|NB, Key K|} (shrK B)|}                  \
   582 \                   : set_of_list evs)";
   583 by (parts_induct_tac 1);
   584 (*OR1: it cannot be a new Nonce, contradiction.*)
   585 by (fast_tac (!claset addSIs [parts_insertI]
   586                       addSEs partsEs
   587                       addEs [Says_imp_old_nonces RS less_irrefl]
   588                       addss (!simpset)) 1);
   589 (*OR3 and OR4*)  (** LEVEL 5 **)
   590 (*OR4*)
   591 by (REPEAT (Safe_step_tac 2));
   592 br (Crypt_imp_OR2 RS exE) 2;
   593 by (REPEAT (fast_tac (!claset addEs partsEs) 2));
   594 (*OR3*)  (** LEVEL 8 **)
   595 by (step_tac (!claset delrules [disjCI, impCE]) 1);
   596 by (fast_tac (!claset delrules [conjI] (*stop split-up*)) 3); 
   597 by (fast_tac (!claset addSDs [Says_imp_sees_Spy RS parts.Inj]
   598                       addSEs [MPair_parts]
   599                       addDs  [unique_NB]) 2);
   600 by (fast_tac (!claset addSEs [MPair_parts]
   601                       addSDs [Says_imp_sees_Spy RS parts.Inj]
   602                       addSEs  [no_nonce_OR1_OR2 RSN (2, rev_notE)]
   603                       delrules [conjI, impCE] (*stop split-up*)) 1);
   604 qed_spec_mp "NB_Crypt_imp_Server_msg";
   605 
   606 
   607 (*Guarantee for B: if it gets a message with matching NB then the Server
   608   has sent the correct message.*)
   609 goal thy 
   610  "!!evs. [| B ~: lost;  B ~= Spy;  evs : otway lost;               \
   611 \           Says S B {|NA, X, Crypt {|NB, Key K|} (shrK B)|}       \
   612 \            : set_of_list evs;                                    \
   613 \           Says B Server {|NA, Agent A, Agent B, X',              \
   614 \                           Crypt {|NA, NB, Agent A, Agent B|}     \
   615 \                                 (shrK B)|}                       \
   616 \            : set_of_list evs |]                                  \
   617 \        ==> Says Server B                                         \
   618 \                 {|NA,                                            \
   619 \                   Crypt {|NA, Key K|} (shrK A),                  \
   620 \                   Crypt {|NB, Key K|} (shrK B)|}                 \
   621 \                   : set_of_list evs";
   622 by (fast_tac (!claset addSIs [NB_Crypt_imp_Server_msg]
   623                       addEs  partsEs
   624                       addDs  [Says_imp_sees_Spy RS parts.Inj]) 1);
   625 qed "B_trust_OR3";
   626 
   627 
   628 B_trust_OR3 RS Spy_not_see_encrypted_key;
   629 
   630 
   631 (** A session key uniquely identifies a pair of senders in the message
   632     encrypted by a good agent C.  NEEDED?  INTERESTING?**)
   633 goal thy 
   634  "!!evs. evs : otway lost ==>                                           \
   635 \      EX A B. ALL C N.                                                 \
   636 \         C ~: lost -->                                                 \
   637 \         Crypt {|N, Key K|} (shrK C) : parts (sees lost Spy evs) -->   \
   638 \         C=A | C=B";
   639 by (Simp_tac 1);        (*Miniscoping*)
   640 by (etac otway.induct 1);
   641 by analz_Fake_tac;
   642 (*spy_analz_tac just does not work here: it is an entirely different proof!*)
   643 by (ALLGOALS 
   644     (asm_simp_tac (!simpset addsimps [all_conj_distrib, ex_disj_distrib,
   645                                       imp_conjR, parts_insert_sees,
   646                                       parts_insert2])));
   647 by (REPEAT_FIRST (etac exE));
   648 (*OR3: extraction of K = newK evsa to global context...*) (** LEVEL 6 **)
   649 by (expand_case_tac "K = ?y" 4);
   650 by (REPEAT (ares_tac [exI] 5));
   651 (*...we prove this case by contradiction: the key is too new!*)
   652 by (fast_tac (!claset addSEs partsEs
   653                       addEs [Says_imp_old_keys RS less_irrefl]
   654                       addss (!simpset)) 4);
   655 (*Base, Fake, OR2, OR4*)
   656 by (REPEAT_FIRST ex_strip_tac);
   657 by (dtac synth.Inj 4);
   658 by (dtac synth.Inj 3);
   659 (*Now in effect there are three Fake cases*)
   660 by (REPEAT_FIRST (best_tac (!claset addDs [impOfSubs Fake_parts_insert]
   661                                     delrules [disjCI, disjE]
   662                                     addss (!simpset))));
   663 qed "key_identifies_senders";