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