| author | haftmann | 
| Fri, 26 Nov 2010 11:38:20 +0100 | |
| changeset 40709 | b29c70cd5c93 | 
| parent 39247 | 3a15ee47c610 | 
| child 41693 | 47532fe9e075 | 
| permissions | -rw-r--r-- | 
| 37936 | 1 | (* Title: HOL/Auth/Shared.thy | 
| 1934 | 2 | Author: Lawrence C Paulson, Cambridge University Computer Laboratory | 
| 3 | Copyright 1996 University of Cambridge | |
| 4 | ||
| 5 | Theory of Shared Keys (common to all symmetric-key protocols) | |
| 6 | ||
| 3512 
9dcb4daa15e8
Moving common declarations and proofs from theories "Shared"
 paulson parents: 
3472diff
changeset | 7 | Shared, long-term keys; initial states of agents | 
| 1934 | 8 | *) | 
| 9 | ||
| 32631 | 10 | theory Shared | 
| 11 | imports Event All_Symmetric | |
| 12 | begin | |
| 1934 | 13 | |
| 14 | consts | |
| 39216 | 15 | shrK :: "agent => key" (*symmetric keys*) | 
| 14126 
28824746d046
Tidying and replacement of some axioms by specifications
 paulson parents: 
13956diff
changeset | 16 | |
| 
28824746d046
Tidying and replacement of some axioms by specifications
 paulson parents: 
13956diff
changeset | 17 | specification (shrK) | 
| 
28824746d046
Tidying and replacement of some axioms by specifications
 paulson parents: 
13956diff
changeset | 18 | inj_shrK: "inj shrK" | 
| 
28824746d046
Tidying and replacement of some axioms by specifications
 paulson parents: 
13956diff
changeset | 19 |   --{*No two agents have the same long-term key*}
 | 
| 
28824746d046
Tidying and replacement of some axioms by specifications
 paulson parents: 
13956diff
changeset | 20 | apply (rule exI [of _ "agent_case 0 (\<lambda>n. n + 2) 1"]) | 
| 
28824746d046
Tidying and replacement of some axioms by specifications
 paulson parents: 
13956diff
changeset | 21 | apply (simp add: inj_on_def split: agent.split) | 
| 
28824746d046
Tidying and replacement of some axioms by specifications
 paulson parents: 
13956diff
changeset | 22 | done | 
| 1967 | 23 | |
| 14126 
28824746d046
Tidying and replacement of some axioms by specifications
 paulson parents: 
13956diff
changeset | 24 | text{*Server knows all long-term keys; other agents know only their own*}
 | 
| 39246 | 25 | |
| 26 | overloading | |
| 27 | initState \<equiv> initState | |
| 28 | begin | |
| 29 | ||
| 30 | primrec initState where | |
| 11104 | 31 | initState_Server: "initState Server = Key ` range shrK" | 
| 39246 | 32 | | initState_Friend:  "initState (Friend i) = {Key (shrK (Friend i))}"
 | 
| 33 | | initState_Spy: "initState Spy = Key`shrK`bad" | |
| 34 | ||
| 35 | end | |
| 2032 | 36 | |
| 1934 | 37 | |
| 13926 | 38 | subsection{*Basic properties of shrK*}
 | 
