src/HOL/Auth/Yahalom.thy
author paulson
Sat Aug 17 14:55:08 2002 +0200 (2002-08-17)
changeset 13507 febb8e5d2a9d
parent 11655 923e4d0d36d5
child 13926 6e62e5357a10
permissions -rw-r--r--
tidying of Isar scripts
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@1985
     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@11251
    11
paulson@11251
    12
This theory has the prototypical example of a secrecy relation, KeyCryptNonce.
paulson@1985
    13
*)
paulson@1985
    14
paulson@11251
    15
theory Yahalom = Shared:
paulson@1985
    16
paulson@11251
    17
consts  yahalom   :: "event list set"
paulson@3519
    18
inductive "yahalom"
paulson@11251
    19
  intros 
paulson@1985
    20
         (*Initial trace is empty*)
paulson@11251
    21
   Nil:  "[] \<in> yahalom"
paulson@1985
    22
paulson@2032
    23
         (*The spy MAY say anything he CAN say.  We do not expect him to
paulson@1985
    24
           invent new nonces here, but he can also use NS1.  Common to
paulson@1985
    25
           all similar protocols.*)
paulson@11251
    26
   Fake: "[| evsf \<in> yahalom;  X \<in> synth (analz (knows Spy evsf)) |]
paulson@11251
    27
          ==> Says Spy B X  # evsf \<in> yahalom"
paulson@1985
    28
paulson@6335
    29
         (*A message that has been sent can be received by the
paulson@6335
    30
           intended recipient.*)
paulson@11251
    31
   Reception: "[| evsr \<in> yahalom;  Says A B X \<in> set evsr |]
paulson@11251
    32
               ==> Gets B X # evsr \<in> yahalom"
paulson@6335
    33
paulson@1985
    34
         (*Alice initiates a protocol run*)
paulson@11251
    35
   YM1:  "[| evs1 \<in> yahalom;  Nonce NA \<notin> used evs1 |]
paulson@11251
    36
          ==> Says A B {|Agent A, Nonce NA|} # evs1 \<in> yahalom"
paulson@1985
    37
paulson@6335
    38
         (*Bob's response to Alice's message.*)
paulson@11251
    39
   YM2:  "[| evs2 \<in> yahalom;  Nonce NB \<notin> used evs2;
paulson@11251
    40
             Gets B {|Agent A, Nonce NA|} \<in> set evs2 |]
paulson@1985
    41
          ==> Says B Server 
paulson@2516
    42
                  {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|}
paulson@11251
    43
                # evs2 \<in> yahalom"
paulson@1985
    44
paulson@1985
    45
         (*The Server receives Bob's message.  He responds by sending a
paulson@1985
    46
            new session key to Alice, with a packet for forwarding to Bob.*)
paulson@11251
    47
   YM3:  "[| evs3 \<in> yahalom;  Key KAB \<notin> used evs3;
paulson@6335
    48
             Gets Server 
paulson@2284
    49
                  {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|}
paulson@11251
    50
               \<in> set evs3 |]
paulson@1995
    51
          ==> Says Server A
paulson@3447
    52
                   {|Crypt (shrK A) {|Agent B, Key KAB, Nonce NA, Nonce NB|},
paulson@3447
    53
                     Crypt (shrK B) {|Agent A, Key KAB|}|}
paulson@11251
    54
                # evs3 \<in> yahalom"
paulson@1985
    55
paulson@1995
    56
         (*Alice receives the Server's (?) message, checks her Nonce, and
paulson@3961
    57
           uses the new session key to send Bob his Nonce.  The premise
paulson@11251
    58
           A \<noteq> Server is needed to prove Says_Server_not_range.*)
paulson@11251
    59
   YM4:  "[| evs4 \<in> yahalom;  A \<noteq> Server;
paulson@6335
    60
             Gets A {|Crypt(shrK A) {|Agent B, Key K, Nonce NA, Nonce NB|}, X|}
paulson@11251
    61
                \<in> set evs4;
paulson@11251
    62
             Says A B {|Agent A, Nonce NA|} \<in> set evs4 |]
paulson@11251
    63
          ==> Says A B {|X, Crypt K (Nonce NB)|} # evs4 \<in> yahalom"
paulson@1985
    64
paulson@2110
    65
         (*This message models possible leaks of session keys.  The Nonces
paulson@2156
    66
           identify the protocol run.  Quoting Server here ensures they are
paulson@2156
    67
           correct.*)
paulson@11251
    68
   Oops: "[| evso \<in> yahalom;  
paulson@2284
    69
             Says Server A {|Crypt (shrK A)
paulson@2284
    70
                                   {|Agent B, Key K, Nonce NA, Nonce NB|},
paulson@11251
    71
                             X|}  \<in> set evso |]
paulson@11251
    72
          ==> Notes Spy {|Nonce NA, Nonce NB, Key K|} # evso \<in> yahalom"
paulson@2110
    73
paulson@3447
    74
paulson@3447
    75
constdefs 
paulson@11251
    76
  KeyWithNonce :: "[key, nat, event list] => bool"
paulson@3447
    77
  "KeyWithNonce K NB evs ==
paulson@11251
    78
     \<exists>A B na X. 
paulson@3447
    79
       Says Server A {|Crypt (shrK A) {|Agent B, Key K, na, Nonce NB|}, X|} 
paulson@11251
    80
         \<in> set evs"
paulson@11251
    81
paulson@11251
    82
paulson@11251
    83
declare Says_imp_knows_Spy [THEN analz.Inj, dest]
paulson@11251
    84
declare parts.Body  [dest]
paulson@11251
    85
declare Fake_parts_insert_in_Un  [dest]
paulson@11251
    86
declare analz_into_parts [dest]
paulson@11251
    87
