src/HOL/Auth/Yahalom.ML
author paulson
Tue Nov 11 11:16:18 1997 +0100 (1997-11-11)
changeset 4198 c63639beeff1
parent 4091 771b1f6422a8
child 4238 679a233fb206
permissions -rw-r--r--
Fixed spelling error
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@1995
    19
paulson@2322
    20
(*A "possibility property": there are traces that reach the end*)
paulson@1995
    21
goal thy 
paulson@1995
    22
 "!!A B. [| A ~= B; A ~= Server; B ~= Server |]   \
paulson@3519
    23
\        ==> EX X NB K. EX evs: yahalom.     \
nipkow@3465
    24
\               Says A B {|X, Crypt K (Nonce NB)|} : set evs";
paulson@1995
    25
by (REPEAT (resolve_tac [exI,bexI] 1));
paulson@2516
    26
by (rtac (yahalom.Nil RS yahalom.YM1 RS yahalom.YM2 RS yahalom.YM3 RS 
paulson@2516
    27
          yahalom.YM4) 2);
paulson@2516
    28
by possibility_tac;
paulson@2013
    29
result();
paulson@1995
    30
paulson@1995
    31
paulson@1985
    32
(**** Inductive proofs about yahalom ****)
paulson@1985
    33
paulson@1985
    34
(*Nobody sends themselves messages*)
paulson@3519
    35
goal thy "!!evs. evs: yahalom ==> ALL A X. Says A A X ~: set evs";
paulson@2032
    36
by (etac yahalom.induct 1);
paulson@1985
    37
by (Auto_tac());
paulson@1985
    38
qed_spec_mp "not_Says_to_self";
paulson@1985
    39
Addsimps [not_Says_to_self];
paulson@1985
    40
AddSEs   [not_Says_to_self RSN (2, rev_notE)];
paulson@1985
    41
paulson@1985
    42
paulson@1985
    43
(** For reasoning about the encrypted portion of messages **)
paulson@1985
    44
paulson@1995
    45
(*Lets us treat YM4 using a similar argument as for the Fake case.*)
nipkow@3465
    46
goal thy "!!evs. Says S A {|Crypt (shrK A) Y, X|} : set evs ==> \
paulson@3683
    47
\                X : analz (spies evs)";
wenzelm@4091
    48
by (blast_tac (claset() addSDs [Says_imp_spies RS analz.Inj]) 1);
paulson@3683
    49
qed "YM4_analz_spies";
paulson@1985
    50
paulson@3683
    51
bind_thm ("YM4_parts_spies",
paulson@3683
    52
          YM4_analz_spies RS (impOfSubs analz_subset_parts));
paulson@2110
    53
paulson@2133
    54
(*Relates to both YM4 and Oops*)
paulson@3466
    55
goal thy "!!evs. Says S A {|Crypt (shrK A) {|B,K,NA,NB|}, X|} : set evs ==> \
paulson@3683
    56
\                K : parts (spies evs)";
wenzelm@4091
    57
by (blast_tac (claset() addSEs partsEs
paulson@3683
    58
                      addSDs [Says_imp_spies RS parts.Inj]) 1);
paulson@3683
    59
qed "YM4_Key_parts_spies";
paulson@2110
    60
paulson@3683
    61
(*For proving the easier theorems about X ~: parts (spies evs).*)
paulson@3683
    62
fun parts_spies_tac i = 
paulson@3683
    63
    forward_tac [YM4_Key_parts_spies] (i+6) THEN
paulson@3683
    64
    forward_tac [YM4_parts_spies] (i+5)     THEN
paulson@3519
    65
    prove_simple_subgoals_tac  i;
paulson@1985
    66
paulson@3519
    67
(*Induction for regularity theorems.  If induction formula has the form
paulson@3683
    68
   X ~: analz (spies evs) --> ... then it shortens the proof by discarding
paulson@3683
    69
   needless information about analz (insert X (spies evs))  *)
paulson@3519
    70
fun parts_induct_tac i = 
paulson@3519
    71
    etac yahalom.induct i
paulson@3519
    72
    THEN 
paulson@3519
    73
    REPEAT (FIRSTGOAL analz_mono_contra_tac)
paulson@3683
    74
    THEN  parts_spies_tac i;
paulson@1985
    75
paulson@1985
    76
paulson@3683
    77
(** Theorems of the form X ~: parts (spies evs) imply that NOBODY
paulson@2013
    78
    sends messages containing X! **)
paulson@1985
    79
paulson@3683
    80
(*Spy never sees another agent's shared key! (unless it's bad at start)*)
paulson@1985
    81
goal thy 
paulson@3683
    82
 "!!evs. evs : yahalom ==> (Key (shrK A) : parts (spies evs)) = (A : bad)";
paulson@3519
    83
by (parts_induct_tac 1);
paulson@3121
    84
by (Fake_parts_insert_tac 1);
paulson@3961
    85
by (ALLGOALS Blast_tac);
paulson@2133
    86
qed "Spy_see_shrK";
paulson@2133
    87
Addsimps [Spy_see_shrK];
paulson@1985
    88
paulson@2133
    89
goal thy 
paulson@3683
    90
 "!!evs. evs : yahalom ==> (Key (shrK A) : analz (spies evs)) = (A : bad)";
wenzelm@4091
    91
by (auto_tac(claset() addDs [impOfSubs analz_subset_parts], simpset()));
paulson@2133
    92
qed "Spy_analz_shrK";
paulson@2133
    93
Addsimps [Spy_analz_shrK];
paulson@1985
    94
paulson@3683
    95
goal thy  "!!A. [| Key (shrK A) : parts (spies evs);       \
paulson@3683
    96
\                  evs : yahalom |] ==> A:bad";
wenzelm@4091
    97
by (blast_tac (claset() addDs [Spy_see_shrK]) 1);
paulson@2133
    98
qed "Spy_see_shrK_D";
paulson@1985
    99
paulson@2133
   100
