src/HOL/Auth/Yahalom.ML
author oheimb
Sat Feb 15 17:52:31 1997 +0100 (1997-02-15)
changeset 2637 e9b203f854ae
parent 2516 4d68fbe6378b
child 3121 cbb6c0c1c58a
permissions -rw-r--r--
reflecting my recent changes of the simplifier and classical reasoner
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@2516
    17
Pretty.setdepth 25;
paulson@1985
    18
oheimb@2637
    19
val op addss = op unsafe_addss;
oheimb@2637
    20
paulson@1995
    21
paulson@2322
    22
(*A "possibility property": there are traces that reach the end*)
paulson@1995
    23
goal thy 
paulson@1995
    24
 "!!A B. [| A ~= B; A ~= Server; B ~= Server |]   \
paulson@2032
    25
\        ==> EX X NB K. EX evs: yahalom lost.          \
paulson@2284
    26
\               Says A B {|X, Crypt K (Nonce NB)|} : set_of_list evs";
paulson@1995
    27
by (REPEAT (resolve_tac [exI,bexI] 1));
paulson@2516
    28
by (rtac (yahalom.Nil RS yahalom.YM1 RS yahalom.YM2 RS yahalom.YM3 RS 
paulson@2516
    29
          yahalom.YM4) 2);
paulson@2516
    30
by possibility_tac;
paulson@2013
    31
result();
paulson@1995
    32
paulson@1995
    33
paulson@1985
    34
(**** Inductive proofs about yahalom ****)
paulson@1985
    35
paulson@2110
    36
(*Monotonicity*)
paulson@2045
    37
goal thy "!!evs. lost' <= lost ==> yahalom lost' <= yahalom lost";
paulson@2045
    38
by (rtac subsetI 1);
paulson@2045
    39
by (etac yahalom.induct 1);
paulson@2045
    40
by (REPEAT_FIRST
paulson@2045
    41
    (best_tac (!claset addIs (impOfSubs (sees_mono RS analz_mono RS synth_mono)
paulson@2045
    42
                              :: yahalom.intrs))));
paulson@2045
    43
qed "yahalom_mono";
paulson@2045
    44
paulson@1985
    45
paulson@1985
    46
(*Nobody sends themselves messages*)
paulson@2051
    47
goal thy "!!evs. evs: yahalom lost ==> ALL A X. Says A A X ~: set_of_list evs";
paulson@2032
    48
by (etac yahalom.induct 1);
paulson@1985
    49
by (Auto_tac());
paulson@1985
    50
qed_spec_mp "not_Says_to_self";
paulson@1985
    51
Addsimps [not_Says_to_self];
paulson@1985
    52
AddSEs   [not_Says_to_self RSN (2, rev_notE)];
paulson@1985
    53
paulson@1985
    54
paulson@1985
    55
(** For reasoning about the encrypted portion of messages **)
paulson@1985
    56
paulson@1995
    57
(*Lets us treat YM4 using a similar argument as for the Fake case.*)
paulson@2284
    58
goal thy "!!evs. Says S A {|Crypt (shrK A) Y, X|} : set_of_list evs ==> \
paulson@2032
    59
\                X : analz (sees lost Spy evs)";
paulson@2032
    60
by (fast_tac (!claset addSDs [Says_imp_sees_Spy RS analz.Inj]) 1);
paulson@2032
    61
qed "YM4_analz_sees_Spy";
paulson@1985
    62
paulson@2110
    63
bind_thm ("YM4_parts_sees_Spy",
paulson@2110
    64
          YM4_analz_sees_Spy RS (impOfSubs analz_subset_parts));
paulson@2110
    65
paulson@2133
    66
(*Relates to both YM4 and Oops*)
paulson@2284
    67
goal thy "!!evs. Says S A {|Crypt (shrK A) {|B, K, NA, NB|}, X|} \
paulson@1995
    68
\                  : set_of_list evs ==> \
paulson@2032
    69
\                K : parts (sees lost Spy evs)";
paulson@1985
    70
by (fast_tac (!claset addSEs partsEs
paulson@2032
    71
                      addSDs [Says_imp_sees_Spy RS parts.Inj]) 1);
paulson@2110
    72
qed "YM4_Key_parts_sees_Spy";
paulson@2110
    73
paulson@2110
    74
(*We instantiate the variable to "lost".  Leaving it as a Var makes proofs
paulson@2110
    75
  harder: the simplifier does less.*)
paulson@2110
    76
val parts_Fake_tac = 
paulson@2110
    77
    forw_inst_tac [("lost","lost")] YM4_parts_sees_Spy 6 THEN
paulson@2110
    78
    forw_inst_tac [("lost","lost")] YM4_Key_parts_sees_Spy 7;
paulson@1985
    79
paulson@2110
    80
(*For proving the easier theorems about X ~: parts (sees lost Spy evs) *)
paulson@2110
    81
fun parts_induct_tac i = SELECT_GOAL
paulson@2110
    82
    (DETERM (etac yahalom.induct 1 THEN parts_Fake_tac THEN
paulson@2170
    83
             (*Fake message*)
paulson@2170
    84
             TRY (best_tac (!claset addDs [impOfSubs analz_subset_parts,
paulson@2170
    85
                                           impOfSubs Fake_parts_insert]
paulson@2110
    86
                                    addss (!simpset)) 2)) THEN
paulson@2110
    87
     (*Base case*)
paulson@2110
    88
     fast_tac (!claset addss (!simpset)) 1 THEN
paulson@2110
    89
     ALLGOALS Asm_simp_tac) i;
paulson@1985
    90
paulson@1985
    91
paulson@2032
    92
(** Theorems of the form X ~: parts (sees lost Spy evs) imply that NOBODY
paulson@2013
    93
    sends messages containing X! **)
paulson@1985
    94
paulson@2133
    95
(*Spy never sees another agent's shared key! (unless it's lost at start)*)
paulson@1985
    96
goal thy 
paulson@2133
    97
 "!!evs. evs : yahalom lost \
paulson@2133
    98
\        ==> (Key (shrK A) : parts (sees lost Spy evs)) = (A : lost)";
paulson@2110
    99
by (parts_induct_tac 1);
paulson@1985
   100
by (Auto_tac());
paulson@2133
   101
