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