src/HOL/Auth/Yahalom2.thy
author wenzelm
Mon Jan 11 21:21:02 2016 +0100 (2016-01-11)
changeset 62145 5b946c81dfbf
parent 61956 38b73f7940af
child 64364 464420ba7f74
permissions -rw-r--r--
eliminated old defs;
wenzelm@37936
     1
(*  Title:      HOL/Auth/Yahalom2.thy
paulson@2111
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@2111
     3
    Copyright   1996  University of Cambridge
paulson@14207
     4
*)
paulson@2111
     5
wenzelm@61830
     6
section\<open>The Yahalom Protocol, Variant 2\<close>
paulson@14207
     7
haftmann@16417
     8
theory Yahalom2 imports Public begin
paulson@14207
     9
wenzelm@61830
    10
text\<open>
paulson@2111
    11
This version trades encryption of NB for additional explicitness in YM3.
paulson@3432
    12
Also in YM3, care is taken to make the two certificates distinct.
paulson@2111
    13
paulson@2111
    14
From page 259 of
paulson@14207
    15
  Burrows, Abadi and Needham (1989).  A Logic of Authentication.
paulson@14207
    16
  Proc. Royal Soc. 426
paulson@2111
    17
paulson@14207
    18
This theory has the prototypical example of a secrecy relation, KeyCryptNonce.
wenzelm@61830
    19
\<close>
paulson@2111
    20
berghofe@23746
    21
inductive_set yahalom :: "event list set"
berghofe@23746
    22
  where
paulson@2111
    23
         (*Initial trace is empty*)
paulson@11251
    24
   Nil:  "[] \<in> yahalom"
paulson@2111
    25
paulson@2111
    26
         (*The spy MAY say anything he CAN say.  We do not expect him to
paulson@2111
    27
           invent new nonces here, but he can also use NS1.  Common to
paulson@2111
    28
           all similar protocols.*)
berghofe@23746
    29
 | Fake: "[| evsf \<in> yahalom;  X \<in> synth (analz (knows Spy evsf)) |]
paulson@11251
    30
          ==> Says Spy B X  # evsf \<in> yahalom"
paulson@2111
    31
paulson@6335
    32
         (*A message that has been sent can be received by the
paulson@6335
    33
           intended recipient.*)
berghofe@23746
    34
 | Reception: "[| evsr \<in> yahalom;  Says A B X \<in> set evsr |]
paulson@11251
    35
               ==> Gets B X # evsr \<in> yahalom"
paulson@6335
    36
paulson@2111
    37
         (*Alice initiates a protocol run*)
berghofe@23746
    38
 | YM1:  "[| evs1 \<in> yahalom;  Nonce NA \<notin> used evs1 |]
wenzelm@61956
    39
          ==> Says A B \<lbrace>Agent A, Nonce NA\<rbrace> # evs1 \<in> yahalom"
paulson@2111
    40
paulson@6335
    41
         (*Bob's response to Alice's message.*)
berghofe@23746
    42
 | YM2:  "[| evs2 \<in> yahalom;  Nonce NB \<notin> used evs2;
wenzelm@61956
    43
             Gets B \<lbrace>Agent A, Nonce NA\<rbrace> \<in> set evs2 |]
paulson@11251
    44
          ==> Says B Server
wenzelm@61956
    45
                  \<lbrace>Agent B, Nonce NB, Crypt (shrK B) \<lbrace>Agent A, Nonce NA\<rbrace>\<rbrace>
paulson@11251
    46
                # evs2 \<in> yahalom"
paulson@2111
    47
paulson@2111
    48
         (*The Server receives Bob's message.  He responds by sending a
paulson@3659
    49
           new session key to Alice, with a certificate for forwarding to Bob.
paulson@5066
    50
           Both agents are quoted in the 2nd certificate to prevent attacks!*)
berghofe@23746
    51
 | YM3:  "[| evs3 \<in> yahalom;  Key KAB \<notin> used evs3;
wenzelm@61956
    52
             Gets Server \<lbrace>Agent B, Nonce NB,
wenzelm@61956
    53
                           Crypt (shrK B) \<lbrace>Agent A, Nonce NA\<rbrace>\<rbrace>
paulson@11251
    54
               \<in> set evs3 |]
