src/HOL/Auth/OtwayRees_Bad.thy
author wenzelm
Mon Jan 11 21:21:02 2016 +0100 (2016-01-11)
changeset 62145 5b946c81dfbf
parent 61956 38b73f7940af
child 67443 3abf6a722518
permissions -rw-r--r--
eliminated old defs;
wenzelm@37936
     1
(*  Title:      HOL/Auth/OtwayRees_Bad.thy
paulson@2002
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@2002
     3
    Copyright   1996  University of Cambridge
paulson@14207
     4
*)
paulson@2002
     5
paulson@14207
     6
wenzelm@61830
     7
section\<open>The Otway-Rees Protocol: The Faulty BAN Version\<close>
paulson@2002
     8
haftmann@16417
     9
theory OtwayRees_Bad imports Public begin
paulson@14207
    10
wenzelm@61830
    11
text\<open>The FAULTY version omitting encryption of Nonce NB, as suggested on 
paulson@14207
    12
page 247 of
paulson@14207
    13
  Burrows, Abadi and Needham (1988).  A Logic of Authentication.
paulson@14207
    14
  Proc. Royal Soc. 426
paulson@11251
    15
paulson@11251
    16
This file illustrates the consequences of such errors.  We can still prove
wenzelm@61830
    17
impressive-looking properties such as \<open>Spy_not_see_encrypted_key\<close>, yet
paulson@14207
    18
the protocol is open to a middleperson attack.  Attempting to prove some key
wenzelm@61830
    19
lemmas indicates the possibility of this attack.\<close>
paulson@2052
    20
berghofe@23746
    21
inductive_set otway :: "event list set"
berghofe@23746
    22
  where
wenzelm@61830
    23
   Nil: \<comment>\<open>The empty trace\<close>
paulson@14225
    24
        "[] \<in> otway"
paulson@2002
    25
wenzelm@61830
    26
 | Fake: \<comment>\<open>The Spy may say anything he can say.  The sender field is correct,
wenzelm@61830
    27
            but agents don't use that information.\<close>
paulson@14225
    28
         "[| evsf \<in> otway;  X \<in> synth (analz (knows Spy evsf)) |]
paulson@11251
    29
          ==> Says Spy B X  # evsf \<in> otway"
paulson@2002
    30
paulson@14225
    31
        
wenzelm@61830
    32
 | Reception: \<comment>\<open>A message that has been sent can be received by the
wenzelm@61830
    33
                  intended recipient.\<close>
wenzelm@32960
    34
              "[| evsr \<in> otway;  Says A B X \<in>set evsr |]
paulson@11251
    35
               ==> Gets B X # evsr \<in> otway"
paulson@6308
    36
wenzelm@61830
    37
 | OR1:  \<comment>\<open>Alice initiates a protocol run\<close>
wenzelm@32960
    38
         "[| evs1 \<in> otway;  Nonce NA \<notin> used evs1 |]
wenzelm@61956
    39
          ==> Says A B \<lbrace>Nonce NA, Agent A, Agent B,
wenzelm@61956
    40
                         Crypt (shrK A) \<lbrace>Nonce NA, Agent A, Agent B\<rbrace>\<rbrace>
paulson@11251
    41
                 # evs1 \<in> otway"
paulson@2002
    42
wenzelm@61830
    43
 | OR2:  \<comment>\<open>Bob's response to Alice's message.
wenzelm@61830
    44
             This variant of the protocol does NOT encrypt NB.\<close>
wenzelm@32960
    45
         "[| evs2 \<in> otway;  Nonce NB \<notin> used evs2;
wenzelm@61956
    46
             Gets B \<lbrace>Nonce NA, Agent A, Agent B, X\<rbrace> \<in> set evs2 |]
paulson@11251
    47
          ==> Says B Server
wenzelm@61956
    48
                  \<lbrace>Nonce NA, Agent A, Agent B, X, Nonce NB,
