src/HOL/Auth/OtwayRees_AN.thy
author huffman
Sat Jun 06 09:11:12 2009 -0700 (2009-06-06)
changeset 31488 5691ccb8d6b5
parent 23746 a455e69c31cc
child 32366 b269b56b6a14
permissions -rw-r--r--
generalize tendsto to class topological_space
paulson@2090
     1
(*  Title:      HOL/Auth/OtwayRees
paulson@2090
     2
    ID:         $Id$
paulson@2090
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@2090
     4
    Copyright   1996  University of Cambridge
paulson@14207
     5
*)
paulson@2090
     6
paulson@14207
     7
header{*The Otway-Rees Protocol as Modified by Abadi and Needham*}
paulson@2090
     8
haftmann@16417
     9
theory OtwayRees_AN imports Public begin
paulson@14207
    10
paulson@14207
    11
text{*
paulson@14207
    12
This simplified version has minimal encryption and explicit messages.
paulson@2090
    13
paulson@2516
    14
Note that the formalization does not even assume that nonces are fresh.
paulson@2516
    15
This is because the protocol does not rely on uniqueness of nonces for
paulson@2516
    16
security, only for freshness, and the proof script does not prove freshness
paulson@2516
    17
properties.
paulson@2516
    18
paulson@2090
    19
From page 11 of
paulson@14207
    20
  Abadi and Needham (1996).  
paulson@14207
    21
  Prudent Engineering Practice for Cryptographic Protocols.
paulson@14207
    22
  IEEE Trans. SE 22 (1)
paulson@14207
    23
*}
paulson@2090
    24
berghofe@23746
    25
inductive_set otway :: "event list set"
berghofe@23746
    26
  where
paulson@14238
    27
   Nil: --{*The empty trace*}
paulson@14238
    28
        "[] \<in> otway"
paulson@2090
    29
berghofe@23746
    30
 | Fake: --{*The Spy may say anything he can say.  The sender field is correct,
paulson@14238
    31
            but agents don't use that information.*}
paulson@14238
    32
         "[| evsf \<in> otway;  X \<in> synth (analz (knows Spy evsf)) |]
paulson@11251
    33
          ==> Says Spy B X  # evsf \<in> otway"
paulson@2090
    34
paulson@14238
    35
        
berghofe@23746
    36
 | Reception: --{*A message that has been sent can be received by the
paulson@14238
    37
                  intended recipient.*}
paulson@14238
    38
	      "[| evsr \<in> otway;  Says A B X \<in>set evsr |]
paulson@11251
    39
               ==> Gets B X # evsr \<in> otway"
paulson@6308
    40
berghofe@23746
    41
 | OR1:  --{*Alice initiates a protocol run*}
paulson@14238
    42
         "evs1 \<in> otway
paulson@11251
    43
          ==> Says A B {|Agent A, Agent B, Nonce NA|} # evs1 \<in> otway"
paulson@2090
    44
berghofe@23746
    45
 | OR2:  --{*Bob's response to Alice's message.*}
paulson@14238
    46
	 "[| evs2 \<in> otway;
paulson@11251
    47
             Gets B {|Agent A, Agent B, Nonce NA|} \<in>set evs2 |]
paulson@2516
    48
          ==> Says B Server {|Agent A, Agent B, Nonce NA, Nonce NB|}
paulson@11251
    49
                 # evs2 \<in> otway"
paulson@2090
    50
berghofe@23746
    51
 | OR3:  --{*The Server receives Bob's message.  Then he sends a new
paulson@14238
    52
           session key to Bob with a packet for forwarding to Alice.*}
paulson@14238
    53
	 "[| evs3 \<in> otway;  Key KAB \<notin> used evs3;
paulson@6308
    54
             Gets Server {|Agent A, Agent B, Nonce NA, Nonce NB|}
paulson@11251
    55
               \<in>set evs3 |]
paulson@11251
    56
          ==> Says Server B
