src/HOL/Auth/OtwayRees_AN.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@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@2090
     5
paulson@2090
     6
Inductive relation "otway" for the Otway-Rees protocol.
paulson@2090
     7
paulson@11251
     8
Abadi-Needham simplified version: minimal encryption, explicit messages
paulson@2090
     9
paulson@2516
    10
Note that the formalization does not even assume that nonces are fresh.
paulson@2516
    11
This is because the protocol does not rely on uniqueness of nonces for
paulson@2516
    12
security, only for freshness, and the proof script does not prove freshness
paulson@2516
    13
properties.
paulson@2516
    14
paulson@2090
    15
From page 11 of
paulson@2090
    16
  Abadi and Needham.  Prudent Engineering Practice for Cryptographic Protocols.
paulson@2090
    17
  IEEE Trans. SE 22 (1), 1996
paulson@2090
    18
*)
paulson@2090
    19
paulson@11251
    20
theory OtwayRees_AN = Shared:
paulson@2090
    21
paulson@11251
    22
consts  otway   :: "event list set"
paulson@3519
    23
inductive "otway"
paulson@11251
    24
  intros
paulson@2090
    25
         (*Initial trace is empty*)
paulson@11251
    26
   Nil:  "[] \<in> otway"
paulson@2090
    27
paulson@2090
    28
         (*The spy MAY say anything he CAN say.  We do not expect him to
paulson@2090
    29
           invent new nonces here, but he can also use NS1.  Common to
paulson@2090
    30
           all similar protocols.*)
paulson@11251
    31
   Fake: "[| evsf \<in> otway;  X \<in> synth (analz (knows Spy evsf)) |]
paulson@11251
    32
          ==> Says Spy B X  # evsf \<in> otway"
paulson@2090
    33
paulson@6308
    34
         (*A message that has been sent can be received by the
paulson@6308
    35
           intended recipient.*)
paulson@11251
    36
   Reception: "[| evsr \<in> otway;  Says A B X \<in>set evsr |]
paulson@11251
    37
               ==> Gets B X # evsr \<in> otway"
paulson@6308
    38
paulson@2090
    39
         (*Alice initiates a protocol run*)
paulson@11251
    40
   OR1:  "evs1 \<in> otway
paulson@11251
    41
          ==> Says A B {|Agent A, Agent B, Nonce NA|} # evs1 \<in> otway"
paulson@2090
    42
paulson@6333
    43
         (*Bob's response to Alice's message.*)
paulson@11251
    44
   OR2:  "[| evs2 \<in> otway;
paulson@11251
    45
             Gets B {|Agent A, Agent B, Nonce NA|} \<in>set evs2 |]
paulson@2516
    46
          ==> Says B Server {|Agent A, Agent B, Nonce NA, Nonce NB|}
paulson@11251
    47
                 # evs2 \<in> otway"
paulson@2090
    48
paulson@2090
    49
         (*The Server receives Bob's message.  Then he sends a new
paulson@2090
    50
           session key to Bob with a packet for forwarding to Alice.*)
paulson@11251
    51
   OR3:  "[| evs3 \<in> otway;  Key KAB \<notin> used evs3;
paulson@6308
    52
             Gets Server {|Agent A, Agent B, Nonce NA, Nonce NB|}
paulson@11251
    53
               \<in>set evs3 |]
paulson@11251
    54
          ==> Says Server B
paulson@2516
    55
               {|Crypt (shrK A) {|Nonce NA, Agent A, Agent B, Key KAB|},
paulson@2516
    56
                 Crypt (shrK B) {|Nonce NB, Agent A, Agent B, Key KAB|}|}
paulson@11251
    57
              # evs3 \<in> otway"
paulson@2090
    58
paulson@2090
    59
         (*Bob receives the Server's (?) message and compares the Nonces with
paulson@5434
    60
	   those in the message he previously sent the Server.
paulson@11251
    61
           Need B \<noteq> Server because we allow messages to self.*)
paulson@11251
    62
   OR4:  "[| evs4 \<in> otway;  B \<noteq> Server;
paulson@11251
    63
             Says B Server {|Agent A, Agent B, Nonce NA, Nonce NB|} \<in>set evs4;
paulson@6308
    64
             Gets B {|X, Crypt(shrK B){|Nonce NB,Agent A,Agent B,Key K|}|}
paulson@11251
    65
               \<in>set evs4 |]
paulson@11251
    66
          ==> Says B A X # evs4 \<in> otway"
paulson@2090
    67
paulson@2131
    68
         (*This message models possible leaks of session keys.  The nonces
paulson@2131
    69
           identify the protocol run.  B is not assumed to know shrK A.*)
paulson@11251
    70
   Oops: "[| evso \<in> otway;
paulson@11251
    71
             Says Server B
paulson@11251
    72
                      {|Crypt (shrK A) {|Nonce NA, Agent A, Agent B, Key K|},
paulson@2284
    73
                        Crypt (shrK B) {|Nonce NB, Agent A, Agent B, Key K|}|}
