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