qed "Spy_see_shrK";
paulson@2133
   102
Addsimps [Spy_see_shrK];
paulson@1985
   103
paulson@2133
   104
goal thy 
paulson@2133
   105
 "!!evs. evs : yahalom lost \
paulson@2133
   106
\        ==> (Key (shrK A) : analz (sees lost Spy evs)) = (A : lost)";
paulson@2133
   107
by (auto_tac(!claset addDs [impOfSubs analz_subset_parts], !simpset));
paulson@2133
   108
qed "Spy_analz_shrK";
paulson@2133
   109
Addsimps [Spy_analz_shrK];
paulson@1985
   110
paulson@2133
   111
goal thy  "!!A. [| Key (shrK A) : parts (sees lost Spy evs);       \
paulson@2133
   112
\                  evs : yahalom lost |] ==> A:lost";
paulson@2133
   113
by (fast_tac (!claset addDs [Spy_see_shrK]) 1);
paulson@2133
   114
qed "Spy_see_shrK_D";
paulson@1985
   115
paulson@2133
   116
bind_thm ("Spy_analz_shrK_D", analz_subset_parts RS subsetD RS Spy_see_shrK_D);
paulson@2133
   117
AddSDs [Spy_see_shrK_D, Spy_analz_shrK_D];
paulson@1985
   118
paulson@1985
   119
paulson@2516
   120
(*Nobody can have used non-existent keys!*)
paulson@2516
   121
goal thy "!!evs. evs : yahalom lost ==>          \
paulson@2516
   122
\         Key K ~: used evs --> K ~: keysFor (parts (sees lost Spy evs))";
paulson@2110
   123
by (parts_induct_tac 1);
paulson@2516
   124
(*YM4: Key K is not fresh!*)
paulson@2516
   125
by (fast_tac (!claset addSEs sees_Spy_partsEs) 3);
paulson@2516
   126
(*YM3*)
paulson@2516
   127
by (fast_tac (!claset addss (!simpset)) 2);
paulson@2516
   128
(*Fake*)
paulson@2516
   129
by (best_tac
paulson@2516
   130
      (!claset addIs [impOfSubs analz_subset_parts]
paulson@2516
   131
               addDs [impOfSubs (analz_subset_parts RS keysFor_mono),
paulson@2516
   132
                      impOfSubs (parts_insert_subset_Un RS keysFor_mono)]
paulson@2516
   133
               addss (!simpset)) 1);
paulson@2160
   134
qed_spec_mp "new_keys_not_used";
paulson@1985
   135
paulson@1985
   136
bind_thm ("new_keys_not_analzd",
paulson@2032
   137
          [analz_subset_parts RS keysFor_mono,
paulson@2032
   138
           new_keys_not_used] MRS contra_subsetD);
paulson@1985
   139
paulson@1985
   140
Addsimps [new_keys_not_used, new_keys_not_analzd];
paulson@1985
   141
paulson@1985
   142
paulson@2133
   143
(*Describes the form of K when the Server sends this message.  Useful for
paulson@2133
   144
  Oops as well as main secrecy property.*)
paulson@2110
   145
goal thy 
paulson@2516
   146
 "!!evs. [| Says Server A {|Crypt (shrK A) {|Agent B, Key K, NA, NB|}, X|} \
paulson@2516
   147
\             : set_of_list evs;                                           \
paulson@2516
   148
\           evs : yahalom lost |]                                          \
paulson@2516
   149
\        ==> K ~: range shrK";
paulson@2133
   150
by (etac rev_mp 1);
paulson@2133
   151
by (etac yahalom.induct 1);
paulson@2133
   152
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@2133
   153
qed "Says_Server_message_form";
paulson@2110
   154
paulson@2110
   155
paulson@2110
   156
(*For proofs involving analz.  We again instantiate the variable to "lost".*)
paulson@2110
   157
val analz_Fake_tac = 
paulson@2133
   158
    forw_inst_tac [("lost","lost")] YM4_analz_sees_Spy 6 THEN
paulson@2133
   159
    forw_inst_tac [("lost","lost")] Says_Server_message_form 7 THEN
