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