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