paulson@2516
   160
    assume_tac 7 THEN REPEAT ((etac exE ORELSE' hyp_subst_tac) 7);
paulson@1985
   161
paulson@1985
   162
paulson@1985
   163
(****
paulson@1985
   164
 The following is to prove theorems of the form
paulson@1985
   165
paulson@2516
   166
  Key K : analz (insert (Key KAB) (sees lost Spy evs)) ==>
paulson@2451
   167
  Key K : analz (sees lost Spy evs)
paulson@1985
   168
paulson@1985
   169
 A more general formula must be proved inductively.
paulson@1985
   170
****)
paulson@1985
   171
paulson@1985
   172
(** Session keys are not used to encrypt other session keys **)
paulson@1985
   173
paulson@1985
   174
goal thy  
paulson@2032
   175
 "!!evs. evs : yahalom lost ==> \
paulson@2516
   176
\  ALL K KK. KK <= Compl (range shrK) -->                      \
paulson@2516
   177
\            (Key K : analz (Key``KK Un (sees lost Spy evs))) = \
paulson@2516
   178
\            (K : KK | Key K : analz (sees lost Spy evs))";
paulson@2032
   179
by (etac yahalom.induct 1);
paulson@2110
   180
by analz_Fake_tac;
paulson@2516
   181
by (REPEAT_FIRST (resolve_tac [allI, impI]));
paulson@2516
   182
by (REPEAT_FIRST (rtac analz_image_freshK_lemma ));
paulson@2516
   183
by (ALLGOALS (asm_simp_tac analz_image_freshK_ss));
paulson@2516
   184
(*Base*)
paulson@2516
   185
by (fast_tac (!claset addIs [image_eqI] addss (!simpset)) 1);
paulson@2133
   186
(*YM4, Fake*) 
paulson@2516
   187
by (REPEAT (spy_analz_tac 1));
paulson@2516
   188
qed_spec_mp "analz_image_freshK";
paulson@1985
   189
paulson@1985
   190
goal thy
paulson@2516
   191
 "!!evs. [| evs : yahalom lost;  KAB ~: range shrK |] ==>             \
paulson@2516
   192
\        Key K : analz (insert (Key KAB) (sees lost Spy evs)) = \
paulson@2516
   193
\        (K = KAB | Key K : analz (sees lost Spy evs))";
paulson@2516
   194
by (asm_simp_tac (analz_image_freshK_ss addsimps [analz_image_freshK]) 1);
paulson@2516
   195
qed "analz_insert_freshK";
paulson@1985
   196
paulson@1985
   197
paulson@2110
   198
(*** The Key K uniquely identifies the Server's  message. **)
paulson@2110
   199
paulson@2110
   200
goal thy 
paulson@2110
   201
 "!!evs. evs : yahalom lost ==>                                     \
paulson@2133
   202
\      EX A' B' NA' NB' X'. ALL A B NA NB X.                             \
paulson@2110
   203
\          Says Server A                                            \
paulson@2284
   204
\           {|Crypt (shrK A) {|Agent B, Key K, NA, NB|}, X|}        \
paulson@2133
   205
\          : set_of_list evs --> A=A' & B=B' & NA=NA' & NB=NB' & X=X'";
paulson@2110
   206
by (etac yahalom.induct 1);
paulson@2110
   207
by (ALLGOALS (asm_simp_tac (!simpset addsimps [all_conj_distrib])));
paulson@2110
   208
by (Step_tac 1);
paulson@2133
   209
by (ex_strip_tac 2);
paulson@2133
   210
by (Fast_tac 2);
paulson@2110
   211
(*Remaining case: YM3*)
paulson@2110
   212
by (expand_case_tac "K = ?y" 1);
paulson@2110
   213
by (REPEAT (ares_tac [refl,exI,impI,conjI] 2));
paulson@2516
   214
(*...we assume X is a recent message and handle this case by contradiction*)
paulson@2516
   215
by (fast_tac (!claset addSEs sees_Spy_partsEs
paulson@2516
   216
                      delrules [conjI]    (*prevent split-up into 4 subgoals*)
paulson@2516
   217
                      addss (!simpset addsimps [parts_insertI])) 1);
paulson@2110
   218
val lemma = result();
paulson@2110
   219
paulson@2110
   220
goal thy 
paulson@2110
   221
"!!evs. [| Says Server A                                            \
paulson@2284
   222
\           {|Crypt (shrK A) {|Agent B, Key K, NA, NB|}, X|}        \
paulson@2110
   223
\           : set_of_list evs;                                      \
paulson@2110
   224
\          Says Server A'                                           \
paulson@2284
   225
\           {|Crypt (shrK A') {|Agent B', Key K, NA', NB'|}, X'|}   \
paulson@2110
   226
\           : set_of_list evs;                                      \
paulson@2110
   227
\          evs : yahalom lost |]                                    \
paulson@2110
   228
\       ==> A=A' & B=B' & NA=NA' & NB=NB'";
paulson@2451
   229
by (prove_unique_tac lemma 1);
paulson@2110
   230
qed "unique_session_keys";
paulson@2110
   231
paulson@2110
   232
paulson@2110
   233
(*If the encrypted message appears then it originated with the Server*)
paulson@2110
   234
goal thy
paulson@2284
   235
 "!!evs. [| Crypt (shrK A) {|Agent B, Key K, NA, NB|}                  \
paulson@2110
   236
\            : parts (sees lost Spy evs);                              \
paulson@2110
   237
\           A ~: lost;  evs : yahalom lost |]                          \
paulson@2110
   238
\         ==> Says Server A                                            \
paulson@2284
   239
\              {|Crypt (shrK A) {|Agent B, Key K, NA, NB|},            \
paulson@2284
   240
\                Crypt (shrK B) {|Agent A, Key K|}|}                   \
paulson@2110
   241
\             : set_of_list evs";
paulson@2110
   242
by (etac rev_mp 1);
paulson@2110
   243
by (parts_induct_tac 1);
paulson@2322
   244
qed "A_trusts_YM3";
paulson@2110
   245
paulson@2110
   246
paulson@2110
   247
(** Crucial secrecy property: Spy does not see the keys sent in msg YM3 **)
paulson@2013
   248
paulson@2013
   249
goal thy 
paulson@2133
   250
 "!!evs. [| A ~: lost;  B ~: lost;  evs : yahalom lost |]         \
paulson@2051
   251
\        ==> Says Server A                                        \
paulson@2284
   252
\              {|Crypt (shrK A) {|Agent B, Key K, NA, NB|},       \
paulson@2284
   253
\                Crypt (shrK B) {|Agent A, Key K|}|}              \
paulson@2110
   254
\             : set_of_list evs -->                               \
paulson@2110
   255
\            Says A Spy {|NA, NB, Key K|} ~: set_of_list evs -->  \
paulson@2051
   256
\            Key K ~: analz (sees lost Spy evs)";
paulson@2032
   257
by (etac yahalom.induct 1);
paulson@2110
   258
by analz_Fake_tac;
paulson@2013
   259
by (ALLGOALS
paulson@2013
   260
    (asm_simp_tac 
paulson@2516
   261
     (!simpset addsimps [not_parts_not_analz, analz_insert_freshK]
paulson@2013
   262
               setloop split_tac [expand_if])));
paulson@2013
   263
(*YM3*)
paulson@2516
   264
by (fast_tac (!claset delrules [impCE]
paulson@2516
   265
                      addSEs sees_Spy_partsEs
paulson@2516
   266
                      addIs [impOfSubs analz_subset_parts]
paulson@2516
   267
                      addss (!simpset addsimps [parts_insert2])) 2);
paulson@2133
   268
(*OR4, Fake*) 
paulson@2377
   269
by (REPEAT_FIRST spy_analz_tac);
paulson@2451
   270
(*Oops*)
paulson@2110
   271
by (fast_tac (!claset delrules [disjE] 
paulson@2170
   272
                      addDs [unique_session_keys]
paulson@2170
   273
                      addss (!simpset)) 1);
paulson@2110
   274
val lemma = result() RS mp RS mp RSN(2,rev_notE);
paulson@2013
   275
paulson@2013
   276
paulson@2013
   277
(*Final version: Server's message in the most abstract form*)
paulson@1985
   278
goal thy 
paulson@2516
   279
 "!!evs. [| Says Server A                                         \
paulson@2516
   280
\              {|Crypt (shrK A) {|Agent B, Key K, NA, NB|},       \
paulson@2516
   281
\                Crypt (shrK B) {|Agent A, Key K|}|}              \
paulson@2516
   282
\             : set_of_list evs;                                  \
paulson@2516
   283
\           Says A Spy {|NA, NB, Key K|} ~: set_of_list evs;      \
paulson@2516
   284
\           A ~: lost;  B ~: lost;  evs : yahalom lost |]         \
paulson@2516
   285
\        ==> Key K ~: analz (sees lost Spy evs)";
paulson@2013
   286
by (forward_tac [Says_Server_message_form] 1 THEN assume_tac 1);
paulson@2013
   287
by (fast_tac (!claset addSEs [lemma]) 1);
paulson@2032
   288
qed "Spy_not_see_encrypted_key";
paulson@2001
   289
paulson@2001
   290
paulson@2045
   291
goal thy 
paulson@2516
   292
 "!!evs. [| C ~: {A,B,Server};                                    \
paulson@2516
   293
\           Says Server A                                         \
paulson@2516
   294
\              {|Crypt (shrK A) {|Agent B, Key K, NA, NB|},       \
paulson@2516
   295
\                Crypt (shrK B) {|Agent A, Key K|}|}              \
paulson@2516
   296
\             : set_of_list evs;                                  \
paulson@2516
   297
\           Says A Spy {|NA, NB, Key K|} ~: set_of_list evs;      \
paulson@2516
   298
\           A ~: lost;  B ~: lost;  evs : yahalom lost |]         \
paulson@2516
   299
\        ==> Key K ~: analz (sees lost C evs)";
paulson@2045
   300
by (rtac (subset_insertI RS sees_mono RS analz_mono RS contra_subsetD) 1);
paulson@2045
   301
by (rtac (sees_lost_agent_subset_sees_Spy RS analz_mono RS contra_subsetD) 1);
paulson@2045
   302
by (FIRSTGOAL (rtac Spy_not_see_encrypted_key));
paulson@2045
   303
by (REPEAT_FIRST (fast_tac (!claset addIs [yahalom_mono RS subsetD])));
paulson@2045
   304
qed "Agent_not_see_encrypted_key";
paulson@2045
   305
paulson@2045
   306
paulson@2110
   307
(*** Security Guarantee for B upon receiving YM4 ***)
paulson@2013
   308
paulson@2110
   309
(*B knows, by the first part of A's message, that the Server distributed 
paulson@2110
   310
  the key for A and B.  But this part says nothing about nonces.*)
paulson@2001
   311
goal thy 
paulson@2284
   312
 "!!evs. [| Crypt (shrK B) {|Agent A, Key K|} : parts (sees lost Spy evs); \
paulson@2051
   313
\           B ~: lost;  evs : yahalom lost |]                           \
paulson@2001
   314
