src/HOL/Auth/NS_Public_Bad.thy
author huffman
Sat Jun 06 09:11:12 2009 -0700 (2009-06-06)
changeset 31488 5691ccb8d6b5
parent 23746 a455e69c31cc
child 32960 69916a850301
permissions -rw-r--r--
generalize tendsto to class topological_space
paulson@2318
     1
(*  Title:      HOL/Auth/NS_Public_Bad
paulson@2318
     2
    ID:         $Id$
paulson@2318
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@2318
     4
    Copyright   1996  University of Cambridge
paulson@2318
     5
paulson@2318
     6
Inductive relation "ns_public" for the Needham-Schroeder Public-Key protocol.
paulson@2318
     7
Flawed version, vulnerable to Lowe's attack.
paulson@2318
     8
paulson@2318
     9
From page 260 of
paulson@2318
    10
  Burrows, Abadi and Needham.  A Logic of Authentication.
paulson@2318
    11
  Proc. Royal Soc. 426 (1989)
paulson@2318
    12
*)
paulson@2318
    13
paulson@13956
    14
header{*Verifying the Needham-Schroeder Public-Key Protocol*}
paulson@13956
    15
haftmann@16417
    16
theory NS_Public_Bad imports Public begin
paulson@2318
    17
berghofe@23746
    18
inductive_set ns_public :: "event list set"
berghofe@23746
    19
  where
paulson@2318
    20
         (*Initial trace is empty*)
paulson@11104
    21
   Nil:  "[] \<in> ns_public"
paulson@2318
    22
paulson@2318
    23
         (*The spy MAY say anything he CAN say.  We do not expect him to
paulson@2318
    24
           invent new nonces here, but he can also use NS1.  Common to
paulson@2318
    25
           all similar protocols.*)
berghofe@23746
    26
 | Fake: "\<lbrakk>evsf \<in> ns_public;  X \<in> synth (analz (spies evsf))\<rbrakk>
paulson@11366
    27
          \<Longrightarrow> Says Spy B X  # evsf \<in> ns_public"
paulson@2318
    28
paulson@2318
    29
         (*Alice initiates a protocol run, sending a nonce to Bob*)
berghofe@23746
    30
 | NS1:  "\<lbrakk>evs1 \<in> ns_public;  Nonce NA \<notin> used evs1\<rbrakk>
