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