wenzelm@61956
    49
                    Crypt (shrK B) \<lbrace>Nonce NA, Agent A, Agent B\<rbrace>\<rbrace>
paulson@11251
    50
                 # evs2 \<in> otway"
paulson@2002
    51
wenzelm@61830
    52
 | OR3:  \<comment>\<open>The Server receives Bob's message and checks that the three NAs
paulson@2002
    53
           match.  Then he sends a new session key to Bob with a packet for
wenzelm@61830
    54
           forwarding to Alice.\<close>
wenzelm@32960
    55
         "[| evs3 \<in> otway;  Key KAB \<notin> used evs3;
paulson@11251
    56
             Gets Server
wenzelm@61956
    57
                  \<lbrace>Nonce NA, Agent A, Agent B,
wenzelm@61956
    58
                    Crypt (shrK A) \<lbrace>Nonce NA, Agent A, Agent B\<rbrace>,
paulson@11251
    59
                    Nonce NB,
wenzelm@61956
    60
                    Crypt (shrK B) \<lbrace>Nonce NA, Agent A, Agent B\<rbrace>\<rbrace>
paulson@11251
    61
               \<in> set evs3 |]
paulson@11251
    62
          ==> Says Server B
wenzelm@61956
    63
                  \<lbrace>Nonce NA,
wenzelm@61956
    64
                    Crypt (shrK A) \<lbrace>Nonce NA, Key KAB\<rbrace>,
wenzelm@61956
    65
                    Crypt (shrK B) \<lbrace>Nonce NB, Key KAB\<rbrace>\<rbrace>
paulson@11251
    66
                 # evs3 \<in> otway"
paulson@2002
    67
wenzelm@61830
    68
 | OR4:  \<comment>\<open>Bob receives the Server's (?) message and compares the Nonces with
wenzelm@32960
    69
             those in the message he previously sent the Server.
wenzelm@61830
    70
             Need @{term "B \<noteq> Server"} because we allow messages to self.\<close>
wenzelm@32960
    71
         "[| evs4 \<in> otway;  B \<noteq> Server;
wenzelm@61956
    72
             Says B Server \<lbrace>Nonce NA, Agent A, Agent B, X', Nonce NB,
wenzelm@61956
    73
                             Crypt (shrK B) \<lbrace>Nonce NA, Agent A, Agent B\<rbrace>\<rbrace>
paulson@11251
    74
               \<in> set evs4;
wenzelm@61956
    75
             Gets B \<lbrace>Nonce NA, X, Crypt (shrK B) \<lbrace>Nonce NB, Key K\<rbrace>\<rbrace>
paulson@11251
    76
               \<in> set evs4 |]
wenzelm@61956
    77
          ==> Says B A \<lbrace>Nonce NA, X\<rbrace> # evs4 \<in> otway"
paulson@2002
    78
wenzelm@61830
    79
 | Oops: \<comment>\<open>This message models possible leaks of session keys.  The nonces
wenzelm@61830
    80
             identify the protocol run.\<close>
wenzelm@32960
    81
         "[| evso \<in> otway;
wenzelm@61956
    82
             Says Server B \<lbrace>Nonce NA, X, Crypt (shrK B) \<lbrace>Nonce NB, Key K\<rbrace>\<rbrace>
paulson@11251
    83
               \<in> set evso |]
wenzelm@61956
    84
          ==> Notes Spy \<lbrace>Nonce NA, Nonce NB, Key K\<rbrace> # evso \<in> otway"
paulson@11251
    85
paulson@11251
    86
paulson@11251
    87
declare Says_imp_knows_Spy [THEN analz.Inj, dest]
paulson@11251
    88
declare parts.Body  [dest]
paulson@11251
    89
declare analz_into_parts [dest]
paulson@11251
    90
declare Fake_parts_insert_in_Un  [dest]
paulson@11251
    91
wenzelm@61830
    92