paulson@11251
    74
               \<in>set evso |]
paulson@11251
    75
          ==> Notes Spy {|Nonce NA, Nonce NB, Key K|} # evso \<in> otway"
paulson@11251
    76
paulson@11251
    77
paulson@11251
    78
declare Says_imp_knows_Spy [THEN analz.Inj, dest]
paulson@11251
    79
declare parts.Body  [dest]
paulson@11251
    80
declare analz_into_parts [dest]
paulson@11251
    81
declare Fake_parts_insert_in_Un  [dest]
paulson@11251
    82
paulson@11251
    83
paulson@11251
    84
(*A "possibility property": there are traces that reach the end*)
paulson@11251
    85
lemma "B \<noteq> Server
paulson@11251
    86
      ==> \<exists>K. \<exists>evs \<in> otway.
paulson@11251
    87
           Says B A (Crypt (shrK A) {|Nonce NA, Agent A, Agent B, Key K|})
paulson@11251
    88
             \<in> set evs"
paulson@11251
    89
apply (intro exI bexI)
paulson@11251
    90
apply (rule_tac [2] otway.Nil
paulson@11251
    91
                    [THEN otway.OR1, THEN otway.Reception,
paulson@11251
    92
                     THEN otway.OR2, THEN otway.Reception,
paulson@13507
    93
                     THEN otway.OR3, THEN otway.Reception, THEN otway.OR4], possibility)
paulson@11251
    94
done
paulson@11251
    95
paulson@11251
    96
lemma Gets_imp_Says [dest!]:
paulson@11251
    97
     "[| Gets B X \<in> set evs; evs \<in> otway |] ==> \<exists>A. Says A B X \<in> set evs"
paulson@11251
    98
by (erule rev_mp, erule otway.induct, auto)
paulson@11251
    99
paulson@11251
   100
paulson@11251
   101
(**** Inductive proofs about otway ****)
paulson@11251
   102
paulson@11251
   103
(** For reasoning about the encrypted portion of messages **)
paulson@11251
   104
paulson@11251
   105
lemma OR4_analz_knows_Spy:
paulson@11251
   106
     "[| Gets B {|X, Crypt(shrK B) X'|} \<in> set evs;  evs \<in> otway |]
paulson@11251
   107
      ==> X \<in> analz (knows Spy evs)"
paulson@11251
   108
by blast
paulson@11251
   109
paulson@11251
   110
paulson@11251
   111
(** Theorems of the form X \<notin> parts (knows Spy evs) imply that NOBODY
paulson@11251
   112
    sends messages containing X! **)
paulson@11251
   113
paulson@11251
   114