paulson@11251
    88
(*A "possibility property": there are traces that reach the end*)
paulson@11251
    89
lemma "A \<noteq> Server  
paulson@11251
    90
      ==> \<exists>X NB K. \<exists>evs \<in> yahalom.           
paulson@11251
    91
             Says A B {|X, Crypt K (Nonce NB)|} \<in> set evs"
paulson@11251
    92
apply (intro exI bexI)
paulson@11251
    93
apply (rule_tac [2] yahalom.Nil
paulson@11251
    94
                    [THEN yahalom.YM1, THEN yahalom.Reception, 
paulson@11251
    95
                     THEN yahalom.YM2, THEN yahalom.Reception, 
paulson@11251
    96
                     THEN yahalom.YM3, THEN yahalom.Reception, 
paulson@13507
    97
                     THEN yahalom.YM4], possibility)
paulson@11251
    98
done
paulson@11251
    99
paulson@11251
   100
lemma Gets_imp_Says:
paulson@11251
   101
     "[| Gets B X \<in> set evs; evs \<in> yahalom |] ==> \<exists>A. Says A B X \<in> set evs"
paulson@11251
   102
by (erule rev_mp, erule yahalom.induct, auto)
paulson@11251
   103
paulson@11251
   104
(*Must be proved separately for each protocol*)
paulson@11251
   105
lemma Gets_imp_knows_Spy:
paulson@11251
   106
     "[| Gets B X \<in> set evs; evs \<in> yahalom |]  ==> X \<in> knows Spy evs"
paulson@11251
   107
by (blast dest!: Gets_imp_Says Says_imp_knows_Spy)
paulson@11251
   108
paulson@11251
   109
declare Gets_imp_knows_Spy [THEN analz.Inj, dest]
paulson@11251
   110
paulson@11251
   111
paulson@11251
   112
(**** Inductive proofs about yahalom ****)
paulson@11251
   113
paulson@11251
   114
(*Lets us treat YM4 using a similar argument as for the Fake case.*)
paulson@11251
   115
lemma YM4_analz_knows_Spy:
paulson@11251
   116
     "[| Gets A {|Crypt (shrK A) Y, X|} \<in> set evs;  evs \<in> yahalom |]   
paulson@11251
   117
      ==> X \<in> analz (knows Spy evs)"
paulson@11251
   118
by blast
paulson@11251
   119
paulson@11251
   120
lemmas YM4_parts_knows_Spy = 
paulson@11251
   121
       YM4_analz_knows_Spy [THEN analz_into_parts, standard]
paulson@11251
   122
paulson@11251
   123
(*For Oops*)
paulson@11251
   124
lemma YM4_Key_parts_knows_Spy:
paulson@11251
   125
     "Says Server A {|Crypt (shrK A) {|B,K,NA,NB|}, X|} \<in> set evs  
paulson@11251
   126
      ==> K \<in> parts (knows Spy evs)"
paulson@11251
   127
by (blast dest!: parts.Body Says_imp_knows_Spy [THEN parts.Inj])
paulson@11251
   128
paulson@11251
   129
paulson@11251
   130
(** Theorems of the form X \<notin> parts (knows Spy evs) imply that NOBODY
paulson@11251
   131
    sends messages containing X! **)
paulson@11251
   132
paulson@11251
   133
(*Spy never sees a good agent's shared key!*)
paulson@11251
   134
lemma Spy_see_shrK [simp]:
paulson@11251
   135
     "evs \<in> yahalom ==> (Key (shrK A) \<in> parts (knows Spy evs)) = (A \<in> bad)"
paulson@11251
   136
apply (erule yahalom.induct, force, 
paulson@13507
   137
       drule_tac [6] YM4_parts_knows_Spy, simp_all, blast+)
paulson@11251
   138
done
paulson@11251
   139
paulson@11251
   140
lemma Spy_analz_shrK [simp]:
paulson@11251
   141
     "evs \<in> yahalom ==> (Key (shrK A) \<in> analz (knows Spy evs)) = (A \<in> bad)"
paulson@11251
   142
by auto
paulson@11251
   143
paulson@11251
   144
lemma Spy_see_shrK_D [dest!]:
paulson@11251
   145
     "[|Key (shrK A) \<in> parts (knows Spy evs);  evs \<in> yahalom|] ==> A \<in> bad"
paulson@11251
   146
by (blast dest: Spy_see_shrK)
paulson@11251
   147
paulson@11251
   148
(*Nobody can have used non-existent keys!  Needed to apply analz_insert_Key*)
paulson@11251
   149
lemma new_keys_not_used [rule_format, simp]:
paulson@11251
   150
 "evs \<in> yahalom ==> Key K \<notin> used evs --> K \<notin> keysFor (parts (knows Spy evs))"
paulson@11251
   151
apply (erule yahalom.induct, force, 
paulson@11251
   152
       frule_tac [6] YM4_parts_knows_Spy, simp_all)
paulson@11251
   153
(*Fake, YM3, YM4*)
paulson@11251
   154
apply (blast dest!: keysFor_parts_insert)+
paulson@11251
   155
done
paulson@11251
   156
paulson@11251
   157
paulson@11251
   158
(*Earlier, all protocol proofs declared this theorem.  
paulson@11251
   159
  But only a few proofs need it, e.g. Yahalom and Kerberos IV.*)
paulson@11251
   160
lemma new_keys_not_analzd:
paulson@11251
   161
 "[|evs \<in> yahalom; Key K \<notin> used evs|] ==> K \<notin> keysFor (analz (knows Spy evs))"
paulson@11251
   162
by (blast dest: new_keys_not_used intro: keysFor_mono [THEN subsetD]) 
paulson@11251
   163
paulson@11251
   164
paulson@11251
   165
(*Describes the form of K when the Server sends this message.  Useful for
paulson@11251
   166
  Oops as well as main secrecy property.*)
paulson@11251
   167
lemma Says_Server_not_range [simp]:
paulson@11251
   168
     "[| Says Server A {|Crypt (shrK A) {|Agent B, Key K, na, nb|}, X|}  
paulson@11251
   169
           \<in> set evs;   evs \<in> yahalom |]                                 
