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