bind_thm ("Spy_analz_shrK_D", analz_subset_parts RS subsetD RS Spy_see_shrK_D);
paulson@2133
   101
AddSDs [Spy_see_shrK_D, Spy_analz_shrK_D];
paulson@1985
   102
paulson@1985
   103
paulson@3432
   104
(*Nobody can have used non-existent keys!  Needed to apply analz_insert_Key*)
paulson@3519
   105
goal thy "!!evs. evs : yahalom ==>          \
paulson@3683
   106
\         Key K ~: used evs --> K ~: keysFor (parts (spies evs))";
paulson@3519
   107
by (parts_induct_tac 1);
paulson@2516
   108
(*Fake*)
paulson@2516
   109
by (best_tac
wenzelm@4091
   110
      (claset() addSDs [impOfSubs (parts_insert_subset_Un RS keysFor_mono)]
paulson@3961
   111
               addIs  [impOfSubs analz_subset_parts]
paulson@3961
   112
               addDs  [impOfSubs (analz_subset_parts RS keysFor_mono)]
wenzelm@4091
   113
               addss  (simpset())) 1);
paulson@3961
   114
(*YM2-4: Because Key K is not fresh, etc.*)
wenzelm@4091
   115
by (REPEAT (blast_tac (claset() addSEs spies_partsEs) 1));
paulson@2160
   116
qed_spec_mp "new_keys_not_used";
paulson@1985
   117
paulson@1985
   118
bind_thm ("new_keys_not_analzd",
paulson@2032
   119
          [analz_subset_parts RS keysFor_mono,
paulson@2032
   120
           new_keys_not_used] MRS contra_subsetD);
paulson@1985
   121
paulson@1985
   122
Addsimps [new_keys_not_used, new_keys_not_analzd];
paulson@1985
   123
paulson@1985
   124
paulson@2133
   125
(*Describes the form of K when the Server sends this message.  Useful for
paulson@2133
   126
  Oops as well as main secrecy property.*)
paulson@2110
   127
goal thy 
paulson@3501
   128
 "!!evs. [| Says Server A {|Crypt (shrK A) {|Agent B, Key K, na, nb|}, X|} \
paulson@3466
   129
\             : set evs;                                                   \
paulson@3519
   130
\           evs : yahalom |]                                          \
paulson@2516
   131
\        ==> K ~: range shrK";
paulson@2133
   132
by (etac rev_mp 1);
paulson@2133
   133
by (etac yahalom.induct 1);
paulson@3121
   134
by (ALLGOALS Asm_simp_tac);
paulson@3121
   135
by (Blast_tac 1);
paulson@2133
   136
qed "Says_Server_message_form";
paulson@2110
   137
paulson@2110
   138
paulson@3519
   139
(*For proofs involving analz.*)
paulson@3683
   140
val analz_spies_tac = 
paulson@3683
   141
    forward_tac [YM4_analz_spies] 6 THEN
paulson@3519
   142
    forward_tac [Says_Server_message_form] 7 THEN