\        ==> EX NA NB. Says Server A                                    \
paulson@2451
   315
\                        {|Crypt (shrK A) {|Agent B, Key K,             \
paulson@2516
   316
\                                           Nonce NA, Nonce NB|},       \
paulson@2284
   317
\                          Crypt (shrK B) {|Agent A, Key K|}|}          \
paulson@2013
   318
\                       : set_of_list evs";
paulson@2032
   319
by (etac rev_mp 1);
paulson@2110
   320
by (parts_induct_tac 1);
paulson@2110
   321
(*YM3*)
paulson@2110
   322
by (Fast_tac 1);
paulson@2110
   323
qed "B_trusts_YM4_shrK";
paulson@2110
   324
paulson@2133
   325
paulson@2133
   326
(** The Nonce NB uniquely identifies B's message. **)
paulson@2133
   327
paulson@2133
   328
goal thy 
paulson@2451
   329
 "!!evs. evs : yahalom lost ==> \
paulson@2451
   330
\   EX NA' A' B'. ALL NA A B. \
paulson@2284
   331
\      Crypt (shrK B) {|Agent A, Nonce NA, NB|} : parts(sees lost Spy evs) \
paulson@2133
   332
\      --> B ~: lost --> NA = NA' & A = A' & B = B'";
paulson@2451
   333
by (etac yahalom.induct 1 THEN parts_Fake_tac);
paulson@2451
   334
(*Fake: the tactic in parts_induct_tac works, but takes 4 times longer*)
paulson@2451
   335
by (REPEAT (etac exE 2) THEN 
paulson@2451
   336
    best_tac (!claset addSIs [exI]
paulson@2516
   337
                      addDs [impOfSubs Fake_parts_insert]
paulson@2516
   338
                      addss (!simpset)) 2);
paulson@2451
   339
(*Base case*)
paulson@2451
   340
by (fast_tac (!claset addss (!simpset)) 1);
paulson@2451
   341
by (ALLGOALS (asm_simp_tac (!simpset addsimps [all_conj_distrib]))); 
paulson@2133
   342
(*YM2: creation of new Nonce.  Move assertion into global context*)
paulson@2133
   343
by (expand_case_tac "NB = ?y" 1);
paulson@2516
   344
by (REPEAT (resolve_tac [exI, conjI, impI, refl] 1));
paulson@2516
   345
by (fast_tac (!claset addSEs sees_Spy_partsEs) 1);
paulson@2133
   346
val lemma = result();
paulson@2133
   347
paulson@2110
   348
goal thy 
paulson@2284
   349
 "!!evs.[| Crypt (shrK B) {|Agent A, Nonce NA, NB|} \
paulson@2133
   350
\                  : parts (sees lost Spy evs);         \
paulson@2284
   351
\          Crypt (shrK B') {|Agent A', Nonce NA', NB|} \
paulson@2133
   352
\                  : parts (sees lost Spy evs);         \
paulson@2133
   353
\          evs : yahalom lost;  B ~: lost;  B' ~: lost |]  \
paulson@2133
   354
\        ==> NA' = NA & A' = A & B' = B";
paulson@2451
   355
by (prove_unique_tac lemma 1);
paulson@2133
   356
qed "unique_NB";
paulson@2133
   357
paulson@2133
   358
fun lost_tac s =
paulson@2133
   359
    case_tac ("(" ^ s ^ ") : lost") THEN'
paulson@2133
   360
    SELECT_GOAL 
paulson@2133
   361
      (REPEAT_DETERM (dtac (Says_imp_sees_Spy RS analz.Inj) 1) THEN
paulson@2133
   362
       REPEAT_DETERM (etac MPair_analz 1) THEN
paulson@2133
   363
       THEN_BEST_FIRST 
paulson@2133
   364
         (dres_inst_tac [("A", s)] Crypt_Spy_analz_lost 1 THEN assume_tac 1)
paulson@2170
   365
         (has_fewer_prems 1, size_of_thm)
paulson@2170
   366
         (Step_tac 1));
paulson@2133
   367
paulson@2133
   368
paulson@2133
   369
(*Variant useful for proving secrecy of NB*)
paulson@2133
   370
goal thy 
paulson@2284
   371
 "!!evs.[| Says C D   {|X,  Crypt (shrK B) {|Agent A, Nonce NA, NB|}|} \
paulson@2133
   372
\          : set_of_list evs;  B ~: lost;         \
paulson@2284
   373
\          Says C' D' {|X', Crypt (shrK B') {|Agent A', Nonce NA', NB|}|} \
paulson@2133
   374
\          : set_of_list evs;                           \
paulson@2133
   375
\          NB ~: analz (sees lost Spy evs);             \
paulson@2133
   376
\          evs : yahalom lost |]  \
paulson@2133
   377
