src/HOL/Auth/OtwayRees_Bad.ML
author paulson
Wed Dec 24 10:02:30 1997 +0100 (1997-12-24)
changeset 4477 b3e5857d8d99
parent 4471 0abf9d3f4391
child 4509 828148415197
permissions -rw-r--r--
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
     1 (*  Title:      HOL/Auth/OtwayRees_Bad
     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 The FAULTY version omitting encryption of Nonce NB, as suggested on page 247 of
     9   Burrows, Abadi and Needham.  A Logic of Authentication.
    10   Proc. Royal Soc. 426 (1989)
    11 
    12 This file illustrates the consequences of such errors.  We can still prove
    13 impressive-looking properties such as Spy_not_see_encrypted_key, yet the
    14 protocol is open to a middleperson attack.  Attempting to prove some key lemmas
    15 indicates the possibility of this attack.
    16 *)
    17 
    18 open OtwayRees_Bad;
    19 
    20 set proof_timing;
    21 HOL_quantifiers := false;
    22 
    23 
    24 (*A "possibility property": there are traces that reach the end*)
    25 goal thy 
    26  "!!A B. [| A ~= B; A ~= Server; B ~= Server |]   \
    27 \        ==> EX K. EX NA. EX evs: otway.          \
    28 \               Says B A {|Nonce NA, Crypt (shrK A) {|Nonce NA, Key K|}|} \
    29 \                 : set evs";
    30 by (REPEAT (resolve_tac [exI,bexI] 1));
    31 by (rtac (otway.Nil RS otway.OR1 RS otway.OR2 RS otway.OR3 RS otway.OR4) 2);
    32 by possibility_tac;
    33 result();
    34 
    35 
    36 (**** Inductive proofs about otway ****)
    37 
    38 (*Nobody sends themselves messages*)
    39 goal thy "!!evs. evs : otway ==> ALL A X. Says A A X ~: set evs";
    40 by (etac otway.induct 1);
    41 by Auto_tac;
    42 qed_spec_mp "not_Says_to_self";
    43 Addsimps [not_Says_to_self];
    44 AddSEs   [not_Says_to_self RSN (2, rev_notE)];
    45 
    46 
    47 (** For reasoning about the encrypted portion of messages **)
    48 
    49 goal thy "!!evs. Says A' B {|N, Agent A, Agent B, X|} : set evs ==> \
    50 \                X : analz (spies evs)";
    51 by (blast_tac (claset() addSDs [Says_imp_spies RS analz.Inj]) 1);
    52 qed "OR2_analz_spies";
    53 
    54 goal thy "!!evs. Says S' B {|N, X, Crypt (shrK B) X'|} : set evs ==> \
    55 \                X : analz (spies evs)";
    56 by (blast_tac (claset() addSDs [Says_imp_spies RS analz.Inj]) 1);
    57 qed "OR4_analz_spies";
    58 
    59 goal thy "!!evs. Says Server B {|NA, X, Crypt K' {|NB,K|}|} : set evs \
    60 \                 ==> K : parts (spies evs)";
    61 by (blast_tac (claset() addSEs spies_partsEs) 1);
    62 qed "Oops_parts_spies";
    63 
    64 (*OR2_analz... and OR4_analz... let us treat those cases using the same 
    65   argument as for the Fake case.  This is possible for most, but not all,
    66   proofs: Fake does not invent new nonces (as in OR2), and of course Fake
    67   messages originate from the Spy. *)
    68 
    69 bind_thm ("OR2_parts_spies",
    70           OR2_analz_spies RS (impOfSubs analz_subset_parts));
    71 bind_thm ("OR4_parts_spies",
    72           OR4_analz_spies RS (impOfSubs analz_subset_parts));
    73 
    74 (*For proving the easier theorems about X ~: parts (spies evs).*)
    75 fun parts_induct_tac i = 
    76     etac otway.induct i			THEN 
    77     forward_tac [Oops_parts_spies] (i+6) THEN
    78     forward_tac [OR4_parts_spies]  (i+5) THEN
    79     forward_tac [OR2_parts_spies]  (i+3) THEN 
    80     prove_simple_subgoals_tac  i;
    81 
    82 
    83 (** Theorems of the form X ~: parts (spies evs) imply that NOBODY
    84     sends messages containing X! **)
    85 
    86 (*Spy never sees another agent's shared key! (unless it's bad at start)*)
    87 goal thy 
    88  "!!evs. evs : otway ==> (Key (shrK A) : parts (spies evs)) = (A : bad)";
    89 by (parts_induct_tac 1);
    90 by (Fake_parts_insert_tac 1);
    91 by (ALLGOALS Blast_tac);
    92 qed "Spy_see_shrK";
    93 Addsimps [Spy_see_shrK];
    94 
    95 goal thy 
    96  "!!evs. evs : otway ==> (Key (shrK A) : analz (spies evs)) = (A : bad)";
    97 by (auto_tac(claset() addDs [impOfSubs analz_subset_parts], simpset()));
    98 qed "Spy_analz_shrK";
    99 Addsimps [Spy_analz_shrK];
   100 
   101 AddSDs [Spy_see_shrK RSN (2, rev_iffD1), 
   102 	Spy_analz_shrK RSN (2, rev_iffD1)];
   103 
   104 
   105 (*Nobody can have used non-existent keys!*)
   106 goal thy "!!evs. evs : otway ==>          \
   107 \         Key K ~: used evs --> K ~: keysFor (parts (spies evs))";
   108 by (parts_induct_tac 1);
   109 (*Fake*)
   110 by (best_tac
   111       (claset() addSDs [impOfSubs (parts_insert_subset_Un RS keysFor_mono)]
   112                addIs  [impOfSubs analz_subset_parts]
   113                addDs  [impOfSubs (analz_subset_parts RS keysFor_mono)]
   114                addss  (simpset())) 1);
   115 (*OR1-3*)
   116 by (ALLGOALS Blast_tac);
   117 qed_spec_mp "new_keys_not_used";
   118 
   119 bind_thm ("new_keys_not_analzd",
   120           [analz_subset_parts RS keysFor_mono,
   121            new_keys_not_used] MRS contra_subsetD);
   122 
   123 Addsimps [new_keys_not_used, new_keys_not_analzd];
   124 
   125 
   126 
   127 (*** Proofs involving analz ***)
   128 
   129 (*Describes the form of K and NA when the Server sends this message.  Also
   130   for Oops case.*)
   131 goal thy 
   132  "!!evs. [| Says Server B                                                 \
   133 \            {|NA, X, Crypt (shrK B) {|NB, Key K|}|} : set evs;           \
   134 \           evs : otway |]                                                \
   135 \     ==> K ~: range shrK & (EX i. NA = Nonce i) & (EX j. NB = Nonce j)";
   136 by (etac rev_mp 1);
   137 by (etac otway.induct 1);
   138 by (prove_simple_subgoals_tac 1);
   139 by (Blast_tac 1); 
   140 qed "Says_Server_message_form";
   141 
   142 
   143 (*For proofs involving analz.*)
   144 val analz_spies_tac = 
   145     dtac OR2_analz_spies 4 THEN 
   146     dtac OR4_analz_spies 6 THEN
   147     forward_tac [Says_Server_message_form] 7 THEN assume_tac 7 THEN 
   148     REPEAT ((eresolve_tac [exE, conjE] ORELSE' hyp_subst_tac) 7);
   149 
   150 
   151 (****
   152  The following is to prove theorems of the form
   153 
   154   Key K : analz (insert (Key KAB) (spies evs)) ==>
   155   Key K : analz (spies evs)
   156 
   157  A more general formula must be proved inductively.
   158 ****)
   159 
   160 
   161 (** Session keys are not used to encrypt other session keys **)
   162 
   163 (*The equality makes the induction hypothesis easier to apply*)
   164 goal thy  
   165  "!!evs. evs : otway ==>                                    \
   166 \  ALL K KK. KK <= Compl (range shrK) -->                   \
   167 \            (Key K : analz (Key``KK Un (spies evs))) =  \
   168 \            (K : KK | Key K : analz (spies evs))";
   169 by (etac otway.induct 1);
   170 by analz_spies_tac;
   171 by (REPEAT_FIRST (resolve_tac [allI, impI]));
   172 by (REPEAT_FIRST (rtac analz_image_freshK_lemma ));
   173 by (ALLGOALS (asm_simp_tac analz_image_freshK_ss));
   174 (*Fake*) 
   175 by (spy_analz_tac 1);
   176 qed_spec_mp "analz_image_freshK";
   177 
   178 
   179 goal thy
   180  "!!evs. [| evs : otway;  KAB ~: range shrK |] ==>          \
   181 \        Key K : analz (insert (Key KAB) (spies evs)) =  \
   182 \        (K = KAB | Key K : analz (spies evs))";
   183 by (asm_simp_tac (analz_image_freshK_ss addsimps [analz_image_freshK]) 1);
   184 qed "analz_insert_freshK";
   185 
   186 
   187 (*** The Key K uniquely identifies the Server's  message. **)
   188 
   189 goal thy 
   190  "!!evs. evs : otway ==>                                                  \
   191 \   EX B' NA' NB' X'. ALL B NA NB X.                                      \
   192 \     Says Server B {|NA, X, Crypt (shrK B) {|NB, K|}|} : set evs -->     \
   193 \     B=B' & NA=NA' & NB=NB' & X=X'";
   194 by (etac otway.induct 1);
   195 by (ALLGOALS (asm_simp_tac (simpset() addsimps [all_conj_distrib])));
   196 by (ALLGOALS Clarify_tac);
   197 (*Remaining cases: OR3 and OR4*)
   198 by (ex_strip_tac 2);
   199 by (Blast_tac 2);
   200 by (expand_case_tac "K = ?y" 1);
   201 by (REPEAT (ares_tac [refl,exI,impI,conjI] 2));
   202 (*...we assume X is a recent message, and handle this case by contradiction*)
   203 by (blast_tac (claset() addSEs spies_partsEs
   204                       delrules [conjI]    (*no split-up to 4 subgoals*)) 1);
   205 val lemma = result();
   206 
   207 goal thy 
   208  "!!evs. [| Says Server B {|NA, X, Crypt (shrK B) {|NB, K|}|}   : set evs; \ 
   209 \           Says Server B' {|NA',X',Crypt (shrK B') {|NB',K|}|} : set evs; \
   210 \           evs : otway |] ==> X=X' & B=B' & NA=NA' & NB=NB'";
   211 by (prove_unique_tac lemma 1);
   212 qed "unique_session_keys";
   213 
   214 
   215 (*Crucial security property, but not itself enough to guarantee correctness!*)
   216 goal thy 
   217  "!!evs. [| A ~: bad;  B ~: bad;  evs : otway |]                    \
   218 \        ==> Says Server B                                            \
   219 \              {|NA, Crypt (shrK A) {|NA, Key K|},                    \
   220 \                Crypt (shrK B) {|NB, Key K|}|} : set evs -->         \
   221 \            Says B Spy {|NA, NB, Key K|} ~: set evs -->              \
   222 \            Key K ~: analz (spies evs)";
   223 by (etac otway.induct 1);
   224 by analz_spies_tac;
   225 by (ALLGOALS
   226     (asm_simp_tac (simpset() addcongs [conj_cong] 
   227                             addsimps [analz_insert_eq, analz_insert_freshK]
   228                             addsimps (pushes@expand_ifs))));
   229 (*Oops*)
   230 by (blast_tac (claset() addSDs [unique_session_keys]) 4);
   231 (*OR4*) 
   232 by (Blast_tac 3);
   233 (*OR3*)
   234 by (blast_tac (claset() addSEs spies_partsEs
   235                        addIs [impOfSubs analz_subset_parts]) 2);
   236 (*Fake*) 
   237 by (spy_analz_tac 1);
   238 val lemma = result() RS mp RS mp RSN(2,rev_notE);
   239 
   240 goal thy 
   241  "!!evs. [| Says Server B                                         \
   242 \            {|NA, Crypt (shrK A) {|NA, Key K|},                  \
   243 \                  Crypt (shrK B) {|NB, Key K|}|} : set evs;      \
   244 \           Says B Spy {|NA, NB, Key K|} ~: set evs;              \
   245 \           A ~: bad;  B ~: bad;  evs : otway |]                \
   246 \        ==> Key K ~: analz (spies evs)";
   247 by (forward_tac [Says_Server_message_form] 1 THEN assume_tac 1);
   248 by (blast_tac (claset() addSEs [lemma]) 1);
   249 qed "Spy_not_see_encrypted_key";
   250 
   251 
   252 (*** Attempting to prove stronger properties ***)
   253 
   254 (*Only OR1 can have caused such a part of a message to appear.
   255   I'm not sure why A ~= B premise is needed: OtwayRees.ML doesn't need it.
   256   Perhaps it's because OR2 has two similar-looking encrypted messages in
   257         this version.*)
   258 goal thy 
   259  "!!evs. [| A ~: bad;  A ~= B;  evs : otway |]                \
   260 \        ==> Crypt (shrK A) {|NA, Agent A, Agent B|} : parts (spies evs) --> \
   261 \            Says A B {|NA, Agent A, Agent B,                  \
   262 \                       Crypt (shrK A) {|NA, Agent A, Agent B|}|}  : set evs";
   263 by (parts_induct_tac 1);
   264 by (Fake_parts_insert_tac 1);
   265 by (Blast_tac 1);
   266 qed_spec_mp "Crypt_imp_OR1";
   267 
   268 
   269 (*Crucial property: If the encrypted message appears, and A has used NA
   270   to start a run, then it originated with the Server!*)
   271 (*Only it is FALSE.  Somebody could make a fake message to Server
   272           substituting some other nonce NA' for NB.*)
   273 goal thy 
   274  "!!evs. [| A ~: bad;  A ~= Spy;  evs : otway |]                    \
   275 \        ==> Crypt (shrK A) {|NA, Key K|} : parts (spies evs) --> \
   276 \            Says A B {|NA, Agent A, Agent B,                        \
   277 \                       Crypt (shrK A) {|NA, Agent A, Agent B|}|}    \
   278 \             : set evs -->                                          \
   279 \            (EX B NB. Says Server B                                 \
   280 \                 {|NA,                                              \
   281 \                   Crypt (shrK A) {|NA, Key K|},                    \
   282 \                   Crypt (shrK B) {|NB, Key K|}|}  : set evs)";
   283 by (parts_induct_tac 1);
   284 by (Fake_parts_insert_tac 1);
   285 (*OR1: it cannot be a new Nonce, contradiction.*)
   286 by (blast_tac (claset() addSIs [parts_insertI]
   287                        addSEs spies_partsEs) 1);
   288 (*OR3 and OR4*)
   289 by (ALLGOALS (asm_simp_tac (simpset() addsimps [ex_disj_distrib])));
   290 by (ALLGOALS Clarify_tac);
   291 (*OR4*)
   292 by (blast_tac (claset() addSIs [Crypt_imp_OR1]
   293                        addEs  spies_partsEs) 2);
   294 (*OR3*)  (** LEVEL 5 **)
   295 (*The hypotheses at this point suggest an attack in which nonce NB is used
   296   in two different roles:
   297           Says B' Server
   298            {|Nonce NA, Agent Aa, Agent A,
   299              Crypt (shrK Aa) {|Nonce NA, Agent Aa, Agent A|}, Nonce NB,
   300              Crypt (shrK A) {|Nonce NA, Agent Aa, Agent A|}|}
   301           : set evs3;
   302           Says A B
   303            {|Nonce NB, Agent A, Agent B,
   304              Crypt (shrK A) {|Nonce NB, Agent A, Agent B|}|}
   305           : set evs3;
   306 *)
   307 writeln "GIVE UP! on NA_Crypt_imp_Server_msg";
   308 
   309 
   310 (*Thus the key property A_can_trust probably fails too.*)