paulson@2111
    55
          ==> Says Server A
wenzelm@61956
    56
               \<lbrace>Nonce NB,
wenzelm@61956
    57
                 Crypt (shrK A) \<lbrace>Agent B, Key KAB, Nonce NA\<rbrace>,
wenzelm@61956
    58
                 Crypt (shrK B) \<lbrace>Agent A, Agent B, Key KAB, Nonce NB\<rbrace>\<rbrace>
paulson@11251
    59
                 # evs3 \<in> yahalom"
paulson@2111
    60
paulson@2111
    61
         (*Alice receives the Server's (?) message, checks her Nonce, and
paulson@2111
    62
           uses the new session key to send Bob his Nonce.*)
berghofe@23746
    63
 | YM4:  "[| evs4 \<in> yahalom;
wenzelm@61956
    64
             Gets A \<lbrace>Nonce NB, Crypt (shrK A) \<lbrace>Agent B, Key K, Nonce NA\<rbrace>,
wenzelm@61956
    65
                      X\<rbrace>  \<in> set evs4;
wenzelm@61956
    66
             Says A B \<lbrace>Agent A, Nonce NA\<rbrace> \<in> set evs4 |]
wenzelm@61956
    67
          ==> Says A B \<lbrace>X, Crypt K (Nonce NB)\<rbrace> # evs4 \<in> yahalom"
paulson@2111
    68
paulson@2155
    69
         (*This message models possible leaks of session keys.  The nonces
paulson@2155
    70
           identify the protocol run.  Quoting Server here ensures they are
paulson@2155
    71
           correct. *)
berghofe@23746
    72
 | Oops: "[| evso \<in> yahalom;
wenzelm@61956
    73
             Says Server A \<lbrace>Nonce NB,
wenzelm@61956
    74
                             Crypt (shrK A) \<lbrace>Agent B, Key K, Nonce NA\<rbrace>,
wenzelm@61956
    75
                             X\<rbrace>  \<in> set evso |]
wenzelm@61956
    76
          ==> Notes Spy \<lbrace>Nonce NA, Nonce NB, Key K\<rbrace> # evso \<in> yahalom"
paulson@11251
    77
paulson@11251
    78
paulson@11251
    79
declare Says_imp_knows_Spy [THEN analz.Inj, dest]
paulson@11251
    80
declare parts.Body  [dest]
paulson@11251
    81
declare Fake_parts_insert_in_Un  [dest]
paulson@11251
    82
declare analz_into_parts [dest]
paulson@11251
    83
wenzelm@61830
    84
text\<open>A "possibility property": there are traces that reach the end\<close>
paulson@14200
    85
lemma "Key K \<notin> used []
paulson@14200
    86
       ==> \<exists>X NB. \<exists>evs \<in> yahalom.
wenzelm@61956
    87
             Says A B \<lbrace>X, Crypt K (Nonce NB)\<rbrace> \<in> set evs"
paulson@11251
    88
apply (intro exI bexI)
paulson@11251
    89
apply (rule_tac [2] yahalom.Nil
paulson@11251
    90
                    [THEN yahalom.YM1, THEN yahalom.Reception,
paulson@11251
    91
                     THEN yahalom.YM2, THEN yahalom.Reception,
paulson@11251
    92
                     THEN yahalom.YM3, THEN yahalom.Reception,
paulson@14200
    93
                     THEN yahalom.YM4])
paulson@14207
    94
apply (possibility, simp add: used_Cons)
paulson@11251
    95
done
paulson@11251
    96
paulson@11251
    97
lemma Gets_imp_Says:
paulson@11251
    98
     "[| Gets B X \<in> set evs; evs \<in> yahalom |] ==> \<exists>A. Says A B X \<in> set evs"
paulson@11251
    99
by (erule rev_mp, erule yahalom.induct, auto)
paulson@11251
   100
wenzelm@61830
   101
text\<open>Must be proved separately for each protocol\<close>
paulson@11251
   102
lemma Gets_imp_knows_Spy:
paulson@11251
   103
     "[| Gets B X \<in> set evs; evs \<in> yahalom |]  ==> X \<in> knows Spy evs"
paulson@11251
   104
by (blast dest!: Gets_imp_Says Says_imp_knows_Spy)
paulson@11251
   105