text\<open>A "possibility property": there are traces that reach the end\<close>
paulson@14200
    93
lemma "[| B \<noteq> Server; Key K \<notin> used [] |]
paulson@14200
    94
      ==> \<exists>NA. \<exists>evs \<in> otway.
wenzelm@61956
    95
            Says B A \<lbrace>Nonce NA, Crypt (shrK A) \<lbrace>Nonce NA, Key K\<rbrace>\<rbrace>
paulson@11251
    96
              \<in> set evs"
paulson@11251
    97
apply (intro exI bexI)
paulson@11251
    98
apply (rule_tac [2] otway.Nil
paulson@11251
    99
                    [THEN otway.OR1, THEN otway.Reception,
paulson@11251
   100
                     THEN otway.OR2, THEN otway.Reception,
paulson@14200
   101
                     THEN otway.OR3, THEN otway.Reception, THEN otway.OR4])
paulson@14200
   102
apply (possibility, simp add: used_Cons) 
paulson@11251
   103
done
paulson@11251
   104
paulson@11251
   105
lemma Gets_imp_Says [dest!]:
paulson@11251
   106
     "[| Gets B X \<in> set evs; evs \<in> otway |] ==> \<exists>A. Says A B X \<in> set evs"
paulson@11251
   107
apply (erule rev_mp)
paulson@13507
   108
apply (erule otway.induct, auto)
paulson@11251
   109
done
paulson@11251
   110
paulson@11251
   111
wenzelm@61830
   112
subsection\<open>For reasoning about the encrypted portion of messages\<close>
paulson@11251
   113
paulson@11251
   114
lemma OR2_analz_knows_Spy:
wenzelm@61956
   115
     "[| Gets B \<lbrace>N, Agent A, Agent B, X\<rbrace> \<in> set evs;  evs \<in> otway |]
paulson@11251
   116
      ==> X \<in> analz (knows Spy evs)"
paulson@11251
   117
by blast
paulson@11251
   118
paulson@11251
   119
lemma OR4_analz_knows_Spy:
wenzelm@61956
   120
     "[| Gets B \<lbrace>N, X, Crypt (shrK B) X'\<rbrace> \<in> set evs;  evs \<in> otway |]
paulson@11251
   121
      ==> X \<in> analz (knows Spy evs)"
paulson@11251
   122
by blast
paulson@11251
   123
paulson@11251
   124
lemma Oops_parts_knows_Spy:
wenzelm@61956
   125
     "Says Server B \<lbrace>NA, X, Crypt K' \<lbrace>NB,K\<rbrace>\<rbrace> \<in> set evs
paulson@11251
   126
      ==> K \<in> parts (knows Spy evs)"
paulson@11251
   127
by blast
paulson@11251
   128
wenzelm@61830
   129
text\<open>Forwarding lemma: see comments in OtwayRees.thy\<close>
paulson@11251
   130
lemmas OR2_parts_knows_Spy =
wenzelm@45605
   131
    OR2_analz_knows_Spy [THEN analz_into_parts]
paulson@11251
   132
paulson@11251
   133
wenzelm@61830
   134
text\<open>Theorems of the form @{term "X \<notin> parts (spies evs)"} imply that
wenzelm@61830
   135
NOBODY sends messages containing X!\<close>
paulson@11251
   136
wenzelm@61830
   137
text\<open>Spy never sees a good agent's shared key!\<close>
paulson@11251
   138
lemma Spy_see_shrK [simp]:
paulson@11251
   139
     "evs \<in> otway ==> (Key (shrK A) \<in> parts (knows Spy evs)) = (A \<in> bad)"
paulson@14225
   140
by (erule otway.induct, force,
paulson@14225
   141
    drule_tac [4] OR2_parts_knows_Spy, simp_all, blast+)
paulson@14225
   142
paulson@11251
   143
paulson@11251
   144
