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