paulson@11251
   170
      ==> K \<notin> range shrK"
paulson@13507
   171
apply (erule rev_mp, erule yahalom.induct, simp_all, blast)
paulson@11251
   172
done
paulson@11251
   173
paulson@11251
   174
paulson@11251
   175
(*For proofs involving analz.
paulson@11251
   176
val analz_knows_Spy_tac = 
paulson@11251
   177
    ftac YM4_analz_knows_Spy 7 THEN assume_tac 7
paulson@11251
   178
*)
paulson@11251
   179
paulson@11251
   180
(****
paulson@11251
   181
 The following is to prove theorems of the form
paulson@11251
   182
paulson@11251
   183
  Key K \<in> analz (insert (Key KAB) (knows Spy evs)) ==>
paulson@11251
   184
  Key K \<in> analz (knows Spy evs)
paulson@11251
   185
paulson@11251
   186
 A more general formula must be proved inductively.
paulson@11251
   187
****)
paulson@11251
   188
paulson@11251
   189
(** Session keys are not used to encrypt other session keys **)
paulson@11251
   190
paulson@11251
   191
lemma analz_image_freshK [rule_format]:
paulson@11251
   192
 "evs \<in> yahalom ==>                                
paulson@11251
   193
   \<forall>K KK. KK <= - (range shrK) -->                  
