src/HOL/Auth/OtwayRees_AN.ML
author paulson
Thu Aug 06 15:48:13 1998 +0200 (1998-08-06)
changeset 5278 a903b66822e2
parent 5223 4cb05273f764
child 5421 01fc8d6a40f2
permissions -rw-r--r--
even more tidying of Goal commands
     1 (*  Title:      HOL/Auth/OtwayRees_AN
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1996  University of Cambridge
     5 
     6 Inductive relation "otway" for the Otway-Rees protocol.
     7 
     8 Abadi-Needham version: minimal encryption, explicit messages
     9 
    10 From page 11 of
    11   Abadi and Needham.  Prudent Engineering Practice for Cryptographic Protocols.
    12   IEEE Trans. SE 22 (1), 1996
    13 *)
    14 
    15 AddEs spies_partsEs;
    16 AddDs [impOfSubs analz_subset_parts];
    17 AddDs [impOfSubs Fake_parts_insert];
    18 
    19 
    20 (*A "possibility property": there are traces that reach the end*)
    21 Goal "[| A ~= B; A ~= Server; B ~= Server |]                            \
    22 \  ==> EX K. EX NA. EX evs: otway.                                      \
    23 \       Says B A (Crypt (shrK A) {|Nonce NA, Agent A, Agent B, Key K|}) \
    24 \       : set evs";
    25 by (REPEAT (resolve_tac [exI,bexI] 1));
    26 by (rtac (otway.Nil RS otway.OR1 RS otway.OR2 RS otway.OR3 RS otway.OR4) 2);
    27 by possibility_tac;
    28 result();
    29 
    30 
    31 (**** Inductive proofs about otway ****)
    32 
    33 (*Nobody sends themselves messages*)
    34 Goal "evs : otway ==> ALL A X. Says A A X ~: set evs";
    35 by (etac otway.induct 1);
    36 by Auto_tac;
    37 qed_spec_mp "not_Says_to_self";
    38 Addsimps [not_Says_to_self];
    39 AddSEs   [not_Says_to_self RSN (2, rev_notE)];
    40 
    41 
    42 (** For reasoning about the encrypted portion of messages **)
    43 
    44 Goal "Says S' B {|X, Crypt(shrK B) X'|} : set evs ==> \
    45 \          X : analz (spies evs)";
    46 by (dtac (Says_imp_spies RS analz.Inj) 1);
    47 by (Blast_tac 1);
    48 qed "OR4_analz_spies";
    49 
    50 Goal "Says Server B {|X, Crypt K' {|NB, a, Agent B, K|}|} \
    51 \            : set evs ==> K : parts (spies evs)";
    52 by (Blast_tac 1);
    53 qed "Oops_parts_spies";
    54 
    55 bind_thm ("OR4_parts_spies",
    56           OR4_analz_spies RS (impOfSubs analz_subset_parts));
    57 
    58 (*For proving the easier theorems about X ~: parts (spies evs).*)
    59 fun parts_induct_tac i = 
    60     etac otway.induct i			THEN 
    61     forward_tac [Oops_parts_spies] (i+6) THEN
    62     forward_tac [OR4_parts_spies]  (i+5) THEN
    63     prove_simple_subgoals_tac  i;
    64 
    65 
    66 (** Theorems of the form X ~: parts (spies evs) imply that NOBODY
    67     sends messages containing X! **)
    68 
    69 (*Spy never sees a good agent's shared key!*)
    70 Goal "evs : otway ==> (Key (shrK A) : parts (spies evs)) = (A : bad)";
    71 by (parts_induct_tac 1);
    72 by (ALLGOALS Blast_tac);
    73 qed "Spy_see_shrK";
    74 Addsimps [Spy_see_shrK];
    75 
    76 Goal "evs : otway ==> (Key (shrK A) : analz (spies evs)) = (A : bad)";
    77 by (auto_tac(claset() addDs [impOfSubs analz_subset_parts], simpset()));
    78 qed "Spy_analz_shrK";
    79 Addsimps [Spy_analz_shrK];
    80 
    81 AddSDs [Spy_see_shrK RSN (2, rev_iffD1), 
    82 	Spy_analz_shrK RSN (2, rev_iffD1)];
    83 
    84 
    85 (*Nobody can have used non-existent keys!*)
    86 Goal "evs : otway ==> Key K ~: used evs --> K ~: keysFor (parts (spies evs))";
    87 by (parts_induct_tac 1);
    88 (*Fake*)
    89 by (blast_tac (claset() addSDs [keysFor_parts_insert]) 1);
    90 (*OR3*)
    91 by (Blast_tac 1);
    92 qed_spec_mp "new_keys_not_used";
    93 
    94 bind_thm ("new_keys_not_analzd",
    95           [analz_subset_parts RS keysFor_mono,
    96            new_keys_not_used] MRS contra_subsetD);
    97 
    98 Addsimps [new_keys_not_used, new_keys_not_analzd];
    99 
   100 
   101 
   102 (*** Proofs involving analz ***)
   103 
   104 (*Describes the form of K and NA when the Server sends this message.*)
   105 Goal "[| Says Server B                                           \
   106 \           {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},    \
   107 \             Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}   \
   108 \          : set evs;                                            \
   109 \        evs : otway |]                                          \
   110 \     ==> K ~: range shrK & (EX i. NA = Nonce i) & (EX j. NB = Nonce j)";
   111 by (etac rev_mp 1);
   112 by (etac otway.induct 1);
   113 by (ALLGOALS Asm_simp_tac);
   114 by (Blast_tac 1);
   115 qed "Says_Server_message_form";
   116 
   117 
   118 (*For proofs involving analz.*)
   119 val analz_spies_tac = 
   120     dtac OR4_analz_spies 6 THEN
   121     forward_tac [Says_Server_message_form] 7 THEN
   122     assume_tac 7 THEN
   123     REPEAT ((eresolve_tac [exE, conjE] ORELSE' hyp_subst_tac) 7);
   124 
   125 
   126 (****
   127  The following is to prove theorems of the form
   128 
   129   Key K : analz (insert (Key KAB) (spies evs)) ==>
   130   Key K : analz (spies evs)
   131 
   132  A more general formula must be proved inductively.
   133 ****)
   134 
   135 
   136 (** Session keys are not used to encrypt other session keys **)
   137 
   138 (*The equality makes the induction hypothesis easier to apply*)
   139 Goal "evs : otway ==>                                 \
   140 \  ALL K KK. KK <= Compl (range shrK) -->                \
   141 \         (Key K : analz (Key``KK Un (spies evs))) =  \
   142 \         (K : KK | Key K : analz (spies evs))";
   143 by (etac otway.induct 1);
   144 by analz_spies_tac;
   145 by (REPEAT_FIRST (resolve_tac [allI, impI]));
   146 by (REPEAT_FIRST (rtac analz_image_freshK_lemma ));
   147 by (ALLGOALS (asm_simp_tac analz_image_freshK_ss));
   148 (*Fake*) 
   149 by (spy_analz_tac 1);
   150 qed_spec_mp "analz_image_freshK";
   151 
   152 
   153 Goal "[| evs : otway;  KAB ~: range shrK |] ==>       \
   154 \     Key K : analz (insert (Key KAB) (spies evs)) =  \
   155 \     (K = KAB | Key K : analz (spies evs))";
   156 by (asm_simp_tac (analz_image_freshK_ss addsimps [analz_image_freshK]) 1);
   157 qed "analz_insert_freshK";
   158 
   159 
   160 (*** The Key K uniquely identifies the Server's message. **)
   161 
   162 Goal "evs : otway ==>                                            \
   163 \   EX A' B' NA' NB'. ALL A B NA NB.                             \
   164 \    Says Server B                                               \
   165 \      {|Crypt (shrK A) {|NA, Agent A, Agent B, K|},             \
   166 \        Crypt (shrK B) {|NB, Agent A, Agent B, K|}|} : set evs  \
   167 \    --> A=A' & B=B' & NA=NA' & NB=NB'";
   168 by (etac otway.induct 1);
   169 by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
   170 by (ALLGOALS Clarify_tac);
   171 (*Remaining cases: OR3 and OR4*)
   172 by (ex_strip_tac 2);
   173 by (Blast_tac 2);
   174 by (expand_case_tac "K = ?y" 1);
   175 by (REPEAT (ares_tac [refl,exI,impI,conjI] 2));
   176 (*...we assume X is a recent message and handle this case by contradiction*)
   177 by (blast_tac (claset() addSEs spies_partsEs) 1);
   178 val lemma = result();
   179 
   180 
   181 Goal "[| Says Server B                                           \
   182 \         {|Crypt (shrK A) {|NA, Agent A, Agent B, K|},         \
   183 \           Crypt (shrK B) {|NB, Agent A, Agent B, K|}|}        \
   184 \        : set evs;                                             \
   185 \       Says Server B'                                          \
   186 \         {|Crypt (shrK A') {|NA', Agent A', Agent B', K|},     \
   187 \           Crypt (shrK B') {|NB', Agent A', Agent B', K|}|}    \
   188 \        : set evs;                                             \
   189 \       evs : otway |]                                          \
   190 \    ==> A=A' & B=B' & NA=NA' & NB=NB'";
   191 by (prove_unique_tac lemma 1);
   192 qed "unique_session_keys";
   193 
   194 
   195 
   196 (**** Authenticity properties relating to NA ****)
   197 
   198 (*If the encrypted message appears then it originated with the Server!*)
   199 Goal "[| A ~: bad;  evs : otway |]                 \
   200 \ ==> Crypt (shrK A) {|NA, Agent A, Agent B, Key K|} : parts (spies evs) \
   201 \  --> (EX NB. Says Server B                                          \
   202 \               {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},     \
   203 \                 Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}    \
   204 \               : set evs)";
   205 by (parts_induct_tac 1);
   206 by (Blast_tac 1);
   207 by (ALLGOALS (asm_simp_tac (simpset() addsimps [ex_disj_distrib])));
   208 (*OR3*)
   209 by (Blast_tac 1);
   210 qed_spec_mp "NA_Crypt_imp_Server_msg";
   211 
   212 
   213 (*Corollary: if A receives B's OR4 message then it originated with the Server.
   214   Freshness may be inferred from nonce NA.*)
   215 Goal "[| Says B' A (Crypt (shrK A) {|NA, Agent A, Agent B, Key K|})  \
   216 \         : set evs;                                                 \
   217 \        A ~: bad;  evs : otway |]                                  \
   218 \     ==> EX NB. Says Server B                                       \
   219 \                 {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},  \
   220 \                   Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|} \
   221 \                : set evs";
   222 by (blast_tac (claset() addSIs [NA_Crypt_imp_Server_msg]) 1);
   223 qed "A_trusts_OR4";
   224 
   225 
   226 (** Crucial secrecy property: Spy does not see the keys sent in msg OR3
   227     Does not in itself guarantee security: an attack could violate 
   228     the premises, e.g. by having A=Spy **)
   229 
   230 Goal "[| A ~: bad;  B ~: bad;  evs : otway |]                   \
   231 \     ==> Says Server B                                         \
   232 \          {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},    \
   233 \            Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}   \
   234 \         : set evs -->                                         \
   235 \         Notes Spy {|NA, NB, Key K|} ~: set evs -->            \
   236 \         Key K ~: analz (spies evs)";
   237 by (etac otway.induct 1);
   238 by analz_spies_tac;
   239 by (ALLGOALS
   240     (asm_simp_tac (simpset() addcongs [conj_cong, if_weak_cong] 
   241                              addsimps [analz_insert_eq, analz_insert_freshK]
   242                              addsimps (pushes@split_ifs))));
   243 (*Oops*)
   244 by (blast_tac (claset() addSDs [unique_session_keys]) 4);
   245 (*OR4*) 
   246 by (Blast_tac 3);
   247 (*OR3*)
   248 by (Blast_tac 2);
   249 (*Fake*) 
   250 by (spy_analz_tac 1);
   251 val lemma = result() RS mp RS mp RSN(2,rev_notE);
   252 
   253 Goal "[| Says Server B                                           \
   254 \           {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},    \
   255 \             Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}   \
   256 \          : set evs;                                            \
   257 \        Notes Spy {|NA, NB, Key K|} ~: set evs;                 \
   258 \        A ~: bad;  B ~: bad;  evs : otway |]                    \
   259 \     ==> Key K ~: analz (spies evs)";
   260 by (forward_tac [Says_Server_message_form] 1 THEN assume_tac 1);
   261 by (blast_tac (claset() addSEs [lemma]) 1);
   262 qed "Spy_not_see_encrypted_key";
   263 
   264 
   265 (*A's guarantee.  The Oops premise quantifies over NB because A cannot know
   266   what it is.*)
   267 Goal "[| Says B' A (Crypt (shrK A) {|NA, Agent A, Agent B, Key K|})  \
   268 \         : set evs;                                                 \
   269 \        ALL NB. Notes Spy {|NA, NB, Key K|} ~: set evs;         \
   270 \        A ~: bad;  B ~: bad;  evs : otway |]                    \
   271 \     ==> Key K ~: analz (spies evs)";
   272 by (blast_tac (claset() addSDs [A_trusts_OR4, Spy_not_see_encrypted_key]) 1);
   273 qed "A_gets_good_key";
   274 
   275 
   276 (**** Authenticity properties relating to NB ****)
   277 
   278 (*If the encrypted message appears then it originated with the Server!*)
   279 Goal "[| B ~: bad;  evs : otway |]                                 \
   280 \ ==> Crypt (shrK B) {|NB, Agent A, Agent B, Key K|} : parts (spies evs) \
   281 \     --> (EX NA. Says Server B                                          \
   282 \                  {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},     \
   283 \                    Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}    \
   284 \                  : set evs)";
   285 by (parts_induct_tac 1);
   286 by (Blast_tac 1);
   287 by (ALLGOALS (asm_simp_tac (simpset() addsimps [ex_disj_distrib])));
   288 (*OR3*)
   289 by (Blast_tac 1);
   290 qed_spec_mp "NB_Crypt_imp_Server_msg";
   291 
   292 
   293 (*Guarantee for B: if it gets a well-formed certificate then the Server
   294   has sent the correct message in round 3.*)
   295 Goal "[| Says S' B {|X, Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|} \
   296 \          : set evs;                                                    \
   297 \        B ~: bad;  evs : otway |]                                       \
   298 \     ==> EX NA. Says Server B                                           \
   299 \                  {|Crypt (shrK A) {|NA, Agent A, Agent B, Key K|},     \
   300 \                    Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|}    \
   301 \                  : set evs";
   302 by (blast_tac (claset() addSIs [NB_Crypt_imp_Server_msg]) 1);
   303 qed "B_trusts_OR3";
   304 
   305 
   306 (*The obvious combination of B_trusts_OR3 with Spy_not_see_encrypted_key*)
   307 Goal "[| Says S' B {|X, Crypt (shrK B) {|NB, Agent A, Agent B, Key K|}|} \
   308 \         : set evs;                                            \
   309 \        ALL NA. Notes Spy {|NA, NB, Key K|} ~: set evs;                \
   310 \        A ~: bad;  B ~: bad;  evs : otway |]                   \
   311 \     ==> Key K ~: analz (spies evs)";
   312 by (blast_tac (claset() addDs [B_trusts_OR3, Spy_not_see_encrypted_key]) 1);
   313 qed "B_gets_good_key";