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