src/HOL/Auth/OtwayRees.thy
author haftmann
Fri Jan 02 08:12:46 2009 +0100 (2009-01-02)
changeset 29332 edc1e2a56398
parent 23746 a455e69c31cc
child 32960 69916a850301
permissions -rw-r--r--
named code theorem for Fract_norm
paulson@11251
     1
(*  Title:      HOL/Auth/OtwayRees
paulson@11251
     2
    ID:         $Id$
paulson@11251
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@11251
     4
    Copyright   1996  University of Cambridge
paulson@1941
     5
*)
paulson@1941
     6
paulson@14207
     7
header{*The Original Otway-Rees Protocol*}
paulson@14207
     8
haftmann@16417
     9
theory OtwayRees imports Public begin
paulson@13907
    10
paulson@14207
    11
text{* From page 244 of
paulson@14207
    12
  Burrows, Abadi and Needham (1989).  A Logic of Authentication.
paulson@14207
    13
  Proc. Royal Soc. 426
paulson@1941
    14
paulson@14207
    15
This is the original version, which encrypts Nonce NB.*}
paulson@6308
    16
berghofe@23746
    17
inductive_set otway :: "event list set"
berghofe@23746
    18
  where
paulson@1941
    19
         (*Initial trace is empty*)
paulson@11251
    20
   Nil:  "[] \<in> otway"
paulson@5434
    21
paulson@2032
    22
         (*The spy MAY say anything he CAN say.  We do not expect him to
paulson@1941
    23
           invent new nonces here, but he can also use NS1.  Common to
paulson@1941
    24
           all similar protocols.*)
berghofe@23746
    25
 | Fake: "[| evsf \<in> otway;  X \<in> synth (analz (knows Spy evsf)) |]
paulson@11251
    26
          ==> Says Spy B X  # evsf \<in> otway"
paulson@6308
    27
paulson@6308
    28
         (*A message that has been sent can be received by the
paulson@6308
    29
           intended recipient.*)
berghofe@23746
    30
 | Reception: "[| evsr \<in> otway;  Says A B X \<in>set evsr |]
paulson@11251
    31
               ==> Gets B X # evsr \<in> otway"
paulson@1941
    32
paulson@1941
    33
         (*Alice initiates a protocol run*)
berghofe@23746
    34
 | OR1:  "[| evs1 \<in> otway;  Nonce NA \<notin> used evs1 |]
paulson@11251
    35
          ==> Says A B {|Nonce NA, Agent A, Agent B,
paulson@11251
    36
                         Crypt (shrK A) {|Nonce NA, Agent A, Agent B|} |}
paulson@3659
    37
                 # evs1 : otway"
paulson@1941
    38
paulson@6333
    39
         (*Bob's response to Alice's message.  Note that NB is encrypted.*)
berghofe@23746
    40
 | OR2:  "[| evs2 \<in> otway;  Nonce NB \<notin> used evs2;
paulson@6308
    41
             Gets B {|Nonce NA, Agent A, Agent B, X|} : set evs2 |]
paulson@11251
    42
          ==> Says B Server
paulson@11251
    43
                  {|Nonce NA, Agent A, Agent B, X,
paulson@2451
    44
                    Crypt (shrK B)
paulson@2516
    45
                      {|Nonce NA, Nonce NB, Agent A, Agent B|}|}
paulson@3659
    46
                 # evs2 : otway"
paulson@1941
    47
paulson@1941
    48
         (*The Server receives Bob's message and checks that the three NAs
paulson@1941
    49
           match.  Then he sends a new session key to Bob with a packet for
paulson@1941
    50
           forwarding to Alice.*)
berghofe@23746
    51
 | OR3:  "[| evs3 \<in> otway;  Key KAB \<notin> used evs3;
paulson@11251
    52
             Gets Server
paulson@11251
    53
                  {|Nonce NA, Agent A, Agent B,
paulson@11251
    54
                    Crypt (shrK A) {|Nonce NA, Agent A, Agent B|},
paulson@2284
    55
                    Crypt (shrK B) {|Nonce NA, Nonce NB, Agent A, Agent B|}|}