paulson@2516
    57
               {|Crypt (shrK A) {|Nonce NA, Agent A, Agent B, Key KAB|},
paulson@2516
    58
                 Crypt (shrK B) {|Nonce NB, Agent A, Agent B, Key KAB|}|}
paulson@11251
    59
              # evs3 \<in> otway"
paulson@2090
    60
berghofe@23746
    61
 | OR4:  --{*Bob receives the Server's (?) message and compares the Nonces with
paulson@14238
    62
	     those in the message he previously sent the Server.
paulson@14238
    63
             Need @{term "B \<noteq> Server"} because we allow messages to self.*}
paulson@14238
    64
	 "[| evs4 \<in> otway;  B \<noteq> Server;
paulson@11251
    65
             Says B Server {|Agent A, Agent B, Nonce NA, Nonce NB|} \<in>set evs4;
paulson@6308
    66
             Gets B {|X, Crypt(shrK B){|Nonce NB,Agent A,Agent B,Key K|}|}
paulson@11251
    67
               \<in>set evs4 |]
paulson@11251
    68
          ==> Says B A X # evs4 \<in> otway"
paulson@2090
    69
berghofe@23746
    70
 | Oops: --{*This message models possible leaks of session keys.  The nonces
paulson@14238
    71
             identify the protocol run.*}
paulson@14238
    72
	 "[| evso \<in> otway;
paulson@11251
    73
             Says Server B
paulson@11251
    74
                      {|Crypt (shrK A) {|Nonce NA, Agent A, Agent B, Key K|},
paulson@2284
    75
                        Crypt (shrK B) {|Nonce NB, Agent A, Agent B, Key K|}|}
paulson@11251
    76
               \<in>set evso |]
paulson@11251
    77
          ==> Notes Spy {|Nonce NA, Nonce NB, Key K|} # evso \<in> otway"
paulson@11251
    78
paulson@11251
    79
paulson@11251
    80
declare Says_imp_knows_Spy [THEN analz.Inj, dest]
paulson@11251
    81
declare parts.Body  [dest]
paulson@11251
    82
declare analz_into_parts [dest]
paulson@11251
    83
declare Fake_parts_insert_in_Un  [dest]
paulson@11251
    84
paulson@11251
    85
paulson@14238
    86
text{*A "possibility property": there are traces that reach the end*}
paulson@14200
    87
lemma "[| B \<noteq> Server; Key K \<notin> used [] |]
paulson@14200
    88
      ==> \<exists>evs \<in> otway.
paulson@11251
    89
           Says B A (Crypt (shrK A) {|Nonce NA, Agent A, Agent B, Key K|})
paulson@11251
    90
             \<in> set evs"
paulson@11251
    91
apply (intro exI bexI)
paulson@11251
    92
apply (rule_tac [2] otway.Nil
paulson@11251
    93
                    [THEN otway.OR1, THEN otway.Reception,
paulson@11251
    94
                     THEN otway.OR2, THEN otway.Reception,
paulson@14200
    95
                     THEN otway.OR3, THEN otway.Reception, THEN otway.OR4])
paulson@14200
    96
apply (possibility, simp add: used_Cons) 
paulson@11251
    97
done
paulson@11251
    98
paulson@11251
    99
lemma Gets_imp_Says [dest!]:
paulson@11251
   100
     "[| Gets B X \<in> set evs; evs \<in> otway |] ==> \<exists>A. Says A B X \<in> set evs"
paulson@11251
   101
by (erule rev_mp, erule otway.induct, auto)
paulson@11251
   102
paulson@11251
   103
paulson@11251
   104
paulson@14238
   105
text{* For reasoning about the encrypted portion of messages *}
paulson@11251
   106
paulson@11251
   107
lemma OR4_analz_knows_Spy:
paulson@11251
   108
     "[| Gets B {|X, Crypt(shrK B) X'|} \<in> set evs;  evs \<in> otway |]
