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