paulson@3659
    56
               : set evs3 |]
paulson@11251
    57
          ==> Says Server B
paulson@11251
    58
                  {|Nonce NA,
paulson@2516
    59
                    Crypt (shrK A) {|Nonce NA, Key KAB|},
paulson@2516
    60
                    Crypt (shrK B) {|Nonce NB, Key KAB|}|}
paulson@3659
    61
                 # evs3 : otway"
paulson@1941
    62
paulson@1941
    63
         (*Bob receives the Server's (?) message and compares the Nonces with
paulson@5434
    64
	   those in the message he previously sent the Server.
paulson@11251
    65
           Need B \<noteq> Server because we allow messages to self.*)
berghofe@23746
    66
 | OR4:  "[| evs4 \<in> otway;  B \<noteq> Server;
paulson@11251
    67
             Says B Server {|Nonce NA, Agent A, Agent B, X',
paulson@2284
    68
                             Crypt (shrK B)
paulson@2284
    69
                                   {|Nonce NA, Nonce NB, Agent A, Agent B|}|}
paulson@3659
    70
               : set evs4;
paulson@6308
    71
             Gets B {|Nonce NA, X, Crypt (shrK B) {|Nonce NB, Key K|}|}
paulson@3659
    72
               : set evs4 |]
paulson@3659
    73
          ==> Says B A {|Nonce NA, X|} # evs4 : otway"
paulson@1941
    74
paulson@2135
    75
         (*This message models possible leaks of session keys.  The nonces
paulson@2135
    76
           identify the protocol run.*)
berghofe@23746
    77
 | Oops: "[| evso \<in> otway;
paulson@2284
    78
             Says Server B {|Nonce NA, X, Crypt (shrK B) {|Nonce NB, Key K|}|}
paulson@3659
    79
               : set evso |]
paulson@4537
    80
          ==> Notes Spy {|Nonce NA, Nonce NB, Key K|} # evso : otway"
paulson@1941
    81
paulson@11251
    82
paulson@18570
    83
declare Says_imp_analz_Spy [dest]
paulson@11251
    84
declare parts.Body  [dest]
paulson@11251
    85
declare analz_into_parts [dest]
paulson@11251
    86
declare Fake_parts_insert_in_Un  [dest]
paulson@11251
    87
paulson@11251
    88
paulson@13907
    89
text{*A "possibility property": there are traces that reach the end*}
paulson@14200
    90
lemma "[| B \<noteq> Server; Key K \<notin> used [] |]
paulson@14200
    91
      ==> \<exists>evs \<in> otway.
paulson@11251
    92
             Says B A {|Nonce NA, Crypt (shrK A) {|Nonce NA, Key K|}|}
paulson@11251
    93
               \<in> set evs"
paulson@11251
    94
apply (intro exI bexI)
paulson@11251
    95
apply (rule_tac [2] otway.Nil
paulson@11251
    96
                    [THEN otway.OR1, THEN otway.Reception,
paulson@11251
    97
                     THEN otway.OR2, THEN otway.Reception,
paulson@14200
    98
                     THEN otway.OR3, THEN otway.Reception, THEN otway.OR4]) 
paulson@14200
    99
apply (possibility, simp add: used_Cons) 
paulson@11251
   100
done
paulson@11251
   101
paulson@11251
   102
lemma Gets_imp_Says [dest!]:
paulson@11251
   103
     "[| Gets B X \<in> set evs; evs \<in> otway |] ==> \<exists>A. Says A B X \<in> set evs"
paulson@11251
   104
apply (erule rev_mp)
paulson@13507
   105
apply (erule otway.induct, auto)
paulson@11251
   106
done
paulson@11251
   107
paulson@11251
   108
paulson@11251
   109
(** For reasoning about the encrypted portion of messages **)
paulson@11251
   110
paulson@11251
   111
lemma OR2_analz_knows_Spy:
paulson@11251
   112
     "[| Gets B {|N, Agent A, Agent B, X|} \<in> set evs;  evs \<in> otway |]
paulson@11251
   113
      ==> X \<in> analz (knows Spy evs)"
paulson@11251
   114
