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