paulson@13922
    31
          \<Longrightarrow> Says A B (Crypt (pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>)
paulson@11104
    32
                # evs1  \<in>  ns_public"
paulson@2318
    33
paulson@2318
    34
         (*Bob responds to Alice's message with a further nonce*)
berghofe@23746
    35
 | NS2:  "\<lbrakk>evs2 \<in> ns_public;  Nonce NB \<notin> used evs2;
paulson@13922
    36
           Says A' B (Crypt (pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs2\<rbrakk>
paulson@13922
    37
          \<Longrightarrow> Says B A (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB\<rbrace>)
paulson@11104
    38
                # evs2  \<in>  ns_public"
paulson@2318
    39
paulson@2318
    40
         (*Alice proves her existence by sending NB back to Bob.*)
berghofe@23746
    41
 | NS3:  "\<lbrakk>evs3 \<in> ns_public;
paulson@13922
    42
           Says A  B (Crypt (pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs3;
paulson@13922
    43
           Says B' A (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB\<rbrace>) \<in> set evs3\<rbrakk>
paulson@13922
    44
          \<Longrightarrow> Says A B (Crypt (pubEK B) (Nonce NB)) # evs3 \<in> ns_public"
paulson@11104
    45
paulson@11104
    46
declare knows_Spy_partsEs [elim]
paulson@14200
    47
declare analz_into_parts [dest]
paulson@14200
    48
declare Fake_parts_insert_in_Un  [dest]
paulson@11104
    49
declare image_eq_UN [simp]  (*accelerates proofs involving nested images*)
paulson@11104
    50
paulson@11104
    51
(*A "possibility property": there are traces that reach the end*)
paulson@13922
    52
lemma "\<exists>NB. \<exists>evs \<in> ns_public. Says A B (Crypt (pubEK B) (Nonce NB)) \<in> set evs"
paulson@11104
    53
apply (intro exI bexI)
paulson@11104
    54
apply (rule_tac [2] ns_public.Nil [THEN ns_public.NS1, THEN ns_public.NS2, 
paulson@11104
    55
                                   THEN ns_public.NS3])
paulson@11104
    56
by possibility
paulson@11104
    57
paulson@11104
    58
paulson@11104
    59
(**** Inductive proofs about ns_public ****)
paulson@11104
    60
paulson@11104
    61
(** Theorems of the form X \<notin> parts (spies evs) imply that NOBODY
paulson@11104
    62
    sends messages containing X! **)
paulson@11104
    63
paulson@11104
    64
(*Spy never sees another agent's private key! (unless it's bad at start)*)
paulson@13922
    65
lemma Spy_see_priEK [simp]: 
paulson@13922
    66
      "evs \<in> ns_public \<Longrightarrow> (Key (priEK A) \<in> parts (spies evs)) = (A \<in> bad)"
paulson@11104
    67
by (erule ns_public.induct, auto)
paulson@11104
    68
paulson@13922
    69
lemma Spy_analz_priEK [simp]: 
paulson@13922
    70
      "evs \<in> ns_public \<Longrightarrow> (Key (priEK A) \<in> analz (spies evs)) = (A \<in> bad)"
paulson@11104
    71
by auto
paulson@11104
    72
paulson@11104
    73
paulson@11104
    74
(*** Authenticity properties obtained from NS2 ***)
paulson@11104
    75
paulson@11104
    76
(*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce
paulson@11104
    77
  is secret.  (Honest users generate fresh nonces.)*)
paulson@11104
    78
lemma no_nonce_NS1_NS2 [rule_format]: 
paulson@11104
    79
      "evs \<in> ns_public 
paulson@13922
    80
       \<Longrightarrow> Crypt (pubEK C) \<lbrace>NA', Nonce NA\<rbrace> \<in> parts (spies evs) \<longrightarrow>
paulson@13922
    81
           Crypt (pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace> \<in> parts (spies evs) \<longrightarrow>  
paulson@11104
    82
           Nonce NA \<in> analz (spies evs)"
paulson@11104
    83
apply (erule ns_public.induct, simp_all)
paulson@11104
    84
apply (blast intro: analz_insertI)+
paulson@11104
    85
done
paulson@11104
    86
paulson@11104
    87
paulson@11104
    88
(*Unicity for NS1: nonce NA identifies agents A and B*)
paulson@11104
    89
lemma unique_NA: 
paulson@13922
    90
     "\<lbrakk>Crypt(pubEK B)  \<lbrace>Nonce NA, Agent A \<rbrace> \<in> parts(spies evs);  
paulson@13922
    91
       Crypt(pubEK B') \<lbrace>Nonce NA, Agent A'\<rbrace> \<in> parts(spies evs);  
paulson@11104
    92
       Nonce NA \<notin> analz (spies evs); evs \<in> ns_public\<rbrakk>
paulson@11104
    93
      \<Longrightarrow> A=A' \<and> B=B'"
paulson@11104
    94
apply (erule rev_mp, erule rev_mp, erule rev_mp)   
paulson@11104
    95
apply (erule ns_public.induct, simp_all)
paulson@11104
    96
(*Fake, NS1*)
paulson@11104
    97
apply (blast intro!: analz_insertI)+
paulson@11104
    98
done
paulson@11104
    99
paulson@11104
   100
paulson@11104
   101
(*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure
paulson@11104
   102
  The major premise "Says A B ..." makes it a dest-rule, so we use
paulson@11104
   103
  (erule rev_mp) rather than rule_format. *)
paulson@11104
   104
theorem Spy_not_see_NA: 
paulson@13922
   105
      "\<lbrakk>Says A B (Crypt(pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs;
paulson@11104
   106
        A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                     
paulson@11104
   107
       \<Longrightarrow> Nonce NA \<notin> analz (spies evs)"
paulson@11104
   108
apply (erule rev_mp)   
paulson@13507
   109
apply (erule ns_public.induct, simp_all, spy_analz)
paulson@11104
   110
apply (blast dest: unique_NA intro: no_nonce_NS1_NS2)+
paulson@11104
   111
done
paulson@11104
   112
paulson@11104
   113
paulson@11104
   114
(*Authentication for A: if she receives message 2 and has used NA
paulson@11104
   115
  to start a run, then B has sent message 2.*)
paulson@11104
   116
lemma A_trusts_NS2_lemma [rule_format]: 
paulson@11104
   117
   "\<lbrakk>A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                     
paulson@13922
   118
    \<Longrightarrow> Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB\<rbrace> \<in> parts (spies evs) \<longrightarrow>
paulson@13922
   119
	Says A B (Crypt(pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs \<longrightarrow>
paulson@13922
   120
	Says B A (Crypt(pubEK A) \<lbrace>Nonce NA, Nonce NB\<rbrace>) \<in> set evs"
paulson@11104
   121
apply (erule ns_public.induct)
paulson@11104
   122
apply (auto dest: Spy_not_see_NA unique_NA)
paulson@11104
   123
done
paulson@11104
   124
paulson@11104
   125
theorem A_trusts_NS2: 
paulson@13922
   126
     "\<lbrakk>Says A  B (Crypt(pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs;   
paulson@13922
   127
       Says B' A (Crypt(pubEK A) \<lbrace>Nonce NA, Nonce NB\<rbrace>) \<in> set evs;
paulson@11104
   128
       A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                     
paulson@13922
   129
      \<Longrightarrow> Says B A (Crypt(pubEK A) \<lbrace>Nonce NA, Nonce NB\<rbrace>) \<in> set evs"
paulson@11104
   130
by (blast intro: A_trusts_NS2_lemma)
paulson@11104
   131
paulson@2318
   132
paulson@11104
   133
(*If the encrypted message appears then it originated with Alice in NS1*)
paulson@11104
   134
lemma B_trusts_NS1 [rule_format]:
paulson@11104
   135
     "evs \<in> ns_public                                         
paulson@13922
   136
      \<Longrightarrow> Crypt (pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace> \<in> parts (spies evs) \<longrightarrow>
paulson@11104
   137
	  Nonce NA \<notin> analz (spies evs) \<longrightarrow>
paulson@13922
   138
	  Says A B (Crypt (pubEK B) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs"
paulson@11104
   139
apply (erule ns_public.induct, simp_all)
paulson@11104
   140
(*Fake*)
paulson@11104
   141
apply (blast intro!: analz_insertI)
paulson@11104
   142
done
paulson@11104
   143
paulson@11104
   144
paulson@11104
   145
paulson@11104
   146
(*** Authenticity properties obtained from NS2 ***)
paulson@11104
   147
paulson@11104
   148
(*Unicity for NS2: nonce NB identifies nonce NA and agent A
paulson@11104
   149
  [proof closely follows that for unique_NA] *)
paulson@11104
   150
lemma unique_NB [dest]: 
paulson@13922
   151
     "\<lbrakk>Crypt(pubEK A)  \<lbrace>Nonce NA, Nonce NB\<rbrace> \<in> parts(spies evs);
paulson@13922
   152
       Crypt(pubEK A') \<lbrace>Nonce NA', Nonce NB\<rbrace> \<in> parts(spies evs);
paulson@11104
   153
       Nonce NB \<notin> analz (spies evs); evs \<in> ns_public\<rbrakk>
paulson@11104
   154
     \<Longrightarrow> A=A' \<and> NA=NA'"
paulson@11104
   155
apply (erule rev_mp, erule rev_mp, erule rev_mp)   
paulson@11104
   156
apply (erule ns_public.induct, simp_all)
paulson@11104
   157
(*Fake, NS2*)
paulson@11104
   158
apply (blast intro!: analz_insertI)+
paulson@11104
   159
done
paulson@11104
   160
paulson@11104
   161
paulson@11104
   162
(*NB remains secret PROVIDED Alice never responds with round 3*)
paulson@11104
   163
theorem Spy_not_see_NB [dest]:
paulson@13922
   164
     "\<lbrakk>Says B A (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB\<rbrace>) \<in> set evs;   
paulson@13922
   165
       \<forall>C. Says A C (Crypt (pubEK C) (Nonce NB)) \<notin> set evs;       
paulson@11104
   166
       A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                      
paulson@11104
   167
     \<Longrightarrow> Nonce NB \<notin> analz (spies evs)"
paulson@11104
   168
apply (erule rev_mp, erule rev_mp)
paulson@13507
   169
apply (erule ns_public.induct, simp_all, spy_analz)
paulson@11104
   170
apply (simp_all add: all_conj_distrib) (*speeds up the next step*)
paulson@11104
   171
apply (blast intro: no_nonce_NS1_NS2)+
paulson@11104
   172
done
paulson@11104
   173
paulson@11104
   174
paulson@11104
   175
(*Authentication for B: if he receives message 3 and has used NB
paulson@11104
   176
  in message 2, then A has sent message 3--to somebody....*)
paulson@11104
   177
paulson@11104
   178
lemma B_trusts_NS3_lemma [rule_format]:
paulson@11104
   179
     "\<lbrakk>A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                    
paulson@13922
   180
      \<Longrightarrow> Crypt (pubEK B) (Nonce NB) \<in> parts (spies evs) \<longrightarrow>
paulson@13922
   181
          Says B A  (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB\<rbrace>) \<in> set evs \<longrightarrow>
paulson@13922
   182
          (\<exists>C. Says A C (Crypt (pubEK C) (Nonce NB)) \<in> set evs)"
paulson@11104
   183
apply (erule ns_public.induct, auto)
paulson@11104
   184
by (blast intro: no_nonce_NS1_NS2)+
paulson@11104
   185
paulson@11104
   186
theorem B_trusts_NS3:
paulson@13922
   187
     "\<lbrakk>Says B A  (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB\<rbrace>) \<in> set evs;
paulson@13922
   188
       Says A' B (Crypt (pubEK B) (Nonce NB)) \<in> set evs;             
paulson@11104
   189
       A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>                    
paulson@13922
   190
      \<Longrightarrow> \<exists>C. Says A C (Crypt (pubEK C) (Nonce NB)) \<in> set evs"
paulson@11104
   191
by (blast intro: B_trusts_NS3_lemma)
paulson@11104
   192
paulson@11104
   193
paulson@11104
   194
(*Can we strengthen the secrecy theorem Spy_not_see_NB?  NO*)
paulson@11104
   195
lemma "\<lbrakk>A \<notin> bad;  B \<notin> bad;  evs \<in> ns_public\<rbrakk>            
paulson@13922
   196
       \<Longrightarrow> Says B A (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB\<rbrace>) \<in> set evs  
paulson@11104
   197
           \<longrightarrow> Nonce NB \<notin> analz (spies evs)"
paulson@13507
   198
apply (erule ns_public.induct, simp_all, spy_analz)
paulson@11104
   199
(*NS1: by freshness*)
paulson@11150
   200
apply blast
paulson@11104
   201
(*NS2: by freshness and unicity of NB*)
paulson@11104
   202
apply (blast intro: no_nonce_NS1_NS2)
paulson@11104
   203
(*NS3: unicity of NB identifies A and NA, but not B*)
paulson@11104
   204
apply clarify
paulson@13507
   205
apply (frule_tac A' = A in 
paulson@13507
   206
       Says_imp_knows_Spy [THEN parts.Inj, THEN unique_NB], auto)
paulson@11104
   207
apply (rename_tac C B' evs3)
paulson@14200
   208
txt{*This is the attack!
paulson@14200
   209
@{subgoals[display,indent=0,margin=65]}
paulson@14200
   210
*}
paulson@11104
   211
oops
paulson@11104
   212
paulson@11104
   213
(*
paulson@11104
   214
THIS IS THE ATTACK!
paulson@11104
   215
Level 8
paulson@11104
   216
!!evs. \<lbrakk>A \<notin> bad; B \<notin> bad; evs \<in> ns_public\<rbrakk>
paulson@13922
   217
       \<Longrightarrow> Says B A (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB\<rbrace>) \<in> set evs \<longrightarrow>
paulson@11104
   218
           Nonce NB \<notin> analz (spies evs)
paulson@11104
   219
 1. !!C B' evs3.
paulson@11104
   220
       \<lbrakk>A \<notin> bad; B \<notin> bad; evs3 \<in> ns_public
paulson@13922
   221
        Says A C (Crypt (pubEK C) \<lbrace>Nonce NA, Agent A\<rbrace>) \<in> set evs3;
paulson@13922
   222
        Says B' A (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB\<rbrace>) \<in> set evs3; 
paulson@11104
   223
        C \<in> bad;
paulson@13922
   224
        Says B A (Crypt (pubEK A) \<lbrace>Nonce NA, Nonce NB\<rbrace>) \<in> set evs3;
paulson@11104
   225
        Nonce NB \<notin> analz (spies evs3)\<rbrakk>
paulson@11104
   226
       \<Longrightarrow> False
paulson@11104
   227
*)
paulson@2318
   228
paulson@2318
   229
end