\        ==> NA' = NA & A' = A & B' = B";
paulson@2133
   378
by (lost_tac "B'" 1);
paulson@2133
   379
by (fast_tac (!claset addSDs [Says_imp_sees_Spy RS parts.Inj]
paulson@2133
   380
                      addSEs [MPair_parts]
paulson@2133
   381
                      addDs  [unique_NB]) 1);
paulson@2133
   382
qed "Says_unique_NB";
paulson@2133
   383
paulson@2133
   384
goal thy 
paulson@2133
   385
 "!!evs. [| B ~: lost;  evs : yahalom lost  |]               \
paulson@2133
   386
\ ==>  Nonce NB ~: analz (sees lost Spy evs) -->  \
paulson@2284
   387
\      Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|} : parts (sees lost Spy evs) \
paulson@2284
   388
\ --> Crypt (shrK B') {|Agent A', Nonce NB, NB'|} ~: parts (sees lost Spy evs)";
paulson@2133
   389
by (etac yahalom.induct 1);
paulson@2133
   390
by parts_Fake_tac;
paulson@2133
   391
by (REPEAT_FIRST 
paulson@2133
   392
    (rtac impI THEN' 
paulson@2133
   393
     dtac (sees_subset_sees_Says RS analz_mono RS contra_subsetD) THEN'
paulson@2133
   394
     mp_tac));
paulson@2133
   395
by (best_tac (!claset addDs [impOfSubs analz_subset_parts,
paulson@2170
   396
                             impOfSubs Fake_parts_insert]
paulson@2170
   397
                      addss (!simpset)) 2);
paulson@2133
   398
by (ALLGOALS Asm_simp_tac);
paulson@2133
   399
by (fast_tac (!claset addss (!simpset)) 1);
paulson@2133
   400
by (fast_tac (!claset addDs [Says_imp_sees_Spy RS analz.Inj]
paulson@2170
   401
                      addSIs [parts_insertI]
paulson@2133
   402
                      addSEs partsEs
paulson@2133
   403
                      addss (!simpset)) 1);
paulson@2133
   404
val no_nonce_YM1_YM2 = standard (result() RS mp RSN (2, rev_mp) RS notE);
paulson@2133
   405
paulson@2133
   406
paulson@2133
   407
paulson@2133
   408
(**** Towards proving secrecy of Nonce NB ****)
paulson@2133
   409
paulson@2133
   410
(*B knows, by the second part of A's message, that the Server distributed 
paulson@2133
   411
  the key quoting nonce NB.  This part says nothing about agent names. 
paulson@2133
   412
  Secrecy of NB is crucial.*)
paulson@2133
   413
goal thy 
paulson@2133
   414
 "!!evs. evs : yahalom lost                                             \
paulson@2133
   415
\        ==> Nonce NB ~: analz (sees lost Spy evs) -->                  \
paulson@2284
   416
\            Crypt K (Nonce NB) : parts (sees lost Spy evs) -->         \
paulson@2133
   417
\            (EX A B NA. Says Server A                                  \
paulson@2516
   418
\                        {|Crypt (shrK A) {|Agent B, Key K,             \
paulson@2516
   419
\                                  Nonce NA, Nonce NB|},                \
paulson@2284
   420
\                          Crypt (shrK B) {|Agent A, Key K|}|}          \
paulson@2133
   421
\                       : set_of_list evs)";
paulson@2133
   422
by (etac yahalom.induct 1);
paulson@2133
   423
by parts_Fake_tac;
paulson@2133
   424
by (fast_tac (!claset addss (!simpset)) 1);
paulson@2133
   425
by (REPEAT_FIRST
paulson@2133
   426
    (rtac impI THEN'
paulson@2133
   427
     dtac (sees_subset_sees_Says RS analz_mono RS contra_subsetD)));
paulson@2133
   428
by (ALLGOALS Asm_simp_tac);
paulson@2133
   429
(*Fake, YM3, YM4*)
paulson@2133
   430
by (Fast_tac 2);
paulson@2133
   431
by (fast_tac (!claset addSDs [impOfSubs Fake_parts_insert]
paulson@2133
   432
                      addDs [impOfSubs analz_subset_parts]
paulson@2133
   433
                      addss (!simpset)) 1);
paulson@2133
   434
(*YM4*)
paulson@2133
   435
by (Step_tac 1);
paulson@2133
   436
by (lost_tac "A" 1);
paulson@2133
   437
by (fast_tac (!claset addDs [Says_imp_sees_Spy RS parts.Inj RS parts.Fst RS
paulson@2322
   438
                             A_trusts_YM3]) 1);
paulson@2133
   439
val B_trusts_YM4_newK = result() RS mp RSN (2, rev_mp);
paulson@2133
   440
paulson@2133
   441
paulson@2133
   442
(*This is the original version of the result above.  But it is of little
paulson@2133
   443
  value because it assumes secrecy of K, which we cannot be assured of
paulson@2133
   444
  until we know that K is fresh -- which we do not know at the point this
paulson@2133
   445
  result is applied.*)
paulson@2133
   446
goal thy 
paulson@2133
   447
 "!!evs. evs : yahalom lost                                             \
paulson@2133
   448
\        ==> Key K ~: analz (sees lost Spy evs) -->                     \
paulson@2284
   449
\            Crypt K (Nonce NB) : parts (sees lost Spy evs) -->         \
paulson@2110
   450
\            (EX A B NA. Says Server A                                  \
paulson@2284
   451
\                        {|Crypt (shrK A) {|Agent B, Key K,                      \
paulson@2284
   452
\                                  Nonce NA, Nonce NB|},       \
paulson@2284
   453
\                          Crypt (shrK B) {|Agent A, Key K|}|}          \
paulson@2110
   454
\                       : set_of_list evs)";
paulson@2032
   455
by (etac yahalom.induct 1);
paulson@2110
   456
by parts_Fake_tac;
paulson@2001
   457
by (fast_tac (!claset addss (!simpset)) 1);
paulson@2110
   458
by (TRYALL (rtac impI));
paulson@2110
   459
by (REPEAT_FIRST
paulson@2110
   460
    (dtac (sees_subset_sees_Says RS analz_mono RS contra_subsetD)));
paulson@2110
   461
by (ALLGOALS Asm_simp_tac);
paulson@2110
   462
(*Fake, YM3, YM4*)
paulson@2110
   463
by (fast_tac (!claset addSDs [Crypt_Fake_parts_insert]
paulson@2133
   464
                      addDs  [impOfSubs analz_subset_parts]) 1);
paulson@2110
   465
by (Fast_tac 1);
paulson@2110
   466
(*YM4*)
paulson@2110
   467
by (Step_tac 1);
paulson@2133
   468
by (lost_tac "A" 1);
paulson@2110
   469
by (fast_tac (!claset addDs [Says_imp_sees_Spy RS parts.Inj RS parts.Fst RS
paulson@2322
   470
                             A_trusts_YM3]) 1);
paulson@2133
   471
result() RS mp RSN (2, rev_mp);
paulson@2133
   472
paulson@2133
   473
paulson@2133
   474
(*YM3 can only be triggered by YM2*)
paulson@2133
   475
goal thy 
paulson@2133
   476
 "!!evs. [| Says Server A                                           \
paulson@2284
   477
\            {|Crypt (shrK A) {|Agent B, k, na, nb|}, X|} : set_of_list evs; \
paulson@2133
   478
\           evs : yahalom lost |]                                        \
paulson@2133
   479
