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