src/HOL/Auth/Shared.ML
author paulson
Fri Jul 04 17:34:55 1997 +0200 (1997-07-04)
changeset 3500 0d8ad2f192d8
parent 3479 2aacd6f10654
child 3512 9dcb4daa15e8
permissions -rw-r--r--
New constant "certificate"--just an abbreviation
     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; freshness; 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 ***)
    28 
    29 (*Injectiveness: Agents' long-term keys are distinct.*)
    30 AddIffs [inj_shrK RS inj_eq];
    31 
    32 (* invKey(shrK A) = shrK A *)
    33 Addsimps [rewrite_rule [isSymKey_def] isSym_keys];
    34 
    35 (** Rewrites should not refer to  initState(Friend i) 
    36     -- not in normal form! **)
    37 
    38 goalw thy [keysFor_def] "keysFor (parts (initState lost C)) = {}";
    39 by (agent.induct_tac "C" 1);
    40 by (Auto_tac ());
    41 qed "keysFor_parts_initState";
    42 Addsimps [keysFor_parts_initState];
    43 
    44 goalw thy [keysFor_def] "keysFor (Key``E) = {}";
    45 by (Auto_tac ());
    46 qed "keysFor_image_Key";
    47 Addsimps [keysFor_image_Key];
    48 
    49 
    50 (*** Function "sees" ***)
    51 
    52 goal thy
    53     "!!evs. lost' <= lost ==> sees lost' A evs <= sees lost A evs";
    54 by (list.induct_tac "evs" 1);
    55 by (agent.induct_tac "A" 1);
    56 by (event.induct_tac "a" 2);
    57 by (Auto_tac ());
    58 qed "sees_mono";
    59 
    60 (*Agents see their own shared keys!*)
    61 goal thy "A ~= Spy --> Key (shrK A) : sees lost A evs";
    62 by (list.induct_tac "evs" 1);
    63 by (agent.induct_tac "A" 1);
    64 by (Auto_tac ());
    65 qed_spec_mp "sees_own_shrK";
    66 
    67 (*Spy sees shared keys of lost agents!*)
    68 goal thy "!!A. A: lost ==> Key (shrK A) : sees lost Spy evs";
    69 by (list.induct_tac "evs" 1);
    70 by (Auto_tac());
    71 qed "Spy_sees_lost";
    72 
    73 AddSIs [sees_own_shrK, Spy_sees_lost];
    74 
    75 (** Specialized rewrite rules for (sees lost A (Says...#evs)) **)
    76 
    77 goal thy "sees lost B (Says A B X # evs) = insert X (sees lost B evs)";
    78 by (Simp_tac 1);
    79 qed "sees_own";
    80 
    81 goal thy "!!A. Server ~= B ==> \
    82 \          sees lost Server (Says A B X # evs) = sees lost Server evs";
    83 by (Asm_simp_tac 1);
    84 qed "sees_Server";
    85 
    86 goal thy "!!A. Friend i ~= B ==> \
    87 \          sees lost (Friend i) (Says A B X # evs) = sees lost (Friend i) evs";
    88 by (Asm_simp_tac 1);
    89 qed "sees_Friend";
    90 
    91 goal thy "sees lost Spy (Says A B X # evs) = insert X (sees lost Spy evs)";
    92 by (Simp_tac 1);
    93 qed "sees_Spy";
    94 
    95 goal thy "sees lost A (Says A' B X # evs) <= insert X (sees lost A evs)";
    96 by (simp_tac (!simpset setloop split_tac [expand_if]) 1);
    97 by (Blast_tac 1);
    98 qed "sees_Says_subset_insert";
    99 
   100 goal thy "sees lost A evs <= sees lost A (Says A' B X # evs)";
   101 by (simp_tac (!simpset setloop split_tac [expand_if]) 1);
   102 by (Blast_tac 1);
   103 qed "sees_subset_sees_Says";
   104 
   105 (*Pushing Unions into parts.  One of the agents A is B, and thus sees Y.
   106   Once used to prove new_keys_not_seen; now obsolete.*)
   107 goal thy "(UN A. parts (sees lost A (Says B C Y # evs))) = \
   108 \         parts {Y} Un (UN A. parts (sees lost A evs))";
   109 by (Step_tac 1);
   110 by (etac rev_mp 1);     (*split_tac does not work on assumptions*)
   111 by (ALLGOALS
   112     (fast_tac (!claset addss (!simpset addsimps [parts_Un, sees_Cons] 
   113 				            setloop split_tac [expand_if]))));
   114 qed "UN_parts_sees_Says";
   115 
   116 goal thy "Says A B X : set evs --> X : sees lost Spy evs";
   117 by (list.induct_tac "evs" 1);
   118 by (Auto_tac ());
   119 qed_spec_mp "Says_imp_sees_Spy";
   120 
   121 (*Use with addSEs to derive contradictions from old Says events containing
   122   items known to be fresh*)
   123 val sees_Spy_partsEs = make_elim (Says_imp_sees_Spy RS parts.Inj):: partsEs;
   124 
   125 (*For not_lost_tac*)
   126 goal thy "!!A. [| Crypt (shrK A) X : analz (sees lost Spy evs);  A: lost |] \
   127 \              ==> X : analz (sees lost Spy evs)";
   128 by (fast_tac (!claset addSDs [analz.Decrypt] addss (!simpset)) 1);
   129 qed "Crypt_Spy_analz_lost";
   130 
   131 (*Prove that the agent is uncompromised by the confidentiality of 
   132   a component of a message she's said.*)
   133 fun not_lost_tac s =
   134     case_tac ("(" ^ s ^ ") : lost") THEN'
   135     SELECT_GOAL 
   136       (REPEAT_DETERM (dtac (Says_imp_sees_Spy RS analz.Inj) 1) THEN
   137        REPEAT_DETERM (etac MPair_analz 1) THEN
   138        THEN_BEST_FIRST 
   139          (dres_inst_tac [("A", s)] Crypt_Spy_analz_lost 1 THEN assume_tac 1)
   140          (has_fewer_prems 1, size_of_thm)
   141          (Step_tac 1));
   142 
   143 Addsimps [sees_own, sees_Server, sees_Friend, sees_Spy];
   144 Delsimps [sees_Cons];   (**** NOTE REMOVAL -- laws above are cleaner ****)
   145 
   146 
   147 (*** Fresh nonces ***)
   148 
   149 goal thy "Nonce N ~: parts (initState lost B)";
   150 by (agent.induct_tac "B" 1);
   151 by (Auto_tac ());
   152 qed "Nonce_notin_initState";
   153 
   154 AddIffs [Nonce_notin_initState];
   155 
   156 goalw thy [used_def] "!!X. X: parts (sees lost B evs) ==> X: used evs";
   157 by (etac (impOfSubs parts_mono) 1);
   158 by (Blast_tac 1);
   159 qed "usedI";
   160 
   161 AddIs [usedI];
   162 
   163 (** Fresh keys never clash with long-term shared keys **)
   164 
   165 goal thy "Key (shrK A) : used evs";
   166 by (Blast_tac 1);
   167 qed "shrK_in_used";
   168 AddIffs [shrK_in_used];
   169 
   170 (*Used in parts_induct_tac and analz_Fake_tac to distinguish session keys
   171   from long-term shared keys*)
   172 goal thy "!!K. Key K ~: used evs ==> K ~: range shrK";
   173 by (Blast_tac 1);
   174 qed "Key_not_used";
   175 
   176 (*A session key cannot clash with a long-term shared key*)
   177 goal thy "!!K. K ~: range shrK ==> shrK B ~= K";
   178 by (Blast_tac 1);
   179 qed "shrK_neq";
   180 
   181 Addsimps [Key_not_used, shrK_neq, shrK_neq RS not_sym];
   182 
   183 
   184 goal thy "used (Says A B X # evs) = parts{X} Un used evs";
   185 by (simp_tac (!simpset addsimps [used_def, UN_parts_sees_Says]) 1);
   186 qed "used_Says";
   187 Addsimps [used_Says];
   188 
   189 goal thy "used [] <= used l";
   190 by (list.induct_tac "l" 1);
   191 by (event.induct_tac "a" 2);
   192 by (ALLGOALS Asm_simp_tac);
   193 by (Blast_tac 1);
   194 qed "used_nil_subset";
   195 
   196 goal thy "used l <= used (l@l')";
   197 by (list.induct_tac "l" 1);
   198 by (simp_tac (!simpset addsimps [used_nil_subset]) 1);
   199 by (event.induct_tac "a" 1);
   200 by (Asm_simp_tac 1);
   201 by (Blast_tac 1);
   202 qed "used_subset_append";
   203 
   204 
   205 (*** Supply fresh nonces for possibility theorems. ***)
   206 
   207 goalw thy [used_def] "EX N. ALL n. N<=n --> Nonce n ~: used evs";
   208 by (list.induct_tac "evs" 1);
   209 by (res_inst_tac [("x","0")] exI 1);
   210 by (Step_tac 1);
   211 by (Full_simp_tac 1);
   212 (*Inductive step*)
   213 by (event.induct_tac "a" 1);
   214 by (full_simp_tac (!simpset addsimps [UN_parts_sees_Says]) 1);
   215 by (msg.induct_tac "msg" 1);
   216 by (ALLGOALS (asm_simp_tac (!simpset addsimps [exI, parts_insert2])));
   217 by (Step_tac 1);
   218 (*MPair case*)
   219 by (res_inst_tac [("x","Na+Nb")] exI 2);
   220 by (blast_tac (!claset addSEs [add_leE]) 2);
   221 (*Nonce case*)
   222 by (res_inst_tac [("x","N + Suc nat")] exI 1);
   223 by (fast_tac (!claset addSEs [add_leE] addaltern trans_tac) 1);
   224 val lemma = result();
   225 
   226 goal thy "EX N. Nonce N ~: used evs";
   227 by (rtac (lemma RS exE) 1);
   228 by (Blast_tac 1);
   229 qed "Nonce_supply1";
   230 
   231 goal thy "EX N N'. Nonce N ~: used evs & Nonce N' ~: used evs' & N ~= N'";
   232 by (cut_inst_tac [("evs","evs")] lemma 1);
   233 by (cut_inst_tac [("evs","evs'")] lemma 1);
   234 by (Step_tac 1);
   235 by (res_inst_tac [("x","N")] exI 1);
   236 by (res_inst_tac [("x","Suc (N+Na)")] exI 1);
   237 by (asm_simp_tac (!simpset addsimps [less_not_refl2 RS not_sym, 
   238 				     le_add2, le_add1, 
   239 				     le_eq_less_Suc RS sym]) 1);
   240 qed "Nonce_supply2";
   241 
   242 goal thy "EX N N' N''. Nonce N ~: used evs & Nonce N' ~: used evs' & \
   243 \                   Nonce N'' ~: used evs'' & N ~= N' & N' ~= N'' & N ~= N''";
   244 by (cut_inst_tac [("evs","evs")] lemma 1);
   245 by (cut_inst_tac [("evs","evs'")] lemma 1);
   246 by (cut_inst_tac [("evs","evs''")] lemma 1);
   247 by (Step_tac 1);
   248 by (res_inst_tac [("x","N")] exI 1);
   249 by (res_inst_tac [("x","Suc (N+Na)")] exI 1);
   250 by (res_inst_tac [("x","Suc (Suc (N+Na+Nb))")] exI 1);
   251 by (asm_simp_tac (!simpset addsimps [less_not_refl2 RS not_sym, 
   252 				     le_add2, le_add1, 
   253 				     le_eq_less_Suc RS sym]) 1);
   254 by (rtac (less_trans RS less_not_refl2 RS not_sym) 1);
   255 by (stac (le_eq_less_Suc RS sym) 1);
   256 by (asm_simp_tac (!simpset addsimps [le_eq_less_Suc RS sym]) 2);
   257 by (REPEAT (rtac le_add1 1));
   258 qed "Nonce_supply3";
   259 
   260 goal thy "Nonce (@ N. Nonce N ~: used evs) ~: used evs";
   261 by (rtac (lemma RS exE) 1);
   262 by (rtac selectI 1);
   263 by (Blast_tac 1);
   264 qed "Nonce_supply";
   265 
   266 (*** Supply fresh keys for possibility theorems. ***)
   267 
   268 goal thy "EX K. Key K ~: used evs";
   269 by (rtac (Finites.emptyI RS Key_supply_ax RS exE) 1);
   270 by (Blast_tac 1);
   271 qed "Key_supply1";
   272 
   273 goal thy "EX K K'. Key K ~: used evs & Key K' ~: used evs' & K ~= K'";
   274 by (cut_inst_tac [("evs","evs")] (Finites.emptyI RS Key_supply_ax) 1);
   275 by (etac exE 1);
   276 by (cut_inst_tac [("evs","evs'")] 
   277     (Finites.emptyI RS Finites.insertI RS Key_supply_ax) 1);
   278 by (Auto_tac());
   279 qed "Key_supply2";
   280 
   281 goal thy "EX K K' K''. Key K ~: used evs & Key K' ~: used evs' & \
   282 \                      Key K'' ~: used evs'' & K ~= K' & K' ~= K'' & K ~= K''";
   283 by (cut_inst_tac [("evs","evs")] (Finites.emptyI RS Key_supply_ax) 1);
   284 by (etac exE 1);
   285 by (cut_inst_tac [("evs","evs'")] 
   286     (Finites.emptyI RS Finites.insertI RS Key_supply_ax) 1);
   287 by (etac exE 1);
   288 by (cut_inst_tac [("evs","evs''")] 
   289     (Finites.emptyI RS Finites.insertI RS Finites.insertI RS Key_supply_ax) 1);
   290 by (Step_tac 1);
   291 by (Full_simp_tac 1);
   292 by (fast_tac (!claset addSEs [allE]) 1);
   293 qed "Key_supply3";
   294 
   295 goal thy "Key (@ K. Key K ~: used evs) ~: used evs";
   296 by (rtac (Finites.emptyI RS Key_supply_ax RS exE) 1);
   297 by (rtac selectI 1);
   298 by (Blast_tac 1);
   299 qed "Key_supply";
   300 
   301 (*** Tactics for possibility theorems ***)
   302 
   303 val possibility_tac =
   304     REPEAT (*omit used_Says so that Nonces, Keys start from different traces!*)
   305     (ALLGOALS (simp_tac 
   306                (!simpset delsimps [used_Says] setSolver safe_solver))
   307      THEN
   308      REPEAT_FIRST (eq_assume_tac ORELSE' 
   309                    resolve_tac [refl, conjI, Nonce_supply, Key_supply]));
   310 
   311 (*For harder protocols (such as Recur) where we have to set up some
   312   nonces and keys initially*)
   313 val basic_possibility_tac =
   314     REPEAT 
   315     (ALLGOALS (asm_simp_tac (!simpset setSolver safe_solver))
   316      THEN
   317      REPEAT_FIRST (resolve_tac [refl, conjI]));
   318 
   319 
   320 (** Power of the Spy **)
   321 
   322 (*The Spy can see more than anybody else, except for their initial state*)
   323 goal thy "sees lost A evs <= initState lost A Un sees lost Spy evs";
   324 by (list.induct_tac "evs" 1);
   325 by (event.induct_tac "a" 2);
   326 by (ALLGOALS Asm_simp_tac);
   327 by (ALLGOALS (blast_tac (!claset addDs [sees_Says_subset_insert RS subsetD])));
   328 qed "sees_agent_subset_sees_Spy";
   329 
   330 (*The Spy can see more than anybody else who's lost their key!*)
   331 goal thy "A: lost --> A ~= Server --> sees lost A evs <= sees lost Spy evs";
   332 by (list.induct_tac "evs" 1);
   333 by (event.induct_tac "a" 2);
   334 by (agent.induct_tac "A" 1);
   335 by (ALLGOALS Asm_simp_tac);
   336 by (ALLGOALS (blast_tac (!claset addDs [sees_Says_subset_insert RS subsetD])));
   337 qed_spec_mp "sees_lost_agent_subset_sees_Spy";
   338 
   339 
   340 (** Simplifying   parts (insert X (sees lost A evs))
   341       = parts {X} Un parts (sees lost A evs) -- since general case loops*)
   342 
   343 val parts_insert_sees = 
   344     parts_insert |> read_instantiate_sg (sign_of thy)
   345                                         [("H", "sees lost A evs")]
   346                  |> standard;
   347 
   348 
   349 (*** Specialized rewriting for analz_insert_freshK ***)
   350 
   351 goal thy "!!A. A <= Compl (range shrK) ==> shrK x ~: A";
   352 by (Blast_tac 1);
   353 qed "subset_Compl_range";
   354 
   355 goal thy "insert (Key K) H = Key `` {K} Un H";
   356 by (Blast_tac 1);
   357 qed "insert_Key_singleton";
   358 
   359 goal thy "insert (Key K) (Key``KK Un C) = Key `` (insert K KK) Un C";
   360 by (Blast_tac 1);
   361 qed "insert_Key_image";
   362 
   363 (*Reverse the normal simplification of "image" to build up (not break down)
   364   the set of keys.  Use analz_insert_eq with (Un_upper2 RS analz_mono) to
   365   erase occurrences of forwarded message components (X).*)
   366 val analz_image_freshK_ss = 
   367      !simpset delsimps [image_insert, image_Un]
   368               addsimps ([image_insert RS sym, image_Un RS sym,
   369                          analz_insert_eq, impOfSubs (Un_upper2 RS analz_mono),
   370                          insert_Key_singleton, subset_Compl_range,
   371                          Key_not_used, insert_Key_image, Un_assoc RS sym]
   372                         @disj_comms)
   373               setloop split_tac [expand_if];
   374 
   375 (*Lemma for the trivial direction of the if-and-only-if*)
   376 goal thy  
   377  "!!evs. (Key K : analz (Key``nE Un H)) --> (K : nE | Key K : analz H)  ==> \
   378 \        (Key K : analz (Key``nE Un H)) = (K : nE | Key K : analz H)";
   379 by (blast_tac (!claset addIs [impOfSubs analz_mono]) 1);
   380 qed "analz_image_freshK_lemma";