\        ==> EX B'. Says B' Server                                       \
paulson@2284
   480
\                      {| Agent B, Crypt (shrK B) {|Agent A, na, nb|} |} \
paulson@2133
   481
\                   : set_of_list evs";
paulson@2133
   482
by (etac rev_mp 1);
paulson@2133
   483
by (etac yahalom.induct 1);
paulson@2133
   484
by (ALLGOALS Asm_simp_tac);
paulson@2133
   485
by (ALLGOALS Fast_tac);
paulson@2133
   486
qed "Says_Server_imp_YM2";
paulson@2133
   487
paulson@2133
   488
paulson@2133
   489
(** Dedicated tactics for the nonce secrecy proofs **)
paulson@2133
   490
paulson@2133
   491
val no_nonce_tac = SELECT_GOAL
paulson@2133
   492
   (REPEAT (resolve_tac [impI, notI] 1) THEN
paulson@2133
   493
    REPEAT (hyp_subst_tac 1) THEN
paulson@2133
   494
    etac (Says_imp_sees_Spy RS parts.Inj RS parts.Snd RS no_nonce_YM1_YM2) 1
paulson@2133
   495
    THEN
paulson@2133
   496
    etac (Says_imp_sees_Spy RS parts.Inj RS parts.Snd) 4
paulson@2133
   497
    THEN 
paulson@2133
   498
    REPEAT_FIRST assume_tac);
paulson@2133
   499
paulson@2133
   500
val not_analz_insert = subset_insertI RS analz_mono RS contra_subsetD;
paulson@2133
   501
paulson@2133
   502
paulson@2133
   503
(*The only nonces that can be found with the help of session keys are
paulson@2133
   504
  those distributed as nonce NB by the Server.  The form of the theorem
paulson@2516
   505
  recalls analz_image_freshK, but it is much more complicated.*)
paulson@2516
   506
paulson@2516
   507
(*As with analz_image_freshK, we take some pains to express the property
paulson@2516
   508
  as a logical equivalence so that the simplifier can apply it.*)
paulson@2516
   509
goal thy  
paulson@2516
   510
 "!!evs. P --> (X : analz (G Un H)) --> (X : analz H)  ==> \
paulson@2516
   511
\        P --> (X : analz (G Un H)) = (X : analz H)";
paulson@2516
   512
by (fast_tac (!claset addSEs [impOfSubs analz_mono]) 1);
paulson@2516
   513
qed "Nonce_secrecy_lemma";
paulson@2516
   514
paulson@2133
   515
goal thy 
paulson@2516
   516
 "!!evs. evs : yahalom lost ==>                                          \
paulson@2516
   517
\        (ALL KK. KK <= Compl (range shrK) -->                               \
paulson@2516
   518
\             (ALL K: KK. ALL A B na X.                                       \
paulson@2516
   519
\                 Says Server A                                              \
paulson@2516
   520
\                     {|Crypt (shrK A) {|Agent B, Key K, na, Nonce NB|}, X|} \
paulson@2516
   521
\                 ~: set_of_list evs)   -->  \
paulson@2516
   522
\             (Nonce NB : analz (Key``KK Un (sees lost Spy evs))) =      \
paulson@2516
   523
\             (Nonce NB : analz (sees lost Spy evs)))";
paulson@2133
   524
by (etac yahalom.induct 1);
paulson@2133
   525
by analz_Fake_tac;
paulson@2516
   526
by (REPEAT_FIRST (resolve_tac [impI RS allI]));
paulson@2516
   527
by (REPEAT_FIRST (rtac Nonce_secrecy_lemma ));
paulson@2516
   528
by (rtac ccontr 7);
paulson@2516
   529