by blast
paulson@11251
   115
paulson@11251
   116
lemma OR4_analz_knows_Spy:
paulson@11251
   117
     "[| Gets B {|N, X, Crypt (shrK B) X'|} \<in> set evs;  evs \<in> otway |]
paulson@11251
   118
      ==> X \<in> analz (knows Spy evs)"
paulson@11251
   119
by blast
paulson@11251
   120
paulson@11251
   121
(*These lemmas assist simplification by removing forwarded X-variables.
paulson@11251
   122
  We can replace them by rewriting with parts_insert2 and proving using
paulson@11251
   123
  dest: parts_cut, but the proofs become more difficult.*)
paulson@11251
   124
lemmas OR2_parts_knows_Spy =
paulson@11251
   125
    OR2_analz_knows_Spy [THEN analz_into_parts, standard]
paulson@11251
   126
paulson@11251
   127
(*There could be OR4_parts_knows_Spy and Oops_parts_knows_Spy, but for
paulson@11251
   128
  some reason proofs work without them!*)
paulson@11251
   129
paulson@11251
   130
paulson@14225
   131
text{*Theorems of the form @{term "X \<notin> parts (spies evs)"} imply that
paulson@14225
   132
NOBODY sends messages containing X! *}
paulson@11251
   133
paulson@14225
   134
text{*Spy never sees a good agent's shared key!*}
paulson@11251
   135
lemma Spy_see_shrK [simp]:
paulson@11251
   136
     "evs \<in> otway ==> (Key (shrK A) \<in> parts (knows Spy evs)) = (A \<in> bad)"
paulson@13907
   137
by (erule otway.induct, force,
paulson@13907
   138
    drule_tac [4] OR2_parts_knows_Spy, simp_all, blast+)
paulson@13907
   139
paulson@11251
   140
paulson@11251
   141
lemma Spy_analz_shrK [simp]:
paulson@11251
   142
     "evs \<in> otway ==> (Key (shrK A) \<in> analz (knows Spy evs)) = (A \<in> bad)"
paulson@11251
   143
by auto
paulson@11251
   144
paulson@11251
   145
lemma Spy_see_shrK_D [dest!]:
paulson@11251
   146
     "[|Key (shrK A) \<in> parts (knows Spy evs);  evs \<in> otway|] ==> A \<in> bad"
paulson@11251
   147
by (blast dest: Spy_see_shrK)
paulson@11251
   148
paulson@11251
   149
paulson@13907
   150
subsection{*Towards Secrecy: Proofs Involving @{term analz}*}
paulson@11251
   151
paulson@11251
   152
(*Describes the form of K and NA when the Server sends this message.  Also
paulson@11251
   153
  for Oops case.*)
paulson@11251
   154
lemma Says_Server_message_form:
paulson@11251
   155
     "[| Says Server B {|NA, X, Crypt (shrK B) {|NB, Key K|}|} \<in> set evs;
paulson@11251
   156
         evs \<in> otway |]
paulson@11251
   157
      ==> K \<notin> range shrK & (\<exists>i. NA = Nonce i) & (\<exists>j. NB = Nonce j)"
nipkow@17778
   158
by (erule rev_mp, erule otway.induct, simp_all)
paulson@11251
   159
paulson@11251
   160
paulson@11251
   161
(****
paulson@11251
   162
 The following is to prove theorems of the form
paulson@11251
   163
paulson@11251
   164
  Key K \<in> analz (insert (Key KAB) (knows Spy evs)) ==>
paulson@11251
   165
  Key K \<in> analz (knows Spy evs)
paulson@11251
   166
paulson@11251
   167
 A more general formula must be proved inductively.
paulson@11251
   168
****)
paulson@11251
   169
paulson@11251
   170
paulson@13907
   171
text{*Session keys are not used to encrypt other session keys*}
paulson@11251
   172
paulson@14225
   173
text{*The equality makes the induction hypothesis easier to apply*}
paulson@11251
   174
lemma analz_image_freshK [rule_format]:
paulson@11251
   175
 "evs \<in> otway ==>
paulson@11251
   176
   \<forall>K KK. KK <= -(range shrK) -->
