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