paulson@11251
   194
          (Key K \<in> analz (Key`KK Un (knows Spy evs))) =   
paulson@11251
   195
          (K \<in> KK | Key K \<in> analz (knows Spy evs))"
paulson@11251
   196
apply (erule yahalom.induct, force, 
paulson@13507
   197
       drule_tac [6] YM4_analz_knows_Spy, analz_freshK, spy_analz)
paulson@11251
   198
apply (simp only: Says_Server_not_range analz_image_freshK_simps)
paulson@11251
   199
done
paulson@11251
   200
paulson@11251
   201
lemma analz_insert_freshK:
paulson@11251
   202
     "[| evs \<in> yahalom;  KAB \<notin> range shrK |] ==>      
wenzelm@11655
   203
      (Key K \<in> analz (insert (Key KAB) (knows Spy evs))) =
paulson@11251
   204
      (K = KAB | Key K \<in> analz (knows Spy evs))"
paulson@11251
   205
by (simp only: analz_image_freshK analz_image_freshK_simps)
paulson@11251
   206
paulson@11251
   207
paulson@11251
   208
(*** The Key K uniquely identifies the Server's  message. **)
paulson@11251
   209
paulson@11251
   210
lemma unique_session_keys:
paulson@11251
   211
     "[| Says Server A                                                  
paulson@11251
   212
          {|Crypt (shrK A) {|Agent B, Key K, na, nb|}, X|} \<in> set evs;  
paulson@11251
   213
        Says Server A'                                                 
paulson@11251
   214
          {|Crypt (shrK A') {|Agent B', Key K, na', nb'|}, X'|} \<in> set evs;  
paulson@11251
   215
        evs \<in> yahalom |]                                     
paulson@11251
   216
     ==> A=A' & B=B' & na=na' & nb=nb'"
paulson@11251
   217
apply (erule rev_mp, erule rev_mp)
paulson@11251
   218
apply (erule yahalom.induct, simp_all)
paulson@11251
   219
(*YM3, by freshness, and YM4*)
paulson@11251
   220
apply blast+
paulson@11251
   221
done
paulson@11251
   222
paulson@11251
   223
paulson@11251
   224
(** Crucial secrecy property: Spy does not see the keys sent in msg YM3 **)
paulson@11251
   225
paulson@11251
   226
lemma secrecy_lemma:
paulson@11251
   227
     "[| A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]                 
paulson@11251
   228
      ==> Says Server A                                         
paulson@11251
   229
            {|Crypt (shrK A) {|Agent B, Key K, na, nb|},        
paulson@11251
   230
              Crypt (shrK B) {|Agent A, Key K|}|}               
paulson@11251
   231
           \<in> set evs -->                                        
paulson@11251
   232
          Notes Spy {|na, nb, Key K|} \<notin> set evs -->            
paulson@11251
   233
          Key K \<notin> analz (knows Spy evs)"
paulson@11251
   234
apply (erule yahalom.induct, force, 
paulson@11251
   235
       drule_tac [6] YM4_analz_knows_Spy)
paulson@13507
   236
apply (simp_all add: pushes analz_insert_eq analz_insert_freshK, spy_analz)  (*Fake*)
paulson@11251
   237
apply (blast dest: unique_session_keys)+  (*YM3, Oops*)
paulson@11251
   238
done
paulson@11251
   239
paulson@11251
   240
(*Final version*)
paulson@11251
   241
lemma Spy_not_see_encrypted_key:
paulson@11251
   242
     "[| Says Server A                                          
paulson@11251
   243
            {|Crypt (shrK A) {|Agent B, Key K, na, nb|},        
paulson@11251
   244
              Crypt (shrK B) {|Agent A, Key K|}|}               
paulson@11251
   245
           \<in> set evs;                                           
paulson@11251
   246
         Notes Spy {|na, nb, Key K|} \<notin> set evs;                
paulson@11251
   247
         A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]                 
paulson@11251
   248
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   249
by (blast dest: secrecy_lemma)
paulson@11251
   250
paulson@11251
   251
paulson@11251
   252
(** Security Guarantee for A upon receiving YM3 **)
paulson@11251
   253
paulson@11251
   254
(*If the encrypted message appears then it originated with the Server*)
paulson@11251
   255
lemma A_trusts_YM3:
paulson@11251
   256
     "[| Crypt (shrK A) {|Agent B, Key K, na, nb|} \<in> parts (knows Spy evs);  
paulson@11251
   257
         A \<notin> bad;  evs \<in> yahalom |]                           
paulson@11251
   258
       ==> Says Server A                                             
paulson@11251
   259
            {|Crypt (shrK A) {|Agent B, Key K, na, nb|},             
paulson@11251
   260
              Crypt (shrK B) {|Agent A, Key K|}|}                    
paulson@11251
   261
           \<in> set evs"
paulson@11251
   262
apply (erule rev_mp)
paulson@11251
   263
apply (erule yahalom.induct, force, 
paulson@11251
   264
       frule_tac [6] YM4_parts_knows_Spy, simp_all)
paulson@11251
   265
(*Fake, YM3*)
paulson@11251
   266
apply blast+
paulson@11251
   267
done
paulson@11251
   268
paulson@11251
   269
(*The obvious combination of A_trusts_YM3 with Spy_not_see_encrypted_key*)
paulson@11251
   270
lemma A_gets_good_key:
paulson@11251
   271
     "[| Crypt (shrK A) {|Agent B, Key K, na, nb|} \<in> parts (knows Spy evs);  
paulson@11251
   272
         Notes Spy {|na, nb, Key K|} \<notin> set evs;                
paulson@11251
   273
         A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]                 
paulson@11251
   274
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   275
by (blast dest!: A_trusts_YM3 Spy_not_see_encrypted_key)
paulson@11251
   276
paulson@11251
   277
(** Security Guarantees for B upon receiving YM4 **)
paulson@11251
   278
paulson@11251
   279
(*B knows, by the first part of A's message, that the Server distributed 
paulson@11251
   280
  the key for A and B.  But this part says nothing about nonces.*)
paulson@11251
   281
lemma B_trusts_YM4_shrK:
paulson@11251
   282
     "[| Crypt (shrK B) {|Agent A, Key K|} \<in> parts (knows Spy evs);       
paulson@11251
   283
         B \<notin> bad;  evs \<in> yahalom |]                                  
paulson@11251
   284
      ==> \<exists>NA NB. Says Server A                                     
paulson@11251
   285
                      {|Crypt (shrK A) {|Agent B, Key K,              
paulson@11251
   286
                                         Nonce NA, Nonce NB|},        
paulson@11251
   287
                        Crypt (shrK B) {|Agent A, Key K|}|}           
paulson@11251
   288
                     \<in> set evs"
paulson@11251
   289
apply (erule rev_mp)
paulson@11251
   290
apply (erule yahalom.induct, force, 
paulson@11251
   291
       frule_tac [6] YM4_parts_knows_Spy, simp_all)
paulson@11251
   292
(*Fake, YM3*)
paulson@11251
   293
apply blast+
paulson@11251
   294
done
paulson@11251
   295
paulson@11251
   296
(*B knows, by the second part of A's message, that the Server distributed 
paulson@11251
   297
  the key quoting nonce NB.  This part says nothing about agent names. 
paulson@11251
   298
  Secrecy of NB is crucial.  Note that  Nonce NB \<notin> analz(knows Spy evs)  must
paulson@11251
   299
  be the FIRST antecedent of the induction formula.*)
paulson@11251
   300
lemma B_trusts_YM4_newK[rule_format]:
paulson@11251
   301
     "[|Crypt K (Nonce NB) \<in> parts (knows Spy evs);
paulson@11251
   302
        Nonce NB \<notin> analz (knows Spy evs);  evs \<in> yahalom|]
paulson@11251
   303
      ==> \<exists>A B NA. Says Server A                           
paulson@11251
   304
                      {|Crypt (shrK A) {|Agent B, Key K, Nonce NA, Nonce NB|},
paulson@11251
   305
                        Crypt (shrK B) {|Agent A, Key K|}|}   
paulson@11251
   306
                     \<in> set evs"
paulson@11251
   307
apply (erule rev_mp, erule rev_mp)
paulson@11251
   308
apply (erule yahalom.induct, force, 
paulson@11251
   309
       frule_tac [6] YM4_parts_knows_Spy)
paulson@11251
   310
apply (analz_mono_contra, simp_all)
paulson@11251
   311
(*Fake, YM3*)
paulson@11251
   312
apply blast
paulson@11251
   313
apply blast
paulson@11251
   314
(*YM4*)
paulson@11251
   315
(*A is uncompromised because NB is secure
paulson@11251
   316
  A's certificate guarantees the existence of the Server message*)
paulson@11251
   317
apply (blast dest!: Gets_imp_Says Crypt_Spy_analz_bad 
paulson@11251
   318
             dest: Says_imp_spies 
paulson@11251
   319
                   parts.Inj [THEN parts.Fst, THEN A_trusts_YM3])
paulson@11251
   320
done
paulson@11251
   321
paulson@11251
   322
paulson@11251
   323
(**** Towards proving secrecy of Nonce NB ****)
paulson@11251
   324
paulson@11251
   325
(** Lemmas about the predicate KeyWithNonce **)
paulson@11251
   326
paulson@11251
   327
lemma KeyWithNonceI: 
paulson@11251
   328
 "Says Server A                                               
paulson@11251
   329
          {|Crypt (shrK A) {|Agent B, Key K, na, Nonce NB|}, X|}  
paulson@11251
   330
        \<in> set evs ==> KeyWithNonce K NB evs"
paulson@11251
   331
by (unfold KeyWithNonce_def, blast)
paulson@11251
   332
paulson@11251
   333
lemma KeyWithNonce_Says [simp]: 
paulson@11251
   334
   "KeyWithNonce K NB (Says S A X # evs) =                                     
paulson@11251
   335
      (Server = S &
paulson@11251
   336
       (\<exists>B n X'. X = {|Crypt (shrK A) {|Agent B, Key K, n, Nonce NB|}, X'|})  
paulson@11251
   337
      | KeyWithNonce K NB evs)"
paulson@11251
   338
by (simp add: KeyWithNonce_def, blast)
paulson@11251
   339
paulson@11251
   340
paulson@11251
   341
lemma KeyWithNonce_Notes [simp]: 
paulson@11251
   342
   "KeyWithNonce K NB (Notes A X # evs) = KeyWithNonce K NB evs"
paulson@11251
   343
by (simp add: KeyWithNonce_def)
paulson@11251
   344
paulson@11251
   345
lemma KeyWithNonce_Gets [simp]: 
paulson@11251
   346
   "KeyWithNonce K NB (Gets A X # evs) = KeyWithNonce K NB evs"
paulson@11251
   347
by (simp add: KeyWithNonce_def)
paulson@11251
   348
paulson@11251
   349
(*A fresh key cannot be associated with any nonce 
paulson@11251
   350
  (with respect to a given trace). *)
paulson@11251
   351
lemma fresh_not_KeyWithNonce: 
paulson@11251
   352
 "Key K \<notin> used evs ==> ~ KeyWithNonce K NB evs"
paulson@11251
   353
by (unfold KeyWithNonce_def, blast)
paulson@11251
   354
paulson@11251
   355
(*The Server message associates K with NB' and therefore not with any 
paulson@11251
   356
  other nonce NB.*)
paulson@11251
   357
lemma Says_Server_KeyWithNonce: 
paulson@11251
   358
 "[| Says Server A {|Crypt (shrK A) {|Agent B, Key K, na, Nonce NB'|}, X|}  
paulson@11251
   359
       \<in> set evs;                                                  
paulson@11251
   360
     NB \<noteq> NB';  evs \<in> yahalom |]                                  
paulson@11251
   361
  ==> ~ KeyWithNonce K NB evs"
paulson@11251
   362
by (unfold KeyWithNonce_def, blast dest: unique_session_keys)
paulson@11251
   363
paulson@11251
   364
paulson@11251
   365
(*The only nonces that can be found with the help of session keys are
paulson@11251
   366
  those distributed as nonce NB by the Server.  The form of the theorem
paulson@11251
   367
  recalls analz_image_freshK, but it is much more complicated.*)
paulson@11251
   368
paulson@11251
   369
paulson@11251
   370
(*As with analz_image_freshK, we take some pains to express the property
paulson@11251
   371
  as a logical equivalence so that the simplifier can apply it.*)
paulson@11251
   372
lemma Nonce_secrecy_lemma:
paulson@11251
   373
     "P --> (X \<in> analz (G Un H)) --> (X \<in> analz H)  ==>  
paulson@11251
   374
      P --> (X \<in> analz (G Un H)) = (X \<in> analz H)"
paulson@11251
   375
by (blast intro: analz_mono [THEN subsetD])
paulson@11251
   376
paulson@11251
   377
lemma Nonce_secrecy:
paulson@11251
   378
     "evs \<in> yahalom ==>                                       
paulson@11251
   379
      (\<forall>KK. KK <= - (range shrK) -->                       
paulson@11251
   380
           (\<forall>K \<in> KK. ~ KeyWithNonce K NB evs)   -->         
paulson@11251
   381
           (Nonce NB \<in> analz (Key`KK Un (knows Spy evs))) =      
