src/HOL/Auth/Shared.ML
author nipkow
Tue Apr 08 10:48:42 1997 +0200 (1997-04-08)
changeset 2919 953a47dc0519
parent 2891 d8f254ad1ab9
child 2922 580647a879cf
permissions -rw-r--r--
Dep. on Provers/nat_transitive
     1 (*  Title:      HOL/Auth/Shared
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1996  University of Cambridge
     5 
     6 Theory of Shared Keys (common to all symmetric-key protocols)
     7 
     8 Server keys; initial states of agents; new nonces and keys; function "sees" 
     9 *)
    10 
    11 
    12 open Shared;
    13 
    14 (*Holds because Friend is injective: thus cannot prove for all f*)
    15 goal thy "(Friend x : Friend``A) = (x:A)";
    16 by (Auto_tac());
    17 qed "Friend_image_eq";
    18 Addsimps [Friend_image_eq];
    19 
    20 Addsimps [Un_insert_left, Un_insert_right];
    21 
    22 (*By default only o_apply is built-in.  But in the presence of eta-expansion
    23   this means that some terms displayed as (f o g) will be rewritten, and others
    24   will not!*)
    25 Addsimps [o_def];
    26 
    27 (*** Basic properties of shrK and newK ***)
    28 
    29 (*Injectiveness and freshness of new keys and nonces*)
    30 AddIffs [inj_shrK RS inj_eq, inj_newN RS inj_eq, 
    31          inj_newK RS inj_eq, inj_nPair RS inj_eq];
    32 
    33 (* invKey (shrK A) = shrK A *)
    34 bind_thm ("invKey_id", rewrite_rule [isSymKey_def] isSym_keys);
    35 
    36 Addsimps [invKey_id];
    37 
    38 goal thy "!!K. newK i = invKey K ==> newK i = K";
    39 by (rtac (invKey_eq RS iffD1) 1);
    40 by (Full_simp_tac 1);
    41 val newK_invKey = result();
    42 
    43 AddSDs [newK_invKey, sym RS newK_invKey];
    44 
    45 Addsimps [newK_neq_shrK, newK_neq_shrK RS not_sym];
    46 
    47 (** Rewrites should not refer to  initState(Friend i) 
    48     -- not in normal form! **)
    49 
    50 goal thy "Key (newK i) ~: parts (initState lost B)";
    51 by (agent.induct_tac "B" 1);
    52 by (Auto_tac ());
    53 qed "newK_notin_initState";
    54 
    55 AddIffs [newK_notin_initState];
    56 
    57 goalw thy [keysFor_def] "keysFor (parts (initState lost C)) = {}";
    58 by (agent.induct_tac "C" 1);
    59 by (auto_tac (!claset addIs [range_eqI], !simpset));
    60 qed "keysFor_parts_initState";
    61 Addsimps [keysFor_parts_initState];
    62 
    63 goalw thy [keysFor_def] "keysFor (Key``E) = {}";
    64 by (Auto_tac ());
    65 qed "keysFor_image_Key";
    66 Addsimps [keysFor_image_Key];
    67 
    68 goal thy "shrK A ~: newK``E";
    69 by (agent.induct_tac "A" 1);
    70 by (Auto_tac ());
    71 qed "shrK_notin_image_newK";
    72 Addsimps [shrK_notin_image_newK];
    73 
    74 
    75 (*** Function "sees" ***)
    76 
    77 goal thy
    78     "!!evs. lost' <= lost ==> sees lost' A evs <= sees lost A evs";
    79 by (list.induct_tac "evs" 1);
    80 by (agent.induct_tac "A" 1);
    81 by (event.induct_tac "a" 2);
    82 by (Auto_tac ());
    83 qed "sees_mono";
    84 
    85 (*Agents see their own shared keys!*)
    86 goal thy "A ~= Spy --> Key (shrK A) : sees lost A evs";
    87 by (list.induct_tac "evs" 1);
    88 by (agent.induct_tac "A" 1);
    89 by (Auto_tac ());
    90 qed_spec_mp "sees_own_shrK";
    91 
    92 (*Spy sees shared keys of lost agents!*)
    93 goal thy "!!A. A: lost ==> Key (shrK A) : sees lost Spy evs";
    94 by (list.induct_tac "evs" 1);
    95 by (Auto_tac());
    96 qed "Spy_sees_lost";
    97 
    98 AddSIs [sees_own_shrK, Spy_sees_lost];
    99 
   100 (*Added for Yahalom/lost_tac*)
   101 goal thy "!!A. [| Crypt (shrK A) X : analz (sees lost Spy evs);  A: lost |] \
   102 \              ==> X : analz (sees lost Spy evs)";
   103 by (fast_tac (!claset addSDs [analz.Decrypt] addss (!simpset)) 1);
   104 qed "Crypt_Spy_analz_lost";
   105 
   106 (** Specialized rewrite rules for (sees lost A (Says...#evs)) **)
   107 
   108 goal thy "sees lost B (Says A B X # evs) = insert X (sees lost B evs)";
   109 by (Simp_tac 1);
   110 qed "sees_own";
   111 
   112 goal thy "!!A. Server ~= B ==> \
   113 \          sees lost Server (Says A B X # evs) = sees lost Server evs";
   114 by (Asm_simp_tac 1);
   115 qed "sees_Server";
   116 
   117 goal thy "!!A. Friend i ~= B ==> \
   118 \          sees lost (Friend i) (Says A B X # evs) = sees lost (Friend i) evs";
   119 by (Asm_simp_tac 1);
   120 qed "sees_Friend";
   121 
   122 goal thy "sees lost Spy (Says A B X # evs) = insert X (sees lost Spy evs)";
   123 by (Simp_tac 1);
   124 qed "sees_Spy";
   125 
   126 goal thy "sees lost A (Says A' B X # evs) <= insert X (sees lost A evs)";
   127 by (simp_tac (!simpset setloop split_tac [expand_if]) 1);
   128 by (Blast_tac 1);
   129 qed "sees_Says_subset_insert";
   130 
   131 goal thy "sees lost A evs <= sees lost A (Says A' B X # evs)";
   132 by (simp_tac (!simpset setloop split_tac [expand_if]) 1);
   133 by (Blast_tac 1);
   134 qed "sees_subset_sees_Says";
   135 
   136 (*Pushing Unions into parts.  One of the agents A is B, and thus sees Y.
   137   Once used to prove new_keys_not_seen; now obsolete.*)
   138 goal thy "(UN A. parts (sees lost A (Says B C Y # evs))) = \
   139 \         parts {Y} Un (UN A. parts (sees lost A evs))";
   140 by (Step_tac 1);
   141 by (etac rev_mp 1);     (*split_tac does not work on assumptions*)
   142 by (ALLGOALS
   143     (fast_tac (!claset unsafe_addss (!simpset addsimps [parts_Un, sees_Cons] 
   144 				            setloop split_tac [expand_if]))));
   145 qed "UN_parts_sees_Says";
   146 
   147 goal thy "Says A B X : set_of_list evs --> X : sees lost Spy evs";
   148 by (list.induct_tac "evs" 1);
   149 by (Auto_tac ());
   150 qed_spec_mp "Says_imp_sees_Spy";
   151 
   152 (*Use with addSEs to derive contradictions from old Says events containing
   153   items known to be fresh*)
   154 val sees_Spy_partsEs = make_elim (Says_imp_sees_Spy RS parts.Inj):: partsEs;
   155 
   156 goal thy  
   157  "!!evs. [| Says A B (Crypt (shrK C) X) : set_of_list evs;  C : lost |] \
   158 \        ==> X : analz (sees lost Spy evs)";
   159 by (fast_tac (!claset addSDs [Says_imp_sees_Spy RS analz.Inj]
   160                       unsafe_addss (!simpset)) 1);
   161 qed "Says_Crypt_lost";
   162 
   163 goal thy  
   164  "!!evs. [| Says A B (Crypt (shrK C) X) : set_of_list evs;        \
   165 \           X ~: analz (sees lost Spy evs) |]                     \
   166 \        ==> C ~: lost";
   167 by (fast_tac (!claset addSDs [Says_imp_sees_Spy RS analz.Inj]
   168                       unsafe_addss (!simpset)) 1);
   169 qed "Says_Crypt_not_lost";
   170 
   171 (*NEEDED??*)
   172 goal thy "initState lost C <= Key `` range shrK";
   173 by (agent.induct_tac "C" 1);
   174 by (Auto_tac ());
   175 qed "initState_subset";
   176 
   177 (*NEEDED??*)
   178 goal thy "X : sees lost C evs --> \
   179 \          (EX A B. Says A B X : set_of_list evs) | (EX A. X = Key (shrK A))";
   180 by (list.induct_tac "evs" 1);
   181 by (ALLGOALS Asm_simp_tac);
   182 by (blast_tac (!claset addDs [impOfSubs initState_subset]) 1);
   183 by (rtac conjI 1);
   184 by (Blast_tac 2);
   185 by (event.induct_tac "a" 1);
   186 by (ALLGOALS (asm_simp_tac (!simpset addsimps [mem_if])));
   187 by (ALLGOALS Blast_tac);
   188 qed_spec_mp "seesD";
   189 
   190 Addsimps [sees_own, sees_Server, sees_Friend, sees_Spy];
   191 Delsimps [sees_Cons];   (**** NOTE REMOVAL -- laws above are cleaner ****)
   192 
   193 
   194 (*** Fresh nonces ***)
   195 
   196 goal thy "Nonce N ~: parts (initState lost B)";
   197 by (agent.induct_tac "B" 1);
   198 by (Auto_tac ());
   199 qed "Nonce_notin_initState";
   200 
   201 AddIffs [Nonce_notin_initState];
   202 
   203 goalw thy [used_def] "!!X. X: parts (sees lost B evs) ==> X: used evs";
   204 by (etac (impOfSubs parts_mono) 1);
   205 by (Blast_tac 1);
   206 qed "usedI";
   207 
   208 AddIs [usedI];
   209 
   210 (** Fresh keys never clash with long-term shared keys **)
   211 
   212 goal thy "Key (shrK A) : used evs";
   213 by (Best_tac 1);
   214 qed "shrK_in_used";
   215 AddIffs [shrK_in_used];
   216 
   217 (*Used in parts_Fake_tac and analz_Fake_tac to distinguish session keys
   218   from long-term shared keys*)
   219 goal thy "!!K. Key K ~: used evs ==> K ~: range shrK";
   220 by (Best_tac 1);
   221 qed "Key_not_used";
   222 
   223 (*A session key cannot clash with a long-term shared key*)
   224 goal thy "!!K. K ~: range shrK ==> shrK B ~= K";
   225 by (Blast_tac 1);
   226 qed "shrK_neq";
   227 
   228 Addsimps [Key_not_used, shrK_neq, shrK_neq RS not_sym];
   229 
   230 
   231 goal thy "used (Says A B X # evs) = parts{X} Un used evs";
   232 by (simp_tac (!simpset addsimps [used_def, UN_parts_sees_Says]) 1);
   233 qed "used_Says";
   234 Addsimps [used_Says];
   235 
   236 goal thy "used [] <= used l";
   237 by (list.induct_tac "l" 1);
   238 by (event.induct_tac "a" 2);
   239 by (ALLGOALS Asm_simp_tac);
   240 by (Best_tac 1);
   241 qed "used_nil_subset";
   242 
   243 goal thy "used l <= used (l@l')";
   244 by (list.induct_tac "l" 1);
   245 by (simp_tac (!simpset addsimps [used_nil_subset]) 1);
   246 by (event.induct_tac "a" 1);
   247 by (Asm_simp_tac 1);
   248 by (Best_tac 1);
   249 qed "used_subset_append";
   250 
   251 
   252 (*** Supply fresh nonces for possibility theorems. ***)
   253 
   254 goalw thy [used_def] "EX N. ALL n. N<=n --> Nonce n ~: used evs";
   255 by (list.induct_tac "evs" 1);
   256 by (res_inst_tac [("x","0")] exI 1);
   257 by (Step_tac 1);
   258 by (Full_simp_tac 1);
   259 (*Inductive step*)
   260 by (event.induct_tac "a" 1);
   261 by (full_simp_tac (!simpset addsimps [UN_parts_sees_Says]) 1);
   262 by (msg.induct_tac "msg" 1);
   263 by (ALLGOALS (asm_simp_tac (!simpset addsimps [exI, parts_insert2])));
   264 by (Step_tac 1);
   265 (*MPair case*)
   266 by (res_inst_tac [("x","Na+Nb")] exI 2);
   267 by (blast_tac (!claset addSEs [add_leE]) 2);
   268 (*Nonce case*)
   269 by (res_inst_tac [("x","N + Suc nat")] exI 1);
   270 by (fast_tac (!claset addSEs [add_leE] addaltern trans_tac) 1);
   271 val lemma = result();
   272 
   273 goal thy "EX N. Nonce N ~: used evs";
   274 by (rtac (lemma RS exE) 1);
   275 by (Blast_tac 1);
   276 qed "Nonce_supply1";
   277 
   278 goal thy "EX N N'. Nonce N ~: used evs & Nonce N' ~: used evs' & N ~= N'";
   279 by (cut_inst_tac [("evs","evs")] lemma 1);
   280 by (cut_inst_tac [("evs","evs'")] lemma 1);
   281 by (Step_tac 1);
   282 by (res_inst_tac [("x","N")] exI 1);
   283 by (res_inst_tac [("x","Suc (N+Na)")] exI 1);
   284 by (asm_simp_tac (!simpset addsimps [less_not_refl2 RS not_sym, 
   285 				     le_add2, le_add1, 
   286 				     le_eq_less_Suc RS sym]) 1);
   287 qed "Nonce_supply2";
   288 
   289 goal thy "EX N N' N''. Nonce N ~: used evs & Nonce N' ~: used evs' & \
   290 \                   Nonce N'' ~: used evs'' & N ~= N' & N' ~= N'' & N ~= N''";
   291 by (cut_inst_tac [("evs","evs")] lemma 1);
   292 by (cut_inst_tac [("evs","evs'")] lemma 1);
   293 by (cut_inst_tac [("evs","evs''")] lemma 1);
   294 by (Step_tac 1);
   295 by (res_inst_tac [("x","N")] exI 1);
   296 by (res_inst_tac [("x","Suc (N+Na)")] exI 1);
   297 by (res_inst_tac [("x","Suc (Suc (N+Na+Nb))")] exI 1);
   298 by (asm_simp_tac (!simpset addsimps [less_not_refl2 RS not_sym, 
   299 				     le_add2, le_add1, 
   300 				     le_eq_less_Suc RS sym]) 1);
   301 by (rtac (less_trans RS less_not_refl2 RS not_sym) 1);
   302 by (stac (le_eq_less_Suc RS sym) 1);
   303 by (asm_simp_tac (!simpset addsimps [le_eq_less_Suc RS sym]) 2);
   304 by (REPEAT (rtac le_add1 1));
   305 qed "Nonce_supply3";
   306 
   307 goal thy "Nonce (@ N. Nonce N ~: used evs) ~: used evs";
   308 by (rtac (lemma RS exE) 1);
   309 by (rtac selectI 1);
   310 by (Blast_tac 1);
   311 qed "Nonce_supply";
   312 
   313 (*** Supply fresh keys for possibility theorems. ***)
   314 
   315 goal thy "EX K. Key K ~: used evs";
   316 by (rtac (Fin.emptyI RS Key_supply_ax RS exE) 1);
   317 by (Blast_tac 1);
   318 qed "Key_supply1";
   319 
   320 val Fin_UNIV_insertI = UNIV_I RS Fin.insertI;
   321 
   322 goal thy "EX K K'. Key K ~: used evs & Key K' ~: used evs' & K ~= K'";
   323 by (cut_inst_tac [("evs","evs")] (Fin.emptyI RS Key_supply_ax) 1);
   324 by (etac exE 1);
   325 by (cut_inst_tac [("evs","evs'")] 
   326     (Fin.emptyI RS Fin_UNIV_insertI RS Key_supply_ax) 1);
   327 by (Auto_tac());
   328 qed "Key_supply2";
   329 
   330 goal thy "EX K K' K''. Key K ~: used evs & Key K' ~: used evs' & \
   331 \                      Key K'' ~: used evs'' & K ~= K' & K' ~= K'' & K ~= K''";
   332 by (cut_inst_tac [("evs","evs")] (Fin.emptyI RS Key_supply_ax) 1);
   333 by (etac exE 1);
   334 by (cut_inst_tac [("evs","evs'")] 
   335     (Fin.emptyI RS Fin_UNIV_insertI RS Key_supply_ax) 1);
   336 by (etac exE 1);
   337 by (cut_inst_tac [("evs","evs''")] 
   338     (Fin.emptyI RS Fin_UNIV_insertI RS Fin_UNIV_insertI RS Key_supply_ax) 1);
   339 by (Step_tac 1);
   340 by (Full_simp_tac 1);
   341 by (fast_tac (!claset addSEs [allE]) 1);
   342 qed "Key_supply3";
   343 
   344 goal thy "Key (@ K. Key K ~: used evs) ~: used evs";
   345 by (rtac (Fin.emptyI RS Key_supply_ax RS exE) 1);
   346 by (rtac selectI 1);
   347 by (Blast_tac 1);
   348 qed "Key_supply";
   349 
   350 (*** Tactics for possibility theorems ***)
   351 
   352 val possibility_tac =
   353     REPEAT (*omit used_Says so that Nonces, Keys start from different traces!*)
   354     (ALLGOALS (simp_tac 
   355                (!simpset delsimps [used_Says] setSolver safe_solver))
   356      THEN
   357      REPEAT_FIRST (eq_assume_tac ORELSE' 
   358                    resolve_tac [refl, conjI, Nonce_supply, Key_supply]));
   359 
   360 (*For harder protocols (such as Recur) where we have to set up some
   361   nonces and keys initially*)
   362 val basic_possibility_tac =
   363     REPEAT 
   364     (ALLGOALS (asm_simp_tac (!simpset setSolver safe_solver))
   365      THEN
   366      REPEAT_FIRST (resolve_tac [refl, conjI]));
   367 
   368 
   369 (** Power of the Spy **)
   370 
   371 (*The Spy can see more than anybody else, except for their initial state*)
   372 goal thy "sees lost A evs <= initState lost A Un sees lost Spy evs";
   373 by (list.induct_tac "evs" 1);
   374 by (event.induct_tac "a" 2);
   375 by (ALLGOALS (fast_tac (!claset addDs [sees_Says_subset_insert RS subsetD] 
   376                                 addss (!simpset))));
   377 qed "sees_agent_subset_sees_Spy";
   378 
   379 (*The Spy can see more than anybody else who's lost their key!*)
   380 goal thy "A: lost --> A ~= Server --> sees lost A evs <= sees lost Spy evs";
   381 by (list.induct_tac "evs" 1);
   382 by (event.induct_tac "a" 2);
   383 by (agent.induct_tac "A" 1);
   384 by (auto_tac (!claset addDs [sees_Says_subset_insert RS subsetD], (!simpset)));
   385 qed_spec_mp "sees_lost_agent_subset_sees_Spy";
   386 
   387 
   388 (** Simplifying   parts (insert X (sees lost A evs))
   389       = parts {X} Un parts (sees lost A evs) -- since general case loops*)
   390 
   391 val parts_insert_sees = 
   392     parts_insert |> read_instantiate_sg (sign_of thy)
   393                                         [("H", "sees lost A evs")]
   394                  |> standard;
   395 
   396 
   397 (*** Specialized rewriting for analz_insert_Key_newK ***)
   398 
   399 (*Push newK applications in, allowing other keys to be pulled out*)
   400 val pushKey_newK = insComm thy "Key (newK ?evs)"  "Key (shrK ?C)";
   401 
   402 goal thy "!!A. A <= Compl (range shrK) ==> shrK x ~: A";
   403 by (Blast_tac 1);
   404 qed "subset_Compl_range";
   405 
   406 goal thy "insert (Key K) H = Key `` {K} Un H";
   407 by (Blast_tac 1);
   408 qed "insert_Key_singleton";
   409 
   410 goal thy "insert (Key K) (Key``KK Un C) = Key `` (insert K KK) Un C";
   411 by (Blast_tac 1);
   412 qed "insert_Key_image";
   413 
   414 val analz_image_freshK_ss = 
   415      !simpset delsimps [image_insert, image_Un]
   416               addsimps ([image_insert RS sym, image_Un RS sym,
   417                          Key_not_used, 
   418                          insert_Key_singleton, subset_Compl_range,
   419                          insert_Key_image, Un_assoc RS sym]
   420                         @disj_comms)
   421               setloop split_tac [expand_if];
   422 
   423 (*Lemma for the trivial direction of the if-and-only-if*)
   424 goal thy  
   425  "!!evs. (Key K : analz (Key``nE Un H)) --> (K : nE | Key K : analz H)  ==> \
   426 \        (Key K : analz (Key``nE Un H)) = (K : nE | Key K : analz H)";
   427 by (fast_tac (!claset addSEs [impOfSubs analz_mono]) 1);
   428 qed "analz_image_freshK_lemma";