paulson@11251
   177
          (Key K \<in> analz (Key`KK Un (knows Spy evs))) =
paulson@11251
   178
          (K \<in> KK | Key K \<in> analz (knows Spy evs))"
paulson@14207
   179
apply (erule otway.induct)
paulson@14207
   180
apply (frule_tac [8] Says_Server_message_form)
paulson@14207
   181
apply (drule_tac [7] OR4_analz_knows_Spy)
paulson@14207
   182
apply (drule_tac [5] OR2_analz_knows_Spy, analz_freshK, spy_analz, auto) 
paulson@11251
   183
done
paulson@11251
   184
paulson@11251
   185
lemma analz_insert_freshK:
paulson@11251
   186
  "[| evs \<in> otway;  KAB \<notin> range shrK |] ==>
wenzelm@11655
   187
      (Key K \<in> analz (insert (Key KAB) (knows Spy evs))) =
paulson@11251
   188
      (K = KAB | Key K \<in> analz (knows Spy evs))"
paulson@11251
   189
by (simp only: analz_image_freshK analz_image_freshK_simps)
paulson@11251
   190
paulson@11251
   191
paulson@14225
   192
text{*The Key K uniquely identifies the Server's  message. *}
paulson@11251
   193
lemma unique_session_keys:
paulson@11251
   194
     "[| Says Server B {|NA, X, Crypt (shrK B) {|NB, K|}|}   \<in> set evs;
paulson@11251
   195
         Says Server B' {|NA',X',Crypt (shrK B') {|NB',K|}|} \<in> set evs;
paulson@11251
   196
         evs \<in> otway |] ==> X=X' & B=B' & NA=NA' & NB=NB'"
paulson@11251
   197
apply (erule rev_mp)
paulson@11251
   198
apply (erule rev_mp)
paulson@11251
   199
apply (erule otway.induct, simp_all)
paulson@14225
   200
apply blast+  --{*OR3 and OR4*}
paulson@11251
   201
done
paulson@11251
   202
paulson@11251
   203
paulson@13907
   204
subsection{*Authenticity properties relating to NA*}
paulson@11251
   205
paulson@14225
   206
text{*Only OR1 can have caused such a part of a message to appear.*}
paulson@11251
   207
lemma Crypt_imp_OR1 [rule_format]:
paulson@11251
   208
 "[| A \<notin> bad;  evs \<in> otway |]
paulson@11251
   209
  ==> Crypt (shrK A) {|NA, Agent A, Agent B|} \<in> parts (knows Spy evs) -->
paulson@11251
   210
      Says A B {|NA, Agent A, Agent B,
paulson@11251
   211
                 Crypt (shrK A) {|NA, Agent A, Agent B|}|}
paulson@11251
   212
        \<in> set evs"
paulson@14225
   213
by (erule otway.induct, force,
paulson@14225
   214
    drule_tac [4] OR2_parts_knows_Spy, simp_all, blast+)
paulson@11251
   215
paulson@11251
   216
lemma Crypt_imp_OR1_Gets:
paulson@11251
   217
     "[| Gets B {|NA, Agent A, Agent B,
paulson@11251
   218
                  Crypt (shrK A) {|NA, Agent A, Agent B|}|} \<in> set evs;
paulson@11251
   219
         A \<notin> bad; evs \<in> otway |]
paulson@11251
   220
       ==> Says A B {|NA, Agent A, Agent B,
paulson@11251
   221
                      Crypt (shrK A) {|NA, Agent A, Agent B|}|}
paulson@11251
   222
             \<in> set evs"
paulson@11251
   223
by (blast dest: Crypt_imp_OR1)
paulson@11251
   224
paulson@11251
   225
paulson@13907
   226
text{*The Nonce NA uniquely identifies A's message*}
paulson@11251
   227
lemma unique_NA:
paulson@11251
   228
     "[| Crypt (shrK A) {|NA, Agent A, Agent B|} \<in> parts (knows Spy evs);
paulson@11251
   229
         Crypt (shrK A) {|NA, Agent A, Agent C|} \<in> parts (knows Spy evs);
paulson@11251
   230
         evs \<in> otway;  A \<notin> bad |]
paulson@11251
   231
      ==> B = C"
paulson@11251
   232
apply (erule rev_mp, erule rev_mp)
paulson@11251
   233
apply (erule otway.induct, force,
paulson@13507
   234
       drule_tac [4] OR2_parts_knows_Spy, simp_all, blast+)
paulson@11251
   235
done
paulson@11251
   236
paulson@11251
   237
paulson@14225
   238
text{*It is impossible to re-use a nonce in both OR1 and OR2.  This holds because
paulson@11251
   239
  OR2 encrypts Nonce NB.  It prevents the attack that can occur in the
wenzelm@17411
   240
  over-simplified version of this protocol: see @{text OtwayRees_Bad}.*}
paulson@11251
   241
lemma no_nonce_OR1_OR2:
paulson@11251
   242
   "[| Crypt (shrK A) {|NA, Agent A, Agent B|} \<in> parts (knows Spy evs);
paulson@11251
   243
       A \<notin> bad;  evs \<in> otway |]
paulson@11251
   244
    ==> Crypt (shrK A) {|NA', NA, Agent A', Agent A|} \<notin> parts (knows Spy evs)"
paulson@11251
   245
apply (erule rev_mp)
paulson@11251
   246
apply (erule otway.induct, force,
paulson@13507
   247
       drule_tac [4] OR2_parts_knows_Spy, simp_all, blast+)
paulson@11251
   248
done
paulson@11251
   249
paulson@14225
   250
text{*Crucial property: If the encrypted message appears, and A has used NA
paulson@14225
   251
  to start a run, then it originated with the Server!*}
paulson@11251
   252
lemma NA_Crypt_imp_Server_msg [rule_format]:
paulson@11251
   253
     "[| A \<notin> bad;  evs \<in> otway |]
paulson@11251
   254
      ==> Says A B {|NA, Agent A, Agent B,
paulson@11251
   255
                     Crypt (shrK A) {|NA, Agent A, Agent B|}|} \<in> set evs -->
paulson@11251
   256
          Crypt (shrK A) {|NA, Key K|} \<in> parts (knows Spy evs)
paulson@11251
   257
          --> (\<exists>NB. Says Server B
paulson@11251
   258
                         {|NA,
paulson@11251
   259
                           Crypt (shrK A) {|NA, Key K|},
paulson@11251
   260
                           Crypt (shrK B) {|NB, Key K|}|} \<in> set evs)"
paulson@11251
   261
apply (erule otway.induct, force,
paulson@13507
   262
       drule_tac [4] OR2_parts_knows_Spy, simp_all, blast)
paulson@14225
   263
apply blast  --{*OR1: by freshness*}
paulson@14225
   264
apply (blast dest!: no_nonce_OR1_OR2 intro: unique_NA)  --{*OR3*}
paulson@14225
   265
apply (blast intro!: Crypt_imp_OR1)  --{*OR4*}
paulson@11251
   266
done
paulson@11251
   267
paulson@11251
   268
paulson@14225
   269
text{*Corollary: if A receives B's OR4 message and the nonce NA agrees
paulson@11251
   270
  then the key really did come from the Server!  CANNOT prove this of the
paulson@11251
   271
  bad form of this protocol, even though we can prove
wenzelm@17411
   272
  @{text Spy_not_see_encrypted_key} *}
paulson@11251
   273
lemma A_trusts_OR4:
paulson@11251
   274
     "[| Says A  B {|NA, Agent A, Agent B,
paulson@11251
   275
                     Crypt (shrK A) {|NA, Agent A, Agent B|}|} \<in> set evs;
paulson@11251
   276
         Says B' A {|NA, Crypt (shrK A) {|NA, Key K|}|} \<in> set evs;
paulson@11251
   277
     A \<notin> bad;  evs \<in> otway |]
paulson@11251
   278
  ==> \<exists>NB. Says Server B
paulson@11251
   279
               {|NA,
paulson@11251
   280
                 Crypt (shrK A) {|NA, Key K|},
paulson@11251
   281
                 Crypt (shrK B) {|NB, Key K|}|}
paulson@11251
   282
                 \<in> set evs"
paulson@11251
   283
by (blast intro!: NA_Crypt_imp_Server_msg)
paulson@11251
   284
paulson@11251
   285
paulson@14225
   286
text{*Crucial secrecy property: Spy does not see the keys sent in msg OR3
paulson@11251
   287
    Does not in itself guarantee security: an attack could violate
paulson@14225
   288
    the premises, e.g. by having @{term "A=Spy"}*}
paulson@11251
   289
lemma secrecy_lemma:
paulson@11251
   290
 "[| A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@11251
   291
  ==> Says Server B
paulson@11251
   292
        {|NA, Crypt (shrK A) {|NA, Key K|},
paulson@11251
   293
          Crypt (shrK B) {|NB, Key K|}|} \<in> set evs -->
paulson@11251
   294
      Notes Spy {|NA, NB, Key K|} \<notin> set evs -->
paulson@11251
   295
      Key K \<notin> analz (knows Spy evs)"
paulson@11251
   296
apply (erule otway.induct, force)
paulson@11251
   297
apply (frule_tac [7] Says_Server_message_form)
paulson@11251
   298
apply (drule_tac [6] OR4_analz_knows_Spy)
paulson@11251
   299
apply (drule_tac [4] OR2_analz_knows_Spy)
paulson@14225
   300
apply (simp_all add: analz_insert_eq analz_insert_freshK pushes)
paulson@14225
   301
apply spy_analz  --{*Fake*}
paulson@14225
   302
apply (blast dest: unique_session_keys)+  --{*OR3, OR4, Oops*}
paulson@11251
   303
done
paulson@11251
   304
paulson@13907
   305
theorem Spy_not_see_encrypted_key:
paulson@11251
   306
     "[| Says Server B
paulson@11251
   307
          {|NA, Crypt (shrK A) {|NA, Key K|},
paulson@11251
   308
                Crypt (shrK B) {|NB, Key K|}|} \<in> set evs;
paulson@11251
   309
         Notes Spy {|NA, NB, Key K|} \<notin> set evs;
paulson@11251
   310
         A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@11251
   311
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   312
by (blast dest: Says_Server_message_form secrecy_lemma)
paulson@11251
   313
paulson@13907
   314
text{*This form is an immediate consequence of the previous result.  It is 
paulson@13907
   315
similar to the assertions established by other methods.  It is equivalent
paulson@13907
   316
to the previous result in that the Spy already has @{term analz} and
paulson@13907
   317
@{term synth} at his disposal.  However, the conclusion 
paulson@13907
   318
@{term "Key K \<notin> knows Spy evs"} appears not to be inductive: all the cases
paulson@13907
   319
other than Fake are trivial, while Fake requires 
paulson@13907
   320
@{term "Key K \<notin> analz (knows Spy evs)"}. *}
paulson@13907
   321
lemma Spy_not_know_encrypted_key:
paulson@13907
   322
     "[| Says Server B
paulson@13907
   323
          {|NA, Crypt (shrK A) {|NA, Key K|},
paulson@13907
   324
                Crypt (shrK B) {|NB, Key K|}|} \<in> set evs;
paulson@13907
   325
         Notes Spy {|NA, NB, Key K|} \<notin> set evs;
paulson@13907
   326
         A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@13907
   327
      ==> Key K \<notin> knows Spy evs"
paulson@13907
   328
by (blast dest: Spy_not_see_encrypted_key)
paulson@13907
   329
paulson@11251
   330
paulson@14225
   331
text{*A's guarantee.  The Oops premise quantifies over NB because A cannot know
paulson@14225
   332
  what it is.*}
paulson@11251
   333
lemma A_gets_good_key:
paulson@11251
   334
     "[| Says A  B {|NA, Agent A, Agent B,
paulson@11251
   335
                     Crypt (shrK A) {|NA, Agent A, Agent B|}|} \<in> set evs;
paulson@11251
   336
         Says B' A {|NA, Crypt (shrK A) {|NA, Key K|}|} \<in> set evs;
paulson@11251
   337
         \<forall>NB. Notes Spy {|NA, NB, Key K|} \<notin> set evs;
paulson@11251
   338
         A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@11251
   339
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   340
by (blast dest!: A_trusts_OR4 Spy_not_see_encrypted_key)
paulson@11251
   341
paulson@11251
   342
paulson@13907
   343
subsection{*Authenticity properties relating to NB*}
paulson@11251
   344
paulson@14225
   345
text{*Only OR2 can have caused such a part of a message to appear.  We do not
paulson@14225
   346
  know anything about X: it does NOT have to have the right form.*}
paulson@11251
   347
lemma Crypt_imp_OR2:
paulson@11251
   348
     "[| Crypt (shrK B) {|NA, NB, Agent A, Agent B|} \<in> parts (knows Spy evs);
paulson@11251
   349
         B \<notin> bad;  evs \<in> otway |]
paulson@11251
   350
      ==> \<exists>X. Says B Server
paulson@11251
   351
                 {|NA, Agent A, Agent B, X,
paulson@11251
   352
                   Crypt (shrK B) {|NA, NB, Agent A, Agent B|}|}
paulson@11251
   353
                 \<in> set evs"
paulson@11251
   354
apply (erule rev_mp)
paulson@11251
   355
apply (erule otway.induct, force,
paulson@13507
   356
       drule_tac [4] OR2_parts_knows_Spy, simp_all, blast+)
paulson@11251
   357
done
paulson@11251
   358
paulson@11251
   359
paulson@13907
   360
text{*The Nonce NB uniquely identifies B's  message*}
paulson@11251
   361
lemma unique_NB:
paulson@11251
   362
     "[| Crypt (shrK B) {|NA, NB, Agent A, Agent B|} \<in> parts(knows Spy evs);
paulson@11251
   363
         Crypt (shrK B) {|NC, NB, Agent C, Agent B|} \<in> parts(knows Spy evs);
paulson@11251
   364
           evs \<in> otway;  B \<notin> bad |]
paulson@11251
   365
         ==> NC = NA & C = A"
paulson@11251
   366
apply (erule rev_mp, erule rev_mp)
paulson@11251
   367
apply (erule otway.induct, force,
paulson@11251
   368
       drule_tac [4] OR2_parts_knows_Spy, simp_all)
paulson@14225
   369
apply blast+  --{*Fake, OR2*}
paulson@11251
   370
done
paulson@11251
   371
paulson@14225
   372
text{*If the encrypted message appears, and B has used Nonce NB,
paulson@14225
   373
  then it originated with the Server!  Quite messy proof.*}
paulson@11251
   374
lemma NB_Crypt_imp_Server_msg [rule_format]:
paulson@11251
   375
 "[| B \<notin> bad;  evs \<in> otway |]
paulson@11251
   376
  ==> Crypt (shrK B) {|NB, Key K|} \<in> parts (knows Spy evs)
paulson@11251
   377
      --> (\<forall>X'. Says B Server
paulson@11251
   378
                     {|NA, Agent A, Agent B, X',
paulson@11251
   379
                       Crypt (shrK B) {|NA, NB, Agent A, Agent B|}|}
paulson@11251
   380
           \<in> set evs
paulson@11251
   381
           --> Says Server B
paulson@11251
   382
                {|NA, Crypt (shrK A) {|NA, Key K|},
paulson@11251
   383
                      Crypt (shrK B) {|NB, Key K|}|}
paulson@11251
   384
                    \<in> set evs)"
paulson@11251
   385
apply simp
paulson@11251
   386
apply (erule otway.induct, force,
paulson@14225
   387
       drule_tac [4] OR2_parts_knows_Spy, simp_all)
paulson@14225
   388
apply blast  --{*Fake*}
paulson@14225
   389
apply blast  --{*OR2*}
paulson@14225
   390
apply (blast dest: unique_NB dest!: no_nonce_OR1_OR2)  --{*OR3*}
paulson@14225
   391
apply (blast dest!: Crypt_imp_OR2)  --{*OR4*}
paulson@11251
   392
done
paulson@11251
   393
paulson@11251
   394
paulson@13907
   395
text{*Guarantee for B: if it gets a message with matching NB then the Server
paulson@13907
   396
  has sent the correct message.*}
paulson@13907
   397
theorem B_trusts_OR3:
paulson@11251
   398
     "[| Says B Server {|NA, Agent A, Agent B, X',
paulson@11251
   399
                         Crypt (shrK B) {|NA, NB, Agent A, Agent B|} |}
paulson@11251
   400
           \<in> set evs;
paulson@11251
   401
         Gets B {|NA, X, Crypt (shrK B) {|NB, Key K|}|} \<in> set evs;
paulson@11251
   402
         B \<notin> bad;  evs \<in> otway |]
paulson@11251
   403
      ==> Says Server B
paulson@11251
   404
               {|NA,
paulson@11251
   405
                 Crypt (shrK A) {|NA, Key K|},
paulson@11251
   406
                 Crypt (shrK B) {|NB, Key K|}|}
paulson@11251
   407
                 \<in> set evs"
paulson@11251
   408
by (blast intro!: NB_Crypt_imp_Server_msg)
paulson@11251
   409
paulson@11251
   410
paulson@14225
   411
text{*The obvious combination of @{text B_trusts_OR3} with 
paulson@14225
   412
      @{text Spy_not_see_encrypted_key}*}
paulson@11251
   413
lemma B_gets_good_key:
paulson@11251
   414
     "[| Says B Server {|NA, Agent A, Agent B, X',
paulson@11251
   415
                         Crypt (shrK B) {|NA, NB, Agent A, Agent B|} |}
paulson@11251
   416
           \<in> set evs;
paulson@11251
   417
         Gets B {|NA, X, Crypt (shrK B) {|NB, Key K|}|} \<in> set evs;
paulson@11251
   418
         Notes Spy {|NA, NB, Key K|} \<notin> set evs;
paulson@11251
   419
         A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@11251
   420
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   421
by (blast dest!: B_trusts_OR3 Spy_not_see_encrypted_key)
paulson@11251
   422
paulson@11251
   423
paulson@11251
   424
lemma OR3_imp_OR2:
paulson@11251
   425
     "[| Says Server B
paulson@11251
   426
              {|NA, Crypt (shrK A) {|NA, Key K|},
paulson@11251
   427
                Crypt (shrK B) {|NB, Key K|}|} \<in> set evs;
paulson@11251
   428
         B \<notin> bad;  evs \<in> otway |]
paulson@11251
   429
  ==> \<exists>X. Says B Server {|NA, Agent A, Agent B, X,
paulson@11251
   430
                            Crypt (shrK B) {|NA, NB, Agent A, Agent B|} |}
paulson@11251
   431
              \<in> set evs"
paulson@11251
   432
apply (erule rev_mp)
paulson@11251
   433
apply (erule otway.induct, simp_all)
paulson@11251
   434
apply (blast dest!: Crypt_imp_OR2)+
paulson@11251
   435
done
paulson@11251
   436
paulson@11251
   437
paulson@13907
   438
text{*After getting and checking OR4, agent A can trust that B has been active.
paulson@11251
   439
  We could probably prove that X has the expected form, but that is not
paulson@13907
   440
  strictly necessary for authentication.*}
paulson@13907
   441
theorem A_auths_B:
paulson@11251
   442
     "[| Says B' A {|NA, Crypt (shrK A) {|NA, Key K|}|} \<in> set evs;
paulson@11251
   443
         Says A  B {|NA, Agent A, Agent B,
paulson@11251
   444
                     Crypt (shrK A) {|NA, Agent A, Agent B|}|} \<in> set evs;
paulson@11251
   445
         A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@11251
   446
  ==> \<exists>NB X. Says B Server {|NA, Agent A, Agent B, X,
paulson@11251
   447
                               Crypt (shrK B)  {|NA, NB, Agent A, Agent B|} |}
paulson@11251
   448
                 \<in> set evs"
paulson@11251
   449
by (blast dest!: A_trusts_OR4 OR3_imp_OR2)
paulson@11251
   450
paulson@1941
   451
end