paulson@11251
   382
           (Nonce NB \<in> analz (knows Spy evs)))"
paulson@11251
   383
apply (erule yahalom.induct, force, 
paulson@11251
   384
       frule_tac [6] YM4_analz_knows_Spy)
paulson@11251
   385
apply (safe del: allI impI intro!: Nonce_secrecy_lemma [THEN impI, THEN allI])
paulson@11251
   386
apply (simp_all del: image_insert image_Un 
paulson@11251
   387
       add: analz_image_freshK_simps split_ifs
paulson@11251
   388
            all_conj_distrib ball_conj_distrib 
paulson@11251
   389
            analz_image_freshK fresh_not_KeyWithNonce
paulson@11251
   390
            imp_disj_not1               (*Moves NBa\<noteq>NB to the front*)
paulson@11251
   391
            Says_Server_KeyWithNonce)
paulson@11251
   392
(*For Oops, simplification proves NBa\<noteq>NB.  By Says_Server_KeyWithNonce,
paulson@11251
   393
  we get (~ KeyWithNonce K NB evs); then simplification can apply the
paulson@11251
   394
  induction hypothesis with KK = {K}.*)
paulson@11251
   395
(*Fake*) 
paulson@11251
   396
apply spy_analz
paulson@11251
   397
(*YM4*)  (** LEVEL 6 **)
paulson@13507
   398
apply (erule_tac V = "\<forall>KK. ?P KK" in thin_rl, clarify)
paulson@11251
   399
(*If A \<in> bad then NBa is known, therefore NBa \<noteq> NB.  Previous two steps make
paulson@11251
   400
  the next step faster.*)
paulson@11251
   401
apply (blast dest!: Gets_imp_Says Says_imp_spies Crypt_Spy_analz_bad
paulson@11251
   402
         dest: analz.Inj
paulson@11251
   403
           parts.Inj [THEN parts.Fst, THEN A_trusts_YM3, THEN KeyWithNonceI])