paulson@11251
   106
declare Gets_imp_knows_Spy [THEN analz.Inj, dest]
paulson@11251
   107
paulson@11251
   108
wenzelm@61830
   109
subsection\<open>Inductive Proofs\<close>
paulson@11251
   110
wenzelm@61830
   111
text\<open>Result for reasoning about the encrypted portion of messages.
wenzelm@61830
   112
Lets us treat YM4 using a similar argument as for the Fake case.\<close>
paulson@11251
   113
lemma YM4_analz_knows_Spy:
wenzelm@61956
   114
     "[| Gets A \<lbrace>NB, Crypt (shrK A) Y, X\<rbrace> \<in> set evs;  evs \<in> yahalom |]
paulson@11251
   115
      ==> X \<in> analz (knows Spy evs)"
paulson@11251
   116
by blast
paulson@11251
   117
paulson@11251
   118
lemmas YM4_parts_knows_Spy =
wenzelm@45605
   119
       YM4_analz_knows_Spy [THEN analz_into_parts]
paulson@11251
   120
paulson@11251
   121
paulson@11251
   122
(** Theorems of the form X \<notin> parts (knows Spy evs) imply that NOBODY
paulson@11251
   123
    sends messages containing X! **)
paulson@11251
   124
wenzelm@61830
   125
text\<open>Spy never sees a good agent's shared key!\<close>
paulson@11251
   126
lemma Spy_see_shrK [simp]:
paulson@11251
   127
     "evs \<in> yahalom ==> (Key (shrK A) \<in> parts (knows Spy evs)) = (A \<in> bad)"
paulson@13907
   128
by (erule yahalom.induct, force,
paulson@13907
   129
    drule_tac [6] YM4_parts_knows_Spy, simp_all, blast+)
paulson@11251
   130
paulson@11251
   131
lemma Spy_analz_shrK [simp]:
paulson@11251
   132
     "evs \<in> yahalom ==> (Key (shrK A) \<in> analz (knows Spy evs)) = (A \<in> bad)"
paulson@11251
   133
by auto
paulson@11251
   134
paulson@11251
   135
lemma Spy_see_shrK_D [dest!]:
paulson@11251
   136
     "[|Key (shrK A) \<in> parts (knows Spy evs);  evs \<in> yahalom|] ==> A \<in> bad"
paulson@11251
   137
by (blast dest: Spy_see_shrK)
paulson@11251
   138
wenzelm@61830
   139
text\<open>Nobody can have used non-existent keys!  
wenzelm@61830
   140
    Needed to apply \<open>analz_insert_Key\<close>\<close>
paulson@14207
   141
lemma new_keys_not_used [simp]:
paulson@14207
   142
    "[|Key K \<notin> used evs; K \<in> symKeys; evs \<in> yahalom|]
paulson@14207
   143
     ==> K \<notin> keysFor (parts (spies evs))"
paulson@14207
   144
apply (erule rev_mp)
paulson@11251
   145
apply (erule yahalom.induct, force,
paulson@11251
   146
       frule_tac [6] YM4_parts_knows_Spy, simp_all)
wenzelm@61830
   147
txt\<open>Fake\<close>
paulson@13926
   148
apply (force dest!: keysFor_parts_insert)
wenzelm@61830
   149
txt\<open>YM3\<close>
paulson@14207
   150
apply blast
wenzelm@61830
   151
txt\<open>YM4\<close>
paulson@14207
   152
apply auto
paulson@14207
   153
apply (blast dest!: Gets_imp_knows_Spy [THEN parts.Inj])
paulson@11251
   154
done
paulson@11251
   155
paulson@11251
   156
wenzelm@61830
   157
text\<open>Describes the form of K when the Server sends this message.  Useful for
wenzelm@61830
   158
  Oops as well as main secrecy property.\<close>
paulson@11251
   159
lemma Says_Server_message_form:
wenzelm@61956
   160
     "[| Says Server A \<lbrace>nb', Crypt (shrK A) \<lbrace>Agent B, Key K, na\<rbrace>, X\<rbrace>
paulson@11251
   161
          \<in> set evs;  evs \<in> yahalom |]
paulson@11251
   162
      ==> K \<notin> range shrK"
paulson@11251
   163