by (subgoal_tac "ALL A B na X.                                       \
paulson@2516
   530
\                 Says Server A                                              \
paulson@2516
   531
\                     {|Crypt (shrK A) {|Agent B, Key K, na, Nonce NB|}, X|} \
paulson@2516
   532
\                 ~: set_of_list evsa" 7);
paulson@2516
   533
by (eres_inst_tac [("P","?PP-->?QQ")] notE 7);
paulson@2516
   534
by (subgoal_tac "ALL A B na X.                                       \
paulson@2516
   535
\                 Says Server A                                              \
paulson@2516
   536
\                    {|Crypt (shrK A) {|Agent B, Key KAB, na, Nonce NB|}, X|} \
paulson@2516
   537
\                 ~: set_of_list evsa" 5);
paulson@2451
   538
by (ALLGOALS  (*22 seconds*)
paulson@2133
   539
    (asm_simp_tac 
paulson@2516
   540
     (analz_image_freshK_ss  addsimps
paulson@2516
   541
             ([all_conj_distrib, 
paulson@2516
   542
               not_parts_not_analz, analz_image_freshK]
paulson@2516
   543
              @ pushes @ ball_simps))));
paulson@2133
   544
(*Base*)
paulson@2133
   545
by (fast_tac (!claset addss (!simpset)) 1);
paulson@2516
   546
(*Fake*) (** LEVEL 10 **)
paulson@2133
   547
by (spy_analz_tac 1);
paulson@2516
   548
(*YM3*)
paulson@2516
   549
by (fast_tac (!claset addSEs sees_Spy_partsEs) 1);
paulson@2133
   550
(*Oops*)
paulson@2516
   551
(*20 secs*)
paulson@2516
   552
by (fast_tac (!claset delrules [ballE] addDs [unique_session_keys]
paulson@2170
   553
                      addss (!simpset)) 2);
paulson@2133
   554
(*YM4*)
paulson@2516
   555
(** LEVEL 13 **)
paulson@2516
   556
by (REPEAT (resolve_tac [impI, allI] 1));
paulson@2377
   557
by (dtac (impOfSubs Fake_analz_insert) 1 THEN etac synth.Inj 1);
paulson@2516
   558
by (stac insert_commute 1);
paulson@2133
   559
by (eres_inst_tac [("P","Nonce NB : ?HH")] rev_mp 1);
paulson@2516
   560
by (asm_simp_tac (analz_image_freshK_ss 
paulson@2516
   561
                  addsimps [analz_insertI, analz_image_freshK]) 1);
paulson@2516
   562
by (step_tac (!claset addSDs [not_analz_insert]) 1);
paulson@2133
   563
by (lost_tac "A" 1);
paulson@2516
   564
(** LEVEL 20 **)
paulson@2322
   565
by (dtac (Says_imp_sees_Spy RS parts.Inj RS parts.Fst RS A_trusts_YM3) 1
paulson@2133
   566
    THEN REPEAT (assume_tac 1));
paulson@2516
   567
by (thin_tac "All ?PP" 1);
paulson@2516
   568
by (Fast_tac 1);
paulson@2516
   569
qed_spec_mp "Nonce_secrecy";
paulson@2133
   570
paulson@2133
   571
paulson@2133
   572
(*Version required below: if NB can be decrypted using a session key then it
paulson@2133
   573
  was distributed with that key.  The more general form above is required
paulson@2133
   574
  for the induction to carry through.*)
paulson@2133
   575
goal thy 
paulson@2516
   576
 "!!evs. [| Says Server A                                              \
paulson@2516
   577
\            {|Crypt (shrK A) {|Agent B, Key KAB, na, Nonce NB'|}, X|} \
paulson@2516
   578
\           : set_of_list evs;                                         \
paulson@2516
   579
\           Nonce NB : analz (insert (Key KAB) (sees lost Spy evs));   \
paulson@2516
   580
\           Nonce NB ~: analz (sees lost Spy evs);                     \
paulson@2516
   581
\           KAB ~: range shrK;  evs : yahalom lost |]                  \
paulson@2516
   582
\        ==>  NB = NB'";
paulson@2516
   583
by (rtac ccontr 1);
paulson@2516
   584
by (subgoal_tac "ALL A B na X.                                       \
paulson@2516
   585
\                 Says Server A                                              \
paulson@2516
   586
\                    {|Crypt (shrK A) {|Agent B, Key KAB, na, Nonce NB|}, X|} \
paulson@2516
   587
\                 ~: set_of_list evs" 1);
paulson@2516
   588
by (eres_inst_tac [("P","Nonce NB : ?HH")] rev_mp 1);
paulson@2516
   589
by (asm_simp_tac (analz_image_freshK_ss 
paulson@2516
   590
                  addsimps ([Nonce_secrecy] @ ball_simps)) 1);
paulson@2516
   591
by (auto_tac (!claset addDs [unique_session_keys], (!simpset)));
paulson@2516
   592
qed "single_Nonce_secrecy";
paulson@2133
   593
paulson@2133
   594
paulson@2133
   595
goal thy 
paulson@2133
   596
 "!!evs. [| A ~: lost;  B ~: lost;  Spy: lost;  evs : yahalom lost |]  \
paulson@2133
   597
\ ==> Says B Server                                                    \
paulson@2284
   598
\          {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|} \
paulson@2133
   599
\     : set_of_list evs -->                               \
paulson@2133
   600
\     (ALL k. Says A Spy {|Nonce NA, Nonce NB, k|} ~: set_of_list evs) -->  \
paulson@2133
   601
\     Nonce NB ~: analz (sees lost Spy evs)";
paulson@2133
   602
by (etac yahalom.induct 1);
paulson@2133
   603
by analz_Fake_tac;
paulson@2133
   604
by (ALLGOALS
paulson@2133
   605
    (asm_simp_tac 
paulson@2377
   606
     (!simpset addsimps ([not_parts_not_analz,
paulson@2516
   607
                          analz_insert_freshK] @ pushes)
paulson@2133
   608
               setloop split_tac [expand_if])));
paulson@2133
   609
by (fast_tac (!claset addSIs [parts_insertI]
paulson@2516
   610
                      addSEs sees_Spy_partsEs
paulson@2133
   611
                      addss (!simpset)) 2);
paulson@2377
   612
(*Proof of YM2*) (** LEVEL 4 **)
paulson@2516
   613
by (deepen_tac (!claset addDs [Says_imp_sees_Spy RS analz.Inj,
paulson@2516
   614
                               impOfSubs analz_subset_parts]
paulson@2516
   615
                        addSEs partsEs) 3 2);
paulson@2133
   616
(*Prove YM3 by showing that no NB can also be an NA*)
paulson@2133
   617
by (REPEAT (Safe_step_tac 2 ORELSE no_nonce_tac 2));
paulson@2133
   618
by (deepen_tac (!claset addDs [Says_unique_NB]) 1 2);
paulson@2377
   619
(*Fake*)
paulson@2377
   620
by (spy_analz_tac 1);
paulson@2516
   621
(*YM4*) (** LEVEL 8 **)
paulson@2133
   622
by (res_inst_tac [("x1","X")] (insert_commute RS ssubst) 1);
paulson@2133
   623
by (simp_tac (!simpset setloop split_tac [expand_if]) 1);
paulson@2516
   624
(*43 secs??*)
paulson@2377
   625
by (SELECT_GOAL (REPEAT_FIRST (spy_analz_tac ORELSE' Safe_step_tac)) 1);
paulson@2133
   626
by (lost_tac "Aa" 1);
paulson@2322
   627
by (dtac (Says_imp_sees_Spy RS parts.Inj RS parts.Fst RS A_trusts_YM3) 1);
paulson@2133
   628
by (forward_tac [Says_Server_message_form] 3);
paulson@2133
   629
by (forward_tac [Says_Server_imp_YM2] 4);
paulson@2516
   630
(** LEVEL 15 **)
paulson@2133
   631
by (REPEAT_FIRST ((eresolve_tac [asm_rl, bexE, exE, disjE])));
paulson@2133
   632
by (lost_tac "Ba" 1);
paulson@2170
   633
by (dtac (Says_imp_sees_Spy RS parts.Inj RS parts.Snd RS unique_NB) 1);
paulson@2133
   634
by (fast_tac (!claset addSDs [Says_imp_sees_Spy RS parts.Inj]
paulson@2133
   635
                      addSEs [MPair_parts]) 1);
paulson@2133
   636
by (REPEAT (assume_tac 1 ORELSE Safe_step_tac 1)); 
paulson@2516
   637
(** LEVEL 20 **)
paulson@2170
   638
by (dtac Spy_not_see_encrypted_key 1);
paulson@2133
   639
by (REPEAT (assume_tac 1 ORELSE Fast_tac 1)); 
paulson@2133
   640
by (spy_analz_tac 1);
paulson@2516
   641
(*Oops case*) (** LEVEL 23 **)
paulson@2133
   642
by (full_simp_tac (!simpset addsimps [all_conj_distrib]) 1);
paulson@2133
   643
by (step_tac (!claset delrules [disjE, conjI]) 1);
paulson@2133
   644
by (forward_tac [Says_Server_imp_YM2] 1 THEN assume_tac 1 THEN etac exE 1);
paulson@2133
   645
by (expand_case_tac "NB = NBa" 1);
paulson@2133
   646
by (deepen_tac (!claset addDs [Says_unique_NB]) 1 1);
paulson@2170
   647
by (rtac conjI 1);
paulson@2133
   648
by (no_nonce_tac 1);
paulson@2516
   649
(** LEVEL 30 **)
paulson@2133
   650
by (thin_tac "?PP|?QQ" 1);  (*subsumption!*)
paulson@2133
   651
by (fast_tac (!claset addSDs [single_Nonce_secrecy]) 1);
paulson@2133
   652
val Spy_not_see_NB = result() RSN(2,rev_mp) RSN(2,rev_mp) |> standard;
paulson@2133
   653
paulson@2001
   654
paulson@2110
   655
(*What can B deduce from receipt of YM4?  Note how the two components of
paulson@2110
   656
  the message contribute to a single conclusion about the Server's message.
paulson@2110
   657
  It's annoying that the "Says A Spy" assumption must quantify over 
paulson@2133
   658
  ALL POSSIBLE keys instead of our particular K (though at least the
paulson@2133
   659
  nonces are forced to agree with NA and NB). *)
paulson@2001
   660
goal thy 
paulson@2516
   661
 "!!evs. [| Says B Server                                               \
paulson@2284
   662
\            {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|}  \
paulson@2133
   663
\           : set_of_list evs;       \
paulson@2284
   664
\           Says A' B {|Crypt (shrK B) {|Agent A, Key K|},              \
paulson@2284
   665
\                       Crypt K (Nonce NB)|} : set_of_list evs;         \
paulson@2133
   666
\           ALL k. Says A Spy {|Nonce NA, Nonce NB, k|} ~: set_of_list evs; \
paulson@2133
   667
\           A ~: lost;  B ~: lost;  Spy: lost;  evs : yahalom lost |]   \
paulson@2516
   668
\         ==> Says Server A                                             \
paulson@2516
   669
\                     {|Crypt (shrK A) {|Agent B, Key K,                \
paulson@2516
   670
\                               Nonce NA, Nonce NB|},                   \
paulson@2284
   671
\                       Crypt (shrK B) {|Agent A, Key K|}|}             \
paulson@2001
   672
\                   : set_of_list evs";
paulson@2133
   673
by (forward_tac [Spy_not_see_NB] 1 THEN REPEAT (assume_tac 1));
paulson@2133
   674
by (etac (Says_imp_sees_Spy RS parts.Inj RS MPair_parts) 1 THEN
paulson@2133
   675
    dtac B_trusts_YM4_shrK 1);
paulson@2170
   676
by (dtac B_trusts_YM4_newK 3);
paulson@2110
   677
by (REPEAT_FIRST (eresolve_tac [asm_rl, exE]));
paulson@2133
   678
by (forward_tac [Says_Server_imp_YM2] 1 THEN assume_tac 1);
paulson@2170
   679
by (dtac unique_session_keys 1 THEN REPEAT (assume_tac 1));
paulson@2133
   680
by (deepen_tac (!claset addDs [Says_unique_NB] addss (!simpset)) 0 1);
paulson@2322
   681
qed "B_trusts_YM4";