paulson@11251
   404
done
paulson@11251
   405
paulson@11251
   406
paulson@11251
   407
(*Version required below: if NB can be decrypted using a session key then it
paulson@11251
   408
  was distributed with that key.  The more general form above is required
paulson@11251
   409
  for the induction to carry through.*)
paulson@11251
   410
lemma single_Nonce_secrecy:
paulson@11251
   411
     "[| Says Server A                                                
paulson@11251
   412
          {|Crypt (shrK A) {|Agent B, Key KAB, na, Nonce NB'|}, X|}   
paulson@11251
   413
         \<in> set evs;                                                   
paulson@11251
   414
         NB \<noteq> NB';  KAB \<notin> range shrK;  evs \<in> yahalom |]             
paulson@11251
   415
      ==> (Nonce NB \<in> analz (insert (Key KAB) (knows Spy evs))) =         
paulson@11251
   416
          (Nonce NB \<in> analz (knows Spy evs))"
paulson@11251
   417
by (simp_all del: image_insert image_Un imp_disjL
paulson@11251
   418
             add: analz_image_freshK_simps split_ifs
paulson@13507
   419
                  Nonce_secrecy Says_Server_KeyWithNonce)
paulson@11251
   420
paulson@11251
   421
paulson@11251
   422
(*** The Nonce NB uniquely identifies B's message. ***)
paulson@11251
   423
paulson@11251
   424
lemma unique_NB:
paulson@11251
   425
     "[| Crypt (shrK B) {|Agent A, Nonce NA, nb|} \<in> parts (knows Spy evs);     
paulson@11251
   426
         Crypt (shrK B') {|Agent A', Nonce NA', nb|} \<in> parts (knows Spy evs);  
paulson@11251
   427
        evs \<in> yahalom;  B \<notin> bad;  B' \<notin> bad |]   
paulson@11251
   428
      ==> NA' = NA & A' = A & B' = B"
paulson@11251
   429
apply (erule rev_mp, erule rev_mp)
paulson@11251
   430
apply (erule yahalom.induct, force, 
paulson@11251
   431
       frule_tac [6] YM4_parts_knows_Spy, simp_all)
paulson@11251
   432
(*Fake, and YM2 by freshness*)
paulson@11251
   433
apply blast+
paulson@11251
   434
done
paulson@11251
   435
paulson@11251
   436
paulson@11251
   437
(*Variant useful for proving secrecy of NB.  Because nb is assumed to be 
paulson@11251
   438
  secret, we no longer must assume B, B' not bad.*)
paulson@11251
   439
lemma Says_unique_NB:
paulson@11251
   440
     "[| Says C S   {|X,  Crypt (shrK B) {|Agent A, Nonce NA, nb|}|}     
paulson@11251
   441
           \<in> set evs;                           
paulson@11251
   442
         Gets S' {|X', Crypt (shrK B') {|Agent A', Nonce NA', nb|}|}     
paulson@11251
   443
           \<in> set evs;                                                    
paulson@11251
   444
         nb \<notin> analz (knows Spy evs);  evs \<in> yahalom |]                  
paulson@11251
   445
      ==> NA' = NA & A' = A & B' = B"
paulson@11251
   446
by (blast dest!: Gets_imp_Says Crypt_Spy_analz_bad 
paulson@11251
   447
          dest: Says_imp_spies unique_NB parts.Inj analz.Inj)
paulson@11251
   448
paulson@11251
   449
paulson@11251
   450
(** A nonce value is never used both as NA and as NB **)
paulson@11251
   451
paulson@11251
   452
lemma no_nonce_YM1_YM2:
paulson@11251
   453
     "[|Crypt (shrK B') {|Agent A', Nonce NB, nb'|} \<in> parts(knows Spy evs);
paulson@11251
   454
        Nonce NB \<notin> analz (knows Spy evs);  evs \<in> yahalom|]
paulson@11251
   455
  ==> Crypt (shrK B)  {|Agent A, na, Nonce NB|} \<notin> parts(knows Spy evs)"
paulson@11251
   456
apply (erule rev_mp, erule rev_mp)
paulson@11251
   457
apply (erule yahalom.induct, force, 
paulson@11251
   458
       frule_tac [6] YM4_parts_knows_Spy)
paulson@11251
   459
apply (analz_mono_contra, simp_all)
paulson@11251
   460
(*Fake, YM2*)
paulson@11251
   461
apply blast+
paulson@11251
   462
done
paulson@11251
   463
paulson@11251
   464
(*The Server sends YM3 only in response to YM2.*)
paulson@11251
   465
lemma Says_Server_imp_YM2:
paulson@11251
   466
     "[| Says Server A {|Crypt (shrK A) {|Agent B, k, na, nb|}, X|} \<in> set evs;
paulson@11251
   467
         evs \<in> yahalom |]                                              
paulson@11251
   468
      ==> Gets Server {| Agent B, Crypt (shrK B) {|Agent A, na, nb|} |}  
paulson@11251
   469
             \<in> set evs"
paulson@13507
   470
apply (erule rev_mp, erule yahalom.induct, auto)
paulson@11251
   471
done
paulson@11251
   472
paulson@11251
   473
paulson@11251
   474
(*A vital theorem for B, that nonce NB remains secure from the Spy.*)
paulson@11251
   475
lemma Spy_not_see_NB :
paulson@11251
   476
     "[| Says B Server                                                     
paulson@11251
   477
	        {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|}  
paulson@11251
   478
	   \<in> set evs;
paulson@11251
   479
	 (\<forall>k. Notes Spy {|Nonce NA, Nonce NB, k|} \<notin> set evs);
paulson@11251
   480
         A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]   
paulson@11251
   481
      ==> Nonce NB \<notin> analz (knows Spy evs)"
paulson@11251
   482
apply (erule rev_mp, erule rev_mp)
paulson@11251
   483
apply (erule yahalom.induct, force, 
paulson@11251
   484
       frule_tac [6] YM4_analz_knows_Spy)
paulson@11251
   485
apply (simp_all add: split_ifs pushes new_keys_not_analzd analz_insert_eq
paulson@11251
   486
                     analz_insert_freshK)
paulson@11251
   487
(*Fake*)
paulson@11251
   488
apply spy_analz
paulson@11251
   489
(*YM1: NB=NA is impossible anyway, but NA is secret because it is fresh!*)
paulson@11251
   490
apply blast
paulson@11251
   491
(*YM2*)
paulson@11251
   492
apply blast
paulson@11251
   493
(*Prove YM3 by showing that no NB can also be an NA*)
paulson@11251
   494
apply (blast dest!: no_nonce_YM1_YM2 dest: Gets_imp_Says Says_unique_NB)
paulson@11251
   495
(** LEVEL 7: YM4 and Oops remain **)
paulson@11251
   496
apply (clarify, simp add: all_conj_distrib)
paulson@11251
   497
(*YM4: key K is visible to Spy, contradicting session key secrecy theorem*) 
paulson@11251
   498
(*Case analysis on Aa:bad; PROOF FAILED problems
paulson@11251
   499
  use Says_unique_NB to identify message components: Aa=A, Ba=B*)  
paulson@11251
   500
apply (blast dest!: Says_unique_NB 
paulson@11251
   501
                    parts.Inj [THEN parts.Fst, THEN A_trusts_YM3] 
paulson@11251
   502
             dest: Gets_imp_Says Says_imp_spies Says_Server_imp_YM2
paulson@11251
   503
                   Spy_not_see_encrypted_key)
paulson@11251
   504
(*Oops case: if the nonce is betrayed now, show that the Oops event is 
paulson@11251
   505
  covered by the quantified Oops assumption.*)
paulson@11251
   506
apply (clarify, simp add: all_conj_distrib)
paulson@11251
   507
apply (frule Says_Server_imp_YM2, assumption)
paulson@11251
   508
apply (case_tac "NB = NBa")
paulson@11251
   509
(*If NB=NBa then all other components of the Oops message agree*)
paulson@11251
   510
apply (blast dest: Says_unique_NB)
paulson@11251
   511
(*case NB \<noteq> NBa*)
paulson@11251
   512
apply (simp add: single_Nonce_secrecy)
paulson@11251
   513
apply (blast dest!: no_nonce_YM1_YM2 (*to prove NB\<noteq>NAa*))
paulson@11251
   514
done
paulson@11251
   515
paulson@11251
   516
paulson@11251
   517
(*B's session key guarantee from YM4.  The two certificates contribute to a
paulson@11251
   518
  single conclusion about the Server's message.  Note that the "Notes Spy"
paulson@11251
   519
  assumption must quantify over \<forall>POSSIBLE keys instead of our particular K.
paulson@11251
   520
  If this run is broken and the spy substitutes a certificate containing an
paulson@11251
   521
  old key, B has no means of telling.*)
paulson@11251
   522
lemma B_trusts_YM4:
paulson@11251
   523
     "[| Gets B {|Crypt (shrK B) {|Agent A, Key K|},                   
paulson@11251
   524
                  Crypt K (Nonce NB)|} \<in> set evs;                      
paulson@11251
   525
         Says B Server                                                    
paulson@11251
   526
           {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|}    
paulson@11251
   527
           \<in> set evs;                                                     
paulson@11251
   528
         \<forall>k. Notes Spy {|Nonce NA, Nonce NB, k|} \<notin> set evs;           
paulson@11251
   529
         A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]        
