src/HOL/Auth/Yahalom.ML
author paulson
Fri Sep 13 13:16:57 1996 +0200 (1996-09-13)
changeset 1995 c80e58e78d9c
parent 1985 84cf16192e03
child 2001 974167c1d2c4
permissions -rw-r--r--
Addition of Yahalom protocol
paulson@1995
     1
(*  Title:      HOL/Auth/Yahalom
paulson@1985
     2
    ID:         $Id$
paulson@1985
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@1985
     4
    Copyright   1996  University of Cambridge
paulson@1985
     5
paulson@1985
     6
Inductive relation "otway" for the Yahalom protocol.
paulson@1985
     7
paulson@1985
     8
From page 257 of
paulson@1985
     9
  Burrows, Abadi and Needham.  A Logic of Authentication.
paulson@1985
    10
  Proc. Royal Soc. 426 (1989)
paulson@1985
    11
*)
paulson@1985
    12
paulson@1995
    13
open Yahalom;
paulson@1985
    14
paulson@1985
    15
proof_timing:=true;
paulson@1985
    16
HOL_quantifiers := false;
paulson@1985
    17
paulson@1995
    18
paulson@1995
    19
(** Weak liveness: there are traces that reach the end **)
paulson@1995
    20
paulson@1995
    21
goal thy 
paulson@1995
    22
 "!!A B. [| A ~= B; A ~= Server; B ~= Server |]   \
paulson@1995
    23
\        ==> EX X NB K. EX evs: yahalom.          \
paulson@1995
    24
\               Says A B {|X, Crypt (Nonce NB) K|} : set_of_list evs";
paulson@1995
    25
by (REPEAT (resolve_tac [exI,bexI] 1));
paulson@1995
    26
br (yahalom.Nil RS yahalom.YM1 RS yahalom.YM2 RS yahalom.YM3 RS yahalom.YM4) 2;
paulson@1995
    27
by (ALLGOALS (simp_tac (!simpset setsolver safe_solver)));
paulson@1995
    28
by (ALLGOALS Fast_tac);
paulson@1995
    29
qed "weak_liveness";
paulson@1995
    30
paulson@1995
    31
paulson@1985
    32
(**** Inductive proofs about yahalom ****)
paulson@1985
    33
paulson@1985
    34
(*The Enemy can see more than anybody else, except for their initial state*)
paulson@1985
    35
goal thy 
paulson@1985
    36
 "!!evs. evs : yahalom ==> \
paulson@1985
    37
\     sees A evs <= initState A Un sees Enemy evs";
paulson@1985
    38
be yahalom.induct 1;
paulson@1985
    39
by (ALLGOALS (fast_tac (!claset addDs [sees_Says_subset_insert RS subsetD] 
paulson@1985
    40
			        addss (!simpset))));
paulson@1985
    41
qed "sees_agent_subset_sees_Enemy";
paulson@1985
    42
paulson@1985
    43
paulson@1985
    44
(*Nobody sends themselves messages*)
paulson@1985
    45
goal thy "!!evs. evs : yahalom ==> ALL A X. Says A A X ~: set_of_list evs";
paulson@1985
    46
be yahalom.induct 1;
paulson@1985
    47
by (Auto_tac());
paulson@1985
    48
qed_spec_mp "not_Says_to_self";
paulson@1985
    49
Addsimps [not_Says_to_self];
paulson@1985
    50
AddSEs   [not_Says_to_self RSN (2, rev_notE)];
paulson@1985
    51
paulson@1985
    52
goal thy "!!evs. evs : yahalom ==> Notes A X ~: set_of_list evs";
paulson@1985
    53
be yahalom.induct 1;
paulson@1985
    54
by (Auto_tac());
paulson@1985
    55
qed "not_Notes";
paulson@1985
    56
Addsimps [not_Notes];
paulson@1985
    57
AddSEs   [not_Notes RSN (2, rev_notE)];
paulson@1985
    58