paulson@2516
   143
    assume_tac 7 THEN REPEAT ((etac exE ORELSE' hyp_subst_tac) 7);
paulson@1985
   144
paulson@1985
   145
paulson@1985
   146
(****
paulson@1985
   147
 The following is to prove theorems of the form
paulson@1985
   148
paulson@3683
   149
  Key K : analz (insert (Key KAB) (spies evs)) ==>
paulson@3683
   150
  Key K : analz (spies evs)
paulson@1985
   151
paulson@1985
   152
 A more general formula must be proved inductively.
paulson@1985
   153
****)
paulson@1985
   154
paulson@1985
   155
(** Session keys are not used to encrypt other session keys **)
paulson@1985
   156
paulson@1985
   157
goal thy  
paulson@3519
   158
 "!!evs. evs : yahalom ==>                                 \
paulson@3466
   159
\  ALL K KK. KK <= Compl (range shrK) -->                       \
paulson@3683
   160
\            (Key K : analz (Key``KK Un (spies evs))) = \
paulson@3683
   161
\            (K : KK | Key K : analz (spies evs))";
paulson@2032
   162
by (etac yahalom.induct 1);
paulson@3683
   163
by analz_spies_tac;
paulson@2516
   164
by (REPEAT_FIRST (resolve_tac [allI, impI]));
paulson@3679
   165
by (REPEAT_FIRST (rtac analz_image_freshK_lemma));
paulson@2516
   166
by (ALLGOALS (asm_simp_tac analz_image_freshK_ss));
paulson@3450
   167
(*Fake*) 
paulson@3450
   168
by (spy_analz_tac 2);
paulson@2516
   169
(*Base*)
paulson@3121
   170
by (Blast_tac 1);
paulson@2516
   171
qed_spec_mp "analz_image_freshK";
paulson@1985
   172
paulson@1985
   173
goal thy
paulson@3519
   174
 "!!evs. [| evs : yahalom;  KAB ~: range shrK |] ==>             \
paulson@3683
   175
\        Key K : analz (insert (Key KAB) (spies evs)) =       \
paulson@3683
   176
\        (K = KAB | Key K : analz (spies evs))";
paulson@2516
   177
by (asm_simp_tac (analz_image_freshK_ss addsimps [analz_image_freshK]) 1);
paulson@2516
   178
qed "analz_insert_freshK";
paulson@1985
   179
paulson@1985
   180
paulson@2110
   181
(*** The Key K uniquely identifies the Server's  message. **)
paulson@2110
   182
paulson@2110
   183
goal thy 
paulson@3519
   184
 "!!evs. evs : yahalom ==>                                     \
paulson@3466
   185
\      EX A' B' na' nb' X'. ALL A B na nb X.                        \
paulson@2110
   186
\          Says Server A                                            \
paulson@3450
   187
\           {|Crypt (shrK A) {|Agent B, Key K, na, nb|}, X|}        \
nipkow@3465
   188
\          : set evs --> A=A' & B=B' & na=na' & nb=nb' & X=X'";
paulson@2110
   189
by (etac yahalom.induct 1);
wenzelm@4091
   190
by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
paulson@3708
   191
by (ALLGOALS Clarify_tac);
paulson@2133
   192
by (ex_strip_tac 2);
paulson@3121
   193
by (Blast_tac 2);
paulson@2110
   194
(*Remaining case: YM3*)
paulson@2110
   195
by (expand_case_tac "K = ?y" 1);
paulson@2110
   196
by (REPEAT (ares_tac [refl,exI,impI,conjI] 2));
paulson@2516
   197
(*...we assume X is a recent message and handle this case by contradiction*)
wenzelm@4091
   198
by (blast_tac (claset() addSEs spies_partsEs
paulson@3708
   199
                       delrules [conjI]    (*no split-up to 4 subgoals*)) 1);
paulson@2110
   200
val lemma = result();
paulson@2110
   201
paulson@2110
   202
goal thy 
paulson@3683
   203
"!!evs. [| Says Server A                                                 \
paulson@3683
   204
\            {|Crypt (shrK A) {|Agent B, Key K, na, nb|}, X|} : set evs; \
paulson@3683
   205
\          Says Server A'                                                \
paulson@3683
   206
\            {|Crypt (shrK A') {|Agent B', Key K, na', nb'|}, X'|} : set evs; \
paulson@3519
   207
\          evs : yahalom |]                                    \
paulson@3450
   208
\       ==> A=A' & B=B' & na=na' & nb=nb'";
paulson@2451
   209
by (prove_unique_tac lemma 1);
paulson@2110
   210
qed "unique_session_keys";
paulson@2110
   211
paulson@2110
   212
paulson@2110
   213
(** Crucial secrecy property: Spy does not see the keys sent in msg YM3 **)
paulson@2013
   214
paulson@2013
   215
goal thy 
paulson@3683
   216
 "!!evs. [| A ~: bad;  B ~: bad;  evs : yahalom |]         \
paulson@2051
   217
\        ==> Says Server A                                        \
paulson@3450
   218
\              {|Crypt (shrK A) {|Agent B, Key K, na, nb|},       \
paulson@2284
   219
\                Crypt (shrK B) {|Agent A, Key K|}|}              \
paulson@3466
   220
\             : set evs -->                                       \
paulson@3466
   221
\            Says A Spy {|na, nb, Key K|} ~: set evs -->          \
paulson@3683
   222
\            Key K ~: analz (spies evs)";
paulson@2032
   223
by (etac yahalom.induct 1);
paulson@3683
   224
by analz_spies_tac;
paulson@2013
   225
by (ALLGOALS
paulson@2013
   226
    (asm_simp_tac 
wenzelm@4091
   227
     (simpset() addsimps (expand_ifs@pushes)
paulson@3961
   228
	       addsimps [analz_insert_eq, analz_insert_freshK])));
paulson@3450
   229
(*Oops*)
wenzelm@4091
   230
by (blast_tac (claset() addDs [unique_session_keys]) 3);
paulson@2013
   231
(*YM3*)
wenzelm@4091
   232
by (blast_tac (claset() delrules [impCE]
paulson@3683
   233
                       addSEs spies_partsEs
paulson@3121
   234
                       addIs [impOfSubs analz_subset_parts]) 2);
paulson@3450
   235
(*Fake*) 
paulson@3450
   236
by (spy_analz_tac 1);
paulson@2110
   237
val lemma = result() RS mp RS mp RSN(2,rev_notE);
paulson@2013
   238
paulson@2013
   239
paulson@3432
   240
(*Final version*)
paulson@1985
   241
goal thy 
paulson@2516
   242
 "!!evs. [| Says Server A                                         \
paulson@3450
   243
\              {|Crypt (shrK A) {|Agent B, Key K, na, nb|},       \
paulson@2516
   244
\                Crypt (shrK B) {|Agent A, Key K|}|}              \
paulson@3466
   245
\             : set evs;                                          \
paulson@3466
   246
\           Says A Spy {|na, nb, Key K|} ~: set evs;              \
paulson@3683
   247
\           A ~: bad;  B ~: bad;  evs : yahalom |]         \
paulson@3683
   248
\        ==> Key K ~: analz (spies evs)";
paulson@2013
   249
by (forward_tac [Says_Server_message_form] 1 THEN assume_tac 1);
wenzelm@4091
   250
by (blast_tac (claset() addSEs [lemma]) 1);
paulson@2032
   251
qed "Spy_not_see_encrypted_key";
paulson@2001
   252
paulson@2001
   253
paulson@3444
   254
(** Security Guarantee for A upon receiving YM3 **)
paulson@3444
   255
paulson@3444
   256
(*If the encrypted message appears then it originated with the Server*)
paulson@3444
   257
goal thy
paulson@3683
   258
 "!!evs. [| Crypt (shrK A) {|Agent B, Key K, na, nb|} : parts (spies evs); \
paulson@3683
   259
\           A ~: bad;  evs : yahalom |]                          \
paulson@3444
   260
\         ==> Says Server A                                            \
paulson@3450
   261
\              {|Crypt (shrK A) {|Agent B, Key K, na, nb|},            \
paulson@3444
   262
\                Crypt (shrK B) {|Agent A, Key K|}|}                   \
nipkow@3465
   263
\             : set evs";
paulson@3444
   264
by (etac rev_mp 1);
paulson@3519
   265
by (parts_induct_tac 1);
paulson@3444
   266
by (Fake_parts_insert_tac 1);
paulson@3444
   267
qed "A_trusts_YM3";
paulson@3444
   268
paulson@3444
   269
paulson@3444
   270
(** Security Guarantees for B upon receiving YM4 **)
paulson@2013
   271
paulson@2110
   272
(*B knows, by the first part of A's message, that the Server distributed 
paulson@2110
   273
  the key for A and B.  But this part says nothing about nonces.*)
paulson@2001
   274
goal thy 
paulson@3683
   275
 "!!evs. [| Crypt (shrK B) {|Agent A, Key K|} : parts (spies evs);   \
paulson@3683
   276
\           B ~: bad;  evs : yahalom |]                                \
paulson@2001
   277
