src/HOL/Auth/Yahalom.ML
author paulson
Thu Feb 05 10:38:34 1998 +0100 (1998-02-05)
changeset 4598 649bf14debe7
parent 4537 4e835bd9fada
child 4831 dae4d63a1318
permissions -rw-r--r--
Added some more explicit guarantees of key secrecy for agents

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