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