\        ==> EX NA NB. Says Server A                                    \
paulson@2451
   278
\                        {|Crypt (shrK A) {|Agent B, Key K,             \
paulson@2516
   279
\                                           Nonce NA, Nonce NB|},       \
paulson@2284
   280
\                          Crypt (shrK B) {|Agent A, Key K|}|}          \
nipkow@3465
   281
\                       : set evs";
paulson@2032
   282
by (etac rev_mp 1);
paulson@3519
   283
by (parts_induct_tac 1);
paulson@3121
   284
by (Fake_parts_insert_tac 1);
paulson@2110
   285
(*YM3*)
paulson@3121
   286
by (Blast_tac 1);
paulson@2110
   287
qed "B_trusts_YM4_shrK";
paulson@2110
   288
paulson@3444
   289
(*B knows, by the second part of A's message, that the Server distributed 
paulson@3444
   290
  the key quoting nonce NB.  This part says nothing about agent names. 
paulson@3444
   291
  Secrecy of NB is crucial.*)
paulson@3444
   292
goal thy 
paulson@3519
   293
 "!!evs. evs : yahalom                                             \
paulson@3683
   294
\        ==> Nonce NB ~: analz (spies evs) -->                  \
paulson@3683
   295
\            Crypt K (Nonce NB) : parts (spies evs) -->         \
paulson@3543
   296
\            (EX A B NA. Says Server A                             \
paulson@3543
   297
\                        {|Crypt (shrK A) {|Agent B, Key K,        \
paulson@3543
   298
\                                  Nonce NA, Nonce NB|},           \
paulson@3543
   299
\                          Crypt (shrK B) {|Agent A, Key K|}|}     \
nipkow@3465
   300
\                       : set evs)";
paulson@3519
   301
by (parts_induct_tac 1);
paulson@3708
   302
by (ALLGOALS Clarify_tac);
paulson@3444
   303
(*YM3 & Fake*)
paulson@3444
   304
by (Blast_tac 2);
paulson@3444
   305
by (Fake_parts_insert_tac 1);
paulson@3444
   306
(*YM4*)
paulson@3444
   307
(*A is uncompromised because NB is secure*)
paulson@3683
   308
by (not_bad_tac "A" 1);
paulson@3444
   309
(*A's certificate guarantees the existence of the Server message*)
wenzelm@4091
   310
by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj RS parts.Fst RS
paulson@3444
   311
			      A_trusts_YM3]) 1);
paulson@3464
   312
bind_thm ("B_trusts_YM4_newK", result() RS mp RSN (2, rev_mp));
paulson@2133
   313
paulson@3444
   314
paulson@3444
   315
(**** Towards proving secrecy of Nonce NB ****)
paulson@3444
   316
paulson@3444
   317
(** Lemmas about the predicate KeyWithNonce **)
paulson@3444
   318
paulson@3444
   319
goalw thy [KeyWithNonce_def]
paulson@3444
   320
 "!!evs. Says Server A                                              \
paulson@3444
   321
\            {|Crypt (shrK A) {|Agent B, Key K, na, Nonce NB|}, X|} \
nipkow@3465
   322
\          : set evs ==> KeyWithNonce K NB evs";
paulson@3444
   323
by (Blast_tac 1);
paulson@3444
   324
qed "KeyWithNonceI";
paulson@3444
   325
paulson@3444
   326
goalw thy [KeyWithNonce_def]
paulson@3444
   327
   "KeyWithNonce K NB (Says S A X # evs) =                                    \
paulson@3444
   328
\    (Server = S &                                                            \
paulson@3444
   329
\     (EX B n X'. X = {|Crypt (shrK A) {|Agent B, Key K, n, Nonce NB|}, X'|}) \
paulson@3444
   330
\    | KeyWithNonce K NB evs)";
paulson@3444
   331
by (Simp_tac 1);
paulson@3444
   332
by (Blast_tac 1);
paulson@3444
   333
qed "KeyWithNonce_Says";
paulson@3444
   334
Addsimps [KeyWithNonce_Says];
paulson@3444
   335
paulson@3464
   336
(*A fresh key cannot be associated with any nonce 
paulson@3464
   337
  (with respect to a given trace). *)
paulson@3444
   338
goalw thy [KeyWithNonce_def]
paulson@3444
   339
 "!!evs. Key K ~: used evs ==> ~ KeyWithNonce K NB evs";
wenzelm@4091
   340
by (blast_tac (claset() addSEs spies_partsEs) 1);
paulson@3444
   341
qed "fresh_not_KeyWithNonce";
paulson@3444
   342
paulson@3444
   343
(*The Server message associates K with NB' and therefore not with any 
paulson@3444
   344
  other nonce NB.*)
paulson@3444
   345
goalw thy [KeyWithNonce_def]
paulson@3444
   346
 "!!evs. [| Says Server A                                                \
paulson@3444
   347