paulson@1985
    59
paulson@1985
    60
(** For reasoning about the encrypted portion of messages **)
paulson@1985
    61
paulson@1995
    62
(*Lets us treat YM4 using a similar argument as for the Fake case.*)
paulson@1995
    63
goal thy "!!evs. Says S A {|Crypt Y (shrK A), X|} : set_of_list evs ==> \
paulson@1985
    64
\                X : analz (sees Enemy evs)";
paulson@1985
    65
by (fast_tac (!claset addSDs [Says_imp_sees_Enemy RS analz.Inj]) 1);
paulson@1985
    66
qed "YM4_analz_sees_Enemy";
paulson@1985
    67
paulson@1995
    68
goal thy "!!evs. Says S A {|Crypt {|B, K, NA, NB|} (shrK A), X|} \
paulson@1995
    69
\                  : set_of_list evs ==> \
paulson@1985
    70
\                K : parts (sees Enemy evs)";
paulson@1985
    71
by (fast_tac (!claset addSEs partsEs
paulson@1985
    72
	              addSDs [Says_imp_sees_Enemy RS parts.Inj]) 1);
paulson@1995
    73
qed "YM4_parts_sees_Enemy";
paulson@1985
    74
paulson@1985
    75
paulson@1985
    76
paulson@1985
    77
(*** Shared keys are not betrayed ***)
paulson@1985
    78
paulson@1985
    79
(*Enemy never sees another agent's shared key! (unless it is leaked at start)*)
paulson@1985
    80
goal thy 
paulson@1985
    81
 "!!evs. [| evs : yahalom;  A ~: bad |] ==> \
paulson@1985
    82
\        Key (shrK A) ~: parts (sees Enemy evs)";
paulson@1985
    83
be yahalom.induct 1;
paulson@1995
    84
bd (YM4_analz_sees_Enemy RS synth.Inj) 6;
paulson@1995
    85
by (ALLGOALS Asm_simp_tac);
paulson@1995
    86
by (stac insert_commute 3);
paulson@1985
    87
by (Auto_tac());
paulson@1995
    88
(*Fake and YM4 are similar*)
paulson@1995
    89
by (ALLGOALS (best_tac (!claset addSDs [impOfSubs analz_subset_parts,
paulson@1995
    90
					impOfSubs Fake_parts_insert])));
paulson@1985
    91
qed "Enemy_not_see_shrK";
paulson@1985
    92
paulson@1985
    93
bind_thm ("Enemy_not_analz_shrK",
paulson@1985
    94
	  [analz_subset_parts, Enemy_not_see_shrK] MRS contra_subsetD);
paulson@1985
    95
paulson@1985
    96
Addsimps [Enemy_not_see_shrK, Enemy_not_analz_shrK];
paulson@1985
    97
paulson@1985
    98
(*We go to some trouble to preserve R in the 3rd and 4th subgoals
paulson@1985
    99
  As usual fast_tac cannot be used because it uses the equalities too soon*)
paulson@1985
   100
val major::prems = 
paulson@1985
   101
goal thy  "[| Key (shrK A) : parts (sees Enemy evs);       \
paulson@1995
   102
\             evs : yahalom;                               \
paulson@1985
   103
\             A:bad ==> R                                  \
paulson@1985
   104
\           |] ==> R";
paulson@1985
   105
br ccontr 1;
paulson@1985
   106
br ([major, Enemy_not_see_shrK] MRS rev_notE) 1;
paulson@1985
   107
by (swap_res_tac prems 2);
paulson@1985
   108
by (ALLGOALS (fast_tac (!claset addIs prems)));
paulson@1985
   109
qed "Enemy_see_shrK_E";
paulson@1985
   110
paulson@1985
   111
bind_thm ("Enemy_analz_shrK_E", 
paulson@1985
   112
	  analz_subset_parts RS subsetD RS Enemy_see_shrK_E);
