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