lemma Spy_analz_shrK [simp]:
paulson@11251
   145
     "evs \<in> otway ==> (Key (shrK A) \<in> analz (knows Spy evs)) = (A \<in> bad)"
paulson@11251
   146
by auto
paulson@11251
   147
paulson@11251
   148
lemma Spy_see_shrK_D [dest!]:
paulson@11251
   149
     "[|Key (shrK A) \<in> parts (knows Spy evs);  evs \<in> otway|] ==> A \<in> bad"
paulson@11251
   150
by (blast dest: Spy_see_shrK)
paulson@11251
   151
paulson@11251
   152
wenzelm@61830
   153
subsection\<open>Proofs involving analz\<close>
paulson@11251
   154
wenzelm@61830
   155
text\<open>Describes the form of K and NA when the Server sends this message.  Also
wenzelm@61830
   156
  for Oops case.\<close>
paulson@11251
   157
lemma Says_Server_message_form:
wenzelm@61956
   158
     "[| Says Server B \<lbrace>NA, X, Crypt (shrK B) \<lbrace>NB, Key K\<rbrace>\<rbrace> \<in> set evs;
paulson@11251
   159
         evs \<in> otway |]
paulson@11251
   160
      ==> K \<notin> range shrK & (\<exists>i. NA = Nonce i) & (\<exists>j. NB = Nonce j)"
paulson@11251
   161
apply (erule rev_mp)
nipkow@17778
   162
apply (erule otway.induct, simp_all)
paulson@11251
   163
done
paulson@11251
   164
paulson@11251
   165
paulson@11251
   166
(****
paulson@11251
   167
 The following is to prove theorems of the form
paulson@11251
   168
paulson@11251
   169
  Key K \<in> analz (insert (Key KAB) (knows Spy evs)) ==>
paulson@11251
   170
  Key K \<in> analz (knows Spy evs)
paulson@11251
   171
paulson@11251
   172
 A more general formula must be proved inductively.
paulson@11251
   173
****)
paulson@11251
   174
paulson@11251
   175
wenzelm@61830
   176
text\<open>Session keys are not used to encrypt other session keys\<close>
paulson@11251
   177
wenzelm@61830
   178
text\<open>The equality makes the induction hypothesis easier to apply\<close>
paulson@11251
   179
lemma analz_image_freshK [rule_format]:
paulson@11251
   180
 "evs \<in> otway ==>
paulson@11251
   181
   \<forall>K KK. KK <= -(range shrK) -->