paulson@1985
   113
paulson@1985
   114
AddSEs [Enemy_see_shrK_E, Enemy_analz_shrK_E];
paulson@1985
   115
paulson@1985
   116
paulson@1985
   117
(*** Future keys can't be seen or used! ***)
paulson@1985
   118
paulson@1985
   119
(*Nobody can have SEEN keys that will be generated in the future.
paulson@1985
   120
  This has to be proved anew for each protocol description,
paulson@1985
   121
  but should go by similar reasoning every time.  Hardest case is the
paulson@1985
   122
  standard Fake rule.  
paulson@1985
   123
      The length comparison, and Union over C, are essential for the 
paulson@1985
   124
  induction! *)
paulson@1985
   125
goal thy "!!evs. evs : yahalom ==> \
paulson@1985
   126
\                length evs <= length evs' --> \
paulson@1985
   127
\                          Key (newK evs') ~: (UN C. parts (sees C evs))";
paulson@1985
   128
be yahalom.induct 1;
paulson@1995
   129
bd (YM4_analz_sees_Enemy RS synth.Inj) 6;
paulson@1985
   130
by (REPEAT_FIRST (best_tac (!claset addDs [impOfSubs analz_subset_parts,
paulson@1995
   131
					   impOfSubs parts_insert_subset_Un,
paulson@1995
   132
					   Suc_leD]
paulson@1995
   133
			            addss (!simpset))));
paulson@1985
   134
val lemma = result();
paulson@1985
   135
paulson@1985
   136
(*Variant needed for the main theorem below*)
paulson@1985
   137
goal thy 
paulson@1985
   138
 "!!evs. [| evs : yahalom;  length evs <= length evs' |] ==> \
paulson@1985
   139
\        Key (newK evs') ~: parts (sees C evs)";
paulson@1985
   140
by (fast_tac (!claset addDs [lemma]) 1);
paulson@1985
   141
qed "new_keys_not_seen";
paulson@1985
   142
Addsimps [new_keys_not_seen];
paulson@1985
   143
paulson@1985
   144
(*Another variant: old messages must contain old keys!*)
paulson@1985
   145
goal thy 
paulson@1985
   146
 "!!evs. [| Says A B X : set_of_list evs;  \
paulson@1985
   147
\           Key (newK evt) : parts {X};    \
paulson@1985
   148
\           evs : yahalom                 \
paulson@1985
   149
\        |] ==> length evt < length evs";
paulson@1985
   150
br ccontr 1;
paulson@1985
   151
by (fast_tac (!claset addSDs [new_keys_not_seen, Says_imp_sees_Enemy]
paulson@1985
   152
	              addIs [impOfSubs parts_mono, leI]) 1);
paulson@1985
   153
qed "Says_imp_old_keys";
paulson@1985
   154
paulson@1985
   155
paulson@1985
   156
(*Nobody can have USED keys that will be generated in the future.
paulson@1985
   157
  ...very like new_keys_not_seen*)
paulson@1985
   158
goal thy "!!evs. evs : yahalom ==> \
paulson@1985
   159
\                length evs <= length evs' --> \
paulson@1985
   160
\                newK evs' ~: keysFor (UN C. parts (sees C evs))";
paulson@1985
   161
be yahalom.induct 1;
paulson@1995
   162
by (forward_tac [YM4_parts_sees_Enemy] 6);
paulson@1995
   163
bd (YM4_analz_sees_Enemy RS synth.Inj) 6;
paulson@1995
   164
by (ALLGOALS Asm_full_simp_tac);
paulson@1995
   165
(*YM1, YM2 and YM3*)
paulson@1995
   166
by (EVERY (map (fast_tac (!claset addDs [Suc_leD] addss (!simpset))) [4,3,2]));
paulson@1995
   167
(*Fake and YM4: these messages send unknown (X) components*)
paulson@1995
   168
by (stac insert_commute 2);
paulson@1995
   169
by (Simp_tac 2);
paulson@1995
   170
(*YM4: the only way K could have been used is if it had been seen,
paulson@1995
   171
  contradicting new_keys_not_seen*)
paulson@1995
   172
by (ALLGOALS
paulson@1985
   173
     (best_tac
paulson@1995
   174
      (!claset addDs [impOfSubs (analz_subset_parts RS keysFor_mono),
paulson@1985
   175
		      impOfSubs (parts_insert_subset_Un RS keysFor_mono),
paulson@1985
   176
		      Suc_leD]
paulson@1995
   177
	       addDs [impOfSubs analz_subset_parts]
paulson@1995
   178
	       addEs [new_keys_not_seen RSN(2,rev_notE)]
paulson@1995
   179
	       addss (!simpset))));
paulson@1985
   180
val lemma = result();
paulson@1985
   181
paulson@1985
   182
goal thy 
paulson@1985
   183
 "!!evs. [| evs : yahalom;  length evs <= length evs' |] ==> \
paulson@1985
   184
\        newK evs' ~: keysFor (parts (sees C evs))";
paulson@1985
   185
by (fast_tac (!claset addSDs [lemma] addss (!simpset)) 1);
paulson@1985
   186
qed "new_keys_not_used";
paulson@1985
   187
paulson@1985
   188
bind_thm ("new_keys_not_analzd",
paulson@1985
   189
	  [analz_subset_parts RS keysFor_mono,
paulson@1985
   190
	   new_keys_not_used] MRS contra_subsetD);
paulson@1985
   191
paulson@1985
   192
Addsimps [new_keys_not_used, new_keys_not_analzd];
paulson@1985
   193
paulson@1985
   194
paulson@1985
   195
(** Lemmas concerning the form of items passed in messages **)
paulson@1985
   196
paulson@1985
   197
paulson@1985
   198
(****
paulson@1985
   199
 The following is to prove theorems of the form
paulson@1985
   200
paulson@1985
   201
          Key K : analz (insert (Key (newK evt)) (sees Enemy evs)) ==>
paulson@1985
   202
          Key K : analz (sees Enemy evs)
paulson@1985
   203
paulson@1985
   204
 A more general formula must be proved inductively.
paulson@1985
   205
paulson@1985
   206
****)
paulson@1985
   207
paulson@1985
   208
paulson@1985
   209
(*NOT useful in this form, but it says that session keys are not used
paulson@1985
   210
  to encrypt messages containing other keys, in the actual protocol.
paulson@1985
   211
  We require that agents should behave like this subsequently also.*)
paulson@1985
   212
goal thy 
paulson@1985
   213
 "!!evs. evs : yahalom ==> \
paulson@1985
   214
\        (Crypt X (newK evt)) : parts (sees Enemy evs) & \
paulson@1985
   215
\        Key K : parts {X} --> Key K : parts (sees Enemy evs)";
paulson@1985
   216
be yahalom.induct 1;
paulson@1995
   217
bd (YM4_analz_sees_Enemy RS synth.Inj) 6;
paulson@1985
   218
by (ALLGOALS (asm_simp_tac (!simpset addsimps pushes)));
paulson@1985
   219
(*Deals with Faked messages*)
paulson@1995
   220
by (EVERY 
paulson@1995
   221
    (map (best_tac (!claset addSEs partsEs
paulson@1995
   222
			    addDs [impOfSubs analz_subset_parts,
paulson@1995
   223
				   impOfSubs parts_insert_subset_Un]
paulson@1995
   224
			    addss (!simpset)))
paulson@1995
   225
     [3,2]));
paulson@1995
   226
(*Base case*)
paulson@1985
   227
by (Auto_tac());
paulson@1985
   228
result();
paulson@1985
   229
paulson@1985
   230
paulson@1985
   231
(** Specialized rewriting for this proof **)
paulson@1985
   232
paulson@1985
   233
Delsimps [image_insert];
paulson@1985
   234
Addsimps [image_insert RS sym];
paulson@1985
   235
paulson@1985
   236
Delsimps [image_Un];
paulson@1985
   237
Addsimps [image_Un RS sym];
paulson@1985
   238
paulson@1985
   239
goal thy "insert (Key (newK x)) (sees A evs) = \
paulson@1985
   240
\         Key `` (newK``{x}) Un (sees A evs)";
paulson@1985
   241
by (Fast_tac 1);
paulson@1985
   242
val insert_Key_singleton = result();
paulson@1985
   243
paulson@1985
   244
goal thy "insert (Key (f x)) (Key``(f``E) Un C) = \
paulson@1985
   245
\         Key `` (f `` (insert x E)) Un C";
paulson@1985
   246
by (Fast_tac 1);
paulson@1985
   247
val insert_Key_image = result();
paulson@1985
   248
paulson@1985
   249
paulson@1985
   250
(*This lets us avoid analyzing the new message -- unless we have to!*)
paulson@1985
   251
(*NEEDED??*)
paulson@1985
   252
goal thy "synth (analz (sees Enemy evs)) <=   \
paulson@1985
   253
\         synth (analz (sees Enemy (Says A B X # evs)))";
paulson@1985
   254
by (Simp_tac 1);
paulson@1985
   255
br (subset_insertI RS analz_mono RS synth_mono) 1;
paulson@1985
   256
qed "synth_analz_thin";
paulson@1985
   257
paulson@1985
   258
AddIs [impOfSubs synth_analz_thin];
paulson@1985
   259
paulson@1985
   260
paulson@1985
   261
paulson@1985
   262
(** Session keys are not used to encrypt other session keys **)
paulson@1985
   263
paulson@1985
   264
(*Lemma for the trivial direction of the if-and-only-if*)
paulson@1985
   265
goal thy  
paulson@1985
   266
 "!!evs. (Key K : analz (Key``nE Un sEe)) --> \
paulson@1985
   267
\         (K : nE | Key K : analz sEe)  ==>     \
paulson@1985
   268
\        (Key K : analz (Key``nE Un sEe)) = (K : nE | Key K : analz sEe)";
paulson@1985
   269
by (fast_tac (!claset addSEs [impOfSubs analz_mono]) 1);
paulson@1985
   270
val lemma = result();
paulson@1985
   271
paulson@1985
   272
paulson@1985
   273
goal thy  
paulson@1985
   274
 "!!evs. evs : yahalom ==> \
paulson@1985
   275
\  ALL K E. (Key K : analz (Key``(newK``E) Un (sees Enemy evs))) = \
paulson@1985
   276
\           (K : newK``E | Key K : analz (sees Enemy evs))";
paulson@1985
   277
be yahalom.induct 1;
paulson@1985
   278
bd YM4_analz_sees_Enemy 6;
paulson@1985
   279
by (REPEAT_FIRST (resolve_tac [allI, lemma]));
paulson@1995
   280
by (ALLGOALS 
paulson@1985
   281
    (asm_simp_tac 
paulson@1985
   282
     (!simpset addsimps ([insert_Key_singleton, insert_Key_image, pushKey_newK]
paulson@1985
   283
			 @ pushes)
paulson@1985
   284
               setloop split_tac [expand_if])));
paulson@1985
   285
(*YM4*) 
paulson@1995
   286
by (enemy_analz_tac 4);
paulson@1985
   287
(*YM3*)
paulson@1995
   288
by (Fast_tac 3);
paulson@1995
   289
(*Fake case*)
paulson@1985
   290
by (enemy_analz_tac 2);
paulson@1985
   291
(*Base case*)
paulson@1985
   292
by (fast_tac (!claset addIs [image_eqI] addss (!simpset)) 1);
paulson@1985
   293
qed_spec_mp "analz_image_newK";
paulson@1985
   294
paulson@1985
   295
goal thy
paulson@1985
   296
 "!!evs. evs : yahalom ==>                               \
paulson@1985
   297
\        Key K : analz (insert (Key (newK evt)) (sees Enemy evs)) = \
paulson@1985
   298
\        (K = newK evt | Key K : analz (sees Enemy evs))";
paulson@1985
   299
by (asm_simp_tac (HOL_ss addsimps [pushKey_newK, analz_image_newK, 
paulson@1985
   300
				   insert_Key_singleton]) 1);
paulson@1985
   301
by (Fast_tac 1);
paulson@1985
   302
qed "analz_insert_Key_newK";
paulson@1985
   303
paulson@1985
   304
paulson@1985
   305
(*Describes the form *and age* of K when the following message is sent*)
paulson@1985
   306
goal thy 
paulson@1995
   307
 "!!evs. [| Says Server A                                           \
paulson@1995
   308
\            {|Crypt {|Agent B, K, NA, NB|} (shrK A),               \
paulson@1995
   309
\              Crypt {|Agent A, K|} (shrK B)|} : set_of_list evs;   \
paulson@1985
   310
\           evs : yahalom |]                                        \
paulson@1995
   311
\        ==> (EX evt:yahalom. K = Key(newK evt) &                   \
paulson@1995
   312
\                           length evt < length evs)";
paulson@1985
   313
be rev_mp 1;
paulson@1985
   314
be yahalom.induct 1;
paulson@1985
   315
by (ALLGOALS (fast_tac (!claset addIs [less_SucI] addss (!simpset))));
paulson@1985
   316
qed "Says_Server_message_form";
paulson@1985
   317
paulson@1985
   318
paulson@1995
   319
(*Crucial secrecy property: Enemy does not see the keys sent in msg YM3
paulson@1995
   320
  As with Otway-Rees, proof does not need uniqueness of session keys.*)
paulson@1985
   321
goal thy 
paulson@1985
   322
 "!!evs. [| Says Server A \
paulson@1995
   323
\            {|Crypt {|Agent B, K, NA, NB|} (shrK A),                   \
paulson@1995
   324
\              Crypt {|Agent A, K|} (shrK B)|} : set_of_list evs;       \
paulson@1995
   325
\           A ~: bad;  B ~: bad;  evs : yahalom |] ==>                  \
paulson@1985
   326
\     K ~: analz (sees Enemy evs)";
paulson@1985
   327
be rev_mp 1;
paulson@1985
   328
be yahalom.induct 1;
paulson@1985
   329
bd YM4_analz_sees_Enemy 6;
paulson@1985
   330
by (ALLGOALS Asm_simp_tac);
paulson@1985
   331
(*Next 3 steps infer that K has the form "Key (newK evs'" ... *)
paulson@1985
   332
by (REPEAT_FIRST (resolve_tac [conjI, impI]));
paulson@1985
   333
by (TRYALL (forward_tac [Says_Server_message_form] THEN' assume_tac));
paulson@1985
   334
by (REPEAT_FIRST (eresolve_tac [bexE, exE, conjE] ORELSE' hyp_subst_tac));
paulson@1985
   335
by (ALLGOALS
paulson@1985
   336
    (asm_full_simp_tac 
paulson@1985
   337
     (!simpset addsimps ([analz_subset_parts RS contra_subsetD,
paulson@1985
   338
			  analz_insert_Key_newK] @ pushes)
paulson@1985
   339
               setloop split_tac [expand_if])));
paulson@1995
   340
(*YM4*)
paulson@1995
   341
by (enemy_analz_tac 3);
paulson@1985
   342
(*YM3*)
paulson@1995
   343
by (fast_tac (!claset addSEs [less_irrefl]) 2);
paulson@1985
   344
(*Fake*) (** LEVEL 10 **)
paulson@1985
   345
by (enemy_analz_tac 1);
paulson@1985
   346
qed "Enemy_not_see_encrypted_key";