by (erule rev_mp, erule yahalom.induct, simp_all)
paulson@11251
   164
paulson@11251
   165
paulson@11251
   166
(****
paulson@11251
   167
 The following is to prove theorems of the form
paulson@11251
   168
paulson@11251
   169
          Key K \<in> analz (insert (Key KAB) (knows Spy evs)) ==>
paulson@11251
   170
          Key K \<in> analz (knows Spy evs)
paulson@11251
   171
paulson@11251
   172
 A more general formula must be proved inductively.
paulson@11251
   173
****)
paulson@11251
   174
paulson@11251
   175
(** Session keys are not used to encrypt other session keys **)
paulson@11251
   176
paulson@11251
   177
lemma analz_image_freshK [rule_format]:
paulson@11251
   178
 "evs \<in> yahalom ==>
paulson@11251
   179
   \<forall>K KK. KK <= - (range shrK) -->
paulson@11251
   180
          (Key K \<in> analz (Key`KK Un (knows Spy evs))) =
paulson@11251
   181
          (K \<in> KK | Key K \<in> analz (knows Spy evs))"
paulson@14207
   182
apply (erule yahalom.induct)
paulson@14207
   183
apply (frule_tac [8] Says_Server_message_form)
paulson@14207
   184
apply (drule_tac [7] YM4_analz_knows_Spy, analz_freshK, spy_analz, blast)
paulson@11251
   185
done
paulson@11251
   186
paulson@11251
   187
lemma analz_insert_freshK:
paulson@11251
   188
     "[| evs \<in> yahalom;  KAB \<notin> range shrK |] ==>
wenzelm@11655
   189
      (Key K \<in> analz (insert (Key KAB) (knows Spy evs))) =
paulson@11251
   190
      (K = KAB | Key K \<in> analz (knows Spy evs))"
paulson@11251
   191
by (simp only: analz_image_freshK analz_image_freshK_simps)
paulson@11251
   192
paulson@11251
   193
wenzelm@61830
   194
text\<open>The Key K uniquely identifies the Server's  message\<close>
paulson@11251
   195
lemma unique_session_keys:
paulson@11251
   196
     "[| Says Server A
wenzelm@61956
   197
          \<lbrace>nb, Crypt (shrK A) \<lbrace>Agent B, Key K, na\<rbrace>, X\<rbrace> \<in> set evs;
paulson@11251
   198
        Says Server A'
wenzelm@61956
   199
          \<lbrace>nb', Crypt (shrK A') \<lbrace>Agent B', Key K, na'\<rbrace>, X'\<rbrace> \<in> set evs;
paulson@11251
   200
        evs \<in> yahalom |]
paulson@11251
   201
     ==> A=A' & B=B' & na=na' & nb=nb'"
paulson@11251
   202
apply (erule rev_mp, erule rev_mp)
paulson@11251
   203
apply (erule yahalom.induct, simp_all)
wenzelm@61830
   204
txt\<open>YM3, by freshness\<close>
paulson@11251
   205
apply blast
paulson@11251
   206
done
paulson@11251
   207
paulson@11251
   208
wenzelm@61830
   209
subsection\<open>Crucial Secrecy Property: Spy Does Not See Key @{term KAB}\<close>
paulson@11251
   210
paulson@11251
   211
lemma secrecy_lemma:
paulson@11251
   212
     "[| A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]
paulson@11251
   213
      ==> Says Server A
wenzelm@61956
   214
            \<lbrace>nb, Crypt (shrK A) \<lbrace>Agent B, Key K, na\<rbrace>,
wenzelm@61956
   215
                  Crypt (shrK B) \<lbrace>Agent A, Agent B, Key K, nb\<rbrace>\<rbrace>
paulson@11251
   216
           \<in> set evs -->
wenzelm@61956
   217
          Notes Spy \<lbrace>na, nb, Key K\<rbrace> \<notin> set evs -->
paulson@11251
   218
          Key K \<notin> analz (knows Spy evs)"
paulson@11251
   219
apply (erule yahalom.induct, force, frule_tac [7] Says_Server_message_form,
paulson@11251
   220
       drule_tac [6] YM4_analz_knows_Spy)
paulson@13907
   221
apply (simp_all add: pushes analz_insert_eq analz_insert_freshK, spy_analz)
paulson@11251
   222
apply (blast dest: unique_session_keys)+  (*YM3, Oops*)
paulson@11251
   223
done
paulson@11251
   224
paulson@11251
   225
wenzelm@61830
   226
text\<open>Final version\<close>
paulson@11251
   227
lemma Spy_not_see_encrypted_key:
paulson@11251
   228
     "[| Says Server A
wenzelm@61956
   229
            \<lbrace>nb, Crypt (shrK A) \<lbrace>Agent B, Key K, na\<rbrace>,
wenzelm@61956
   230
                  Crypt (shrK B) \<lbrace>Agent A, Agent B, Key K, nb\<rbrace>\<rbrace>
paulson@11251
   231
         \<in> set evs;
wenzelm@61956
   232
         Notes Spy \<lbrace>na, nb, Key K\<rbrace> \<notin> set evs;
paulson@11251
   233
         A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]
paulson@11251
   234
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   235
by (blast dest: secrecy_lemma Says_Server_message_form)
paulson@11251
   236
paulson@11251
   237
paulson@13907
   238
wenzelm@61830
   239
text\<open>This form is an immediate consequence of the previous result.  It is
paulson@13907
   240
similar to the assertions established by other methods.  It is equivalent
paulson@13907
   241
to the previous result in that the Spy already has @{term analz} and
paulson@14207
   242
@{term synth} at his disposal.  However, the conclusion
paulson@13907
   243
@{term "Key K \<notin> knows Spy evs"} appears not to be inductive: all the cases
paulson@14207
   244
other than Fake are trivial, while Fake requires
wenzelm@61830
   245
@{term "Key K \<notin> analz (knows Spy evs)"}.\<close>
paulson@13907
   246
lemma Spy_not_know_encrypted_key:
paulson@13907
   247
     "[| Says Server A
wenzelm@61956
   248
            \<lbrace>nb, Crypt (shrK A) \<lbrace>Agent B, Key K, na\<rbrace>,
wenzelm@61956
   249
                  Crypt (shrK B) \<lbrace>Agent A, Agent B, Key K, nb\<rbrace>\<rbrace>
paulson@13907
   250
         \<in> set evs;
wenzelm@61956
   251
         Notes Spy \<lbrace>na, nb, Key K\<rbrace> \<notin> set evs;
paulson@13907
   252
         A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]
paulson@13907
   253
      ==> Key K \<notin> knows Spy evs"
paulson@13907
   254
by (blast dest: Spy_not_see_encrypted_key)
paulson@13907
   255
paulson@13907
   256
wenzelm@61830
   257
subsection\<open>Security Guarantee for A upon receiving YM3\<close>
paulson@11251
   258
wenzelm@61830
   259
text\<open>If the encrypted message appears then it originated with the Server.
wenzelm@61830
   260
  May now apply \<open>Spy_not_see_encrypted_key\<close>, subject to its conditions.\<close>
paulson@11251
   261
lemma A_trusts_YM3:
wenzelm@61956
   262
     "[| Crypt (shrK A) \<lbrace>Agent B, Key K, na\<rbrace> \<in> parts (knows Spy evs);
paulson@11251
   263
         A \<notin> bad;  evs \<in> yahalom |]
paulson@11251
   264
      ==> \<exists>nb. Says Server A
wenzelm@61956
   265
                    \<lbrace>nb, Crypt (shrK A) \<lbrace>Agent B, Key K, na\<rbrace>,
wenzelm@61956
   266
                          Crypt (shrK B) \<lbrace>Agent A, Agent B, Key K, nb\<rbrace>\<rbrace>
paulson@11251
   267
                  \<in> set evs"
paulson@11251
   268
apply (erule rev_mp)
paulson@11251
   269
apply (erule yahalom.induct, force,
paulson@11251
   270
       frule_tac [6] YM4_parts_knows_Spy, simp_all)
wenzelm@61830
   271
txt\<open>Fake, YM3\<close>
paulson@11251
   272
apply blast+
paulson@11251
   273
done
paulson@11251
   274
wenzelm@61830
   275
text\<open>The obvious combination of \<open>A_trusts_YM3\<close> with 
wenzelm@61830
   276
\<open>Spy_not_see_encrypted_key\<close>\<close>
paulson@13907
   277
theorem A_gets_good_key:
wenzelm@61956
   278
     "[| Crypt (shrK A) \<lbrace>Agent B, Key K, na\<rbrace> \<in> parts (knows Spy evs);
wenzelm@61956
   279
         \<forall>nb. Notes Spy \<lbrace>na, nb, Key K\<rbrace> \<notin> set evs;
paulson@11251
   280
         A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]
paulson@11251
   281
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   282
by (blast dest!: A_trusts_YM3 Spy_not_see_encrypted_key)
paulson@11251
   283
paulson@11251
   284
wenzelm@61830
   285
subsection\<open>Security Guarantee for B upon receiving YM4\<close>
paulson@11251
   286
wenzelm@61830
   287
text\<open>B knows, by the first part of A's message, that the Server distributed
wenzelm@61830
   288
  the key for A and B, and has associated it with NB.\<close>
paulson@11251
   289
lemma B_trusts_YM4_shrK:
wenzelm@61956
   290
     "[| Crypt (shrK B) \<lbrace>Agent A, Agent B, Key K, Nonce NB\<rbrace>
paulson@11251
   291
           \<in> parts (knows Spy evs);
paulson@11251
   292
         B \<notin> bad;  evs \<in> yahalom |]
paulson@11251
   293
  ==> \<exists>NA. Says Server A
wenzelm@61956
   294
             \<lbrace>Nonce NB,
wenzelm@61956
   295
               Crypt (shrK A) \<lbrace>Agent B, Key K, Nonce NA\<rbrace>,
wenzelm@61956
   296
               Crypt (shrK B) \<lbrace>Agent A, Agent B, Key K, Nonce NB\<rbrace>\<rbrace>
paulson@11251
   297
             \<in> set evs"
paulson@11251
   298
apply (erule rev_mp)
paulson@11251
   299
apply (erule yahalom.induct, force,
paulson@11251
   300
       frule_tac [6] YM4_parts_knows_Spy, simp_all)
wenzelm@61830
   301
txt\<open>Fake, YM3\<close>
paulson@11251
   302
apply blast+
paulson@11251
   303
done
paulson@11251
   304
paulson@11251
   305
wenzelm@61830
   306
text\<open>With this protocol variant, we don't need the 2nd part of YM4 at all:
wenzelm@61830
   307
  Nonce NB is available in the first part.\<close>
paulson@11251
   308
wenzelm@61830
   309
text\<open>What can B deduce from receipt of YM4?  Stronger and simpler than Yahalom
wenzelm@61830
   310
  because we do not have to show that NB is secret.\<close>
paulson@11251
   311
lemma B_trusts_YM4:
wenzelm@61956
   312
     "[| Gets B \<lbrace>Crypt (shrK B) \<lbrace>Agent A, Agent B, Key K, Nonce NB\<rbrace>,  X\<rbrace>
paulson@11251
   313
           \<in> set evs;
paulson@11251
   314
         A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]
paulson@11251
   315
  ==> \<exists>NA. Says Server A
wenzelm@61956
   316
             \<lbrace>Nonce NB,
wenzelm@61956
   317
               Crypt (shrK A) \<lbrace>Agent B, Key K, Nonce NA\<rbrace>,
wenzelm@61956
   318
               Crypt (shrK B) \<lbrace>Agent A, Agent B, Key K, Nonce NB\<rbrace>\<rbrace>
paulson@11251
   319
            \<in> set evs"
paulson@11251
   320
by (blast dest!: B_trusts_YM4_shrK)
paulson@11251
   321
paulson@11251
   322
wenzelm@61830
   323
text\<open>The obvious combination of \<open>B_trusts_YM4\<close> with 
wenzelm@61830
   324
\<open>Spy_not_see_encrypted_key\<close>\<close>
paulson@13907
   325
theorem B_gets_good_key:
wenzelm@61956
   326
     "[| Gets B \<lbrace>Crypt (shrK B) \<lbrace>Agent A, Agent B, Key K, Nonce NB\<rbrace>, X\<rbrace>
paulson@11251
   327
           \<in> set evs;
wenzelm@61956
   328
         \<forall>na. Notes Spy \<lbrace>na, Nonce NB, Key K\<rbrace> \<notin> set evs;
paulson@11251
   329
         A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]
paulson@11251
   330
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   331
by (blast dest!: B_trusts_YM4 Spy_not_see_encrypted_key)
paulson@11251
   332
paulson@11251
   333
wenzelm@61830
   334
subsection\<open>Authenticating B to A\<close>
paulson@11251
   335
wenzelm@61830
   336
text\<open>The encryption in message YM2 tells us it cannot be faked.\<close>
paulson@11251
   337
lemma B_Said_YM2:
wenzelm@61956
   338
     "[| Crypt (shrK B) \<lbrace>Agent A, Nonce NA\<rbrace> \<in> parts (knows Spy evs);
paulson@11251
   339
         B \<notin> bad;  evs \<in> yahalom |]
wenzelm@61956
   340
      ==> \<exists>NB. Says B Server \<lbrace>Agent B, Nonce NB,
wenzelm@61956
   341
                               Crypt (shrK B) \<lbrace>Agent A, Nonce NA\<rbrace>\<rbrace>
paulson@11251
   342
                      \<in> set evs"
paulson@11251
   343
apply (erule rev_mp)
paulson@11251
   344
apply (erule yahalom.induct, force,
paulson@11251
   345
       frule_tac [6] YM4_parts_knows_Spy, simp_all)
wenzelm@61830
   346
txt\<open>Fake, YM2\<close>
paulson@11251
   347
apply blast+
paulson@11251
   348
done
paulson@11251
   349
paulson@11251
   350
wenzelm@61830
   351
text\<open>If the server sends YM3 then B sent YM2, perhaps with a different NB\<close>
paulson@11251
   352
lemma YM3_auth_B_to_A_lemma:
wenzelm@61956
   353
     "[| Says Server A \<lbrace>nb, Crypt (shrK A) \<lbrace>Agent B, Key K, Nonce NA\<rbrace>, X\<rbrace>
paulson@11251
   354
           \<in> set evs;
paulson@11251
   355
         B \<notin> bad;  evs \<in> yahalom |]
wenzelm@61956
   356
      ==> \<exists>nb'. Says B Server \<lbrace>Agent B, nb',
wenzelm@61956
   357
                                   Crypt (shrK B) \<lbrace>Agent A, Nonce NA\<rbrace>\<rbrace>
paulson@11251
   358
                       \<in> set evs"
paulson@11251
   359
apply (erule rev_mp)
paulson@11251
   360
apply (erule yahalom.induct, simp_all)
wenzelm@61830
   361
txt\<open>Fake, YM2, YM3\<close>
paulson@11251
   362
apply (blast dest!: B_Said_YM2)+
paulson@11251
   363
done
paulson@11251
   364
wenzelm@61830
   365
text\<open>If A receives YM3 then B has used nonce NA (and therefore is alive)\<close>
paulson@13907
   366
theorem YM3_auth_B_to_A:
wenzelm@61956
   367
     "[| Gets A \<lbrace>nb, Crypt (shrK A) \<lbrace>Agent B, Key K, Nonce NA\<rbrace>, X\<rbrace>
paulson@11251
   368
           \<in> set evs;
paulson@11251
   369
         A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]
paulson@11251
   370
 ==> \<exists>nb'. Says B Server
wenzelm@61956
   371
                  \<lbrace>Agent B, nb', Crypt (shrK B) \<lbrace>Agent A, Nonce NA\<rbrace>\<rbrace>
paulson@11251
   372
               \<in> set evs"
paulson@11251
   373
by (blast dest!: A_trusts_YM3 YM3_auth_B_to_A_lemma)
paulson@11251
   374
paulson@11251
   375
wenzelm@61830
   376
subsection\<open>Authenticating A to B\<close>
paulson@11251
   377
wenzelm@61830
   378
text\<open>using the certificate @{term "Crypt K (Nonce NB)"}\<close>
paulson@11251
   379
wenzelm@61830
   380
text\<open>Assuming the session key is secure, if both certificates are present then
paulson@11251
   381
  A has said NB.  We can't be sure about the rest of A's message, but only
paulson@14207
   382
  NB matters for freshness.  Note that @{term "Key K \<notin> analz (knows Spy evs)"}
wenzelm@61830
   383
  must be the FIRST antecedent of the induction formula.\<close>
paulson@11251
   384
wenzelm@61830
   385
text\<open>This lemma allows a use of \<open>unique_session_keys\<close> in the next proof,
wenzelm@61830
   386
  which otherwise is extremely slow.\<close>
paulson@11251
   387
lemma secure_unique_session_keys:
wenzelm@61956
   388
     "[| Crypt (shrK A) \<lbrace>Agent B, Key K, na\<rbrace> \<in> analz (spies evs);
wenzelm@61956
   389
         Crypt (shrK A') \<lbrace>Agent B', Key K, na'\<rbrace> \<in> analz (spies evs);
paulson@11251
   390
         Key K \<notin> analz (knows Spy evs);  evs \<in> yahalom |]
paulson@11251
   391
     ==> A=A' & B=B'"
paulson@11251
   392
by (blast dest!: A_trusts_YM3 dest: unique_session_keys Crypt_Spy_analz_bad)
paulson@11251
   393
paulson@11251
   394
paulson@11251
   395
lemma Auth_A_to_B_lemma [rule_format]:
paulson@11251
   396
     "evs \<in> yahalom
paulson@11251
   397
      ==> Key K \<notin> analz (knows Spy evs) -->
paulson@14207
   398
          K \<in> symKeys -->
paulson@11251
   399
          Crypt K (Nonce NB) \<in> parts (knows Spy evs) -->
wenzelm@61956
   400
          Crypt (shrK B) \<lbrace>Agent A, Agent B, Key K, Nonce NB\<rbrace>
paulson@11251
   401
            \<in> parts (knows Spy evs) -->
paulson@11251
   402
          B \<notin> bad -->
wenzelm@61956
   403
          (\<exists>X. Says A B \<lbrace>X, Crypt K (Nonce NB)\<rbrace> \<in> set evs)"
paulson@11251
   404
apply (erule yahalom.induct, force,
paulson@11251
   405
       frule_tac [6] YM4_parts_knows_Spy)
paulson@11251
   406
apply (analz_mono_contra, simp_all)
wenzelm@61830
   407
txt\<open>Fake\<close>
paulson@11251
   408
apply blast
wenzelm@61830
   409
txt\<open>YM3: by \<open>new_keys_not_used\<close>, the message
wenzelm@61830
   410
   @{term "Crypt K (Nonce NB)"} could not exist\<close>
paulson@11251
   411
apply (force dest!: Crypt_imp_keysFor)
wenzelm@61830
   412
txt\<open>YM4: was   @{term "Crypt K (Nonce NB)"} the very last message?  If so, 
wenzelm@61830
   413
    apply unicity of session keys; if not, use the induction hypothesis\<close>
paulson@14207
   414
apply (blast dest!: B_trusts_YM4_shrK dest: secure_unique_session_keys)
paulson@11251
   415
done
paulson@11251
   416
paulson@11251
   417
wenzelm@61830
   418
text\<open>If B receives YM4 then A has used nonce NB (and therefore is alive).
paulson@11251
   419
  Moreover, A associates K with NB (thus is talking about the same run).
wenzelm@61830
   420
  Other premises guarantee secrecy of K.\<close>
paulson@13907
   421
theorem YM4_imp_A_Said_YM3 [rule_format]:
wenzelm@61956
   422
     "[| Gets B \<lbrace>Crypt (shrK B) \<lbrace>Agent A, Agent B, Key K, Nonce NB\<rbrace>,
wenzelm@61956
   423
                  Crypt K (Nonce NB)\<rbrace> \<in> set evs;
wenzelm@61956
   424
         (\<forall>NA. Notes Spy \<lbrace>Nonce NA, Nonce NB, Key K\<rbrace> \<notin> set evs);
paulson@14207
   425
         K \<in> symKeys;  A \<notin> bad;  B \<notin> bad;  evs \<in> yahalom |]
wenzelm@61956
   426
      ==> \<exists>X. Says A B \<lbrace>X, Crypt K (Nonce NB)\<rbrace> \<in> set evs"
paulson@11251
   427
by (blast intro: Auth_A_to_B_lemma
paulson@11251
   428
          dest: Spy_not_see_encrypted_key B_trusts_YM4_shrK)
paulson@2111
   429
paulson@2111
   430
end