paulson@11251
   530
       ==> Says Server A                                                  
paulson@11251
   531
                   {|Crypt (shrK A) {|Agent B, Key K,                     
paulson@11251
   532
                             Nonce NA, Nonce NB|},                        
paulson@11251
   533
                     Crypt (shrK B) {|Agent A, Key K|}|}                  
paulson@11251
   534
             \<in> set evs"
paulson@11251
   535
by (blast dest: Spy_not_see_NB Says_unique_NB 
paulson@11251
   536
                Says_Server_imp_YM2 B_trusts_YM4_newK)
paulson@11251
   537
paulson@11251
   538
paulson@11251
   539
paulson@11251
   540
(*The obvious combination of B_trusts_YM4 with Spy_not_see_encrypted_key*)
paulson@11251
   541
lemma B_gets_good_key:
paulson@11251
   542
     "[| Gets B {|Crypt (shrK B) {|Agent A, Key K|},
paulson@11251
   543
                  Crypt K (Nonce NB)|} \<in> set evs;
paulson@11251
   544
         Says B Server                                                    
paulson@11251
   545
           {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|}    
paulson@11251
   546
           \<in> set evs;                                                     
paulson@11251
   547
         \<forall>k. Notes Spy {|Nonce NA, Nonce NB, k|} \<notin> set evs;           
paulson@11251
   548
         A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]                 
paulson@11251
   549
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   550
by (blast dest!: B_trusts_YM4 Spy_not_see_encrypted_key)
paulson@11251
   551
paulson@11251
   552
paulson@11251
   553
(*** Authenticating B to A ***)
paulson@11251
   554
paulson@11251
   555
(*The encryption in message YM2 tells us it cannot be faked.*)
paulson@11251
   556
lemma B_Said_YM2 [rule_format]:
paulson@11251
   557
     "[|Crypt (shrK B) {|Agent A, Nonce NA, nb|} \<in> parts (knows Spy evs);
