src/HOL/Auth/Yahalom.ML
author paulson
Mon Jul 14 12:47:21 1997 +0200 (1997-07-14)
changeset 3519 ab0a9fbed4c0
parent 3516 470626799511
child 3543 82f33248d89d
permissions -rw-r--r--
Changing "lost" from a parameter of protocol definitions to a constant.

Advantages: no "lost" argument everywhere; fewer Vars in subgoals;
less need for specially instantiated rules
Disadvantage: can no longer prove "Agent_not_see_encrypted_key", but this
theorem was never used, and its original proof was also broken
the introduction of the "Notes" constructor.
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@3519
    47
\                X : analz (sees Spy evs)";
paulson@3519
    48
by (blast_tac (!claset addSDs [Says_imp_sees_Spy RS analz.Inj]) 1);
paulson@2032
    49
qed "YM4_analz_sees_Spy";
paulson@1985
    50
paulson@2110
    51
bind_thm ("YM4_parts_sees_Spy",
paulson@2110
    52
          YM4_analz_sees_Spy 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@3519
    56
\                K : parts (sees Spy evs)";
paulson@3121
    57
by (blast_tac (!claset addSEs partsEs
paulson@3519
    58
                      addSDs [Says_imp_sees_Spy RS parts.Inj]) 1);
paulson@2110
    59
qed "YM4_Key_parts_sees_Spy";
paulson@2110
    60
paulson@3519
    61
(*For proving the easier theorems about X ~: parts (sees Spy evs).*)
paulson@3519
    62
fun parts_sees_tac i = 
paulson@3519
    63
    forward_tac [YM4_Key_parts_sees_Spy] (i+6) THEN
paulson@3519
    64
    forward_tac [YM4_parts_sees_Spy] (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@3519
    68
   X ~: analz (sees Spy evs) --> ... then it shortens the proof by discarding
paulson@3519
    69
   needless information about analz (insert X (sees Spy 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@3519
    74
    THEN  parts_sees_tac i;
paulson@1985
    75
paulson@1985
    76
paulson@3519
    77
(** Theorems of the form X ~: parts (sees Spy evs) imply that NOBODY
paulson@2013
    78
    sends messages containing X! **)
paulson@1985
    79
paulson@2133
    80
(*Spy never sees another agent's shared key! (unless it's lost at start)*)
paulson@1985
    81
goal thy 
paulson@3519
    82
 "!!evs. evs : yahalom ==> (Key (shrK A) : parts (sees Spy evs)) = (A : lost)";
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@3519
    90
 "!!evs. evs : yahalom ==> (Key (shrK A) : analz (sees Spy evs)) = (A : lost)";
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@3519
    95
goal thy  "!!A. [| Key (shrK A) : parts (sees Spy evs);       \
paulson@3519
    96
\                  evs : yahalom |] ==> A:lost";
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@3519
   106
\         Key K ~: used evs --> K ~: keysFor (parts (sees Spy evs))";
paulson@3519
   107
by (parts_induct_tac 1);
paulson@2516
   108
(*YM4: Key K is not fresh!*)
paulson@3121
   109
by (blast_tac (!claset addSEs sees_Spy_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@3121
   142
val analz_sees_tac = 
paulson@3519
   143
    forward_tac [YM4_analz_sees_Spy] 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@3519
   151
  Key K : analz (insert (Key KAB) (sees Spy evs)) ==>
paulson@3519
   152
  Key K : analz (sees Spy 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@3519
   162
\            (Key K : analz (Key``KK Un (sees Spy evs))) = \
paulson@3519
   163
\            (K : KK | Key K : analz (sees Spy evs))";
paulson@2032
   164
by (etac yahalom.induct 1);
paulson@3121
   165
by analz_sees_tac;
paulson@2516
   166
by (REPEAT_FIRST (resolve_tac [allI, impI]));
paulson@2516
   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@3519
   177
\        Key K : analz (insert (Key KAB) (sees Spy evs)) =       \
paulson@3519
   178
\        (K = KAB | Key K : analz (sees Spy 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@3121
   200
by (blast_tac (!claset addSEs sees_Spy_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@2110
   205
"!!evs. [| Says Server A                                            \
paulson@3450
   206
\           {|Crypt (shrK A) {|Agent B, Key K, na, nb|}, X|}        \
paulson@3466
   207
\           : set evs;                                              \
paulson@2110
   208
\          Says Server A'                                           \
paulson@3450
   209
\           {|Crypt (shrK A') {|Agent B', Key K, na', nb'|}, X'|}   \
paulson@3466
   210
\           : set evs;                                              \
paulson@3519
   211
\          evs : yahalom |]                                    \
paulson@3450
   212
\       ==> A=A' & B=B' & na=na' & nb=nb'";
paulson@2451
   213
by (prove_unique_tac lemma 1);
paulson@2110
   214
qed "unique_session_keys";
paulson@2110
   215
paulson@2110
   216
paulson@2110
   217
(** Crucial secrecy property: Spy does not see the keys sent in msg YM3 **)
paulson@2013
   218
paulson@2013
   219
goal thy 
paulson@3519
   220
 "!!evs. [| A ~: lost;  B ~: lost;  evs : yahalom |]         \
paulson@2051
   221
\        ==> Says Server A                                        \
paulson@3450
   222
\              {|Crypt (shrK A) {|Agent B, Key K, na, nb|},       \
paulson@2284
   223
\                Crypt (shrK B) {|Agent A, Key K|}|}              \
paulson@3466
   224
\             : set evs -->                                       \
paulson@3466
   225
\            Says A Spy {|na, nb, Key K|} ~: set evs -->          \
paulson@3519
   226
\            Key K ~: analz (sees Spy evs)";
paulson@2032
   227
by (etac yahalom.induct 1);
paulson@3121
   228
by analz_sees_tac;
paulson@2013
   229
by (ALLGOALS
paulson@2013
   230
    (asm_simp_tac 
paulson@3450
   231
     (!simpset addsimps [analz_insert_eq, not_parts_not_analz, 
paulson@3450
   232
			 analz_insert_freshK]
paulson@2013
   233
               setloop split_tac [expand_if])));
paulson@3450
   234
(*Oops*)
paulson@3450
   235
by (blast_tac (!claset addDs [unique_session_keys]) 3);
paulson@2013
   236
(*YM3*)
paulson@3121
   237
by (blast_tac (!claset delrules [impCE]
paulson@3121
   238
                       addSEs sees_Spy_partsEs
paulson@3121
   239
                       addIs [impOfSubs analz_subset_parts]) 2);
paulson@3450
   240
(*Fake*) 
paulson@3450
   241
by (spy_analz_tac 1);
paulson@2110
   242
val lemma = result() RS mp RS mp RSN(2,rev_notE);
paulson@2013
   243
paulson@2013
   244
paulson@3432
   245
(*Final version*)
paulson@1985
   246
goal thy 
paulson@2516
   247
 "!!evs. [| Says Server A                                         \
paulson@3450
   248
\              {|Crypt (shrK A) {|Agent B, Key K, na, nb|},       \
paulson@2516
   249
\                Crypt (shrK B) {|Agent A, Key K|}|}              \
paulson@3466
   250
\             : set evs;                                          \
paulson@3466
   251
\           Says A Spy {|na, nb, Key K|} ~: set evs;              \
paulson@3519
   252
\           A ~: lost;  B ~: lost;  evs : yahalom |]         \
paulson@3519
   253
\        ==> Key K ~: analz (sees Spy evs)";
paulson@2013
   254
by (forward_tac [Says_Server_message_form] 1 THEN assume_tac 1);
paulson@3121
   255
by (blast_tac (!claset addSEs [lemma]) 1);
paulson@2032
   256
qed "Spy_not_see_encrypted_key";
paulson@2001
   257
paulson@2001
   258
paulson@3444
   259
(** Security Guarantee for A upon receiving YM3 **)
paulson@3444
   260
paulson@3444
   261
(*If the encrypted message appears then it originated with the Server*)
paulson@3444
   262
goal thy
paulson@3450
   263
 "!!evs. [| Crypt (shrK A) {|Agent B, Key K, na, nb|}                  \
paulson@3519
   264
\            : parts (sees Spy evs);                              \
paulson@3519
   265
\           A ~: lost;  evs : yahalom |]                          \
paulson@3444
   266
\         ==> Says Server A                                            \
paulson@3450
   267
\              {|Crypt (shrK A) {|Agent B, Key K, na, nb|},            \
paulson@3444
   268
\                Crypt (shrK B) {|Agent A, Key K|}|}                   \
nipkow@3465
   269
\             : set evs";
paulson@3444
   270
by (etac rev_mp 1);
paulson@3519
   271
by (parts_induct_tac 1);
paulson@3444
   272
by (Fake_parts_insert_tac 1);
paulson@3444
   273
qed "A_trusts_YM3";
paulson@3444
   274
paulson@3444
   275
paulson@3444
   276
(** Security Guarantees for B upon receiving YM4 **)
paulson@2013
   277
paulson@2110
   278
(*B knows, by the first part of A's message, that the Server distributed 
paulson@2110
   279
  the key for A and B.  But this part says nothing about nonces.*)
paulson@2001
   280
goal thy 
paulson@3519
   281
 "!!evs. [| Crypt (shrK B) {|Agent A, Key K|} : parts (sees Spy evs); \
paulson@3519
   282
\           B ~: lost;  evs : yahalom |]                           \
paulson@2001
   283
\        ==> EX NA NB. Says Server A                                    \
paulson@2451
   284
\                        {|Crypt (shrK A) {|Agent B, Key K,             \
paulson@2516
   285
\                                           Nonce NA, Nonce NB|},       \
paulson@2284
   286
\                          Crypt (shrK B) {|Agent A, Key K|}|}          \
nipkow@3465
   287
\                       : set evs";
paulson@2032
   288
by (etac rev_mp 1);
paulson@3519
   289
by (parts_induct_tac 1);
paulson@3121
   290
by (Fake_parts_insert_tac 1);
paulson@2110
   291
(*YM3*)
paulson@3121
   292
by (Blast_tac 1);
paulson@2110
   293
qed "B_trusts_YM4_shrK";
paulson@2110
   294
paulson@3444
   295
(*B knows, by the second part of A's message, that the Server distributed 
paulson@3444
   296
  the key quoting nonce NB.  This part says nothing about agent names. 
paulson@3444
   297
  Secrecy of NB is crucial.*)
paulson@3444
   298
goal thy 
paulson@3519
   299
 "!!evs. evs : yahalom                                             \
paulson@3519
   300
\        ==> Nonce NB ~: analz (sees Spy evs) -->                  \
paulson@3519
   301
\            Crypt K (Nonce NB) : parts (sees Spy evs) -->         \
paulson@3444
   302
\            (EX A B NA. Says Server A                                  \
paulson@3444
   303
\                        {|Crypt (shrK A) {|Agent B, Key K,             \
paulson@3444
   304
\                                  Nonce NA, Nonce NB|},                \
paulson@3444
   305
\                          Crypt (shrK B) {|Agent A, Key K|}|}          \
nipkow@3465
   306
\                       : set evs)";
paulson@3519
   307
by (parts_induct_tac 1);
paulson@3444
   308
(*YM3 & Fake*)
paulson@3444
   309
by (Blast_tac 2);
paulson@3444
   310
by (Fake_parts_insert_tac 1);
paulson@3444
   311
(*YM4*)
paulson@3444
   312
by (Step_tac 1);
paulson@3444
   313
(*A is uncompromised because NB is secure*)
paulson@3444
   314
by (not_lost_tac "A" 1);
paulson@3444
   315
(*A's certificate guarantees the existence of the Server message*)
paulson@3519
   316
by (blast_tac (!claset addDs [Says_imp_sees_Spy RS parts.Inj RS parts.Fst RS
paulson@3444
   317
			      A_trusts_YM3]) 1);
paulson@3464
   318
bind_thm ("B_trusts_YM4_newK", result() RS mp RSN (2, rev_mp));
paulson@2133
   319
paulson@3444
   320
paulson@3444
   321
(**** Towards proving secrecy of Nonce NB ****)
paulson@3444
   322
paulson@3444
   323
(** Lemmas about the predicate KeyWithNonce **)
paulson@3444
   324
paulson@3444
   325
goalw thy [KeyWithNonce_def]
paulson@3444
   326
 "!!evs. Says Server A                                              \
paulson@3444
   327
\            {|Crypt (shrK A) {|Agent B, Key K, na, Nonce NB|}, X|} \
nipkow@3465
   328
\          : set evs ==> KeyWithNonce K NB evs";
paulson@3444
   329
by (Blast_tac 1);
paulson@3444
   330
qed "KeyWithNonceI";
paulson@3444
   331
paulson@3444
   332
goalw thy [KeyWithNonce_def]
paulson@3444
   333
   "KeyWithNonce K NB (Says S A X # evs) =                                    \
paulson@3444
   334
\    (Server = S &                                                            \
paulson@3444
   335
\     (EX B n X'. X = {|Crypt (shrK A) {|Agent B, Key K, n, Nonce NB|}, X'|}) \
paulson@3444
   336
\    | KeyWithNonce K NB evs)";
paulson@3444
   337
by (Simp_tac 1);
paulson@3444
   338
by (Blast_tac 1);
paulson@3444
   339
qed "KeyWithNonce_Says";
paulson@3444
   340
Addsimps [KeyWithNonce_Says];
paulson@3444
   341
paulson@3464
   342
(*A fresh key cannot be associated with any nonce 
paulson@3464
   343
  (with respect to a given trace). *)
paulson@3444
   344
goalw thy [KeyWithNonce_def]
paulson@3444
   345
 "!!evs. Key K ~: used evs ==> ~ KeyWithNonce K NB evs";
paulson@3444
   346
by (blast_tac (!claset addSEs sees_Spy_partsEs) 1);
paulson@3444
   347
qed "fresh_not_KeyWithNonce";
paulson@3444
   348
paulson@3444
   349
(*The Server message associates K with NB' and therefore not with any 
paulson@3444
   350
  other nonce NB.*)
paulson@3444
   351
goalw thy [KeyWithNonce_def]
paulson@3444
   352
 "!!evs. [| Says Server A                                                \
paulson@3444
   353
\                {|Crypt (shrK A) {|Agent B, Key K, na, Nonce NB'|}, X|} \
paulson@3466
   354
\             : set evs;                                                 \
paulson@3519
   355
\           NB ~= NB';  evs : yahalom |]                            \
paulson@3444
   356
\        ==> ~ KeyWithNonce K NB evs";
paulson@3444
   357
by (blast_tac (!claset addDs [unique_session_keys]) 1);
paulson@3444
   358
qed "Says_Server_KeyWithNonce";
paulson@3444
   359
paulson@3444
   360
paulson@3444
   361
(*The only nonces that can be found with the help of session keys are
paulson@3444
   362
  those distributed as nonce NB by the Server.  The form of the theorem
paulson@3444
   363
  recalls analz_image_freshK, but it is much more complicated.*)
paulson@3444
   364
paulson@3444
   365
paulson@3444
   366
(*As with analz_image_freshK, we take some pains to express the property
paulson@3444
   367
  as a logical equivalence so that the simplifier can apply it.*)
paulson@3444
   368
goal thy  
paulson@3444
   369
 "!!evs. P --> (X : analz (G Un H)) --> (X : analz H)  ==> \
paulson@3444
   370
\        P --> (X : analz (G Un H)) = (X : analz H)";
paulson@3444
   371
by (blast_tac (!claset addIs [impOfSubs analz_mono]) 1);
paulson@3444
   372
val lemma = result();
paulson@2133
   373
paulson@2133
   374
goal thy 
paulson@3519
   375
 "!!evs. evs : yahalom ==>                                         \
paulson@3444
   376
\        (ALL KK. KK <= Compl (range shrK) -->                          \
paulson@3444
   377
\             (ALL K: KK. ~ KeyWithNonce K NB evs)   -->                \
paulson@3519
   378
\             (Nonce NB : analz (Key``KK Un (sees Spy evs))) =     \
paulson@3519
   379
\             (Nonce NB : analz (sees Spy evs)))";
paulson@3444
   380
by (etac yahalom.induct 1);
paulson@3444
   381
by analz_sees_tac;
paulson@3444
   382
by (REPEAT_FIRST (resolve_tac [impI RS allI]));
paulson@3444
   383
by (REPEAT_FIRST (rtac lemma));
paulson@3444
   384
(*For Oops, simplification proves NBa~=NB.  By Says_Server_KeyWithNonce,
paulson@3444
   385
  we get (~ KeyWithNonce K NB evsa); then simplification can apply the
paulson@3444
   386
  induction hypothesis with KK = {K}.*)
paulson@3444
   387
by (ALLGOALS  (*22 seconds*)
paulson@3444
   388
    (asm_simp_tac 
paulson@3444
   389
     (analz_image_freshK_ss addsimps
paulson@3444
   390
        ([all_conj_distrib, not_parts_not_analz, analz_image_freshK,
paulson@3444
   391
	  KeyWithNonce_Says, fresh_not_KeyWithNonce, 
paulson@3444
   392
	  imp_disj_not1,  (*Moves NBa~=NB to the front*)
paulson@3444
   393
	  Says_Server_KeyWithNonce] 
paulson@3444
   394
	 @ pushes))));
paulson@3444
   395
(*Base*)
paulson@3444
   396
by (Blast_tac 1);
paulson@3444
   397
(*Fake*) 
paulson@3444
   398
by (spy_analz_tac 1);
paulson@3444
   399
(*YM4*)  (** LEVEL 7 **)
paulson@3444
   400
by (not_lost_tac "A" 1);
paulson@3519
   401
by (dtac (Says_imp_sees_Spy RS parts.Inj RS parts.Fst RS A_trusts_YM3) 1
paulson@3444
   402
    THEN REPEAT (assume_tac 1));
paulson@3444
   403
by (blast_tac (!claset addIs [KeyWithNonceI]) 1);
paulson@3444
   404
qed_spec_mp "Nonce_secrecy";
paulson@3444
   405
paulson@3444
   406
paulson@3444
   407
(*Version required below: if NB can be decrypted using a session key then it
paulson@3444
   408
  was distributed with that key.  The more general form above is required
paulson@3444
   409
  for the induction to carry through.*)
paulson@3444
   410
goal thy 
paulson@3444
   411
 "!!evs. [| Says Server A                                                 \
paulson@3444
   412
\            {|Crypt (shrK A) {|Agent B, Key KAB, na, Nonce NB'|}, X|}    \
paulson@3466
   413
\           : set evs;                                                    \
paulson@3519
   414
\           NB ~= NB';  KAB ~: range shrK;  evs : yahalom |]         \
paulson@3519
   415
\        ==> (Nonce NB : analz (insert (Key KAB) (sees Spy evs))) =  \
paulson@3519
   416
\            (Nonce NB : analz (sees Spy evs))";
paulson@3444
   417
by (asm_simp_tac (analz_image_freshK_ss addsimps 
paulson@3444
   418
		  [Nonce_secrecy, Says_Server_KeyWithNonce]) 1);
paulson@3444
   419
qed "single_Nonce_secrecy";
paulson@3444
   420
paulson@3444
   421
paulson@3444
   422
(*** The Nonce NB uniquely identifies B's message. ***)
paulson@3444
   423
paulson@3444
   424
goal thy 
paulson@3519
   425
 "!!evs. evs : yahalom ==>                                            \
paulson@3444
   426
\   EX NA' A' B'. ALL NA A B.                                              \
paulson@3519
   427
\      Crypt (shrK B) {|Agent A, Nonce NA, nb|} : parts(sees Spy evs) \
paulson@2133
   428
\      --> B ~: lost --> NA = NA' & A = A' & B = B'";
paulson@3519
   429
by (parts_induct_tac 1);
paulson@3121
   430
(*Fake*)
paulson@3121
   431
by (REPEAT (etac (exI RSN (2,exE)) 1)   (*stripping EXs makes proof faster*)
paulson@3121
   432
    THEN Fake_parts_insert_tac 1);
paulson@3121
   433
by (asm_simp_tac (!simpset addsimps [all_conj_distrib]) 1); 
paulson@2133
   434
(*YM2: creation of new Nonce.  Move assertion into global context*)
paulson@3501
   435
by (expand_case_tac "nb = ?y" 1);
paulson@2516
   436
by (REPEAT (resolve_tac [exI, conjI, impI, refl] 1));
paulson@3121
   437
by (blast_tac (!claset addSEs sees_Spy_partsEs) 1);
paulson@2133
   438
val lemma = result();
paulson@2133
   439
paulson@2110
   440
goal thy 
paulson@3501
   441
 "!!evs.[| Crypt (shrK B) {|Agent A, Nonce NA, nb|}        \
paulson@3519
   442
\                  : parts (sees Spy evs);            \
paulson@3501
   443
\          Crypt (shrK B') {|Agent A', Nonce NA', nb|}     \
paulson@3519
   444
\                  : parts (sees Spy evs);            \
paulson@3519
   445
\          evs : yahalom;  B ~: lost;  B' ~: lost |]  \
paulson@2133
   446
\        ==> NA' = NA & A' = A & B' = B";
paulson@2451
   447
by (prove_unique_tac lemma 1);
paulson@2133
   448
qed "unique_NB";
paulson@2133
   449
paulson@2133
   450
paulson@3444
   451
(*Variant useful for proving secrecy of NB: the Says... form allows 
paulson@3444
   452
  not_lost_tac to remove the assumption B' ~: lost.*)
paulson@2133
   453
goal thy 
paulson@3501
   454
 "!!evs.[| Says C D   {|X,  Crypt (shrK B) {|Agent A, Nonce NA, nb|}|}    \
paulson@3466
   455
\            : set evs;          B ~: lost;                               \
paulson@3501
   456
\          Says C' D' {|X', Crypt (shrK B') {|Agent A', Nonce NA', nb|}|} \
paulson@3466
   457
\            : set evs;                                                   \
paulson@3519
   458
\          nb ~: analz (sees Spy evs);  evs : yahalom |]        \
paulson@2133
   459
\        ==> NA' = NA & A' = A & B' = B";
paulson@3444
   460
by (not_lost_tac "B'" 1);
paulson@3519
   461
by (blast_tac (!claset addSDs [Says_imp_sees_Spy RS parts.Inj]
paulson@3121
   462
                       addSEs [MPair_parts]
paulson@3121
   463
                       addDs  [unique_NB]) 1);
paulson@2133
   464
qed "Says_unique_NB";
paulson@2133
   465
paulson@3444
   466
paulson@3444
   467
(** A nonce value is never used both as NA and as NB **)
paulson@3121
   468
paulson@2133
   469
goal thy 
paulson@3519
   470
 "!!evs. [| B ~: lost;  evs : yahalom  |]            \
paulson@3519
   471
\ ==> Nonce NB ~: analz (sees Spy evs) -->           \
paulson@3501
   472
\     Crypt (shrK B') {|Agent A', Nonce NB, nb'|}    \
paulson@3519
   473
\       : parts(sees Spy evs)                        \
paulson@3464
   474
\ --> Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|} \
paulson@3519
   475
\       ~: parts(sees Spy evs)";
paulson@3519
   476
by (parts_induct_tac 1);
paulson@3121
   477
by (Fake_parts_insert_tac 1);
paulson@3519
   478
by (blast_tac (!claset addDs [Says_imp_sees_Spy RS analz.Inj]
paulson@3121
   479
                       addSIs [parts_insertI]
paulson@3121
   480
                       addSEs partsEs) 1);
paulson@3464
   481
bind_thm ("no_nonce_YM1_YM2", result() RS mp RSN (2,rev_mp) RSN (2,rev_notE));
paulson@2133
   482
paulson@3464
   483
(*The Server sends YM3 only in response to YM2.*)
paulson@2133
   484
goal thy 
paulson@3466
   485
 "!!evs. [| Says Server A                                                \
paulson@3466
   486
\            {|Crypt (shrK A) {|Agent B, k, na, nb|}, X|} : set evs;     \
paulson@3519
   487
\           evs : yahalom |]                                             \
paulson@2133
   488
\        ==> EX B'. Says B' Server                                       \
paulson@2284
   489
\                      {| Agent B, Crypt (shrK B) {|Agent A, na, nb|} |} \
nipkow@3465
   490
\                   : set evs";
paulson@2133
   491
by (etac rev_mp 1);
paulson@2133
   492
by (etac yahalom.induct 1);
paulson@2133
   493
by (ALLGOALS Asm_simp_tac);
paulson@3121
   494
by (ALLGOALS Blast_tac);
paulson@2133
   495
qed "Says_Server_imp_YM2";
paulson@2133
   496
paulson@2133
   497
paulson@3519
   498
(*A vital theorem for B, that nonce NB remains secure from the Spy.*)
paulson@2133
   499
goal thy 
paulson@3519
   500
 "!!evs. [| A ~: lost;  B ~: lost;  evs : yahalom |]  \
paulson@2133
   501
\ ==> Says B Server                                                    \
paulson@2284
   502
\          {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|} \
paulson@3466
   503
\     : set evs -->                                                    \
paulson@3466
   504
\     (ALL k. Says A Spy {|Nonce NA, Nonce NB, k|} ~: set evs) -->     \
paulson@3519
   505
\     Nonce NB ~: analz (sees Spy evs)";
paulson@2133
   506
by (etac yahalom.induct 1);
paulson@3121
   507
by analz_sees_tac;
paulson@2133
   508
by (ALLGOALS
paulson@2133
   509
    (asm_simp_tac 
paulson@3444
   510
     (!simpset addsimps ([analz_insert_eq, not_parts_not_analz,
paulson@2516
   511
                          analz_insert_freshK] @ pushes)
paulson@2133
   512
               setloop split_tac [expand_if])));
paulson@3450
   513
(*Prove YM3 by showing that no NB can also be an NA*)
paulson@3519
   514
by (blast_tac (!claset addDs [Says_imp_sees_Spy RS parts.Inj]
paulson@3450
   515
	               addSEs [MPair_parts]
paulson@3519
   516
		       addDs  [no_nonce_YM1_YM2, Says_unique_NB]) 4
paulson@3450
   517
    THEN flexflex_tac);
paulson@3444
   518
(*YM2: similar freshness reasoning*) 
paulson@3121
   519
by (blast_tac (!claset addSEs partsEs
paulson@3519
   520
		       addDs  [Says_imp_sees_Spy RS analz.Inj,
paulson@3450
   521
			       impOfSubs analz_subset_parts]) 3);
paulson@3450
   522
(*YM1: NB=NA is impossible anyway, but NA is secret because it is fresh!*)
paulson@3450
   523
by (blast_tac (!claset addSIs [parts_insertI]
paulson@3450
   524
                       addSEs sees_Spy_partsEs) 2);
paulson@2377
   525
(*Fake*)
paulson@2377
   526
by (spy_analz_tac 1);
paulson@3444
   527
(** LEVEL 7: YM4 and Oops remain **)
paulson@3444
   528
(*YM4: key K is visible to Spy, contradicting session key secrecy theorem*) 
paulson@3444
   529
by (REPEAT (Safe_step_tac 1));
paulson@3444
   530
by (not_lost_tac "Aa" 1);
paulson@3519
   531
by (dtac (Says_imp_sees_Spy RS parts.Inj RS parts.Fst RS A_trusts_YM3) 1);
paulson@2133
   532
by (forward_tac [Says_Server_message_form] 3);
paulson@2133
   533
by (forward_tac [Says_Server_imp_YM2] 4);
paulson@3121
   534
by (REPEAT_FIRST (eresolve_tac [asm_rl, bexE, exE, disjE]));
paulson@3519
   535
(*  use Says_unique_NB to identify message components: Aa=A, Ba=B, NAa=NA *)
paulson@3519
   536
by (blast_tac (!claset addDs [Says_unique_NB, Spy_not_see_encrypted_key,
paulson@3444
   537
			      impOfSubs Fake_analz_insert]) 1);
paulson@3444
   538
(** LEVEL 14 **)
paulson@3444
   539
(*Oops case: if the nonce is betrayed now, show that the Oops event is 
paulson@3444
   540
  covered by the quantified Oops assumption.*)
paulson@2133
   541
by (full_simp_tac (!simpset addsimps [all_conj_distrib]) 1);
paulson@2133
   542
by (step_tac (!claset delrules [disjE, conjI]) 1);
paulson@2133
   543
by (forward_tac [Says_Server_imp_YM2] 1 THEN assume_tac 1 THEN etac exE 1);
paulson@2133
   544
by (expand_case_tac "NB = NBa" 1);
paulson@3444
   545
(*If NB=NBa then all other components of the Oops message agree*)
paulson@3519
   546
by (blast_tac (!claset addDs [Says_unique_NB]) 1 THEN flexflex_tac);
paulson@3444
   547
(*case NB ~= NBa*)
paulson@3444
   548
by (asm_simp_tac (!simpset addsimps [single_Nonce_secrecy]) 1);
paulson@3444
   549
by (blast_tac (!claset addSEs [MPair_parts]
paulson@3519
   550
		       addDs  [Says_imp_sees_Spy RS parts.Inj, 
paulson@3444
   551
			       no_nonce_YM1_YM2 (*to prove NB~=NAa*) ]) 1);
paulson@3444
   552
bind_thm ("Spy_not_see_NB", result() RSN(2,rev_mp) RSN(2,rev_mp));
paulson@2133
   553
paulson@2001
   554
paulson@3464
   555
(*B's session key guarantee from YM4.  The two certificates contribute to a
paulson@3464
   556
  single conclusion about the Server's message.  Note that the "Says A Spy"
paulson@3464
   557
  assumption must quantify over ALL POSSIBLE keys instead of our particular K.
paulson@3464
   558
  If this run is broken and the spy substitutes a certificate containing an
paulson@3464
   559
  old key, B has no means of telling.*)
paulson@2001
   560
goal thy 
paulson@3444
   561
 "!!evs. [| Says B Server                                                   \
paulson@3444
   562
\             {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|}   \
paulson@3466
   563
\             : set evs;                                                    \
paulson@3444
   564
\           Says A' B {|Crypt (shrK B) {|Agent A, Key K|},                  \
paulson@3466
   565
\                       Crypt K (Nonce NB)|} : set evs;                     \
paulson@3466
   566
\           ALL k. Says A Spy {|Nonce NA, Nonce NB, k|} ~: set evs;         \
paulson@3519
   567
\           A ~: lost;  B ~: lost;  evs : yahalom |]       \
paulson@3444
   568
\         ==> Says Server A                                                 \
paulson@3444
   569
\                     {|Crypt (shrK A) {|Agent B, Key K,                    \
paulson@3444
   570
\                               Nonce NA, Nonce NB|},                       \
paulson@3444
   571
\                       Crypt (shrK B) {|Agent A, Key K|}|}                 \
nipkow@3465
   572
\               : set evs";
paulson@2133
   573
by (forward_tac [Spy_not_see_NB] 1 THEN REPEAT (assume_tac 1));
paulson@3519
   574
by (etac (Says_imp_sees_Spy RS parts.Inj RS MPair_parts) 1 THEN
paulson@2133
   575
    dtac B_trusts_YM4_shrK 1);
paulson@2170
   576
by (dtac B_trusts_YM4_newK 3);
paulson@2110
   577
by (REPEAT_FIRST (eresolve_tac [asm_rl, exE]));
paulson@2133
   578
by (forward_tac [Says_Server_imp_YM2] 1 THEN assume_tac 1);
paulson@2170
   579
by (dtac unique_session_keys 1 THEN REPEAT (assume_tac 1));
paulson@3519
   580
by (blast_tac (!claset addDs [Says_unique_NB]) 1);
paulson@2322
   581
qed "B_trusts_YM4";
paulson@3444
   582
paulson@3444
   583
paulson@3444
   584
paulson@3444
   585
(*** Authenticating B to A ***)
paulson@3444
   586
paulson@3444
   587
(*The encryption in message YM2 tells us it cannot be faked.*)
paulson@3444
   588
goal thy 
paulson@3519
   589
 "!!evs. evs : yahalom                                            \
paulson@3519
   590
\  ==> Crypt (shrK B) {|Agent A, Nonce NA, nb|}                   \
paulson@3519
   591
\        : parts (sees Spy evs) -->                               \
paulson@3519
   592
\      B ~: lost -->                                              \
paulson@3466
   593
\      Says B Server {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, nb|}|}  \
nipkow@3465
   594
\         : set evs";
paulson@3519
   595
by (parts_induct_tac 1);
paulson@3444
   596
by (Fake_parts_insert_tac 1);
paulson@3444
   597
bind_thm ("B_Said_YM2", result() RSN (2, rev_mp) RS mp);
paulson@3444
   598
paulson@3444
   599
(*If the server sends YM3 then B sent YM2*)
paulson@3444
   600
goal thy 
paulson@3519
   601
 "!!evs. evs : yahalom                                                      \
paulson@3444
   602
\  ==> Says Server A {|Crypt (shrK A) {|Agent B, Key K, Nonce NA, nb|}, X|} \
paulson@3466
   603
\         : set evs -->                                                     \
paulson@3466
   604
\      B ~: lost -->                                                        \
paulson@3466
   605
\      Says B Server {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, nb|}|}  \
nipkow@3465
   606
\                 : set evs";
paulson@3444
   607
by (etac yahalom.induct 1);
paulson@3444
   608
by (ALLGOALS Asm_simp_tac);
paulson@3444
   609
(*YM4*)
paulson@3444
   610
by (Blast_tac 2);
paulson@3444
   611
(*YM3*)
paulson@3519
   612
by (best_tac (!claset addSDs [B_Said_YM2, Says_imp_sees_Spy RS parts.Inj]
paulson@3444
   613
		      addSEs [MPair_parts]) 1);
paulson@3444
   614
val lemma = result() RSN (2, rev_mp) RS mp |> standard;
paulson@3444
   615
paulson@3444
   616
(*If A receives YM3 then B has used nonce NA (and therefore is alive)*)
paulson@3444
   617
goal thy
paulson@3444
   618
 "!!evs. [| Says S A {|Crypt (shrK A) {|Agent B, Key K, Nonce NA, nb|}, X|} \
paulson@3466
   619
\             : set evs;                                                    \
paulson@3519
   620
\           A ~: lost;  B ~: lost;  evs : yahalom |]                        \
paulson@3444
   621
\   ==> Says B Server {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, nb|}|} \
nipkow@3465
   622
\         : set evs";
paulson@3444
   623
by (blast_tac (!claset addSDs [A_trusts_YM3, lemma]
paulson@3444
   624
		       addEs sees_Spy_partsEs) 1);
paulson@3444
   625
qed "YM3_auth_B_to_A";
paulson@3444
   626
paulson@3444
   627
paulson@3444
   628
(*** Authenticating A to B using the certificate Crypt K (Nonce NB) ***)
paulson@3444
   629
paulson@3444
   630
(*Assuming the session key is secure, if both certificates are present then
paulson@3444
   631
  A has said NB.  We can't be sure about the rest of A's message, but only
paulson@3444
   632
  NB matters for freshness.*)  
paulson@3444
   633
goal thy 
paulson@3519
   634
 "!!evs. evs : yahalom                                             \
paulson@3519
   635
\        ==> Key K ~: analz (sees Spy evs) -->                     \
paulson@3519
   636
\            Crypt K (Nonce NB) : parts (sees Spy evs) -->         \
paulson@3519
   637
\            Crypt (shrK B) {|Agent A, Key K|}                     \
paulson@3519
   638
\              : parts (sees Spy evs) -->                          \
paulson@3519
   639
\            B ~: lost -->                                         \
nipkow@3465
   640
\             (EX X. Says A B {|X, Crypt K (Nonce NB)|} : set evs)";
paulson@3519
   641
by (parts_induct_tac 1);
paulson@3444
   642
(*Fake*)
paulson@3444
   643
by (Fake_parts_insert_tac 1);
paulson@3444
   644
(*YM3: by new_keys_not_used we note that Crypt K (Nonce NB) could not exist*)
paulson@3444
   645
by (fast_tac (!claset addSDs [Crypt_imp_invKey_keysFor] addss (!simpset)) 1); 
paulson@3444
   646
(*YM4: was Crypt K (Nonce NB) the very last message?  If not, use ind. hyp.*)
paulson@3444
   647
by (asm_simp_tac (!simpset addsimps [ex_disj_distrib]) 1);
paulson@3444
   648
(*yes: apply unicity of session keys*)
paulson@3444
   649
by (not_lost_tac "Aa" 1);
paulson@3444
   650
by (blast_tac (!claset addSEs [MPair_parts]
paulson@3444
   651
                       addSDs [A_trusts_YM3, B_trusts_YM4_shrK]
paulson@3519
   652
		       addDs  [Says_imp_sees_Spy RS parts.Inj,
paulson@3444
   653
			       unique_session_keys]) 1);
paulson@3444
   654
val lemma = normalize_thm [RSspec, RSmp] (result()) |> standard;
paulson@3444
   655
paulson@3444
   656
(*If B receives YM4 then A has used nonce NB (and therefore is alive).
paulson@3444
   657
  Moreover, A associates K with NB (thus is talking about the same run).
paulson@3444
   658
  Other premises guarantee secrecy of K.*)
paulson@3444
   659
goal thy 
paulson@3444
   660
 "!!evs. [| Says B Server                                                   \
paulson@3444
   661
\             {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|}   \
paulson@3466
   662
\             : set evs;                                                    \
paulson@3466
   663
\           Says A' B {|Crypt (shrK B) {|Agent A, Key K|},                  \
paulson@3466
   664
\                       Crypt K (Nonce NB)|} : set evs;                     \
paulson@3466
   665
\           (ALL NA k. Says A Spy {|Nonce NA, Nonce NB, k|} ~: set evs);    \
paulson@3519
   666
\           A ~: lost;  B ~: lost;  evs : yahalom |]       \
nipkow@3465
   667
\        ==> EX X. Says A B {|X, Crypt K (Nonce NB)|} : set evs";
paulson@3444
   668
by (dtac B_trusts_YM4 1);
paulson@3444
   669
by (REPEAT_FIRST (eresolve_tac [asm_rl, spec]));
paulson@3519
   670
by (etac (Says_imp_sees_Spy RS parts.Inj RS MPair_parts) 1);
paulson@3444
   671
by (rtac lemma 1);
paulson@3444
   672
by (rtac Spy_not_see_encrypted_key 2);
paulson@3444
   673
by (REPEAT_FIRST assume_tac);
paulson@3444
   674
by (blast_tac (!claset addSEs [MPair_parts]
paulson@3519
   675
	       	       addDs [Says_imp_sees_Spy RS parts.Inj]) 1);
paulson@3444
   676
qed_spec_mp "YM4_imp_A_Said_YM3";