\                {|Crypt (shrK A) {|Agent B, Key K, na, Nonce NB'|}, X|} \
paulson@3466
   348
\             : set evs;                                                 \
paulson@3519
   349
\           NB ~= NB';  evs : yahalom |]                            \
paulson@3444
   350
\        ==> ~ KeyWithNonce K NB evs";
wenzelm@4091
   351
by (blast_tac (claset() addDs [unique_session_keys]) 1);
paulson@3444
   352
qed "Says_Server_KeyWithNonce";
paulson@3444
   353
paulson@3444
   354
paulson@3444
   355
(*The only nonces that can be found with the help of session keys are
paulson@3444
   356
  those distributed as nonce NB by the Server.  The form of the theorem
paulson@3444
   357
  recalls analz_image_freshK, but it is much more complicated.*)
paulson@3444
   358
paulson@3444
   359
paulson@3444
   360
(*As with analz_image_freshK, we take some pains to express the property
paulson@3444
   361
  as a logical equivalence so that the simplifier can apply it.*)
paulson@3444
   362
goal thy  
paulson@3444
   363
 "!!evs. P --> (X : analz (G Un H)) --> (X : analz H)  ==> \
paulson@3444
   364
\        P --> (X : analz (G Un H)) = (X : analz H)";
wenzelm@4091
   365
by (blast_tac (claset() addIs [impOfSubs analz_mono]) 1);
paulson@3961
   366
val Nonce_secrecy_lemma = result();
paulson@2133
   367
paulson@2133
   368
goal thy 
paulson@3519
   369
 "!!evs. evs : yahalom ==>                                         \
paulson@3444
   370
\        (ALL KK. KK <= Compl (range shrK) -->                          \
paulson@3444
   371
\             (ALL K: KK. ~ KeyWithNonce K NB evs)   -->                \
paulson@3683
   372
\             (Nonce NB : analz (Key``KK Un (spies evs))) =     \
paulson@3683
   373
\             (Nonce NB : analz (spies evs)))";
paulson@3444
   374
by (etac yahalom.induct 1);
paulson@3683
   375
by analz_spies_tac;
paulson@3444
   376
by (REPEAT_FIRST (resolve_tac [impI RS allI]));
paulson@3961
   377
by (REPEAT_FIRST (rtac Nonce_secrecy_lemma));
paulson@3444
   378
(*For Oops, simplification proves NBa~=NB.  By Says_Server_KeyWithNonce,
paulson@3444
   379
  we get (~ KeyWithNonce K NB evsa); then simplification can apply the
paulson@3444
   380
  induction hypothesis with KK = {K}.*)
paulson@3961
   381
by (ALLGOALS  (*12 seconds*)
paulson@3444
   382
    (asm_simp_tac 
paulson@3961
   383
     (analz_image_freshK_ss 
paulson@3961
   384
       addsimps expand_ifs
paulson@3961
   385
       addsimps [all_conj_distrib, analz_image_freshK,
paulson@3961
   386
		 KeyWithNonce_Says, fresh_not_KeyWithNonce, 
paulson@3961
   387
		 imp_disj_not1,		     (*Moves NBa~=NB to the front*)
paulson@3961
   388
		 Says_Server_KeyWithNonce])));
paulson@3444
   389
(*Base*)
paulson@3444
   390
by (Blast_tac 1);
paulson@3444
   391
(*Fake*) 
paulson@3444
   392
by (spy_analz_tac 1);
paulson@3444
   393
(*YM4*)  (** LEVEL 7 **)
paulson@3683
   394
by (not_bad_tac "A" 1);
paulson@3683
   395
by (dtac (Says_imp_spies RS parts.Inj RS parts.Fst RS A_trusts_YM3) 1
paulson@3444
   396
    THEN REPEAT (assume_tac 1));
wenzelm@4091
   397
by (blast_tac (claset() addIs [KeyWithNonceI]) 1);
paulson@3444
   398
qed_spec_mp "Nonce_secrecy";
paulson@3444
   399
paulson@3444
   400
paulson@3444
   401
(*Version required below: if NB can be decrypted using a session key then it
paulson@3444
   402
  was distributed with that key.  The more general form above is required
paulson@3444
   403
  for the induction to carry through.*)
paulson@3444
   404
goal thy 
paulson@3444
   405
 "!!evs. [| Says Server A                                                 \
paulson@3444
   406
\            {|Crypt (shrK A) {|Agent B, Key KAB, na, Nonce NB'|}, X|}    \
paulson@3466
   407
\           : set evs;                                                    \
paulson@3519
   408
\           NB ~= NB';  KAB ~: range shrK;  evs : yahalom |]         \
paulson@3683
   409
\        ==> (Nonce NB : analz (insert (Key KAB) (spies evs))) =  \
paulson@3683
   410
\            (Nonce NB : analz (spies evs))";
paulson@3444
   411
by (asm_simp_tac (analz_image_freshK_ss addsimps 
paulson@3444
   412
		  [Nonce_secrecy, Says_Server_KeyWithNonce]) 1);
paulson@3444
   413
qed "single_Nonce_secrecy";
paulson@3444
   414
paulson@3444
   415
paulson@3444
   416
(*** The Nonce NB uniquely identifies B's message. ***)
paulson@3444
   417
paulson@3444
   418
goal thy 
paulson@3519
   419
 "!!evs. evs : yahalom ==>                                            \
paulson@3444
   420
\   EX NA' A' B'. ALL NA A B.                                              \
paulson@3683
   421
\      Crypt (shrK B) {|Agent A, Nonce NA, nb|} : parts(spies evs) \
paulson@3683
   422
\      --> B ~: bad --> NA = NA' & A = A' & B = B'";
paulson@3519
   423
by (parts_induct_tac 1);
paulson@3121
   424
(*Fake*)
paulson@3121
   425
by (REPEAT (etac (exI RSN (2,exE)) 1)   (*stripping EXs makes proof faster*)
paulson@3121
   426
    THEN Fake_parts_insert_tac 1);
wenzelm@4091
   427
by (asm_simp_tac (simpset() addsimps [all_conj_distrib]) 1); 
paulson@2133
   428
(*YM2: creation of new Nonce.  Move assertion into global context*)
paulson@3501
   429
by (expand_case_tac "nb = ?y" 1);
paulson@2516
   430
by (REPEAT (resolve_tac [exI, conjI, impI, refl] 1));
wenzelm@4091
   431
by (blast_tac (claset() addSEs spies_partsEs) 1);
paulson@2133
   432
val lemma = result();
paulson@2133
   433
paulson@2110
   434
goal thy 
paulson@3683
   435
 "!!evs.[| Crypt (shrK B) {|Agent A, Nonce NA, nb|} : parts (spies evs); \
paulson@3683
   436
\          Crypt (shrK B') {|Agent A', Nonce NA', nb|} : parts (spies evs); \
paulson@3683
   437
\          evs : yahalom;  B ~: bad;  B' ~: bad |]  \
paulson@2133
   438
\        ==> NA' = NA & A' = A & B' = B";
paulson@2451
   439
by (prove_unique_tac lemma 1);
paulson@2133
   440
qed "unique_NB";
paulson@2133
   441
paulson@2133
   442
paulson@3444
   443
(*Variant useful for proving secrecy of NB: the Says... form allows 
paulson@3683
   444
  not_bad_tac to remove the assumption B' ~: bad.*)
paulson@2133
   445
goal thy 
paulson@3501
   446
 "!!evs.[| Says C D   {|X,  Crypt (shrK B) {|Agent A, Nonce NA, nb|}|}    \
paulson@3683
   447
\            : set evs;          B ~: bad;                               \
paulson@3501
   448
\          Says C' D' {|X', Crypt (shrK B') {|Agent A', Nonce NA', nb|}|} \
paulson@3466
   449
\            : set evs;                                                   \
paulson@3683
   450
\          nb ~: analz (spies evs);  evs : yahalom |]        \
paulson@2133
   451
\        ==> NA' = NA & A' = A & B' = B";
paulson@3683
   452
by (not_bad_tac "B'" 1);
wenzelm@4091
   453
by (blast_tac (claset() addSDs [Says_imp_spies RS parts.Inj]
paulson@3121
   454
                       addSEs [MPair_parts]
paulson@3121
   455
                       addDs  [unique_NB]) 1);
paulson@2133
   456
qed "Says_unique_NB";
paulson@2133
   457
paulson@3444
   458
paulson@3444
   459
(** A nonce value is never used both as NA and as NB **)
paulson@3121
   460
paulson@2133
   461
goal thy 
paulson@3683
   462
 "!!evs. [| B ~: bad;  evs : yahalom  |]            \
paulson@3683
   463
\ ==> Nonce NB ~: analz (spies evs) -->           \
paulson@3683
   464
\     Crypt (shrK B') {|Agent A', Nonce NB, nb'|} : parts(spies evs) --> \
paulson@3683
   465
\     Crypt (shrK B)  {|Agent A, Nonce NA, Nonce NB|} ~: parts(spies evs)";
paulson@3519
   466
by (parts_induct_tac 1);
paulson@3121
   467
by (Fake_parts_insert_tac 1);
wenzelm@4091
   468
by (blast_tac (claset() addDs [Says_imp_spies RS analz.Inj]
paulson@3121
   469
                       addSIs [parts_insertI]
paulson@3121
   470
                       addSEs partsEs) 1);
paulson@3464
   471
bind_thm ("no_nonce_YM1_YM2", result() RS mp RSN (2,rev_mp) RSN (2,rev_notE));
paulson@2133
   472
paulson@3464
   473
(*The Server sends YM3 only in response to YM2.*)
paulson@2133
   474
goal thy 
paulson@3466
   475
 "!!evs. [| Says Server A                                                \
paulson@3466
   476
\            {|Crypt (shrK A) {|Agent B, k, na, nb|}, X|} : set evs;     \
paulson@3519
   477
\           evs : yahalom |]                                             \
paulson@2133
   478
\        ==> EX B'. Says B' Server                                       \
paulson@2284
   479
\                      {| Agent B, Crypt (shrK B) {|Agent A, na, nb|} |} \
nipkow@3465
   480
\                   : set evs";
paulson@2133
   481
by (etac rev_mp 1);
paulson@2133
   482
by (etac yahalom.induct 1);
paulson@2133
   483
by (ALLGOALS Asm_simp_tac);
paulson@3121
   484
by (ALLGOALS Blast_tac);
paulson@2133
   485
qed "Says_Server_imp_YM2";
paulson@2133
   486
paulson@2133
   487
paulson@3519
   488
(*A vital theorem for B, that nonce NB remains secure from the Spy.*)
paulson@2133
   489
goal thy 
paulson@3683
   490
 "!!evs. [| A ~: bad;  B ~: bad;  evs : yahalom |]  \
paulson@2133
   491
\ ==> Says B Server                                                    \
paulson@2284
   492
\          {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|} \
paulson@3466
   493
\     : set evs -->                                                    \
paulson@3466
   494
\     (ALL k. Says A Spy {|Nonce NA, Nonce NB, k|} ~: set evs) -->     \
paulson@3683
   495
\     Nonce NB ~: analz (spies evs)";
paulson@2133
   496
by (etac yahalom.induct 1);
paulson@3683
   497
by analz_spies_tac;
paulson@2133
   498
by (ALLGOALS
paulson@2133
   499
    (asm_simp_tac 
wenzelm@4091
   500
     (simpset() addsimps (expand_ifs@pushes)
paulson@3961
   501
	       addsimps [analz_insert_eq, analz_insert_freshK])));
paulson@3450
   502
(*Prove YM3 by showing that no NB can also be an NA*)
wenzelm@4091
   503
by (blast_tac (claset() addDs [Says_imp_spies RS parts.Inj]
paulson@3450
   504
	               addSEs [MPair_parts]
paulson@3519
   505
		       addDs  [no_nonce_YM1_YM2, Says_unique_NB]) 4
paulson@3450
   506
    THEN flexflex_tac);
paulson@3444
   507
(*YM2: similar freshness reasoning*) 
wenzelm@4091
   508
by (blast_tac (claset() addSEs partsEs
paulson@3683
   509
		       addDs  [Says_imp_spies RS analz.Inj,
paulson@3450
   510
			       impOfSubs analz_subset_parts]) 3);
paulson@3450
   511
(*YM1: NB=NA is impossible anyway, but NA is secret because it is fresh!*)
wenzelm@4091
   512
by (blast_tac (claset() addSIs [parts_insertI]
paulson@3683
   513
                       addSEs spies_partsEs) 2);
paulson@2377
   514
(*Fake*)
paulson@2377
   515
by (spy_analz_tac 1);
paulson@3444
   516
(** LEVEL 7: YM4 and Oops remain **)
paulson@3708
   517
by (ALLGOALS Clarify_tac);
paulson@3444
   518
(*YM4: key K is visible to Spy, contradicting session key secrecy theorem*) 
paulson@3683
   519
by (not_bad_tac "Aa" 1);
paulson@3683
   520
by (dtac (Says_imp_spies RS parts.Inj RS parts.Fst RS A_trusts_YM3) 1);
paulson@2133
   521
by (forward_tac [Says_Server_message_form] 3);
paulson@2133
   522
by (forward_tac [Says_Server_imp_YM2] 4);
paulson@3121
   523
by (REPEAT_FIRST (eresolve_tac [asm_rl, bexE, exE, disjE]));
paulson@3519
   524
(*  use Says_unique_NB to identify message components: Aa=A, Ba=B, NAa=NA *)
wenzelm@4091
   525
by (blast_tac (claset() addDs [Says_unique_NB, Spy_not_see_encrypted_key,
paulson@3444
   526
			      impOfSubs Fake_analz_insert]) 1);
paulson@3444
   527
(** LEVEL 14 **)
paulson@3444
   528
(*Oops case: if the nonce is betrayed now, show that the Oops event is 
paulson@3444
   529
  covered by the quantified Oops assumption.*)
wenzelm@4091
   530
by (full_simp_tac (simpset() addsimps [all_conj_distrib]) 1);
paulson@2133
   531
by (forward_tac [Says_Server_imp_YM2] 1 THEN assume_tac 1 THEN etac exE 1);
paulson@2133
   532
by (expand_case_tac "NB = NBa" 1);
paulson@3444
   533
(*If NB=NBa then all other components of the Oops message agree*)
wenzelm@4091
   534
by (blast_tac (claset() addDs [Says_unique_NB]) 1 THEN flexflex_tac);
paulson@3444
   535
(*case NB ~= NBa*)
wenzelm@4091
   536
by (asm_simp_tac (simpset() addsimps [single_Nonce_secrecy]) 1);
wenzelm@4091
   537
by (blast_tac (claset() addSEs [MPair_parts]
paulson@3683
   538
		       addDs  [Says_imp_spies RS parts.Inj, 
paulson@3444
   539
			       no_nonce_YM1_YM2 (*to prove NB~=NAa*) ]) 1);
paulson@3444
   540
bind_thm ("Spy_not_see_NB", result() RSN(2,rev_mp) RSN(2,rev_mp));
paulson@2133
   541
paulson@2001
   542
paulson@3464
   543
(*B's session key guarantee from YM4.  The two certificates contribute to a
paulson@3464
   544
  single conclusion about the Server's message.  Note that the "Says A Spy"
paulson@3464
   545
  assumption must quantify over ALL POSSIBLE keys instead of our particular K.
paulson@3464
   546
  If this run is broken and the spy substitutes a certificate containing an
paulson@3464
   547
  old key, B has no means of telling.*)
paulson@2001
   548
goal thy 
paulson@3444
   549
 "!!evs. [| Says B Server                                                   \
paulson@3444
   550
\             {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|}   \
paulson@3466
   551
\             : set evs;                                                    \
paulson@3444
   552
\           Says A' B {|Crypt (shrK B) {|Agent A, Key K|},                  \
paulson@3466
   553
\                       Crypt K (Nonce NB)|} : set evs;                     \
paulson@3466
   554
\           ALL k. Says A Spy {|Nonce NA, Nonce NB, k|} ~: set evs;         \
paulson@3683
   555
\           A ~: bad;  B ~: bad;  evs : yahalom |]       \
paulson@3444
   556
\         ==> Says Server A                                                 \
paulson@3444
   557
\                     {|Crypt (shrK A) {|Agent B, Key K,                    \
paulson@3444
   558
\                               Nonce NA, Nonce NB|},                       \
paulson@3444
   559
\                       Crypt (shrK B) {|Agent A, Key K|}|}                 \
nipkow@3465
   560
\               : set evs";
paulson@2133
   561
by (forward_tac [Spy_not_see_NB] 1 THEN REPEAT (assume_tac 1));
paulson@3683
   562
by (etac (Says_imp_spies RS parts.Inj RS MPair_parts) 1 THEN
paulson@2133
   563
    dtac B_trusts_YM4_shrK 1);
paulson@2170
   564
by (dtac B_trusts_YM4_newK 3);
paulson@2110
   565
by (REPEAT_FIRST (eresolve_tac [asm_rl, exE]));
paulson@2133
   566
by (forward_tac [Says_Server_imp_YM2] 1 THEN assume_tac 1);
paulson@2170
   567
by (dtac unique_session_keys 1 THEN REPEAT (assume_tac 1));
wenzelm@4091
   568
by (blast_tac (claset() addDs [Says_unique_NB]) 1);
paulson@2322
   569
qed "B_trusts_YM4";
paulson@3444
   570
paulson@3444
   571
paulson@3444
   572
paulson@3444
   573
(*** Authenticating B to A ***)
paulson@3444
   574
paulson@3444
   575
(*The encryption in message YM2 tells us it cannot be faked.*)
paulson@3444
   576
goal thy 
paulson@3519
   577
 "!!evs. evs : yahalom                                            \
paulson@3683
   578
\  ==> Crypt (shrK B) {|Agent A, Nonce NA, nb|} : parts (spies evs) --> \
paulson@3683
   579
\      B ~: bad -->                                              \
paulson@3466
   580
\      Says B Server {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, nb|}|}  \
nipkow@3465
   581
\         : set evs";
paulson@3519
   582
by (parts_induct_tac 1);
paulson@3444
   583
by (Fake_parts_insert_tac 1);
paulson@3444
   584
bind_thm ("B_Said_YM2", result() RSN (2, rev_mp) RS mp);
paulson@3444
   585
paulson@3444
   586
(*If the server sends YM3 then B sent YM2*)
paulson@3444
   587
goal thy 
paulson@3519
   588
 "!!evs. evs : yahalom                                                      \
paulson@3444
   589
\  ==> Says Server A {|Crypt (shrK A) {|Agent B, Key K, Nonce NA, nb|}, X|} \
paulson@3466
   590
\         : set evs -->                                                     \
paulson@3683
   591
\      B ~: bad -->                                                        \
paulson@3466
   592
\      Says B Server {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, nb|}|}  \
nipkow@3465
   593
\                 : set evs";
paulson@3444
   594
by (etac yahalom.induct 1);
paulson@3444
   595
by (ALLGOALS Asm_simp_tac);
paulson@3444
   596
(*YM4*)
paulson@3444
   597
by (Blast_tac 2);
paulson@3444
   598
(*YM3*)
wenzelm@4091
   599
by (best_tac (claset() addSDs [B_Said_YM2, Says_imp_spies RS parts.Inj]
paulson@3444
   600
		      addSEs [MPair_parts]) 1);
paulson@3444
   601
val lemma = result() RSN (2, rev_mp) RS mp |> standard;
paulson@3444
   602
paulson@3444
   603
(*If A receives YM3 then B has used nonce NA (and therefore is alive)*)
paulson@3444
   604
goal thy
paulson@3444
   605
 "!!evs. [| Says S A {|Crypt (shrK A) {|Agent B, Key K, Nonce NA, nb|}, X|} \
paulson@3466
   606
\             : set evs;                                                    \
paulson@3683
   607
\           A ~: bad;  B ~: bad;  evs : yahalom |]                        \
paulson@3444
   608