(*Spy never sees a good agent's shared key!*)
paulson@11251
   115
lemma Spy_see_shrK [simp]:
paulson@11251
   116
     "evs \<in> otway ==> (Key (shrK A) \<in> parts (knows Spy evs)) = (A \<in> bad)"
paulson@13507
   117
apply (erule otway.induct, simp_all, blast+)
paulson@11251
   118
done
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@11251
   129
(*** Proofs involving analz ***)
paulson@11251
   130
paulson@11251
   131
(*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@13507
   140
apply (erule otway.induct, simp_all, blast)
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@11251
   155
(** Session keys are not used to encrypt other session keys **)
paulson@11251
   156
paulson@11251
   157
(*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@11251
   163
apply (erule otway.induct, force)
paulson@11251
   164
apply (frule_tac [7] Says_Server_message_form)
paulson@13507
   165
apply (drule_tac [6] OR4_analz_knows_Spy, analz_freshK, spy_analz)
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@11251
   175
(*** The Key K uniquely identifies the Server's message. **)
paulson@11251
   176
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@11251
   189
(*Remaining cases: OR3 and OR4*)
paulson@11251
   190
apply blast+
paulson@11251
   191
done
paulson@11251
   192
paulson@11251
   193
paulson@11251
   194
(**** Authenticity properties relating to NA ****)
paulson@11251
   195
paulson@11251
   196
(*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@11251
   206
(*Fake, OR3*)
paulson@13507
   207
apply blast+
paulson@11251
   208
done
paulson@11251
   209
paulson@11251
   210
paulson@11251
   211
(*Corollary: if A receives B's OR4 message then it originated with the Server.
paulson@11251
   212
  Freshness may be inferred from nonce NA.*)
paulson@11251
   213
lemma A_trusts_OR4:
paulson@11251
   214
     "[| Says B' A (Crypt (shrK A) {|NA, Agent A, Agent B, Key K|}) \<in> set evs;
paulson@11251
   215
         A \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251
   216
      ==> \<exists>NB. Says Server B
paulson@11251
   217
                  {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251
   218
                    Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   219
                 \<in> set evs"
paulson@11251
   220
by (blast intro!: NA_Crypt_imp_Server_msg)
paulson@11251
   221
paulson@11251
   222
paulson@11251
   223
(** Crucial secrecy property: Spy does not see the keys sent in msg OR3
paulson@11251
   224
    Does not in itself guarantee security: an attack could violate
paulson@11251
   225
    the premises, e.g. by having A=Spy **)
paulson@11251
   226
paulson@11251
   227
lemma secrecy_lemma:
paulson@11251
   228
     "[| A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@11251
   229
      ==> Says Server B
paulson@11251
   230
           {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251
   231
             Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   232
          \<in> set evs -->
paulson@11251
   233
          Notes Spy {|NA, NB, Key K|} \<notin> set evs -->
paulson@11251
   234
          Key K \<notin> analz (knows Spy evs)"
paulson@11251
   235
apply (erule otway.induct, force)
paulson@11251
   236
apply (frule_tac [7] Says_Server_message_form)
paulson@11251
   237
apply (drule_tac [6] OR4_analz_knows_Spy)
paulson@13507
   238
apply (simp_all add: analz_insert_eq analz_insert_freshK pushes, spy_analz)  (*Fake*)
paulson@11251
   239
(*OR3, OR4, Oops*)
paulson@11251
   240
apply (blast dest: unique_session_keys)+
paulson@11251
   241
done
paulson@11251
   242
paulson@11251
   243
paulson@11251
   244
lemma Spy_not_see_encrypted_key:
paulson@11251
   245
     "[| Says Server B
paulson@11251
   246
            {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251
   247
              Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   248
           \<in> set evs;
paulson@11251
   249
         Notes Spy {|NA, NB, Key K|} \<notin> set evs;
paulson@11251
   250
         A \<notin> bad;  B \<notin> bad;  evs \<in> otway |]
paulson@11251
   251
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   252
by (blast dest: Says_Server_message_form secrecy_lemma)
paulson@11251
   253
paulson@11251
   254
paulson@11251
   255
(*A's guarantee.  The Oops premise quantifies over NB because A cannot know
paulson@11251
   256
  what it is.*)
paulson@11251
   257
lemma A_gets_good_key:
paulson@11251
   258
     "[| Says B' A (Crypt (shrK A) {|NA, Agent A, Agent B, Key K|}) \<in> set evs;
paulson@11251
   259
         \<forall>NB. Notes Spy {|NA, NB, Key K|} \<notin> set evs;
paulson@11251
   260
         A \<notin> bad;  B \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251
   261
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   262
by (blast dest!: A_trusts_OR4 Spy_not_see_encrypted_key)
paulson@11251
   263
paulson@11251
   264
paulson@11251
   265
paulson@11251
   266
(**** Authenticity properties relating to NB ****)
paulson@11251
   267
paulson@11251
   268
(*If the encrypted message appears then it originated with the Server!*)
paulson@11251
   269
paulson@11251
   270
lemma NB_Crypt_imp_Server_msg [rule_format]:
paulson@11251
   271
 "[| B \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251
   272
  ==> Crypt (shrK B) {|NB, Agent A, Agent B, Key K|} \<in> parts (knows Spy evs)
paulson@11251
   273
      --> (\<exists>NA. Says Server B
paulson@11251
   274
                   {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251
   275
                     Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   276
                   \<in> set evs)"
paulson@11251
   277
apply (erule otway.induct, force, simp_all add: ex_disj_distrib)
paulson@11251
   278
(*Fake, OR3*)
paulson@13507
   279
apply blast+
paulson@11251
   280
done
paulson@11251
   281
paulson@11251
   282
paulson@11251
   283
paulson@11251
   284
(*Guarantee for B: if it gets a well-formed certificate then the Server
paulson@11251
   285
  has sent the correct message in round 3.*)
paulson@11251
   286
lemma B_trusts_OR3:
paulson@11251
   287
     "[| Says S B {|X, Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   288
           \<in> set evs;
paulson@11251
   289
         B \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251
   290
      ==> \<exists>NA. Says Server B
paulson@11251
   291
                   {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},
paulson@11251
   292
                     Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   293
                   \<in> set evs"
paulson@11251
   294
by (blast intro!: NB_Crypt_imp_Server_msg)
paulson@11251
   295
paulson@11251
   296
paulson@11251
   297
(*The obvious combination of B_trusts_OR3 with Spy_not_see_encrypted_key*)
paulson@11251
   298
lemma B_gets_good_key:
paulson@11251
   299
     "[| Gets B {|X, Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}
paulson@11251
   300
          \<in> set evs;
paulson@11251
   301
         \<forall>NA. Notes Spy {|NA, NB, Key K|} \<notin> set evs;
paulson@11251
   302
         A \<notin> bad;  B \<notin> bad;  A \<noteq> B;  evs \<in> otway |]
paulson@11251
   303
      ==> Key K \<notin> analz (knows Spy evs)"
paulson@11251
   304
by (blast dest: B_trusts_OR3 Spy_not_see_encrypted_key)
paulson@2090
   305
paulson@2090
   306
end