paulson@11251
   182
          (Key K \<in> analz (Key`KK Un (knows Spy evs))) =
paulson@11251
   183
          (K \<in> KK | Key K \<in> analz (knows Spy evs))"
paulson@14207
   184
apply (erule otway.induct)
paulson@14207
   185
apply (frule_tac [8] Says_Server_message_form)
paulson@14207
   186
apply (drule_tac [7] OR4_analz_knows_Spy)
paulson@14207
   187
apply (drule_tac [5] OR2_analz_knows_Spy, analz_freshK, spy_analz, auto) 
paulson@11251
   188
done
paulson@11251
   189
paulson@11251
   190
lemma analz_insert_freshK:
paulson@11251
   191
  "[| evs \<in> otway;  KAB \<notin> range shrK |] ==>
wenzelm@11655
   192
      (Key K \<in> analz (insert (Key KAB) (knows Spy evs))) =
paulson@11251
   193
      (K = KAB | Key K \<in> analz (knows Spy evs))"
paulson@11251
   194
by (simp only: analz_image_freshK analz_image_freshK_simps)
paulson@11251
   195
paulson@11251
   196
wenzelm@61830
   197
text\<open>The Key K uniquely identifies the Server's  message.\<close>
paulson@11251
   198
lemma unique_session_keys:
wenzelm@61956
   199
     "[| Says Server B \<lbrace>NA, X, Crypt (shrK B) \<lbrace>NB, K\<rbrace>\<rbrace>   \<in> set evs;
wenzelm@61956
   200
         Says Server B' \<lbrace>NA',X',Crypt (shrK B') \<lbrace>NB',K\<rbrace>\<rbrace> \<in> set evs;
paulson@11251
   201
         evs \<in> otway |] ==> X=X' & B=B' & NA=NA' & NB=NB'"
paulson@11251
   202
apply (erule rev_mp)
paulson@11251
   203
apply (erule rev_mp)
paulson@11251
   204
apply (erule otway.induct, simp_all)
wenzelm@61830
   205
apply blast+  \<comment>\<open>OR3 and OR4\<close>
paulson@11251
   206
done
paulson@11251
   207
paulson@11251
   208
wenzelm@61830
   209
text\<open>Crucial secrecy property: Spy does not see the keys sent in msg OR3
paulson@11251
   210
    Does not in itself guarantee security: an attack could violate
wenzelm@61830
   211
    the premises, e.g. by having @{term "A=Spy"}\<close>
paulson@11251
   212
lemma secrecy_lemma:
paulson@11251
   213
 "[| A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@11251
   214
  ==> Says Server B
wenzelm@61956
   215
        \<lbrace>NA, Crypt (shrK A) \<lbrace>NA, Key K\<rbrace>,
wenzelm@61956
   216
          Crypt (shrK B) \<lbrace>NB, Key K\<rbrace>\<rbrace> \<in> set evs -->
wenzelm@61956
   217
      Notes Spy \<lbrace>NA, NB, Key K\<rbrace> \<notin> set evs -->
paulson@11251
   218
      Key K \<notin> analz (knows Spy evs)"
paulson@11251
   219
apply (erule otway.induct, force)
paulson@11251
   220
apply (frule_tac [7] Says_Server_message_form)
paulson@11251
   221
apply (drule_tac [6] OR4_analz_knows_Spy)
paulson@11251
   222
apply (drule_tac [4] OR2_analz_knows_Spy)
paulson@14225
   223
apply (simp_all add: analz_insert_eq analz_insert_freshK pushes)
wenzelm@61830
   224
apply spy_analz  \<comment>\<open>Fake\<close>
wenzelm@61830
   225
apply (blast dest: unique_session_keys)+  \<comment>\<open>OR3, OR4, Oops\<close>
paulson@11251
   226
done
paulson@11251
   227
paulson@11251
   228
paulson@11251
   229
lemma Spy_not_see_encrypted_key:
paulson@11251
   230
     "[| Says Server B
wenzelm@61956
   231
          \<lbrace>NA, Crypt (shrK A) \<lbrace>NA, Key K\<rbrace>,
wenzelm@61956
   232
                Crypt (shrK B) \<lbrace>NB, Key K\<rbrace>\<rbrace> \<in> set evs;
wenzelm@61956
   233
         Notes Spy \<lbrace>NA, NB, Key K\<rbrace> \<notin> set evs;
paulson@11251
   234
         A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@11251
   235
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   236
by (blast dest: Says_Server_message_form secrecy_lemma)
paulson@11251
   237
paulson@11251
   238
wenzelm@61830
   239
subsection\<open>Attempting to prove stronger properties\<close>
paulson@11251
   240
wenzelm@61830
   241
text\<open>Only OR1 can have caused such a part of a message to appear. The premise
paulson@14225
   242
  @{term "A \<noteq> B"} prevents OR2's similar-looking cryptogram from being picked 
wenzelm@61830
   243
  up. Original Otway-Rees doesn't need it.\<close>
paulson@11251
   244
lemma Crypt_imp_OR1 [rule_format]:
paulson@11251
   245
     "[| A \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
wenzelm@61956
   246
      ==> Crypt (shrK A) \<lbrace>NA, Agent A, Agent B\<rbrace> \<in> parts (knows Spy evs) -->
wenzelm@61956
   247
          Says A B \<lbrace>NA, Agent A, Agent B,
wenzelm@61956
   248
                     Crypt (shrK A) \<lbrace>NA, Agent A, Agent B\<rbrace>\<rbrace>  \<in> set evs"
paulson@14225
   249
by (erule otway.induct, force,
paulson@14225
   250
    drule_tac [4] OR2_parts_knows_Spy, simp_all, blast+)
paulson@11251
   251
paulson@11251
   252
wenzelm@61830
   253
text\<open>Crucial property: If the encrypted message appears, and A has used NA
paulson@11251
   254
  to start a run, then it originated with the Server!
wenzelm@61830
   255
  The premise @{term "A \<noteq> B"} allows use of \<open>Crypt_imp_OR1\<close>\<close>
wenzelm@61830
   256
text\<open>Only it is FALSE.  Somebody could make a fake message to Server
wenzelm@61830
   257
          substituting some other nonce NA' for NB.\<close>
paulson@11251
   258
lemma "[| A \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
wenzelm@61956
   259
       ==> Crypt (shrK A) \<lbrace>NA, Key K\<rbrace> \<in> parts (knows Spy evs) -->
wenzelm@61956
   260
           Says A B \<lbrace>NA, Agent A, Agent B,
wenzelm@61956
   261
                      Crypt (shrK A) \<lbrace>NA, Agent A, Agent B\<rbrace>\<rbrace>
paulson@11251
   262
            \<in> set evs -->
paulson@11251
   263
           (\<exists>B NB. Says Server B
wenzelm@61956
   264
                \<lbrace>NA,
wenzelm@61956
   265
                  Crypt (shrK A) \<lbrace>NA, Key K\<rbrace>,
wenzelm@61956
   266
                  Crypt (shrK B) \<lbrace>NB, Key K\<rbrace>\<rbrace> \<in> set evs)"
paulson@11251
   267
apply (erule otway.induct, force,
paulson@13507
   268
       drule_tac [4] OR2_parts_knows_Spy, simp_all)
wenzelm@61830
   269
apply blast  \<comment>\<open>Fake\<close>
wenzelm@61830
   270
apply blast  \<comment>\<open>OR1: it cannot be a new Nonce, contradiction.\<close>
wenzelm@61830
   271
txt\<open>OR3 and OR4\<close>
paulson@11251
   272
apply (simp_all add: ex_disj_distrib)
wenzelm@61830
   273
 prefer 2 apply (blast intro!: Crypt_imp_OR1)  \<comment>\<open>OR4\<close>
wenzelm@61830
   274
txt\<open>OR3\<close>
paulson@11251
   275
apply clarify
paulson@11251
   276
(*The hypotheses at this point suggest an attack in which nonce NB is used
paulson@11251
   277
  in two different roles:
paulson@11251
   278
          Gets Server
wenzelm@61956
   279
           \<lbrace>Nonce NA, Agent Aa, Agent A,
wenzelm@61956
   280
             Crypt (shrK Aa) \<lbrace>Nonce NA, Agent Aa, Agent A\<rbrace>, Nonce NB,
wenzelm@61956
   281
             Crypt (shrK A) \<lbrace>Nonce NA, Agent Aa, Agent A\<rbrace>\<rbrace>
paulson@11251
   282
          \<in> set evs3
paulson@11251
   283
          Says A B
wenzelm@61956
   284
           \<lbrace>Nonce NB, Agent A, Agent B,
wenzelm@61956
   285
             Crypt (shrK A) \<lbrace>Nonce NB, Agent A, Agent B\<rbrace>\<rbrace>
paulson@11251
   286
          \<in> set evs3;
paulson@11251
   287
*)
paulson@11251
   288
paulson@11251
   289
paulson@11251
   290
(*Thus the key property A_can_trust probably fails too.*)
paulson@11251
   291
oops
paulson@2002
   292
paulson@2002
   293
end