paulson@11251
   558
        evs \<in> yahalom|]
paulson@11251
   559
      ==> B \<notin> bad -->
paulson@11251
   560
          Says B Server {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, nb|}|}
paulson@11251
   561
            \<in> set evs"
paulson@11251
   562
apply (erule rev_mp, erule yahalom.induct, force, 
paulson@11251
   563
       frule_tac [6] YM4_parts_knows_Spy, simp_all)
paulson@11251
   564
(*Fake*)
paulson@11251
   565
apply blast
paulson@11251
   566
done
paulson@11251
   567
paulson@11251
   568
(*If the server sends YM3 then B sent YM2*)
paulson@11251
   569
lemma YM3_auth_B_to_A_lemma:
paulson@11251
   570
     "[|Says Server A {|Crypt (shrK A) {|Agent B, Key K, Nonce NA, nb|}, X|}  
paulson@11251
   571
       \<in> set evs;  evs \<in> yahalom|]
paulson@11251
   572
      ==> B \<notin> bad -->                                                         
paulson@11251
   573
          Says B Server {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, nb|}|}
paulson@11251
   574
            \<in> set evs"
paulson@11251
   575
apply (erule rev_mp, erule yahalom.induct, simp_all)
paulson@11251
   576
(*YM3, YM4*)
paulson@11251
   577
apply (blast dest!: B_Said_YM2)+
paulson@11251
   578
done
paulson@11251
   579
paulson@11251
   580
(*If A receives YM3 then B has used nonce NA (and therefore is alive)*)
paulson@11251
   581
lemma YM3_auth_B_to_A:
paulson@11251
   582
     "[| Gets A {|Crypt (shrK A) {|Agent B, Key K, Nonce NA, nb|}, X|}  
paulson@11251
   583
           \<in> set evs;                                                     
paulson@11251
   584
         A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]                         
paulson@11251
   585
      ==> Says B Server {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, nb|}|}  
paulson@11251
   586
       \<in> set evs"
paulson@11251
   587
by (blast dest!: A_trusts_YM3 YM3_auth_B_to_A_lemma elim: knows_Spy_partsEs)
paulson@11251
   588
paulson@11251
   589
paulson@11251
   590
(*** Authenticating A to B using the certificate Crypt K (Nonce NB) ***)
paulson@11251
   591
paulson@11251
   592
(*Assuming the session key is secure, if both certificates are present then
paulson@11251
   593
  A has said NB.  We can't be sure about the rest of A's message, but only
paulson@11251
   594
  NB matters for freshness.*)  
paulson@11251
   595
lemma A_Said_YM3_lemma [rule_format]:
paulson@11251
   596
     "evs \<in> yahalom
paulson@11251
   597
      ==> Key K \<notin> analz (knows Spy evs) -->
paulson@11251
   598
          Crypt K (Nonce NB) \<in> parts (knows Spy evs) -->
paulson@11251
   599
          Crypt (shrK B) {|Agent A, Key K|} \<in> parts (knows Spy evs) -->
paulson@11251
   600
          B \<notin> bad -->
paulson@11251
   601
          (\<exists>X. Says A B {|X, Crypt K (Nonce NB)|} \<in> set evs)"
paulson@11251
   602
apply (erule yahalom.induct, force, 
paulson@11251
   603
       frule_tac [6] YM4_parts_knows_Spy)
paulson@11251
   604
apply (analz_mono_contra, simp_all)
paulson@11251
   605
(*Fake*)
paulson@11251
   606
apply blast
paulson@11251
   607
(*YM3: by new_keys_not_used we note that Crypt K (Nonce NB) could not exist*)
paulson@11251
   608
apply (force dest!: Crypt_imp_keysFor)
paulson@11251
   609
(*YM4: was Crypt K (Nonce NB) the very last message?  If not, use ind. hyp.*)
paulson@11251
   610
apply (simp add: ex_disj_distrib)
paulson@11251
   611
(*yes: apply unicity of session keys*)
paulson@11251
   612
apply (blast dest!: Gets_imp_Says A_trusts_YM3 B_trusts_YM4_shrK
paulson@11251
   613
                    Crypt_Spy_analz_bad 
paulson@11251
   614
             dest: Says_imp_knows_Spy [THEN parts.Inj] unique_session_keys)
paulson@11251
   615
done
paulson@11251
   616
paulson@11251
   617
(*If B receives YM4 then A has used nonce NB (and therefore is alive).
paulson@11251
   618
  Moreover, A associates K with NB (thus is talking about the same run).
paulson@11251
   619
  Other premises guarantee secrecy of K.*)
paulson@11251
   620
lemma YM4_imp_A_Said_YM3 [rule_format]:
paulson@11251
   621
     "[| Gets B {|Crypt (shrK B) {|Agent A, Key K|},
paulson@11251
   622
                  Crypt K (Nonce NB)|} \<in> set evs;
paulson@11251
   623
         Says B Server
paulson@11251
   624
           {|Agent B, Crypt (shrK B) {|Agent A, Nonce NA, Nonce NB|}|}
paulson@11251
   625
           \<in> set evs;
paulson@11251
   626
         (\<forall>NA k. Notes Spy {|Nonce NA, Nonce NB, k|} \<notin> set evs);
paulson@11251
   627
         A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]
paulson@11251
   628
      ==> \<exists>X. Says A B {|X, Crypt K (Nonce NB)|} \<in> set evs"
paulson@11251
   629
by (blast intro!: A_Said_YM3_lemma 
paulson@11251
   630
          dest: Spy_not_see_encrypted_key B_trusts_YM4 Gets_imp_Says)
paulson@3447
   631
paulson@1985
   632
end