\   ==> Says B Server {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, nb|}|} \
nipkow@3465
   609
\         : set evs";
wenzelm@4091
   610
by (blast_tac (claset() addSDs [A_trusts_YM3, lemma]
paulson@3683
   611
		       addEs spies_partsEs) 1);
paulson@3444
   612
qed "YM3_auth_B_to_A";
paulson@3444
   613
paulson@3444
   614
paulson@3444
   615
(*** Authenticating A to B using the certificate Crypt K (Nonce NB) ***)
paulson@3444
   616
paulson@3444
   617
(*Assuming the session key is secure, if both certificates are present then
paulson@3444
   618
  A has said NB.  We can't be sure about the rest of A's message, but only
paulson@3444
   619
  NB matters for freshness.*)  
paulson@3444
   620
goal thy 
paulson@3519
   621
 "!!evs. evs : yahalom                                             \
paulson@3683
   622
\        ==> Key K ~: analz (spies evs) -->                     \
paulson@3683
   623
\            Crypt K (Nonce NB) : parts (spies evs) -->         \
paulson@3683
   624
\            Crypt (shrK B) {|Agent A, Key K|} : parts (spies evs) --> \
paulson@3683
   625
\            B ~: bad -->                                         \
paulson@3683
   626
\            (EX X. Says A B {|X, Crypt K (Nonce NB)|} : set evs)";
paulson@3519
   627
