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