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