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