by (parts_induct_tac 1);
paulson@3444
   628
(*Fake*)
paulson@3444
   629
by (Fake_parts_insert_tac 1);
paulson@3444
   630
(*YM3: by new_keys_not_used we note that Crypt K (Nonce NB) could not exist*)
wenzelm@4091
   631
by (fast_tac (claset() addSDs [Crypt_imp_invKey_keysFor] addss (simpset())) 1); 
paulson@3444
   632
(*YM4: was Crypt K (Nonce NB) the very last message?  If not, use ind. hyp.*)
wenzelm@4091
   633
by (asm_simp_tac (simpset() addsimps [ex_disj_distrib]) 1);
paulson@3444
   634
(*yes: apply unicity of session keys*)
paulson@3683
   635
by (not_bad_tac "Aa" 1);
wenzelm@4091
   636
by (blast_tac (claset() addSEs [MPair_parts]
paulson@3444
   637
                       addSDs [A_trusts_YM3, B_trusts_YM4_shrK]
paulson@3683
   638
		       addDs  [Says_imp_spies RS parts.Inj,
paulson@3444
   639
			       unique_session_keys]) 1);
paulson@3444
   640
val lemma = normalize_thm [RSspec, RSmp] (result()) |> standard;
paulson@3444
   641
paulson@3444
   642