paulson@11251
   109
      ==> X \<in> analz (knows Spy evs)"
paulson@11251
   110
by blast
paulson@11251
   111
paulson@11251
   112
paulson@14238
   113
text{*Theorems of the form @{term "X \<notin> parts (spies evs)"} imply that
paulson@14238
   114
NOBODY sends messages containing X! *}
paulson@11251
   115
paulson@14238
   116
text{*Spy never sees a good agent's shared key!*}
paulson@11251
   117
lemma Spy_see_shrK [simp]:
paulson@11251
   118
     "evs \<in> otway ==> (Key (shrK A) \<in> parts (knows Spy evs)) = (A \<in> bad)"
paulson@14238
   119
by (erule otway.induct, simp_all, blast+)
paulson@11251
   120
paulson@11251
   121
lemma Spy_analz_shrK [simp]:
paulson@11251
   122
     "evs \<in> otway ==> (Key (shrK A) \<in> analz (knows Spy evs)) = (A \<in> bad)"
paulson@11251
   123
by auto
paulson@11251
   124
paulson@11251
   125
lemma Spy_see_shrK_D [dest!]:
paulson@11251
   126
     "[|Key (shrK A) \<in> parts (knows Spy evs);  evs \<in> otway|] ==> A \<in> bad"
paulson@11251
   127
by (blast dest: Spy_see_shrK)
paulson@11251
   128
paulson@11251
   129
paulson@14238
   130
subsection{*Proofs involving analz *}
paulson@11251
   131
paulson@14238
   132
text{*Describes the form of K and NA when the Server sends this message.*}
paulson@11251
   133
lemma Says_Server_message_form:
paulson@11251
   134
     "[| Says Server B
paulson@11251
   135
            {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251
   136
              Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   137
           \<in> set evs;
paulson@11251
   138
         evs \<in> otway |]
paulson@11251
   139
      ==> K \<notin> range shrK & (\<exists>i. NA = Nonce i) & (\<exists>j. NB = Nonce j)"
paulson@11251
   140
apply (erule rev_mp)
paulson@14207
   141
apply (erule otway.induct, auto)
paulson@11251
   142
done
paulson@11251
   143
paulson@11251
   144
paulson@11251
   145
paulson@11251
   146
(****
paulson@11251
   147
 The following is to prove theorems of the form
paulson@11251
   148
paulson@11251
   149
  Key K \<in> analz (insert (Key KAB) (knows Spy evs)) ==>
paulson@11251
   150
  Key K \<in> analz (knows Spy evs)
paulson@11251
   151
paulson@11251
   152
 A more general formula must be proved inductively.
paulson@11251
   153
****)
paulson@11251
   154
paulson@11251
   155
paulson@14238
   156
text{* Session keys are not used to encrypt other session keys *}
paulson@11251
   157
paulson@14238
   158
text{*The equality makes the induction hypothesis easier to apply*}
paulson@11251
   159
lemma analz_image_freshK [rule_format]:
paulson@11251
   160
 "evs \<in> otway ==>
paulson@11251
   161
   \<forall>K KK. KK <= -(range shrK) -->
paulson@11251
   162
          (Key K \<in> analz (Key`KK Un (knows Spy evs))) =
paulson@11251
   163
          (K \<in> KK | Key K \<in> analz (knows Spy evs))"
paulson@14207
   164
apply (erule otway.induct) 
paulson@14207
   165
apply (frule_tac [8] Says_Server_message_form)
paulson@14207
   166
apply (drule_tac [7] OR4_analz_knows_Spy, analz_freshK, spy_analz, auto) 
paulson@11251
   167
done
paulson@11251
   168
paulson@11251
   169
lemma analz_insert_freshK:
paulson@11251
   170
  "[| evs \<in> otway;  KAB \<notin> range shrK |] ==>
wenzelm@11655
   171
      (Key K \<in> analz (insert (Key KAB) (knows Spy evs))) =
paulson@11251
   172
      (K = KAB | Key K \<in> analz (knows Spy evs))"
paulson@11251
   173
by (simp only: analz_image_freshK analz_image_freshK_simps)
paulson@11251
   174
paulson@11251
   175
paulson@14238
   176
text{*The Key K uniquely identifies the Server's message.*}
paulson@11251
   177
lemma unique_session_keys:
paulson@11251
   178
     "[| Says Server B
paulson@11251
   179
          {|Crypt (shrK A) {|NA, Agent A, Agent B, K|},
paulson@11251
   180
            Crypt (shrK B) {|NB, Agent A, Agent B, K|}|}
paulson@11251
   181
         \<in> set evs;
paulson@11251
   182
        Says Server B'
paulson@11251
   183
          {|Crypt (shrK A') {|NA', Agent A', Agent B', K|},
paulson@11251
   184
            Crypt (shrK B') {|NB', Agent A', Agent B', K|}|}
paulson@11251
   185
         \<in> set evs;
paulson@11251
   186
        evs \<in> otway |]
paulson@11251
   187
     ==> A=A' & B=B' & NA=NA' & NB=NB'"
paulson@13507
   188
apply (erule rev_mp, erule rev_mp, erule otway.induct, simp_all)
paulson@14238
   189
apply blast+  --{*OR3 and OR4*}
paulson@11251
   190
done
paulson@11251
   191
paulson@11251
   192
paulson@14238
   193
subsection{*Authenticity properties relating to NA*}
paulson@11251
   194
paulson@14238
   195
text{*If the encrypted message appears then it originated with the Server!*}
paulson@11251
   196
lemma NA_Crypt_imp_Server_msg [rule_format]:
paulson@11251
   197
    "[| A \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251
   198
     ==> Crypt (shrK A) {|NA, Agent A, Agent B, Key K|} \<in> parts (knows Spy evs)
paulson@11251
   199
       --> (\<exists>NB. Says Server B
paulson@11251
   200
                    {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251
   201
                      Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   202
                    \<in> set evs)"
paulson@11251
   203
apply (erule otway.induct, force)
paulson@11251
   204
apply (simp_all add: ex_disj_distrib)
paulson@14238
   205
apply blast+  --{*Fake, OR3*}
paulson@11251
   206
done
paulson@11251
   207
paulson@11251
   208
paulson@14238
   209
text{*Corollary: if A receives B's OR4 message then it originated with the
paulson@14238
   210
      Server. Freshness may be inferred from nonce NA.*}
paulson@11251
   211
lemma A_trusts_OR4:
paulson@11251
   212
     "[| Says B' A (Crypt (shrK A) {|NA, Agent A, Agent B, Key K|}) \<in> set evs;
paulson@11251
   213
         A \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251
   214
      ==> \<exists>NB. Says Server B
paulson@11251
   215
                  {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251
   216
                    Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   217
                 \<in> set evs"
paulson@11251
   218
by (blast intro!: NA_Crypt_imp_Server_msg)
paulson@11251
   219
paulson@11251
   220
paulson@14238
   221
text{*Crucial secrecy property: Spy does not see the keys sent in msg OR3
paulson@11251
   222
    Does not in itself guarantee security: an attack could violate
paulson@14238
   223
    the premises, e.g. by having @{term "A=Spy"}*}
paulson@11251
   224
lemma secrecy_lemma:
paulson@11251
   225
     "[| A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@11251
   226
      ==> Says Server B
paulson@11251
   227
           {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251
   228
             Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   229
          \<in> set evs -->
paulson@11251
   230
          Notes Spy {|NA, NB, Key K|} \<notin> set evs -->
paulson@11251
   231
          Key K \<notin> analz (knows Spy evs)"
paulson@11251
   232
apply (erule otway.induct, force)
paulson@11251
   233
apply (frule_tac [7] Says_Server_message_form)
paulson@11251
   234
apply (drule_tac [6] OR4_analz_knows_Spy)
paulson@14238
   235
apply (simp_all add: analz_insert_eq analz_insert_freshK pushes)
paulson@14238
   236
apply spy_analz  --{*Fake*}
paulson@14238
   237
apply (blast dest: unique_session_keys)+  --{*OR3, OR4, Oops*}
paulson@11251
   238
done
paulson@11251
   239
paulson@11251
   240
paulson@11251
   241
lemma Spy_not_see_encrypted_key:
paulson@11251
   242
     "[| Says Server B
paulson@11251
   243
            {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251
   244
              Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   245
           \<in> set evs;
paulson@11251
   246
         Notes Spy {|NA, NB, Key K|} \<notin> set evs;
paulson@11251
   247
         A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@11251
   248
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   249
by (blast dest: Says_Server_message_form secrecy_lemma)
paulson@11251
   250
paulson@11251
   251
paulson@14238
   252
text{*A's guarantee.  The Oops premise quantifies over NB because A cannot know
paulson@14238
   253
  what it is.*}
paulson@11251
   254
lemma A_gets_good_key:
paulson@11251
   255
     "[| Says B' A (Crypt (shrK A) {|NA, Agent A, Agent B, Key K|}) \<in> set evs;
paulson@11251
   256
         \<forall>NB. Notes Spy {|NA, NB, Key K|} \<notin> set evs;
paulson@11251
   257
         A \<notin> bad;  B \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251
   258
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   259
by (blast dest!: A_trusts_OR4 Spy_not_see_encrypted_key)
paulson@11251
   260
paulson@11251
   261
paulson@11251
   262
paulson@14238
   263
subsection{*Authenticity properties relating to NB*}
paulson@11251
   264
paulson@14238
   265
text{*If the encrypted message appears then it originated with the Server!*}
paulson@11251
   266
lemma NB_Crypt_imp_Server_msg [rule_format]:
paulson@11251
   267
 "[| B \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251
   268
  ==> Crypt (shrK B) {|NB, Agent A, Agent B, Key K|} \<in> parts (knows Spy evs)
paulson@11251
   269
      --> (\<exists>NA. Says Server B
paulson@11251
   270
                   {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251
   271
                     Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   272
                   \<in> set evs)"
paulson@11251
   273
apply (erule otway.induct, force, simp_all add: ex_disj_distrib)
paulson@14238
   274
apply blast+  --{*Fake, OR3*}
paulson@11251
   275
done
paulson@11251
   276
paulson@11251
   277
paulson@11251
   278
paulson@14238
   279
text{*Guarantee for B: if it gets a well-formed certificate then the Server
paulson@14238
   280
  has sent the correct message in round 3.*}
paulson@11251
   281
lemma B_trusts_OR3:
paulson@11251
   282
     "[| Says S B {|X, Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   283
           \<in> set evs;
paulson@11251
   284
         B \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251
   285
      ==> \<exists>NA. Says Server B
paulson@11251
   286
                   {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251
   287
                     Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   288
                   \<in> set evs"
paulson@11251
   289
by (blast intro!: NB_Crypt_imp_Server_msg)
paulson@11251
   290
paulson@11251
   291
paulson@14238
   292
text{*The obvious combination of @{text B_trusts_OR3} with 
paulson@14238
   293
      @{text Spy_not_see_encrypted_key}*}
paulson@11251
   294
lemma B_gets_good_key:
paulson@11251
   295
     "[| Gets B {|X, Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   296
          \<in> set evs;
paulson@11251
   297
         \<forall>NA. Notes Spy {|NA, NB, Key K|} \<notin> set evs;
paulson@11251
   298
         A \<notin> bad;  B \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251
   299
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   300
by (blast dest: B_trusts_OR3 Spy_not_see_encrypted_key)
paulson@2090
   301
paulson@2090
   302
end