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