(*If B receives YM4 then A has used nonce NB (and therefore is alive).
paulson@3444
   643
  Moreover, A associates K with NB (thus is talking about the same run).
paulson@3444
   644
  Other premises guarantee secrecy of K.*)
paulson@3444
   645
goal thy 
paulson@3444
   646
 "!!evs. [| Says B Server                                                   \
paulson@3444
   647
\             {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|}   \
paulson@3466
   648
\             : set evs;                                                    \
paulson@3466
   649
\           Says A' B {|Crypt (shrK B) {|Agent A, Key K|},                  \
paulson@3466
   650
\                       Crypt K (Nonce NB)|} : set evs;                     \
paulson@3466
   651
\           (ALL NA k. Says A Spy {|Nonce NA, Nonce NB, k|} ~: set evs);    \
paulson@3683
   652
\           A ~: bad;  B ~: bad;  evs : yahalom |]       \
nipkow@3465
   653
\        ==> EX X. Says A B {|X, Crypt K (Nonce NB)|} : set evs";
paulson@3444
   654
by (dtac B_trusts_YM4 1);
paulson@3444
   655
by (REPEAT_FIRST (eresolve_tac [asm_rl, spec]));
paulson@3683
   656
by (etac (Says_imp_spies RS parts.Inj RS MPair_parts) 1);
paulson@3444
   657
by (rtac lemma 1);
paulson@3444
   658
by (rtac Spy_not_see_encrypted_key 2);
paulson@3444
   659
by (REPEAT_FIRST assume_tac);
wenzelm@4091
   660
by (blast_tac (claset() addSEs [MPair_parts]
paulson@3683
   661
	       	       addDs [Says_imp_spies RS parts.Inj]) 1);
paulson@3444
   662
qed_spec_mp "YM4_imp_A_Said_YM3";