| 39 | ||
| 40 | (*Injectiveness: Agents' long-term keys are distinct.*) | |
| 18749 
31c2af8b0c60
replacement of bool by a datatype (making problems first-order). More lemma names
 paulson parents: 
17744diff
changeset | 41 | lemmas shrK_injective = inj_shrK [THEN inj_eq] | 
| 
31c2af8b0c60
replacement of bool by a datatype (making problems first-order). More lemma names
 paulson parents: 
17744diff
changeset | 42 | declare shrK_injective [iff] | 
| 13926 | 43 | |
| 44 | lemma invKey_K [simp]: "invKey K = K" | |
| 45 | apply (insert isSym_keys) | |
| 46 | apply (simp add: symKeys_def) | |
| 47 | done | |
| 48 | ||
| 49 | ||
| 50 | lemma analz_Decrypt' [dest]: | |
| 51 | "[| Crypt K X \<in> analz H; Key K \<in> analz H |] ==> X \<in> analz H" | |
| 52 | by auto | |
| 53 | ||
| 54 | text{*Now cancel the @{text dest} attribute given to
 | |
| 55 |  @{text analz.Decrypt} in its declaration.*}
 | |
| 14200 
d8598e24f8fa
Removal of the Key_supply axiom (affects many possbility proofs) and minor
 paulson parents: 
14181diff
changeset | 56 | declare analz.Decrypt [rule del] | 
| 13926 | 57 | |
| 58 | text{*Rewrites should not refer to  @{term "initState(Friend i)"} because
 | |
| 59 | that expression is not in normal form.*} | |
| 60 | ||
| 61 | lemma keysFor_parts_initState [simp]: "keysFor (parts (initState C)) = {}"
 | |
| 62 | apply (unfold keysFor_def) | |
| 63 | apply (induct_tac "C", auto) | |
| 64 | done | |
| 65 | ||
| 66 | (*Specialized to shared-key model: no @{term invKey}*)
 | |
| 67 | lemma keysFor_parts_insert: | |
| 14983 | 68 | "[| K \<in> keysFor (parts (insert X G)); X \<in> synth (analz H) |] | 
| 39216 | 69 | ==> K \<in> keysFor (parts (G \<union> H)) | Key K \<in> parts H" | 
| 13926 | 70 | by (force dest: Event.keysFor_parts_insert) | 
| 71 | ||
| 72 | lemma Crypt_imp_keysFor: "Crypt K X \<in> H ==> K \<in> keysFor H" | |
| 73 | by (drule Crypt_imp_invKey_keysFor, simp) | |
| 74 | ||
| 75 | ||
| 76 | subsection{*Function "knows"*}
 | |
| 77 | ||
| 78 | (*Spy sees shared keys of agents!*) | |
| 79 | lemma Spy_knows_Spy_bad [intro!]: "A: bad ==> Key (shrK A) \<in> knows Spy evs" | |
| 80 | apply (induct_tac "evs") | |
| 81 | apply (simp_all (no_asm_simp) add: imageI knows_Cons split add: event.split) | |
| 82 | done | |
| 83 | ||
| 84 | (*For case analysis on whether or not an agent is compromised*) | |
| 85 | lemma Crypt_Spy_analz_bad: "[| Crypt (shrK A) X \<in> analz (knows Spy evs); A: bad |] | |
| 86 | ==> X \<in> analz (knows Spy evs)" | |
| 87 | apply (force dest!: analz.Decrypt) | |
| 88 | done | |
| 89 | ||
| 90 | ||
| 91 | (** Fresh keys never clash with long-term shared keys **) | |
| 92 | ||
| 93 | (*Agents see their own shared keys!*) | |
| 94 | lemma shrK_in_initState [iff]: "Key (shrK A) \<in> initState A" | |
| 95 | by (induct_tac "A", auto) | |
| 96 | ||
| 97 | lemma shrK_in_used [iff]: "Key (shrK A) \<in> used evs" | |
| 98 | by (rule initState_into_used, blast) | |
| 99 | ||
| 100 | (*Used in parts_induct_tac and analz_Fake_tac to distinguish session keys | |
| 101 | from long-term shared keys*) | |
| 102 | lemma Key_not_used [simp]: "Key K \<notin> used evs ==> K \<notin> range shrK" | |
| 103 | by blast | |
| 104 | ||
| 105 | lemma shrK_neq [simp]: "Key K \<notin> used evs ==> shrK B \<noteq> K" | |
| 106 | by blast | |
| 107 | ||
| 17744 | 108 | lemmas shrK_sym_neq = shrK_neq [THEN not_sym] | 
| 109 | declare shrK_sym_neq [simp] | |
| 13926 | 110 | |
| 111 | ||
| 112 | subsection{*Fresh nonces*}
 | |
| 113 | ||
| 114 | lemma Nonce_notin_initState [iff]: "Nonce N \<notin> parts (initState B)" | |
| 115 | by (induct_tac "B", auto) | |
| 116 | ||
| 117 | lemma Nonce_notin_used_empty [simp]: "Nonce N \<notin> used []" | |
| 118 | apply (simp (no_asm) add: used_Nil) | |
| 119 | done | |
| 120 | ||
| 121 | ||
| 122 | subsection{*Supply fresh nonces for possibility theorems.*}
 | |
| 123 | ||
| 124 | (*In any trace, there is an upper bound N on the greatest nonce in use.*) | |
| 125 | lemma Nonce_supply_lemma: "\<exists>N. ALL n. N<=n --> Nonce n \<notin> used evs" | |
| 126 | apply (induct_tac "evs") | |
| 127 | apply (rule_tac x = 0 in exI) | |
| 128 | apply (simp_all (no_asm_simp) add: used_Cons split add: event.split) | |
| 129 | apply safe | |
| 130 | apply (rule msg_Nonce_supply [THEN exE], blast elim!: add_leE)+ | |
| 131 | done | |
| 132 | ||
| 133 | lemma Nonce_supply1: "\<exists>N. Nonce N \<notin> used evs" | |
| 134 | by (rule Nonce_supply_lemma [THEN exE], blast) | |
| 135 | ||
| 136 | lemma Nonce_supply2: "\<exists>N N'. Nonce N \<notin> used evs & Nonce N' \<notin> used evs' & N \<noteq> N'" | |
| 137 | apply (cut_tac evs = evs in Nonce_supply_lemma) | |
| 138 | apply (cut_tac evs = "evs'" in Nonce_supply_lemma, clarify) | |
| 139 | apply (rule_tac x = N in exI) | |
| 14200 
d8598e24f8fa
Removal of the Key_supply axiom (affects many possbility proofs) and minor
 paulson parents: 
14181diff
changeset | 140 | apply (rule_tac x = "Suc (N+Na)" in exI) | 
| 13926 | 141 | apply (simp (no_asm_simp) add: less_not_refl3 le_add1 le_add2 less_Suc_eq_le) | 
| 142 | done | |
| 143 | ||
| 144 | lemma Nonce_supply3: "\<exists>N N' N''. Nonce N \<notin> used evs & Nonce N' \<notin> used evs' & | |
| 145 | Nonce N'' \<notin> used evs'' & N \<noteq> N' & N' \<noteq> N'' & N \<noteq> N''" | |
| 146 | apply (cut_tac evs = evs in Nonce_supply_lemma) | |
| 147 | apply (cut_tac evs = "evs'" in Nonce_supply_lemma) | |
| 148 | apply (cut_tac evs = "evs''" in Nonce_supply_lemma, clarify) | |
| 149 | apply (rule_tac x = N in exI) | |
| 14200 
d8598e24f8fa
Removal of the Key_supply axiom (affects many possbility proofs) and minor
 paulson parents: 
14181diff
changeset | 150 | apply (rule_tac x = "Suc (N+Na)" in exI) | 
| 13926 | 151 | apply (rule_tac x = "Suc (Suc (N+Na+Nb))" in exI) | 
| 152 | apply (simp (no_asm_simp) add: less_not_refl3 le_add1 le_add2 less_Suc_eq_le) | |
| 153 | done | |
| 154 | ||
| 155 | lemma Nonce_supply: "Nonce (@ N. Nonce N \<notin> used evs) \<notin> used evs" | |
| 156 | apply (rule Nonce_supply_lemma [THEN exE]) | |
| 157 | apply (rule someI, blast) | |
| 158 | done | |
| 159 | ||
| 14200 
d8598e24f8fa
Removal of the Key_supply axiom (affects many possbility proofs) and minor
 paulson parents: 
14181diff
changeset | 160 | text{*Unlike the corresponding property of nonces, we cannot prove
 | 
| 
d8598e24f8fa
Removal of the Key_supply axiom (affects many possbility proofs) and minor
 paulson parents: 
14181diff
changeset | 161 |     @{term "finite KK ==> \<exists>K. K \<notin> KK & Key K \<notin> used evs"}.
 | 
| 2516 
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
 paulson parents: 
2451diff
changeset | 162 | We have infinitely many agents and there is nothing to stop their | 
| 14200 
d8598e24f8fa
Removal of the Key_supply axiom (affects many possbility proofs) and minor
 paulson parents: 
14181diff
changeset | 163 | long-term keys from exhausting all the natural numbers. Instead, | 
| 
d8598e24f8fa
Removal of the Key_supply axiom (affects many possbility proofs) and minor
 paulson parents: 
14181diff
changeset | 164 | possibility theorems must assume the existence of a few keys.*} | 
| 13926 | 165 | |
| 166 | ||
| 13956 | 167 | subsection{*Specialized Rewriting for Theorems About @{term analz} and Image*}
 | 
| 13926 | 168 | |
| 169 | lemma subset_Compl_range: "A <= - (range shrK) ==> shrK x \<notin> A" | |
| 170 | by blast | |
| 171 | ||
| 172 | lemma insert_Key_singleton: "insert (Key K) H = Key ` {K} \<union> H"
 | |
| 173 | by blast | |
| 174 | ||
| 13956 | 175 | lemma insert_Key_image: "insert (Key K) (Key`KK \<union> C) = Key`(insert K KK) \<union> C" | 
| 13926 | 176 | by blast | 
| 177 | ||
| 178 | (** Reverse the normal simplification of "image" to build up (not break down) | |
| 179 | the set of keys. Use analz_insert_eq with (Un_upper2 RS analz_mono) to | |
| 180 | erase occurrences of forwarded message components (X). **) | |
| 181 | ||
| 182 | lemmas analz_image_freshK_simps = | |
| 183 |        simp_thms mem_simps --{*these two allow its use with @{text "only:"}*}
 | |
| 184 | disj_comms | |
| 185 | image_insert [THEN sym] image_Un [THEN sym] empty_subsetI insert_subset | |
| 186 | analz_insert_eq Un_upper2 [THEN analz_mono, THEN [2] rev_subsetD] | |
| 187 | insert_Key_singleton subset_Compl_range | |
| 188 | Key_not_used insert_Key_image Un_assoc [THEN sym] | |
| 189 | ||
| 190 | (*Lemma for the trivial direction of the if-and-only-if*) | |
| 191 | lemma analz_image_freshK_lemma: | |
| 192 | "(Key K \<in> analz (Key`nE \<union> H)) --> (K \<in> nE | Key K \<in> analz H) ==> | |
| 193 | (Key K \<in> analz (Key`nE \<union> H)) = (K \<in> nE | Key K \<in> analz H)" | |
| 194 | by (blast intro: analz_mono [THEN [2] rev_subsetD]) | |
| 195 | ||
| 24122 | 196 | |
| 197 | subsection{*Tactics for possibility theorems*}
 | |
| 198 | ||
| 13926 | 199 | ML | 
| 200 | {*
 | |
| 24122 | 201 | structure Shared = | 
| 202 | struct | |
| 203 | ||
| 204 | (*Omitting used_Says makes the tactic much faster: it leaves expressions | |
| 205 | such as Nonce ?N \<notin> used evs that match Nonce_supply*) | |
| 206 | fun possibility_tac ctxt = | |
| 207 | (REPEAT | |
| 32149 
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
 wenzelm parents: 
30549diff
changeset | 208 | (ALLGOALS (simp_tac (simpset_of ctxt | 
| 24122 | 209 |           delsimps [@{thm used_Says}, @{thm used_Notes}, @{thm used_Gets}] 
 | 
| 210 | setSolver safe_solver)) | |
| 211 | THEN | |
| 212 | REPEAT_FIRST (eq_assume_tac ORELSE' | |
| 213 |                    resolve_tac [refl, conjI, @{thm Nonce_supply}])))
 | |
| 13926 | 214 | |
| 24122 | 215 | (*For harder protocols (such as Recur) where we have to set up some | 
| 216 | nonces and keys initially*) | |
| 217 | fun basic_possibility_tac ctxt = | |
| 218 | REPEAT | |
| 32149 
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
 wenzelm parents: 
30549diff
changeset | 219 | (ALLGOALS (asm_simp_tac (simpset_of ctxt setSolver safe_solver)) | 
| 24122 | 220 | THEN | 
| 221 | REPEAT_FIRST (resolve_tac [refl, conjI])) | |
| 222 | ||
| 223 | ||
| 224 | val analz_image_freshK_ss = | |
| 225 |   @{simpset} delsimps [image_insert, image_Un]
 | |
| 226 |       delsimps [@{thm imp_disjL}]    (*reduces blow-up*)
 | |
| 227 |       addsimps @{thms analz_image_freshK_simps}
 | |
| 228 | ||
| 229 | end | |
| 13926 | 230 | *} | 
| 231 | ||
| 232 | ||
| 11104 | 233 | |
| 234 | (*Lets blast_tac perform this step without needing the simplifier*) | |
| 235 | lemma invKey_shrK_iff [iff]: | |
| 11270 
a315a3862bb4
better treatment of methods: uses Method.ctxt_args to refer to current
 paulson parents: 
11230diff
changeset | 236 | "(Key (invKey K) \<in> X) = (Key K \<in> X)" | 
| 13507 | 237 | by auto | 
| 11104 | 238 | |
| 239 | (*Specialized methods*) | |
| 240 | ||
| 241 | method_setup analz_freshK = {*
 | |
| 30549 | 242 | Scan.succeed (fn ctxt => | 
| 30510 
4120fc59dd85
unified type Proof.method and pervasive METHOD combinators;
 wenzelm parents: 
24122diff
changeset | 243 | (SIMPLE_METHOD | 
| 21588 | 244 | (EVERY [REPEAT_FIRST (resolve_tac [allI, ballI, impI]), | 
| 24122 | 245 |           REPEAT_FIRST (rtac @{thm analz_image_freshK_lemma}),
 | 
| 246 | ALLGOALS (asm_simp_tac (Simplifier.context ctxt Shared.analz_image_freshK_ss))]))) *} | |
| 11104 | 247 | "for proving the Session Key Compromise theorem" | 
| 248 | ||
| 249 | method_setup possibility = {*
 | |
| 30549 | 250 | Scan.succeed (fn ctxt => SIMPLE_METHOD (Shared.possibility_tac ctxt)) *} | 
| 23894 
1a4167d761ac
tactics: avoid dynamic reference to accidental theory context (via ML_Context.the_context etc.);
 wenzelm parents: 
21588diff
changeset | 251 | "for proving possibility theorems" | 
| 
1a4167d761ac
tactics: avoid dynamic reference to accidental theory context (via ML_Context.the_context etc.);
 wenzelm parents: 
21588diff
changeset | 252 | |
| 
1a4167d761ac
tactics: avoid dynamic reference to accidental theory context (via ML_Context.the_context etc.);
 wenzelm parents: 
21588diff
changeset | 253 | method_setup basic_possibility = {*
 | 
| 30549 | 254 | Scan.succeed (fn ctxt => SIMPLE_METHOD (Shared.basic_possibility_tac ctxt)) *} | 
| 11104 | 255 | "for proving possibility theorems" | 
| 2516 
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
 paulson parents: 
2451diff
changeset | 256 | |
| 12415 
74977582a585
Slightly generalized the agents' knowledge theorems
 paulson parents: 
11270diff
changeset | 257 | lemma knows_subset_knows_Cons: "knows A evs <= knows A (e # evs)" | 
| 23894 
1a4167d761ac
tactics: avoid dynamic reference to accidental theory context (via ML_Context.the_context etc.);
 wenzelm parents: 
21588diff
changeset | 258 | by (induct e) (auto simp: knows_Cons) | 
| 12415 
74977582a585
Slightly generalized the agents' knowledge theorems
 paulson parents: 
11270diff
changeset | 259 | |
| 1934 | 260 | end |